import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USARadio } from './usa-radio.js'; const meta: Meta = { title: 'Forms/Radio', component: 'usa-radio', parameters: { layout: 'padded', docs: { description: { component: ` # USA Radio The USA Radio component provides accessible radio button selection using official USWDS styling. This component wraps the standard HTML radio input element with USWDS classes and accessibility features. ## Features - Default and tile variants - Optional descriptions for tile variant - Full accessibility support with ARIA attributes - Native form validation - Single selection within a group ## Usage Guidelines - Only one radio button can be selected in a group - Use vertical listing for better readability - Avoid setting default values without user research - Ensure adequate spacing for touch screens - Group related radio buttons with fieldset/legend ## Accessibility - Labels are properly associated with radio buttons - Fieldset and legend for grouped radio buttons - Required fields clearly marked - Supports keyboard navigation - Screen reader announcements for state changes ` } } }, argTypes: { label: { control: { type: 'text' }, description: 'Label text for the radio button', }, value: { control: { type: 'text' }, description: 'Radio button value', }, checked: { control: { type: 'boolean' }, description: 'Whether the radio button is checked', }, description: { control: { type: 'text' }, description: 'Description text (only shown for tile variant)', }, disabled: { control: { type: 'boolean' }, description: 'Whether the radio button is disabled', }, required: { control: { type: 'boolean' }, description: 'Whether the radio button group is required', }, tile: { control: { type: 'boolean' }, description: 'Whether to use the tile variant', }, }, args: { label: 'Radio button label', value: 'radio-value', checked: false, description: '', disabled: false, required: false, tile: false, }, }; export default meta; type Story = StoryObj; export const Default: Story = { render: (args) => html` `, }; export const Checked: Story = { args: { label: 'Selected option', checked: true, }, }; export const Disabled: Story = { args: { label: 'Disabled option', disabled: true, }, }; export const TileVariant: Story = { args: { label: 'Email notifications', description: 'Receive important updates and announcements via email.', tile: true, }, }; export const RadioGroup: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`
Select your preferred contact method
`, }; export const TileGroup: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`
Choose your subscription plan
`, }; export const FormExample: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`
{ e.preventDefault(); const form = e.target as HTMLFormElement; const formData = new FormData(form); const radioValue = Object.fromEntries(formData); console.log('Form data:', radioValue); alert('Form submitted! Check console for data.'); }} >
Delivery method
Continue
`, }; export const ValidationStates: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`
Default radio group
Disabled options
Required selection *
`, }; export const AccessibilityFeatures: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Accessibility Features Demo

This demo shows various accessibility features of the radio button component.

Accessible radio button group

Features demonstrated:

  • Labels properly associated with radio buttons
  • Fieldset and legend for grouped radio buttons
  • Required group clearly indicated
  • Keyboard navigation support (arrow keys within group)
  • Screen reader state announcements
  • Single selection enforcement within group
  • Tile descriptions for enhanced context
`, };