Mac Keyboard, animated React component
A Mac keyboard drawn in HTML, in silver or space grey. Press a key and it sinks, squashes and springs back while a ring of backlight spreads out from it through the gaps; it can listen to the real keyboard, plays a recorded mechanical click for each key the instant it goes down, and shows what you type in a strip above.
- Free
- Motion Effects
- Spring
Silver, typing on its own
Space grey, listening to your keyboard
Like Mac Keyboard? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Mac Keyboard stays free.
Play with it
Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| layout | "mac" | "compact" | "mac" | Full layout with the Esc and F-key row, or compact without it. |
| theme | "dark" | "light" | "auto" | "auto" | Space grey, silver, or follow the page's dark class. |
| listen | boolean | false | Reacts to the real keyboard: keys sink, ripple, click and type. With several listening keyboards on a page, only one answers: the last one pressed or hovered, else the one nearest the middle of the screen. |
| showOutput | boolean | true | Shows a strip above the keys with what has been typed. Return clears it. |
| placeholder | string | "Start typing..." | Text in the strip before anything is typed. |
| autoplay | boolean | false | Types autoplayText on the keys again and again until someone presses a key. |
| autoplayText | string | "hello, nexus" | What the demo types. |
| accent | string | "#0a84ff" | Colour of the backlight ripple. |
| enableSound | boolean | true | Plays a key click the moment a key goes down (not during autoplay). |
| soundSrc | string | "/sounds/keys.ogg" | Recorded Cherry MX clicks, one per key. Put keys.ogg in public/sounds; until it loads, or if it is missing, the synthesised click plays. Pass "" to always synthesise. |
| soundType | "mechanical" | "soft" | "clicky" | "mechanical" | Timbre of the synthesised click (used when there is no recording). |
| volume | number | 0.6 | Click volume, 0 to 1. |
| showFunctionRow | boolean | true | Shows the Esc and F-key row (mac layout). |
| activeKeys | string[] | [] | KeyboardEvent.code values to show as held, e.g. from usePhysicalKeyboard(). |
| onKeyPress | (key: KeyDef) => void | — | Fires when a key on screen is pressed. |
| className | string | — | Extra classes on the keyboard body. |
| keyClassName | string | — | Extra classes on every keycap. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/mac-keyboard
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/key-sound/index.tskey-sound-slices.tskey-sound.tsuse-key-sound.tskeyboard/index.tskeyboard-key.tsxkeyboard-layout.tskeyboard.tsxuse-keyboard-sound.tsmac-keyboard.tsx - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { MacKeyboard } from "@/components/keyboard"; export default function Page() { return ( <main> <MacKeyboard /> </main> ); }
Like Mac Keyboard? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Mac Keyboard stays free.
About Mac Keyboard
The Mac Keyboard component renders an animated replica of a standard Apple keyboard layout with spring-animated key press physics. Individual keys depress with a Framer Motion spring transition on hover, matching the physical press feel of a real keyboard. Use it in developer tool demos to illustrate keyboard shortcuts, in documentation to highlight key bindings, or as a decorative product visual that communicates the tool is built for keyboard-first users.
Good for
- Keyboard shortcut documentation pages
- Developer tool feature illustrations
- Interactive onboarding guides
- CLI and terminal tool marketing pages
Mac Keyboard questions
How do I install the Mac keyboard?
Run `npx shadcn@latest add @nexus-labs/mac-keyboard`. It installs framer-motion. For the recorded key clicks, copy `keys.ogg` (about 200 KB) into `public/sounds/`; without it the keys use a click synthesised with the Web Audio API, so nothing breaks.
How do I highlight keys as the user types?
Call the exported `usePhysicalKeyboard()` hook and pass its result to `activeKeys`. Keys matching the pressed `KeyboardEvent.code` values show as held down.
Which sound options are there?
`enableSound` turns sound on or off, `soundType` picks "mechanical", "soft" or "clicky", and `volume` goes from 0 to 1. Sounds play when virtual keys are clicked, and `onKeyPress` gives you the key that was pressed.
Can I change the layout and theme?
`layout` is "mac" or "compact", `showFunctionRow` hides the Esc and F-key row, and `theme` is "dark", "light" or "auto", which follows the `dark` class on the html element.