From 57d55dce1aa7329d5144d248139b4f35e8144071 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 13 Jun 2023 19:29:28 +0100 Subject: [PATCH] feat: display shortcut key tips --- src/components/ui/EditorToolbar.tsx | 23 ++++++++++++++++++++--- src/lib/utils.ts | 7 +++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/ui/EditorToolbar.tsx b/src/components/ui/EditorToolbar.tsx index 25fd1ee5..fb93cd5a 100644 --- a/src/components/ui/EditorToolbar.tsx +++ b/src/components/ui/EditorToolbar.tsx @@ -7,6 +7,7 @@ import { Popover } from "@headlessui/react" import type { ICommand } from "~/editor" import { useTranslation } from "~/lib/i18n/client" +import { isMacOS } from "~/lib/utils" import { Tooltip } from "./Tooltip" @@ -22,6 +23,12 @@ enum ToolbarMode { type IToolbarItemProps = ICommand & { view?: EditorView } +const keyDisplay = (shortcut?: { key?: string }) => { + return shortcut?.key + ? `(${shortcut?.key.replace("Mod", isMacOS() ? "⌘" : "Ctrl")})` + : "" +} + const ToolbarItemWithPopover = ({ name, icon, @@ -29,6 +36,7 @@ const ToolbarItemWithPopover = ({ execute, ui, view, + shortcut, }: IToolbarItemProps) => { const { t } = useTranslation("dashboard") let [popoverButtonRef, setPopoverButtonRef] = @@ -44,7 +52,11 @@ const ToolbarItemWithPopover = ({ {({ open }: { open: boolean }) => ( <> - + { const renderToolbar = useCallback( (mode: ToolbarMode) => // eslint-disable-next-line react/display-name - ({ name, icon, label, execute, ui }: ICommand) => { + ({ name, icon, label, execute, ui, shortcut }: ICommand) => { return ui ? ( { execute={execute} ui={ui} view={view} + shortcut={shortcut} /> ) : ( - +