clickworks
Works / Hero

Keycap Matrix

A small field of keys, like a keyboard seen up close, with a glyph raised out of it. A soft pillow lens follows the cursor and bulges the keys under it. Click and the keys flip, one after another, to the next glyph. It's drawn on one canvas and only runs while something moves.

Free1 file0 dependencies4.4 kB gzippedRenders on the serverKeyboard and screen reader

Install

npx shadcn@latest add https://clickworks.dev/r/keycap-matrix.json

The files land in components/clickworks/keycap-matrix/. No other packages are added.

Usage

import { KeycapMatrix } from "@/components/clickworks/keycap-matrix/react/KeycapMatrix"

export function Hero() {
  return <KeycapMatrix glyph="Sparkle" style={{ width: 360, height: 360 }} />
}

Props

glyph
string

The sign the keys start on: Sparkle, Heart, Star, Bolt, Arrow, Check, Moon and 17 more.

Default "Smile"

theme
"light" | "dark" | "auto"

Auto follows the page (its background, data-theme or dark class), then the device.

Default "auto"

light / dark
{ key?, glyph? }

Key and glyph colours for each theme.

shadow
{ color?, strength? }

The shadow under every key.

Default "#000000", 1

bulge
number

How much the lens lifts the keys under it.

Default 0.13

lens
boolean

The lens follows the cursor.

Default true

cycle
boolean

A click moves on to the next glyph.

Default true

flip
boolean

Keys flip one after another when the glyph changes.

Default true

Events

Styling

It fills its frame and stays square. Colours come in through the light and dark props.

Behaviour and accessibility

  • Drawn on one canvas; the loop only runs while the lens moves or keys flip.
  • On touch there is no lens. A tap moves on to the next glyph.
  • With reduced motion keys change without flipping.

Files

react/KeycapMatrix.tsxReact component