Blocks / Shortcuts sheet

Shortcuts sheet

A dialog listing the app's shortcuts by section, searchable, built from the same actions as useActions.

import { ShortcutsSheet, editorShortcutEntries, editorGroupShortcuts, useActions, formatShortcut } from "@forgeron/ui";
/01 → Default
import { Button, ShortcutsSheet, type Action } from "@forgeron/ui";
import { useState } from "react";

const actions: Action[] = [
  { id: "undo", label: "Undo", shortcut: "mod+z", group: "Edit" },
  { id: "redo", label: "Redo", shortcut: "mod+shift+z", group: "Edit" },
  { id: "dup", label: "Duplicate", shortcut: "mod+d", group: "Edit", keywords: ["copy", "clone"] },
  { id: "del", label: "Delete", shortcut: "backspace", group: "Edit" },
  { id: "select", label: "Select", shortcut: "v", group: "Tools" },
  { id: "rect", label: "Rectangle", shortcut: "r", group: "Tools" },
  { id: "text", label: "Text", shortcut: "t", group: "Tools" },
  { id: "zoom-in", label: "Zoom in", shortcut: "mod+=", group: "View" },
  { id: "zoom-out", label: "Zoom out", shortcut: "mod+-", group: "View" },
  { id: "fit", label: "Zoom to fit", shortcut: "shift+1", group: "View" },
];

export default function Default() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button kbd="?" onClick={() => setOpen(true)}>
        Keyboard shortcuts
      </Button>
      <ShortcutsSheet
        actions={actions}
        open={open}
        onOpenChange={setOpen}
        entries={[
          {
            id: "pan",
            label: "Pan",
            keys: ["Space", "drag"],
            group: "View",
            keywords: ["move", "hand"],
          },
          { id: "zoom-wheel", label: "Zoom", keys: ["⌘", "scroll"], group: "View" },
        ]}
        sectionOrder={["Tools", "Edit", "View"]}
      />
    </>
  );
}
API → Props
PropTypeDefaultDescription
actionsAction[]—As given to useActions: those with a shortcut are listed under their group.
entries{ id, label, shortcut? | keys?, group?, keywords? }[]—More: keys that are not a combination (keys: [“Space”, “drag”]).
open / defaultOpen / onOpenChangeboolean—Controlled or not.
hotkeystring | false"shift+?"Opens the sheet from anywhere (not while typing).
macboolean—Reads ⌘ (true) or Ctrl (false) in the hints. Default: from the platform.
title / fallbackGroup / sectionOrder / footerReactNode; string; string[]; ReactNode—Wording, the order of sections, a note under the list.