No.46 · Buttons
Glass Lens Switch
A segmented control whose selection is a drop of liquid glass: it slides on a spring, stretching as it moves, and magnifies whatever passes under it. You can drag it, too.
The prompt
Written for the variant you picked above: Night
Build a frosted segmented control (Day / Week / Month / Year) where the selection indicator is a glass lens. Measure each option's offsetLeft and width. Drive the lens's x and width with a spring (k 520, damping 30) in a requestAnimationFrame loop that stops when settled; while moving, stretch it by its speed (scaleX up to 1.24, scaleY down to 0.86), so it reads as liquid and wobbles slightly on arrival. The lens is frosted (backdrop blur 6px, saturate, brightness) so the label under it goes soft, and it contains a second, sharp copy of the whole row of labels, translated by −x so it lines up with the track and scaled 1.14 about the lens's centre. The words under the lens are magnified and brightened, and they swell as the lens slides across. Inner highlights and a soft shadow make it glass. Options are a radiogroup with roving tabindex; arrows, Home and End move and select. Press on the lens and drag past 4px to slide it by hand (pointer capture); on release it snaps to the nearest option and selects it. Selected variant — Night (night): Palette for this theme (Night): --gls-edge rgb(255 255 255 / 0.18); --gls-focus rgb(255 255 255 / 0.9); --gls-ink rgb(255 255 255 / 0.72); --gls-ink-on #ffffff; --gls-lens rgb(255 255 255 / 0.2); --gls-track rgb(255 255 255 / 0.1). Treat these as the root colour tokens, one value per role, and name them to suit your code. Select it with the theme option set to "night". Keep every dimension, spacing value, state and motion from the brief unchanged, and keep text at 4.5:1 contrast or better on these surfaces. 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: Click or use the arrow keys to move the lens; or grab it and drag, and it snaps to the nearest option. Motion: Spring k 520 / c 30, with velocity-based squash and stretch; settles in about 400ms. Accessibility: A labelled radiogroup of real buttons with aria-checked and roving tabindex; the lens and its magnified copy are aria-hidden. Dragging is an extra; every option is reachable by click and keyboard. Reduced motion moves the lens instantly. Responsive behavior: Intrinsic width; re-measured on resize so the lens always sits on its option. Touch: Tap an option, or drag the lens with a finger; vertical scrolling still works. 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
- Click or use the arrow keys to move the lens; or grab it and drag, and it snaps to the nearest option.
- Motion
- Spring k 520 / c 30, with velocity-based squash and stretch; settles in about 400ms.
- Accessibility
- A labelled radiogroup of real buttons with aria-checked and roving tabindex; the lens and its magnified copy are aria-hidden. Dragging is an extra; every option is reachable by click and keyboard. Reduced motion moves the lens instantly.
- Responsive
- Intrinsic width; re-measured on resize so the lens always sits on its option.
- On touch
- Tap an option, or drag the lens with a finger; vertical scrolling still works.