import type { Meta, StoryObj } from 'storybook-solidjs-vite'; import { fn } from 'storybook/test'; import { createSignal, For } from 'solid-js'; import { FileUpload, FileUploadTrigger, FileUploadContent } from './file-upload'; import { Upload } from 'lucide-solid'; import { componentDescription } from '../stories/docs/element-controls'; const meta = { title: 'Solid (Advanced)/Elements/FileUpload', component: FileUpload, tags: ['autodocs'], parameters: { layout: 'padded', docs: { controls: { exclude: ['use:eventListener'] }, description: componentDescription([ 'A headless file-upload root that handles window-wide drag-and-drop plus a hidden file input, composed with `FileUploadTrigger` (opens the picker) and `FileUploadContent` (full-screen drop overlay).', '**When to use:** to let users attach files to a chat — via a button click or by dragging files anywhere onto the page.', '**How to use:** wrap a `FileUploadTrigger` and optional `FileUploadContent` in `FileUpload`, and read selected files from `onFilesAdded`. Set `multiple`, `accept`, or `disabled` as needed.', '**Placement:** in the prompt input area or composer toolbar where attachments are added.', ]), }, }, argTypes: { multiple: { control: 'boolean', description: 'Allow selecting / dropping more than one file.', table: { defaultValue: { summary: 'true' } }, }, accept: { control: 'text', description: 'Accepted file types, forwarded to the file input (e.g. `image/*`).', }, disabled: { control: 'boolean', description: 'Disables the file input and suppresses the drop overlay.', }, onFilesAdded: { action: 'filesAdded', description: 'Fired with the selected/dropped `File[]` (capped to one when `multiple` is false).', table: { category: 'Events' }, }, children: { control: false, description: 'Trigger and overlay composition (`FileUploadTrigger`, `FileUploadContent`).', }, }, args: { multiple: true, onFilesAdded: fn(), }, render: (args) => ( Upload files

Drop files here

), } satisfies Meta; export default meta; type Story = StoryObj; const IMPORT = `import { FileUpload, FileUploadTrigger, FileUploadContent } from '@kitn.ai/chat';`; const src = (code: string) => ({ parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } }, }); /** Interactive playground — toggle multiple/disabled and watch the `filesAdded` action. */ export const Playground: Story = { ...src(` console.log(files)}> Upload files

Drop files here

`), }; /** Multi-file upload with a live list of selected files (showcase). */ export const Default: Story = { render: () => { const [files, setFiles] = createSignal([]); return (
setFiles((prev) => [...prev, ...f])}> Upload files

Drop files here

{(file) => (
{file.name} ({(file.size / 1024).toFixed(1)} KB)
)}
); }, ...src(` setFiles((prev) => [...prev, ...f])}> Upload files

Drop files here

`), }; /** Single-file, image-only upload (showcase). */ export const SingleFile: Story = { render: () => { const [file, setFile] = createSignal(null); return (
setFile(f[0] ?? null)} multiple={false} accept="image/*" > Choose image

Drop an image here

{file() ? `Selected: ${file()!.name}` : 'No file selected'}
); }, ...src(` setFile(f[0] ?? null)} multiple={false} accept="image/*"> Choose image

Drop an image here

`), };