checkbox.tsx 1.0 KB

12345678910111213141516171819202122232425262728
  1. import * as React from "react"
  2. import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
  3. import { CheckIcon } from "@radix-ui/react-icons"
  4. import { cn } from "@/lib/utils"
  5. const Checkbox = React.forwardRef<
  6. React.ElementRef<typeof CheckboxPrimitive.Root>,
  7. React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
  8. >(({ className, ...props }, ref) => (
  9. <CheckboxPrimitive.Root
  10. ref={ref}
  11. className={cn(
  12. "peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
  13. className
  14. )}
  15. {...props}
  16. >
  17. <CheckboxPrimitive.Indicator
  18. className={cn("flex items-center justify-center text-current")}
  19. >
  20. <CheckIcon className="h-4 w-4" />
  21. </CheckboxPrimitive.Indicator>
  22. </CheckboxPrimitive.Root>
  23. ))
  24. Checkbox.displayName = CheckboxPrimitive.Root.displayName
  25. export { Checkbox }