(props: {
enabled: boolean;
setEnabled: (enabled: boolean) => void;
size: "sm" | "md";
sr?: string;
})
| 2 | import classNames from "classnames"; |
| 3 | |
| 4 | export default function Toggle(props: { |
| 5 | enabled: boolean; |
| 6 | setEnabled: (enabled: boolean) => void; |
| 7 | size: "sm" | "md"; |
| 8 | sr?: string; |
| 9 | }) { |
| 10 | return ( |
| 11 | <Switch |
| 12 | checked={props.enabled} |
| 13 | onChange={props.setEnabled} |
| 14 | className={classNames( |
| 15 | props.enabled ? "bg-purple-600" : "bg-gray-300", |
| 16 | "relative inline-flex flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none", |
| 17 | props.size === "sm" ? "h-5 w-9" : "h-6 w-11", |
| 18 | )} |
| 19 | > |
| 20 | {props.sr && <span className="sr-only">{props.sr}</span>} |
| 21 | <span |
| 22 | aria-hidden="true" |
| 23 | className={classNames( |
| 24 | props.enabled |
| 25 | ? props.size === "sm" |
| 26 | ? "translate-x-4" |
| 27 | : "translate-x-5" |
| 28 | : "translate-x-0", |
| 29 | "pointer-events-none inline-block transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out", |
| 30 | props.size === "sm" ? "h-4 w-4" : "h-5 w-5", |
| 31 | )} |
| 32 | /> |
| 33 | </Switch> |
| 34 | ); |
| 35 | } |
nothing calls this directly
no test coverage detected