@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,81 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Separator } from './separator';
|
|
3
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Solid (Advanced)/Primitives/Separator',
|
|
7
|
+
component: Separator,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A thin **divider** line (a `role="separator"` element) that visually splits content either horizontally or vertically.',
|
|
15
|
+
'**When to use:** to separate stacked sections, group items in a menu/list, or divide inline controls in a toolbar.',
|
|
16
|
+
'**How to use:** set `orientation` to `horizontal` (full-width line) or `vertical` (full-height line). For a vertical separator, give the parent a height so the line has something to fill.',
|
|
17
|
+
'**Placement:** between message groups, in dropdown/menu sections, header toolbars, and between sidebar regions.',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
orientation: {
|
|
23
|
+
control: 'select',
|
|
24
|
+
options: ['horizontal', 'vertical'],
|
|
25
|
+
description: 'Direction of the divider line.',
|
|
26
|
+
table: { defaultValue: { summary: 'horizontal' } },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
args: {
|
|
30
|
+
orientation: 'horizontal',
|
|
31
|
+
},
|
|
32
|
+
render: (args) => (
|
|
33
|
+
<div class="w-64 p-4">
|
|
34
|
+
<p class="text-sm text-foreground mb-3">Above</p>
|
|
35
|
+
<Separator {...args} />
|
|
36
|
+
<p class="text-sm text-foreground mt-3">Below</p>
|
|
37
|
+
</div>
|
|
38
|
+
),
|
|
39
|
+
} satisfies Meta<typeof Separator>;
|
|
40
|
+
|
|
41
|
+
export default meta;
|
|
42
|
+
type Story = StoryObj<typeof meta>;
|
|
43
|
+
|
|
44
|
+
const IMPORT = `import { Separator } from '@kitn.ai/ui';`;
|
|
45
|
+
const src = (code: string) => ({
|
|
46
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** Interactive playground — flip the orientation. */
|
|
50
|
+
export const Playground: Story = {
|
|
51
|
+
...src(`<Separator orientation="horizontal" />`),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const Horizontal: Story = {
|
|
55
|
+
args: { orientation: 'horizontal' },
|
|
56
|
+
...src(`<div class="w-64 p-4">
|
|
57
|
+
<p class="text-sm mb-3">Above</p>
|
|
58
|
+
<Separator />
|
|
59
|
+
<p class="text-sm mt-3">Below</p>
|
|
60
|
+
</div>`),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Vertical divider — needs a parent with a fixed height (showcase). */
|
|
64
|
+
export const Vertical: Story = {
|
|
65
|
+
render: () => (
|
|
66
|
+
<div class="flex items-center gap-3 p-4">
|
|
67
|
+
<span class="text-sm text-foreground">Left</span>
|
|
68
|
+
<div class="h-6">
|
|
69
|
+
<Separator orientation="vertical" />
|
|
70
|
+
</div>
|
|
71
|
+
<span class="text-sm text-foreground">Right</span>
|
|
72
|
+
</div>
|
|
73
|
+
),
|
|
74
|
+
...src(`<div class="flex items-center gap-3 p-4">
|
|
75
|
+
<span class="text-sm">Left</span>
|
|
76
|
+
<div class="h-6">
|
|
77
|
+
<Separator orientation="vertical" />
|
|
78
|
+
</div>
|
|
79
|
+
<span class="text-sm">Right</span>
|
|
80
|
+
</div>`),
|
|
81
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
export interface SeparatorProps extends JSX.HTMLAttributes<HTMLDivElement> { orientation?: 'horizontal' | 'vertical'; }
|
|
5
|
+
|
|
6
|
+
export function Separator(props: SeparatorProps) {
|
|
7
|
+
const [local, rest] = splitProps(props, ['orientation', 'class']);
|
|
8
|
+
const isVertical = () => local.orientation === 'vertical';
|
|
9
|
+
return <div role="separator" class={cn('shrink-0 bg-border', isVertical() ? 'h-full w-px' : 'h-px w-full', local.class)} {...rest} />;
|
|
10
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Skeleton } from './skeleton';
|
|
3
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Solid (Advanced)/Primitives/Skeleton',
|
|
7
|
+
component: Skeleton,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A pulsing **placeholder** block used to indicate loading content. It has no shape of its own — size and rounding come from the `class` you pass.',
|
|
15
|
+
'**When to use:** while content (messages, lists, cards, tool output) is loading, to preserve layout and signal progress without a spinner.',
|
|
16
|
+
'**How to use:** compose one or more `Skeleton` elements and set width/height/rounding via utility classes (e.g. `class="h-4 w-3/4"`). Build skeletons that mirror the real layout they replace.',
|
|
17
|
+
'**Placement:** message bubbles, conversation lists, code blocks, tool calls, input areas, and full-page loading states.',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
class: {
|
|
23
|
+
control: 'text',
|
|
24
|
+
description: 'Utility classes that set the size and rounding of the placeholder.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
args: {
|
|
28
|
+
class: 'h-4 w-64',
|
|
29
|
+
},
|
|
30
|
+
render: (args) => <Skeleton {...args} />,
|
|
31
|
+
} satisfies Meta<typeof Skeleton>;
|
|
32
|
+
|
|
33
|
+
export default meta;
|
|
34
|
+
type Story = StoryObj<typeof meta>;
|
|
35
|
+
|
|
36
|
+
const IMPORT = `import { Skeleton } from '@kitn.ai/ui';`;
|
|
37
|
+
const src = (code: string) => ({
|
|
38
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** Interactive playground — edit `class` to resize the placeholder. */
|
|
42
|
+
export const Playground: Story = {
|
|
43
|
+
...src(`<Skeleton class="h-4 w-64" />`),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const Basic: Story = {
|
|
47
|
+
render: () => (
|
|
48
|
+
<div class="space-y-3 w-80">
|
|
49
|
+
<Skeleton class="h-4 w-full" />
|
|
50
|
+
<Skeleton class="h-4 w-3/4" />
|
|
51
|
+
<Skeleton class="h-4 w-1/2" />
|
|
52
|
+
</div>
|
|
53
|
+
),
|
|
54
|
+
...src(`<div class="space-y-3 w-80">
|
|
55
|
+
<Skeleton class="h-4 w-full" />
|
|
56
|
+
<Skeleton class="h-4 w-3/4" />
|
|
57
|
+
<Skeleton class="h-4 w-1/2" />
|
|
58
|
+
</div>`),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const MessageBubble: Story = {
|
|
62
|
+
name: 'Message Bubble',
|
|
63
|
+
render: () => (
|
|
64
|
+
<div class="space-y-6 w-full max-w-2xl">
|
|
65
|
+
{/* User message skeleton */}
|
|
66
|
+
<div class="flex justify-end">
|
|
67
|
+
<Skeleton class="h-12 w-64 rounded-3xl" />
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{/* Assistant message skeleton */}
|
|
71
|
+
<div class="flex gap-3 items-start">
|
|
72
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
73
|
+
<div class="flex-1 space-y-2">
|
|
74
|
+
<Skeleton class="h-4 w-full" />
|
|
75
|
+
<Skeleton class="h-4 w-full" />
|
|
76
|
+
<Skeleton class="h-4 w-5/6" />
|
|
77
|
+
<Skeleton class="h-4 w-2/3" />
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
),
|
|
82
|
+
...src(`<div class="space-y-6 w-full max-w-2xl">
|
|
83
|
+
<div class="flex justify-end">
|
|
84
|
+
<Skeleton class="h-12 w-64 rounded-3xl" />
|
|
85
|
+
</div>
|
|
86
|
+
<div class="flex gap-3 items-start">
|
|
87
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
88
|
+
<div class="flex-1 space-y-2">
|
|
89
|
+
<Skeleton class="h-4 w-full" />
|
|
90
|
+
<Skeleton class="h-4 w-full" />
|
|
91
|
+
<Skeleton class="h-4 w-5/6" />
|
|
92
|
+
<Skeleton class="h-4 w-2/3" />
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</div>`),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const MessageWithCode: Story = {
|
|
99
|
+
name: 'Message with Code Block',
|
|
100
|
+
render: () => (
|
|
101
|
+
<div class="flex gap-3 items-start w-full max-w-2xl">
|
|
102
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
103
|
+
<div class="flex-1 space-y-3">
|
|
104
|
+
<div class="space-y-2">
|
|
105
|
+
<Skeleton class="h-4 w-full" />
|
|
106
|
+
<Skeleton class="h-4 w-4/5" />
|
|
107
|
+
</div>
|
|
108
|
+
{/* Code block skeleton */}
|
|
109
|
+
<Skeleton class="h-32 w-full rounded-xl" />
|
|
110
|
+
<div class="space-y-2">
|
|
111
|
+
<Skeleton class="h-4 w-full" />
|
|
112
|
+
<Skeleton class="h-4 w-3/5" />
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
),
|
|
117
|
+
...src(`<div class="flex gap-3 items-start w-full max-w-2xl">
|
|
118
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
119
|
+
<div class="flex-1 space-y-3">
|
|
120
|
+
<div class="space-y-2">
|
|
121
|
+
<Skeleton class="h-4 w-full" />
|
|
122
|
+
<Skeleton class="h-4 w-4/5" />
|
|
123
|
+
</div>
|
|
124
|
+
<Skeleton class="h-32 w-full rounded-xl" />
|
|
125
|
+
<div class="space-y-2">
|
|
126
|
+
<Skeleton class="h-4 w-full" />
|
|
127
|
+
<Skeleton class="h-4 w-3/5" />
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
</div>`),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const ConversationList: Story = {
|
|
134
|
+
name: 'Conversation List',
|
|
135
|
+
render: () => (
|
|
136
|
+
<div class="w-64 space-y-1">
|
|
137
|
+
{/* Section header */}
|
|
138
|
+
<Skeleton class="h-3 w-12 mb-2" />
|
|
139
|
+
{[1, 2, 3].map(() => (
|
|
140
|
+
<div class="flex items-center gap-2 px-2 py-2">
|
|
141
|
+
<Skeleton class="h-4 w-4 rounded shrink-0" />
|
|
142
|
+
<Skeleton class="h-4 flex-1" />
|
|
143
|
+
</div>
|
|
144
|
+
))}
|
|
145
|
+
{/* Section header */}
|
|
146
|
+
<Skeleton class="h-3 w-16 mt-4 mb-2" />
|
|
147
|
+
{[1, 2].map(() => (
|
|
148
|
+
<div class="flex items-center gap-2 px-2 py-2">
|
|
149
|
+
<Skeleton class="h-4 w-4 rounded shrink-0" />
|
|
150
|
+
<Skeleton class="h-4 flex-1" />
|
|
151
|
+
</div>
|
|
152
|
+
))}
|
|
153
|
+
</div>
|
|
154
|
+
),
|
|
155
|
+
...src(`<div class="w-64 space-y-1">
|
|
156
|
+
<Skeleton class="h-3 w-12 mb-2" />
|
|
157
|
+
{[1, 2, 3].map(() => (
|
|
158
|
+
<div class="flex items-center gap-2 px-2 py-2">
|
|
159
|
+
<Skeleton class="h-4 w-4 rounded shrink-0" />
|
|
160
|
+
<Skeleton class="h-4 flex-1" />
|
|
161
|
+
</div>
|
|
162
|
+
))}
|
|
163
|
+
</div>`),
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const ToolCall: Story = {
|
|
167
|
+
name: 'Tool Call',
|
|
168
|
+
render: () => (
|
|
169
|
+
<div class="w-full max-w-2xl">
|
|
170
|
+
<div class="border border-border rounded-xl overflow-hidden">
|
|
171
|
+
{/* Tool header */}
|
|
172
|
+
<div class="flex items-center gap-2 px-3 py-2.5">
|
|
173
|
+
<Skeleton class="h-4 w-4 rounded-full" />
|
|
174
|
+
<Skeleton class="h-4 w-32" />
|
|
175
|
+
<Skeleton class="h-5 w-20 rounded-full" />
|
|
176
|
+
</div>
|
|
177
|
+
{/* Tool body */}
|
|
178
|
+
<div class="border-t border-border p-3 space-y-3">
|
|
179
|
+
<div>
|
|
180
|
+
<Skeleton class="h-3 w-10 mb-2" />
|
|
181
|
+
<Skeleton class="h-20 w-full rounded" />
|
|
182
|
+
</div>
|
|
183
|
+
<div>
|
|
184
|
+
<Skeleton class="h-3 w-12 mb-2" />
|
|
185
|
+
<Skeleton class="h-16 w-full rounded" />
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
),
|
|
191
|
+
...src(`<div class="w-full max-w-2xl">
|
|
192
|
+
<div class="border border-border rounded-xl overflow-hidden">
|
|
193
|
+
<div class="flex items-center gap-2 px-3 py-2.5">
|
|
194
|
+
<Skeleton class="h-4 w-4 rounded-full" />
|
|
195
|
+
<Skeleton class="h-4 w-32" />
|
|
196
|
+
<Skeleton class="h-5 w-20 rounded-full" />
|
|
197
|
+
</div>
|
|
198
|
+
<div class="border-t border-border p-3 space-y-3">
|
|
199
|
+
<Skeleton class="h-3 w-10 mb-2" />
|
|
200
|
+
<Skeleton class="h-20 w-full rounded" />
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
</div>`),
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export const Card: Story = {
|
|
207
|
+
name: 'Content Card',
|
|
208
|
+
render: () => (
|
|
209
|
+
<div class="w-72">
|
|
210
|
+
<Skeleton class="h-40 w-full rounded-xl mb-3" />
|
|
211
|
+
<div class="flex gap-3">
|
|
212
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
213
|
+
<div class="flex-1 space-y-2">
|
|
214
|
+
<Skeleton class="h-4 w-full" />
|
|
215
|
+
<Skeleton class="h-3 w-24" />
|
|
216
|
+
<Skeleton class="h-3 w-32" />
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
),
|
|
221
|
+
...src(`<div class="w-72">
|
|
222
|
+
<Skeleton class="h-40 w-full rounded-xl mb-3" />
|
|
223
|
+
<div class="flex gap-3">
|
|
224
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
225
|
+
<div class="flex-1 space-y-2">
|
|
226
|
+
<Skeleton class="h-4 w-full" />
|
|
227
|
+
<Skeleton class="h-3 w-24" />
|
|
228
|
+
<Skeleton class="h-3 w-32" />
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
</div>`),
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export const InputArea: Story = {
|
|
235
|
+
name: 'Input Area',
|
|
236
|
+
render: () => (
|
|
237
|
+
<div class="w-full max-w-2xl">
|
|
238
|
+
<div class="border border-border rounded-2xl p-3 space-y-3">
|
|
239
|
+
<Skeleton class="h-10 w-full rounded-lg" />
|
|
240
|
+
<div class="flex items-center justify-between">
|
|
241
|
+
<div class="flex gap-2">
|
|
242
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
243
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
244
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
245
|
+
</div>
|
|
246
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
),
|
|
251
|
+
...src(`<div class="w-full max-w-2xl">
|
|
252
|
+
<div class="border border-border rounded-2xl p-3 space-y-3">
|
|
253
|
+
<Skeleton class="h-10 w-full rounded-lg" />
|
|
254
|
+
<div class="flex items-center justify-between">
|
|
255
|
+
<div class="flex gap-2">
|
|
256
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
257
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
258
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
259
|
+
</div>
|
|
260
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
</div>`),
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export const FullChat: Story = {
|
|
267
|
+
name: 'Full Chat Layout',
|
|
268
|
+
render: () => (
|
|
269
|
+
<div class="flex w-full max-w-4xl h-96 border border-border rounded-xl overflow-hidden">
|
|
270
|
+
{/* Sidebar */}
|
|
271
|
+
<div class="w-56 border-r border-border p-3 space-y-3 shrink-0">
|
|
272
|
+
<Skeleton class="h-8 w-full rounded-lg" />
|
|
273
|
+
<div class="space-y-1 mt-4">
|
|
274
|
+
<Skeleton class="h-3 w-12 mb-2" />
|
|
275
|
+
{[1, 2, 3].map(() => (
|
|
276
|
+
<Skeleton class="h-8 w-full rounded-lg" />
|
|
277
|
+
))}
|
|
278
|
+
<Skeleton class="h-3 w-16 mt-3 mb-2" />
|
|
279
|
+
{[1, 2].map(() => (
|
|
280
|
+
<Skeleton class="h-8 w-full rounded-lg" />
|
|
281
|
+
))}
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
{/* Main */}
|
|
286
|
+
<div class="flex-1 flex flex-col">
|
|
287
|
+
{/* Header */}
|
|
288
|
+
<div class="flex items-center justify-between px-4 py-3 border-b border-border">
|
|
289
|
+
<Skeleton class="h-4 w-48" />
|
|
290
|
+
<div class="flex gap-2">
|
|
291
|
+
<Skeleton class="h-8 w-28 rounded-lg" />
|
|
292
|
+
<Skeleton class="h-8 w-8 rounded-full" />
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
|
|
296
|
+
{/* Messages */}
|
|
297
|
+
<div class="flex-1 p-4 space-y-6 overflow-hidden">
|
|
298
|
+
<div class="flex justify-end">
|
|
299
|
+
<Skeleton class="h-10 w-52 rounded-3xl" />
|
|
300
|
+
</div>
|
|
301
|
+
<div class="flex gap-3 items-start">
|
|
302
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
303
|
+
<div class="flex-1 space-y-2">
|
|
304
|
+
<Skeleton class="h-4 w-full" />
|
|
305
|
+
<Skeleton class="h-4 w-5/6" />
|
|
306
|
+
<Skeleton class="h-4 w-2/3" />
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
{/* Input */}
|
|
312
|
+
<div class="p-3">
|
|
313
|
+
<Skeleton class="h-14 w-full rounded-2xl" />
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
),
|
|
318
|
+
...src(`<div class="flex w-full max-w-4xl h-96 border rounded-xl overflow-hidden">
|
|
319
|
+
<div class="w-56 border-r p-3 space-y-3 shrink-0">
|
|
320
|
+
<Skeleton class="h-8 w-full rounded-lg" />
|
|
321
|
+
</div>
|
|
322
|
+
<div class="flex-1 flex flex-col">
|
|
323
|
+
<div class="flex-1 p-4 space-y-6">
|
|
324
|
+
<div class="flex gap-3 items-start">
|
|
325
|
+
<Skeleton class="h-8 w-8 rounded-full shrink-0" />
|
|
326
|
+
<div class="flex-1 space-y-2">
|
|
327
|
+
<Skeleton class="h-4 w-full" />
|
|
328
|
+
<Skeleton class="h-4 w-5/6" />
|
|
329
|
+
</div>
|
|
330
|
+
</div>
|
|
331
|
+
</div>
|
|
332
|
+
<div class="p-3">
|
|
333
|
+
<Skeleton class="h-14 w-full rounded-2xl" />
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
</div>`),
|
|
337
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
export interface SkeletonProps extends JSX.HTMLAttributes<HTMLDivElement> {}
|
|
5
|
+
|
|
6
|
+
function Skeleton(props: SkeletonProps) {
|
|
7
|
+
const [local, rest] = splitProps(props, ['class']);
|
|
8
|
+
return (
|
|
9
|
+
<div
|
|
10
|
+
class={cn('animate-pulse rounded-md bg-muted', local.class)}
|
|
11
|
+
{...rest}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { Skeleton };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { Switch, type SwitchProps } from './switch';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Solid (Advanced)/Primitives/Switch',
|
|
8
|
+
component: Switch,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'padded',
|
|
12
|
+
docs: {
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A toggle **switch** (`role="switch"`) for an immediate on/off setting, built on a native `<button>`.',
|
|
15
|
+
'**When to use:** a preference that applies the moment it flips — "Temporary chat", notifications, a feature flag. For a labelled choice submitted with a form, prefer a checkbox.',
|
|
16
|
+
'**How to use:** uncontrolled via `defaultChecked`, or controlled via `checked` + `onChange`. Operable with Space/Enter. Pass `label` for the accessible name.',
|
|
17
|
+
'**Placement:** settings rows, preference panels, and popover menus such as a chat header model menu.',
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
checked: { control: 'boolean', description: 'Controlled checked state. Drive it from `onChange`.' },
|
|
23
|
+
defaultChecked: { control: 'boolean', description: 'Initial state when uncontrolled.' },
|
|
24
|
+
disabled: { control: 'boolean', description: 'Disable interaction.' },
|
|
25
|
+
label: { control: 'text', description: 'Accessible label.' },
|
|
26
|
+
},
|
|
27
|
+
args: { label: 'Temporary chat', onChange: fn() },
|
|
28
|
+
} satisfies Meta<typeof Switch>;
|
|
29
|
+
|
|
30
|
+
export default meta;
|
|
31
|
+
type Story = StoryObj<typeof meta>;
|
|
32
|
+
|
|
33
|
+
/** Off by default; click or press Space to toggle. */
|
|
34
|
+
export const Playground: Story = {};
|
|
35
|
+
|
|
36
|
+
/** Starts on via `defaultChecked`. */
|
|
37
|
+
export const On: Story = { args: { defaultChecked: true } };
|
|
38
|
+
|
|
39
|
+
/** Non-interactive. */
|
|
40
|
+
export const Disabled: Story = { args: { disabled: true } };
|
|
41
|
+
|
|
42
|
+
/** The common shape: a labelled settings row with the switch trailing. */
|
|
43
|
+
export const SettingsRow: Story = {
|
|
44
|
+
name: 'In a settings row',
|
|
45
|
+
render: (args: SwitchProps) => (
|
|
46
|
+
<div style={{ display: 'flex', 'align-items': 'center', 'justify-content': 'space-between', gap: '2rem', width: '18rem' }}>
|
|
47
|
+
<span style={{ 'font-size': '14px' }}>Temporary chat</span>
|
|
48
|
+
<Switch {...args} />
|
|
49
|
+
</div>
|
|
50
|
+
),
|
|
51
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import '@testing-library/jest-dom/vitest';
|
|
3
|
+
import { render, cleanup, fireEvent } from '@solidjs/testing-library';
|
|
4
|
+
import { Switch } from './switch';
|
|
5
|
+
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
describe('Switch', () => {
|
|
9
|
+
it('renders a switch role, off by default', () => {
|
|
10
|
+
const { getByRole } = render(() => <Switch label="Temporary chat" />);
|
|
11
|
+
const sw = getByRole('switch');
|
|
12
|
+
expect(sw).toHaveAttribute('aria-checked', 'false');
|
|
13
|
+
expect(sw).toHaveAttribute('aria-label', 'Temporary chat');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('honours defaultChecked for the initial (uncontrolled) state', () => {
|
|
17
|
+
const { getByRole } = render(() => <Switch defaultChecked />);
|
|
18
|
+
expect(getByRole('switch')).toHaveAttribute('aria-checked', 'true');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('toggles on click and reports the new state', () => {
|
|
22
|
+
const onChange = vi.fn();
|
|
23
|
+
const { getByRole } = render(() => <Switch onChange={onChange} />);
|
|
24
|
+
const sw = getByRole('switch');
|
|
25
|
+
fireEvent.click(sw);
|
|
26
|
+
expect(sw).toHaveAttribute('aria-checked', 'true');
|
|
27
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
28
|
+
fireEvent.click(sw);
|
|
29
|
+
expect(sw).toHaveAttribute('aria-checked', 'false');
|
|
30
|
+
expect(onChange).toHaveBeenLastCalledWith(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('toggles with the keyboard (Space / Enter)', () => {
|
|
34
|
+
const onChange = vi.fn();
|
|
35
|
+
const { getByRole } = render(() => <Switch onChange={onChange} />);
|
|
36
|
+
fireEvent.keyDown(getByRole('switch'), { key: ' ' });
|
|
37
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('is controlled when `checked` is set — defers state to the parent', () => {
|
|
41
|
+
const onChange = vi.fn();
|
|
42
|
+
const { getByRole } = render(() => <Switch checked={false} onChange={onChange} />);
|
|
43
|
+
const sw = getByRole('switch');
|
|
44
|
+
fireEvent.click(sw);
|
|
45
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
46
|
+
// controlled: stays off until the parent flips `checked`
|
|
47
|
+
expect(sw).toHaveAttribute('aria-checked', 'false');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('does not toggle when disabled', () => {
|
|
51
|
+
const onChange = vi.fn();
|
|
52
|
+
const { getByRole } = render(() => <Switch disabled onChange={onChange} />);
|
|
53
|
+
const sw = getByRole('switch');
|
|
54
|
+
fireEvent.click(sw);
|
|
55
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
56
|
+
expect(sw).toHaveAttribute('aria-checked', 'false');
|
|
57
|
+
expect(sw).toBeDisabled();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createSignal } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
export interface SwitchProps {
|
|
5
|
+
/** Controlled checked state. When set, the component defers state to the
|
|
6
|
+
* parent — drive it from `onChange`. Omit for uncontrolled (internal) state. */
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** Initial checked state when uncontrolled. */
|
|
9
|
+
defaultChecked?: boolean;
|
|
10
|
+
/** Disable interaction. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Accessible label for the control. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** Fires with the next checked state on toggle. */
|
|
15
|
+
onChange?: (checked: boolean) => void;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A toggle switch (`role="switch"`). Controlled via `checked`, or uncontrolled
|
|
21
|
+
* from `defaultChecked`. Keyboard-operable (Space/Enter) and theme-tokened.
|
|
22
|
+
*/
|
|
23
|
+
export function Switch(props: SwitchProps) {
|
|
24
|
+
const [internal, setInternal] = createSignal(props.defaultChecked ?? false);
|
|
25
|
+
const isControlled = () => props.checked !== undefined;
|
|
26
|
+
const isOn = () => (isControlled() ? !!props.checked : internal());
|
|
27
|
+
|
|
28
|
+
const toggle = () => {
|
|
29
|
+
if (props.disabled) return;
|
|
30
|
+
const next = !isOn();
|
|
31
|
+
if (!isControlled()) setInternal(next);
|
|
32
|
+
props.onChange?.(next);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
role="switch"
|
|
39
|
+
aria-checked={isOn()}
|
|
40
|
+
aria-label={props.label}
|
|
41
|
+
disabled={props.disabled}
|
|
42
|
+
onClick={toggle}
|
|
43
|
+
onKeyDown={(e) => {
|
|
44
|
+
if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); toggle(); }
|
|
45
|
+
}}
|
|
46
|
+
class={cn(
|
|
47
|
+
'relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full transition-colors',
|
|
48
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
49
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
50
|
+
isOn() ? 'bg-primary' : 'bg-muted',
|
|
51
|
+
props.class,
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
<span
|
|
55
|
+
class={cn(
|
|
56
|
+
'inline-block h-4 w-4 rounded-full bg-white shadow transition-transform',
|
|
57
|
+
isOn() ? 'translate-x-[1.125rem]' : 'translate-x-0.5',
|
|
58
|
+
)}
|
|
59
|
+
/>
|
|
60
|
+
</button>
|
|
61
|
+
);
|
|
62
|
+
}
|