@kitnai/chat 0.1.0
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 +314 -0
- package/dist/bash-InADTalH.js +6 -0
- package/dist/core-AYMC6_lb.js +5874 -0
- package/dist/engine-javascript-vq0WuIJl.js +2643 -0
- package/dist/github-dark-dimmed-DUshB20C.js +4 -0
- package/dist/github-light-JYsPkUQd.js +4 -0
- package/dist/javascript-C25yR2R2.js +6 -0
- package/dist/json-DxJze_jm.js +6 -0
- package/dist/kitn-chat.es.js +6632 -0
- package/dist/tsx-B8rCNbgL.js +6 -0
- package/dist/typescript-RycA9KXf.js +6 -0
- package/package.json +80 -0
- package/src/components/attachments.stories.tsx +304 -0
- package/src/components/attachments.tsx +394 -0
- package/src/components/chain-of-thought.stories.tsx +212 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +188 -0
- package/src/components/chat-container.tsx +78 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/checkpoint.stories.tsx +103 -0
- package/src/components/checkpoint.tsx +81 -0
- package/src/components/code-block.stories.tsx +151 -0
- package/src/components/code-block.tsx +99 -0
- package/src/components/context.stories.tsx +180 -0
- package/src/components/context.tsx +323 -0
- package/src/components/conversation-item.stories.tsx +126 -0
- package/src/components/conversation-item.tsx +18 -0
- package/src/components/conversation-list.stories.tsx +134 -0
- package/src/components/conversation-list.tsx +100 -0
- package/src/components/empty.stories.tsx +435 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +101 -0
- package/src/components/feedback-bar.tsx +58 -0
- package/src/components/file-upload.stories.tsx +157 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/image.stories.tsx +90 -0
- package/src/components/image.tsx +67 -0
- package/src/components/loader.stories.tsx +182 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +181 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-narrow.stories.tsx +330 -0
- package/src/components/message-skills.stories.tsx +212 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +282 -0
- package/src/components/message.tsx +149 -0
- package/src/components/model-switcher.stories.tsx +98 -0
- package/src/components/model-switcher.tsx +36 -0
- package/src/components/prompt-input.stories.tsx +223 -0
- package/src/components/prompt-input.tsx +190 -0
- package/src/components/prompt-suggestion.stories.tsx +143 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +141 -0
- package/src/components/reasoning.tsx +157 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +101 -0
- package/src/components/scroll-button.tsx +33 -0
- package/src/components/slash-command.stories.tsx +164 -0
- package/src/components/slash-command.tsx +223 -0
- package/src/components/source.stories.tsx +125 -0
- package/src/components/source.tsx +129 -0
- package/src/components/text-shimmer.stories.tsx +88 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +88 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +154 -0
- package/src/components/tool.tsx +173 -0
- package/src/components/voice-input.stories.tsx +84 -0
- package/src/components/voice-input.tsx +103 -0
- package/src/elements/chat-types.ts +14 -0
- package/src/elements/chat.tsx +111 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/conversation-list.tsx +26 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +53 -0
- package/src/elements/define.tsx +54 -0
- package/src/elements/kitn-chat.stories.tsx +105 -0
- package/src/elements/kitn-conversation-list.stories.tsx +177 -0
- package/src/elements/kitn-prompt-input.stories.tsx +123 -0
- package/src/elements/prompt-input.tsx +39 -0
- package/src/elements/register.ts +9 -0
- package/src/elements/styles.css +12 -0
- package/src/index.ts +128 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/highlighter.ts +150 -0
- package/src/primitives/use-auto-resize.ts +31 -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/stories/chat-panel-layout.stories.tsx +144 -0
- package/src/stories/chat-scene.tsx +570 -0
- package/src/stories/checkpoint-restore.stories.tsx +224 -0
- package/src/stories/context-usage.stories.tsx +155 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +151 -0
- package/src/stories/conversation-with-sources.stories.tsx +165 -0
- package/src/stories/docs/GettingStarted.mdx +76 -0
- package/src/stories/docs/Installation.mdx +48 -0
- package/src/stories/docs/Integrations.mdx +110 -0
- package/src/stories/docs/Introduction.mdx +29 -0
- package/src/stories/docs/Theming.mdx +87 -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 +145 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +167 -0
- package/src/stories/prompt-input-variants.stories.tsx +179 -0
- package/src/stories/streaming-response.stories.tsx +234 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/types.ts +41 -0
- package/src/ui/avatar.stories.tsx +104 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +87 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +146 -0
- package/src/ui/button.tsx +37 -0
- package/src/ui/collapsible.tsx +14 -0
- package/src/ui/dialog.tsx +21 -0
- package/src/ui/dropdown.tsx +26 -0
- package/src/ui/hover-card.tsx +48 -0
- package/src/ui/resizable.stories.tsx +171 -0
- package/src/ui/resizable.tsx +219 -0
- package/src/ui/scroll-area.tsx +13 -0
- package/src/ui/separator.stories.tsx +82 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +338 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +75 -0
- package/src/ui/tooltip.tsx +22 -0
- package/src/utils/cn.ts +6 -0
- package/theme.css +115 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Badge } from './badge';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'UI/Badge',
|
|
6
|
+
component: Badge,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: 'padded',
|
|
10
|
+
docs: {
|
|
11
|
+
controls: { exclude: ['use:eventListener'] },
|
|
12
|
+
description: {
|
|
13
|
+
component: [
|
|
14
|
+
'A compact pill **badge** for short status text, counts, or citation markers, rendered as an inline `<span>`.',
|
|
15
|
+
'**When to use:** to annotate a count (unread, results), tag a status/label, or mark an inline source citation in assistant output.',
|
|
16
|
+
'**How to use:** choose a `variant` (`default` label, `count` numeric pill, `citation` clickable source marker) and pass the text or number as children.',
|
|
17
|
+
'**Placement:** inline with message text (citations), next to titles or list items (labels), and on toolbar/icon buttons (counts).',
|
|
18
|
+
].join('\n\n'),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
argTypes: {
|
|
23
|
+
variant: {
|
|
24
|
+
control: 'select',
|
|
25
|
+
options: ['default', 'count', 'citation'],
|
|
26
|
+
description: 'Visual style: neutral label, numeric count pill, or clickable citation marker.',
|
|
27
|
+
table: { defaultValue: { summary: 'default' } },
|
|
28
|
+
},
|
|
29
|
+
children: {
|
|
30
|
+
control: 'text',
|
|
31
|
+
description: 'Badge content — short text or a number.',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
variant: 'default',
|
|
36
|
+
children: 'Default badge',
|
|
37
|
+
},
|
|
38
|
+
render: (args) => <Badge {...args} />,
|
|
39
|
+
} satisfies Meta<typeof Badge>;
|
|
40
|
+
|
|
41
|
+
export default meta;
|
|
42
|
+
type Story = StoryObj<typeof meta>;
|
|
43
|
+
|
|
44
|
+
const IMPORT = `import { Badge } from '@kitnai/chat';`;
|
|
45
|
+
const src = (code: string) => ({
|
|
46
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** Interactive playground — switch the variant and edit the content. */
|
|
50
|
+
export const Playground: Story = {
|
|
51
|
+
...src(`<Badge variant="default">Default badge</Badge>`),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const Default: Story = {
|
|
55
|
+
args: { variant: 'default', children: 'Default badge' },
|
|
56
|
+
...src(`<Badge variant="default">Default badge</Badge>`),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const Count: Story = {
|
|
60
|
+
args: { variant: 'count', children: '12' },
|
|
61
|
+
...src(`<Badge variant="count">12</Badge>`),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const Citation: Story = {
|
|
65
|
+
args: { variant: 'citation', children: '1' },
|
|
66
|
+
...src(`<Badge variant="citation">1</Badge>`),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** All variants side by side (showcase — not driven by controls). */
|
|
70
|
+
export const AllVariants: Story = {
|
|
71
|
+
render: () => (
|
|
72
|
+
<div class="flex items-center gap-3">
|
|
73
|
+
<Badge variant="default">Default</Badge>
|
|
74
|
+
<Badge variant="count">5</Badge>
|
|
75
|
+
<Badge variant="citation">1</Badge>
|
|
76
|
+
<Badge variant="citation">2</Badge>
|
|
77
|
+
<Badge variant="citation">3</Badge>
|
|
78
|
+
</div>
|
|
79
|
+
),
|
|
80
|
+
...src(`<div class="flex items-center gap-3">
|
|
81
|
+
<Badge variant="default">Default</Badge>
|
|
82
|
+
<Badge variant="count">5</Badge>
|
|
83
|
+
<Badge variant="citation">1</Badge>
|
|
84
|
+
<Badge variant="citation">2</Badge>
|
|
85
|
+
<Badge variant="citation">3</Badge>
|
|
86
|
+
</div>`),
|
|
87
|
+
};
|
package/src/ui/badge.tsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
|
|
5
|
+
const badgeVariants = cva('inline-flex items-center justify-center rounded-full text-xs font-medium min-h-5 min-w-5', {
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: 'bg-muted text-muted-foreground px-2 py-0.5',
|
|
9
|
+
count: 'bg-muted text-muted-foreground h-5 px-1.5',
|
|
10
|
+
citation: 'bg-primary text-primary-foreground px-1.5 py-0.5 cursor-pointer',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
defaultVariants: { variant: 'default' },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export interface BadgeProps extends JSX.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof badgeVariants> {}
|
|
17
|
+
|
|
18
|
+
export function Badge(props: BadgeProps) {
|
|
19
|
+
const [local, rest] = splitProps(props, ['variant', 'class', 'children']);
|
|
20
|
+
return <span class={cn(badgeVariants({ variant: local.variant }), local.class)} {...rest}>{local.children}</span>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { Button } from './button';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convention exemplar — every component story should follow this shape:
|
|
7
|
+
* `component`, a description, `argTypes` (controls), `args` (defaults incl.
|
|
8
|
+
* `fn()` for events), a `Playground` story rendered from args, plus showcase
|
|
9
|
+
* stories for notable variations.
|
|
10
|
+
*/
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'UI/Button',
|
|
13
|
+
component: Button,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
parameters: {
|
|
16
|
+
layout: 'padded',
|
|
17
|
+
docs: {
|
|
18
|
+
description: {
|
|
19
|
+
component: [
|
|
20
|
+
'A clickable button with style **variants** and **sizes**, built on a native `<button>` (all standard button attributes pass through).',
|
|
21
|
+
'**When to use:** any user-triggered action — submitting input, toolbar/icon actions, confirming or dismissing. Use `default` for the primary action, `ghost`/`outline` for secondary or low-emphasis actions.',
|
|
22
|
+
'**How to use:** set `variant` and `size`, pass label or an icon as children, and wire `onClick`. For icon-only buttons use `size="icon"` / `"icon-sm"` and include an `aria-label`.',
|
|
23
|
+
'**Placement:** prompt action bars, message action rows, dialogs, toolbars, and empty-state CTAs.',
|
|
24
|
+
].join('\n\n'),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
argTypes: {
|
|
29
|
+
variant: {
|
|
30
|
+
control: 'select',
|
|
31
|
+
options: ['default', 'ghost', 'outline'],
|
|
32
|
+
description: 'Visual emphasis of the button.',
|
|
33
|
+
table: { defaultValue: { summary: 'default' } },
|
|
34
|
+
},
|
|
35
|
+
size: {
|
|
36
|
+
control: 'select',
|
|
37
|
+
options: ['sm', 'md', 'lg', 'icon', 'icon-sm'],
|
|
38
|
+
description: 'Height/padding preset. `icon` / `icon-sm` are square for icon-only buttons.',
|
|
39
|
+
table: { defaultValue: { summary: 'md' } },
|
|
40
|
+
},
|
|
41
|
+
disabled: {
|
|
42
|
+
control: 'boolean',
|
|
43
|
+
description: 'Disables interaction and dims the button.',
|
|
44
|
+
},
|
|
45
|
+
children: {
|
|
46
|
+
control: 'text',
|
|
47
|
+
description: 'Button content — text or an icon element.',
|
|
48
|
+
},
|
|
49
|
+
onClick: {
|
|
50
|
+
action: 'click',
|
|
51
|
+
description: 'Fired when the button is clicked.',
|
|
52
|
+
table: { category: 'Events' },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
args: {
|
|
56
|
+
variant: 'default',
|
|
57
|
+
size: 'md',
|
|
58
|
+
disabled: false,
|
|
59
|
+
children: 'Click me',
|
|
60
|
+
onClick: fn(),
|
|
61
|
+
},
|
|
62
|
+
render: (args) => <Button {...args} />,
|
|
63
|
+
} satisfies Meta<typeof Button>;
|
|
64
|
+
|
|
65
|
+
export default meta;
|
|
66
|
+
type Story = StoryObj<typeof meta>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Attach a clean, copy-paste-ready SolidJS snippet to a story. SolidJS stories
|
|
70
|
+
* can't auto-serialize an args-spread render (it shows `{}`), so we provide real
|
|
71
|
+
* usage code (with the import line, so it's truly paste-ready) that the docs
|
|
72
|
+
* "Show code" / "Copy code" buttons surface. `language: 'tsx'` labels it as SolidJS.
|
|
73
|
+
*
|
|
74
|
+
* Note: `Button` is a SolidJS *component* (a scoped import), not a global custom
|
|
75
|
+
* element, so the unprefixed name can't conflict with anything — alias on import
|
|
76
|
+
* if a host already has a `Button`. Only the web components (`<kitn-chat>`, …)
|
|
77
|
+
* are prefixed, because those claim global custom-element tag names.
|
|
78
|
+
*/
|
|
79
|
+
const IMPORT = `import { Button } from '@kitnai/chat';`;
|
|
80
|
+
const src = (code: string) => ({
|
|
81
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/** Interactive playground — tweak the controls to explore every combination. */
|
|
85
|
+
export const Playground: Story = {
|
|
86
|
+
...src(`<Button variant="default" size="md" onClick={() => {}}>Click me</Button>`),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const Ghost: Story = {
|
|
90
|
+
args: { variant: 'ghost', children: 'Ghost' },
|
|
91
|
+
...src(`<Button variant="ghost">Ghost</Button>`),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const Outline: Story = {
|
|
95
|
+
args: { variant: 'outline', children: 'Outline' },
|
|
96
|
+
...src(`<Button variant="outline">Outline</Button>`),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const Small: Story = {
|
|
100
|
+
args: { size: 'sm', children: 'Small' },
|
|
101
|
+
...src(`<Button size="sm">Small</Button>`),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const Large: Story = {
|
|
105
|
+
args: { size: 'lg', children: 'Large' },
|
|
106
|
+
...src(`<Button size="lg">Large</Button>`),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const Disabled: Story = {
|
|
110
|
+
args: { disabled: true, children: 'Disabled' },
|
|
111
|
+
...src(`<Button disabled>Disabled</Button>`),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const PlusIcon = () => (
|
|
115
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
116
|
+
<line x1="12" y1="5" x2="12" y2="19" />
|
|
117
|
+
<line x1="5" y1="12" x2="19" y2="12" />
|
|
118
|
+
</svg>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export const Icon: Story = {
|
|
122
|
+
args: { size: 'icon', children: <PlusIcon />, 'aria-label': 'Add' } as never,
|
|
123
|
+
...src(`<Button size="icon" aria-label="Add">\n <PlusIcon />\n</Button>`),
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** All variants and sizes side by side (showcase — not driven by controls). */
|
|
127
|
+
export const AllVariants: Story = {
|
|
128
|
+
render: () => (
|
|
129
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
130
|
+
<Button variant="default">Default</Button>
|
|
131
|
+
<Button variant="ghost">Ghost</Button>
|
|
132
|
+
<Button variant="outline">Outline</Button>
|
|
133
|
+
<Button variant="default" size="sm">Small</Button>
|
|
134
|
+
<Button variant="default" size="lg">Large</Button>
|
|
135
|
+
<Button variant="default" size="icon" aria-label="Add"><PlusIcon /></Button>
|
|
136
|
+
</div>
|
|
137
|
+
),
|
|
138
|
+
...src(`<div class="flex flex-wrap items-center gap-3">
|
|
139
|
+
<Button variant="default">Default</Button>
|
|
140
|
+
<Button variant="ghost">Ghost</Button>
|
|
141
|
+
<Button variant="outline">Outline</Button>
|
|
142
|
+
<Button size="sm">Small</Button>
|
|
143
|
+
<Button size="lg">Large</Button>
|
|
144
|
+
<Button size="icon" aria-label="Add"><PlusIcon /></Button>
|
|
145
|
+
</div>`),
|
|
146
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
|
|
5
|
+
const buttonVariants = cva(
|
|
6
|
+
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
|
11
|
+
ghost: 'hover:bg-muted text-foreground',
|
|
12
|
+
outline: 'bg-muted/50 text-foreground hover:bg-muted',
|
|
13
|
+
},
|
|
14
|
+
size: {
|
|
15
|
+
sm: 'h-8 px-3 text-xs rounded-md',
|
|
16
|
+
md: 'h-9 px-4 text-sm',
|
|
17
|
+
lg: 'h-10 px-6 text-sm',
|
|
18
|
+
icon: 'h-9 w-9',
|
|
19
|
+
'icon-sm': 'h-7 w-7',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: { variant: 'default', size: 'md' },
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export interface ButtonProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}
|
|
27
|
+
|
|
28
|
+
export function Button(props: ButtonProps) {
|
|
29
|
+
const [local, rest] = splitProps(props, ['variant', 'size', 'class', 'children']);
|
|
30
|
+
return (
|
|
31
|
+
<button class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)} {...rest}>
|
|
32
|
+
{local.children}
|
|
33
|
+
</button>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { buttonVariants };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Collapsible as KCollapsible } from '@kobalte/core/collapsible';
|
|
2
|
+
import { type JSX } from 'solid-js';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
|
|
5
|
+
export const Collapsible = KCollapsible;
|
|
6
|
+
export const CollapsibleTrigger = KCollapsible.Trigger;
|
|
7
|
+
|
|
8
|
+
export function CollapsibleContent(props: { children: JSX.Element; class?: string }) {
|
|
9
|
+
return (
|
|
10
|
+
<KCollapsible.Content class={cn('overflow-hidden', props.class)}>
|
|
11
|
+
{props.children}
|
|
12
|
+
</KCollapsible.Content>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dialog as KDialog } from '@kobalte/core/dialog';
|
|
2
|
+
import { type JSX } from 'solid-js';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
import { useChatConfig } from '../primitives/chat-config';
|
|
5
|
+
|
|
6
|
+
export const Dialog = KDialog;
|
|
7
|
+
export const DialogTrigger = KDialog.Trigger;
|
|
8
|
+
|
|
9
|
+
export function DialogContent(props: { children: JSX.Element; class?: string; title: string }) {
|
|
10
|
+
const config = useChatConfig();
|
|
11
|
+
return (
|
|
12
|
+
<KDialog.Portal mount={config.portalMount()}>
|
|
13
|
+
<KDialog.Overlay class="fixed inset-0 z-50 bg-black/50 animate-in fade-in-0" />
|
|
14
|
+
<KDialog.Content class={cn('fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2 rounded-xl bg-card p-6 shadow-xl animate-in fade-in-0 zoom-in-95 w-full max-w-md', props.class)}>
|
|
15
|
+
<KDialog.Title class="text-lg font-semibold">{props.title}</KDialog.Title>
|
|
16
|
+
{props.children}
|
|
17
|
+
<KDialog.CloseButton class="absolute right-4 top-4 text-muted-foreground hover:text-foreground" />
|
|
18
|
+
</KDialog.Content>
|
|
19
|
+
</KDialog.Portal>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DropdownMenu as KDropdown } from '@kobalte/core/dropdown-menu';
|
|
2
|
+
import { type JSX } from 'solid-js';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
import { useChatConfig } from '../primitives/chat-config';
|
|
5
|
+
|
|
6
|
+
export const Dropdown = KDropdown;
|
|
7
|
+
export const DropdownTrigger = KDropdown.Trigger;
|
|
8
|
+
|
|
9
|
+
export function DropdownContent(props: { children: JSX.Element; class?: string }) {
|
|
10
|
+
const config = useChatConfig();
|
|
11
|
+
return (
|
|
12
|
+
<KDropdown.Portal mount={config.portalMount()}>
|
|
13
|
+
<KDropdown.Content class={cn('z-50 min-w-[8rem] rounded-lg bg-card p-1 shadow-lg animate-in fade-in-0 zoom-in-95', props.class)}>
|
|
14
|
+
{props.children}
|
|
15
|
+
</KDropdown.Content>
|
|
16
|
+
</KDropdown.Portal>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function DropdownItem(props: { children: JSX.Element; class?: string; onSelect?: () => void; }) {
|
|
21
|
+
return (
|
|
22
|
+
<KDropdown.Item class={cn('flex cursor-pointer items-center rounded-md px-2 py-1.5 text-sm outline-none hover:bg-muted transition-colors', props.class)} onSelect={props.onSelect}>
|
|
23
|
+
{props.children}
|
|
24
|
+
</KDropdown.Item>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HoverCard as KHoverCard } from '@kobalte/core/hover-card';
|
|
2
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
3
|
+
import { cn } from '../utils/cn';
|
|
4
|
+
import { useChatConfig } from '../primitives/chat-config';
|
|
5
|
+
|
|
6
|
+
export interface HoverCardProps { trigger: JSX.Element; children: JSX.Element; class?: string; openDelay?: number; closeDelay?: number; }
|
|
7
|
+
|
|
8
|
+
export function HoverCard(props: HoverCardProps) {
|
|
9
|
+
const [local] = splitProps(props, ['trigger', 'children', 'class', 'openDelay', 'closeDelay']);
|
|
10
|
+
const config = useChatConfig();
|
|
11
|
+
return (
|
|
12
|
+
<KHoverCard openDelay={local.openDelay} closeDelay={local.closeDelay}>
|
|
13
|
+
<KHoverCard.Trigger as="span">{local.trigger}</KHoverCard.Trigger>
|
|
14
|
+
<KHoverCard.Portal mount={config.portalMount()}>
|
|
15
|
+
<KHoverCard.Content class={cn('z-50 w-64 rounded-lg bg-card p-4 shadow-lg animate-in fade-in-0 zoom-in-95', local.class)}>
|
|
16
|
+
<KHoverCard.Arrow />
|
|
17
|
+
{local.children}
|
|
18
|
+
</KHoverCard.Content>
|
|
19
|
+
</KHoverCard.Portal>
|
|
20
|
+
</KHoverCard>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Compound primitives for custom layouts (e.g. Source component)
|
|
25
|
+
export interface HoverCardRootProps { children: JSX.Element; openDelay?: number; closeDelay?: number; }
|
|
26
|
+
|
|
27
|
+
export function HoverCardRoot(props: HoverCardRootProps) {
|
|
28
|
+
return <KHoverCard openDelay={props.openDelay} closeDelay={props.closeDelay}>{props.children}</KHoverCard>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface HoverCardTriggerProps { children: JSX.Element; }
|
|
32
|
+
|
|
33
|
+
export function HoverCardTrigger(props: HoverCardTriggerProps) {
|
|
34
|
+
return <KHoverCard.Trigger as="span">{props.children}</KHoverCard.Trigger>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface HoverCardContentProps { children: JSX.Element; class?: string; }
|
|
38
|
+
|
|
39
|
+
export function HoverCardContent(props: HoverCardContentProps) {
|
|
40
|
+
const config = useChatConfig();
|
|
41
|
+
return (
|
|
42
|
+
<KHoverCard.Portal mount={config.portalMount()}>
|
|
43
|
+
<KHoverCard.Content class={cn('z-50 rounded-lg bg-card shadow-lg animate-in fade-in-0 zoom-in-95', props.class)}>
|
|
44
|
+
{props.children}
|
|
45
|
+
</KHoverCard.Content>
|
|
46
|
+
</KHoverCard.Portal>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from './resizable';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'UI/Resizable',
|
|
7
|
+
component: ResizablePanelGroup,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: {
|
|
14
|
+
component: [
|
|
15
|
+
'A **resizable split layout**: `ResizablePanelGroup` lays out `ResizablePanel` children along an axis, divided by a draggable `ResizableHandle`.',
|
|
16
|
+
'**When to use:** to let users adjust the relative size of two or more regions — e.g. a collapsible sidebar next to the main chat, or a chat pane next to an inspector.',
|
|
17
|
+
'**How to use:** wrap panels in `ResizablePanelGroup` and set `orientation` (`horizontal` row / `vertical` column). Give panels a `defaultSize` (percent) and optional `minSize`/`maxSize`; min/max are read from `data-min-size`/`data-max-size` attributes at drag time. Place a `ResizableHandle` (add `withHandle` for a visible grip) between panels. The group needs a sized container (height/width).',
|
|
18
|
+
'**Placement:** app shells — sidebar + conversation, conversation + context/inspector panels, or stacked editor/preview regions.',
|
|
19
|
+
].join('\n\n'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
orientation: {
|
|
25
|
+
control: 'select',
|
|
26
|
+
options: ['horizontal', 'vertical'],
|
|
27
|
+
description: 'Axis the panels are laid out along.',
|
|
28
|
+
table: { defaultValue: { summary: 'horizontal' } },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
args: {
|
|
32
|
+
orientation: 'horizontal',
|
|
33
|
+
},
|
|
34
|
+
render: (args) => (
|
|
35
|
+
<div class="h-48 w-full max-w-2xl rounded-lg border border-border overflow-hidden">
|
|
36
|
+
<ResizablePanelGroup {...args}>
|
|
37
|
+
<ResizablePanel defaultSize={30} data-min-size="100" data-max-size="400">
|
|
38
|
+
<div class="flex h-full items-center justify-center bg-muted/30 p-4">
|
|
39
|
+
<span class="text-sm text-muted-foreground">Sidebar</span>
|
|
40
|
+
</div>
|
|
41
|
+
</ResizablePanel>
|
|
42
|
+
<ResizableHandle withHandle />
|
|
43
|
+
<ResizablePanel>
|
|
44
|
+
<div class="flex h-full items-center justify-center p-4">
|
|
45
|
+
<span class="text-sm text-muted-foreground">Content</span>
|
|
46
|
+
</div>
|
|
47
|
+
</ResizablePanel>
|
|
48
|
+
</ResizablePanelGroup>
|
|
49
|
+
</div>
|
|
50
|
+
),
|
|
51
|
+
} satisfies Meta<typeof ResizablePanelGroup>;
|
|
52
|
+
|
|
53
|
+
export default meta;
|
|
54
|
+
type Story = StoryObj<typeof meta>;
|
|
55
|
+
|
|
56
|
+
const IMPORT = `import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@kitnai/chat';`;
|
|
57
|
+
const src = (code: string) => ({
|
|
58
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** Interactive playground — flip the orientation, then drag the handle. */
|
|
62
|
+
export const Playground: Story = {
|
|
63
|
+
...src(`<ResizablePanelGroup orientation="horizontal">
|
|
64
|
+
<ResizablePanel defaultSize={30} data-min-size="100" data-max-size="400">
|
|
65
|
+
Sidebar
|
|
66
|
+
</ResizablePanel>
|
|
67
|
+
<ResizableHandle withHandle />
|
|
68
|
+
<ResizablePanel>Content</ResizablePanel>
|
|
69
|
+
</ResizablePanelGroup>`),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const Horizontal: Story = {
|
|
73
|
+
args: { orientation: 'horizontal' },
|
|
74
|
+
...src(`<ResizablePanelGroup orientation="horizontal">
|
|
75
|
+
<ResizablePanel defaultSize={30} data-min-size="100" data-max-size="400">
|
|
76
|
+
Sidebar
|
|
77
|
+
</ResizablePanel>
|
|
78
|
+
<ResizableHandle withHandle />
|
|
79
|
+
<ResizablePanel>Content</ResizablePanel>
|
|
80
|
+
</ResizablePanelGroup>`),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Stacked top/bottom split (showcase). */
|
|
84
|
+
export const Vertical: Story = {
|
|
85
|
+
render: () => (
|
|
86
|
+
<div class="h-96 w-full max-w-md rounded-lg border border-border overflow-hidden">
|
|
87
|
+
<ResizablePanelGroup orientation="vertical">
|
|
88
|
+
<ResizablePanel defaultSize={40} data-min-size="60" data-max-size="300">
|
|
89
|
+
<div class="flex h-full items-center justify-center bg-muted/30 p-4">
|
|
90
|
+
<span class="text-sm text-muted-foreground">Top</span>
|
|
91
|
+
</div>
|
|
92
|
+
</ResizablePanel>
|
|
93
|
+
<ResizableHandle withHandle />
|
|
94
|
+
<ResizablePanel>
|
|
95
|
+
<div class="flex h-full items-center justify-center p-4">
|
|
96
|
+
<span class="text-sm text-muted-foreground">Bottom</span>
|
|
97
|
+
</div>
|
|
98
|
+
</ResizablePanel>
|
|
99
|
+
</ResizablePanelGroup>
|
|
100
|
+
</div>
|
|
101
|
+
),
|
|
102
|
+
...src(`<ResizablePanelGroup orientation="vertical">
|
|
103
|
+
<ResizablePanel defaultSize={40} data-min-size="60" data-max-size="300">
|
|
104
|
+
Top
|
|
105
|
+
</ResizablePanel>
|
|
106
|
+
<ResizableHandle withHandle />
|
|
107
|
+
<ResizablePanel>Bottom</ResizablePanel>
|
|
108
|
+
</ResizablePanelGroup>`),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** Three panels with two handles (showcase). */
|
|
112
|
+
export const ThreePanels: Story = {
|
|
113
|
+
name: 'Three Panels',
|
|
114
|
+
render: () => (
|
|
115
|
+
<div class="h-48 w-full max-w-2xl rounded-lg border border-border overflow-hidden">
|
|
116
|
+
<ResizablePanelGroup orientation="horizontal">
|
|
117
|
+
<ResizablePanel defaultSize={25} data-min-size="80" data-max-size="300">
|
|
118
|
+
<div class="flex h-full items-center justify-center bg-muted/30 p-4">
|
|
119
|
+
<span class="text-sm text-muted-foreground">Left</span>
|
|
120
|
+
</div>
|
|
121
|
+
</ResizablePanel>
|
|
122
|
+
<ResizableHandle />
|
|
123
|
+
<ResizablePanel>
|
|
124
|
+
<div class="flex h-full items-center justify-center p-4">
|
|
125
|
+
<span class="text-sm text-muted-foreground">Center</span>
|
|
126
|
+
</div>
|
|
127
|
+
</ResizablePanel>
|
|
128
|
+
<ResizableHandle />
|
|
129
|
+
<ResizablePanel defaultSize={25} data-min-size="80" data-max-size="300">
|
|
130
|
+
<div class="flex h-full items-center justify-center bg-muted/30 p-4">
|
|
131
|
+
<span class="text-sm text-muted-foreground">Right</span>
|
|
132
|
+
</div>
|
|
133
|
+
</ResizablePanel>
|
|
134
|
+
</ResizablePanelGroup>
|
|
135
|
+
</div>
|
|
136
|
+
),
|
|
137
|
+
...src(`<ResizablePanelGroup orientation="horizontal">
|
|
138
|
+
<ResizablePanel defaultSize={25} data-min-size="80" data-max-size="300">Left</ResizablePanel>
|
|
139
|
+
<ResizableHandle />
|
|
140
|
+
<ResizablePanel>Center</ResizablePanel>
|
|
141
|
+
<ResizableHandle />
|
|
142
|
+
<ResizablePanel defaultSize={25} data-min-size="80" data-max-size="300">Right</ResizablePanel>
|
|
143
|
+
</ResizablePanelGroup>`),
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** Handle without a visible grip; reports drag deltas via `onPanelResize` (showcase). */
|
|
147
|
+
export const NoHandle: Story = {
|
|
148
|
+
name: 'Without Handle',
|
|
149
|
+
render: () => (
|
|
150
|
+
<div class="h-48 w-full max-w-2xl rounded-lg border border-border overflow-hidden">
|
|
151
|
+
<ResizablePanelGroup orientation="horizontal">
|
|
152
|
+
<ResizablePanel defaultSize={40}>
|
|
153
|
+
<div class="flex h-full items-center justify-center bg-muted/30 p-4">
|
|
154
|
+
<span class="text-sm text-muted-foreground">Panel A</span>
|
|
155
|
+
</div>
|
|
156
|
+
</ResizablePanel>
|
|
157
|
+
<ResizableHandle onPanelResize={fn()} />
|
|
158
|
+
<ResizablePanel>
|
|
159
|
+
<div class="flex h-full items-center justify-center p-4">
|
|
160
|
+
<span class="text-sm text-muted-foreground">Panel B</span>
|
|
161
|
+
</div>
|
|
162
|
+
</ResizablePanel>
|
|
163
|
+
</ResizablePanelGroup>
|
|
164
|
+
</div>
|
|
165
|
+
),
|
|
166
|
+
...src(`<ResizablePanelGroup orientation="horizontal">
|
|
167
|
+
<ResizablePanel defaultSize={40}>Panel A</ResizablePanel>
|
|
168
|
+
<ResizableHandle onPanelResize={(delta) => console.log(delta)} />
|
|
169
|
+
<ResizablePanel>Panel B</ResizablePanel>
|
|
170
|
+
</ResizablePanelGroup>`),
|
|
171
|
+
};
|