{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "checkbox", "title": "Checkbox", "description": "A simple checkbox component", "dependencies": [ "@radix-ui/react-checkbox", "lucide-react" ], "files": [ { "path": "registry/cs/ui/checkbox/checkbox.tsx", "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CheckIcon, MinusIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** Checkbox switch color. */\nexport type CsSwitchColor = \"default\" | \"dark\" | \"green\" | \"red\" | \"blue\" | \"yellow\"\n\nconst CHECKBOX_SIZES = {\n xs: \"size-3.5\",\n sm: \"size-4\",\n md: \"size-[18px]\",\n lg: \"size-[22px]\",\n xl: \"size-[27px]\",\n}\n\nconst CHECKBOX_ICON_SIZES = {\n xs: \"size-2.5\",\n sm: \"size-3\",\n md: \"size-3.5\",\n lg: \"size-4\",\n xl: \"size-5\",\n}\n\nconst LABEL_SIZES = {\n xs: \"text-xs\",\n sm: \"text-sm\",\n md: \"text-sm\",\n lg: \"text-base\",\n xl: \"text-lg\",\n}\n\nconst colorMap: Record = {\n default: \"accent-cs-primary\",\n dark: \"accent-cs-dark\",\n green: \"accent-cs-green\",\n red: \"accent-cs-red\",\n blue: \"accent-cs-blue\",\n yellow: \"accent-cs-yellow\",\n}\n\nconst checkedBg: Record = {\n default: \"bg-cs-primary border-cs-primary\",\n dark: \"bg-cs-dark border-cs-dark\",\n green: \"bg-cs-green border-cs-green\",\n red: \"bg-cs-red border-cs-red\",\n blue: \"bg-cs-blue border-cs-blue\",\n yellow: \"bg-cs-yellow border-cs-yellow\",\n}\n\nexport interface CheckboxProps extends Omit, \"size\" | \"color\" | \"type\"> {\n /** Label text. */\n label?: string\n /** Checkbox size. */\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\"\n /** Checkbox color when checked. */\n color?: CsSwitchColor\n /** Is bold label text. */\n bold?: boolean\n /** Label position relative to checkbox. Default is \"right\". */\n labelPosition?: \"left\" | \"right\"\n /** Indeterminate state. */\n indeterminate?: boolean\n /** Callback when checked state changes. */\n onCheck?: (checked: boolean, value?: string) => void\n}\n\nconst Checkbox = React.forwardRef(\n (\n {\n className,\n label,\n size = \"md\",\n color = \"default\",\n bold = false,\n labelPosition = \"right\",\n indeterminate = false,\n checked,\n defaultChecked,\n disabled,\n onChange,\n onCheck,\n id: idProp,\n ...props\n },\n ref\n ) => {\n const autoId = React.useId()\n const id = idProp ?? autoId\n const innerRef = React.useRef(null)\n const combinedRef = (node: HTMLInputElement | null) => {\n (innerRef as React.MutableRefObject).current = node\n if (typeof ref === \"function\") ref(node)\n else if (ref) (ref as React.MutableRefObject).current = node\n }\n\n React.useEffect(() => {\n if (innerRef.current) {\n innerRef.current.indeterminate = indeterminate\n }\n }, [indeterminate])\n\n const [isChecked, setIsChecked] = React.useState(defaultChecked ?? false)\n const controlledChecked = checked !== undefined ? checked : isChecked\n\n const handleChange = (e: React.ChangeEvent) => {\n if (checked === undefined) setIsChecked(e.currentTarget.checked)\n onChange?.(e)\n onCheck?.(e.currentTarget.checked, e.currentTarget.value)\n }\n\n return (\n \n \n \n {controlledChecked && !indeterminate && (\n \n )}\n {indeterminate && (\n \n )}\n \n {label && (\n \n {label}\n \n )}\n \n )\n }\n)\nCheckbox.displayName = \"Checkbox\"\n\nexport { Checkbox, CHECKBOX_SIZES }\n", "type": "registry:ui" } ], "type": "registry:ui" }