import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import '../icon/index.ts'; import type { USATooltip } from './usa-tooltip.js'; const meta: Meta = { title: 'Feedback/Tooltip', component: 'usa-tooltip', parameters: { layout: 'padded', // Improve tooltip positioning in Storybook iframe viewport: { defaultViewport: 'large', }, backgrounds: { default: 'light', }, docs: { description: { component: ` # USA Tooltip The USA Tooltip component uses official USWDS styling and behavior. This component provides contextual help text that appears on hover and focus, following USWDS patterns. ## Usage Guidelines - Follow USWDS design system guidelines - Component uses official USWDS CSS classes - Accessibility features are built-in - Supports four positions: top, bottom, left, right - Triggers on mouseover and focus events ## Events - \`tooltip-show\` - Dispatched when tooltip is shown - \`tooltip-hide\` - Dispatched when tooltip is hidden ## Accessibility - Uses proper ARIA roles and attributes (tooltip, aria-describedby) - Keyboard navigation support (Escape to close) - Screen reader compatible - Focus management for keyboard users - Follows USWDS accessibility patterns `, }, }, }, argTypes: { text: { control: { type: 'text' }, description: 'Tooltip text content', }, position: { control: { type: 'select' }, options: ['top', 'bottom', 'left', 'right'], description: 'Position of the tooltip relative to the trigger element', }, }, args: { text: 'This is a helpful tooltip', position: 'top', }, }; export default meta; type Story = StoryObj; export const Default: Story = { render: (args) => html`
`, }; export const OnLink: Story = { args: { text: 'This link opens in a new window', position: 'top', }, render: (args) => html`

Visit our documentation site for more information.

`, }; export const OnIconButton: Story = { args: { text: 'Get help with this form', position: 'right', }, render: (args) => html`
`, }; export const TopPosition: Story = { args: { text: 'This tooltip appears above the trigger', position: 'top', }, render: (args) => html`
`, }; export const BottomPosition: Story = { args: { text: 'This tooltip appears below the trigger', position: 'bottom', }, render: (args) => html`
`, }; export const LeftPosition: Story = { args: { text: 'This tooltip appears to the left', position: 'left', }, render: (args) => html`
`, }; export const RightPosition: Story = { args: { text: 'This tooltip appears to the right', position: 'right', }, render: (args) => html`
`, }; export const WithUtilityClass: Story = { args: { text: 'This tooltip has additional styling classes', position: 'top', }, render: (args) => html` `, }; export const OnInput: Story = { args: { text: 'This tooltip appears when the input receives focus or hover', position: 'top', }, render: (args) => html` `, }; export const LongText: Story = { args: { text: 'This is a much longer tooltip text that demonstrates how tooltips handle longer content. It provides detailed information that might be helpful to users but would clutter the interface if always visible.', position: 'top', }, render: (args) => html` `, }; export const MultipleTooltips: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`
`, }; export const FormHelp: Story = { args: { text: 'Your tax ID is used to verify your identity and eligibility. This information is protected under privacy policies.', position: 'right', }, render: (args) => html`
`, }; export const AccessLevelInfo: Story = { args: { text: 'Access level determines permissions to system resources. Contact your administrator for access updates.', position: 'bottom', }, render: (args) => html`

Personnel Information

Access Level: Standard ℹ️ More info
`, }; export const BudgetAllocationHelp: Story = { args: { text: 'Budget allocations must align with approved spending categories. Transfers between categories require supervisor approval.', position: 'top', }, render: (args) => html`

2024 Budget Allocation

Personnel: $2,500,000
Operations: $750,000
Equipment: $1,200,000
Travel: $150,000
`, }; export const AccessibilityHelp: Story = { args: { text: 'This form meets WCAG accessibility standards. Use Tab to navigate, Enter to activate controls, and Escape to close dialogs.', position: 'top', }, render: (args) => html`

Accessible Form

All form controls are keyboard accessible and screen reader compatible.

`, }; export const DataPrivacyNotice: Story = { args: { text: 'Personal information is collected to process your application and may be used as permitted by applicable privacy laws.', position: 'right', }, render: (args) => html`
🔒
Privacy Notice

Your personal information is protected under privacy laws.

`, }; export const EmergencyContactInfo: Story = { args: { text: 'Emergency contact information is used only in case of workplace emergencies or critical situations. Contact HR to update this information.', position: 'bottom', }, render: (args) => html`
Emergency Contact Information
`, }; export const CustomContent: Story = { parameters: { controls: { disable: true }, docs: { description: { story: 'Demonstrates using the default slot for custom content.', }, }, }, render: () => html`

This is custom slotted content.

Slots allow you to provide your own HTML content to the component.

`, };