import type { Meta, StoryObj } from 'storybook-solidjs-vite'; import { Message, MessageAvatar, MessageContent, MessageActions } from './message'; import { Button } from '../ui/button'; import { Copy, ThumbsUp, ThumbsDown, RefreshCw, Pencil } from 'lucide-solid'; import { componentDescription } from '../stories/docs/element-controls'; const meta = { title: 'Solid (Advanced)/Elements/Message', component: Message, tags: ['autodocs'], parameters: { layout: 'padded', docs: { controls: { exclude: ['use:eventListener'] }, description: componentDescription([ 'A horizontal message row that composes an optional `MessageAvatar`, a `MessageContent` body (plain or markdown), and an optional `MessageActions` toolbar.', '**When to use:** rendering any chat turn — user or assistant. Use a bubble + right alignment for user turns, and an avatar + transparent content for assistant turns.', '**How to use:** wrap the parts in ``. Add `MessageAvatar` for the speaker, `MessageContent` for the text (set `markdown` to render markdown), and `MessageActions` for hover actions. Layout (alignment, bubble) is controlled via `class`.', '**Placement:** inside a `ChatContainer`/scroll region, stacked vertically as the conversation transcript.', ]), }, }, argTypes: { children: { control: false, description: 'The composed message parts (avatar, content, actions).', }, class: { control: 'text', description: 'Layout classes — e.g. `flex flex-col items-end` for right-aligned user turns.', }, }, args: { class: '', }, render: (args) => (
I can help with a variety of tasks: answering questions, providing information, assisting with coding, and generating creative content. What would you like help with today?
), } satisfies Meta; export default meta; type Story = StoryObj; const IMPORT = `import { Message, MessageAvatar, MessageContent, MessageActions } from '@kitn.ai/chat';`; const src = (code: string) => ({ parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } }, }); /** Interactive playground — an assistant turn; tweak `class` to change layout. */ export const Playground: Story = { ...src(` I can help with a variety of tasks... `), }; /** A user turn — right-aligned bubble, no avatar. */ export const UserMessage: Story = { render: () => (
Hello! How can I help you today?
), ...src(` Hello! How can I help you today? `), }; /** An assistant turn — avatar plus a secondary-background content block. */ export const AssistantMessage: Story = { render: () => (
I can help with a variety of tasks: answering questions, providing information, assisting with coding, generating creative content. What would you like help with today?
), ...src(` I can help with a variety of tasks... `), }; /** Assistant turn with a transparent, flush content block (no bubble). */ export const AssistantNoBg: Story = { name: 'Assistant (No Background)', render: () => (
I can help with a variety of tasks: answering questions, providing information, assisting with coding, generating creative content. What would you like help with today?
), ...src(` ... `), }; /** User bubble with hover-revealed edit/copy actions. */ export const UserAlignedRight: Story = { name: 'User (Right-Aligned)', render: () => (
Can you explain how SolidJS reactivity differs from React hooks?
), ...src(`
Can you explain how SolidJS reactivity differs from React hooks?
`), }; /** Markdown body — set `markdown` on `MessageContent` and pass a markdown string. */ export const MarkdownMessage: Story = { render: () => (
{`Here's a **bold** statement with some \`inline code\` and a list: - First item - Second item - Third item And a code block: \`\`\`typescript const greeting = "Hello, world!"; console.log(greeting); \`\`\``}
), ...src(` {markdownString} `), }; /** Assistant turn with a hover action row (copy / feedback / regenerate). */ export const WithActions: Story = { render: () => (
Here is a response with hover actions below it.
), ...src(`
Here is a response...
`), }; /** A user + assistant pair showing both layouts together (showcase). */ export const Conversation: Story = { render: () => (
What is TypeScript?
{`**TypeScript** is a strongly typed programming language that builds on JavaScript. It adds optional static type checking and other features like interfaces, enums, and generics. Key benefits: - Catches errors at compile time - Better IDE support and autocompletion - Makes large codebases more maintainable`}
), ...src(`
What is TypeScript? {answerMarkdown}
`), };