"use client"; import * as React from "react"; import { Checkbox as KumoCheckbox, type CheckboxProps as KumoCheckboxProps } from "@cloudflare/kumo/components/checkbox"; import { cn } from "@/lib/utils"; type CheckboxProps = Omit & { checked?: boolean; defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; }; export function Checkbox({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, checked, className, defaultChecked = false, label, name, onCheckedChange, ...props }: CheckboxProps): React.ReactElement { const generatedId = React.useId().replace(/:/g, ""); const labelId = label ? `teatea-checkbox-label-${generatedId}` : undefined; const [uncontrolledChecked, setUncontrolledChecked] = React.useState(defaultChecked); const isControlled = checked !== undefined; const currentChecked = isControlled ? checked : uncontrolledChecked; return ( { const booleanValue = Boolean(nextChecked); if (!isControlled) { setUncontrolledChecked(booleanValue); } onCheckedChange?.(booleanValue); }} {...props} /> {label ? ( {label} ) : null} {name && currentChecked ? : null} ); }