'use client'; import { useState } from 'react'; import { CreditCardIcon, PlaneIcon, SmartphoneIcon, TruckIcon, } from 'lucide-react'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { Label } from '@kit/ui/label'; import { RadioGroup, RadioGroupItem, RadioGroupItemLabel, } from '@kit/ui/radio-group'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@kit/ui/select'; import { Switch } from '@kit/ui/switch'; import { generateImportStatement, generatePropsString, useStoryControls, } from '../lib/story-utils'; import { ComponentStoryLayout } from './story-layout'; interface RadioGroupStoryControls { orientation: 'vertical' | 'horizontal'; disabled: boolean; useLabels: boolean; showValue: boolean; size: 'sm' | 'md' | 'lg'; } const paymentMethods = [ { value: 'card', label: 'Credit Card', icon: CreditCardIcon, description: 'Pay with your credit or debit card', }, { value: 'bank', label: 'Bank Transfer', icon: CreditCardIcon, description: 'Direct bank transfer', }, { value: 'mobile', label: 'Mobile Payment', icon: SmartphoneIcon, description: 'Pay with mobile wallet', }, ]; const shippingOptions = [ { value: 'standard', label: 'Standard Shipping', icon: TruckIcon, description: '5-7 business days', price: 'Free', }, { value: 'express', label: 'Express Shipping', icon: TruckIcon, description: '2-3 business days', price: '$9.99', }, { value: 'overnight', label: 'Overnight Shipping', icon: PlaneIcon, description: '1 business day', price: '$19.99', }, ]; export default function RadioGroupStory() { const { controls, updateControl } = useStoryControls( { orientation: 'vertical', disabled: false, useLabels: false, showValue: true, size: 'md', }, ); const [selectedValue, setSelectedValue] = useState(''); const generateCode = () => { const propsString = generatePropsString( { value: selectedValue || 'option1', onValueChange: 'setValue', disabled: controls.disabled, className: controls.orientation === 'horizontal' ? 'flex gap-4' : 'space-y-2', }, { disabled: false, }, ); const imports = generateImportStatement( controls.useLabels ? ['RadioGroup', 'RadioGroupItem', 'RadioGroupItemLabel'] : ['RadioGroup', 'RadioGroupItem'], '@kit/ui/radio-group', ); const labelImport = controls.useLabels ? '' : `\nimport { Label } from '@kit/ui/label';`; const itemsCode = controls.useLabels ? ` {paymentMethods.map((method) => (

{method.label}

{method.description}

))}` : `
`; return `${imports}${labelImport}\n\nfunction PaymentForm() {\n const [selectedValue, setSelectedValue] = useState('${selectedValue || 'option1'}');\n\n return (\n \n${itemsCode}\n \n );\n}`; }; const sizeClasses = { sm: 'h-3 w-3', md: 'h-4 w-4', lg: 'h-5 w-5', }; const controlsContent = ( Radio Group Controls
updateControl('disabled', checked)} />
updateControl('useLabels', checked)} />
updateControl('showValue', checked)} />
{controls.showValue && selectedValue && (

Selected Value:

{selectedValue}

)}
); const previewContent = ( Radio Group Preview
{controls.useLabels ? paymentMethods.slice(0, 3).map((method) => (

{method.label}

{method.description}

)) : ['Option 1', 'Option 2', 'Option 3'].map((option, index) => (
))}
); return (

Basic Radio Groups

Simple Options
Horizontal Layout

Payment Method Selection

Choose Payment Method {paymentMethods.map((method) => (

{method.label}

{method.description}

))}

Shipping Options

Select Shipping Method {shippingOptions.map((option) => (

{option.label}

{option.description}

{option.price}

))}

Settings Form

Notification Preferences
} apiReference={

Radio Group Components

Component Props Description
RadioGroup value, onValueChange, disabled, name Root radio group container
RadioGroupItem value, disabled, id Individual radio button
RadioGroupItemLabel selected, className Enhanced label with styling

RadioGroup Props

Prop Type Default Description
value string - Currently selected value
onValueChange (value: string) ={'>'} void - Callback when selection changes
defaultValue string - Default selected value
disabled boolean false Disable the entire group
name string - HTML name attribute for form submission
required boolean false Mark as required field
dir 'ltr' | 'rtl' 'ltr' Text direction for internationalization
loop boolean true Whether keyboard navigation should loop

RadioGroupItem Props

Prop Type Default Description
value string - Value when this item is selected
disabled boolean false Disable this specific item
id string - HTML id for label association

Layout Options

Layout Patterns

Vertical (default) Horizontal Grid layout Enhanced labels
                  {`// Vertical (default)


// Horizontal


// Grid


// Enhanced labels

  
  
Enhanced content
`}
} usageGuidelines={

Basic Usage

Radio groups allow users to select a single option from a list of mutually exclusive choices.

                {`import { RadioGroup, RadioGroupItem } from '@kit/ui/radio-group';
import { Label } from '@kit/ui/label';

function PaymentForm() {
  const [paymentMethod, setPaymentMethod] = useState('card');

  return (
    
      
); }`}

Form Integration

                {`import { useForm } from 'react-hook-form';

function SettingsForm() {
  const form = useForm();

  return (
    
( Theme Preference Light Dark System )} /> ); }`}

Enhanced Labels

                {`import { RadioGroupItemLabel } from '@kit/ui/radio-group';


  {options.map((option) => (
    
      
      

{option.label}

{option.description}

))}
`}

Best Practices

Selection Guidelines

• Use radio groups for mutually exclusive choices (2-7 options)

• For single true/false choices, consider using a checkbox or switch

• For many options (8+), consider using a select dropdown

• Always provide a default selection when appropriate

Layout and Design

• Use vertical layout for better scannability

• Group related options together

• Provide clear, descriptive labels

• Consider using enhanced labels for complex options

Accessibility

• Always associate labels with radio buttons using htmlFor/id

• Use fieldset and legend for grouped options

• Ensure sufficient color contrast

• Test with keyboard navigation and screen readers

} /> ); } export { RadioGroupStory };