import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USATag } from './usa-tag.js'; const meta: Meta = { title: 'Data Display/Tag', component: 'usa-tag', parameters: { layout: 'padded', docs: { description: { component: ` The USA Tag component provides accessible, interactive labels for categorizing and organizing content using official USWDS styling. Perfect for applications requiring content classification and user interaction. `, }, }, }, argTypes: { text: { control: 'text', description: 'Text content displayed in the tag', }, big: { control: 'boolean', description: 'Apply larger tag styling', }, removable: { control: 'boolean', description: 'Make the tag removable with close button', }, value: { control: 'text', description: 'Internal value for data tracking (used in events)', }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { text: 'Sample Tag', big: false, removable: false, value: '', }, }; export const Big: Story = { args: { text: 'Large Tag', big: true, removable: false, value: '', }, }; export const Removable: Story = { args: { text: 'Removable Tag', big: false, removable: true, value: 'removable-tag', }, render: (args) => html`

Removal Status:

Click the X to remove the tag above

`, }; export const BigRemovable: Story = { args: { text: 'Large Removable', big: true, removable: true, value: 'big-removable', }, }; export const TopicCategories: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Topic Categories

Interactive Topic Tags

These tags represent different topic areas. Click the X button to remove tags and filter content. In a real application, this would update search results or content filters.
`, }; export const ServiceStatus: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Service Status

Available Services

Service Limitations

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

Emergency Response Categories

Priority Levels

Emergency Types

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

Regulatory Compliance Status

Compliant

In Progress

Needs Attention

Compliance tags help track regulatory requirements across government systems and processes.

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

User Feedback Categories

Dynamic Tag Management

Users can add feedback categories that help organizations organize and respond to input. Remove tags by clicking the X button.
`, }; export const CustomContent: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Custom Tag Content

Important Featured Priority: High Protected

Tags can contain custom HTML content including icons, formatting, and complex layouts. When using custom content, the text property is ignored.

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

Accessibility Features Demo

Accessibility Features

  • Keyboard Navigation: Tab to removable tags, Enter/Space to remove
  • Screen Reader Support: Descriptive ARIA labels on remove buttons
  • Focus Management: Clear visual focus indicators
  • Semantic HTML: Proper button elements for interactive features
  • Color Independence: Information not conveyed by color alone

Try it: Use Tab to navigate to removable tags, then press Enter or Space to remove them.

`, }; export const InteractiveDemo: Story = { args: { text: 'Interactive Tag', big: false, removable: false, value: 'interactive', }, render: (args) => html`

Interactive Tag Demo

Tag Options

Real-time Controls

Use the controls above to modify the tag properties in real-time. Changes are reflected immediately.
Status: Ready for interaction
`, }; // Shared event handler for stories function handleTagRemove(e: CustomEvent) { console.log('Tag removed:', e.detail); // Update policy removal log if it exists const policyLog = document.getElementById('policy-removal-log'); if (policyLog) { const logEntryHtml = `
Removed: ${e.detail.text} (${e.detail.value}) at ${new Date().toLocaleTimeString()}
`; policyLog.insertAdjacentHTML('beforeend', logEntryHtml); } // Show removal notification const notificationHtml = ` Removed tag: ${e.detail.text} (value: ${e.detail.value}) `; // Insert notification after the removed tag's container const container = (e.target as Element)?.parentElement; if (container) { container.insertAdjacentHTML('beforeend', notificationHtml); // Remove notification after 3 seconds const addedNotification = container.lastElementChild as HTMLElement; setTimeout(() => { addedNotification?.remove(); }, 3000); } }