-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Checkbox.tsx
33 lines (28 loc) · 1.34 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
import * as React from "react"
import { RxCheck } from "react-icons/rx"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { cn } from "@/lib/utils/cn"
/**
* Common style classes for the checkbox, radio, and switch controls
*/
export const commonControlClasses =
"size-4 border border-body-medium text-background hover:border-primary-high-contrast hover:bg-body-light focus-visible:outline-offset-4 focus-visible:outline-primary-hover disabled:cursor-not-allowed disabled:border-disabled disabled:bg-disabled aria-[invalid]:border-error aria-[invalid]:bg-error-light data-[state='checked']:not-disabled:border-primary data-[state='checked']:not-disabled:bg-primary data-[state='checked']:hover:not-disabled:bg-primary-hover"
export type CheckboxProps = React.ComponentPropsWithoutRef<
typeof CheckboxPrimitive.Root
>
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
CheckboxProps
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(commonControlClasses, "rounded-sm", className)}
{...props}
>
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
<RxCheck className="text-sm" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName
export default Checkbox