No.39 · Buttons
Magnetic Button
A button with a pull: as the pointer comes near the pill leans toward it, the label leans further, and on leaving it springs back with a little overshoot.
The prompt
Written for the variant you picked above: Night
Build a pill button (56px; solid colours from --bg and --fg, plus a ghost style with a hairline ring) that is magnetic. A window pointermove listener measures the pointer's offset from the button's centre; within a reach of 140px plus half the button's size, the target offset is that vector × 0.32 × (1 − d/reach)^0.6, so the pull is strongest close in and fades smoothly. The pill's translate follows the target on a spring (velocity += (target − x)·0.16, ×0.74 damping per frame), so letting go springs back with a small overshoot; the label translates a further 40% of the same offset for parallax. A soft white radial light (120px) sits under the pointer inside the pill and its strength and the drop shadow's depth grow with the pull. Press scales to 0.96. The loop runs only while the spring is moving, and the effect is off on touch and under reduced motion. Selected variant — Night (night): Apply the night theme. Where the brief above gives no colour values for it, choose a restrained night palette with text at 4.5:1 contrast or better. Keep the geometry, states and motion described above unchanged. 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: Bring the pointer near and the button leans toward it; press to click. Motion: Spring stiffness 0.16, damping 0.74; press 180ms. Accessibility: A normal button; the magnetism is pointer-only and removed under reduced motion and on touch, so keyboard and touch use is unaffected. Responsive behavior: Sized by its label; works at any width. Touch: Taps work normally; pointer-only effects are skipped on touch. 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
- Bring the pointer near and the button leans toward it; press to click.
- Motion
- Spring stiffness 0.16, damping 0.74; press 180ms.
- Accessibility
- A normal button; the magnetism is pointer-only and removed under reduced motion and on touch, so keyboard and touch use is unaffected.
- Responsive
- Sized by its label; works at any width.
- On touch
- Taps work normally; pointer-only effects are skipped on touch.