/ src / components / ui / radio-group.tsx
radio-group.tsx
 1  import * as React from "react"
 2  import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
 3  import { Circle } from "lucide-react"
 4  
 5  import { cn } from "@/lib/utils"
 6  
 7  const RadioGroup = React.forwardRef<
 8    React.ElementRef<typeof RadioGroupPrimitive.Root>,
 9    React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
10  >(({ className, ...props }, ref) => {
11    return (
12      <RadioGroupPrimitive.Root
13        className={cn("grid gap-2", className)}
14        {...props}
15        ref={ref}
16      />
17    )
18  })
19  RadioGroup.displayName = RadioGroupPrimitive.Root.displayName
20  
21  const RadioGroupItem = React.forwardRef<
22    React.ElementRef<typeof RadioGroupPrimitive.Item>,
23    React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
24  >(({ className, children, ...props }, ref) => {
25    return (
26      <RadioGroupPrimitive.Item
27        ref={ref}
28        className={cn(
29          "aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
30          className
31        )}
32        {...props}
33      >
34        <RadioGroupPrimitive.Indicator className="flex items-center justify-center">
35          <Circle className="h-2.5 w-2.5 fill-current text-current" />
36        </RadioGroupPrimitive.Indicator>
37      </RadioGroupPrimitive.Item>
38    )
39  })
40  RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName
41  
42  export { RadioGroup, RadioGroupItem }