import type { ExampleUsage, StoryUsage } from './types'; // A small thread reused across the snippets — user + assistant, with actions, // reasoning, and a tool call on the second assistant message. const MESSAGES = `[ { id: 'u1', role: 'user', content: 'Can you explain how SolidJS reactivity differs from React hooks?' }, { id: 'a1', role: 'assistant', content: 'SolidJS uses fine-grained signals: components run once and only the DOM nodes that read a signal update.', actions: ['copy', 'like', 'dislike', 'regenerate'], }, { id: 'u2', role: 'user', content: 'Can you benchmark SolidJS vs React for 10,000 items?' }, { id: 'a2', role: 'assistant', content: 'Here are the benchmark results — SolidJS renders ~7x faster and updates ~42x faster.', actions: ['copy', 'like', 'dislike', 'regenerate'], reasoning: { label: 'Thought for 4 seconds', text: 'Render the same 10,000 items in both frameworks for a fair comparison.' }, tools: [ { type: 'run_benchmark', state: 'output-available', input: { framework: ['solid', 'react'], itemCount: 10000 }, output: { solid: { avgRenderMs: 12.4 }, react: { avgRenderMs: 89.2 } }, toolCallId: 'call_abc123', }, ], }, ]`; const MODELS = `[ { id: 'claude-4', name: 'Claude 4 Opus', provider: 'Anthropic' }, { id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' }, ]`; const CONTEXT = `{ usedTokens: 12400, maxTokens: 200000, inputTokens: 8200, outputTokens: 4200, estimatedCost: 0.042 }`; const SUGGESTIONS = `['How does SolidJS handle context?', 'Show me a store example']`; /** * Default — the entire chat experience in one element. `` renders the * message thread (markdown, reasoning, tool calls, per-message action bars), a * header with the `models` switcher + `context` token meter, the `suggestions` * chips, and the prompt input. The demo's resizable sidebar + conversation list * are separate chrome that lives *outside* the element. */ const fullChat: StoryUsage = { intro: 'Drop in the whole chat experience with one element. `` renders the thread (markdown, reasoning, tool calls, action bars), an optional header model switcher + `context` token meter, `suggestions` chips, and the prompt input — set `messages` as a property and handle `submit` / `messageaction` / `modelchange`. The resizable conversation sidebar in the demo is separate chrome `` does not include. (The live demo composes the SolidJS `ChatContainer`, `Message`, `PromptInput`, and `ConversationList` primitives directly.)', snippets: { html: ` `, react: `import { Chat } from '@kitn.ai/chat/react'; export function ChatApp() { return ( console.log('send', e.detail.value, e.detail.attachments)} onMessageAction={(e) => console.log(e.detail.messageId, e.detail.action)} onModelChange={(e) => console.log(e.detail.modelId)} /> ); }`, vue: ` `, svelte: ` console.log(e.detail.modelId)} />`, angular: `// main.ts: import '@kitn.ai/chat/elements' before bootstrapApplication, // and add CUSTOM_ELEMENTS_SCHEMA to the component. import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @Component({ selector: 'app-chat', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], template: \` \`, }) export class ChatComponent { messages = ${MESSAGES}; models = ${MODELS}; context = ${CONTEXT}; suggestions = ${SUGGESTIONS}; onSubmit(e: CustomEvent<{ value: string; attachments: unknown[] }>) { console.log('send', e.detail.value, e.detail.attachments); } onAction(e: CustomEvent<{ messageId: string; action: string }>) { console.log(e.detail.messageId, e.detail.action); } onModel(e: CustomEvent<{ modelId: string }>) { console.log(e.detail.modelId); } }`, solid: `import { createSignal, For } from 'solid-js'; import { ChatContainer, ChatContainerContent, ChatContainerScrollAnchor, Message, MessageContent, MessageActions, PromptInput, PromptInputTextarea, PromptInputActions, ConversationList, ModelSwitcher, PromptSuggestion, ScrollButton, Button, } from '@kitn.ai/chat'; import { Copy, ThumbsUp, ThumbsDown, RefreshCw, ArrowUp } from 'lucide-solid'; export function ChatApp() { const [value, setValue] = createSignal(''); const [modelId, setModelId] = createSignal('claude-4'); return (
{/* Sidebar — separate chrome from the thread */} {}} onNewChat={() => {}} />
SolidJS reactivity vs React hooks
{assistantReply}
{(s) => setValue(s)}>{s}}
setValue('')}>
); }`, }, }; /** * Example: Full Chat App — the complete experience. As an embedder you reach for * the single `` element; the live demo composes the granular SolidJS * primitives for full control. Per-story: the Usage tab shows the snippet for the * story you're on; the example-level fields below are the fallback. */ const fullChatApp: ExampleUsage = { title: 'Examples/Full Chat App', ...fullChat, // example-level fallback = the "Default" story stories: { Default: fullChat, }, }; export default fullChatApp;