diff --git a/src/renderer/src/components/ui/kbd/Kbd.tsx b/src/renderer/src/components/ui/kbd/Kbd.tsx index 4068a72681..d59db9ae8b 100644 --- a/src/renderer/src/components/ui/kbd/Kbd.tsx +++ b/src/renderer/src/components/ui/kbd/Kbd.tsx @@ -1,12 +1,15 @@ import { cn, getOS } from "@renderer/lib/utils" import type { FC } from "react" -import { Fragment, memo } from "react" import * as React from "react" +import { Fragment, memo } from "react" import { isHotkeyPressed } from "react-hotkeys-hook" const SharedKeys = { backspace: "⌫", space: "␣", + pageup: "PageUp", + pagedown: "PageDown", + tab: "Tab", } const SpecialKeys = { Windows: { @@ -89,38 +92,149 @@ export const Kbd: FC<{ children: string; className?: string }> = memo(({ childre }, [children]) return ( - { + setIsKeyPressed(true) + setTimeout(() => { + setIsKeyPressed(false) + }, 100) + }} > - {children.split("+").map((key_) => { - let key: string = key_.toLowerCase() - for (const [k, v] of Object.entries(specialKeys)) { - key = key.replace(k, v) - } - - switch (key) { - case SharedKeys.space: { - return - } + + isKeyPressed ? "" : "border-b-2", + className, + )} + > + {children.split("+").map((key_) => { + let key: string = key_.toLowerCase() + for (const [k, v] of Object.entries(specialKeys)) { + key = key.replace(k, v) } - default: { - return ( - - {key} - - ) + switch (key) { + case SharedKeys.space: { + return + } + + case SharedKeys.backspace: { + return + } + case SpecialKeys.macOS.meta: { + return + } + case SpecialKeys.macOS.alt: { + return + } + + case SpecialKeys.macOS.ctrl: { + return + } + + case SpecialKeys.macOS.shift: { + return + } + + case SharedKeys.tab: { + return + } + case SpecialKeys.Windows.meta: { + return + } + default: { + return ( + + {key} + + ) + } } - } - })} - + })} + + ) }) + +function MaterialSymbolsKeyboardCommandKey(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsKeyboardOptionKey(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsKeyboardControlKey(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsShiftOutlineRounded(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsKeyboardTabRounded(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsSpaceBarRounded(props: React.SVGProps) { + return ( + + + + ) +} +function MaterialSymbolsBackspace(props: React.SVGProps) { + return ( + + + + ) +} + +function MaterialSymbolsWindowOutlineSharp(props: React.SVGProps) { + return ( + + + + ) +} diff --git a/src/renderer/src/modules/modal/shortcuts.tsx b/src/renderer/src/modules/modal/shortcuts.tsx new file mode 100644 index 0000000000..16e73552cc --- /dev/null +++ b/src/renderer/src/modules/modal/shortcuts.tsx @@ -0,0 +1,66 @@ +import { MotionButtonBase } from "@renderer/components/ui/button" +import { KbdCombined } from "@renderer/components/ui/kbd/Kbd" +import { useCurrentModal, useModalStack } from "@renderer/components/ui/modal" +import { NoopChildren } from "@renderer/components/ui/modal/stacked/utils" +import { ScrollArea } from "@renderer/components/ui/scroll-area" +import { shortcuts } from "@renderer/constants/shortcuts" +import { cn } from "@renderer/lib/utils" +import { m } from "framer-motion" +import { useCallback } from "react" + +const ShortcutModalContent = () => { + const { dismiss } = useCurrentModal() + return ( + +

Shortcuts Guideline

+ + + + +
+ {Object.keys(shortcuts).map((type) => ( +
+
{type}
+
+ {Object.keys(shortcuts[type]).map((action, index) => ( +
+
{shortcuts[type][action].name}
+
+ + {`${shortcuts[type][action].key}${shortcuts[type][action].extra ? `, ${shortcuts[type][action].extra}` : ""}`} + +
+
+ ))} +
+
+ ))} +
+
+
+ ) +} + +export const useShortcutsModal = () => { + const { present } = useModalStack() + + return useCallback(() => { + present({ + title: "Shortcuts", + content: () => , + CustomModalComponent: NoopChildren, + clickOutsideToDismiss: true, + }) + }, [present]) +} diff --git a/src/renderer/src/pages/(main)/layout.tsx b/src/renderer/src/pages/(main)/layout.tsx index fbd4677a33..869891aad3 100644 --- a/src/renderer/src/pages/(main)/layout.tsx +++ b/src/renderer/src/pages/(main)/layout.tsx @@ -21,10 +21,10 @@ import { LoginModalContent } from "@renderer/modules/auth/LoginModalContent" import { FeedColumn } from "@renderer/modules/feed-column" import { AutoUpdater } from "@renderer/modules/feed-column/auto-updater" import { CornerPlayer } from "@renderer/modules/feed-column/corner-player" +import { useShortcutsModal } from "@renderer/modules/modal/shortcuts" import { CmdF } from "@renderer/modules/panel/cmdf" import { SearchCmdK } from "@renderer/modules/panel/cmdk" import { CmdNTrigger } from "@renderer/modules/panel/cmdn" -import { useSettingModal } from "@renderer/modules/settings/modal/hooks" import { throttle } from "lodash-es" import type { PropsWithChildren } from "react" import React, { useEffect, useRef, useState } from "react" @@ -169,16 +169,10 @@ const FeedResponsiveResizerContainer = ({ scopes: HotKeyScopeMap.Home, }, ) - const settingModalPresent = useSettingModal() - useHotkeys( - shortcuts.layout.showShortcuts.key, - () => { - settingModalPresent("shortcuts") - }, - { - scopes: HotKeyScopeMap.Home, - }, - ) + const showShortcuts = useShortcutsModal() + useHotkeys(shortcuts.layout.showShortcuts.key, showShortcuts, { + scopes: HotKeyScopeMap.Home, + }) const [delayShowSplitter, setDelayShowSplitter] = useState(feedColumnShow) diff --git a/src/renderer/src/pages/settings/(settings)/shortcuts.tsx b/src/renderer/src/pages/settings/(settings)/shortcuts.tsx index b307a55073..d10bf27fb1 100644 --- a/src/renderer/src/pages/settings/(settings)/shortcuts.tsx +++ b/src/renderer/src/pages/settings/(settings)/shortcuts.tsx @@ -1,4 +1,4 @@ -import { Kbd, KbdCombined } from "@renderer/components/ui/kbd/Kbd" +import { KbdCombined } from "@renderer/components/ui/kbd/Kbd" import { shortcuts } from "@renderer/constants/shortcuts" import { cn } from "@renderer/lib/utils" import { SettingsTitle } from "@renderer/modules/settings/title" @@ -17,9 +17,7 @@ export function Component() { return ( <> -

- Press H to show this Shortcuts modal. -

+
{Object.keys(shortcuts).map((type) => (