Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

checkbox.tsx

61 lines3.0 KB

1"use client";
2​
3import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
4​
5import { cn } from "~/lib/utils";
6​
7function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
8 return (
9 <CheckboxPrimitive.Root
10 className={cn(
11 "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",
12 className,
13 )}
14 data-slot="checkbox"
15 {...props}
16 >
17 {/* Leave a contrasting inner gap inside the 2px focus outline. */}
18 <CheckboxPrimitive.Indicator
19 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"
20 data-slot="checkbox-indicator"
21 render={(props, state) => (
22 <span {...props}>
23 {state.indeterminate ? (
24 <svg
25 className="size-3.5 sm:size-3"
26 fill="none"
27 height="24"
28 stroke="currentColor"
29 strokeLinecap="round"
30 strokeLinejoin="round"
31 strokeWidth="3"
32 viewBox="0 0 24 24"
33 width="24"
34 xmlns="http://www.w3.org/2000/svg"
35 >
36 <path d="M5.252 12h13.496" />
37 </svg>
38 ) : (
39 <svg
40 className="size-3.5 sm:size-3"
41 fill="none"
42 height="24"
43 stroke="currentColor"
44 strokeLinecap="round"
45 strokeLinejoin="round"
46 strokeWidth="3"
47 viewBox="0 0 24 24"
48 width="24"
49 xmlns="http://www.w3.org/2000/svg"
50 >
51 <path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
52 </svg>
53 )}
54 </span>
55 )}
56 />
57 </CheckboxPrimitive.Root>
58 );
60​
61export { Checkbox };