import React, { useState } from 'react'; import { States } from '../../utilities'; import { ControlLink } from '..'; import { Text } from '../Text'; import { Popover, PopoverProps } from './Popover'; export default { title: 'Components/Popover' }; const LOREM = 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto, inventore provident distinctio delectus debitis quasi modi adipisci unde esse corrupti molestiae eveniet iste ea illo ad sit fugit officiis explicabo!'; const Content = (
{LOREM}
); export const Default = () => (
> states={[ {}, { autoPreview: true }, { smoothTransitioning: true }, { anchor: 'topCenter' }, { anchor: 'topRight' }, { autoPreview: true, smoothTransitioning: true }, { anchor: 'bottomLeft' }, { anchor: 'bottomCenter' }, { anchor: 'bottomRight' }, { open: true } ]} > Hover on Link
); /** * ## Accessibility * * The Popover component supports several accessibility props to make it usable * with screen readers and keyboard navigation. **Consumers are responsible for * adding ARIA attributes to their trigger elements.** * * ### Available Props * * | Prop | Type | Description | * |------|------|-------------| * | `role` | `'tooltip' \| 'dialog' \| 'menu' \| 'listbox'` | Semantic role for the popover content | * | `aria-label` | `string` | Accessible label for the popover | * | `aria-labelledby` | `string` | ID of element that labels the popover | * | `popoverId` | `string` | ID for the content - use in trigger's `aria-controls` or `aria-describedby` | * | `openOnFocus` | `boolean` | Open popover when trigger receives focus | * | `closeOnEscape` | `boolean` | Close on Escape key (default: true) | * | `onClose` | `() => void` | Callback when user attempts to close (Escape key). Required for controlled popovers. | * | `autoFocus` | `boolean` | Automatically focus the popover content when opened | * * ### Trigger ARIA Attributes (Consumer Responsibility) * * For **dialogs/menus**, add to your trigger: * - `aria-expanded={isOpen}` * - `aria-haspopup="dialog"` (or "menu", "listbox") * - `aria-controls={popoverId}` (when open) * * For **tooltips**, add to your trigger: * - `aria-describedby={popoverId}` (when open) */ export const AccessibilityTooltip = () => (
Hover or focus the button to see a tooltip. Press Escape to dismiss.

This is the estimated total you'll pay at checkout, including taxes and shipping.
} > ); AccessibilityTooltip.storyName = 'Accessibility: Tooltip'; /** * For controlled popovers like dialogs or menus, you manage the open state * and add the appropriate ARIA attributes to your trigger. * * Use `onClose` to handle dismiss actions (like Escape key) for controlled popovers. * Use `autoFocus` to move focus into the dialog when it opens. */ export const AccessibilityDialog = () => { const [open, setOpen] = useState(false); return (
Click the button to open a dialog. Press Escape or click Close to dismiss.

setOpen(false)} autoFocus content={
Your Bag
2 items in your bag
} >
); }; AccessibilityDialog.storyName = 'Accessibility: Dialog'; /** * Use `openOnFocus` to make hover-triggered popovers accessible to keyboard users. * The popover opens when the trigger receives focus and closes when focus leaves. */ export const AccessibilityKeyboardNavigation = () => (
Tab to each button to see the popover open on focus.

First item info
} > Second item info
} > Third item info } > ); AccessibilityKeyboardNavigation.storyName = 'Accessibility: Keyboard Navigation';