@kitn.ai/ui 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/kitn-chat.es.js +1 -1
  2. package/package.json +6 -1
  3. package/src/elements/compiled.css +1 -1
  4. package/src/components/artifact.stories.tsx +0 -138
  5. package/src/components/attachments.stories.tsx +0 -303
  6. package/src/components/attachments.test.tsx +0 -64
  7. package/src/components/chain-of-thought.stories.tsx +0 -211
  8. package/src/components/chat-container.stories.tsx +0 -187
  9. package/src/components/chat-thread.test.tsx +0 -58
  10. package/src/components/checkpoint.stories.tsx +0 -102
  11. package/src/components/code-block.stories.tsx +0 -150
  12. package/src/components/confirm-card.stories.tsx +0 -74
  13. package/src/components/context.stories.tsx +0 -229
  14. package/src/components/context.test.tsx +0 -133
  15. package/src/components/conversation-item.stories.tsx +0 -125
  16. package/src/components/conversation-list.stories.tsx +0 -133
  17. package/src/components/default-input.test.tsx +0 -111
  18. package/src/components/empty.stories.tsx +0 -434
  19. package/src/components/feedback-bar.stories.tsx +0 -138
  20. package/src/components/feedback-bar.test.tsx +0 -103
  21. package/src/components/file-tree.stories.tsx +0 -73
  22. package/src/components/file-upload.stories.tsx +0 -156
  23. package/src/components/image.stories.tsx +0 -89
  24. package/src/components/loader.stories.tsx +0 -181
  25. package/src/components/markdown.stories.tsx +0 -180
  26. package/src/components/message-action-bar.test.tsx +0 -128
  27. package/src/components/message-narrow.stories.tsx +0 -329
  28. package/src/components/message-skills.stories.tsx +0 -211
  29. package/src/components/message.stories.tsx +0 -281
  30. package/src/components/model-switcher.stories.tsx +0 -123
  31. package/src/components/model-switcher.test.tsx +0 -65
  32. package/src/components/prompt-input.stories.tsx +0 -222
  33. package/src/components/prompt-suggestion.stories.tsx +0 -142
  34. package/src/components/reasoning.stories.tsx +0 -140
  35. package/src/components/resizable.test.tsx +0 -226
  36. package/src/components/scroll-button.stories.tsx +0 -100
  37. package/src/components/slash-command.stories.tsx +0 -163
  38. package/src/components/source-list.test.tsx +0 -152
  39. package/src/components/source.stories.tsx +0 -124
  40. package/src/components/tasks-card.stories.tsx +0 -78
  41. package/src/components/text-shimmer.stories.tsx +0 -87
  42. package/src/components/thinking-bar.stories.tsx +0 -87
  43. package/src/components/tool.stories.tsx +0 -153
  44. package/src/components/voice-input.stories.tsx +0 -83
  45. package/src/elements/artifact.stories.tsx +0 -506
  46. package/src/elements/attachments.stories.tsx +0 -190
  47. package/src/elements/card.stories.tsx +0 -113
  48. package/src/elements/cards.stories.tsx +0 -59
  49. package/src/elements/catalog.stories.tsx +0 -491
  50. package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
  51. package/src/elements/chain-of-thought.stories.tsx +0 -113
  52. package/src/elements/chat-scope-picker.stories.tsx +0 -73
  53. package/src/elements/chat-workspace.stories.tsx +0 -288
  54. package/src/elements/chat.stories.tsx +0 -151
  55. package/src/elements/checkpoint.stories.tsx +0 -72
  56. package/src/elements/choice.stories.tsx +0 -240
  57. package/src/elements/code-block.stories.tsx +0 -83
  58. package/src/elements/composed-shell.stories.tsx +0 -316
  59. package/src/elements/confirm-card.stories.tsx +0 -227
  60. package/src/elements/context-meter.stories.tsx +0 -151
  61. package/src/elements/conversation-list.declarative.test.tsx +0 -137
  62. package/src/elements/conversation-list.stories.tsx +0 -243
  63. package/src/elements/embed.stories.tsx +0 -213
  64. package/src/elements/empty.stories.tsx +0 -111
  65. package/src/elements/feedback-bar.stories.tsx +0 -114
  66. package/src/elements/file-tree.stories.tsx +0 -134
  67. package/src/elements/file-upload.stories.tsx +0 -82
  68. package/src/elements/form.stories.tsx +0 -248
  69. package/src/elements/image.stories.tsx +0 -71
  70. package/src/elements/link-preview.stories.tsx +0 -209
  71. package/src/elements/loader.stories.tsx +0 -88
  72. package/src/elements/markdown.stories.tsx +0 -76
  73. package/src/elements/message-skills.declarative.test.tsx +0 -104
  74. package/src/elements/message-skills.stories.tsx +0 -114
  75. package/src/elements/message.stories.tsx +0 -218
  76. package/src/elements/model-switcher.declarative.test.tsx +0 -130
  77. package/src/elements/model-switcher.stories.tsx +0 -198
  78. package/src/elements/popover.stories.tsx +0 -80
  79. package/src/elements/prompt-input-slash-command.test.tsx +0 -128
  80. package/src/elements/prompt-input-stoppable.test.tsx +0 -88
  81. package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
  82. package/src/elements/prompt-input.stories.tsx +0 -331
  83. package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
  84. package/src/elements/prompt-suggestions.stories.tsx +0 -213
  85. package/src/elements/reasoning.stories.tsx +0 -77
  86. package/src/elements/remote.stories.tsx +0 -314
  87. package/src/elements/resizable.stories.tsx +0 -426
  88. package/src/elements/response-stream.stories.tsx +0 -79
  89. package/src/elements/scroll-button.stories.tsx +0 -202
  90. package/src/elements/scroll-button.test.tsx +0 -148
  91. package/src/elements/source-list.stories.tsx +0 -143
  92. package/src/elements/source.stories.tsx +0 -88
  93. package/src/elements/switch.stories.tsx +0 -56
  94. package/src/elements/tasks.stories.tsx +0 -237
  95. package/src/elements/text-shimmer.stories.tsx +0 -64
  96. package/src/elements/thinking-bar.stories.tsx +0 -72
  97. package/src/elements/tool.stories.tsx +0 -89
  98. package/src/elements/voice-input.stories.tsx +0 -88
  99. package/src/primitives/controllable.test.ts +0 -47
  100. package/src/stories/chat-panel-layout.stories.tsx +0 -145
  101. package/src/stories/chat-scene.tsx +0 -571
  102. package/src/stories/checkpoint-restore.stories.tsx +0 -256
  103. package/src/stories/context-usage.stories.tsx +0 -212
  104. package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
  105. package/src/stories/conversation-with-sources.stories.tsx +0 -471
  106. package/src/stories/docs/Accessibility.mdx +0 -119
  107. package/src/stories/docs/ChildElements.mdx +0 -269
  108. package/src/stories/docs/ForAIAgents.mdx +0 -162
  109. package/src/stories/docs/GettingStarted.mdx +0 -65
  110. package/src/stories/docs/Installation.mdx +0 -83
  111. package/src/stories/docs/Introduction.mdx +0 -50
  112. package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
  113. package/src/stories/docs/Theming.mdx +0 -85
  114. package/src/stories/docs/element-controls.ts +0 -121
  115. package/src/stories/docs/frameworks/Angular.mdx +0 -245
  116. package/src/stories/docs/frameworks/Html.mdx +0 -227
  117. package/src/stories/docs/frameworks/Overview.mdx +0 -47
  118. package/src/stories/docs/frameworks/React.mdx +0 -227
  119. package/src/stories/docs/frameworks/Solid.mdx +0 -173
  120. package/src/stories/docs/frameworks/Svelte.mdx +0 -194
  121. package/src/stories/docs/frameworks/Vue.mdx +0 -238
  122. package/src/stories/docs/generative-ui-overview.mdx +0 -186
  123. package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
  124. package/src/stories/docs/recipes/Streaming.mdx +0 -68
  125. package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
  126. package/src/stories/docs/theme-editor/canvas.tsx +0 -32
  127. package/src/stories/docs/theme-editor/inspector.tsx +0 -66
  128. package/src/stories/docs/theme-editor/presets.test.ts +0 -32
  129. package/src/stories/docs/theme-editor/presets.ts +0 -64
  130. package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
  131. package/src/stories/docs/theme-editor/theme-css.ts +0 -15
  132. package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
  133. package/src/stories/docs/theme-tokens.tsx +0 -174
  134. package/src/stories/examples/ChoosingComponents.mdx +0 -106
  135. package/src/stories/examples/sample-data.ts +0 -79
  136. package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
  137. package/src/stories/examples/usage/context-usage.ts +0 -591
  138. package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
  139. package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
  140. package/src/stories/examples/usage/empty-state.ts +0 -144
  141. package/src/stories/examples/usage/full-chat-app.ts +0 -277
  142. package/src/stories/examples/usage/index.ts +0 -63
  143. package/src/stories/examples/usage/message-actions.ts +0 -704
  144. package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
  145. package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
  146. package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
  147. package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
  148. package/src/stories/examples/usage/streaming-response.ts +0 -687
  149. package/src/stories/examples/usage/types.ts +0 -33
  150. package/src/stories/full-chat.stories.tsx +0 -18
  151. package/src/stories/message-actions.stories.tsx +0 -230
  152. package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
  153. package/src/stories/pattern-docked-widget.stories.tsx +0 -93
  154. package/src/stories/pattern-empty-state.stories.tsx +0 -76
  155. package/src/stories/prompt-input-variants.stories.tsx +0 -456
  156. package/src/stories/streaming-response.stories.tsx +0 -438
  157. package/src/stories/theme-editor.stories.tsx +0 -16
  158. package/src/stories/token-reference.stories.tsx +0 -18
  159. package/src/stories/typography.stories.tsx +0 -78
  160. package/src/ui/avatar.stories.tsx +0 -103
  161. package/src/ui/badge.stories.tsx +0 -86
  162. package/src/ui/button.stories.tsx +0 -145
  163. package/src/ui/collapsible.stories.tsx +0 -69
  164. package/src/ui/dropdown.stories.tsx +0 -59
  165. package/src/ui/hover-card.stories.tsx +0 -77
  166. package/src/ui/hover-card.test.tsx +0 -30
  167. package/src/ui/overlay.stories.tsx +0 -115
  168. package/src/ui/popover.stories.tsx +0 -81
  169. package/src/ui/popover.test.tsx +0 -99
  170. package/src/ui/resizable.stories.tsx +0 -236
  171. package/src/ui/scroll-area.stories.tsx +0 -50
  172. package/src/ui/separator.stories.tsx +0 -81
  173. package/src/ui/skeleton.stories.tsx +0 -337
  174. package/src/ui/switch.stories.tsx +0 -51
  175. package/src/ui/switch.test.tsx +0 -59
  176. package/src/ui/textarea.stories.tsx +0 -76
  177. package/src/ui/tooltip.stories.tsx +0 -74
@@ -1,281 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { Message, MessageAvatar, MessageContent, MessageActions } from './message';
3
- import { Button } from '../ui/button';
4
- import { Copy, ThumbsUp, ThumbsDown, RefreshCw, Pencil } from 'lucide-solid';
5
- import { componentDescription } from '../stories/docs/element-controls';
6
-
7
- const meta = {
8
- title: 'Solid (Advanced)/Elements/Message',
9
- component: Message,
10
- tags: ['autodocs'],
11
- parameters: {
12
- layout: 'padded',
13
- docs: {
14
- controls: { exclude: ['use:eventListener'] },
15
- description: componentDescription([
16
- 'A horizontal message row that composes an optional `MessageAvatar`, a `MessageContent` body (plain or markdown), and an optional `MessageActions` toolbar.',
17
- '**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.',
18
- '**How to use:** wrap the parts in `<Message>`. 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`.',
19
- '**Placement:** inside a `ChatContainer`/scroll region, stacked vertically as the conversation transcript.',
20
- ]),
21
- },
22
- },
23
- argTypes: {
24
- children: {
25
- control: false,
26
- description: 'The composed message parts (avatar, content, actions).',
27
- },
28
- class: {
29
- control: 'text',
30
- description: 'Layout classes — e.g. `flex flex-col items-end` for right-aligned user turns.',
31
- },
32
- },
33
- args: {
34
- class: '',
35
- },
36
- render: (args) => (
37
- <div class="max-w-2xl">
38
- <Message {...args}>
39
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
40
- <MessageContent>
41
- I can help with a variety of tasks: answering questions, providing
42
- information, assisting with coding, and generating creative content.
43
- What would you like help with today?
44
- </MessageContent>
45
- </Message>
46
- </div>
47
- ),
48
- } satisfies Meta<typeof Message>;
49
-
50
- export default meta;
51
- type Story = StoryObj<typeof meta>;
52
-
53
- const IMPORT = `import { Message, MessageAvatar, MessageContent, MessageActions } from '@kitn.ai/ui';`;
54
- const src = (code: string) => ({
55
- parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
56
- });
57
-
58
- /** Interactive playground — an assistant turn; tweak `class` to change layout. */
59
- export const Playground: Story = {
60
- ...src(`<Message>
61
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
62
- <MessageContent>I can help with a variety of tasks...</MessageContent>
63
- </Message>`),
64
- };
65
-
66
- /** A user turn — right-aligned bubble, no avatar. */
67
- export const UserMessage: Story = {
68
- render: () => (
69
- <div class="max-w-2xl">
70
- <Message class="flex flex-col items-end">
71
- <MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
72
- Hello! How can I help you today?
73
- </MessageContent>
74
- </Message>
75
- </div>
76
- ),
77
- ...src(`<Message class="flex flex-col items-end">
78
- <MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
79
- Hello! How can I help you today?
80
- </MessageContent>
81
- </Message>`),
82
- };
83
-
84
- /** An assistant turn — avatar plus a secondary-background content block. */
85
- export const AssistantMessage: Story = {
86
- render: () => (
87
- <div class="max-w-2xl">
88
- <Message>
89
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
90
- <MessageContent>
91
- I can help with a variety of tasks: answering questions, providing information,
92
- assisting with coding, generating creative content. What would you like help with today?
93
- </MessageContent>
94
- </Message>
95
- </div>
96
- ),
97
- ...src(`<Message>
98
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
99
- <MessageContent>I can help with a variety of tasks...</MessageContent>
100
- </Message>`),
101
- };
102
-
103
- /** Assistant turn with a transparent, flush content block (no bubble). */
104
- export const AssistantNoBg: Story = {
105
- name: 'Assistant (No Background)',
106
- render: () => (
107
- <div class="max-w-2xl">
108
- <Message>
109
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
110
- <MessageContent class="bg-transparent p-0">
111
- I can help with a variety of tasks: answering questions, providing information,
112
- assisting with coding, generating creative content. What would you like help with today?
113
- </MessageContent>
114
- </Message>
115
- </div>
116
- ),
117
- ...src(`<Message>
118
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
119
- <MessageContent class="bg-transparent p-0">...</MessageContent>
120
- </Message>`),
121
- };
122
-
123
- /** User bubble with hover-revealed edit/copy actions. */
124
- export const UserAlignedRight: Story = {
125
- name: 'User (Right-Aligned)',
126
- render: () => (
127
- <div class="max-w-2xl">
128
- <Message class="flex flex-col items-end">
129
- <div class="group flex flex-col items-end gap-1">
130
- <MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
131
- Can you explain how SolidJS reactivity differs from React hooks?
132
- </MessageContent>
133
- <MessageActions class="flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
134
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Edit message">
135
- <Pencil class="size-3.5" />
136
- </Button>
137
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
138
- <Copy class="size-3.5" />
139
- </Button>
140
- </MessageActions>
141
- </div>
142
- </Message>
143
- </div>
144
- ),
145
- ...src(`<Message class="flex flex-col items-end">
146
- <div class="group flex flex-col items-end gap-1">
147
- <MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
148
- Can you explain how SolidJS reactivity differs from React hooks?
149
- </MessageContent>
150
- <MessageActions class="opacity-0 group-hover:opacity-100">
151
- <Button variant="ghost" size="icon-sm"><Pencil class="size-3.5" /></Button>
152
- <Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
153
- </MessageActions>
154
- </div>
155
- </Message>`),
156
- };
157
-
158
- /** Markdown body — set `markdown` on `MessageContent` and pass a markdown string. */
159
- export const MarkdownMessage: Story = {
160
- render: () => (
161
- <div class="max-w-2xl">
162
- <Message>
163
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
164
- <MessageContent markdown class="bg-transparent p-0">
165
- {`Here's a **bold** statement with some \`inline code\` and a list:
166
-
167
- - First item
168
- - Second item
169
- - Third item
170
-
171
- And a code block:
172
-
173
- \`\`\`typescript
174
- const greeting = "Hello, world!";
175
- console.log(greeting);
176
- \`\`\``}
177
- </MessageContent>
178
- </Message>
179
- </div>
180
- ),
181
- ...src(`<Message>
182
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
183
- <MessageContent markdown class="bg-transparent p-0">
184
- {markdownString}
185
- </MessageContent>
186
- </Message>`),
187
- };
188
-
189
- /** Assistant turn with a hover action row (copy / feedback / regenerate). */
190
- export const WithActions: Story = {
191
- render: () => (
192
- <div class="max-w-2xl">
193
- <Message>
194
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
195
- <div class="group flex w-full flex-col gap-0">
196
- <MessageContent class="bg-transparent p-0">
197
- Here is a response with hover actions below it.
198
- </MessageContent>
199
- <MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
200
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
201
- <Copy class="size-3.5" />
202
- </Button>
203
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Good response">
204
- <ThumbsUp class="size-3.5" />
205
- </Button>
206
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Bad response">
207
- <ThumbsDown class="size-3.5" />
208
- </Button>
209
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Regenerate response">
210
- <RefreshCw class="size-3.5" />
211
- </Button>
212
- </MessageActions>
213
- </div>
214
- </Message>
215
- </div>
216
- ),
217
- ...src(`<Message>
218
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
219
- <div class="group flex w-full flex-col gap-0">
220
- <MessageContent class="bg-transparent p-0">Here is a response...</MessageContent>
221
- <MessageActions class="opacity-0 group-hover:opacity-100">
222
- <Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
223
- <Button variant="ghost" size="icon-sm"><ThumbsUp class="size-3.5" /></Button>
224
- <Button variant="ghost" size="icon-sm"><ThumbsDown class="size-3.5" /></Button>
225
- <Button variant="ghost" size="icon-sm"><RefreshCw class="size-3.5" /></Button>
226
- </MessageActions>
227
- </div>
228
- </Message>`),
229
- };
230
-
231
- /** A user + assistant pair showing both layouts together (showcase). */
232
- export const Conversation: Story = {
233
- render: () => (
234
- <div class="max-w-2xl space-y-4">
235
- <Message class="flex flex-col items-end">
236
- <MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
237
- What is TypeScript?
238
- </MessageContent>
239
- </Message>
240
-
241
- <Message>
242
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
243
- <div class="group flex w-full flex-col gap-0">
244
- <MessageContent markdown class="bg-transparent p-0">
245
- {`**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.
246
-
247
- Key benefits:
248
- - Catches errors at compile time
249
- - Better IDE support and autocompletion
250
- - Makes large codebases more maintainable`}
251
- </MessageContent>
252
- <MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
253
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
254
- <Copy class="size-3.5" />
255
- </Button>
256
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Good response">
257
- <ThumbsUp class="size-3.5" />
258
- </Button>
259
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Bad response">
260
- <ThumbsDown class="size-3.5" />
261
- </Button>
262
- <Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Regenerate response">
263
- <RefreshCw class="size-3.5" />
264
- </Button>
265
- </MessageActions>
266
- </div>
267
- </Message>
268
- </div>
269
- ),
270
- ...src(`<div class="space-y-4">
271
- <Message class="flex flex-col items-end">
272
- <MessageContent class="bg-muted text-primary rounded-3xl px-5 py-2.5">
273
- What is TypeScript?
274
- </MessageContent>
275
- </Message>
276
- <Message>
277
- <MessageAvatar src="" fallback="AI" alt="Assistant" />
278
- <MessageContent markdown class="bg-transparent p-0">{answerMarkdown}</MessageContent>
279
- </Message>
280
- </div>`),
281
- };
@@ -1,123 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { fn } from 'storybook/test';
3
- import { ModelSwitcher } from './model-switcher';
4
- import { componentDescription } from '../stories/docs/element-controls';
5
-
6
- const multipleModels = [
7
- { id: 'claude-sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
8
- { id: 'claude-opus', name: 'Claude Opus', provider: 'Anthropic' },
9
- { id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
10
- { id: 'gemini-pro', name: 'Gemini Pro', provider: 'Google' },
11
- ];
12
-
13
- const meta = {
14
- title: 'Solid (Advanced)/Elements/ModelSwitcher',
15
- component: ModelSwitcher,
16
- tags: ['autodocs'],
17
- parameters: {
18
- layout: 'padded',
19
- docs: {
20
- controls: { exclude: ['use:eventListener'] },
21
- description: componentDescription([
22
- 'A compact dropdown that shows the active model and lets the user switch between the available **models** (grouped by optional `provider` label).',
23
- '**When to use:** when a chat surface offers more than one model. It renders nothing when fewer than two models are provided, so it is safe to mount unconditionally.',
24
- '**How to use:** pass the `models` list and the `currentModelId`, then handle `onModelChange` to update your selected-model state.',
25
- '**Placement:** the prompt input action bar, a chat header, or a settings/toolbar row near the composer.',
26
- ]),
27
- },
28
- },
29
- argTypes: {
30
- models: {
31
- control: 'object',
32
- description: 'Selectable models. Each has `id`, `name`, and an optional `provider` label.',
33
- },
34
- currentModelId: {
35
- control: 'text',
36
- description: 'The `id` of the currently selected model.',
37
- },
38
- onModelChange: {
39
- action: 'modelChange',
40
- description: 'Fired with the chosen model `id` when the user picks a model.',
41
- table: { category: 'Events' },
42
- },
43
- class: {
44
- control: 'text',
45
- description: 'Extra classes applied to the trigger button.',
46
- },
47
- },
48
- args: {
49
- models: multipleModels,
50
- currentModelId: 'claude-sonnet',
51
- onModelChange: fn(),
52
- },
53
- render: (args) => <ModelSwitcher {...args} />,
54
- } satisfies Meta<typeof ModelSwitcher>;
55
-
56
- export default meta;
57
- type Story = StoryObj<typeof meta>;
58
-
59
- const IMPORT = `import { ModelSwitcher } from '@kitn.ai/ui';`;
60
- const src = (code: string) => ({
61
- parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
62
- });
63
-
64
- /** Interactive playground — tweak the controls to explore the switcher. */
65
- export const Playground: Story = {
66
- ...src(`<ModelSwitcher
67
- models={models}
68
- currentModelId={modelId()}
69
- onModelChange={setModelId}
70
- />`),
71
- };
72
-
73
- /** Several models across providers — the dropdown lists them with provider labels. */
74
- export const MultipleModels: Story = {
75
- args: { models: multipleModels, currentModelId: 'claude-sonnet' },
76
- ...src(`<ModelSwitcher
77
- models={[
78
- { id: 'claude-sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
79
- { id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
80
- ]}
81
- currentModelId={modelId()}
82
- onModelChange={setModelId}
83
- />`),
84
- };
85
-
86
- /**
87
- * Rich rows + a collapsible group. `description` renders as the row subtitle
88
- * (preferred over `provider`), and models sharing a `group` collect under a
89
- * collapsible section — the ChatGPT-style "Legacy models" pattern.
90
- */
91
- export const GroupedAndDescribed: Story = {
92
- args: {
93
- models: [
94
- { id: 'gpt-5.5', name: 'GPT-5.5', description: 'Flagship model' },
95
- { id: 'gpt-5.5-mini', name: 'GPT-5.5 mini', description: 'Faster, lighter' },
96
- { id: 'gpt-4o', name: 'GPT-4o', group: 'Legacy models' },
97
- { id: 'gpt-4.1', name: 'GPT-4.1', group: 'Legacy models' },
98
- ],
99
- currentModelId: 'gpt-5.5',
100
- },
101
- ...src(`<ModelSwitcher
102
- models={[
103
- { id: 'gpt-5.5', name: 'GPT-5.5', description: 'Flagship model' },
104
- { id: 'gpt-4o', name: 'GPT-4o', group: 'Legacy models' },
105
- { id: 'gpt-4.1', name: 'GPT-4.1', group: 'Legacy models' },
106
- ]}
107
- currentModelId={modelId()}
108
- onModelChange={setModelId}
109
- />`),
110
- };
111
-
112
- /** A single model — the switcher renders nothing (needs 2+ models). */
113
- export const SingleModel: Story = {
114
- args: {
115
- models: [{ id: 'claude-sonnet', name: 'Claude Sonnet' }],
116
- currentModelId: 'claude-sonnet',
117
- },
118
- ...src(`<ModelSwitcher
119
- models={[{ id: 'claude-sonnet', name: 'Claude Sonnet' }]}
120
- currentModelId="claude-sonnet"
121
- onModelChange={setModelId}
122
- />`),
123
- };
@@ -1,65 +0,0 @@
1
- import { describe, it, expect, vi, afterEach } from 'vitest';
2
- import '@testing-library/jest-dom/vitest';
3
- import { render, cleanup, fireEvent, screen } from '@solidjs/testing-library';
4
- import { ModelSwitcher } from './model-switcher';
5
- import type { ModelOption } from '../types';
6
-
7
- afterEach(cleanup);
8
-
9
- const MODELS: ModelOption[] = [
10
- { id: 'gpt-5.5', name: 'GPT-5.5', description: 'Flagship model' },
11
- { id: 'gpt-4o', name: 'GPT-4o', group: 'Legacy models' },
12
- { id: 'gpt-4.1', name: 'GPT-4.1', group: 'Legacy models' },
13
- ];
14
-
15
- // Dropdown content renders through a Portal (outside the render container), so
16
- // query via `screen` (document.body). The trigger button is the only button
17
- // before any group is expanded.
18
- const open = () => fireEvent.click(screen.getByRole('button'));
19
-
20
- describe('ModelSwitcher grouping & descriptions', () => {
21
- it('renders a model description under the model name', () => {
22
- render(() => <ModelSwitcher models={MODELS} currentModelId="gpt-5.5" onModelChange={() => {}} />);
23
- open();
24
- expect(screen.getByText('Flagship model')).toBeInTheDocument();
25
- });
26
-
27
- it('hides grouped models behind a collapsed group header until expanded', () => {
28
- render(() => <ModelSwitcher models={MODELS} currentModelId="gpt-5.5" onModelChange={() => {}} />);
29
- open();
30
- expect(screen.getByText('Legacy models')).toBeInTheDocument();
31
- expect(screen.queryByText('GPT-4o')).not.toBeInTheDocument();
32
- fireEvent.click(screen.getByText('Legacy models'));
33
- expect(screen.getByText('GPT-4o')).toBeInTheDocument();
34
- expect(screen.getByText('GPT-4.1')).toBeInTheDocument();
35
- });
36
-
37
- it('selects an ungrouped model', () => {
38
- const onModelChange = vi.fn();
39
- render(() => <ModelSwitcher models={MODELS} currentModelId="gpt-4o" onModelChange={onModelChange} />);
40
- open();
41
- fireEvent.click(screen.getByText('Flagship model')); // the GPT-5.5 row (description is unique)
42
- expect(onModelChange).toHaveBeenCalledWith('gpt-5.5');
43
- });
44
-
45
- it('selects a grouped model after expanding its group', () => {
46
- const onModelChange = vi.fn();
47
- render(() => <ModelSwitcher models={MODELS} currentModelId="gpt-5.5" onModelChange={onModelChange} />);
48
- open();
49
- fireEvent.click(screen.getByText('Legacy models'));
50
- fireEvent.click(screen.getByText('GPT-4o'));
51
- expect(onModelChange).toHaveBeenCalledWith('gpt-4o');
52
- });
53
-
54
- it('still renders provider when no description is given (back-compat)', () => {
55
- render(() => (
56
- <ModelSwitcher
57
- models={[{ id: 'a', name: 'Model A', provider: 'Acme' }, { id: 'b', name: 'Model B' }]}
58
- currentModelId="a"
59
- onModelChange={() => {}}
60
- />
61
- ));
62
- open();
63
- expect(screen.getByText('Acme')).toBeInTheDocument();
64
- });
65
- });