import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USACard } from './usa-card.js'; const meta: Meta = { title: 'Data Display/Card', component: 'usa-card', parameters: { layout: 'padded', docs: { description: { component: ` The USA Card component provides a flexible, accessible way to display structured content using official USWDS styling. Perfect for organizing information, highlighting services, and creating engaging content layouts. **Use Cases:** - Service highlights and feature cards - Product or program information - Resource and document listings - Staff directory and contact cards - Process step indicators - News and announcement cards - Interactive content containers `, }, }, }, argTypes: { heading: { control: 'text', description: 'Card heading text', }, text: { control: 'text', description: 'Card body text content', }, mediaType: { control: 'select', options: ['none', 'image', 'video'], description: 'Type of media to display', }, mediaSrc: { control: 'text', description: 'Media source URL', }, mediaAlt: { control: 'text', description: 'Alt text for media', }, mediaPosition: { control: 'select', options: ['inset', 'exdent', 'right'], description: 'Media positioning within the card', }, flagLayout: { control: 'boolean', description: 'Use flag layout (media left, content right)', }, headerFirst: { control: 'boolean', description: 'Display header before media', }, actionable: { control: 'boolean', description: 'Make the card clickable', }, href: { control: 'text', description: 'URL for actionable cards', }, target: { control: 'select', options: ['', '_blank', '_self'], description: 'Link target for actionable cards', }, footerText: { control: 'text', description: 'Footer text content', }, headingLevel: { control: 'select', options: ['1', '2', '3', '4', '5', '6'], description: 'Heading level (h1-h6)', }, }, args: { heading: 'Card title', text: '', mediaType: 'none', mediaSrc: '', mediaAlt: '', mediaPosition: 'inset', flagLayout: false, headerFirst: false, actionable: false, href: '', target: '', footerText: '', headingLevel: '3', }, }; export default meta; type Story = StoryObj; // Basic Examples export const Default: Story = { args: { heading: 'Default Card', text: 'This is a basic card with a heading and some descriptive text content.', }, }; export const WithFooter: Story = { args: { heading: 'Card with Footer', text: 'This card includes footer text for additional information or context.', footerText: 'Updated 2 hours ago', }, }; export const ActionableCard: Story = { args: { heading: 'Clickable Card', text: 'This card is actionable - click anywhere on it to trigger the action.', actionable: true, href: '#', }, }; export const WithImage: Story = { args: { heading: 'Card with Image', text: 'This card includes an image with lazy loading and proper alt text.', mediaType: 'image', mediaSrc: 'https://picsum.photos/400/200?random=1', mediaAlt: 'Sample image', }, }; export const MediaRight: Story = { args: { heading: 'Media Right Layout', text: 'This card has media positioned on the right side with content on the left.', mediaType: 'image', mediaSrc: 'https://picsum.photos/200/150?random=2', mediaAlt: 'Sample image', mediaPosition: 'right', }, parameters: { docs: { description: { story: ` **Viewport Requirement**: Media right positioning only takes effect at tablet breakpoint and above (640px/40em). Below this breakpoint, the card will display in standard layout with media above content. To test media right positioning: 1. Ensure browser width is at least 640px 2. Use browser dev tools to test responsive breakpoints 3. Media will appear on the right side of content at desktop sizes `, }, }, }, }; export const FlagLayout: Story = { args: { heading: 'Flag Layout', text: 'Flag layout displays media on the left with content flowing alongside on the right.', mediaType: 'image', mediaSrc: 'https://picsum.photos/150/100?random=3', mediaAlt: 'Sample image', flagLayout: true, }, }; export const HeaderFirst: Story = { args: { heading: 'Header First Layout', text: 'In this layout, the header appears before the media element.', mediaType: 'image', mediaSrc: 'https://picsum.photos/400/150?random=4', mediaAlt: 'Sample image', headerFirst: true, }, }; export const DifferentHeadingLevels: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Card Heading Levels

Cards can use different heading levels for proper document structure:

`, }; // Grid layout examples export const CardGrid: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Service Cards Grid

Example of cards arranged in a responsive grid layout.

`, }; // Process steps example export const ProcessSteps: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Application Process

Step-by-step process cards for applications.

`, }; // News and updates export const NewsUpdates: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Latest News & Updates

Stay informed with the latest news, updates, and announcements.

`, }; // Accessibility features export const AccessibilityDemo: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Accessibility Features

The USA Card component meets accessibility standards and provides excellent user experience for all users.

Accessibility Features:

  • Keyboard Navigation: Full keyboard access with Tab, Enter, and Space keys
  • Screen Reader Support: Proper ARIA attributes and semantic HTML structure
  • Color Contrast: Meets minimum contrast ratio requirements
  • Focus Indicators: Clear visual focus indicators for keyboard users
  • Heading Hierarchy: Configurable heading levels (h1-h6)
  • Alt Text Support: Comprehensive alt text for all media content
  • Semantic HTML: Uses proper HTML elements and USWDS classes
  • Responsive Design: Works across all device sizes
`, }; // Interactive demo export const InteractiveDemo: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Interactive Card Demo

Demonstration of card interactions, events, and dynamic content updates.

{ console.log('Card clicked:', e.detail); // Update display with interaction info const output = document.getElementById('interaction-output'); if (output) { output.innerHTML = ` Card Interaction Detected:
Heading: ${e.detail.heading}
Href: ${e.detail.href}
Timestamp: ${new Date().toLocaleTimeString()} `; } }} footer-text="Click to trigger custom event" >

Interaction Information:

No interactions yet. Click the card above to see event details.

Testing Instructions:

  • Mouse: Click anywhere on the card
  • Keyboard: Tab to focus the card, then press Enter or Space
  • Screen Reader: Card is announced as clickable with proper context
  • Console: Open browser console to see detailed event information
`, }; // Custom content export const CustomContent: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Custom Content

Cards support custom content through slots for advanced layouts and rich media.

This card uses custom content instead of the text property.

  • Custom HTML markup
  • Rich text formatting
  • Interactive elements
  • Multiple paragraphs and lists

Benefits: Complete control over content structure and styling.

Status:

Application ID: APP-2024-001234567

Type: Service Application

Submitted: March 1, 2024

Processing Time: 5 business days

⚠️ System Notice

Scheduled maintenance window tonight from 10 PM to 2 AM EST. Some services may be temporarily unavailable.

System Administrator | Posted: Today 2:30 PM EST

`, };