@kitn.ai/ui 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kitn-chat.es.js +1 -1
- package/package.json +6 -1
- package/src/elements/compiled.css +1 -1
- package/src/components/artifact.stories.tsx +0 -138
- package/src/components/attachments.stories.tsx +0 -303
- package/src/components/attachments.test.tsx +0 -64
- package/src/components/chain-of-thought.stories.tsx +0 -211
- package/src/components/chat-container.stories.tsx +0 -187
- package/src/components/chat-thread.test.tsx +0 -58
- package/src/components/checkpoint.stories.tsx +0 -102
- package/src/components/code-block.stories.tsx +0 -150
- package/src/components/confirm-card.stories.tsx +0 -74
- package/src/components/context.stories.tsx +0 -229
- package/src/components/context.test.tsx +0 -133
- package/src/components/conversation-item.stories.tsx +0 -125
- package/src/components/conversation-list.stories.tsx +0 -133
- package/src/components/default-input.test.tsx +0 -111
- package/src/components/empty.stories.tsx +0 -434
- package/src/components/feedback-bar.stories.tsx +0 -138
- package/src/components/feedback-bar.test.tsx +0 -103
- package/src/components/file-tree.stories.tsx +0 -73
- package/src/components/file-upload.stories.tsx +0 -156
- package/src/components/image.stories.tsx +0 -89
- package/src/components/loader.stories.tsx +0 -181
- package/src/components/markdown.stories.tsx +0 -180
- package/src/components/message-action-bar.test.tsx +0 -128
- package/src/components/message-narrow.stories.tsx +0 -329
- package/src/components/message-skills.stories.tsx +0 -211
- package/src/components/message.stories.tsx +0 -281
- package/src/components/model-switcher.stories.tsx +0 -123
- package/src/components/model-switcher.test.tsx +0 -65
- package/src/components/prompt-input.stories.tsx +0 -222
- package/src/components/prompt-suggestion.stories.tsx +0 -142
- package/src/components/reasoning.stories.tsx +0 -140
- package/src/components/resizable.test.tsx +0 -226
- package/src/components/scroll-button.stories.tsx +0 -100
- package/src/components/slash-command.stories.tsx +0 -163
- package/src/components/source-list.test.tsx +0 -152
- package/src/components/source.stories.tsx +0 -124
- package/src/components/tasks-card.stories.tsx +0 -78
- package/src/components/text-shimmer.stories.tsx +0 -87
- package/src/components/thinking-bar.stories.tsx +0 -87
- package/src/components/tool.stories.tsx +0 -153
- package/src/components/voice-input.stories.tsx +0 -83
- package/src/elements/artifact.stories.tsx +0 -506
- package/src/elements/attachments.stories.tsx +0 -190
- package/src/elements/card.stories.tsx +0 -113
- package/src/elements/cards.stories.tsx +0 -59
- package/src/elements/catalog.stories.tsx +0 -491
- package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
- package/src/elements/chain-of-thought.stories.tsx +0 -113
- package/src/elements/chat-scope-picker.stories.tsx +0 -73
- package/src/elements/chat-workspace.stories.tsx +0 -288
- package/src/elements/chat.stories.tsx +0 -151
- package/src/elements/checkpoint.stories.tsx +0 -72
- package/src/elements/choice.stories.tsx +0 -240
- package/src/elements/code-block.stories.tsx +0 -83
- package/src/elements/composed-shell.stories.tsx +0 -316
- package/src/elements/confirm-card.stories.tsx +0 -227
- package/src/elements/context-meter.stories.tsx +0 -151
- package/src/elements/conversation-list.declarative.test.tsx +0 -137
- package/src/elements/conversation-list.stories.tsx +0 -243
- package/src/elements/embed.stories.tsx +0 -213
- package/src/elements/empty.stories.tsx +0 -111
- package/src/elements/feedback-bar.stories.tsx +0 -114
- package/src/elements/file-tree.stories.tsx +0 -134
- package/src/elements/file-upload.stories.tsx +0 -82
- package/src/elements/form.stories.tsx +0 -248
- package/src/elements/image.stories.tsx +0 -71
- package/src/elements/link-preview.stories.tsx +0 -209
- package/src/elements/loader.stories.tsx +0 -88
- package/src/elements/markdown.stories.tsx +0 -76
- package/src/elements/message-skills.declarative.test.tsx +0 -104
- package/src/elements/message-skills.stories.tsx +0 -114
- package/src/elements/message.stories.tsx +0 -218
- package/src/elements/model-switcher.declarative.test.tsx +0 -130
- package/src/elements/model-switcher.stories.tsx +0 -198
- package/src/elements/popover.stories.tsx +0 -80
- package/src/elements/prompt-input-slash-command.test.tsx +0 -128
- package/src/elements/prompt-input-stoppable.test.tsx +0 -88
- package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
- package/src/elements/prompt-input.stories.tsx +0 -331
- package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
- package/src/elements/prompt-suggestions.stories.tsx +0 -213
- package/src/elements/reasoning.stories.tsx +0 -77
- package/src/elements/remote.stories.tsx +0 -314
- package/src/elements/resizable.stories.tsx +0 -426
- package/src/elements/response-stream.stories.tsx +0 -79
- package/src/elements/scroll-button.stories.tsx +0 -202
- package/src/elements/scroll-button.test.tsx +0 -148
- package/src/elements/source-list.stories.tsx +0 -143
- package/src/elements/source.stories.tsx +0 -88
- package/src/elements/switch.stories.tsx +0 -56
- package/src/elements/tasks.stories.tsx +0 -237
- package/src/elements/text-shimmer.stories.tsx +0 -64
- package/src/elements/thinking-bar.stories.tsx +0 -72
- package/src/elements/tool.stories.tsx +0 -89
- package/src/elements/voice-input.stories.tsx +0 -88
- package/src/primitives/controllable.test.ts +0 -47
- package/src/stories/chat-panel-layout.stories.tsx +0 -145
- package/src/stories/chat-scene.tsx +0 -571
- package/src/stories/checkpoint-restore.stories.tsx +0 -256
- package/src/stories/context-usage.stories.tsx +0 -212
- package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
- package/src/stories/conversation-with-sources.stories.tsx +0 -471
- package/src/stories/docs/Accessibility.mdx +0 -119
- package/src/stories/docs/ChildElements.mdx +0 -269
- package/src/stories/docs/ForAIAgents.mdx +0 -162
- package/src/stories/docs/GettingStarted.mdx +0 -65
- package/src/stories/docs/Installation.mdx +0 -83
- package/src/stories/docs/Introduction.mdx +0 -50
- package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
- package/src/stories/docs/Theming.mdx +0 -85
- package/src/stories/docs/element-controls.ts +0 -121
- package/src/stories/docs/frameworks/Angular.mdx +0 -245
- package/src/stories/docs/frameworks/Html.mdx +0 -227
- package/src/stories/docs/frameworks/Overview.mdx +0 -47
- package/src/stories/docs/frameworks/React.mdx +0 -227
- package/src/stories/docs/frameworks/Solid.mdx +0 -173
- package/src/stories/docs/frameworks/Svelte.mdx +0 -194
- package/src/stories/docs/frameworks/Vue.mdx +0 -238
- package/src/stories/docs/generative-ui-overview.mdx +0 -186
- package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
- package/src/stories/docs/recipes/Streaming.mdx +0 -68
- package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
- package/src/stories/docs/theme-editor/canvas.tsx +0 -32
- package/src/stories/docs/theme-editor/inspector.tsx +0 -66
- package/src/stories/docs/theme-editor/presets.test.ts +0 -32
- package/src/stories/docs/theme-editor/presets.ts +0 -64
- package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
- package/src/stories/docs/theme-editor/theme-css.ts +0 -15
- package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
- package/src/stories/docs/theme-tokens.tsx +0 -174
- package/src/stories/examples/ChoosingComponents.mdx +0 -106
- package/src/stories/examples/sample-data.ts +0 -79
- package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
- package/src/stories/examples/usage/context-usage.ts +0 -591
- package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
- package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
- package/src/stories/examples/usage/empty-state.ts +0 -144
- package/src/stories/examples/usage/full-chat-app.ts +0 -277
- package/src/stories/examples/usage/index.ts +0 -63
- package/src/stories/examples/usage/message-actions.ts +0 -704
- package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
- package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
- package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
- package/src/stories/examples/usage/streaming-response.ts +0 -687
- package/src/stories/examples/usage/types.ts +0 -33
- package/src/stories/full-chat.stories.tsx +0 -18
- package/src/stories/message-actions.stories.tsx +0 -230
- package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
- package/src/stories/pattern-docked-widget.stories.tsx +0 -93
- package/src/stories/pattern-empty-state.stories.tsx +0 -76
- package/src/stories/prompt-input-variants.stories.tsx +0 -456
- package/src/stories/streaming-response.stories.tsx +0 -438
- package/src/stories/theme-editor.stories.tsx +0 -16
- package/src/stories/token-reference.stories.tsx +0 -18
- package/src/stories/typography.stories.tsx +0 -78
- package/src/ui/avatar.stories.tsx +0 -103
- package/src/ui/badge.stories.tsx +0 -86
- package/src/ui/button.stories.tsx +0 -145
- package/src/ui/collapsible.stories.tsx +0 -69
- package/src/ui/dropdown.stories.tsx +0 -59
- package/src/ui/hover-card.stories.tsx +0 -77
- package/src/ui/hover-card.test.tsx +0 -30
- package/src/ui/overlay.stories.tsx +0 -115
- package/src/ui/popover.stories.tsx +0 -81
- package/src/ui/popover.test.tsx +0 -99
- package/src/ui/resizable.stories.tsx +0 -236
- package/src/ui/scroll-area.stories.tsx +0 -50
- package/src/ui/separator.stories.tsx +0 -81
- package/src/ui/skeleton.stories.tsx +0 -337
- package/src/ui/switch.stories.tsx +0 -51
- package/src/ui/switch.test.tsx +0 -59
- package/src/ui/textarea.stories.tsx +0 -76
- package/src/ui/tooltip.stories.tsx +0 -74
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
-
import { createSignal, onMount, type JSX } from 'solid-js';
|
|
3
|
-
import './embed'; // side effect: registers <kai-embed>
|
|
4
|
-
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
-
import type { EmbedCardData } from '../primitives/embed-providers';
|
|
6
|
-
import { configureEmbedAllowlist } from '../primitives/embed-providers';
|
|
7
|
-
import type { CardEvent } from '../primitives/card-contract';
|
|
8
|
-
|
|
9
|
-
// Custom DOM element — declare the tag for JSX.
|
|
10
|
-
declare module 'solid-js' {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
12
|
-
namespace JSX {
|
|
13
|
-
interface IntrinsicElements {
|
|
14
|
-
'kai-embed': JSX.HTMLAttributes<HTMLElement> & {
|
|
15
|
-
'card-id'?: string;
|
|
16
|
-
ref?: (el: HTMLElement) => void;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type EmbedEl = HTMLElement & { cardId?: string; data?: EmbedCardData };
|
|
23
|
-
|
|
24
|
-
/** A sized box the embed sits in. */
|
|
25
|
-
function Frame(props: { children: JSX.Element }) {
|
|
26
|
-
return <div style={{ width: '100%', 'max-width': '560px' }}>{props.children}</div>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Mounts a <kai-embed>, sets `.data`, logs emitted CardEvents under the render. */
|
|
30
|
-
function EmbedDemo(props: { cardId: string; data: EmbedCardData }) {
|
|
31
|
-
const [log, setLog] = createSignal<CardEvent[]>([]);
|
|
32
|
-
let el: EmbedEl | undefined;
|
|
33
|
-
onMount(() => {
|
|
34
|
-
if (!el) return;
|
|
35
|
-
el.cardId = props.cardId;
|
|
36
|
-
el.data = props.data;
|
|
37
|
-
el.addEventListener('kai-card', (e) => {
|
|
38
|
-
const detail = (e as CustomEvent<CardEvent>).detail;
|
|
39
|
-
setLog((prev) => [...prev, detail]);
|
|
40
|
-
if (detail.kind === 'open' && detail.target === 'tab') {
|
|
41
|
-
window.open(detail.url, '_blank', 'noopener,noreferrer');
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
return (
|
|
46
|
-
<Frame>
|
|
47
|
-
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '12px' }}>
|
|
48
|
-
<kai-embed ref={(e) => (el = e as EmbedEl)} card-id={props.cardId} />
|
|
49
|
-
<pre
|
|
50
|
-
style={{
|
|
51
|
-
margin: 0,
|
|
52
|
-
'max-height': '180px',
|
|
53
|
-
overflow: 'auto',
|
|
54
|
-
background: 'var(--color-muted, #f4f4f5)',
|
|
55
|
-
'border-radius': '8px',
|
|
56
|
-
padding: '8px',
|
|
57
|
-
'font-size': '12px',
|
|
58
|
-
}}
|
|
59
|
-
>
|
|
60
|
-
{log().length === 0 ? '// emitted CardEvents appear here' : JSON.stringify(log(), null, 2)}
|
|
61
|
-
</pre>
|
|
62
|
-
</div>
|
|
63
|
-
</Frame>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const YT_ENVELOPE = {
|
|
68
|
-
type: 'embed',
|
|
69
|
-
id: 'card-embed-1',
|
|
70
|
-
title: 'Intro video',
|
|
71
|
-
data: { provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Product intro', aspectRatio: '16:9' },
|
|
72
|
-
} satisfies { type: string; id: string; title: string; data: EmbedCardData };
|
|
73
|
-
|
|
74
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
75
|
-
<kai-embed id="em"></kai-embed>
|
|
76
|
-
|
|
77
|
-
<script type="module">
|
|
78
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
79
|
-
|
|
80
|
-
const em = document.getElementById('em');
|
|
81
|
-
em.cardId = 'card-embed-1';
|
|
82
|
-
// \`data\` is a JS property (the CardEnvelope \`data\`):
|
|
83
|
-
em.data = { provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Product intro' };
|
|
84
|
-
|
|
85
|
-
// NO network to YouTube until the user clicks play (privacy-first lazy facade).
|
|
86
|
-
// kai-embed emits: ready (on mount), open (on "Open on provider" click), error (blocked/invalid).
|
|
87
|
-
// The optional "Open on YouTube" affordance bubbles a composed \`kai-card\` open event:
|
|
88
|
-
em.addEventListener('kai-card', (e) => {
|
|
89
|
-
const ev = e.detail;
|
|
90
|
-
if (ev.kind === 'open' && ev.target === 'tab') {
|
|
91
|
-
window.open(ev.url, '_blank', 'noopener,noreferrer');
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
</script>`;
|
|
95
|
-
|
|
96
|
-
const meta = {
|
|
97
|
-
title: 'Generative UI/Cards/kai-embed',
|
|
98
|
-
tags: ['autodocs'],
|
|
99
|
-
argTypes: argTypesFor('kai-embed'),
|
|
100
|
-
parameters: {
|
|
101
|
-
layout: 'padded',
|
|
102
|
-
docs: {
|
|
103
|
-
description: specDescription('kai-embed', [
|
|
104
|
-
'`<kai-embed>` is a **privacy-first lazy media embed** (YouTube / Vimeo / allowlisted generic player) for the generative-UI feature. It speaks the **Card Contract**: data down (an `embed` `CardEnvelope`), events up (only the `open` verb, plus lifecycle `ready` / failure `error`).',
|
|
105
|
-
'**Lazy facade:** the initial render is just a **poster + play button** — NO provider iframe, NO third-party JS, NO cookies until the user clicks play. YouTube loads via `youtube-nocookie.com`; Vimeo with `dnt=1`. This buys privacy (no tracking until opt-in) and performance (no player JS on load).',
|
|
106
|
-
'**Security:** `generic` embeds frame an arbitrary https URL, so they are **rejected unless the app allowlists their origin** with `configureEmbedAllowlist([...])` (defaults to empty — an agent cannot frame an arbitrary origin). The player iframe is sandboxed for a *trusted provider* (`allow-scripts allow-same-origin` on a cross-origin player) — contrast `<kai-artifact>`, which trusts nothing.',
|
|
107
|
-
'**Never a dead end:** a persistent "Open on {provider}" affordance dispatches the `open` verb (so a provider that refuses framing still has a way out). Set `data` as a JS property; `card-id` via attribute.',
|
|
108
|
-
'See the **Code** tab for the `CardEnvelope` JSON + HTML wiring.',
|
|
109
|
-
]),
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
} satisfies Meta;
|
|
113
|
-
|
|
114
|
-
export default meta;
|
|
115
|
-
type Story = StoryObj;
|
|
116
|
-
|
|
117
|
-
/** YouTube (lazy) — poster + play; the iframe loads (youtube-nocookie) only on click. `ready` fires on mount; `open` fires if the "Open on YouTube" link is used. */
|
|
118
|
-
export const YouTube: Story = {
|
|
119
|
-
name: 'YouTube (lazy)',
|
|
120
|
-
render: () => <EmbedDemo cardId={YT_ENVELOPE.id} data={YT_ENVELOPE.data} />,
|
|
121
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/** Vimeo — supply a `poster` (Vimeo has no static thumbnail URL). */
|
|
125
|
-
export const Vimeo: Story = {
|
|
126
|
-
render: () => (
|
|
127
|
-
<EmbedDemo
|
|
128
|
-
cardId="card-embed-2"
|
|
129
|
-
data={{
|
|
130
|
-
provider: 'vimeo',
|
|
131
|
-
id: '76979871',
|
|
132
|
-
title: 'Vimeo staff pick',
|
|
133
|
-
poster: 'https://placehold.co/1280x720/1ab7ea/ffffff/png?text=Vimeo',
|
|
134
|
-
}}
|
|
135
|
-
/>
|
|
136
|
-
),
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/** Generic player — an https embed URL whose origin the app has allowlisted. */
|
|
140
|
-
export const Generic: Story = {
|
|
141
|
-
name: 'Generic player',
|
|
142
|
-
render: () => {
|
|
143
|
-
configureEmbedAllowlist(['https://www.youtube-nocookie.com']);
|
|
144
|
-
return (
|
|
145
|
-
<EmbedDemo
|
|
146
|
-
cardId="card-embed-3"
|
|
147
|
-
data={{
|
|
148
|
-
provider: 'generic',
|
|
149
|
-
url: 'https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ',
|
|
150
|
-
title: 'Generic embed',
|
|
151
|
-
poster: 'https://placehold.co/1280x720/444/fff/png?text=Generic+player',
|
|
152
|
-
}}
|
|
153
|
-
/>
|
|
154
|
-
);
|
|
155
|
-
},
|
|
156
|
-
parameters: {
|
|
157
|
-
docs: {
|
|
158
|
-
source: {
|
|
159
|
-
code: `import { configureEmbedAllowlist } from '@kitn.ai/ui';
|
|
160
|
-
|
|
161
|
-
// Generic embeds are blocked by default — allowlist the trusted origin first:
|
|
162
|
-
configureEmbedAllowlist(['https://your-player.example.com']);
|
|
163
|
-
|
|
164
|
-
em.data = {
|
|
165
|
-
provider: 'generic',
|
|
166
|
-
url: 'https://your-player.example.com/embed/abc',
|
|
167
|
-
title: 'Generic embed',
|
|
168
|
-
poster: 'https://your-cdn.example.com/poster.jpg',
|
|
169
|
-
};`,
|
|
170
|
-
language: 'ts',
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/** Custom aspect ratio — a vertical 9:16 short. */
|
|
177
|
-
export const CustomAspectRatio: Story = {
|
|
178
|
-
name: 'Custom aspect ratio (9:16)',
|
|
179
|
-
render: () => (
|
|
180
|
-
<div style={{ width: '100%', 'max-width': '280px' }}>
|
|
181
|
-
<EmbedRaw
|
|
182
|
-
cardId="card-embed-4"
|
|
183
|
-
data={{ provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Short', aspectRatio: '9:16' }}
|
|
184
|
-
/>
|
|
185
|
-
</div>
|
|
186
|
-
),
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/** Blocked-embed fallback — the "Open on provider" affordance is always present. */
|
|
190
|
-
export const BlockedFallback: Story = {
|
|
191
|
-
name: 'Blocked-embed fallback',
|
|
192
|
-
render: () => <EmbedDemo cardId="card-embed-5" data={{ provider: 'youtube', id: 'dQw4w9WgXcQ', title: 'Maybe blocked' }} />,
|
|
193
|
-
parameters: {
|
|
194
|
-
docs: {
|
|
195
|
-
description: {
|
|
196
|
-
story:
|
|
197
|
-
'Some providers refuse framing (X-Frame-Options / CSP `frame-ancestors`). We can\'t detect that cross-origin in JS, so the **"Open on {provider}"** affordance is *always* available — a blocked embed is never a dead end.',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// A frame-less variant so the 9:16 story controls its own width.
|
|
204
|
-
function EmbedRaw(props: { cardId: string; data: EmbedCardData }) {
|
|
205
|
-
let el: EmbedEl | undefined;
|
|
206
|
-
onMount(() => {
|
|
207
|
-
if (el) {
|
|
208
|
-
el.cardId = props.cardId;
|
|
209
|
-
el.data = props.data;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
return <kai-embed ref={(e) => (el = e as EmbedEl)} />;
|
|
213
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
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-empty': JSX.HTMLAttributes<HTMLElement>;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
17
|
-
<kai-empty
|
|
18
|
-
empty-title="No conversations yet"
|
|
19
|
-
description="Start a new chat to see it appear here."
|
|
20
|
-
>
|
|
21
|
-
<!-- Route 2 slots: your own icon and actions -->
|
|
22
|
-
<svg slot="media" width="28" height="28" viewBox="0 0 24 24" fill="none"
|
|
23
|
-
stroke="currentColor" stroke-width="2">
|
|
24
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
25
|
-
</svg>
|
|
26
|
-
|
|
27
|
-
<!-- Slotted actions are light DOM, so style them with your own page CSS
|
|
28
|
-
(a ghost button with a + icon, here styled inline for portability). -->
|
|
29
|
-
<button
|
|
30
|
-
style="display:inline-flex; align-items:center; gap:.45rem;
|
|
31
|
-
font:500 13.5px/1 system-ui,sans-serif; padding:.5rem .85rem;
|
|
32
|
-
border-radius:9px; border:1px solid var(--color-border, #e5e5e5);
|
|
33
|
-
background:transparent; color:inherit; cursor:pointer;"
|
|
34
|
-
>
|
|
35
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
|
|
36
|
-
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
37
|
-
<path d="M5 12h14" /><path d="M12 5v14" />
|
|
38
|
-
</svg>
|
|
39
|
-
New chat
|
|
40
|
-
</button>
|
|
41
|
-
</kai-empty>
|
|
42
|
-
|
|
43
|
-
<script type="module">
|
|
44
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
45
|
-
</script>`;
|
|
46
|
-
|
|
47
|
-
const meta = {
|
|
48
|
-
title: 'Components/Empty',
|
|
49
|
-
tags: ['autodocs'],
|
|
50
|
-
argTypes: argTypesFor('kai-empty'),
|
|
51
|
-
parameters: {
|
|
52
|
-
layout: 'fullscreen',
|
|
53
|
-
docs: {
|
|
54
|
-
description: specDescription('kai-empty', [
|
|
55
|
-
'`<kai-empty>` is the framework-agnostic **web component** for an empty-state block — an icon, a title, a description, and actions — isolated in **Shadow DOM**.',
|
|
56
|
-
'**When to use:** placeholder UI for an empty list/thread in a non-Solid app. In SolidJS, compose the `Empty*` primitives.',
|
|
57
|
-
'**Placement:** filling the main content area where a conversation list or message thread would appear; give it (or its parent) a height so the centered layout renders correctly.',
|
|
58
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set `empty-title` (note `empty-title`, not `title`) and `description` via attributes, and use the **slots** (\"Route 2\") to project your own icon (`slot=\"media\"`) and actions (the default slot).",
|
|
59
|
-
'See the **Code** tab for HTML usage.',
|
|
60
|
-
]),
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
} satisfies Meta;
|
|
64
|
-
|
|
65
|
-
export default meta;
|
|
66
|
-
type Story = StoryObj;
|
|
67
|
-
|
|
68
|
-
/** Render the actual `<kai-empty>` custom element with slotted children. */
|
|
69
|
-
function EmptyElement() {
|
|
70
|
-
let el: HTMLElement | undefined;
|
|
71
|
-
onMount(() => {
|
|
72
|
-
if (!el) return;
|
|
73
|
-
el.setAttribute('empty-title', 'No conversations yet');
|
|
74
|
-
el.setAttribute('description', 'Start a new chat to see it appear here.');
|
|
75
|
-
});
|
|
76
|
-
return (
|
|
77
|
-
<kai-empty ref={(e) => (el = e as HTMLElement)} style={{ display: 'block', padding: '24px' }}>
|
|
78
|
-
<svg slot="media" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
79
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
80
|
-
</svg>
|
|
81
|
-
{/* Slotted actions are light DOM — style them with the host page's own
|
|
82
|
-
CSS. Here a ghost "+ New chat" button, styled inline so it renders
|
|
83
|
-
correctly in any context (mirrors the composable example's pill-btn). */}
|
|
84
|
-
<button
|
|
85
|
-
style={{
|
|
86
|
-
display: 'inline-flex',
|
|
87
|
-
'align-items': 'center',
|
|
88
|
-
gap: '0.45rem',
|
|
89
|
-
font: '500 13.5px/1 system-ui, sans-serif',
|
|
90
|
-
padding: '0.5rem 0.85rem',
|
|
91
|
-
'border-radius': '9px',
|
|
92
|
-
border: '1px solid var(--color-border, #e5e5e5)',
|
|
93
|
-
background: 'transparent',
|
|
94
|
-
color: 'inherit',
|
|
95
|
-
cursor: 'pointer',
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
98
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
99
|
-
<path d="M5 12h14" /><path d="M12 5v14" />
|
|
100
|
-
</svg>
|
|
101
|
-
New chat
|
|
102
|
-
</button>
|
|
103
|
-
</kai-empty>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** An empty state with a slotted icon and an action button. */
|
|
108
|
-
export const Default: Story = {
|
|
109
|
-
render: () => <EmptyElement />,
|
|
110
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
111
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
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-feedback-bar': JSX.HTMLAttributes<HTMLElement> & {
|
|
12
|
-
'bar-title'?: string;
|
|
13
|
-
'collect-detail'?: boolean | string;
|
|
14
|
-
'detail-title'?: string;
|
|
15
|
-
'thanks-message'?: string;
|
|
16
|
-
'on:kai-feedback'?: (e: CustomEvent<{ value: 'helpful' | 'not-helpful' }>) => void;
|
|
17
|
-
'on:kai-feedback-detail'?: (e: CustomEvent<{ value: 'helpful' | 'not-helpful'; category?: string; comment?: string }>) => void;
|
|
18
|
-
'on:kai-close'?: (e: CustomEvent) => void;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
25
|
-
<kai-feedback-bar bar-title="Was this helpful?"></kai-feedback-bar>
|
|
26
|
-
|
|
27
|
-
<script type="module">
|
|
28
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
29
|
-
|
|
30
|
-
const bar = document.querySelector('kai-feedback-bar');
|
|
31
|
-
bar.addEventListener('kai-feedback', (e) => console.log('feedback:', e.detail.value)); // 'helpful' | 'not-helpful'
|
|
32
|
-
bar.addEventListener('kai-close', () => bar.remove());
|
|
33
|
-
</script>`;
|
|
34
|
-
|
|
35
|
-
const meta = {
|
|
36
|
-
title: 'Components/FeedbackBar',
|
|
37
|
-
tags: ['autodocs'],
|
|
38
|
-
argTypes: argTypesFor('kai-feedback-bar'),
|
|
39
|
-
parameters: {
|
|
40
|
-
layout: 'fullscreen',
|
|
41
|
-
docs: {
|
|
42
|
-
description: specDescription('kai-feedback-bar', [
|
|
43
|
-
'`<kai-feedback-bar>` is the framework-agnostic **web component** for an inline thumbs up/down feedback banner — isolated in **Shadow DOM**. It owns its own flow: it asks, optionally collects a category + comment on a not-helpful vote (`collect-detail`), then confirms with a thank-you in place. It does **not** disappear on a vote; only the close (X) dismisses it.',
|
|
44
|
-
'**When to use:** collecting a quick reaction (optionally with a reason) after an answer or a completed task. In SolidJS, use the `FeedbackBar` primitive.',
|
|
45
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set the label via the `bar-title` attribute (`title` is avoided — it's a global HTML attribute). For the richer flow add `collect-detail` and set the `categories` **property** (array). Listen for `kai-feedback` (`{ value }`), `kai-feedback-detail` (`{ value, category?, comment? }`), and `kai-close` **CustomEvents**.",
|
|
46
|
-
'See the **Code** tab for HTML usage.',
|
|
47
|
-
]),
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
} satisfies Meta;
|
|
51
|
-
|
|
52
|
-
export default meta;
|
|
53
|
-
type Story = StoryObj;
|
|
54
|
-
|
|
55
|
-
/** The default feedback prompt. */
|
|
56
|
-
export const Default: Story = {
|
|
57
|
-
render: () => (
|
|
58
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
59
|
-
<kai-feedback-bar
|
|
60
|
-
on:kai-feedback={(e) => console.log('feedback:', e.detail.value)}
|
|
61
|
-
on:kai-close={() => console.log('closed')}
|
|
62
|
-
/>
|
|
63
|
-
</div>
|
|
64
|
-
),
|
|
65
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/** A custom label via the `bar-title` attribute. */
|
|
69
|
-
export const CustomTitle: Story = {
|
|
70
|
-
render: () => (
|
|
71
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
72
|
-
<kai-feedback-bar bar-title="Did this answer your question?" />
|
|
73
|
-
</div>
|
|
74
|
-
),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** The full flow with `collect-detail` — a 👎 vote opens an optional detail form
|
|
78
|
-
* (category chips from the `categories` property + a comment) before the thanks. */
|
|
79
|
-
export const WithDetail: Story = {
|
|
80
|
-
render: () => {
|
|
81
|
-
let el: (HTMLElement & { categories?: string[] }) | undefined;
|
|
82
|
-
onMount(() => {
|
|
83
|
-
if (el) el.categories = ['Inaccurate', 'Not helpful', 'Unsafe', 'Other'];
|
|
84
|
-
});
|
|
85
|
-
return (
|
|
86
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
87
|
-
<kai-feedback-bar
|
|
88
|
-
ref={(e) => (el = e as HTMLElement)}
|
|
89
|
-
bar-title="Was this response helpful?"
|
|
90
|
-
collect-detail
|
|
91
|
-
on:kai-feedback={(e) => console.log('vote:', e.detail.value)}
|
|
92
|
-
on:kai-feedback-detail={(e) => console.log('detail:', e.detail)}
|
|
93
|
-
on:kai-close={() => console.log('closed')}
|
|
94
|
-
/>
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
},
|
|
98
|
-
parameters: {
|
|
99
|
-
docs: {
|
|
100
|
-
source: {
|
|
101
|
-
code: `<kai-feedback-bar id="fb" bar-title="Was this response helpful?" collect-detail></kai-feedback-bar>
|
|
102
|
-
<script type="module">
|
|
103
|
-
import '@kitn.ai/ui/elements';
|
|
104
|
-
const fb = document.getElementById('fb');
|
|
105
|
-
fb.categories = ['Inaccurate', 'Not helpful', 'Unsafe', 'Other']; // chips (a JS property)
|
|
106
|
-
fb.addEventListener('kai-feedback', (e) => console.log('vote:', e.detail.value));
|
|
107
|
-
fb.addEventListener('kai-feedback-detail', (e) => console.log('detail:', e.detail)); // { value, category?, comment? }
|
|
108
|
-
fb.addEventListener('kai-close', () => fb.remove());
|
|
109
|
-
</script>`,
|
|
110
|
-
language: 'html',
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
-
import { createSignal, onMount, type JSX } from 'solid-js';
|
|
3
|
-
import './register'; // side effect: registers the custom elements
|
|
4
|
-
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
-
import type { FileTreeFile } from '../components/file-tree';
|
|
6
|
-
|
|
7
|
-
declare module 'solid-js' {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
-
namespace JSX {
|
|
10
|
-
interface IntrinsicElements {
|
|
11
|
-
'kai-file-tree': JSX.HTMLAttributes<HTMLElement> & {
|
|
12
|
-
'active-file'?: string;
|
|
13
|
-
ref?: (el: HTMLElement) => void;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const FILES: FileTreeFile[] = [
|
|
20
|
-
{ path: 'index.html', type: 'html' },
|
|
21
|
-
{ path: 'about.html', type: 'html' },
|
|
22
|
-
{ path: 'css/site.css', type: 'other', language: 'css' },
|
|
23
|
-
{ path: 'src/app.ts', type: 'other', language: 'ts' },
|
|
24
|
-
{ path: 'src/lib/format.ts', type: 'other', language: 'ts' },
|
|
25
|
-
{ path: 'src/lib/parse.ts', type: 'other', language: 'ts' },
|
|
26
|
-
{ path: 'assets/logo.svg', type: 'image' },
|
|
27
|
-
{ path: 'assets/report.pdf', type: 'pdf' },
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
/** A bordered, sized box the tree fills + scrolls within. */
|
|
31
|
-
function Frame(props: { children: JSX.Element }) {
|
|
32
|
-
return (
|
|
33
|
-
<div
|
|
34
|
-
style={{
|
|
35
|
-
height: '320px',
|
|
36
|
-
width: '280px',
|
|
37
|
-
border: '1px solid var(--color-border, #e4e4e7)',
|
|
38
|
-
'border-radius': '10px',
|
|
39
|
-
overflow: 'hidden',
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
{props.children}
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
48
|
-
<kai-file-tree style="display:block;height:320px"></kai-file-tree>
|
|
49
|
-
|
|
50
|
-
<script type="module">
|
|
51
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
52
|
-
|
|
53
|
-
const tree = document.querySelector('kai-file-tree');
|
|
54
|
-
// \`files\` is a JS property (array). Folders are derived from \`/\` in each path.
|
|
55
|
-
tree.files = [
|
|
56
|
-
{ path: 'index.html', type: 'html' },
|
|
57
|
-
{ path: 'src/app.ts', type: 'other' },
|
|
58
|
-
{ path: 'src/lib/format.ts', type: 'other' },
|
|
59
|
-
{ path: 'assets/logo.svg', type: 'image' },
|
|
60
|
-
];
|
|
61
|
-
tree.setAttribute('active-file', 'src/app.ts');
|
|
62
|
-
tree.addEventListener('kai-select', (e) => console.log('selected', e.detail.path));
|
|
63
|
-
</script>`;
|
|
64
|
-
|
|
65
|
-
const meta = {
|
|
66
|
-
title: 'Components/FileTree',
|
|
67
|
-
tags: ['autodocs'],
|
|
68
|
-
argTypes: argTypesFor('kai-file-tree'),
|
|
69
|
-
parameters: {
|
|
70
|
-
layout: 'padded',
|
|
71
|
-
docs: {
|
|
72
|
-
description: specDescription('kai-file-tree', [
|
|
73
|
-
'`<kai-file-tree>` is the framework-agnostic **web component** for a collapsible, keyboard-navigable **file explorer** built from a flat list of `/`-delimited paths (nested folders are derived automatically). ARIA `tree`/`treeitem`. Isolated in **Shadow DOM**.',
|
|
74
|
-
'**When to use:** any time you need a file/folder tree — the Code tab of `<kai-artifact>` uses it, but it ships public so you can reuse it standalone (a project explorer, an attachments browser, a doc outline).',
|
|
75
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, then set the `files` **property** (a JS array of `{ path, url?, code?, language?, type? }`). Folders come from the `/` in each `path`; `type` picks the icon. Set `active-file` to highlight a row, `default-expanded` to control which folders open. Listen for **`select`** (`detail.path`). Arrow keys navigate; Enter/Space selects or toggles.",
|
|
76
|
-
'**Anatomy:** a scrollable ARIA `tree` of **folder nodes** (collapsible `treeitem` groups, derived from `/`-delimited path segments) and **file leaf nodes** (selectable `treeitem` rows with a type icon; the `active-file` row is highlighted). Folders auto-expand on first render; click or arrow-key to collapse/expand.',
|
|
77
|
-
'**Placement:** a sidebar/explorer column — inside `<kai-artifact>`, a `<kai-resizable>` panel, or any file-picker surface. It **fills** its container, so give the parent (or the element) a height.',
|
|
78
|
-
'See the **Code** tab for HTML usage.',
|
|
79
|
-
]),
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
} satisfies Meta;
|
|
83
|
-
|
|
84
|
-
export default meta;
|
|
85
|
-
type Story = StoryObj;
|
|
86
|
-
|
|
87
|
-
/** Interactive playground — click rows, use arrow keys / Enter to navigate. */
|
|
88
|
-
export const Playground: Story = {
|
|
89
|
-
render: () => {
|
|
90
|
-
const [selected, setSelected] = createSignal('src/app.ts');
|
|
91
|
-
let el: HTMLElement & { files?: FileTreeFile[] };
|
|
92
|
-
onMount(() => {
|
|
93
|
-
if (!el) return;
|
|
94
|
-
el.files = FILES;
|
|
95
|
-
el.addEventListener('kai-select', (e) => {
|
|
96
|
-
const path = (e as CustomEvent).detail.path as string;
|
|
97
|
-
setSelected(path);
|
|
98
|
-
el.setAttribute('active-file', path);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
return (
|
|
102
|
-
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '8px' }}>
|
|
103
|
-
<Frame>
|
|
104
|
-
<kai-file-tree
|
|
105
|
-
ref={(e) => (el = e as HTMLElement & { files?: FileTreeFile[] })}
|
|
106
|
-
active-file={selected()}
|
|
107
|
-
/>
|
|
108
|
-
</Frame>
|
|
109
|
-
<span style={{ 'font-size': '13px', color: 'var(--color-muted-foreground, #71717a)' }}>
|
|
110
|
-
Selected: <code>{selected()}</code>
|
|
111
|
-
</span>
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
},
|
|
115
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/** A deeper, nested layout with mixed file types. */
|
|
119
|
-
export const Nested: Story = {
|
|
120
|
-
render: () => {
|
|
121
|
-
let el: HTMLElement & { files?: FileTreeFile[] };
|
|
122
|
-
onMount(() => {
|
|
123
|
-
if (el) el.files = FILES;
|
|
124
|
-
});
|
|
125
|
-
return (
|
|
126
|
-
<Frame>
|
|
127
|
-
<kai-file-tree
|
|
128
|
-
ref={(e) => (el = e as HTMLElement & { files?: FileTreeFile[] })}
|
|
129
|
-
active-file="src/lib/format.ts"
|
|
130
|
-
/>
|
|
131
|
-
</Frame>
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
-
import './register'; // side effect: registers the custom elements
|
|
3
|
-
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
4
|
-
|
|
5
|
-
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
6
|
-
declare module 'solid-js' {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
|
-
namespace JSX {
|
|
9
|
-
interface IntrinsicElements {
|
|
10
|
-
'kai-file-upload': JSX.HTMLAttributes<HTMLElement> & {
|
|
11
|
-
multiple?: boolean | string;
|
|
12
|
-
accept?: string;
|
|
13
|
-
disabled?: boolean | string;
|
|
14
|
-
label?: string;
|
|
15
|
-
'on:kai-files-added'?: (e: CustomEvent<{ files: File[] }>) => void;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
22
|
-
<kai-file-upload accept="image/*" label="Drop images here"></kai-file-upload>
|
|
23
|
-
|
|
24
|
-
<script type="module">
|
|
25
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
26
|
-
|
|
27
|
-
document.querySelector('kai-file-upload')
|
|
28
|
-
.addEventListener('kai-files-added', (e) =>
|
|
29
|
-
console.log(e.detail.files.map((f) => f.name)));
|
|
30
|
-
</script>`;
|
|
31
|
-
|
|
32
|
-
const meta = {
|
|
33
|
-
title: 'Components/FileUpload',
|
|
34
|
-
tags: ['autodocs'],
|
|
35
|
-
argTypes: argTypesFor('kai-file-upload'),
|
|
36
|
-
parameters: {
|
|
37
|
-
layout: 'fullscreen',
|
|
38
|
-
docs: {
|
|
39
|
-
description: specDescription('kai-file-upload', [
|
|
40
|
-
'`<kai-file-upload>` is the framework-agnostic **web component** for a click / drag-and-drop file dropzone — isolated in **Shadow DOM**.',
|
|
41
|
-
'**When to use:** accepting file or image uploads in a non-Solid app. In SolidJS, compose the `FileUpload` primitives.',
|
|
42
|
-
'**Placement:** above or replacing the prompt input, or in a dedicated upload panel; fills its container width (set a `max-width` on the parent to constrain the dropzone).',
|
|
43
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set the `accept` / `multiple` / `label` attributes, and listen for the `kai-files-added` **CustomEvent** (`e.detail.files` is a `File[]`). The default dropzone label can be replaced with your own markup via the default `<slot>`.",
|
|
44
|
-
'See the **Code** tab for HTML usage.',
|
|
45
|
-
]),
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
} satisfies Meta;
|
|
49
|
-
|
|
50
|
-
export default meta;
|
|
51
|
-
type Story = StoryObj;
|
|
52
|
-
|
|
53
|
-
/** A dropzone accepting any files. */
|
|
54
|
-
export const Default: Story = {
|
|
55
|
-
render: () => (
|
|
56
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
57
|
-
<kai-file-upload
|
|
58
|
-
on:kai-files-added={(e: CustomEvent<{ files: File[] }>) =>
|
|
59
|
-
console.log(e.detail.files.map((f) => f.name))}
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
),
|
|
63
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/** Restricted to images, single file, with a custom label. */
|
|
67
|
-
export const ImagesOnly: Story = {
|
|
68
|
-
render: () => (
|
|
69
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
70
|
-
<kai-file-upload accept="image/*" multiple={false} label="Click or drop an image" />
|
|
71
|
-
</div>
|
|
72
|
-
),
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/** A disabled dropzone (non-interactive). */
|
|
76
|
-
export const Disabled: Story = {
|
|
77
|
-
render: () => (
|
|
78
|
-
<div style={{ padding: '24px', 'max-width': '480px' }}>
|
|
79
|
-
<kai-file-upload disabled label="Uploads are disabled" />
|
|
80
|
-
</div>
|
|
81
|
-
),
|
|
82
|
-
};
|