Package Tansy UI as @openkhalix/tansy-ui in a monorepo (v0.4.0)
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.
This commit is contained in:
1 parent
23e67006d3
commit
9255b255a6
214 files changed
+1521
-389
No files matched your search
@@ -0,0 +1,150 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite'
|
||||
import { AlertTriangle, LogOut, Send, Trash2 } from 'lucide-react'
|
||||
import { fn } from 'storybook/test'
|
||||
import { AlertDialog } from './AlertDialog'
|
||||
import { Button } from './Button'
|
||||
import { ALERT_DIALOG_COLORS } from './dialog.tokens'
|
||||
|
||||
const ownFrame = (height = 520) => ({ docs: { story: { inline: false, iframeHeight: height } } })
|
||||
|
||||
const wait = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
|
||||
|
||||
const meta = {
|
||||
title: 'Overlays/AlertDialog',
|
||||
component: AlertDialog,
|
||||
tags: ['autodocs'],
|
||||
parameters: {
|
||||
docs: {
|
||||
description: {
|
||||
component:
|
||||
'Asks the user to confirm an action, on Base UI AlertDialog (`role="alertdialog"`). It doesn’t close on outside clicks and focus starts on Cancel. Use `color="danger"` for destructive actions. When `onConfirm` returns a Promise the confirm button shows a spinner, Cancel and Escape are blocked, and the dialog closes when it resolves (or stays open if it rejects).',
|
||||
},
|
||||
},
|
||||
},
|
||||
argTypes: {
|
||||
title: { control: 'text' },
|
||||
description: { control: 'text' },
|
||||
confirmLabel: { control: 'text', table: { defaultValue: { summary: 'Confirm' } } },
|
||||
cancelLabel: { control: 'text', table: { defaultValue: { summary: 'Cancel' } } },
|
||||
loadingLabel: { control: 'text' },
|
||||
color: { control: 'inline-radio', options: ALERT_DIALOG_COLORS, table: { defaultValue: { summary: 'primary' } } },
|
||||
open: { control: 'boolean' },
|
||||
defaultOpen: { control: 'boolean' },
|
||||
className: { control: 'text' },
|
||||
icon: { control: false },
|
||||
trigger: { control: false },
|
||||
children: { control: false },
|
||||
onConfirm: { control: false },
|
||||
onCancel: { control: false },
|
||||
onOpenChange: { control: false },
|
||||
},
|
||||
args: {
|
||||
title: 'Delete this project?',
|
||||
description: 'Acme Website and its 48 files will be deleted for everyone. This can’t be undone.',
|
||||
confirmLabel: 'Delete project',
|
||||
cancelLabel: 'Cancel',
|
||||
color: 'danger',
|
||||
icon: <Trash2 />,
|
||||
trigger: (
|
||||
<Button color="danger" variant="outline" startIcon={<Trash2 aria-hidden="true" />}>
|
||||
Delete project
|
||||
</Button>
|
||||
),
|
||||
onConfirm: fn(),
|
||||
onCancel: fn(),
|
||||
onOpenChange: fn(),
|
||||
},
|
||||
} satisfies Meta<typeof AlertDialog>
|
||||
|
||||
export default meta
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
export const Playground: Story = {}
|
||||
|
||||
export const Open: Story = {
|
||||
args: { defaultOpen: true },
|
||||
parameters: ownFrame(),
|
||||
}
|
||||
|
||||
export const AsyncConfirm: Story = {
|
||||
args: {
|
||||
defaultOpen: true,
|
||||
loadingLabel: 'Deleting…',
|
||||
onConfirm: fn(() => wait(2000)),
|
||||
},
|
||||
parameters: {
|
||||
...ownFrame(),
|
||||
docs: {
|
||||
...ownFrame().docs,
|
||||
description: { story: 'Press **Delete project**: the button loads for two seconds, then the dialog closes.' },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const WithoutIcon: Story = {
|
||||
args: {
|
||||
defaultOpen: true,
|
||||
icon: undefined,
|
||||
color: 'primary',
|
||||
title: 'Publish changes?',
|
||||
description: 'Your edits to the pricing page will go live for all visitors.',
|
||||
confirmLabel: 'Publish',
|
||||
cancelLabel: 'Keep editing',
|
||||
trigger: <Button startIcon={<Send aria-hidden="true" />}>Publish</Button>,
|
||||
},
|
||||
parameters: ownFrame(),
|
||||
}
|
||||
|
||||
export const Warning: Story = {
|
||||
args: {
|
||||
defaultOpen: true,
|
||||
color: 'warning',
|
||||
icon: <AlertTriangle />,
|
||||
title: 'Sign out of all devices?',
|
||||
description: 'You will need to sign in again on your phone, tablet and other computers.',
|
||||
confirmLabel: 'Sign out everywhere',
|
||||
trigger: (
|
||||
<Button variant="outline" color="neutral" startIcon={<LogOut aria-hidden="true" />}>
|
||||
Sign out everywhere
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
parameters: ownFrame(),
|
||||
}
|
||||
|
||||
export const WithDetails: Story = {
|
||||
args: {
|
||||
defaultOpen: true,
|
||||
title: 'Remove 3 members?',
|
||||
description: 'They lose access to Acme Corporation immediately.',
|
||||
confirmLabel: 'Remove members',
|
||||
children: (
|
||||
<ul className="m-0 list-disc space-y-1 pl-5 text-fg-muted">
|
||||
<li>Jane Doe (name@example.com)</li>
|
||||
<li>John Smith (john@example.com)</li>
|
||||
<li>Alex Kim (alex@example.com)</li>
|
||||
</ul>
|
||||
),
|
||||
},
|
||||
parameters: ownFrame(560),
|
||||
}
|
||||
|
||||
export const Colors: Story = {
|
||||
render: (args) => (
|
||||
<div className="flex flex-wrap gap-3">
|
||||
{ALERT_DIALOG_COLORS.map((color) => (
|
||||
<AlertDialog
|
||||
key={color}
|
||||
{...args}
|
||||
color={color}
|
||||
confirmLabel="Confirm"
|
||||
trigger={
|
||||
<Button variant="outline" color="neutral">
|
||||
{color[0].toUpperCase() + color.slice(1)}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}
|
||||
Reference in new issue
Block a user