Loading preview
Analog Clock
Data displayA station clock whose needle waits at twelve; drag the minute hand to set it by hand.
A compact Mac-style keyboard whose keys press down when clicked, light up as you type on your own keyboard, and can sound like a mechanical keyboard.
npx shadcn@latest add @venusui/keyboardRun this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.
Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.
@/components/ui/keyboard.tsxThe code behind the preview above.
keyboard-demo.tsx
"use client"
import * as React from "react"
import { Keyboard, type KeyboardKeyPress, type KeyboardSound } from "@/components/ui/keyboard"
import { cn } from "@/lib/utils"
const SOUNDS: { value: KeyboardSound | "off"; label: string }[] = [
{ value: "off", label: "Off" },
{ value: "thock", label: "Thock" },
{ value: "clicky", label: "Clicky" },
]
export default function KeyboardDemo() {
const [recent, setRecent] = React.useState<(KeyboardKeyPress & { id: number })[]>([])
const [sound, setSound] = React.useState<KeyboardSound | "off">("thock")
const nextId = React.useRef(0)
return (
<div className="flex w-full max-w-3xl flex-col items-center gap-6">
<div className="flex w-full flex-wrap items-center justify-between gap-3">
<p aria-live="polite" className="flex min-h-7 flex-wrap items-center gap-1.5 text-sm text-muted-foreground">
{recent.length === 0
? "Click a key, or type on your keyboard."
: recent.map((key) => (
<kbd key={key.id} className="rounded-md border bg-muted px-1.5 py-0.5 font-sans text-xs text-foreground">
{key.name}
</kbd>
))}
</p>
<div role="group" aria-label="Sound" className="flex shrink-0 items-center gap-0.5 rounded-lg border p-0.5 text-xs">
{SOUNDS.map((option) => (
<button
key={option.value}
type="button"
aria-pressed={sound === option.value}
onClick={() => setSound(option.value)}
className={cn(
"rounded-md px-2.5 py-1 outline-none focus-visible:ring-3 focus-visible:ring-ring/50",
sound === option.value ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:text-foreground"
)}
>
{option.label}
</button>
))}
</div>
</div>
<Keyboard
sound={sound === "off" ? false : sound}
onKeyPress={(key) => setRecent((all) => [...all, { ...key, id: nextId.current++ }].slice(-8))}
/>
</div>
)
}
| Prop | Type | Default | Description |
|---|---|---|---|
| onKeyPress | (key: KeyboardKeyPress) => void | — | Called for each press with the key's code (e.g. "KeyA"), name (e.g. "A") and source: "click" or "keyboard". |
| listen | boolean | true | Light up keys as they are pressed on the user's real keyboard. |
| sound | boolean | "thock" | "clicky" | false | Mechanical keyboard sound on each press and release: "thock" (deep, linear switches; true plays this) or "clicky" (bright click switches). Synthesized with the Web Audio API, so there are no audio files. |
All <div> props, on the outer element.
lucide-react for the function-row icons. The CLI installs it.max-w-xl to make it smaller.className strings in keyboard.tsx.ROWS data at the top of the file. Each row adds up to 14.5 key units; keep that total if you change key widths.listen={false} to show a keyboard that only responds to clicks, e.g. in a list of several.SHAPES in keyboard.tsx: each is a few filtered noise bursts (the click and the plastic) and pitch-dropping tones (the bottom-out). Lower frequency values sound deeper.aria-pressed and shows a light.listen isn’t false.Unknown registry "@venusui"npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.No components.json foundnpx shadcn@latest init in your project first.A station clock whose needle waits at twelve; drag the minute hand to set it by hand.
Books on a wooden shelf whose spines lift on hover and pull out when selected, with a matching cover.
A messaging conversation that plays out with typing indicators; viewers can send replies too.