import type { Meta, StoryObj } from 'storybook-solidjs-vite'; import { fn } from 'storybook/test'; import { createSignal } from 'solid-js'; import { Reasoning, ReasoningTrigger, ReasoningContent } from './reasoning'; import { componentDescription } from '../stories/docs/element-controls'; const meta = { title: 'Solid (Advanced)/Elements/Reasoning', component: Reasoning, tags: ['autodocs'], parameters: { layout: 'padded', docs: { description: componentDescription([ 'A collapsible disclosure for a model\'s thinking/reasoning. Compose `Reasoning` (root) with `ReasoningTrigger` (the toggle) and `ReasoningContent` (the body, with optional markdown).', '**When to use:** to surface an assistant\'s chain-of-thought or scratch reasoning that should be available but collapsed by default. It can auto-open while streaming and auto-close when streaming ends.', '**How to use:** wrap a trigger and content in `Reasoning`. Leave it uncontrolled, or drive it with `open` + `onOpenChange`. Set `isStreaming` to auto-open during generation. Pass `markdown` on `ReasoningContent` to render a markdown string.', '**Placement:** inside or above an assistant message, before the final answer.', ]), controls: { exclude: ['use:eventListener'] }, }, }, argTypes: { open: { control: 'boolean', description: 'Controlled open state. Omit for uncontrolled behavior.', }, isStreaming: { control: 'boolean', description: 'When true, auto-opens the disclosure; auto-closes when it returns to false.', table: { defaultValue: { summary: 'false' } }, }, onOpenChange: { action: 'openChange', description: 'Fired with the next open state when the trigger is toggled.', table: { category: 'Events' }, }, children: { control: false, description: 'Trigger and content composition.' }, }, args: { isStreaming: false, onOpenChange: fn(), }, render: (args) => ( View reasoning

The user is asking about reactive programming. Let me break down the key concepts of signals, effects, and memos in SolidJS.

), } satisfies Meta; export default meta; type Story = StoryObj; const IMPORT = `import { Reasoning, ReasoningTrigger, ReasoningContent } from '@kitn.ai/chat';`; const src = (code: string) => ({ parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } }, }); /** Interactive playground — toggle `open` / `isStreaming` via the controls. */ export const Playground: Story = { ...src(` View reasoning

Let me break down signals, effects, and memos in SolidJS.

`), }; /** Content rendered from a markdown string. */ export const WithMarkdown: Story = { render: (args: Parameters>[0]) => ( View reasoning {'The user wants to understand **reactive primitives**.\n\n- `createSignal` for state\n- `createEffect` for side effects\n- `createMemo` for derived values'} ), ...src(` View reasoning {'The user wants **reactive primitives**.\\n\\n- \`createSignal\`\\n- \`createEffect\`\\n- \`createMemo\`'} `), }; /** Controlled via `open` + `onOpenChange`, starting open (showcase). */ export const Controlled: Story = { render: () => { const [open, setOpen] = createSignal(true); return ( Thinking process

This is a controlled reasoning component that starts open.

); }, ...src(`const [open, setOpen] = createSignal(true); Thinking process

This is a controlled reasoning component that starts open.

`), }; /** Auto-opens while streaming, auto-closes when it ends (showcase). */ export const Streaming: Story = { render: () => { const [streaming, setStreaming] = createSignal(true); return (
Thinking...

Auto-opens during streaming and auto-closes when streaming ends.

); }, ...src(` Thinking...

Auto-opens during streaming and auto-closes when streaming ends.

`), };