This repository was archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathCheckbox.tsx
46 lines (43 loc) · 1.42 KB
/
Checkbox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { useId } from "react";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import * as LabelPrimitive from "@radix-ui/react-label";
import CheckIcon from "@site/static/img/CheckIcon";
import { cn } from "@site/lib/utils";
type Props = React.ComponentProps<typeof CheckboxPrimitive.Root> & {
label?: string | React.ReactNode;
};
const Checkbox = ({ className, label, ...props }: Props) => {
const id = useId();
return (
<div className="flex items-start">
<CheckboxPrimitive.Root
id={id}
className={cn(
"flex size-twist-core-spacing-5 items-center justify-center",
"relative border-[2px] border-solid border-black focus:outline-none focus-visible:ring focus-visible:ring-black focus-visible:ring-opacity-75",
className,
{
"mt-1.5": typeof label === "object",
},
)}
{...props}
>
<CheckboxPrimitive.Indicator className="absolute inset-0 grid place-items-center bg-black">
<CheckIcon />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
{label && (
<LabelPrimitive.Label
htmlFor={id}
className={cn("select-none", {
"p ml-3 text-sm font-medium text-gray-900":
typeof label === "string",
})}
>
{label}
</LabelPrimitive.Label>
)}
</div>
);
};
export default Checkbox;