No.18 · Buttons
Keycap
A button made like a real key: it has travel, a sculpted top and a shadowed skirt — and it presses itself when you hit the matching key on your keyboard.
The prompt
The design brief behind this component — reuse it to regenerate, remix, or explain it.
Build a keyboard-key button. The dark 'skirt' is the button (radius 12px) with 5px of bottom padding; inside it a face (52px tall, radius 11px) with a sculpted top — a radial gradient lighter at the upper centre — plus an inner top highlight, an inner lower shade and a 1px dark edge. Pressing sinks the face 4px into the skirt in 40ms and compresses its shading (release springs back in 90ms), so it has real travel. Each keycap can declare the shortcut it represents (key plus meta/shift). A window keydown listener presses the cap visually and fires onPress when the real key combination is hit; keyup releases it. Wide caps show a label on the left and the legend (⌘ K) on the right in mono; square caps centre the legend. Tones: graphite, bone and a frost accent.
Notes
- Interaction
- Click it or press its real shortcut on the keyboard — either way it travels down and fires.
- Motion
- 40ms press / 90ms release on the face's translate and shading.
- Accessibility
- A real button; the shortcut is visible in the legend. Pressing the shortcut calls the same handler. Reduced motion removes the travel transition.
- Responsive
- Intrinsic width; wide caps have a 12rem minimum.
- On touch
- Pointer down/up gives the same travel on touch.