Shortcut recorder

Record key combinations into key caps, with conflict warnings, Kbd, and a searchable cheatsheet.

npx shadcn@latest add @silicon-ui/shortcut-recorder
inputsnew
Loading…

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/shortcut-recorder

Manually

  1. Install the dependencies.

    npm install lucide-react motion
  2. Copy these files into your project. Shared files are skipped if you already have them.

    • components/silicon-ui/shortcut-recorder/shortcut-recorder.tsx
    • components/silicon-ui/shortcut-recorder/shortcut-recorder.module.css
  3. Install the foundation once per app for the design and motion tokens: npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

Source codetsx
import { ShortcutRecorder } from "@/components/silicon-ui/shortcut-recorder/shortcut-recorder";

API reference

ShortcutRecorder

PropTypeDefault
label*string—
hideLabelbooleanfalse
valuestring | null—
defaultValuestring | nullnull
onValueChange

`replaced` is the binding the new shortcut was taken from after "Use anyway", so the caller can unbind it.

(value: string | null, details: { replaced?: ShortcutBinding }) => void—
resetValue

What the reset button restores. Defaults to `defaultValue`.

string | null—
bindings

Shortcuts already in use. Recording one of them asks before taking it.

ShortcutBinding[][]
warnReserved

Also warn about combinations the browser or system keeps, such as ⌘W and ⌘C. On by default.

booleantrue
requireModifier

Require ⌘, Ctrl, or ⌥ (function keys are always allowed). On by default.

booleantrue
platformPlatform

"mac""other"

—
placeholderstring"Record shortcut"
descriptionstring—
disabledbooleanfalse
idstring—
classNamestring—

ShortcutKeys

PropTypeDefault
shortcut*string—
platformPlatform

"mac""other"

—
pressed

Held key ids from `usePressedKeys`; matching caps light up.

ReadonlySet<string>—
size"sm" | "md""md"
classNamestring—

ShortcutList

PropTypeDefault
groups*ShortcutListGroup[]—
label

Accessible name of the list.

string"Keyboard shortcuts"
searchablebooleantrue
searchPlaceholderstring"Search shortcuts"
highlightPressed

Light up caps as keys are held, and fade rows that do not use the held modifiers. On by default.

booleantrue
platformPlatform

"mac""other"

—
classNamestring—

ShortcutKbd

PropTypeDefault
children*ReactNode—
pressed

Draws the key pushed down and lit, such as while it is held.

booleanfalse
size"sm" | "md""md"

Also accepts the props of HTMLAttributes<HTMLElement>.

Kbd

PropTypeDefault
children*ReactNode—
pressed

Draws the key pushed down and lit, such as while it is held.

boolean—
size"sm" | "md"—

Also accepts the props of HTMLAttributes.

Dependencies

npm
lucide-reactmotion
Registry
silicon-motion-tokens