Command Palette

Search for a command to run...

Radio Group

A set of round buttons where you can select only one option from the group.

Installation

Follow these simple steps to add the Radio Group component to your project:

Install Dependencies

pnpm add @radix-ui/react-radio-group 

Create a new file components/ui/radio-group.tsx and copy the code below:

"use client";
 
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import * as React from "react";
 
import { cn } from "@/lib/utils";
 
function RadioGroup({
    className,
    ...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
    return (
        <RadioGroupPrimitive.Root
            data-slot="radio-group"
            className={cn("grid gap-3", className)}
            {...props}
        />
    );
}
 
function RadioGroupItem({
    className,
    ...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
    return (
        <RadioGroupPrimitive.Item
            data-slot="radio-group-item"
            className={cn(
                "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive shadow-xs aspect-square size-4 shrink-0 rounded-full border border-input outline-none transition-shadow focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
                className,
            )}
            {...props}
        >
            <RadioGroupPrimitive.Indicator className="flex items-center justify-center text-current">
                <svg
                    width="6"
                    height="6"
                    viewBox="0 0 6 6"
                    fill="currentcolor"
                    xmlns="http://www.w3.org/2000/svg"
                >
                    <circle cx="3" cy="3" r="3" />
                </svg>
            </RadioGroupPrimitive.Indicator>
        </RadioGroupPrimitive.Item>
    );
}
 
export { RadioGroup, RadioGroupItem };

Adjust the import paths in both files according to your project's structure.

Examples

Default

Description

You can use this card with a label and a description.

You can use this card with a label and a description.

Review