← full-stack-fastapi-template  /  frontend/src/components/ui/checkbox.tsx

1
import * as React from "react"
2
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
3
import { CheckIcon } from "lucide-react"
4
5
import { cn } from "@/lib/utils"
6
7
function Checkbox({
8
  className,
9
  ...props
10
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
11
  return (
12
    <CheckboxPrimitive.Root
13
      data-slot="checkbox"
14
      className={cn(
15
        "peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
16
        className
17
      )}
18
      {...props}
19
    >
20
      <CheckboxPrimitive.Indicator
21
        data-slot="checkbox-indicator"
22
        className="grid place-content-center text-current transition-none"
23
      >
24
        <CheckIcon className="size-3.5" />
25
      </CheckboxPrimitive.Indicator>
26
    </CheckboxPrimitive.Root>
27
  )
28
}
29
30
export { Checkbox }
31