An easily stylable radio button component.
Installation
npx shadcn@latest add @caprice/radiopnpm dlx shadcn@latest add @caprice/radioyarn dlx shadcn@latest add @caprice/radiobunx shadcn@latest add @caprice/radionpm install @caprice-ui/reactpnpm add @caprice-ui/reactyarn add @caprice-ui/reactbun add @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react lucide-reactbun add @base-ui/react lucide-reactAdd a cn helper
import { cn as merge } from 'cn';
import type { VariantProps } from 'cva';
import { defineConfig } from 'cva/config';
import { getSchema } from 'cva/tools';
export const { cva, cx: cn } = defineConfig({
cx: merge,
});
export type { VariantProps };
export { getSchema };
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"Examples
API Reference
Last updated on