Add the Nook "Shortcut" component to this project, exactly as Nook ships it.
Keyboard shortcuts: a hook that listens and a label that shows the keys for this device.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add shortcut`. It writes `components/ui/shortcut.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/shortcut.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { Shortcut, useShortcut } from "@/components/ui/shortcut";
export default function ShortcutDefault() {
const [log, setLog] = React.useState("Press one of the shortcuts.");
const [dark, setDark] = React.useState(false);
useShortcut("alt+d", () => {
setDark((value) => !value);
setLog("Toggled the highlight.");
});
return (
New task setLog("New task")} />
Search setLog("Search opened")} />
Highlight
Shortcuts help setLog("Help opened")} />
{log}
);
}
```
API
- `useShortcut`: `useShortcut(keys, handler, options?)` runs the handler when the keys are pressed. Keys read like `mod+k`, `shift+/`, `alt+ArrowUp` or `Escape`; `mod` is ⌘ on Apple devices and Ctrl elsewhere.
- `enabled` (`boolean`, default true): Turn it off without removing the hook.
- `whileTyping` (`boolean`, default false): Also fire while someone is typing in a field.
- `preventDefault` (`boolean`, default true): Stop the browser's own action.
- `Shortcut`: The keys as a row of Kbd, written the way this device writes them. With `onTrigger` it also listens.
- `keys` (`string`): For example "mod+k".
- `onTrigger` (`(event) => void`): What to run. Leave out to only show the keys.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Shortcuts without Ctrl, ⌘ or Alt are ignored while someone types in a field. Always offer the same action somewhere on screen: a shortcut is a faster way, never the only way.
Done when the component renders like the example in light and dark mode and the project type-checks.