Apple Keyboard
NewCustomize
Auto
Highlight colour
Volume0.60
Installation
npx shadcn@latest add https://uibrik.com/r/apple-keyboard.jsonAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/apple-keyboard/apple-keyboard.tsx"use client"; import { useCallback, useEffect, useRef, useState, type ReactNode } from "react"; import { cn } from "@/lib/utils"; // ─── Layout ────────────────────────────────────────────────────────────────── // Everything is measured in key pitches (`--p`, one key plus one gap), so the // keyboard scales with its container and keeps Apple's proportions at any width. // Rows are 14.5 pitches wide, like the compact Magic Keyboard. const GAP = 0.13; const PAD = 0.15; // Corner radii, measured off the Magic Keyboard. Keys have tight corners, but // the four keys at the corners of the case take the case's curve, shrunk by // PAD, so case, well and cap all bend around one centre. const CASE_RADIUS = 0.48; const RADIUS = 0.085; const CORNER = CASE_RADIUS - PAD; const RING = 0.024; const ROW = 0.98; const WIDTH = 14.5 - GAP + PAD * 2; const KEY_H = ROW - GAP; type Size = "letter" | "pair" | "word" | "fn";
Adds the files to
components/uibrik/apple-keyboard. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/apple-keyboard.Usage
import { AppleKeyboard } from "@/components/uibrik/apple-keyboard/apple-keyboard";<AppleKeyboard finish="auto" highlight={["MetaLeft", "K"]} highlightColor="#0a84ff" functionRow listen sound volume={0.6} defaultCapsLock={false} onCapsLockChange={(on) => {}} // capsLock={false} // onKeyDown={(key) => {}} // onKeyUp={(key) => {}}/>Props
AppleKeyboard- finish
- Type "auto" | "silver" | "black"
- "auto"
- Silver with white keys, black with black keys, or follow dark mode.
- highlight
- Type string[]
- ["MetaLeft","K"]
- Keys to light up, by code (KeyK), character (k, 7) or name (Return, Shift).
- highlightColor
- Type string
- "#0a84ff"
- Colour of the highlight.
- functionRow
- Type boolean
- true
- The row of esc, F1–F12 and Lock along the top.
- listen
- Type boolean
- true
- Mirror the physical keyboard: keys go down as you type.
- sound
- Type boolean
- true
- Play key sounds. The first press unlocks audio, as browsers require.
- volume
- Type number
- 0.6
- Loudness of the key sounds.
- capsLock / defaultCapsLock
- Type boolean
- — / false
- Whether the Caps Lock light is on, controlled or uncontrolled.
- onCapsLockChange
- Type (on: boolean) => void
- –
- Called when Caps Lock turns on or off.
- onKeyDown / onKeyUp
- Type (key: { id; name }) => void
- –
- Called as a key goes down and comes back up. id is the KeyboardEvent.code.
- className
- Type string
- –
- Classes for the wrapper. The keyboard fills its width.