"use client"; import { useState, type CSSProperties, type InputHTMLAttributes } from "react"; import { motion, useReducedMotion } from "motion/react"; type ToggleCraftProps = Omit, "type" | "checked" | "defaultChecked" | "onChange" | "className"> & { /** Text next to the switch. */ label: string; /** Small text under the label. */ hint?: string; /** On or off (controlled). */ checked?: boolean; /** On or off at start (uncontrolled). */ defaultChecked?: boolean; /** Called with the new state. */ onChange?: (checked: boolean) => void; /** Colour of the on state. */ accent?: string; /** Wrapper look (width etc.). */ className?: string; }; /* ToggleCraft: a switch built on a real checkbox. The knob stretches while pressed like a soft bead, then springs across while colour spreads out from under it. */ export function ToggleCraft({ label, hint, checked, defaultChecked = false, onChange, accent = "#a78bfa", className = "w-full max-w-xs", ...rest }: ToggleCraftProps) { const reduce = useReducedMotion(); const [inner, setInner] = useState(defaultChecked); const [pressed, setPressed] = useState(false); const on = checked ?? inner; const stretch = pressed && !reduce ? 6 : 0; const spring = reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 520, damping: 30 }; return ( ); }