import type { Meta, StoryObj } from '@storybook/react-vite' import { Bell, CalendarDays, Link2, SlidersHorizontal } from 'lucide-react' import { useState } from 'react' import { fn } from 'storybook/test' import { Button, IconButton } from './Button' import { Input } from './Input' import { Popover } from './Popover' import { POPUP_ALIGNS, POPUP_SIDES } from './popover.tokens' const ownFrame = (height = 420) => ({ docs: { story: { inline: false, iframeHeight: height } } }) const meta = { title: 'Overlays/Popover', component: Popover, tags: ['autodocs'], parameters: { docs: { description: { component: 'Interactive content anchored to a trigger, on Base UI Popover. Opens on click, flips to stay on screen, and closes on Escape or an outside click with focus returning to the trigger. Use it for small forms, filters and details; for short non-interactive hints use Tooltip.', }, }, }, argTypes: { title: { control: 'text' }, description: { control: 'text' }, label: { control: 'text' }, side: { control: 'inline-radio', options: POPUP_SIDES, table: { defaultValue: { summary: 'bottom' } } }, align: { control: 'inline-radio', options: POPUP_ALIGNS, table: { defaultValue: { summary: 'center' } } }, sideOffset: { control: { type: 'number', min: 0, max: 32 }, table: { defaultValue: { summary: '8' } } }, arrow: { control: 'boolean' }, width: { control: 'number', table: { defaultValue: { summary: '320' } } }, open: { control: 'boolean' }, defaultOpen: { control: 'boolean' }, modal: { control: 'boolean' }, className: { control: 'text' }, trigger: { control: false }, children: { control: false }, onOpenChange: { control: false }, }, args: { title: 'Notifications', description: 'You’re all caught up.', side: 'bottom', align: 'center', sideOffset: 8, arrow: false, width: 320, trigger: ( ), onOpenChange: fn(), }, decorators: [ (Story) => (
), ], } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const Open: Story = { args: { defaultOpen: true, arrow: true, width: 380, title: 'Share link', description: 'Anyone at Acme Corporation with the link can view this project.', trigger: ( ), children: (
}>Copy
), }, parameters: ownFrame(), } export const WithForm: Story = { args: { defaultOpen: true, align: 'start', title: 'Dimensions', description: 'Set the size of the selected layer.', width: 300, trigger: } />, children: (
event.preventDefault()}>
}>Cancel }>Apply
), }, parameters: ownFrame(), } export const Sides: Story = { parameters: { ...ownFrame(460), docs: { ...ownFrame(460).docs, description: { story: 'Each side, open. A popover flips when the preferred side has no room.' } }, }, render: (args) => (
{POPUP_SIDES.map((side) => (
{side} } >

Placed on the {side}.

))}
), } export const Alignment: Story = { parameters: ownFrame(360), render: (args) => (
{POPUP_ALIGNS.map((align) => ( {align} } >

Lines up with the trigger’s {align}.

))}
), } export const Controlled: Story = { render: function Render(args) { const [open, setOpen] = useState(false) return (
open: {String(open)}
) }, }