import type { Meta, StoryObj } from '@storybook/web-components-vite'; import { html } from 'lit'; import './index.ts'; import type { USAPagination } from './usa-pagination.js'; const meta: Meta = { title: 'Navigation/Pagination', component: 'usa-pagination', parameters: { layout: 'padded', docs: { description: { component: ` # USA Pagination The Pagination component enables users to navigate through large datasets by breaking content into manageable pages. Essential for data display, search results, and document management systems. ## Applications - **Search Results**: Navigate content, policies, and records - **Data Tables**: Browse large datasets (budgets, contracts, employees) - **Document Libraries**: Access forms, reports, and publications - **Comments**: Review submissions and public feedback - **Case Management**: Navigate documents and records ## Accessibility Guidelines - Provides clear navigation structure with ARIA labels - Supports keyboard navigation and screen readers - Indicates current page clearly for all users - Meets WCAG 2.1 AA standards `, }, }, }, argTypes: { currentPage: { control: { type: 'number', min: 1 }, description: 'Currently active page number', }, totalPages: { control: { type: 'number', min: 1, max: 100 }, description: 'Total number of pages available', }, maxVisible: { control: { type: 'number', min: 3, max: 15 }, description: 'Maximum number of page buttons to display', }, ariaLabel: { control: 'text', description: 'ARIA label for the navigation landmark', }, }, args: { currentPage: 1, totalPages: 10, maxVisible: 7, ariaLabel: 'Pagination', }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { currentPage: 1, totalPages: 10, }, render: (args) => html` `, }; export const FewPages: Story = { name: 'Few Pages (No Ellipsis)', args: { currentPage: 2, totalPages: 5, }, render: (args) => html` `, }; export const ManyPages: Story = { name: 'Many Pages (With Ellipsis)', args: { currentPage: 10, totalPages: 50, maxVisible: 7, }, render: (args) => html` `, }; export const NearBeginning: Story = { name: 'Near Beginning', args: { currentPage: 3, totalPages: 25, maxVisible: 7, }, render: (args) => html` `, }; export const NearEnd: Story = { name: 'Near End', args: { currentPage: 23, totalPages: 25, maxVisible: 7, }, render: (args) => html` `, }; export const Compact: Story = { name: 'Compact (5 Visible)', args: { currentPage: 15, totalPages: 30, maxVisible: 5, }, render: (args) => html` `, }; export const AccessibilityDemo: Story = { parameters: { controls: { disable: true }, // Static demo - no interactive controls needed }, render: () => html`

Pagination Accessibility Compliance

This example demonstrates WCAG 2.1 AA compliance features: ARIA navigation landmarks, clear current page indication, and keyboard accessibility.

Small Dataset (All Pages Visible)

Keyboard: Tab through page links, Space/Enter to activate

{ const feedback1 = document.getElementById('a11y-feedback-1'); if (feedback1) { feedback1.innerHTML = `Navigation: Moved to page ${e.detail.page} of ${e.detail.totalPages}. Screen readers announce current page.`; } }} >
Navigation: Page 3 of 5 is current. Use Tab key to navigate between pages.

Large Dataset (With Ellipsis)

Test with screen readers: NVDA, JAWS, VoiceOver for proper announcements

{ const feedback2 = document.getElementById('a11y-feedback-2'); if (feedback2) { feedback2.innerHTML = `Navigation: Navigated to page ${e.detail.page} of ${e.detail.totalPages}. Ellipsis (...) indicates hidden pages.`; } }} >
Navigation: Page 15 of 50 is current. Ellipsis (...) indicates additional pages available.

Screen Reader Testing Guidelines

  • Navigation Landmark: Pagination is announced as a navigation region
  • Current Page: Screen readers announce "current page" for active page
  • ARIA Labels: Each page has descriptive labels (e.g., "Page 5")
  • Previous/Next: Clear labels for navigation arrows
  • Total Context: Relationship between current and total pages is clear
{ const feedback3 = document.getElementById('a11y-feedback-3'); if (feedback3) { feedback3.innerHTML = ` Screen Reader Announcement:
"Navigation region: Screen reader test pagination"
"Page ${e.detail.page} of ${e.detail.totalPages}, current page"
"Previous page link" and "Next page link" available as appropriate `; } }} >
Screen Reader Announcement:
"Navigation region: Screen reader test pagination"
"Page 2 of 8, current page"
"Previous page link" and "Next page link" available as appropriate
`, };