Files
tansy-ui/src/components/Popover.stories.tsx
T
thekhalidsha 23e67006d3 Make every component and the landing page responsive (v0.3.1)
Every story and the landing page now fit from a 320px phone to a wide
desktop without scrolling sideways.

- Inputs in flex rows (Input, FeaturedInput, NumberInput, Combobox) shrink
  instead of holding their native width
- Tab rows and ToggleGroup scroll within themselves on narrow screens;
  vertical tabs stack above their panel on phones
- Positioned popups cap at Base UI's --available-width
- Landing page: tablet header no longer crowds; code sample fits at 1024px
- Storybook a11y panel skips page-level rules that can't apply to a story
- check-stories.mjs gains --width and fails on horizontal overflow; all
  423 stories pass at 320, 375, 768 and desktop widths in both modes
2026-09-28 22:47:26 +05:30

205 lines
6.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: (
<Button variant="outline" color="neutral" startIcon={<Bell aria-hidden="true" />}>
Notifications
</Button>
),
onOpenChange: fn(),
},
decorators: [
(Story) => (
<div className="flex min-h-80 items-start justify-center pt-4">
<Story />
</div>
),
],
} satisfies Meta<typeof Popover>
export default meta
type Story = StoryObj<typeof meta>
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: (
<Button variant="outline" color="neutral" startIcon={<Link2 aria-hidden="true" />}>
Share
</Button>
),
children: (
<div className="flex gap-2">
<Input aria-label="Project link" readOnly defaultValue="https://example.com/p/acme-website" className="min-w-0 flex-1" />
<Popover.Close render={<Button />}>Copy</Popover.Close>
</div>
),
},
parameters: ownFrame(),
}
export const WithForm: Story = {
args: {
defaultOpen: true,
align: 'start',
title: 'Dimensions',
description: 'Set the size of the selected layer.',
width: 300,
trigger: <IconButton variant="outline" aria-label="Layer dimensions" icon={<SlidersHorizontal />} />,
children: (
<form className="flex flex-col gap-3" onSubmit={(event) => event.preventDefault()}>
<div className="grid grid-cols-2 gap-3">
<Input label="Width" defaultValue="1280" endAddon="px" size="sm" />
<Input label="Height" defaultValue="720" endAddon="px" size="sm" />
</div>
<div className="flex justify-end gap-2">
<Popover.Close render={<Button size="sm" variant="ghost" color="neutral" />}>Cancel</Popover.Close>
<Popover.Close render={<Button size="sm" type="submit" />}>Apply</Popover.Close>
</div>
</form>
),
},
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) => (
<div className="mx-auto grid w-fit grid-cols-3 grid-rows-3 place-items-center gap-x-12 gap-y-24 py-6 sm:gap-x-56">
{POPUP_SIDES.map((side) => (
<div
key={side}
className={
{ top: 'col-start-2 row-start-1', left: 'col-start-1 row-start-2', right: 'col-start-3 row-start-2', bottom: 'col-start-2 row-start-3' }[side]
}
>
<Popover
{...args}
side={side}
arrow
width={170}
defaultOpen
title={undefined}
description={undefined}
label={`Popover on the ${side}`}
trigger={
<Button variant="outline" color="neutral">
{side}
</Button>
}
>
<p className="m-0">Placed on the {side}.</p>
</Popover>
</div>
))}
</div>
),
}
export const Alignment: Story = {
parameters: ownFrame(360),
render: (args) => (
<div className="flex w-full max-w-4xl justify-between pb-32">
{POPUP_ALIGNS.map((align) => (
<Popover
key={align}
{...args}
align={align}
defaultOpen
width={200}
title={`align="${align}"`}
description={undefined}
trigger={
<Button variant="outline" color="neutral">
{align}
</Button>
}
>
<p className="m-0 text-fg-muted">Lines up with the trigger’s {align}.</p>
</Popover>
))}
</div>
),
}
export const Controlled: Story = {
render: function Render(args) {
const [open, setOpen] = useState(false)
return (
<div className="flex items-center gap-3">
<Popover
{...args}
open={open}
onOpenChange={setOpen}
title="Schedule"
description="Publish on Monday 6 October at 9:00."
trigger={
<Button variant="outline" color="neutral" startIcon={<CalendarDays aria-hidden="true" />}>
Schedule
</Button>
}
>
<Button size="sm" onClick={() => setOpen(false)}>
Confirm
</Button>
</Popover>
<span className="text-sm text-fg-muted">open: {String(open)}</span>
</div>
)
},
}