260703_01_FST: First Commit
This commit is contained in:
25
.tooling/components/ui/checkbox.tsx
Normal file
25
.tooling/components/ui/checkbox.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
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";
|
||||
Reference in New Issue
Block a user