1 "use client"
2
3 import { CheckMini, MinusMini } from "@medusajs/icons"
4 import { Checkbox as RadixCheckbox } from "radix-ui"
5 import * as React from "react"
6
7 import { clx } from "@/utils/clx"
8 import { CheckboxCheckedState } from "./types"
9
10 /**
11 * This component is based on the [Radix UI Checkbox](https://www.radix-ui.com/primitives/docs/components/checkbox) primitive.
12 */
13 const Checkbox = React.forwardRef<
14 React.ElementRef<typeof RadixCheckbox.Root>,
15 React.ComponentPropsWithoutRef<typeof RadixCheckbox.Root> & {
16 checked?: CheckboxCheckedState | undefined
17 }
18 >(({ className, checked, ...props }, ref) => {
19 return (
20 <RadixCheckbox.Root
21 {...props}
22 ref={ref}
23 checked={checked}
24 className={clx(
25 "group inline-flex h-5 w-5 items-center justify-center outline-none ",
26 className
27 )}
28 >
29 <div
30 className={clx(
31 "text-ui-fg-on-inverted bg-ui-bg-base shadow-borders-base [&_path]:shadow-details-contrast-on-bg-interactive transition-fg h-[15px] w-[15px] rounded-[3px]",
32 "group-disabled:cursor-not-allowed group-disabled:opacity-50",
33 "group-focus-visible:!shadow-borders-interactive-with-focus",
34 "group-hover:group-enabled:group-data-[state=unchecked]:bg-ui-bg-base-hover",
35 "group-data-[state=checked]:bg-ui-bg-interactive group-data-[state=checked]:shadow-borders-interactive-with-shadow",
36 "group-data-[state=indeterminate]:bg-ui-bg-interactive group-data-[state=indeterminate]:shadow-borders-interactive-with-shadow"
37 )}
38 >
39 <RadixCheckbox.Indicator>
40 {checked === "indeterminate" ? <MinusMini /> : <CheckMini />}
41 </RadixCheckbox.Indicator>
42 </div>
43 </RadixCheckbox.Root>
44 )
45 })
46 Checkbox.displayName = "Checkbox"
47
48 export { Checkbox }