Skip to content

No.44 · Buttons

Pull Cord

A theme switch that works like a light cord: pull the handle down until it clicks and the lights change, then it springs back up and sways until it settles.

The prompt

Copy this text

Automatic copying is unavailable. Copy the selected text using your device’s copy command.

Written for the variant you picked above: Lights on

Build a dark-mode switch as a pull cord in SVG: a small ceiling mount, a cord drawn as a quadratic path from the mount to a brass teardrop handle, and a faint dashed highlight along the cord for twist. The handle is the switch (role=switch, aria-checked, focusable, with a focus ring). Dragging the handle down stretches the cord 1:1 up to 64px, then with 20% resistance; sideways movement sways the handle (half the pointer offset, ±26px), bowing the cord toward it and tilting the handle. At 34px of pull the switch clicks — the theme flips immediately, mid-pull, and a ring pulses off the handle — exactly once per pull. Releasing hands the stretch and sway to two damped springs in requestAnimationFrame (stretch stiff, sway loose), so the handle snaps up, bounces and keeps swinging gently before it comes to rest. A click without dragging, Space or Enter performs a full pull by itself (180ms down, then the springs). Reduced motion flips without the pull or the bounce. Controlled (checked/onChange) or uncontrolled. Selected variant — Lights on (paper): Starts with the lights on: a warm paper reading room (#f3efe6, ink #1b1a17) under a soft lamp pool; pulling switches to dark. This selection takes precedence over references to other themes or options in the general brief. Implement this selected appearance; do not add a variant picker or alternative appearances unless requested. Implementation requirements: Use React and TypeScript. Keep the component self-contained, with uniquely scoped CSS and no animation libraries. Include required imports, styles and font setup in the result. Interaction: Drag the handle down until it clicks, or click it. Space and Enter pull it too. Motion: Drag follows the pointer; release runs two damped springs (stretch k=320, sway k=60); the click pulse is 520ms. Accessibility: A real switch: role=switch with aria-checked and a label ('Lights off'), focusable with a visible ring, operable with Space and Enter. The theme changes on the click, not the release, so it never depends on the animation finishing. Reduced motion flips instantly. Responsive behavior: Fixed 64px wide; its length is a prop. Touch-action is disabled on the handle so dragging doesn't scroll. Touch: Drag with a finger, or tap to pull it once. Preserve keyboard access, visible focus and reduced-motion behavior. Keep fictional demo data and simulated service calls in a separate usage example; expose callbacks for real actions and recover from rejected requests. Keep usage-example links inside the demo: use local buttons or prevent navigation. Demonstration links must not navigate to Vitrine routes or open other pages; preserve real URL support in the reusable component itself. Verify the result at narrow and wide viewport sizes, with keyboard input and reduced motion enabled.

Notes

Interaction
Drag the handle down until it clicks, or click it. Space and Enter pull it too.
Motion
Drag follows the pointer; release runs two damped springs (stretch k=320, sway k=60); the click pulse is 520ms.
Accessibility
A real switch: role=switch with aria-checked and a label ('Lights off'), focusable with a visible ring, operable with Space and Enter. The theme changes on the click, not the release, so it never depends on the animation finishing. Reduced motion flips instantly.
Responsive
Fixed 64px wide; its length is a prop. Touch-action is disabled on the handle so dragging doesn't scroll.
On touch
Drag with a finger, or tap to pull it once.