Restructure the repo into npm workspaces so the component kit publishes as its own package, like MUI and shadcn/ui: - packages/ui: @openkhalix/tansy-ui (published), with components, stories, tests, tokens and the library build - packages/brand: private logo and catalogue data shared by both apps - apps/site: the landing page - apps/docs: Storybook The package: - MIT licence (copyright OpenKhalix) - per-component ES modules and type declarations - "use client" on component modules so they import into Next.js Server Components; helpers stay server-safe - tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps without Tailwind - lucide-react 1.x, whose types compile against current React 19 types The apps resolve the package through a "source" export condition, so they hot-reload component edits, while outside users get dist/. scripts/test-package.mjs packs the package and installs the tarball into Vite + Tailwind (strict types), plain React and Next.js apps; each must build and render correctly. Gitea workflows run CI on push and publish to npm when a vX.Y.Z tag matching the package version is pushed.
205 lines
6.4 KiB
TypeScript
205 lines
6.4 KiB
TypeScript
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>
|
||
)
|
||
},
|
||
}
|