-
Notifications
You must be signed in to change notification settings - Fork 1
/
radio-group.tsx
37 lines (32 loc) · 1.46 KB
/
radio-group.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use client";
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from "react";
import { cn } from "./cn";
const RadioGroup = forwardRef<
ElementRef<typeof RadioGroupPrimitive.Root>,
ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
>(({ className, ...rest }, ref) => (
<RadioGroupPrimitive.Root className={cn("grid gap-2", className)} {...rest} ref={ref} />
));
const RadioGroupItem = forwardRef<
ElementRef<typeof RadioGroupPrimitive.Item>,
ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
>(({ className, ...rest }, ref) => (
<RadioGroupPrimitive.Item
ref={ref}
className={cn(
"aspect-square size-4 rounded-full border border-gray-300 text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 aria-checked:border-primary aria-checked:bg-primary",
className,
)}
{...rest}
>
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
<svg height="6" width="6">
<circle r="3" cx="3" cy="3" className="fill-background" />
</svg>
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
));
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
export { RadioGroup, RadioGroupItem };