@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,202 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { onMount } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
7
|
+
declare module 'solid-js' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'kai-scroll-button': JSX.HTMLAttributes<HTMLElement> & {
|
|
12
|
+
for?: string;
|
|
13
|
+
variant?: string;
|
|
14
|
+
size?: string;
|
|
15
|
+
'on:kai-scroll'?: (e: CustomEvent) => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
22
|
+
<div id="my-chat" style="height:300px; overflow-y:auto; border:1px solid #eee; padding:16px">
|
|
23
|
+
<!-- scrollable content -->
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<!-- Button targets the scroll container by id -->
|
|
27
|
+
<kai-scroll-button for="my-chat"></kai-scroll-button>
|
|
28
|
+
|
|
29
|
+
<script type="module">
|
|
30
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
31
|
+
|
|
32
|
+
const btn = document.querySelector('kai-scroll-button');
|
|
33
|
+
btn.addEventListener('kai-scroll', () => console.log('scrolled to bottom'));
|
|
34
|
+
</script>`;
|
|
35
|
+
|
|
36
|
+
const meta = {
|
|
37
|
+
title: 'Components/ScrollButton',
|
|
38
|
+
tags: ['autodocs'],
|
|
39
|
+
argTypes: argTypesFor('kai-scroll-button'),
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'fullscreen',
|
|
42
|
+
docs: {
|
|
43
|
+
description: specDescription('kai-scroll-button', [
|
|
44
|
+
'`<kai-scroll-button>` is the framework-agnostic **web component** for a floating "scroll to bottom" button — visible when the target container is scrolled up, hidden when already at the bottom. Isolated in **Shadow DOM**.',
|
|
45
|
+
'**When to use:** placing a scroll-to-bottom affordance next to any long scrollable list or chat thread outside SolidJS. In SolidJS, use the `ScrollButton` primitive inside a `ChatContainerRoot`.',
|
|
46
|
+
'**Wiring the scroll target:** set the `for` attribute to the `id` of the scrollable container (mirrors the `<label for="...">` convention). When `for` is omitted the element walks upward to the nearest scrollable ancestor — useful when it is nested inside the container.',
|
|
47
|
+
'**Emitted events:** `kai-scroll` (no detail) fires each time the button is clicked and `scrollToBottom()` is called.',
|
|
48
|
+
'See the **Code** tab for HTML usage.',
|
|
49
|
+
]),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
} satisfies Meta;
|
|
53
|
+
|
|
54
|
+
export default meta;
|
|
55
|
+
type Story = StoryObj;
|
|
56
|
+
|
|
57
|
+
/** Scroll-to-bottom button controlled by a sibling scrollable container via `for`. */
|
|
58
|
+
export const Default: Story = {
|
|
59
|
+
render: () => {
|
|
60
|
+
const items = Array.from({ length: 30 }, (_, i) => `Message ${i + 1}`);
|
|
61
|
+
return (
|
|
62
|
+
<div style={{ padding: '24px', position: 'relative', width: '360px' }}>
|
|
63
|
+
<div
|
|
64
|
+
id="scroll-demo"
|
|
65
|
+
tabindex="0"
|
|
66
|
+
role="region"
|
|
67
|
+
aria-label="Messages"
|
|
68
|
+
style={{
|
|
69
|
+
height: '300px',
|
|
70
|
+
'overflow-y': 'auto',
|
|
71
|
+
border: '1px solid var(--color-border, #e2e8f0)',
|
|
72
|
+
'border-radius': '8px',
|
|
73
|
+
padding: '12px',
|
|
74
|
+
display: 'flex',
|
|
75
|
+
'flex-direction': 'column',
|
|
76
|
+
gap: '8px',
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
{items.map((msg) => (
|
|
80
|
+
<div
|
|
81
|
+
style={{
|
|
82
|
+
padding: '8px 12px',
|
|
83
|
+
background: 'var(--color-muted, #f1f5f9)',
|
|
84
|
+
'border-radius': '6px',
|
|
85
|
+
'font-size': '14px',
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
{msg}
|
|
89
|
+
</div>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
{/* Positioned overlay in the bottom-right of the container */}
|
|
93
|
+
<div
|
|
94
|
+
style={{
|
|
95
|
+
position: 'absolute',
|
|
96
|
+
bottom: '36px',
|
|
97
|
+
right: '36px',
|
|
98
|
+
'pointer-events': 'none',
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<div style={{ 'pointer-events': 'auto' }}>
|
|
102
|
+
<kai-scroll-button
|
|
103
|
+
for="scroll-demo"
|
|
104
|
+
on:kai-scroll={() => console.log('kai-scroll fired')}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Nested inside the scroll container — no `for` needed; ancestor walk finds it. */
|
|
115
|
+
export const AncestorWalk: Story = {
|
|
116
|
+
render: () => {
|
|
117
|
+
const items = Array.from({ length: 30 }, (_, i) => `Entry ${i + 1}`);
|
|
118
|
+
return (
|
|
119
|
+
<div style={{ padding: '24px', width: '360px' }}>
|
|
120
|
+
<div
|
|
121
|
+
style={{
|
|
122
|
+
height: '300px',
|
|
123
|
+
'overflow-y': 'auto',
|
|
124
|
+
border: '1px solid var(--color-border, #e2e8f0)',
|
|
125
|
+
'border-radius': '8px',
|
|
126
|
+
padding: '12px',
|
|
127
|
+
position: 'relative',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{items.map((entry) => (
|
|
131
|
+
<div
|
|
132
|
+
style={{
|
|
133
|
+
padding: '8px 12px',
|
|
134
|
+
background: 'var(--color-muted, #f1f5f9)',
|
|
135
|
+
'border-radius': '6px',
|
|
136
|
+
'font-size': '14px',
|
|
137
|
+
'margin-bottom': '8px',
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{entry}
|
|
141
|
+
</div>
|
|
142
|
+
))}
|
|
143
|
+
{/* No `for` — element is a child of the scrollable container */}
|
|
144
|
+
<div
|
|
145
|
+
style={{
|
|
146
|
+
position: 'sticky',
|
|
147
|
+
bottom: '8px',
|
|
148
|
+
display: 'flex',
|
|
149
|
+
'justify-content': 'center',
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<kai-scroll-button />
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Variant and size showcase. */
|
|
161
|
+
export const Variants: Story = {
|
|
162
|
+
render: () => {
|
|
163
|
+
const items = Array.from({ length: 20 }, (_, i) => `Row ${i + 1}`);
|
|
164
|
+
return (
|
|
165
|
+
<div
|
|
166
|
+
style={{
|
|
167
|
+
display: 'flex',
|
|
168
|
+
gap: '32px',
|
|
169
|
+
padding: '24px',
|
|
170
|
+
'align-items': 'flex-start',
|
|
171
|
+
'flex-wrap': 'wrap',
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
{(['outline', 'ghost', 'default'] as const).map((variant) => (
|
|
175
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '8px', 'align-items': 'center' }}>
|
|
176
|
+
<div
|
|
177
|
+
tabindex="0"
|
|
178
|
+
role="region"
|
|
179
|
+
aria-label={`${variant} scroll demo`}
|
|
180
|
+
style={{
|
|
181
|
+
height: '200px',
|
|
182
|
+
width: '200px',
|
|
183
|
+
'overflow-y': 'auto',
|
|
184
|
+
border: '1px solid var(--color-border, #e2e8f0)',
|
|
185
|
+
'border-radius': '8px',
|
|
186
|
+
padding: '8px',
|
|
187
|
+
position: 'relative',
|
|
188
|
+
}}
|
|
189
|
+
id={`variant-demo-${variant}`}
|
|
190
|
+
>
|
|
191
|
+
{items.map((r) => (
|
|
192
|
+
<div style={{ padding: '4px 8px', 'font-size': '13px' }}>{r}</div>
|
|
193
|
+
))}
|
|
194
|
+
</div>
|
|
195
|
+
<kai-scroll-button for={`variant-demo-${variant}`} variant={variant} />
|
|
196
|
+
<code style={{ 'font-size': '11px', opacity: 0.6 }}>{variant}</code>
|
|
197
|
+
</div>
|
|
198
|
+
))}
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the `kai-scroll-button` scroll-target resolution logic.
|
|
3
|
+
*
|
|
4
|
+
* Strategy: `defineWebComponent` requires a real browser environment
|
|
5
|
+
* (Constructable Stylesheets, shadow roots) and is not suitable for jsdom.
|
|
6
|
+
* Instead we:
|
|
7
|
+
* 1. Test the `findScrollableAncestor` helper in isolation — it only uses
|
|
8
|
+
* DOM APIs that jsdom provides.
|
|
9
|
+
* 2. Test the Solid `Button` + visibility-toggle logic that drives the
|
|
10
|
+
* show/hide animation, using the underlying component directly (mirrors
|
|
11
|
+
* the pattern in `prompt-suggestions.declarative.test.tsx`).
|
|
12
|
+
*/
|
|
13
|
+
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
14
|
+
import '@testing-library/jest-dom/vitest';
|
|
15
|
+
import { render, cleanup, fireEvent } from '@solidjs/testing-library';
|
|
16
|
+
import { createSignal } from 'solid-js';
|
|
17
|
+
import { cn } from '../utils/cn';
|
|
18
|
+
import { Button } from '../ui/button';
|
|
19
|
+
import { ChevronDown } from 'lucide-solid';
|
|
20
|
+
|
|
21
|
+
afterEach(cleanup);
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// findScrollableAncestor — re-implemented inline so we can test without
|
|
25
|
+
// importing the full element (which would call defineWebComponent).
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
function findScrollableAncestor(startEl: HTMLElement): HTMLElement | null {
|
|
29
|
+
let el: HTMLElement | null = startEl.parentElement;
|
|
30
|
+
while (el && el !== document.documentElement) {
|
|
31
|
+
const style = getComputedStyle(el);
|
|
32
|
+
const overflow = style.overflow + style.overflowY;
|
|
33
|
+
if (/auto|scroll/.test(overflow) && el.scrollHeight > el.clientHeight) {
|
|
34
|
+
return el;
|
|
35
|
+
}
|
|
36
|
+
el = el.parentElement;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('findScrollableAncestor', () => {
|
|
42
|
+
it('returns null when no scrollable ancestor exists', () => {
|
|
43
|
+
const wrapper = document.createElement('div');
|
|
44
|
+
const child = document.createElement('span');
|
|
45
|
+
wrapper.appendChild(child);
|
|
46
|
+
document.body.appendChild(wrapper);
|
|
47
|
+
expect(findScrollableAncestor(child)).toBeNull();
|
|
48
|
+
document.body.removeChild(wrapper);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns the first scrollable ancestor', () => {
|
|
52
|
+
const scrollable = document.createElement('div');
|
|
53
|
+
scrollable.style.overflow = 'auto';
|
|
54
|
+
// jsdom doesn't do layout, so scrollHeight === clientHeight by default.
|
|
55
|
+
// Force a difference by mocking.
|
|
56
|
+
Object.defineProperty(scrollable, 'scrollHeight', { value: 500, configurable: true });
|
|
57
|
+
Object.defineProperty(scrollable, 'clientHeight', { value: 300, configurable: true });
|
|
58
|
+
|
|
59
|
+
const child = document.createElement('div');
|
|
60
|
+
scrollable.appendChild(child);
|
|
61
|
+
document.body.appendChild(scrollable);
|
|
62
|
+
|
|
63
|
+
expect(findScrollableAncestor(child)).toBe(scrollable);
|
|
64
|
+
document.body.removeChild(scrollable);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('skips non-scrollable ancestors', () => {
|
|
68
|
+
const nonScrollable = document.createElement('div');
|
|
69
|
+
const scrollable = document.createElement('div');
|
|
70
|
+
scrollable.style.overflowY = 'scroll';
|
|
71
|
+
Object.defineProperty(scrollable, 'scrollHeight', { value: 500, configurable: true });
|
|
72
|
+
Object.defineProperty(scrollable, 'clientHeight', { value: 300, configurable: true });
|
|
73
|
+
|
|
74
|
+
const child = document.createElement('span');
|
|
75
|
+
nonScrollable.appendChild(child);
|
|
76
|
+
scrollable.appendChild(nonScrollable);
|
|
77
|
+
document.body.appendChild(scrollable);
|
|
78
|
+
|
|
79
|
+
expect(findScrollableAncestor(child)).toBe(scrollable);
|
|
80
|
+
document.body.removeChild(scrollable);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Visibility toggle logic — ScrollButtonUI mirrors the render logic inside
|
|
86
|
+
// kai-scroll-button's facade.
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
/** Minimal SolidJS component that mirrors the button render in scroll-button.tsx. */
|
|
90
|
+
function ScrollButtonUI(props: {
|
|
91
|
+
isAtBottom: () => boolean;
|
|
92
|
+
onClick: () => void;
|
|
93
|
+
}) {
|
|
94
|
+
return (
|
|
95
|
+
<Button
|
|
96
|
+
variant="outline"
|
|
97
|
+
size="icon"
|
|
98
|
+
aria-label="Scroll to bottom"
|
|
99
|
+
class={cn(
|
|
100
|
+
'rounded-full transition-all duration-150 ease-out',
|
|
101
|
+
!props.isAtBottom()
|
|
102
|
+
? 'translate-y-0 scale-100 opacity-100'
|
|
103
|
+
: 'pointer-events-none translate-y-4 scale-95 opacity-0',
|
|
104
|
+
)}
|
|
105
|
+
onClick={props.onClick}
|
|
106
|
+
>
|
|
107
|
+
<ChevronDown class="h-5 w-5" />
|
|
108
|
+
</Button>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe('scroll button visibility logic', () => {
|
|
113
|
+
it('is visually hidden when at bottom (has opacity-0 class)', () => {
|
|
114
|
+
const { getByRole } = render(() => (
|
|
115
|
+
<ScrollButtonUI isAtBottom={() => true} onClick={() => {}} />
|
|
116
|
+
));
|
|
117
|
+
const btn = getByRole('button', { name: /scroll to bottom/i });
|
|
118
|
+
expect(btn.className).toMatch(/opacity-0/);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('is visible when not at bottom (has opacity-100 class)', () => {
|
|
122
|
+
const { getByRole } = render(() => (
|
|
123
|
+
<ScrollButtonUI isAtBottom={() => false} onClick={() => {}} />
|
|
124
|
+
));
|
|
125
|
+
const btn = getByRole('button', { name: /scroll to bottom/i });
|
|
126
|
+
expect(btn.className).toMatch(/opacity-100/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('calls onClick when the button is clicked', () => {
|
|
130
|
+
const onClick = vi.fn();
|
|
131
|
+
const { getByRole } = render(() => (
|
|
132
|
+
<ScrollButtonUI isAtBottom={() => false} onClick={onClick} />
|
|
133
|
+
));
|
|
134
|
+
fireEvent.click(getByRole('button', { name: /scroll to bottom/i }));
|
|
135
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('reacts to isAtBottom signal changes', () => {
|
|
139
|
+
const [atBottom, setAtBottom] = createSignal(false);
|
|
140
|
+
const { getByRole } = render(() => (
|
|
141
|
+
<ScrollButtonUI isAtBottom={atBottom} onClick={() => {}} />
|
|
142
|
+
));
|
|
143
|
+
const btn = getByRole('button', { name: /scroll to bottom/i });
|
|
144
|
+
expect(btn.className).toMatch(/opacity-100/);
|
|
145
|
+
setAtBottom(true);
|
|
146
|
+
expect(btn.className).toMatch(/opacity-0/);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createSignal, onCleanup, onMount } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Button } from '../ui/button';
|
|
4
|
+
import { ChevronDown } from 'lucide-solid';
|
|
5
|
+
import { defineWebComponent } from './define';
|
|
6
|
+
|
|
7
|
+
interface Props extends Record<string, unknown> {
|
|
8
|
+
/** CSS id of the scroll container to control. When omitted the element
|
|
9
|
+
* walks up the DOM (outside its own shadow root) to find the nearest
|
|
10
|
+
* scrollable ancestor. Mirrors the `for` convention of `<label for="...">`. */
|
|
11
|
+
for?: string;
|
|
12
|
+
/** Button visual variant: `'outline' | 'ghost' | 'default'`. Defaults to
|
|
13
|
+
* `'outline'`. */
|
|
14
|
+
variant?: 'outline' | 'ghost' | 'default';
|
|
15
|
+
/** Button size token. Defaults to `'icon'` (square). */
|
|
16
|
+
size?: 'sm' | 'md' | 'lg' | 'icon' | 'icon-sm';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Events fired by `<kai-scroll-button>`. */
|
|
20
|
+
interface Events {
|
|
21
|
+
/** Emitted when the user clicks the button and `scrollToBottom()` is
|
|
22
|
+
* called. Carries no detail — consumers use it to know a manual scroll
|
|
23
|
+
* occurred. */
|
|
24
|
+
'kai-scroll': void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SCROLL_THRESHOLD = 50;
|
|
28
|
+
|
|
29
|
+
/** Walk the composed tree upwards from `startEl` (outside shadow roots) to
|
|
30
|
+
* find the nearest scrollable ancestor. */
|
|
31
|
+
function findScrollableAncestor(startEl: HTMLElement): HTMLElement | null {
|
|
32
|
+
let el: HTMLElement | null = startEl.parentElement;
|
|
33
|
+
while (el && el !== document.documentElement) {
|
|
34
|
+
const style = getComputedStyle(el);
|
|
35
|
+
const overflow = style.overflow + style.overflowY;
|
|
36
|
+
if (/auto|scroll/.test(overflow) && el.scrollHeight > el.clientHeight) {
|
|
37
|
+
return el;
|
|
38
|
+
}
|
|
39
|
+
el = el.parentElement;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `<kai-scroll-button>` — a floating "scroll to bottom" button for any
|
|
46
|
+
* scrollable container. It is visible when the container is scrolled up
|
|
47
|
+
* (hidden when at the bottom) and scrolls the container to the bottom on
|
|
48
|
+
* click.
|
|
49
|
+
*
|
|
50
|
+
* **Wiring the scroll target** — use the `for` attribute to point at the
|
|
51
|
+
* container by its DOM `id`:
|
|
52
|
+
* ```html
|
|
53
|
+
* <div id="my-chat" style="overflow:auto; height:400px">...</div>
|
|
54
|
+
* <kai-scroll-button for="my-chat"></kai-scroll-button>
|
|
55
|
+
* ```
|
|
56
|
+
* When `for` is omitted the element walks upward from its host to the nearest
|
|
57
|
+
* scrollable ancestor — useful when it is slotted or nested inside the
|
|
58
|
+
* container.
|
|
59
|
+
*
|
|
60
|
+
* Emits `kai-scroll` (no detail) each time the button is clicked.
|
|
61
|
+
*/
|
|
62
|
+
defineWebComponent<Props, Events>('kai-scroll-button', {
|
|
63
|
+
for: undefined,
|
|
64
|
+
variant: 'outline',
|
|
65
|
+
size: 'icon',
|
|
66
|
+
}, (props, { element, dispatch }) => {
|
|
67
|
+
const [isAtBottom, setIsAtBottom] = createSignal(true);
|
|
68
|
+
let containerEl: HTMLElement | null = null;
|
|
69
|
+
let cleanupFns: (() => void)[] = [];
|
|
70
|
+
|
|
71
|
+
function checkIfAtBottom() {
|
|
72
|
+
if (!containerEl) return;
|
|
73
|
+
const { scrollTop, scrollHeight, clientHeight } = containerEl;
|
|
74
|
+
setIsAtBottom(scrollHeight - scrollTop - clientHeight < SCROLL_THRESHOLD);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function scrollToBottom() {
|
|
78
|
+
if (!containerEl) return;
|
|
79
|
+
containerEl.scrollTo({ top: containerEl.scrollHeight, behavior: 'smooth' });
|
|
80
|
+
setIsAtBottom(true);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function attach(el: HTMLElement) {
|
|
84
|
+
containerEl = el;
|
|
85
|
+
el.addEventListener('scroll', checkIfAtBottom, { passive: true });
|
|
86
|
+
checkIfAtBottom();
|
|
87
|
+
cleanupFns.push(() => el.removeEventListener('scroll', checkIfAtBottom));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function detach() {
|
|
91
|
+
cleanupFns.forEach((fn) => fn());
|
|
92
|
+
cleanupFns = [];
|
|
93
|
+
containerEl = null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onMount(() => {
|
|
97
|
+
// Resolve the scroll container: `for` id → nearest scrollable ancestor.
|
|
98
|
+
const target = props.for
|
|
99
|
+
? document.getElementById(props.for)
|
|
100
|
+
: findScrollableAncestor(element);
|
|
101
|
+
|
|
102
|
+
if (target) attach(target);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
onCleanup(detach);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<Button
|
|
109
|
+
variant={props.variant ?? 'outline'}
|
|
110
|
+
size={props.size ?? 'icon'}
|
|
111
|
+
aria-label="Scroll to bottom"
|
|
112
|
+
class={cn(
|
|
113
|
+
'rounded-full transition-all duration-150 ease-out',
|
|
114
|
+
!isAtBottom()
|
|
115
|
+
? 'translate-y-0 scale-100 opacity-100'
|
|
116
|
+
: 'pointer-events-none translate-y-4 scale-95 opacity-0',
|
|
117
|
+
)}
|
|
118
|
+
onClick={() => {
|
|
119
|
+
scrollToBottom();
|
|
120
|
+
dispatch('kai-scroll');
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<ChevronDown class="h-5 w-5" />
|
|
124
|
+
</Button>
|
|
125
|
+
);
|
|
126
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { onMount } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
7
|
+
declare module 'solid-js' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'kai-sources': JSX.HTMLAttributes<HTMLElement>;
|
|
12
|
+
'kai-source': JSX.HTMLAttributes<HTMLElement> & { href?: string; label?: string; headline?: string; description?: string; 'show-favicon'?: boolean | '' };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface SourceItem {
|
|
18
|
+
href: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
showFavicon?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const sampleSources: SourceItem[] = [
|
|
26
|
+
{ href: 'https://kitn.dev', title: 'kitn — the kit', description: 'Composable SolidJS + web-component chat UI.', showFavicon: true },
|
|
27
|
+
{ href: 'https://solidjs.com', title: 'SolidJS', description: 'A reactive UI library.', showFavicon: true },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/** Render the actual `<kai-sources>` custom element with a `sources` property. */
|
|
31
|
+
function SourceListElement() {
|
|
32
|
+
let el: (HTMLElement & { sources?: SourceItem[] }) | undefined;
|
|
33
|
+
onMount(() => {
|
|
34
|
+
if (el) el.sources = sampleSources;
|
|
35
|
+
});
|
|
36
|
+
return (
|
|
37
|
+
<kai-sources ref={(e) => (el = e as HTMLElement)} style={{ display: 'block', padding: '16px', 'max-width': '720px' }} />
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
42
|
+
<kai-sources id="srcs" show-favicon></kai-sources>
|
|
43
|
+
|
|
44
|
+
<script type="module">
|
|
45
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
46
|
+
|
|
47
|
+
const srcs = document.getElementById('srcs');
|
|
48
|
+
srcs.sources = [
|
|
49
|
+
{ href: 'https://kitn.dev', title: 'kitn — the kit', description: 'Composable chat UI.' },
|
|
50
|
+
{ href: 'https://solidjs.com', title: 'SolidJS', description: 'A reactive UI library.' },
|
|
51
|
+
];
|
|
52
|
+
</script>`;
|
|
53
|
+
|
|
54
|
+
const meta = {
|
|
55
|
+
title: 'Components/Sources',
|
|
56
|
+
tags: ['autodocs'],
|
|
57
|
+
argTypes: argTypesFor('kai-sources'),
|
|
58
|
+
parameters: {
|
|
59
|
+
layout: 'fullscreen',
|
|
60
|
+
docs: {
|
|
61
|
+
description: specDescription('kai-sources', [
|
|
62
|
+
'`<kai-sources>` is the framework-agnostic **web component** for a wrapped row of citation links (each with its own hover-card preview), isolated in **Shadow DOM**.',
|
|
63
|
+
'**When to use:** showing the sources behind an assistant answer in a non-Solid app. For a single citation, use `<kai-source>`; in SolidJS, compose `SourceList` + `Source`.',
|
|
64
|
+
'**Placement:** below an assistant message, above the prompt input — rendered as a wrapping row of citation chips that spans the full message column width.',
|
|
65
|
+
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set the data via the `sources` **property** (each item: `href`, `title`, `description`, `label`, `showFavicon`), and set `show-favicon` to enable favicons for all items (a per-item `showFavicon` overrides it).",
|
|
66
|
+
'**Anatomy:** a wrapping flex row of **citation chips** — each chip is a `<kai-source>` (or a `sources`-property item): a **trigger button** (domain label or `numbered` index, optional favicon) + a **hover-card** (headline + description, shown on hover/focus). Declarative `<kai-source href="…" headline="…">` children are invisible data carriers merged after the `sources` property list.',
|
|
67
|
+
'See the **Code** tab for HTML usage.',
|
|
68
|
+
]),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
} satisfies Meta;
|
|
72
|
+
|
|
73
|
+
export default meta;
|
|
74
|
+
type Story = StoryObj;
|
|
75
|
+
|
|
76
|
+
/** Two citations rendered as a wrapped list with favicons. */
|
|
77
|
+
export const Default: Story = {
|
|
78
|
+
render: () => <SourceListElement />,
|
|
79
|
+
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const DECLARATIVE_HTML_SNIPPET = `<!-- Works in any framework or plain HTML — no JS wiring needed -->
|
|
83
|
+
<kai-sources show-favicon>
|
|
84
|
+
<kai-source
|
|
85
|
+
href="https://kitn.dev"
|
|
86
|
+
label="kitn"
|
|
87
|
+
headline="kitn — the kit"
|
|
88
|
+
description="Composable SolidJS + web-component chat UI."
|
|
89
|
+
show-favicon
|
|
90
|
+
></kai-source>
|
|
91
|
+
<kai-source
|
|
92
|
+
href="https://solidjs.com"
|
|
93
|
+
headline="SolidJS"
|
|
94
|
+
description="A reactive UI library."
|
|
95
|
+
show-favicon
|
|
96
|
+
></kai-source>
|
|
97
|
+
</kai-sources>
|
|
98
|
+
|
|
99
|
+
<script type="module">
|
|
100
|
+
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
101
|
+
</script>`;
|
|
102
|
+
|
|
103
|
+
/** Declarative sources — `<kai-source>` light-DOM children instead of a `sources`
|
|
104
|
+
* property. Each child carries `href`, `label`, `headline`, `description`, and the
|
|
105
|
+
* `show-favicon` flag as HTML attributes. Great for plain HTML with no JS wiring. */
|
|
106
|
+
export const DeclarativeSources: Story = {
|
|
107
|
+
name: 'Declarative Sources (kai-source)',
|
|
108
|
+
render: () => {
|
|
109
|
+
let el: HTMLElement | undefined;
|
|
110
|
+
onMount(() => {
|
|
111
|
+
if (!el) return;
|
|
112
|
+
el.setAttribute('show-favicon', '');
|
|
113
|
+
});
|
|
114
|
+
return (
|
|
115
|
+
<kai-sources
|
|
116
|
+
ref={(e) => (el = e as HTMLElement)}
|
|
117
|
+
style={{ display: 'block', padding: '16px', 'max-width': '720px' }}
|
|
118
|
+
>
|
|
119
|
+
<kai-source
|
|
120
|
+
href="https://kitn.dev"
|
|
121
|
+
label="kitn"
|
|
122
|
+
headline="kitn — the kit"
|
|
123
|
+
description="Composable SolidJS + web-component chat UI."
|
|
124
|
+
show-favicon
|
|
125
|
+
></kai-source>
|
|
126
|
+
<kai-source
|
|
127
|
+
href="https://solidjs.com"
|
|
128
|
+
headline="SolidJS"
|
|
129
|
+
description="A reactive UI library."
|
|
130
|
+
show-favicon
|
|
131
|
+
></kai-source>
|
|
132
|
+
</kai-sources>
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
parameters: {
|
|
136
|
+
docs: {
|
|
137
|
+
source: {
|
|
138
|
+
code: DECLARATIVE_HTML_SNIPPET,
|
|
139
|
+
language: 'html',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
};
|