Files
front-ui-registry/.tooling/components/ui/checkbox.tsx

26 lines
869 B
TypeScript

import { forwardRef, type ButtonHTMLAttributes } from "react";
import { cn } from "@/lib/utils";
type CheckedState = boolean | "indeterminate";
export interface CheckboxProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "checked"> {
checked?: CheckedState;
onCheckedChange?: (checked: CheckedState) => void;
}
export const Checkbox = forwardRef<HTMLButtonElement, CheckboxProps>(
({ className, checked, onCheckedChange, ...props }, ref) => (
<button
ref={ref}
type="button"
role="checkbox"
aria-checked={checked === "indeterminate" ? "mixed" : checked}
data-state={checked === "indeterminate" ? "indeterminate" : checked ? "checked" : "unchecked"}
onClick={() => onCheckedChange?.(checked !== true)}
className={cn(className)}
{...props}
/>
)
);
Checkbox.displayName = "Checkbox";