Radio component
Installation
npx shadcn@latest add @caprice/radionpm install @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactAdd a cn helper
import { defineConfig, type VariantProps } from 'cva';import { twMerge } from 'tailwind-merge';export const { compose, cva, cx: cn,} = defineConfig({ hooks: { onComplete: (className: string) => twMerge(className), },});export type { VariantProps };Copy and paste the following code into your project.
import { Radio as RadioPrimitive } from '@base-ui/react/radio';import { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';import { cn } from '@/lib/utils';/** * Provides a shared state to a series of radio buttons. * Renders a `<div>` element. * * Documentation: [Caprice UI Radio](https://caprice-ui.com/docs/components/radio) * * API Reference: [Base UI Radio](https://base-ui.com/react/components/radio#radiogroup) */export namespace Group { export type State = RadioGroupPrimitive.State; export type Props = React.ComponentProps<typeof RadioGroupPrimitive>; export type ChangeEventDetails = RadioGroupPrimitive.ChangeEventDetails; export type ChangeEventReason = RadioGroupPrimitive.ChangeEventReason;}export function Group({ ...props }: Group.Props) { return <RadioGroupPrimitive data-slot="radio-group" {...props} />;}/** * Represents the radio button itself. * Renders a `<span>` element and a hidden `<input>` beside. * * Documentation: [Caprice UI Radio](https://caprice-ui.com/docs/components/radio) * * API Reference: [Base UI Radio](https://base-ui.com/react/components/radio#root) */export namespace Item { export type State = RadioPrimitive.Root.State; export type Props = React.ComponentProps<typeof RadioPrimitive.Root>;}export function Item({ className, ...props }: Item.Props) { return ( <RadioPrimitive.Root className={cn('', className)} data-slot="radio" {...props}> <RadioPrimitive.Indicator className="" data-slot="radio-indicator" /> </RadioPrimitive.Root> );}Update the import paths to match your project setup.
Usage
import * as Radio from "@/components/caprice-ui/radio"import * as Radio from "@caprice-ui/react/radio"