"use client"; import React from "react"; import { cls } from "../util"; /** * Switch geometry, one row per size: track w x h, knob k, and the knob's * off/on x-offsets. `on` is always `w - k - inset` so the knob is inset by the * same amount at both ends and vertically centred. * * This is a table rather than inline `cls({...})` conditions on purpose. The * offsets used to be computed object keys — `[value ? "translate-x-[24px]" : * "translate-x-[3px]"]: size === "large"` — and `large` and `medium` both * produced the key `translate-x-[3px]` when off. The later literal overwrote * the earlier, so the off-state class was silently dropped for `large` and the * knob sat flush against the edge. */ const SWITCH_GEOMETRY = { smallest: { track: "w-[34px] h-[18px] min-w-[34px] min-h-[18px]", knob: "w-[16px] h-[16px]", off: "translate-x-[1px]", on: "translate-x-[17px]", bar: "w-[16px] h-[6px]", barX: "translate-x-[9px]" }, small: { track: "w-[38px] h-[22px] min-w-[38px] min-h-[22px]", knob: "w-[18px] h-[18px]", off: "translate-x-[2px]", on: "translate-x-[18px]", bar: "w-[18px] h-[8px]", barX: "translate-x-[10px]" }, medium: { track: "w-[44px] h-[26px] min-w-[44px] min-h-[26px]", knob: "w-[20px] h-[20px]", off: "translate-x-[3px]", on: "translate-x-[21px]", bar: "w-[20px] h-[10px]", barX: "translate-x-[12px]" }, large: { track: "w-[48px] h-[28px] min-w-[48px] min-h-[28px]", knob: "w-[22px] h-[22px]", off: "translate-x-[3px]", on: "translate-x-[23px]", bar: "w-[22px] h-[11px]", barX: "translate-x-[13px]" } } as const; export type BooleanSwitchProps = { value: boolean | null; className?: string; disabled?: boolean; size?: "smallest" | "small" | "medium" | "large"; } & ({ allowIndeterminate: true; onValueChange?: (newValue: boolean | null) => void; } | { allowIndeterminate?: false; onValueChange?: (newValue: boolean) => void; }); export const BooleanSwitch = React.forwardRef(function BooleanSwitch({ value, allowIndeterminate, className, onValueChange, disabled = false, size = "medium", ...props }: BooleanSwitchProps, ref: React.Ref) { return ; } ) as React.ForwardRefExoticComponent>;