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.
206 lines
6.9 KiB
TypeScript
206 lines
6.9 KiB
TypeScript
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
import { AtSign, Lock, Mail, Search, UserRound } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { fn } from 'storybook/test'
|
|
import { SIZES } from '../lib/styles'
|
|
import { FeaturedInput } from './FeaturedInput'
|
|
import { TEXT_FIELD_VARIANTS } from './featuredinput.tokens'
|
|
|
|
const meta = {
|
|
title: 'Forms/FeaturedInput',
|
|
component: FeaturedInput,
|
|
tags: ['autodocs'],
|
|
parameters: {
|
|
docs: {
|
|
description: {
|
|
component:
|
|
'A single-line text input whose label sits inside the box and floats up when the input is focused or filled. The float is pure CSS, so it works controlled, uncontrolled and with browser autofill. Same API as `Input`, plus a password reveal toggle (`type="password"`), `loading` and `clearable`. The label stays the accessible name; `description` and `error` are linked to the input.',
|
|
},
|
|
},
|
|
},
|
|
argTypes: {
|
|
label: { control: 'text' },
|
|
description: { control: 'text' },
|
|
error: { control: 'text' },
|
|
placeholder: { control: 'text', description: 'Shown once the label has floated, while the input is focused and empty.' },
|
|
type: { control: 'select', options: ['text', 'email', 'password', 'search', 'tel', 'url'] },
|
|
size: { control: 'inline-radio', options: SIZES, table: { defaultValue: { summary: 'md' } } },
|
|
variant: {
|
|
control: 'inline-radio',
|
|
options: TEXT_FIELD_VARIANTS,
|
|
table: { defaultValue: { summary: 'outline' } },
|
|
},
|
|
required: { control: 'boolean' },
|
|
disabled: { control: 'boolean' },
|
|
readOnly: { control: 'boolean' },
|
|
loading: { control: 'boolean' },
|
|
clearable: { control: 'boolean' },
|
|
value: { control: 'text' },
|
|
defaultValue: { control: 'text' },
|
|
name: { control: 'text' },
|
|
className: { control: 'text' },
|
|
inputClassName: { control: 'text' },
|
|
startIcon: { control: false },
|
|
endIcon: { control: false },
|
|
onValueChange: { control: false },
|
|
onChange: { control: false },
|
|
},
|
|
args: {
|
|
label: 'Work email',
|
|
type: 'email',
|
|
size: 'md',
|
|
variant: 'outline',
|
|
required: false,
|
|
disabled: false,
|
|
readOnly: false,
|
|
loading: false,
|
|
clearable: false,
|
|
onValueChange: fn(),
|
|
onChange: fn(),
|
|
},
|
|
decorators: [
|
|
(Story) => (
|
|
<div className="max-w-sm">
|
|
<Story />
|
|
</div>
|
|
),
|
|
],
|
|
} satisfies Meta<typeof FeaturedInput>
|
|
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
export const Playground: Story = {}
|
|
|
|
export const Filled: Story = {
|
|
args: { defaultValue: '[email protected]' },
|
|
}
|
|
|
|
export const WithDescription: Story = {
|
|
args: { description: 'Invoices from Acme Corporation are sent here.' },
|
|
}
|
|
|
|
export const WithError: Story = {
|
|
args: { defaultValue: 'jane.doe@', error: 'Enter a full email address, like [email protected].' },
|
|
}
|
|
|
|
export const Required: Story = {
|
|
args: { required: true, description: 'We never share your email.' },
|
|
}
|
|
|
|
export const Disabled: Story = {
|
|
args: { disabled: true, defaultValue: '[email protected]' },
|
|
}
|
|
|
|
export const ReadOnly: Story = {
|
|
args: { readOnly: true, defaultValue: '[email protected]', description: 'Managed by your identity provider.' },
|
|
}
|
|
|
|
export const Loading: Story = {
|
|
args: { label: 'Username', type: 'text', loading: true, defaultValue: 'janedoe', description: 'Checking availability…' },
|
|
}
|
|
|
|
export const Clearable: Story = {
|
|
args: { label: 'Search people', type: 'search', clearable: true, defaultValue: 'Jane Doe', startIcon: <Search /> },
|
|
}
|
|
|
|
export const Password: Story = {
|
|
args: {
|
|
label: 'Password',
|
|
type: 'password',
|
|
defaultValue: 'correct-horse-battery',
|
|
required: true,
|
|
description: 'At least 12 characters.',
|
|
autoComplete: 'current-password',
|
|
},
|
|
}
|
|
|
|
export const Variants: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-5">
|
|
{TEXT_FIELD_VARIANTS.map((variant) => (
|
|
<div key={variant} className="grid gap-3">
|
|
<FeaturedInput {...args} variant={variant} label={`${variant[0].toUpperCase()}${variant.slice(1)}, empty`} />
|
|
<FeaturedInput
|
|
{...args}
|
|
variant={variant}
|
|
label={`${variant[0].toUpperCase()}${variant.slice(1)}, filled`}
|
|
defaultValue="[email protected]"
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const Sizes: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-5">
|
|
{SIZES.map((size) => (
|
|
<div key={size} className="grid grid-cols-2 gap-3">
|
|
<FeaturedInput {...args} size={size} label={`Size ${size}`} />
|
|
<FeaturedInput {...args} size={size} label={`Size ${size}`} defaultValue="[email protected]" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const WithIcons: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-5">
|
|
<FeaturedInput {...args} label="Email" startIcon={<Mail />} />
|
|
<FeaturedInput {...args} label="Full name" type="text" startIcon={<UserRound />} defaultValue="Jane Doe" />
|
|
<FeaturedInput {...args} label="Username" type="text" endIcon={<AtSign />} defaultValue="janedoe" />
|
|
<FeaturedInput {...args} label="API key" type="password" startIcon={<Lock />} defaultValue="sk_test_4eC39HqLyjWDarjtT1" clearable />
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const AllStates: Story = {
|
|
render: (args) => (
|
|
<div className="grid gap-5">
|
|
<FeaturedInput {...args} label="Empty" />
|
|
<FeaturedInput {...args} label="Filled" defaultValue="[email protected]" />
|
|
<FeaturedInput {...args} label="Required" required />
|
|
<FeaturedInput {...args} label="Invalid" defaultValue="jane.doe@" error="Enter a full email address." />
|
|
<FeaturedInput {...args} label="Disabled" disabled defaultValue="[email protected]" />
|
|
<FeaturedInput {...args} label="Read-only" readOnly defaultValue="[email protected]" />
|
|
<FeaturedInput {...args} label="Loading" loading defaultValue="[email protected]" />
|
|
</div>
|
|
),
|
|
}
|
|
|
|
export const Uncontrolled: Story = {
|
|
args: { label: 'Company', type: 'text', defaultValue: 'Acme Corporation', clearable: true },
|
|
}
|
|
|
|
function ControlledFeaturedInput(args: Story['args']) {
|
|
const [value, setValue] = useState('Jane Doe')
|
|
return (
|
|
<div className="grid gap-2">
|
|
<FeaturedInput {...args} label="Full name" type="text" clearable
|
|
value={value}
|
|
onValueChange={(next) => {
|
|
setValue(next)
|
|
args?.onValueChange?.(next)
|
|
}}
|
|
/>
|
|
<p className="text-sm text-fg-muted">Value: {value || '(empty)'}</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export const Controlled: Story = {
|
|
render: (args) => <ControlledFeaturedInput {...args} />,
|
|
}
|
|
|
|
export const SignInForm: Story = {
|
|
render: (args) => (
|
|
<form className="grid gap-4 rounded-xl border border-border bg-surface p-5" onSubmit={(e) => e.preventDefault()}>
|
|
<FeaturedInput {...args} label="Email" type="email" autoComplete="email" required startIcon={<Mail />} />
|
|
<FeaturedInput {...args} label="Password" type="password" autoComplete="current-password" required startIcon={<Lock />} />
|
|
</form>
|
|
),
|
|
}
|