checkbox.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. "use client"
  2. import * as React from "react"
  3. import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
  4. import { Check, Minus } from "lucide-react"
  5. import { cn } from "@/lib/utils"
  6. const Checkbox = React.forwardRef<
  7. React.ElementRef<typeof CheckboxPrimitive.Root>,
  8. React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & { indeterminate?: boolean }
  9. >(({ className, indeterminate, checked, ...props }, ref) => (
  10. <CheckboxPrimitive.Root
  11. ref={ref}
  12. className={cn(
  13. "grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-input focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:border-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:text-primary-foreground",
  14. className
  15. )}
  16. checked={indeterminate ? 'indeterminate' : checked}
  17. {...props}
  18. >
  19. <CheckboxPrimitive.Indicator
  20. className={cn("grid place-content-center text-current")}
  21. >
  22. {indeterminate ? <Minus className="h-3.5 w-3.5" /> : <Check className="h-4 w-4" />}
  23. </CheckboxPrimitive.Indicator>
  24. </CheckboxPrimitive.Root>
  25. ))
  26. Checkbox.displayName = CheckboxPrimitive.Root.displayName
  27. export { Checkbox }