"use client"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useId } from "react"; import { EASE_OUT, SPRING_PRESS } from "@/lib/ease"; import { useMessages } from "@/lib/i18n"; import { cn } from "@/lib/utils"; /** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */ export const checkboxMessages = { checked: "Selected", indeterminate: "Partially selected", }; export type CheckboxMessages = typeof checkboxMessages; const CHECK_PATH = "M5 13l4 4L19 7"; const INDETERMINATE_PATH = "M6 12h12"; export interface CheckboxProps { /** Whether the box is checked. */ checked: boolean; /** Called with the new state when the box is toggled. */ onCheckedChange: (checked: boolean) => void; /** Blocks toggling and dims the control. */ disabled?: boolean; /** Shows a dash for a partly selected group. Announced as mixed. */ indeterminate?: boolean; /** Visible text beside the box, also its accessible name. */ label?: string; /** Supporting text under the label, announced as the description rather than the name. */ description?: string; /** Classes merged onto the root label element. */ className?: string; /** Id for the checkbox button. Generated when omitted. */ id?: string; /** Accessible name when there is no visible label. */ "aria-label"?: string; /** Associates an external message (e.g. a form error) with the control. */ "aria-describedby"?: string; /** Override any built-in string. */ labels?: Partial; } export function Checkbox({ checked, onCheckedChange, disabled, indeterminate, label, description, className, id: idProp, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, labels, }: CheckboxProps) { const t = useMessages("checkbox", checkboxMessages, labels); const autoId = useId(); const id = idProp ?? autoId; const reduce = useReducedMotion(); const showMark = checked || indeterminate; const path = indeterminate ? INDETERMINATE_PATH : CHECK_PATH; const descriptionId = description ? `${id}-description` : undefined; // The wrapping