@kitn.ai/ui 0.14.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.
- package/LICENSE +21 -0
- package/README.md +394 -0
- package/dist/bash-InADTalH.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -0
- package/dist/css-M7EaDHN_.js +1 -0
- package/dist/custom-elements.json +4739 -0
- package/dist/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/github-light-JYsPkUQd.js +1 -0
- package/dist/host-embed.d.ts +33 -0
- package/dist/html-CPZ3oZQ7.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/javascript-C25yR2R2.js +1 -0
- package/dist/json-DxJze_jm.js +1 -0
- package/dist/kitn-chat-provider.d.ts +2 -0
- package/dist/kitn-chat-provider.es.js +240 -0
- package/dist/kitn-chat.es.js +77 -0
- package/dist/llms/llms-full.txt +1018 -0
- package/dist/llms/llms.txt +104 -0
- package/dist/origin.d.ts +5 -0
- package/dist/provider-runtime.d.ts +27 -0
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -0
- package/dist/schemas/choice.schema.json +70 -0
- package/dist/schemas/confirm.schema.json +65 -0
- package/dist/schemas/embed.schema.json +65 -0
- package/dist/schemas/form.result.schema.json +7 -0
- package/dist/schemas/form.schema.json +33 -0
- package/dist/schemas/link.schema.json +56 -0
- package/dist/schemas/tasks.result.schema.json +16 -0
- package/dist/schemas/tasks.schema.json +78 -0
- package/dist/svelte--5p79yCD.js +1 -0
- package/dist/theme.tokens.css +176 -0
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/version.d.ts +4 -0
- package/dist/vue-BmIZj4XD.js +1 -0
- package/dist/wire.d.ts +53 -0
- package/frameworks/react/index.tsx +948 -0
- package/frameworks/react/runtime.tsx +94 -0
- package/llms-full.txt +1018 -0
- package/llms.txt +104 -0
- package/package.json +141 -0
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +743 -0
- package/src/components/attachments.stories.tsx +303 -0
- package/src/components/attachments.test.tsx +64 -0
- package/src/components/attachments.tsx +399 -0
- package/src/components/card-fallback.tsx +28 -0
- package/src/components/card-renderer.tsx +52 -0
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +211 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +187 -0
- package/src/components/chat-container.tsx +82 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/chat-thread.test.tsx +58 -0
- package/src/components/chat-thread.tsx +249 -0
- package/src/components/checkpoint.stories.tsx +102 -0
- package/src/components/checkpoint.tsx +88 -0
- package/src/components/choice-card.tsx +569 -0
- package/src/components/code-block.stories.tsx +150 -0
- package/src/components/code-block.tsx +105 -0
- package/src/components/component-meta.json +3735 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +315 -0
- package/src/components/context.stories.tsx +229 -0
- package/src/components/context.test.tsx +133 -0
- package/src/components/context.tsx +363 -0
- package/src/components/conversation-item.stories.tsx +125 -0
- package/src/components/conversation-item.tsx +16 -0
- package/src/components/conversation-list.stories.tsx +133 -0
- package/src/components/conversation-list.tsx +101 -0
- package/src/components/default-input.test.tsx +111 -0
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +434 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +138 -0
- package/src/components/feedback-bar.test.tsx +103 -0
- package/src/components/feedback-bar.tsx +166 -0
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +156 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +873 -0
- package/src/components/image.stories.tsx +89 -0
- package/src/components/image.tsx +67 -0
- package/src/components/link-preview.tsx +194 -0
- package/src/components/loader.stories.tsx +181 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +180 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-action-bar.test.tsx +128 -0
- package/src/components/message-narrow.stories.tsx +329 -0
- package/src/components/message-skills.stories.tsx +211 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +281 -0
- package/src/components/message.tsx +227 -0
- package/src/components/model-switcher.stories.tsx +123 -0
- package/src/components/model-switcher.test.tsx +65 -0
- package/src/components/model-switcher.tsx +87 -0
- package/src/components/prompt-input.stories.tsx +222 -0
- package/src/components/prompt-input.tsx +211 -0
- package/src/components/prompt-suggestion.stories.tsx +142 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +140 -0
- package/src/components/reasoning.tsx +156 -0
- package/src/components/resizable.test.tsx +226 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +100 -0
- package/src/components/scroll-button.tsx +34 -0
- package/src/components/slash-command.stories.tsx +163 -0
- package/src/components/slash-command.tsx +232 -0
- package/src/components/source-list.test.tsx +152 -0
- package/src/components/source.stories.tsx +124 -0
- package/src/components/source.tsx +129 -0
- package/src/components/tasks-card.stories.tsx +78 -0
- package/src/components/tasks-card.tsx +432 -0
- package/src/components/text-shimmer.stories.tsx +87 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +87 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +153 -0
- package/src/components/tool.tsx +184 -0
- package/src/components/use-card-resolution.ts +28 -0
- package/src/components/voice-input.stories.tsx +83 -0
- package/src/components/voice-input.tsx +107 -0
- package/src/elements/artifact.stories.tsx +506 -0
- package/src/elements/artifact.tsx +137 -0
- package/src/elements/attachments.stories.tsx +190 -0
- package/src/elements/attachments.tsx +136 -0
- package/src/elements/card.stories.tsx +113 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/cards.stories.tsx +59 -0
- package/src/elements/cards.tsx +97 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/chain-of-thought.declarative.test.tsx +153 -0
- package/src/elements/chain-of-thought.stories.tsx +113 -0
- package/src/elements/chain-of-thought.tsx +92 -0
- package/src/elements/chat-scope-picker.stories.tsx +73 -0
- package/src/elements/chat-scope-picker.tsx +36 -0
- package/src/elements/chat-types.ts +42 -0
- package/src/elements/chat-workspace.stories.tsx +288 -0
- package/src/elements/chat-workspace.tsx +161 -0
- package/src/elements/chat.stories.tsx +151 -0
- package/src/elements/chat.tsx +80 -0
- package/src/elements/checkpoint.stories.tsx +72 -0
- package/src/elements/checkpoint.tsx +47 -0
- package/src/elements/choice.stories.tsx +240 -0
- package/src/elements/choice.tsx +48 -0
- package/src/elements/code-block.stories.tsx +83 -0
- package/src/elements/code-block.tsx +42 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +227 -0
- package/src/elements/confirm-card.tsx +51 -0
- package/src/elements/context-meter.stories.tsx +151 -0
- package/src/elements/context-meter.tsx +121 -0
- package/src/elements/conversation-list.declarative.test.tsx +137 -0
- package/src/elements/conversation-list.stories.tsx +243 -0
- package/src/elements/conversation-list.tsx +80 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +247 -0
- package/src/elements/define.tsx +171 -0
- package/src/elements/element-meta.json +3314 -0
- package/src/elements/element-types.d.ts +710 -0
- package/src/elements/embed.stories.tsx +213 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/empty.stories.tsx +111 -0
- package/src/elements/empty.tsx +29 -0
- package/src/elements/feedback-bar.stories.tsx +114 -0
- package/src/elements/feedback-bar.tsx +61 -0
- package/src/elements/file-tree.stories.tsx +134 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/file-upload.stories.tsx +82 -0
- package/src/elements/file-upload.tsx +44 -0
- package/src/elements/form.stories.tsx +248 -0
- package/src/elements/form.tsx +43 -0
- package/src/elements/framework-usage.json +563 -0
- package/src/elements/image.stories.tsx +71 -0
- package/src/elements/image.tsx +32 -0
- package/src/elements/link-preview.stories.tsx +209 -0
- package/src/elements/link-preview.tsx +34 -0
- package/src/elements/loader.stories.tsx +88 -0
- package/src/elements/loader.tsx +25 -0
- package/src/elements/markdown.stories.tsx +76 -0
- package/src/elements/markdown.tsx +38 -0
- package/src/elements/message-skills.declarative.test.tsx +104 -0
- package/src/elements/message-skills.stories.tsx +114 -0
- package/src/elements/message-skills.tsx +85 -0
- package/src/elements/message.stories.tsx +218 -0
- package/src/elements/message.tsx +162 -0
- package/src/elements/model-switcher.declarative.test.tsx +130 -0
- package/src/elements/model-switcher.stories.tsx +198 -0
- package/src/elements/model-switcher.tsx +93 -0
- package/src/elements/popover.stories.tsx +80 -0
- package/src/elements/popover.tsx +59 -0
- package/src/elements/prompt-input-slash-command.test.tsx +128 -0
- package/src/elements/prompt-input-stoppable.test.tsx +88 -0
- package/src/elements/prompt-input-toolbar-actions.test.tsx +120 -0
- package/src/elements/prompt-input.stories.tsx +331 -0
- package/src/elements/prompt-input.tsx +185 -0
- package/src/elements/prompt-suggestions.declarative.test.tsx +164 -0
- package/src/elements/prompt-suggestions.stories.tsx +213 -0
- package/src/elements/prompt-suggestions.tsx +94 -0
- package/src/elements/reasoning.stories.tsx +77 -0
- package/src/elements/reasoning.tsx +50 -0
- package/src/elements/register.ts +56 -0
- package/src/elements/remote.stories.tsx +314 -0
- package/src/elements/remote.tsx +221 -0
- package/src/elements/resizable.d.ts +27 -0
- package/src/elements/resizable.stories.tsx +426 -0
- package/src/elements/resizable.tsx +553 -0
- package/src/elements/response-stream.stories.tsx +79 -0
- package/src/elements/response-stream.tsx +40 -0
- package/src/elements/scroll-button.stories.tsx +202 -0
- package/src/elements/scroll-button.test.tsx +148 -0
- package/src/elements/scroll-button.tsx +126 -0
- package/src/elements/source-list.stories.tsx +143 -0
- package/src/elements/source.stories.tsx +88 -0
- package/src/elements/source.tsx +120 -0
- package/src/elements/styles.css +199 -0
- package/src/elements/switch.stories.tsx +56 -0
- package/src/elements/switch.tsx +43 -0
- package/src/elements/tasks.stories.tsx +237 -0
- package/src/elements/tasks.tsx +46 -0
- package/src/elements/text-shimmer.stories.tsx +64 -0
- package/src/elements/text-shimmer.tsx +28 -0
- package/src/elements/thinking-bar.stories.tsx +72 -0
- package/src/elements/thinking-bar.tsx +34 -0
- package/src/elements/tool.stories.tsx +89 -0
- package/src/elements/tool.tsx +23 -0
- package/src/elements/voice-input.stories.tsx +88 -0
- package/src/elements/voice-input.tsx +41 -0
- package/src/index.ts +253 -0
- package/src/primitives/card-contract.ts +71 -0
- package/src/primitives/card-host.tsx +35 -0
- package/src/primitives/card-registry.tsx +67 -0
- package/src/primitives/card-resolution.ts +36 -0
- package/src/primitives/card-routing.ts +79 -0
- package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
- package/src/primitives/card-schemas/card-event.schema.json +12 -0
- package/src/primitives/card-schemas/choice.schema.json +70 -0
- package/src/primitives/card-schemas/confirm.schema.json +65 -0
- package/src/primitives/card-schemas/embed.schema.json +65 -0
- package/src/primitives/card-schemas/form.result.schema.json +7 -0
- package/src/primitives/card-schemas/form.schema.json +33 -0
- package/src/primitives/card-schemas/link.schema.json +56 -0
- package/src/primitives/card-schemas/tasks.result.schema.json +16 -0
- package/src/primitives/card-schemas/tasks.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/controllable.test.ts +47 -0
- package/src/primitives/controllable.ts +21 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +157 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-resize-observer.ts +12 -0
- package/src/primitives/use-stick-to-bottom.ts +43 -0
- package/src/primitives/use-text-stream.ts +112 -0
- package/src/primitives/use-voice-recorder.ts +50 -0
- package/src/remote/host-embed.ts +345 -0
- package/src/remote/index.ts +2 -0
- package/src/remote/origin.ts +30 -0
- package/src/remote/provider-runtime.ts +259 -0
- package/src/remote/provider.ts +2 -0
- package/src/remote/validate.ts +22 -0
- package/src/remote/version.ts +12 -0
- package/src/remote/wire.ts +48 -0
- package/src/stories/chat-panel-layout.stories.tsx +145 -0
- package/src/stories/chat-scene.tsx +571 -0
- package/src/stories/checkpoint-restore.stories.tsx +256 -0
- package/src/stories/context-usage.stories.tsx +212 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +182 -0
- package/src/stories/conversation-with-sources.stories.tsx +471 -0
- package/src/stories/docs/Accessibility.mdx +119 -0
- package/src/stories/docs/ChildElements.mdx +269 -0
- package/src/stories/docs/ForAIAgents.mdx +162 -0
- package/src/stories/docs/GettingStarted.mdx +65 -0
- package/src/stories/docs/Installation.mdx +83 -0
- package/src/stories/docs/Introduction.mdx +50 -0
- package/src/stories/docs/SolidJsAdvanced.mdx +17 -0
- package/src/stories/docs/Theming.mdx +85 -0
- package/src/stories/docs/element-controls.ts +121 -0
- package/src/stories/docs/frameworks/Angular.mdx +245 -0
- package/src/stories/docs/frameworks/Html.mdx +227 -0
- package/src/stories/docs/frameworks/Overview.mdx +47 -0
- package/src/stories/docs/frameworks/React.mdx +227 -0
- package/src/stories/docs/frameworks/Solid.mdx +173 -0
- package/src/stories/docs/frameworks/Svelte.mdx +194 -0
- package/src/stories/docs/frameworks/Vue.mdx +238 -0
- package/src/stories/docs/generative-ui-overview.mdx +186 -0
- package/src/stories/docs/recipes/SpeechToText.mdx +7 -0
- package/src/stories/docs/recipes/Streaming.mdx +68 -0
- package/src/stories/docs/recipes/TextToSpeech.mdx +35 -0
- package/src/stories/docs/theme-editor/canvas.tsx +32 -0
- package/src/stories/docs/theme-editor/inspector.tsx +66 -0
- package/src/stories/docs/theme-editor/presets.test.ts +32 -0
- package/src/stories/docs/theme-editor/presets.ts +64 -0
- package/src/stories/docs/theme-editor/theme-css.test.ts +19 -0
- package/src/stories/docs/theme-editor/theme-css.ts +15 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +146 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/examples/ChoosingComponents.mdx +106 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/examples/usage/checkpoint-restore.ts +156 -0
- package/src/stories/examples/usage/context-usage.ts +591 -0
- package/src/stories/examples/usage/conversation-with-reasoning.ts +224 -0
- package/src/stories/examples/usage/conversation-with-sources.ts +589 -0
- package/src/stories/examples/usage/empty-state.ts +144 -0
- package/src/stories/examples/usage/full-chat-app.ts +277 -0
- package/src/stories/examples/usage/index.ts +63 -0
- package/src/stories/examples/usage/message-actions.ts +704 -0
- package/src/stories/examples/usage/pattern-centered-conversation.ts +446 -0
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +442 -0
- package/src/stories/examples/usage/pattern-docked-widget.ts +479 -0
- package/src/stories/examples/usage/prompt-input-variants.ts +1356 -0
- package/src/stories/examples/usage/streaming-response.ts +687 -0
- package/src/stories/examples/usage/types.ts +33 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +230 -0
- package/src/stories/pattern-centered-conversation.stories.tsx +93 -0
- package/src/stories/pattern-docked-widget.stories.tsx +93 -0
- package/src/stories/pattern-empty-state.stories.tsx +76 -0
- package/src/stories/prompt-input-variants.stories.tsx +456 -0
- package/src/stories/streaming-response.stories.tsx +438 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/stories/typography.stories.tsx +78 -0
- package/src/types.ts +47 -0
- package/src/ui/action-icons.ts +52 -0
- package/src/ui/avatar.stories.tsx +103 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +86 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +145 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.stories.tsx +69 -0
- package/src/ui/collapsible.tsx +125 -0
- package/src/ui/dropdown.stories.tsx +59 -0
- package/src/ui/dropdown.tsx +196 -0
- package/src/ui/hover-card.stories.tsx +77 -0
- package/src/ui/hover-card.test.tsx +30 -0
- package/src/ui/hover-card.tsx +172 -0
- package/src/ui/overlay.stories.tsx +115 -0
- package/src/ui/overlay.tsx +158 -0
- package/src/ui/popover.stories.tsx +81 -0
- package/src/ui/popover.test.tsx +99 -0
- package/src/ui/popover.tsx +92 -0
- package/src/ui/resizable.stories.tsx +236 -0
- package/src/ui/resizable.tsx +576 -0
- package/src/ui/scroll-area.stories.tsx +50 -0
- package/src/ui/scroll-area.tsx +15 -0
- package/src/ui/separator.stories.tsx +81 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +337 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/switch.stories.tsx +51 -0
- package/src/ui/switch.test.tsx +59 -0
- package/src/ui/switch.tsx +62 -0
- package/src/ui/textarea.stories.tsx +76 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +74 -0
- package/src/ui/tooltip.tsx +68 -0
- package/src/utils/cn.ts +24 -0
- package/theme.css +187 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Avatar } from './avatar';
|
|
3
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Solid (Advanced)/Primitives/Avatar',
|
|
7
|
+
component: Avatar,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A small, rounded **avatar** that renders an image when `src` is provided and falls back to short initials otherwise.',
|
|
15
|
+
'**When to use:** to identify the author of a message, a conversation participant, or the current user in a header or list.',
|
|
16
|
+
'**How to use:** always pass a `fallback` (1–2 initials) and a `size`. Provide `src`/`alt` when you have an image; if the image is missing or fails, the `fallback` text shows instead.',
|
|
17
|
+
'**Placement:** message rows (next to assistant/user content), conversation list items, account menus, and headers.',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
src: {
|
|
23
|
+
control: 'text',
|
|
24
|
+
description: 'Image URL. When omitted, the `fallback` initials are shown.',
|
|
25
|
+
},
|
|
26
|
+
alt: {
|
|
27
|
+
control: 'text',
|
|
28
|
+
description: 'Alt text for the image. Defaults to `fallback` when not set.',
|
|
29
|
+
},
|
|
30
|
+
fallback: {
|
|
31
|
+
control: 'text',
|
|
32
|
+
description: 'Initials shown when there is no image (required).',
|
|
33
|
+
},
|
|
34
|
+
size: {
|
|
35
|
+
control: 'select',
|
|
36
|
+
options: ['sm', 'md', 'lg'],
|
|
37
|
+
description: 'Avatar diameter preset.',
|
|
38
|
+
table: { defaultValue: { summary: 'md' } },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
args: {
|
|
42
|
+
fallback: 'JD',
|
|
43
|
+
size: 'md',
|
|
44
|
+
},
|
|
45
|
+
render: (args) => <Avatar {...args} />,
|
|
46
|
+
} satisfies Meta<typeof Avatar>;
|
|
47
|
+
|
|
48
|
+
export default meta;
|
|
49
|
+
type Story = StoryObj<typeof meta>;
|
|
50
|
+
|
|
51
|
+
const IMPORT = `import { Avatar } from '@kitn.ai/ui';`;
|
|
52
|
+
const src = (code: string) => ({
|
|
53
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Interactive playground — tweak the controls to explore image vs. fallback and sizes. */
|
|
57
|
+
export const Playground: Story = {
|
|
58
|
+
...src(`<Avatar fallback="JD" size="md" />`),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const WithFallback: Story = {
|
|
62
|
+
args: { fallback: 'JD', size: 'md' },
|
|
63
|
+
...src(`<Avatar fallback="JD" size="md" />`),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const WithImage: Story = {
|
|
67
|
+
args: {
|
|
68
|
+
src: 'https://api.dicebear.com/7.x/initials/svg?seed=JD',
|
|
69
|
+
alt: 'John Doe',
|
|
70
|
+
fallback: 'JD',
|
|
71
|
+
},
|
|
72
|
+
...src(`<Avatar
|
|
73
|
+
src="https://api.dicebear.com/7.x/initials/svg?seed=JD"
|
|
74
|
+
alt="John Doe"
|
|
75
|
+
fallback="JD"
|
|
76
|
+
/>`),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const Small: Story = {
|
|
80
|
+
args: { size: 'sm', fallback: 'S' },
|
|
81
|
+
...src(`<Avatar size="sm" fallback="S" />`),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const Large: Story = {
|
|
85
|
+
args: { size: 'lg', fallback: 'LG' },
|
|
86
|
+
...src(`<Avatar size="lg" fallback="LG" />`),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Every size side by side (showcase — not driven by controls). */
|
|
90
|
+
export const AllSizes: Story = {
|
|
91
|
+
render: () => (
|
|
92
|
+
<div class="flex items-center gap-3">
|
|
93
|
+
<Avatar size="sm" fallback="SM" />
|
|
94
|
+
<Avatar size="md" fallback="MD" />
|
|
95
|
+
<Avatar size="lg" fallback="LG" />
|
|
96
|
+
</div>
|
|
97
|
+
),
|
|
98
|
+
...src(`<div class="flex items-center gap-3">
|
|
99
|
+
<Avatar size="sm" fallback="SM" />
|
|
100
|
+
<Avatar size="md" fallback="MD" />
|
|
101
|
+
<Avatar size="lg" fallback="LG" />
|
|
102
|
+
</div>`),
|
|
103
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type JSX, splitProps, Show } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
export interface AvatarProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
src?: string;
|
|
6
|
+
alt?: string;
|
|
7
|
+
fallback: string;
|
|
8
|
+
size?: 'sm' | 'md' | 'lg';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const sizeClasses = { sm: 'h-6 w-6 text-[10px]', md: 'h-8 w-8 text-xs', lg: 'h-10 w-10 text-sm' };
|
|
12
|
+
|
|
13
|
+
export function Avatar(props: AvatarProps) {
|
|
14
|
+
const [local, rest] = splitProps(props, ['src', 'alt', 'fallback', 'size', 'class']);
|
|
15
|
+
const size = () => local.size ?? 'md';
|
|
16
|
+
return (
|
|
17
|
+
<div class={cn('inline-flex items-center justify-center rounded-md bg-accent font-semibold text-accent-foreground flex-shrink-0', sizeClasses[size()], local.class)} {...rest}>
|
|
18
|
+
<Show when={local.src} fallback={<span>{local.fallback}</span>}>
|
|
19
|
+
<img src={local.src} alt={local.alt ?? local.fallback} class="h-full w-full rounded-md object-cover" />
|
|
20
|
+
</Show>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Badge } from './badge';
|
|
3
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Solid (Advanced)/Primitives/Badge',
|
|
7
|
+
component: Badge,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A compact pill **badge** for short status text, counts, or citation markers, rendered as an inline `<span>`.',
|
|
15
|
+
'**When to use:** to annotate a count (unread, results), tag a status/label, or mark an inline source citation in assistant output.',
|
|
16
|
+
'**How to use:** choose a `variant` (`default` label, `count` numeric pill, `citation` clickable source marker) and pass the text or number as children.',
|
|
17
|
+
'**Placement:** inline with message text (citations), next to titles or list items (labels), and on toolbar/icon buttons (counts).',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
variant: {
|
|
23
|
+
control: 'select',
|
|
24
|
+
options: ['default', 'count', 'citation'],
|
|
25
|
+
description: 'Visual style: neutral label, numeric count pill, or clickable citation marker.',
|
|
26
|
+
table: { defaultValue: { summary: 'default' } },
|
|
27
|
+
},
|
|
28
|
+
children: {
|
|
29
|
+
control: 'text',
|
|
30
|
+
description: 'Badge content — short text or a number.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
variant: 'default',
|
|
35
|
+
children: 'Default badge',
|
|
36
|
+
},
|
|
37
|
+
render: (args) => <Badge {...args} />,
|
|
38
|
+
} satisfies Meta<typeof Badge>;
|
|
39
|
+
|
|
40
|
+
export default meta;
|
|
41
|
+
type Story = StoryObj<typeof meta>;
|
|
42
|
+
|
|
43
|
+
const IMPORT = `import { Badge } from '@kitn.ai/ui';`;
|
|
44
|
+
const src = (code: string) => ({
|
|
45
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** Interactive playground — switch the variant and edit the content. */
|
|
49
|
+
export const Playground: Story = {
|
|
50
|
+
...src(`<Badge variant="default">Default badge</Badge>`),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const Default: Story = {
|
|
54
|
+
args: { variant: 'default', children: 'Default badge' },
|
|
55
|
+
...src(`<Badge variant="default">Default badge</Badge>`),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Count: Story = {
|
|
59
|
+
args: { variant: 'count', children: '12' },
|
|
60
|
+
...src(`<Badge variant="count">12</Badge>`),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const Citation: Story = {
|
|
64
|
+
args: { variant: 'citation', children: '1' },
|
|
65
|
+
...src(`<Badge variant="citation">1</Badge>`),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** All variants side by side (showcase — not driven by controls). */
|
|
69
|
+
export const AllVariants: Story = {
|
|
70
|
+
render: () => (
|
|
71
|
+
<div class="flex items-center gap-3">
|
|
72
|
+
<Badge variant="default">Default</Badge>
|
|
73
|
+
<Badge variant="count">5</Badge>
|
|
74
|
+
<Badge variant="citation">1</Badge>
|
|
75
|
+
<Badge variant="citation">2</Badge>
|
|
76
|
+
<Badge variant="citation">3</Badge>
|
|
77
|
+
</div>
|
|
78
|
+
),
|
|
79
|
+
...src(`<div class="flex items-center gap-3">
|
|
80
|
+
<Badge variant="default">Default</Badge>
|
|
81
|
+
<Badge variant="count">5</Badge>
|
|
82
|
+
<Badge variant="citation">1</Badge>
|
|
83
|
+
<Badge variant="citation">2</Badge>
|
|
84
|
+
<Badge variant="citation">3</Badge>
|
|
85
|
+
</div>`),
|
|
86
|
+
};
|
package/src/ui/badge.tsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
|
|
5
|
+
const badgeVariants = cva('inline-flex items-center justify-center rounded-full text-xs font-medium min-h-5 min-w-5', {
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: 'bg-muted text-muted-foreground px-2 py-0.5',
|
|
9
|
+
count: 'bg-muted text-muted-foreground h-5 px-1.5',
|
|
10
|
+
citation: 'bg-primary text-primary-foreground px-1.5 py-0.5 cursor-pointer',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
defaultVariants: { variant: 'default' },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export interface BadgeProps extends JSX.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof badgeVariants> {}
|
|
17
|
+
|
|
18
|
+
export function Badge(props: BadgeProps) {
|
|
19
|
+
const [local, rest] = splitProps(props, ['variant', 'class', 'children']);
|
|
20
|
+
return <span class={cn(badgeVariants({ variant: local.variant }), local.class)} {...rest}>{local.children}</span>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { Button } from './button';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convention exemplar — every component story should follow this shape:
|
|
8
|
+
* `component`, a description, `argTypes` (controls), `args` (defaults incl.
|
|
9
|
+
* `fn()` for events), a `Playground` story rendered from args, plus showcase
|
|
10
|
+
* stories for notable variations.
|
|
11
|
+
*/
|
|
12
|
+
const meta = {
|
|
13
|
+
title: 'Solid (Advanced)/Primitives/Button',
|
|
14
|
+
component: Button,
|
|
15
|
+
tags: ['autodocs'],
|
|
16
|
+
parameters: {
|
|
17
|
+
layout: 'padded',
|
|
18
|
+
docs: {
|
|
19
|
+
description: componentDescription([
|
|
20
|
+
'A clickable button with style **variants** and **sizes**, built on a native `<button>` (all standard button attributes pass through).',
|
|
21
|
+
'**When to use:** any user-triggered action — submitting input, toolbar/icon actions, confirming or dismissing. Use `default` for the primary action, `ghost`/`outline` for secondary or low-emphasis actions.',
|
|
22
|
+
'**How to use:** set `variant` and `size`, pass label or an icon as children, and wire `onClick`. For icon-only buttons use `size="icon"` / `"icon-sm"` and include an `aria-label`.',
|
|
23
|
+
'**Placement:** prompt action bars, message action rows, dialogs, toolbars, and empty-state CTAs.',
|
|
24
|
+
]),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
argTypes: {
|
|
28
|
+
variant: {
|
|
29
|
+
control: 'select',
|
|
30
|
+
options: ['default', 'ghost', 'outline'],
|
|
31
|
+
description: 'Visual emphasis of the button.',
|
|
32
|
+
table: { defaultValue: { summary: 'default' } },
|
|
33
|
+
},
|
|
34
|
+
size: {
|
|
35
|
+
control: 'select',
|
|
36
|
+
options: ['sm', 'md', 'lg', 'icon', 'icon-sm'],
|
|
37
|
+
description: 'Height/padding preset. `icon` / `icon-sm` are square for icon-only buttons.',
|
|
38
|
+
table: { defaultValue: { summary: 'md' } },
|
|
39
|
+
},
|
|
40
|
+
disabled: {
|
|
41
|
+
control: 'boolean',
|
|
42
|
+
description: 'Disables interaction and dims the button.',
|
|
43
|
+
},
|
|
44
|
+
children: {
|
|
45
|
+
control: 'text',
|
|
46
|
+
description: 'Button content — text or an icon element.',
|
|
47
|
+
},
|
|
48
|
+
onClick: {
|
|
49
|
+
action: 'click',
|
|
50
|
+
description: 'Fired when the button is clicked.',
|
|
51
|
+
table: { category: 'Events' },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
args: {
|
|
55
|
+
variant: 'default',
|
|
56
|
+
size: 'md',
|
|
57
|
+
disabled: false,
|
|
58
|
+
children: 'Click me',
|
|
59
|
+
onClick: fn(),
|
|
60
|
+
},
|
|
61
|
+
render: (args) => <Button {...args} />,
|
|
62
|
+
} satisfies Meta<typeof Button>;
|
|
63
|
+
|
|
64
|
+
export default meta;
|
|
65
|
+
type Story = StoryObj<typeof meta>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Attach a clean, copy-paste-ready SolidJS snippet to a story. SolidJS stories
|
|
69
|
+
* can't auto-serialize an args-spread render (it shows `{}`), so we provide real
|
|
70
|
+
* usage code (with the import line, so it's truly paste-ready) that the docs
|
|
71
|
+
* "Show code" / "Copy code" buttons surface. `language: 'tsx'` labels it as SolidJS.
|
|
72
|
+
*
|
|
73
|
+
* Note: `Button` is a SolidJS *component* (a scoped import), not a global custom
|
|
74
|
+
* element, so the unprefixed name can't conflict with anything — alias on import
|
|
75
|
+
* if a host already has a `Button`. Only the web components (`<kai-chat>`, …)
|
|
76
|
+
* are prefixed, because those claim global custom-element tag names.
|
|
77
|
+
*/
|
|
78
|
+
const IMPORT = `import { Button } from '@kitn.ai/ui';`;
|
|
79
|
+
const src = (code: string) => ({
|
|
80
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Interactive playground — tweak the controls to explore every combination. */
|
|
84
|
+
export const Playground: Story = {
|
|
85
|
+
...src(`<Button variant="default" size="md" onClick={() => {}}>Click me</Button>`),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const Ghost: Story = {
|
|
89
|
+
args: { variant: 'ghost', children: 'Ghost' },
|
|
90
|
+
...src(`<Button variant="ghost">Ghost</Button>`),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const Outline: Story = {
|
|
94
|
+
args: { variant: 'outline', children: 'Outline' },
|
|
95
|
+
...src(`<Button variant="outline">Outline</Button>`),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const Small: Story = {
|
|
99
|
+
args: { size: 'sm', children: 'Small' },
|
|
100
|
+
...src(`<Button size="sm">Small</Button>`),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const Large: Story = {
|
|
104
|
+
args: { size: 'lg', children: 'Large' },
|
|
105
|
+
...src(`<Button size="lg">Large</Button>`),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const Disabled: Story = {
|
|
109
|
+
args: { disabled: true, children: 'Disabled' },
|
|
110
|
+
...src(`<Button disabled>Disabled</Button>`),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const PlusIcon = () => (
|
|
114
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
115
|
+
<line x1="12" y1="5" x2="12" y2="19" />
|
|
116
|
+
<line x1="5" y1="12" x2="19" y2="12" />
|
|
117
|
+
</svg>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
export const Icon: Story = {
|
|
121
|
+
args: { size: 'icon', children: <PlusIcon />, 'aria-label': 'Add' } as never,
|
|
122
|
+
...src(`<Button size="icon" aria-label="Add">\n <PlusIcon />\n</Button>`),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** All variants and sizes side by side (showcase — not driven by controls). */
|
|
126
|
+
export const AllVariants: Story = {
|
|
127
|
+
render: () => (
|
|
128
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
129
|
+
<Button variant="default">Default</Button>
|
|
130
|
+
<Button variant="ghost">Ghost</Button>
|
|
131
|
+
<Button variant="outline">Outline</Button>
|
|
132
|
+
<Button variant="default" size="sm">Small</Button>
|
|
133
|
+
<Button variant="default" size="lg">Large</Button>
|
|
134
|
+
<Button variant="default" size="icon" aria-label="Add"><PlusIcon /></Button>
|
|
135
|
+
</div>
|
|
136
|
+
),
|
|
137
|
+
...src(`<div class="flex flex-wrap items-center gap-3">
|
|
138
|
+
<Button variant="default">Default</Button>
|
|
139
|
+
<Button variant="ghost">Ghost</Button>
|
|
140
|
+
<Button variant="outline">Outline</Button>
|
|
141
|
+
<Button size="sm">Small</Button>
|
|
142
|
+
<Button size="lg">Large</Button>
|
|
143
|
+
<Button size="icon" aria-label="Add"><PlusIcon /></Button>
|
|
144
|
+
</div>`),
|
|
145
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
|
|
5
|
+
const buttonVariants = cva(
|
|
6
|
+
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50',
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
|
11
|
+
ghost: 'hover:bg-muted text-foreground',
|
|
12
|
+
outline: 'bg-muted/50 text-foreground hover:bg-muted',
|
|
13
|
+
destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
|
14
|
+
},
|
|
15
|
+
size: {
|
|
16
|
+
sm: 'h-8 px-3 text-xs rounded-md',
|
|
17
|
+
md: 'h-9 px-4 text-sm',
|
|
18
|
+
lg: 'h-10 px-6 text-sm',
|
|
19
|
+
icon: 'h-9 w-9',
|
|
20
|
+
'icon-sm': 'h-7 w-7',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: { variant: 'default', size: 'md' },
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export interface ButtonProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}
|
|
28
|
+
|
|
29
|
+
export function Button(props: ButtonProps) {
|
|
30
|
+
const [local, rest] = splitProps(props, ['variant', 'size', 'class', 'children']);
|
|
31
|
+
return (
|
|
32
|
+
<button class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)} {...rest}>
|
|
33
|
+
{local.children}
|
|
34
|
+
</button>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { buttonVariants };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from './collapsible';
|
|
3
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Solid (Advanced)/Primitives/Collapsible',
|
|
7
|
+
component: Collapsible,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
description: componentDescription([
|
|
13
|
+
'A two-state disclosure that expands and collapses a region of content, animating height via a CSS `grid-template-rows` `0fr` → `1fr` transition (no JS measurement, no layout thrash). The trigger carries `aria-expanded`/`aria-controls` and the collapsed content is `inert`, so it is removed from tab order and the accessibility tree. Works controlled (`open` + `onOpenChange`) or uncontrolled (`defaultOpen`).',
|
|
14
|
+
'**When to use:** to hide secondary detail behind a toggle — a reasoning/"chain of thought" panel, a tool-call payload, an expandable conversation group, an FAQ row.',
|
|
15
|
+
'**How to use:** wrap `CollapsibleTrigger` and `CollapsibleContent` in a `Collapsible`. The trigger renders a `<button>` by default; pass `as` to render a custom element.',
|
|
16
|
+
]),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
render: () => <CollapsibleDemo defaultOpen />,
|
|
20
|
+
} satisfies Meta<typeof Collapsible>;
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof meta>;
|
|
24
|
+
|
|
25
|
+
const IMPORT = `import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@kitn.ai/ui';`;
|
|
26
|
+
const src = (code: string) => ({
|
|
27
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function CollapsibleDemo(props: { defaultOpen?: boolean }) {
|
|
31
|
+
return (
|
|
32
|
+
<Collapsible defaultOpen={props.defaultOpen} class="w-80 rounded-lg border border-border">
|
|
33
|
+
<CollapsibleTrigger class="group flex w-full items-center justify-between px-3 py-2 text-sm font-medium text-foreground">
|
|
34
|
+
<span>Reasoning</span>
|
|
35
|
+
<svg
|
|
36
|
+
class="size-4 text-muted-foreground transition-transform duration-200 group-data-[expanded]:rotate-180"
|
|
37
|
+
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
|
38
|
+
>
|
|
39
|
+
<polyline points="6 9 12 15 18 9" />
|
|
40
|
+
</svg>
|
|
41
|
+
</CollapsibleTrigger>
|
|
42
|
+
<CollapsibleContent>
|
|
43
|
+
<p class="px-3 pb-3 text-sm text-muted-foreground">
|
|
44
|
+
First I parsed the request, then checked the available tools, and finally
|
|
45
|
+
composed the answer. This panel is removed from the tab order while collapsed.
|
|
46
|
+
</p>
|
|
47
|
+
</CollapsibleContent>
|
|
48
|
+
</Collapsible>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Toggle the trigger to expand/collapse. The chevron rotates via the `data-expanded` attribute. */
|
|
53
|
+
export const Playground: Story = {
|
|
54
|
+
...src(`<Collapsible defaultOpen>
|
|
55
|
+
<CollapsibleTrigger>Reasoning</CollapsibleTrigger>
|
|
56
|
+
<CollapsibleContent>
|
|
57
|
+
<p>First I parsed the request, then checked the available tools…</p>
|
|
58
|
+
</CollapsibleContent>
|
|
59
|
+
</Collapsible>`),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Starts collapsed. */
|
|
63
|
+
export const InitiallyClosed: Story = {
|
|
64
|
+
render: () => <CollapsibleDemo />,
|
|
65
|
+
...src(`<Collapsible>
|
|
66
|
+
<CollapsibleTrigger>Reasoning</CollapsibleTrigger>
|
|
67
|
+
<CollapsibleContent>…</CollapsibleContent>
|
|
68
|
+
</Collapsible>`),
|
|
69
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
createSignal,
|
|
5
|
+
createUniqueId,
|
|
6
|
+
splitProps,
|
|
7
|
+
type JSX,
|
|
8
|
+
type Accessor,
|
|
9
|
+
} from 'solid-js';
|
|
10
|
+
import { cn } from '../utils/cn';
|
|
11
|
+
|
|
12
|
+
// Extend SolidJS JSX to allow `bool:inert` (forces setAttribute so jsdom reflects it as an attribute).
|
|
13
|
+
declare module 'solid-js' {
|
|
14
|
+
namespace JSX {
|
|
15
|
+
interface ExplicitBoolAttributes {
|
|
16
|
+
inert: boolean;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface CollapsibleCtx {
|
|
22
|
+
open: Accessor<boolean>;
|
|
23
|
+
toggle: () => void;
|
|
24
|
+
contentId: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Ctx = createContext<CollapsibleCtx>();
|
|
28
|
+
|
|
29
|
+
const useCollapsible = () => {
|
|
30
|
+
const c = useContext(Ctx);
|
|
31
|
+
if (!c) throw new Error('Collapsible parts must be used within <Collapsible>');
|
|
32
|
+
return c;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function Collapsible(props: {
|
|
36
|
+
open?: boolean;
|
|
37
|
+
defaultOpen?: boolean;
|
|
38
|
+
onOpenChange?: (open: boolean) => void;
|
|
39
|
+
children: JSX.Element;
|
|
40
|
+
class?: string;
|
|
41
|
+
}) {
|
|
42
|
+
const [local, rest] = splitProps(props, ['open', 'defaultOpen', 'onOpenChange', 'children', 'class']);
|
|
43
|
+
const [uncontrolled, setUncontrolled] = createSignal(local.defaultOpen ?? false);
|
|
44
|
+
const isControlled = () => local.open !== undefined;
|
|
45
|
+
const open = () => (isControlled() ? !!local.open : uncontrolled());
|
|
46
|
+
const toggle = () => {
|
|
47
|
+
const next = !open();
|
|
48
|
+
if (!isControlled()) setUncontrolled(next);
|
|
49
|
+
local.onOpenChange?.(next);
|
|
50
|
+
};
|
|
51
|
+
const contentId = createUniqueId();
|
|
52
|
+
return (
|
|
53
|
+
<Ctx.Provider value={{ open, toggle, contentId }}>
|
|
54
|
+
<div
|
|
55
|
+
class={local.class}
|
|
56
|
+
{...rest}
|
|
57
|
+
data-expanded={open() ? '' : undefined}
|
|
58
|
+
data-closed={open() ? undefined : ''}
|
|
59
|
+
data-state={open() ? 'open' : 'closed'}
|
|
60
|
+
>
|
|
61
|
+
{local.children}
|
|
62
|
+
</div>
|
|
63
|
+
</Ctx.Provider>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function CollapsibleTrigger(props: {
|
|
68
|
+
children?: JSX.Element;
|
|
69
|
+
class?: string;
|
|
70
|
+
as?: (props: Record<string, any>) => JSX.Element;
|
|
71
|
+
onClick?: JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent>;
|
|
72
|
+
[k: string]: any;
|
|
73
|
+
}) {
|
|
74
|
+
const ctx = useCollapsible();
|
|
75
|
+
const [local, rest] = splitProps(props, ['children', 'class', 'as', 'onClick']);
|
|
76
|
+
|
|
77
|
+
const triggerProps = () => ({
|
|
78
|
+
type: 'button' as const,
|
|
79
|
+
'aria-expanded': ctx.open(),
|
|
80
|
+
'aria-controls': ctx.contentId,
|
|
81
|
+
'data-expanded': ctx.open() ? '' : undefined,
|
|
82
|
+
'data-closed': ctx.open() ? undefined : '',
|
|
83
|
+
'data-state': ctx.open() ? 'open' : 'closed',
|
|
84
|
+
onClick: (e: MouseEvent) => {
|
|
85
|
+
if (typeof local.onClick === 'function') {
|
|
86
|
+
(local.onClick as (e: MouseEvent) => void)(e);
|
|
87
|
+
}
|
|
88
|
+
ctx.toggle();
|
|
89
|
+
},
|
|
90
|
+
class: local.class,
|
|
91
|
+
...rest,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
{local.as
|
|
97
|
+
? local.as(triggerProps() as any)
|
|
98
|
+
: (
|
|
99
|
+
<button {...triggerProps()}>
|
|
100
|
+
{local.children}
|
|
101
|
+
</button>
|
|
102
|
+
)}
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function CollapsibleContent(props: { children?: JSX.Element; class?: string; [k: string]: any }) {
|
|
108
|
+
const ctx = useCollapsible();
|
|
109
|
+
const [local, rest] = splitProps(props, ['children', 'class']);
|
|
110
|
+
return (
|
|
111
|
+
<div
|
|
112
|
+
{...rest}
|
|
113
|
+
id={ctx.contentId}
|
|
114
|
+
data-expanded={ctx.open() ? '' : undefined}
|
|
115
|
+
data-closed={ctx.open() ? undefined : ''}
|
|
116
|
+
class={cn(
|
|
117
|
+
'grid transition-[grid-template-rows] duration-200 ease-out',
|
|
118
|
+
ctx.open() ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]',
|
|
119
|
+
)}
|
|
120
|
+
bool:inert={!ctx.open()}
|
|
121
|
+
>
|
|
122
|
+
<div class={cn('overflow-hidden', local.class)}>{local.children}</div>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { createSignal } from 'solid-js';
|
|
3
|
+
import { Dropdown, DropdownTrigger, DropdownContent, DropdownItem } from './dropdown';
|
|
4
|
+
import { buttonVariants } from './button';
|
|
5
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Solid (Advanced)/Primitives/Dropdown',
|
|
9
|
+
component: Dropdown,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: 'padded',
|
|
13
|
+
docs: {
|
|
14
|
+
description: componentDescription([
|
|
15
|
+
'An accessible menu that opens from a trigger, built on the kit\'s DIY overlay core (no third-party dependency). Implements the WAI-ARIA menu-button pattern: `aria-haspopup`/`aria-expanded` wiring, roving focus with Arrow/Home/End, type-ahead, Escape/outside-click dismissal, and focus return to the trigger. Portals into the active shadow root and resolves focus through `getRootNode()` so roving focus works inside web components.',
|
|
16
|
+
'**When to use:** for a list of *actions* or single-choice options triggered by a button — overflow "⋯" menus, model pickers, scope selectors. For hover-only context use `HoverCard`; for a label use `Tooltip`.',
|
|
17
|
+
'**How to use:** compose `Dropdown` › `DropdownTrigger` (the button) + `DropdownContent` › one `DropdownItem` per action. Give each item an `onSelect` handler — selecting also closes the menu.',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
render: () => <DropdownDemo />,
|
|
22
|
+
} satisfies Meta<typeof Dropdown>;
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof meta>;
|
|
26
|
+
|
|
27
|
+
const IMPORT = `import { Dropdown, DropdownTrigger, DropdownContent, DropdownItem } from '@kitn.ai/ui';`;
|
|
28
|
+
const src = (code: string) => ({
|
|
29
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function DropdownDemo() {
|
|
33
|
+
const [last, setLast] = createSignal<string>();
|
|
34
|
+
return (
|
|
35
|
+
<div class="space-y-3">
|
|
36
|
+
<Dropdown>
|
|
37
|
+
<DropdownTrigger class={buttonVariants({ variant: 'outline' })}>Actions ▾</DropdownTrigger>
|
|
38
|
+
<DropdownContent>
|
|
39
|
+
<DropdownItem onSelect={() => setLast('Rename')}>Rename</DropdownItem>
|
|
40
|
+
<DropdownItem onSelect={() => setLast('Duplicate')}>Duplicate</DropdownItem>
|
|
41
|
+
<DropdownItem onSelect={() => setLast('Archive')}>Archive</DropdownItem>
|
|
42
|
+
</DropdownContent>
|
|
43
|
+
</Dropdown>
|
|
44
|
+
<p class="text-xs text-muted-foreground">Last selected: {last() ?? '—'}</p>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Click the trigger (or focus it and press ↓ / Enter) to open the menu; Arrow keys move, Escape closes. */
|
|
50
|
+
export const Playground: Story = {
|
|
51
|
+
...src(`<Dropdown>
|
|
52
|
+
<DropdownTrigger class={buttonVariants({ variant: 'outline' })}>Actions ▾</DropdownTrigger>
|
|
53
|
+
<DropdownContent>
|
|
54
|
+
<DropdownItem onSelect={() => rename()}>Rename</DropdownItem>
|
|
55
|
+
<DropdownItem onSelect={() => duplicate()}>Duplicate</DropdownItem>
|
|
56
|
+
<DropdownItem onSelect={() => archive()}>Archive</DropdownItem>
|
|
57
|
+
</DropdownContent>
|
|
58
|
+
</Dropdown>`),
|
|
59
|
+
};
|