import { action } from 'storybook/actions'; import Button from '../../Button'; import { Position } from '../../common'; import Popover from '..'; import { Meta, StoryObj } from '@storybook/react-webpack5'; import { createSandboxStory, globalScope, } from '../../../.storybook/components/sandbox/SandboxEditor'; type Story = StoryObj; const Content = () => ( <> You’ll get this rate as long as we receive your 10 EUR within the next 51 hours.
Test 1
Test 2
Test 3
); export default { component: Popover, title: 'Dialogs/Popover', args: { preferredPlacement: Position.BOTTOM, title: 'Guaranteed rate', content: , children: ( ), }, argTypes: { preferredPlacement: { control: 'select', options: [Position.TOP, Position.RIGHT, Position.BOTTOM, Position.LEFT], }, }, } satisfies Meta; export const Sandbox = createSandboxStory({ code: ` `, scope: globalScope, }); export const Basic: Story = {}; /** * While it might be easier for sighted users to associate the content * of a `Popover` with the surrounding and trigger content, it's likely * much harder for people relying on the assistive-tech. * * For that reason, the `Popover` must always have an accessible name — * if `title` prop is set, the component will use it automatically, * otherwise `aria-label` must be provided instead. * * **NB:** If both props are provided, then screen readers will prioritise * `aria-label` over `title`. */ export const WithoutVisibleTitle: Story = { args: { preferredPlacement: Position.BOTTOM, title: undefined, 'aria-label': 'Guaranteed rate', content: , children: ( ), }, } satisfies Meta; /** * The `preferredPlacement` prop indicates where the Popover should appear * relative to its trigger element. However, it is a preference, not a guarantee. * * If there isn't enough viewport space in the preferred direction, the Popover * automatically flips to an alternative placement. The fallback order is: * - `top` → tries `bottom`, then `right`, then `left` * - `bottom` → tries `top`, then `right`, then `left` * - `left` → tries `right`, then `top`, then `bottom` * - `right` → tries `left`, then `top`, then `bottom` * * For example, if you set `preferredPlacement="top"` but the trigger is near * the top of the viewport, the Popover will flip to `bottom` instead. * * Try scrolling this story so triggers are near viewport edges to see the * flip behaviour in action. */ export const PreferredPlacement: Story = { render: () => (
{([Position.TOP, Position.RIGHT, Position.BOTTOM, Position.LEFT] as const).map( (placement) => ( } > ), )}
), };