import type { Meta, StoryObj } from '@storybook/react-vite'
import { useState } from 'react'
import { fn } from 'storybook/test'
import { Button } from './Button'
import { Field } from './Field'
import { Form } from './Form'
import { TextInput } from './TextInput'
import { Textarea } from './Textarea'
const meta = {
title: 'Inputs/Form',
component: Form,
parameters: { layout: 'padded' },
args: { onSubmit: fn(), busy: false, 'aria-label': 'Example', children: null },
argTypes: { children: { control: false }, onSubmit: { control: false } },
decorators: [(Story) =>
],
} satisfies Meta
export default meta
type Story = StoryObj
const fields = (error?: string) => (
<>
>
)
/** A list of fields: the form stacks them 24px apart itself. */
export const Default: Story = { render: (args) => }
/** Sending: every field and button inside is switched off at once. */
export const Busy: Story = { args: { busy: true }, render: (args) => }
/** A field showing its error. The form does not send while it shows. */
export const WithError: Story = { render: (args) => }
/**
* **`layout="free"`**: a form that is not a list of fields, here a field and
* its button, places nothing, and lays itself out through `className`.
*/
export const Free: Story = {
args: { layout: 'free', className: 'flex items-center gap-2' },
render: (args) => (
),
}
/**
* Live. Press Enter in the first field, or Send: the form is busy for a
* second and a half, and focus comes back to where it was.
*/
export const WhileSending: Story = {
parameters: { controls: { disable: true } },
render: (args) => {
const [busy, setBusy] = useState(false)
return (
)
},
}