import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USATimePicker } from './usa-time-picker.js'; const meta: Meta = { title: 'Forms/Time Picker', component: 'usa-time-picker', parameters: { layout: 'padded', docs: { description: { component: ` # USA Time Picker The USA Time Picker component provides accessible time selection functionality using a combo box pattern with official USWDS styling. This component allows users to select times from a dropdown list or enter time values directly with intelligent parsing. ## Features - Combo box-style time selection with filtering - 12-hour and 24-hour time format support - Customizable time intervals (step) - Time range constraints (min/max time) - Keyboard navigation support - ARIA attributes for screen readers - Direct text input with intelligent parsing - Form validation integration ## Usage Guidelines - Use for time selection in forms and applications - Provide clear labels indicating time format expectations - Consider time range constraints for business hours - Use appropriate step intervals (15, 30, or 60 minutes) - Test keyboard accessibility for power users - Ensure proper form validation integration ## Common Applications Perfect for: - Appointment scheduling systems - Meeting room reservations - Service hour specifications - Reporting with time requirements - Event scheduling `, }, }, }, argTypes: { value: { control: 'text', description: 'Time value in 24-hour format (HH:mm)', }, label: { control: 'text', description: 'Label text for the time picker', }, hint: { control: 'text', description: 'Helper text shown below the label', }, placeholder: { control: 'text', description: 'Placeholder text for the input', }, disabled: { control: 'boolean', description: 'Whether the time picker is disabled', }, required: { control: 'boolean', description: 'Whether the time picker is required', }, minTime: { control: 'text', description: 'Minimum allowed time in 24-hour format', }, maxTime: { control: 'text', description: 'Maximum allowed time in 24-hour format', }, step: { control: 'select', options: ['5', '15', '30', '60'], description: 'Time interval in minutes', }, name: { control: 'text', description: 'Form field name', }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { label: 'Appointment time', hint: 'Select or enter a time', }, }; export const WithValue: Story = { args: { label: 'Meeting time', value: '14:30', hint: 'Pre-selected time example', }, }; export const Required: Story = { args: { label: 'Required appointment time', hint: 'This field is required', required: true, }, }; export const Disabled: Story = { args: { label: 'Disabled time picker', value: '09:00', hint: 'This time picker is disabled', disabled: true, }, }; export const BusinessHours: Story = { args: { label: 'Business hours appointment', hint: 'Available times between 9 AM and 5 PM', minTime: '09:00', maxTime: '17:00', step: '30', }, }; export const FifteenMinuteIntervals: Story = { args: { label: 'Precise scheduling', hint: '15-minute intervals for detailed scheduling', step: '15', }, }; export const HourlyIntervals: Story = { args: { label: 'Hourly appointments', hint: 'Available on the hour only', step: '60', }, }; export const ExtendedHours: Story = { args: { label: '24-hour service time', hint: 'Select any time of day', minTime: '00:00', maxTime: '23:59', step: '30', }, }; export const MorningOnly: Story = { args: { label: 'Morning appointment', hint: 'Available from 6 AM to 12 PM', minTime: '06:00', maxTime: '12:00', step: '30', }, }; export const CustomPlaceholder: Story = { args: { label: 'Enter time', placeholder: 'Select time...', hint: 'Custom placeholder example', }, }; // Common usage examples export const OfficeHours: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Office Hours Scheduling

Schedule appointments during standard business hours.

Usage Notes:

  • Standard business hours (8:00 AM - 4:30 PM)
  • 30-minute appointment slots
  • Excludes lunch hour (12:00 PM - 1:00 PM) - implement via backend logic
  • Compatible with holiday scheduling systems
`, }; export const MedicalAppointments: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Medical Center Scheduling

Schedule medical appointments at healthcare facilities.

Healthcare Scheduling:

  • Integration with medical records systems
  • Different time slots for various services
  • Compliance with healthcare regulations
  • Patient accessibility considerations
`, }; export const InteractiveDemo: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Interactive Time Picker Demo

Test time selection, formatting, and event handling with real-time feedback.

Real-time Output:

No time selected yet. Choose a time to see event details.

Testing Instructions:

  • Dropdown: Click the dropdown arrow to see available times
  • Typing: Type directly: "9am", "2:30 pm", "14:45"
  • Keyboard: Use arrow keys to navigate, Enter to select
  • Filtering: Type partial times to filter options
`, }; export const AccessibilityShowcase: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Accessibility Features Demonstration

Showcasing WCAG 2.1 AA compliance and accessibility features.

Accessibility Features:

  • Screen Reader Support: ARIA labels, roles, and properties
  • Keyboard Navigation: Arrow keys, Enter, Escape support
  • High Contrast: Compatible with high contrast themes
  • Focus Management: Clear focus indicators and logical tab order
  • Error Handling: Accessible error messages and validation
  • Labels: Proper label association and required indicators

Testing with Assistive Technology:

  • Navigate using Tab key to focus elements
  • Use arrow keys to move through time options
  • Press Enter to select highlighted time
  • Test with screen reader (NVDA, JAWS, VoiceOver)
  • Verify proper announcements for state changes
`, }; export const FormIntegration: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Form Integration

Example of time picker integration in forms with validation.

Form Output:

Submit the form to see the selected times.
`, };