Open History to see the last commit
1import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
2
3import { cn } from "~/lib/utils";
4
5function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
6 return (
7 <CheckboxPrimitive.Root
8 className={cn(
9 "relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[.25rem] border border-input bg-background not-dark:bg-clip-padding shadow-xs/5 outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[3px] not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:outline-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:focus-visible:aria-invalid:outline-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",
10 className,
11 )}
12 data-slot="checkbox"
13 {...props}
14 >
15 {/* Keep an inner gap in the focus outline. Explicit glyph colors resist row icon-muting rules. */}
16 <CheckboxPrimitive.Indicator
17 className="-inset-px absolute flex items-center justify-center rounded-[.25rem] text-primary-foreground data-unchecked:hidden data-checked:bg-primary data-indeterminate:text-foreground in-[[data-slot=checkbox]:focus-visible]:inset-shadow-[0_0_0_3px_var(--background)] in-[[data-slot=checkbox]:focus-visible]:outline-2 in-[[data-slot=checkbox]:focus-visible]:outline-solid in-[[data-slot=checkbox]:focus-visible]:-outline-offset-2 in-[[data-slot=checkbox]:focus-visible]:outline-inherit"
18 data-slot="checkbox-indicator"
19 render={(props, state) => (
20 <span {...props}>
21 {state.indeterminate ? (
22 <svg
23 className="size-3.5 text-current sm:size-3"
24 fill="none"
25 height="24"
26 stroke="currentColor"
27 strokeLinecap="round"
28 strokeLinejoin="round"
29 strokeWidth="3"
30 viewBox="0 0 24 24"
31 width="24"
32 xmlns="http://www.w3.org/2000/svg"
33 >
34 <path d="M5.252 12h13.496" />
35 </svg>
36 ) : (
37 <svg
38 className="size-3.5 text-current sm:size-3"
39 fill="none"
40 height="24"
41 stroke="currentColor"
42 strokeLinecap="round"
43 strokeLinejoin="round"
44 strokeWidth="3"
45 viewBox="0 0 24 24"
46 width="24"
47 xmlns="http://www.w3.org/2000/svg"
48 >
49 <path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
50 </svg>
51 )}
52 </span>
53 )}
54 />
55 </CheckboxPrimitive.Root>
56 );
57}
58
59export { Checkbox };