@kitn.ai/ui 0.14.1 → 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/components/component-meta.json +10 -10
- package/src/elements/compiled.css +1 -1
- package/src/remote/host-embed.ts +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,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the declarative `<kai-step>` light-DOM API of
|
|
3
|
-
* `<kai-chain-of-thought>`.
|
|
4
|
-
*
|
|
5
|
-
* Strategy: the `defineWebComponent` call registers a real Shadow-DOM custom
|
|
6
|
-
* element which requires a full browser environment (Constructable Stylesheets,
|
|
7
|
-
* shadow roots, etc.) and is therefore not suitable for jsdom unit tests.
|
|
8
|
-
* Instead we:
|
|
9
|
-
* 1. Test the exported `parseKaiStepElement` helper in isolation — it has no
|
|
10
|
-
* DOM dependencies beyond `Element`, which jsdom provides perfectly.
|
|
11
|
-
* 2. Test that the merged list of prop + slotted steps renders correctly via
|
|
12
|
-
* the `ChainOfThoughtStep`/`ChainOfThoughtTrigger` primitives, mirroring
|
|
13
|
-
* the pattern used in `prompt-suggestions.declarative.test.tsx`.
|
|
14
|
-
*/
|
|
15
|
-
import { describe, it, expect, afterEach } from 'vitest';
|
|
16
|
-
import '@testing-library/jest-dom/vitest';
|
|
17
|
-
import { render, cleanup } from '@solidjs/testing-library';
|
|
18
|
-
import { For, Show } from 'solid-js';
|
|
19
|
-
import { parseKaiStepElement } from './chain-of-thought';
|
|
20
|
-
|
|
21
|
-
afterEach(cleanup);
|
|
22
|
-
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
// parseKaiStepElement — pure helper
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
describe('parseKaiStepElement', () => {
|
|
28
|
-
function makeEl(label: string | null, textContent?: string): Element {
|
|
29
|
-
const el = document.createElement('kai-step');
|
|
30
|
-
if (label !== null) el.setAttribute('label', label);
|
|
31
|
-
if (textContent !== undefined) el.textContent = textContent;
|
|
32
|
-
return el;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
it('maps label attribute to Step.label', () => {
|
|
36
|
-
const step = parseKaiStepElement(makeEl('Searching docs', 'Found 3 hits'));
|
|
37
|
-
expect(step.label).toBe('Searching docs');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('maps trimmed textContent to Step.content', () => {
|
|
41
|
-
const step = parseKaiStepElement(makeEl('Step', ' Found 3 hits '));
|
|
42
|
-
expect(step.content).toBe('Found 3 hits');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('returns undefined for content when textContent is empty', () => {
|
|
46
|
-
const step = parseKaiStepElement(makeEl('Build & verify', ''));
|
|
47
|
-
expect(step.content).toBeUndefined();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('returns undefined for content when textContent is whitespace only', () => {
|
|
51
|
-
const step = parseKaiStepElement(makeEl('Build & verify', ' '));
|
|
52
|
-
expect(step.content).toBeUndefined();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('falls back to empty string for label when attribute is absent', () => {
|
|
56
|
-
const step = parseKaiStepElement(makeEl(null, 'some detail'));
|
|
57
|
-
expect(step.label).toBe('');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('returns a well-formed Step for a heading-only element', () => {
|
|
61
|
-
const step = parseKaiStepElement(makeEl('Understand the request'));
|
|
62
|
-
expect(step).toEqual({ label: 'Understand the request', content: undefined });
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('returns a well-formed Step for a step with detail', () => {
|
|
66
|
-
const step = parseKaiStepElement(makeEl('Searching docs', 'Found 3 hits'));
|
|
67
|
-
expect(step).toEqual({ label: 'Searching docs', content: 'Found 3 hits' });
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// ---------------------------------------------------------------------------
|
|
72
|
-
// Merge + render: prop steps + slotted steps combine correctly
|
|
73
|
-
// ---------------------------------------------------------------------------
|
|
74
|
-
|
|
75
|
-
interface Step {
|
|
76
|
-
label: string;
|
|
77
|
-
content?: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Minimal test harness that renders a list of Steps as labelled divs,
|
|
82
|
-
* mirroring the merge logic in chain-of-thought.tsx. We render plain divs
|
|
83
|
-
* rather than the full Shadow DOM component to stay within jsdom.
|
|
84
|
-
*/
|
|
85
|
-
function StepList(props: { items: Step[] }) {
|
|
86
|
-
return (
|
|
87
|
-
<div>
|
|
88
|
-
<For each={props.items}>
|
|
89
|
-
{(step) => (
|
|
90
|
-
<div data-testid="step">
|
|
91
|
-
<span data-testid="step-label">{step.label}</span>
|
|
92
|
-
<Show when={step.content}>
|
|
93
|
-
<span data-testid="step-content">{step.content}</span>
|
|
94
|
-
</Show>
|
|
95
|
-
</div>
|
|
96
|
-
)}
|
|
97
|
-
</For>
|
|
98
|
-
</div>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
describe('Step list rendering', () => {
|
|
103
|
-
it('renders one entry per step', () => {
|
|
104
|
-
const steps: Step[] = [
|
|
105
|
-
{ label: 'Understand the request', content: 'The user wants composable web components.' },
|
|
106
|
-
{ label: 'Design the API', content: 'Route 1: variant + flags.' },
|
|
107
|
-
{ label: 'Build & verify' },
|
|
108
|
-
];
|
|
109
|
-
const { getAllByTestId } = render(() => <StepList items={steps} />);
|
|
110
|
-
expect(getAllByTestId('step')).toHaveLength(3);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('renders the label for each step', () => {
|
|
114
|
-
const steps: Step[] = [{ label: 'Searching docs' }, { label: 'Synthesising' }];
|
|
115
|
-
const { getAllByTestId } = render(() => <StepList items={steps} />);
|
|
116
|
-
const labels = getAllByTestId('step-label').map((el) => el.textContent);
|
|
117
|
-
expect(labels).toEqual(['Searching docs', 'Synthesising']);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('renders content only when present', () => {
|
|
121
|
-
const steps: Step[] = [
|
|
122
|
-
{ label: 'With detail', content: 'Found 3 hits' },
|
|
123
|
-
{ label: 'No detail' },
|
|
124
|
-
];
|
|
125
|
-
const { getAllByTestId, queryAllByTestId } = render(() => <StepList items={steps} />);
|
|
126
|
-
const contents = queryAllByTestId('step-content');
|
|
127
|
-
expect(contents).toHaveLength(1);
|
|
128
|
-
expect(contents[0]).toHaveTextContent('Found 3 hits');
|
|
129
|
-
expect(getAllByTestId('step')).toHaveLength(2);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('renders prop steps before declarative (slotted) steps', () => {
|
|
133
|
-
const propSteps: Step[] = [{ label: 'Prop step' }];
|
|
134
|
-
const slottedSteps: Step[] = [{ label: 'Slotted step' }];
|
|
135
|
-
const merged = [...propSteps, ...slottedSteps];
|
|
136
|
-
|
|
137
|
-
const { getAllByTestId } = render(() => <StepList items={merged} />);
|
|
138
|
-
const labels = getAllByTestId('step-label').map((el) => el.textContent);
|
|
139
|
-
expect(labels).toEqual(['Prop step', 'Slotted step']);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('parseKaiStepElement produces steps that render with the correct label and content', () => {
|
|
143
|
-
const el = document.createElement('kai-step');
|
|
144
|
-
el.setAttribute('label', 'Searching docs');
|
|
145
|
-
el.textContent = 'Found 3 hits';
|
|
146
|
-
|
|
147
|
-
const step = parseKaiStepElement(el);
|
|
148
|
-
const { getByTestId } = render(() => <StepList items={[step]} />);
|
|
149
|
-
|
|
150
|
-
expect(getByTestId('step-label')).toHaveTextContent('Searching docs');
|
|
151
|
-
expect(getByTestId('step-content')).toHaveTextContent('Found 3 hits');
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,113 +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
|
-
interface Step {
|
|
7
|
-
label: string;
|
|
8
|
-
content?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
12
|
-
declare module 'solid-js' {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
-
namespace JSX {
|
|
15
|
-
interface IntrinsicElements {
|
|
16
|
-
'kai-chain-of-thought': JSX.HTMLAttributes<HTMLElement>;
|
|
17
|
-
/** Light-DOM data carrier for declarative steps inside `<kai-chain-of-thought>`. */
|
|
18
|
-
'kai-step': JSX.HTMLAttributes<HTMLElement> & { label?: string };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const steps: Step[] = [
|
|
24
|
-
{ label: 'Understand the request', content: 'The user wants a composable set of web components.' },
|
|
25
|
-
{ label: 'Design the API', content: 'Route 1: variant + flags + events; rich data via properties.' },
|
|
26
|
-
{ label: 'Build & verify' },
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
/** Render `<kai-chain-of-thought>` with the `steps` set as a JS property. */
|
|
30
|
-
function CotElement(props: { steps: Step[] }) {
|
|
31
|
-
let el: (HTMLElement & { steps?: Step[] }) | undefined;
|
|
32
|
-
onMount(() => {
|
|
33
|
-
if (el) el.steps = props.steps;
|
|
34
|
-
});
|
|
35
|
-
return (
|
|
36
|
-
<kai-chain-of-thought ref={(e) => (el = e as HTMLElement)} style={{ display: 'block', padding: '24px', 'max-width': '560px' }} />
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
41
|
-
<kai-chain-of-thought id="cot"></kai-chain-of-thought>
|
|
42
|
-
|
|
43
|
-
<script type="module">
|
|
44
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
45
|
-
|
|
46
|
-
document.getElementById('cot').steps = [
|
|
47
|
-
{ label: 'Understand the request', content: 'The user wants a composable set.' },
|
|
48
|
-
{ label: 'Design the API', content: 'Route 1: variant + flags + events.' },
|
|
49
|
-
{ label: 'Build & verify' },
|
|
50
|
-
];
|
|
51
|
-
</script>`;
|
|
52
|
-
|
|
53
|
-
const meta = {
|
|
54
|
-
title: 'Components/ChainOfThought',
|
|
55
|
-
tags: ['autodocs'],
|
|
56
|
-
argTypes: argTypesFor('kai-chain-of-thought'),
|
|
57
|
-
parameters: {
|
|
58
|
-
layout: 'fullscreen',
|
|
59
|
-
docs: {
|
|
60
|
-
description: specDescription('kai-chain-of-thought', [
|
|
61
|
-
'`<kai-chain-of-thought>` is the framework-agnostic **web component** for step-by-step reasoning — a connected list of steps, each with optional collapsible detail — isolated in **Shadow DOM**. The compound primitive collapses to a single `steps` data model (Route 1).',
|
|
62
|
-
'**When to use:** surfacing an agent\'s plan or reasoning trace in a non-Solid app. In SolidJS, compose the `ChainOfThought` primitives for finer control.',
|
|
63
|
-
'**Placement:** as a block above or below a message, or in a dedicated reasoning panel; it is `display: block` and sizes to content height, so no fixed height is required.',
|
|
64
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`. **Property API:** set the `steps` **property** — an array of `{ label, content? }` objects; steps with `content` become expandable. **Declarative API:** compose `<kai-step label=\"…\">…detail…</kai-step>` child elements directly in the HTML — the `label` attribute becomes the heading, `textContent` the optional expandable detail. Declarative children are merged after any prop steps.",
|
|
65
|
-
'See the **Code** tab for HTML usage.',
|
|
66
|
-
]),
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
} satisfies Meta;
|
|
70
|
-
|
|
71
|
-
export default meta;
|
|
72
|
-
type Story = StoryObj;
|
|
73
|
-
|
|
74
|
-
/** A three-step reasoning trace; the last step has no detail. */
|
|
75
|
-
export const Default: Story = {
|
|
76
|
-
render: () => <CotElement steps={steps} />,
|
|
77
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const DECLARATIVE_HTML_SNIPPET = `<!-- Works in any framework or plain HTML — no JS property assignment needed -->
|
|
81
|
-
<kai-chain-of-thought>
|
|
82
|
-
<kai-step label="Understand the request">The user wants a composable set of web components.</kai-step>
|
|
83
|
-
<kai-step label="Design the API">Route 1: variant + flags + events; rich data via properties.</kai-step>
|
|
84
|
-
<kai-step label="Build & verify"></kai-step>
|
|
85
|
-
</kai-chain-of-thought>
|
|
86
|
-
|
|
87
|
-
<script type="module">
|
|
88
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
89
|
-
</script>`;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Declare each reasoning step as a `<kai-step>` child element — no `steps`
|
|
93
|
-
* property or JS array wiring needed. The `label` attribute becomes the
|
|
94
|
-
* step heading; `textContent` becomes the optional expandable detail.
|
|
95
|
-
* Children are light-DOM data carriers hidden by the Shadow DOM — pure data,
|
|
96
|
-
* no visible output of their own.
|
|
97
|
-
* Mix with the `steps` prop: prop items render first, declarative children after.
|
|
98
|
-
*/
|
|
99
|
-
export const DeclarativeSteps: Story = {
|
|
100
|
-
name: 'Declarative Steps (kai-step)',
|
|
101
|
-
render: () => (
|
|
102
|
-
<kai-chain-of-thought style={{ display: 'block', padding: '24px', 'max-width': '560px' }}>
|
|
103
|
-
<kai-step label="Understand the request">The user wants a composable set of web components.</kai-step>
|
|
104
|
-
<kai-step label="Design the API">Route 1: variant + flags + events; rich data via properties.</kai-step>
|
|
105
|
-
<kai-step label="Build & verify"></kai-step>
|
|
106
|
-
</kai-chain-of-thought>
|
|
107
|
-
),
|
|
108
|
-
parameters: {
|
|
109
|
-
docs: {
|
|
110
|
-
source: { code: DECLARATIVE_HTML_SNIPPET, language: 'html' },
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
};
|
|
@@ -1,73 +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-scope-picker': JSX.HTMLAttributes<HTMLElement> & {
|
|
12
|
-
'current-label'?: string;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Render `<kai-scope-picker>` with author/tag options set as properties. */
|
|
19
|
-
function ScopePickerElement(props: { authors: string[]; tags: string[] }) {
|
|
20
|
-
let el: (HTMLElement & { availableAuthors?: string[]; availableTags?: string[] }) | undefined;
|
|
21
|
-
onMount(() => {
|
|
22
|
-
if (!el) return;
|
|
23
|
-
el.availableAuthors = props.authors;
|
|
24
|
-
el.availableTags = props.tags;
|
|
25
|
-
el.addEventListener('kai-scope-change', (e) => {
|
|
26
|
-
const ev = e as CustomEvent<{ filters: unknown }>;
|
|
27
|
-
console.log('kai-scope-change', ev.detail.filters ?? 'all');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
return (
|
|
31
|
-
<kai-scope-picker ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '40px' }} />
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
36
|
-
<kai-scope-picker id="scope"></kai-scope-picker>
|
|
37
|
-
|
|
38
|
-
<script type="module">
|
|
39
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
40
|
-
|
|
41
|
-
const scope = document.getElementById('scope');
|
|
42
|
-
scope.availableAuthors = ['Rob', 'Alex'];
|
|
43
|
-
scope.availableTags = ['design', 'api'];
|
|
44
|
-
// undefined filters means "All Content"
|
|
45
|
-
scope.addEventListener('kai-scope-change', (e) => console.log(e.detail.filters ?? 'all'));
|
|
46
|
-
</script>`;
|
|
47
|
-
|
|
48
|
-
const meta = {
|
|
49
|
-
title: 'Components/ScopePicker',
|
|
50
|
-
tags: ['autodocs'],
|
|
51
|
-
argTypes: argTypesFor('kai-scope-picker'),
|
|
52
|
-
parameters: {
|
|
53
|
-
layout: 'fullscreen',
|
|
54
|
-
docs: {
|
|
55
|
-
description: specDescription('kai-scope-picker', [
|
|
56
|
-
'`<kai-scope-picker>` is the framework-agnostic **web component** for scoping a chat by author or tag — a dropdown that emits the chosen filters — isolated in **Shadow DOM**.',
|
|
57
|
-
'**When to use:** letting users narrow a conversation/search to a subset of content. In SolidJS, use the `ChatScopePicker` primitive.',
|
|
58
|
-
'**Placement:** in the chat header or above the conversation list, beside the search input; it is a compact `inline-block` dropdown trigger that pairs naturally with `<kai-model-switcher>` or other header controls.',
|
|
59
|
-
"**How to use:** register once with `import '@kitn.ai/ui/elements'`, set the `availableAuthors` / `availableTags` **properties** (and optionally `current-label`), and listen for the `kai-scope-change` **CustomEvent** (`undefined` filters = \"All Content\").",
|
|
60
|
-
'See the **Code** tab for HTML usage.',
|
|
61
|
-
]),
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
} satisfies Meta;
|
|
65
|
-
|
|
66
|
-
export default meta;
|
|
67
|
-
type Story = StoryObj;
|
|
68
|
-
|
|
69
|
-
/** Authors and tags available as scope filters. */
|
|
70
|
-
export const Default: Story = {
|
|
71
|
-
render: () => <ScopePickerElement authors={['Rob', 'Alex']} tags={['design', 'api']} />,
|
|
72
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
73
|
-
};
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
-
import { onMount, createSignal } from 'solid-js';
|
|
3
|
-
import './register'; // side effect: registers all kitn custom elements including <kai-workspace>
|
|
4
|
-
import type { ConversationGroup, ConversationSummary, ModelOption } from '../types';
|
|
5
|
-
import type { ChatMessage } from './chat-types';
|
|
6
|
-
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
7
|
-
|
|
8
|
-
// The web components are custom DOM elements, so declare the tags for JSX.
|
|
9
|
-
declare module 'solid-js' {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
11
|
-
namespace JSX {
|
|
12
|
-
interface IntrinsicElements {
|
|
13
|
-
'kai-workspace': JSX.HTMLAttributes<HTMLElement>;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const sampleGroups: ConversationGroup[] = [
|
|
19
|
-
{ id: 'today', name: 'Today', sortOrder: 0, createdAt: '2026-06-13T00:00:00.000Z' },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const sampleConversations: ConversationSummary[] = [
|
|
23
|
-
{
|
|
24
|
-
id: '1',
|
|
25
|
-
title: 'Web component architecture',
|
|
26
|
-
groupId: 'today',
|
|
27
|
-
scope: { type: 'document' },
|
|
28
|
-
messageCount: 12,
|
|
29
|
-
lastMessageAt: '2026-06-13T15:30:00.000Z',
|
|
30
|
-
updatedAt: '2026-06-13T15:30:00.000Z',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: '2',
|
|
34
|
-
title: 'Theming & tokens',
|
|
35
|
-
groupId: 'today',
|
|
36
|
-
scope: { type: 'document' },
|
|
37
|
-
messageCount: 5,
|
|
38
|
-
lastMessageAt: '2026-06-13T11:20:00.000Z',
|
|
39
|
-
updatedAt: '2026-06-13T11:20:00.000Z',
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const sampleModels: ModelOption[] = [
|
|
44
|
-
{ id: 'claude-4', name: 'Claude 4 Opus', provider: 'Anthropic' },
|
|
45
|
-
{ id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
const sampleMessages: ChatMessage[] = [
|
|
49
|
-
{ id: 'm1', role: 'user', content: 'How do I drop the whole chat app in with one tag?' },
|
|
50
|
-
{
|
|
51
|
-
id: 'm2',
|
|
52
|
-
role: 'assistant',
|
|
53
|
-
content:
|
|
54
|
-
'Use `<kai-workspace>` — set `conversations`, `messages`, and `models` as properties and listen for `kai-conversation-select` + `kai-submit`.',
|
|
55
|
-
actions: ['copy', 'like'],
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
type WorkspaceEl = HTMLElement & {
|
|
60
|
-
groups?: ConversationGroup[];
|
|
61
|
-
conversations?: ConversationSummary[];
|
|
62
|
-
activeId?: string;
|
|
63
|
-
messages?: ChatMessage[];
|
|
64
|
-
models?: ModelOption[];
|
|
65
|
-
currentModel?: string;
|
|
66
|
-
chatTitle?: string;
|
|
67
|
-
placeholder?: string;
|
|
68
|
-
loading?: boolean;
|
|
69
|
-
suggestionMode?: string;
|
|
70
|
-
proseSize?: string;
|
|
71
|
-
codeTheme?: string;
|
|
72
|
-
codeHighlight?: boolean;
|
|
73
|
-
scrollButton?: boolean;
|
|
74
|
-
search?: boolean;
|
|
75
|
-
voice?: boolean;
|
|
76
|
-
slashCompact?: boolean;
|
|
77
|
-
sidebarWidth?: number;
|
|
78
|
-
sidebarMinWidth?: number;
|
|
79
|
-
sidebarMaxWidth?: number;
|
|
80
|
-
sidebarCollapsed?: boolean;
|
|
81
|
-
defaultSidebarCollapsed?: boolean;
|
|
82
|
-
value?: string;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/** Live demo of the actual `<kai-workspace>` custom element (Shadow DOM and all). */
|
|
86
|
-
function WorkspaceElement(props: { args?: Record<string, unknown> }) {
|
|
87
|
-
let el: WorkspaceEl | undefined;
|
|
88
|
-
onMount(() => {
|
|
89
|
-
if (el) {
|
|
90
|
-
// Fixed array/object data
|
|
91
|
-
el.groups = sampleGroups;
|
|
92
|
-
el.conversations = sampleConversations;
|
|
93
|
-
el.activeId = '1';
|
|
94
|
-
el.messages = sampleMessages;
|
|
95
|
-
el.models = sampleModels;
|
|
96
|
-
el.currentModel = 'claude-4';
|
|
97
|
-
el.chatTitle = 'Web component architecture';
|
|
98
|
-
// Scalar args from Controls (override defaults above for scalar props)
|
|
99
|
-
const args = props.args;
|
|
100
|
-
if (args) {
|
|
101
|
-
const scalarNames = [
|
|
102
|
-
'placeholder', 'loading', 'suggestionMode', 'proseSize', 'codeTheme',
|
|
103
|
-
'codeHighlight', 'scrollButton', 'search', 'voice', 'slashCompact',
|
|
104
|
-
'sidebarWidth', 'sidebarMinWidth', 'sidebarMaxWidth', 'defaultSidebarCollapsed', 'value',
|
|
105
|
-
];
|
|
106
|
-
for (const name of scalarNames) {
|
|
107
|
-
if (name in args) (el as unknown as Record<string, unknown>)[name] = args[name];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
el.addEventListener('kai-conversation-select', (e) => console.log('select', (e as CustomEvent).detail));
|
|
111
|
-
el.addEventListener('kai-submit', (e) => console.log('submit', (e as unknown as CustomEvent).detail));
|
|
112
|
-
el.addEventListener('kai-sidebar-toggle', (e) => console.log('kai-sidebar-toggle', (e as CustomEvent).detail));
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return (
|
|
116
|
-
<div style={{ height: '720px', width: '100%' }}>
|
|
117
|
-
<kai-workspace
|
|
118
|
-
ref={(e) => (el = e as WorkspaceEl)}
|
|
119
|
-
style={{ display: 'block', height: '100%' }}
|
|
120
|
-
/>
|
|
121
|
-
</div>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
126
|
-
<kai-workspace id="workspace" style="display:block; height:100vh;"></kai-workspace>
|
|
127
|
-
|
|
128
|
-
<script type="module">
|
|
129
|
-
import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
130
|
-
|
|
131
|
-
const workspace = document.getElementById('workspace');
|
|
132
|
-
workspace.conversations = [
|
|
133
|
-
{
|
|
134
|
-
id: '1', title: 'Web component architecture',
|
|
135
|
-
scope: { type: 'document' }, messageCount: 12,
|
|
136
|
-
lastMessageAt: '2026-06-13T15:30:00Z', updatedAt: '2026-06-13T15:30:00Z',
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
workspace.messages = [
|
|
140
|
-
{ id: 'm1', role: 'user', content: 'How do I drop the whole chat app in with one tag?' },
|
|
141
|
-
{ id: 'm2', role: 'assistant', content: 'Use <kai-workspace> — set conversations, messages, and models as properties.' },
|
|
142
|
-
];
|
|
143
|
-
workspace.models = [
|
|
144
|
-
{ id: 'claude-4', name: 'Claude 4 Opus', provider: 'Anthropic' },
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
// events are CustomEvents on the element (they do not bubble)
|
|
148
|
-
workspace.addEventListener('kai-conversation-select', (e) => console.log('selected conversation:', e.detail.id));
|
|
149
|
-
workspace.addEventListener('kai-submit', (e) => console.log('user sent:', e.detail.value));
|
|
150
|
-
workspace.addEventListener('kai-sidebar-toggle', (e) => console.log('sidebar collapsed:', e.detail.collapsed));
|
|
151
|
-
</script>`;
|
|
152
|
-
|
|
153
|
-
const SOLID_SNIPPET = `import '@kitn.ai/ui/elements'; // registers the custom elements
|
|
154
|
-
import { onMount } from 'solid-js';
|
|
155
|
-
import type { ConversationSummary, ModelOption } from '@kitn.ai/ui';
|
|
156
|
-
import type { ChatMessage } from '@kitn.ai/ui/elements';
|
|
157
|
-
|
|
158
|
-
function Workspace() {
|
|
159
|
-
let el: HTMLElement & {
|
|
160
|
-
conversations?: ConversationSummary[];
|
|
161
|
-
messages?: ChatMessage[];
|
|
162
|
-
models?: ModelOption[];
|
|
163
|
-
activeId?: string;
|
|
164
|
-
};
|
|
165
|
-
const conversations: ConversationSummary[] = [
|
|
166
|
-
{
|
|
167
|
-
id: '1', title: 'Web component architecture',
|
|
168
|
-
scope: { type: 'document' }, messageCount: 12,
|
|
169
|
-
lastMessageAt: '2026-06-13T15:30:00Z', updatedAt: '2026-06-13T15:30:00Z',
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
const messages: ChatMessage[] = [
|
|
173
|
-
{ id: 'm1', role: 'user', content: 'How do I drop the whole chat app in with one tag?' },
|
|
174
|
-
{ id: 'm2', role: 'assistant', content: 'Use <kai-workspace> — set conversations, messages, and models as properties.' },
|
|
175
|
-
];
|
|
176
|
-
onMount(() => {
|
|
177
|
-
el.conversations = conversations;
|
|
178
|
-
el.messages = messages;
|
|
179
|
-
el.activeId = '1';
|
|
180
|
-
el.addEventListener('kai-conversation-select', (e) => console.log('selected:', e.detail.id));
|
|
181
|
-
el.addEventListener('kai-submit', (e) => console.log('user sent:', e.detail.value));
|
|
182
|
-
el.addEventListener('kai-sidebar-toggle', (e) => console.log('sidebar collapsed:', e.detail.collapsed));
|
|
183
|
-
});
|
|
184
|
-
return (
|
|
185
|
-
<kai-workspace
|
|
186
|
-
ref={el}
|
|
187
|
-
style={{ display: 'block', height: '100vh' }}
|
|
188
|
-
/>
|
|
189
|
-
);
|
|
190
|
-
}`;
|
|
191
|
-
|
|
192
|
-
const meta = {
|
|
193
|
-
title: 'Components/Workspace',
|
|
194
|
-
tags: ['autodocs'],
|
|
195
|
-
argTypes: argTypesFor('kai-workspace'),
|
|
196
|
-
parameters: {
|
|
197
|
-
layout: 'fullscreen',
|
|
198
|
-
docs: {
|
|
199
|
-
description: specDescription('kai-workspace', [
|
|
200
|
-
'`<kai-workspace>` is the full chat shell as a single **web component** — a resizable split layout with a collapsible conversation list on the left and a full message thread on the right, all isolated in **Shadow DOM**. SolidJS is bundled in, so the host needs nothing.',
|
|
201
|
-
'**When to use:** dropping an entire chat application shell into a non-Solid app (React, Vue, Svelte, plain HTML), or anywhere you want zero style conflicts and a ready-made list+chat layout. If you *are* in SolidJS and want fine-grained control, compose the `ConversationList` and `ChatThread` primitives directly.',
|
|
202
|
-
'**How to use:** register once with `import \'@kitn.ai/ui/elements\'`, set rich data as JS **properties** (`el.conversations = [...]`, `el.messages = [...]`, `el.models = [...]`), and listen for **CustomEvents** (`kai-conversation-select`, `kai-submit`, `kai-sidebar-toggle`, `kai-new-chat`) directly on the element.',
|
|
203
|
-
'**Anatomy:** **sidebar panel** (a `<kai-conversations>` list with new-chat + collapse toggle, drag-resizable via an inner divider handle, collapses to a ghost reveal button) | **divider handle** (drag or click to resize; disappears when collapsed) | **chat panel** (the full `<ChatThread>`: header + message list + prompt composer; the thread node is stable across collapse/expand).',
|
|
204
|
-
'**Placement:** as a full-page surface or large panel. Give it an explicit height (e.g. `height: 100vh`). The sidebar is drag-resizable and can be collapsed via the toggle button in its header.',
|
|
205
|
-
'See the **Code** tab below for the HTML usage; the *SolidJS* story shows the same element inside a Solid component.',
|
|
206
|
-
]),
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
} satisfies Meta;
|
|
210
|
-
|
|
211
|
-
export default meta;
|
|
212
|
-
type Story = StoryObj;
|
|
213
|
-
|
|
214
|
-
/** The element used the plain-HTML / any-framework way. */
|
|
215
|
-
export const Default: Story = {
|
|
216
|
-
args: {
|
|
217
|
-
placeholder: 'Send a message...',
|
|
218
|
-
loading: false,
|
|
219
|
-
suggestionMode: 'submit',
|
|
220
|
-
proseSize: 'sm',
|
|
221
|
-
codeTheme: 'github-dark-dimmed',
|
|
222
|
-
codeHighlight: true,
|
|
223
|
-
scrollButton: true,
|
|
224
|
-
search: false,
|
|
225
|
-
voice: false,
|
|
226
|
-
slashCompact: false,
|
|
227
|
-
},
|
|
228
|
-
render: (args: Record<string, unknown>) => <WorkspaceElement args={args} />,
|
|
229
|
-
parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
/** The same element used inside a SolidJS component (properties via `ref` + `onMount`, events via `addEventListener`). */
|
|
233
|
-
export const InSolidJS: Story = {
|
|
234
|
-
name: 'In SolidJS',
|
|
235
|
-
render: () => <WorkspaceElement />,
|
|
236
|
-
parameters: { docs: { source: { code: SOLID_SNIPPET, language: 'tsx' } } },
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const CONTROLLED_SNIPPET = `const ws = document.getElementById('workspace');
|
|
240
|
-
let collapsed = false;
|
|
241
|
-
ws.sidebarCollapsed = collapsed; // app owns the state
|
|
242
|
-
|
|
243
|
-
// react to the in-component toggle AND drive it from your own UI
|
|
244
|
-
ws.addEventListener('kai-sidebar-toggle', (e) => {
|
|
245
|
-
collapsed = e.detail.collapsed;
|
|
246
|
-
ws.sidebarCollapsed = collapsed; // persist / restore as you like
|
|
247
|
-
});
|
|
248
|
-
document.getElementById('toggle').onclick = () => {
|
|
249
|
-
collapsed = !collapsed;
|
|
250
|
-
ws.sidebarCollapsed = collapsed; // collapse from outside the header
|
|
251
|
-
};`;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Controlled collapse: the app owns `sidebarCollapsed`, drives it as a property,
|
|
255
|
-
* and updates it from `kai-sidebar-toggle`. An external button collapses the
|
|
256
|
-
* sidebar from outside the workspace — only possible because the state is
|
|
257
|
-
* controlled (uncontrolled mode keeps collapse internal to the element).
|
|
258
|
-
*/
|
|
259
|
-
export const ControlledSidebar: Story = {
|
|
260
|
-
name: 'Controlled sidebar',
|
|
261
|
-
render: () => {
|
|
262
|
-
let el: WorkspaceEl | undefined;
|
|
263
|
-
const [collapsed, setCollapsed] = createSignal(false);
|
|
264
|
-
const drive = (next: boolean) => { setCollapsed(next); if (el) el.sidebarCollapsed = next; };
|
|
265
|
-
onMount(() => {
|
|
266
|
-
if (!el) return;
|
|
267
|
-
el.groups = sampleGroups;
|
|
268
|
-
el.conversations = sampleConversations;
|
|
269
|
-
el.activeId = '1';
|
|
270
|
-
el.messages = sampleMessages;
|
|
271
|
-
el.models = sampleModels;
|
|
272
|
-
el.currentModel = 'claude-4';
|
|
273
|
-
el.chatTitle = 'Web component architecture';
|
|
274
|
-
el.sidebarCollapsed = collapsed();
|
|
275
|
-
el.addEventListener('kai-sidebar-toggle', (e) => drive((e as CustomEvent<{ collapsed: boolean }>).detail.collapsed));
|
|
276
|
-
});
|
|
277
|
-
return (
|
|
278
|
-
<div style={{ height: '720px', width: '100%', display: 'flex', 'flex-direction': 'column', gap: '8px' }}>
|
|
279
|
-
<button type="button" onClick={() => drive(!collapsed())} style={{ 'align-self': 'flex-start', padding: '6px 12px', 'border-radius': '8px', border: '1px solid var(--color-border)', cursor: 'pointer' }}>
|
|
280
|
-
{collapsed() ? 'Expand' : 'Collapse'} sidebar (from the app)
|
|
281
|
-
</button>
|
|
282
|
-
<kai-workspace ref={(e) => (el = e as WorkspaceEl)} style={{ display: 'block', flex: '1', 'min-height': '0' }} />
|
|
283
|
-
</div>
|
|
284
|
-
);
|
|
285
|
-
},
|
|
286
|
-
parameters: { docs: { source: { code: CONTROLLED_SNIPPET, language: 'js' } } },
|
|
287
|
-
};
|
|
288
|
-
|