import { useState } from "react"; import { RadioButton } from "./index"; import { DocsPage } from "@shared/stories/DocsTemplate"; import type { Meta, StoryObj } from "@storybook/react"; const meta: Meta = { title: "Components/RadioButton", component: RadioButton, tags: ["autodocs"], parameters: { layout: "centered", docs: { page: DocsPage, description: { component: "A radio button component with support for labels, subtext, error states, and custom variants.", }, }, }, argTypes: { name: { control: { type: "text" }, description: "Radio button group name", }, value: { control: { type: "text" }, description: "Radio button value", }, checked: { control: { type: "boolean" }, description: "Whether the radio button is checked", }, label: { control: { type: "text" }, description: "Label text", }, subText: { control: { type: "text" }, description: "Subtext displayed below the label", }, variant: { control: { type: "select" }, options: ["circle"], description: "Radio button variant", }, hasError: { control: { type: "boolean" }, description: "Show error state", }, disabled: { control: { type: "boolean" }, description: "Disable the radio button", }, }, args: { name: "radio-group", value: "option1", checked: false, label: "Radio Button Label", }, }; export default meta; type Story = StoryObj; // Default radio button export const Default: Story = { args: {}, }; // Checked radio button export const Checked: Story = { args: { checked: true, label: "Checked Radio Button", }, }; // Unchecked radio button export const Unchecked: Story = { args: { checked: false, label: "Unchecked Radio Button", }, }; // With label export const WithLabel: Story = { args: { label: "Option with Label", }, }; // With subtext export const WithSubtext: Story = { args: { label: "Premium Plan", subText: "$29.99/month - Best value", }, }; // Error state export const Error: Story = { args: { label: "Radio Button with Error", hasError: true, }, }; // Disabled state export const Disabled: Story = { args: { label: "Disabled Radio Button", disabled: true, }, }; // Disabled checked export const DisabledChecked: Story = { args: { checked: true, label: "Disabled Checked Radio Button", disabled: true, }, }; // Radio group export const RadioGroup: Story = { render: () => { const [selected, setSelected] = useState("option1"); return (
setSelected("option1")} label="Basic Plan" subText="$9.99/month" /> setSelected("option2")} label="Standard Plan" subText="$19.99/month" /> setSelected("option3")} label="Premium Plan" subText="$29.99/month" />
); }, parameters: { docs: { description: { story: "Radio button group where only one option can be selected.", }, }, }, }; // With error in group export const GroupWithError: Story = { render: () => { const [selected, setSelected] = useState(); return (
setSelected( typeof val === "string" || typeof val === "number" ? String(val) : undefined ) } label="Credit Card" hasError={!selected} /> setSelected( typeof val === "string" || typeof val === "number" ? String(val) : undefined ) } label="Debit Card" hasError={!selected} /> setSelected( typeof val === "string" || typeof val === "number" ? String(val) : undefined ) } label="PayPal" hasError={!selected} /> {!selected && (

Please select a payment method

)}
); }, parameters: { docs: { description: { story: "Radio button group with error state when no option is selected.", }, }, }, }; // All variants showcase export const AllVariants: Story = { render: () => (

States

With Subtext

Error State

), parameters: { docs: { description: { story: "Showcase of all radio button variants and states.", }, }, }, };