@kitn.ai/ui 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +394 -0
- package/dist/bash-InADTalH.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -0
- package/dist/css-M7EaDHN_.js +1 -0
- package/dist/custom-elements.json +4739 -0
- package/dist/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/github-light-JYsPkUQd.js +1 -0
- package/dist/host-embed.d.ts +33 -0
- package/dist/html-CPZ3oZQ7.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/javascript-C25yR2R2.js +1 -0
- package/dist/json-DxJze_jm.js +1 -0
- package/dist/kitn-chat-provider.d.ts +2 -0
- package/dist/kitn-chat-provider.es.js +240 -0
- package/dist/kitn-chat.es.js +77 -0
- package/dist/llms/llms-full.txt +1018 -0
- package/dist/llms/llms.txt +104 -0
- package/dist/origin.d.ts +5 -0
- package/dist/provider-runtime.d.ts +27 -0
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -0
- package/dist/schemas/choice.schema.json +70 -0
- package/dist/schemas/confirm.schema.json +65 -0
- package/dist/schemas/embed.schema.json +65 -0
- package/dist/schemas/form.result.schema.json +7 -0
- package/dist/schemas/form.schema.json +33 -0
- package/dist/schemas/link.schema.json +56 -0
- package/dist/schemas/tasks.result.schema.json +16 -0
- package/dist/schemas/tasks.schema.json +78 -0
- package/dist/svelte--5p79yCD.js +1 -0
- package/dist/theme.tokens.css +176 -0
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/version.d.ts +4 -0
- package/dist/vue-BmIZj4XD.js +1 -0
- package/dist/wire.d.ts +53 -0
- package/frameworks/react/index.tsx +948 -0
- package/frameworks/react/runtime.tsx +94 -0
- package/llms-full.txt +1018 -0
- package/llms.txt +104 -0
- package/package.json +141 -0
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +743 -0
- package/src/components/attachments.stories.tsx +303 -0
- package/src/components/attachments.test.tsx +64 -0
- package/src/components/attachments.tsx +399 -0
- package/src/components/card-fallback.tsx +28 -0
- package/src/components/card-renderer.tsx +52 -0
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +211 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +187 -0
- package/src/components/chat-container.tsx +82 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/chat-thread.test.tsx +58 -0
- package/src/components/chat-thread.tsx +249 -0
- package/src/components/checkpoint.stories.tsx +102 -0
- package/src/components/checkpoint.tsx +88 -0
- package/src/components/choice-card.tsx +569 -0
- package/src/components/code-block.stories.tsx +150 -0
- package/src/components/code-block.tsx +105 -0
- package/src/components/component-meta.json +3735 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +315 -0
- package/src/components/context.stories.tsx +229 -0
- package/src/components/context.test.tsx +133 -0
- package/src/components/context.tsx +363 -0
- package/src/components/conversation-item.stories.tsx +125 -0
- package/src/components/conversation-item.tsx +16 -0
- package/src/components/conversation-list.stories.tsx +133 -0
- package/src/components/conversation-list.tsx +101 -0
- package/src/components/default-input.test.tsx +111 -0
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +434 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +138 -0
- package/src/components/feedback-bar.test.tsx +103 -0
- package/src/components/feedback-bar.tsx +166 -0
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +156 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +873 -0
- package/src/components/image.stories.tsx +89 -0
- package/src/components/image.tsx +67 -0
- package/src/components/link-preview.tsx +194 -0
- package/src/components/loader.stories.tsx +181 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +180 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-action-bar.test.tsx +128 -0
- package/src/components/message-narrow.stories.tsx +329 -0
- package/src/components/message-skills.stories.tsx +211 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +281 -0
- package/src/components/message.tsx +227 -0
- package/src/components/model-switcher.stories.tsx +123 -0
- package/src/components/model-switcher.test.tsx +65 -0
- package/src/components/model-switcher.tsx +87 -0
- package/src/components/prompt-input.stories.tsx +222 -0
- package/src/components/prompt-input.tsx +211 -0
- package/src/components/prompt-suggestion.stories.tsx +142 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +140 -0
- package/src/components/reasoning.tsx +156 -0
- package/src/components/resizable.test.tsx +226 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +100 -0
- package/src/components/scroll-button.tsx +34 -0
- package/src/components/slash-command.stories.tsx +163 -0
- package/src/components/slash-command.tsx +232 -0
- package/src/components/source-list.test.tsx +152 -0
- package/src/components/source.stories.tsx +124 -0
- package/src/components/source.tsx +129 -0
- package/src/components/tasks-card.stories.tsx +78 -0
- package/src/components/tasks-card.tsx +432 -0
- package/src/components/text-shimmer.stories.tsx +87 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +87 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +153 -0
- package/src/components/tool.tsx +184 -0
- package/src/components/use-card-resolution.ts +28 -0
- package/src/components/voice-input.stories.tsx +83 -0
- package/src/components/voice-input.tsx +107 -0
- package/src/elements/artifact.stories.tsx +506 -0
- package/src/elements/artifact.tsx +137 -0
- package/src/elements/attachments.stories.tsx +190 -0
- package/src/elements/attachments.tsx +136 -0
- package/src/elements/card.stories.tsx +113 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/cards.stories.tsx +59 -0
- package/src/elements/cards.tsx +97 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/chain-of-thought.declarative.test.tsx +153 -0
- package/src/elements/chain-of-thought.stories.tsx +113 -0
- package/src/elements/chain-of-thought.tsx +92 -0
- package/src/elements/chat-scope-picker.stories.tsx +73 -0
- package/src/elements/chat-scope-picker.tsx +36 -0
- package/src/elements/chat-types.ts +42 -0
- package/src/elements/chat-workspace.stories.tsx +288 -0
- package/src/elements/chat-workspace.tsx +161 -0
- package/src/elements/chat.stories.tsx +151 -0
- package/src/elements/chat.tsx +80 -0
- package/src/elements/checkpoint.stories.tsx +72 -0
- package/src/elements/checkpoint.tsx +47 -0
- package/src/elements/choice.stories.tsx +240 -0
- package/src/elements/choice.tsx +48 -0
- package/src/elements/code-block.stories.tsx +83 -0
- package/src/elements/code-block.tsx +42 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +227 -0
- package/src/elements/confirm-card.tsx +51 -0
- package/src/elements/context-meter.stories.tsx +151 -0
- package/src/elements/context-meter.tsx +121 -0
- package/src/elements/conversation-list.declarative.test.tsx +137 -0
- package/src/elements/conversation-list.stories.tsx +243 -0
- package/src/elements/conversation-list.tsx +80 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +247 -0
- package/src/elements/define.tsx +171 -0
- package/src/elements/element-meta.json +3314 -0
- package/src/elements/element-types.d.ts +710 -0
- package/src/elements/embed.stories.tsx +213 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/empty.stories.tsx +111 -0
- package/src/elements/empty.tsx +29 -0
- package/src/elements/feedback-bar.stories.tsx +114 -0
- package/src/elements/feedback-bar.tsx +61 -0
- package/src/elements/file-tree.stories.tsx +134 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/file-upload.stories.tsx +82 -0
- package/src/elements/file-upload.tsx +44 -0
- package/src/elements/form.stories.tsx +248 -0
- package/src/elements/form.tsx +43 -0
- package/src/elements/framework-usage.json +563 -0
- package/src/elements/image.stories.tsx +71 -0
- package/src/elements/image.tsx +32 -0
- package/src/elements/link-preview.stories.tsx +209 -0
- package/src/elements/link-preview.tsx +34 -0
- package/src/elements/loader.stories.tsx +88 -0
- package/src/elements/loader.tsx +25 -0
- package/src/elements/markdown.stories.tsx +76 -0
- package/src/elements/markdown.tsx +38 -0
- package/src/elements/message-skills.declarative.test.tsx +104 -0
- package/src/elements/message-skills.stories.tsx +114 -0
- package/src/elements/message-skills.tsx +85 -0
- package/src/elements/message.stories.tsx +218 -0
- package/src/elements/message.tsx +162 -0
- package/src/elements/model-switcher.declarative.test.tsx +130 -0
- package/src/elements/model-switcher.stories.tsx +198 -0
- package/src/elements/model-switcher.tsx +93 -0
- package/src/elements/popover.stories.tsx +80 -0
- package/src/elements/popover.tsx +59 -0
- package/src/elements/prompt-input-slash-command.test.tsx +128 -0
- package/src/elements/prompt-input-stoppable.test.tsx +88 -0
- package/src/elements/prompt-input-toolbar-actions.test.tsx +120 -0
- package/src/elements/prompt-input.stories.tsx +331 -0
- package/src/elements/prompt-input.tsx +185 -0
- package/src/elements/prompt-suggestions.declarative.test.tsx +164 -0
- package/src/elements/prompt-suggestions.stories.tsx +213 -0
- package/src/elements/prompt-suggestions.tsx +94 -0
- package/src/elements/reasoning.stories.tsx +77 -0
- package/src/elements/reasoning.tsx +50 -0
- package/src/elements/register.ts +56 -0
- package/src/elements/remote.stories.tsx +314 -0
- package/src/elements/remote.tsx +221 -0
- package/src/elements/resizable.d.ts +27 -0
- package/src/elements/resizable.stories.tsx +426 -0
- package/src/elements/resizable.tsx +553 -0
- package/src/elements/response-stream.stories.tsx +79 -0
- package/src/elements/response-stream.tsx +40 -0
- package/src/elements/scroll-button.stories.tsx +202 -0
- package/src/elements/scroll-button.test.tsx +148 -0
- package/src/elements/scroll-button.tsx +126 -0
- package/src/elements/source-list.stories.tsx +143 -0
- package/src/elements/source.stories.tsx +88 -0
- package/src/elements/source.tsx +120 -0
- package/src/elements/styles.css +199 -0
- package/src/elements/switch.stories.tsx +56 -0
- package/src/elements/switch.tsx +43 -0
- package/src/elements/tasks.stories.tsx +237 -0
- package/src/elements/tasks.tsx +46 -0
- package/src/elements/text-shimmer.stories.tsx +64 -0
- package/src/elements/text-shimmer.tsx +28 -0
- package/src/elements/thinking-bar.stories.tsx +72 -0
- package/src/elements/thinking-bar.tsx +34 -0
- package/src/elements/tool.stories.tsx +89 -0
- package/src/elements/tool.tsx +23 -0
- package/src/elements/voice-input.stories.tsx +88 -0
- package/src/elements/voice-input.tsx +41 -0
- package/src/index.ts +253 -0
- package/src/primitives/card-contract.ts +71 -0
- package/src/primitives/card-host.tsx +35 -0
- package/src/primitives/card-registry.tsx +67 -0
- package/src/primitives/card-resolution.ts +36 -0
- package/src/primitives/card-routing.ts +79 -0
- package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
- package/src/primitives/card-schemas/card-event.schema.json +12 -0
- package/src/primitives/card-schemas/choice.schema.json +70 -0
- package/src/primitives/card-schemas/confirm.schema.json +65 -0
- package/src/primitives/card-schemas/embed.schema.json +65 -0
- package/src/primitives/card-schemas/form.result.schema.json +7 -0
- package/src/primitives/card-schemas/form.schema.json +33 -0
- package/src/primitives/card-schemas/link.schema.json +56 -0
- package/src/primitives/card-schemas/tasks.result.schema.json +16 -0
- package/src/primitives/card-schemas/tasks.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/controllable.test.ts +47 -0
- package/src/primitives/controllable.ts +21 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +157 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-resize-observer.ts +12 -0
- package/src/primitives/use-stick-to-bottom.ts +43 -0
- package/src/primitives/use-text-stream.ts +112 -0
- package/src/primitives/use-voice-recorder.ts +50 -0
- package/src/remote/host-embed.ts +345 -0
- package/src/remote/index.ts +2 -0
- package/src/remote/origin.ts +30 -0
- package/src/remote/provider-runtime.ts +259 -0
- package/src/remote/provider.ts +2 -0
- package/src/remote/validate.ts +22 -0
- package/src/remote/version.ts +12 -0
- package/src/remote/wire.ts +48 -0
- package/src/stories/chat-panel-layout.stories.tsx +145 -0
- package/src/stories/chat-scene.tsx +571 -0
- package/src/stories/checkpoint-restore.stories.tsx +256 -0
- package/src/stories/context-usage.stories.tsx +212 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +182 -0
- package/src/stories/conversation-with-sources.stories.tsx +471 -0
- package/src/stories/docs/Accessibility.mdx +119 -0
- package/src/stories/docs/ChildElements.mdx +269 -0
- package/src/stories/docs/ForAIAgents.mdx +162 -0
- package/src/stories/docs/GettingStarted.mdx +65 -0
- package/src/stories/docs/Installation.mdx +83 -0
- package/src/stories/docs/Introduction.mdx +50 -0
- package/src/stories/docs/SolidJsAdvanced.mdx +17 -0
- package/src/stories/docs/Theming.mdx +85 -0
- package/src/stories/docs/element-controls.ts +121 -0
- package/src/stories/docs/frameworks/Angular.mdx +245 -0
- package/src/stories/docs/frameworks/Html.mdx +227 -0
- package/src/stories/docs/frameworks/Overview.mdx +47 -0
- package/src/stories/docs/frameworks/React.mdx +227 -0
- package/src/stories/docs/frameworks/Solid.mdx +173 -0
- package/src/stories/docs/frameworks/Svelte.mdx +194 -0
- package/src/stories/docs/frameworks/Vue.mdx +238 -0
- package/src/stories/docs/generative-ui-overview.mdx +186 -0
- package/src/stories/docs/recipes/SpeechToText.mdx +7 -0
- package/src/stories/docs/recipes/Streaming.mdx +68 -0
- package/src/stories/docs/recipes/TextToSpeech.mdx +35 -0
- package/src/stories/docs/theme-editor/canvas.tsx +32 -0
- package/src/stories/docs/theme-editor/inspector.tsx +66 -0
- package/src/stories/docs/theme-editor/presets.test.ts +32 -0
- package/src/stories/docs/theme-editor/presets.ts +64 -0
- package/src/stories/docs/theme-editor/theme-css.test.ts +19 -0
- package/src/stories/docs/theme-editor/theme-css.ts +15 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +146 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/examples/ChoosingComponents.mdx +106 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/examples/usage/checkpoint-restore.ts +156 -0
- package/src/stories/examples/usage/context-usage.ts +591 -0
- package/src/stories/examples/usage/conversation-with-reasoning.ts +224 -0
- package/src/stories/examples/usage/conversation-with-sources.ts +589 -0
- package/src/stories/examples/usage/empty-state.ts +144 -0
- package/src/stories/examples/usage/full-chat-app.ts +277 -0
- package/src/stories/examples/usage/index.ts +63 -0
- package/src/stories/examples/usage/message-actions.ts +704 -0
- package/src/stories/examples/usage/pattern-centered-conversation.ts +446 -0
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +442 -0
- package/src/stories/examples/usage/pattern-docked-widget.ts +479 -0
- package/src/stories/examples/usage/prompt-input-variants.ts +1356 -0
- package/src/stories/examples/usage/streaming-response.ts +687 -0
- package/src/stories/examples/usage/types.ts +33 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +230 -0
- package/src/stories/pattern-centered-conversation.stories.tsx +93 -0
- package/src/stories/pattern-docked-widget.stories.tsx +93 -0
- package/src/stories/pattern-empty-state.stories.tsx +76 -0
- package/src/stories/prompt-input-variants.stories.tsx +456 -0
- package/src/stories/streaming-response.stories.tsx +438 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/stories/typography.stories.tsx +78 -0
- package/src/types.ts +47 -0
- package/src/ui/action-icons.ts +52 -0
- package/src/ui/avatar.stories.tsx +103 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +86 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +145 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.stories.tsx +69 -0
- package/src/ui/collapsible.tsx +125 -0
- package/src/ui/dropdown.stories.tsx +59 -0
- package/src/ui/dropdown.tsx +196 -0
- package/src/ui/hover-card.stories.tsx +77 -0
- package/src/ui/hover-card.test.tsx +30 -0
- package/src/ui/hover-card.tsx +172 -0
- package/src/ui/overlay.stories.tsx +115 -0
- package/src/ui/overlay.tsx +158 -0
- package/src/ui/popover.stories.tsx +81 -0
- package/src/ui/popover.test.tsx +99 -0
- package/src/ui/popover.tsx +92 -0
- package/src/ui/resizable.stories.tsx +236 -0
- package/src/ui/resizable.tsx +576 -0
- package/src/ui/scroll-area.stories.tsx +50 -0
- package/src/ui/scroll-area.tsx +15 -0
- package/src/ui/separator.stories.tsx +81 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +337 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/switch.stories.tsx +51 -0
- package/src/ui/switch.test.tsx +59 -0
- package/src/ui/switch.tsx +62 -0
- package/src/ui/textarea.stories.tsx +76 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +74 -0
- package/src/ui/tooltip.tsx +68 -0
- package/src/utils/cn.ts +24 -0
- package/theme.css +187 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { type JSX, splitProps, createSignal, createEffect, createContext, useContext, For, Show, children as resolveChildren } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
// --- Types ---
|
|
5
|
+
|
|
6
|
+
type Orientation = 'horizontal' | 'vertical';
|
|
7
|
+
|
|
8
|
+
/** A size value: a number (percent), `"25%"` (percent), or `"280px"` (pixels). */
|
|
9
|
+
export type SizeValue = number | string;
|
|
10
|
+
|
|
11
|
+
interface ResizableContextValue {
|
|
12
|
+
orientation: Orientation;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ResizableContext = createContext<ResizableContextValue>();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Normalize a px-or-% size into a CSS length string usable as `flex-basis`.
|
|
19
|
+
* - number → percent (`30` → `"30%"`)
|
|
20
|
+
* - `"25%"` → percent passthrough
|
|
21
|
+
* - `"280px"` → pixel passthrough
|
|
22
|
+
* Returns `undefined` for unset values (caller falls back to flexible `flex: 1`).
|
|
23
|
+
*/
|
|
24
|
+
export function normalizeSize(value: SizeValue | undefined): string | undefined {
|
|
25
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
26
|
+
if (typeof value === 'number') return Number.isFinite(value) ? `${value}%` : undefined;
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
if (trimmed === '') return undefined;
|
|
29
|
+
if (trimmed.endsWith('%') || trimmed.endsWith('px')) return trimmed;
|
|
30
|
+
// bare numeric string → percent
|
|
31
|
+
const n = Number(trimmed);
|
|
32
|
+
return Number.isFinite(n) ? `${n}%` : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Resolve a px-or-% size to pixels, given the container's main-axis size.
|
|
37
|
+
* Used to seed `data-min-size` / `data-max-size` (which the handle reads as px).
|
|
38
|
+
* Returns `undefined` when the value is unset.
|
|
39
|
+
*/
|
|
40
|
+
export function resolveToPx(value: SizeValue | undefined, containerPx: number): number | undefined {
|
|
41
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
42
|
+
if (typeof value === 'number') return Number.isFinite(value) ? (value / 100) * containerPx : undefined;
|
|
43
|
+
const trimmed = value.trim();
|
|
44
|
+
if (trimmed.endsWith('px')) {
|
|
45
|
+
const n = parseFloat(trimmed);
|
|
46
|
+
return Number.isFinite(n) ? n : undefined;
|
|
47
|
+
}
|
|
48
|
+
if (trimmed.endsWith('%')) {
|
|
49
|
+
const n = parseFloat(trimmed);
|
|
50
|
+
return Number.isFinite(n) ? (n / 100) * containerPx : undefined;
|
|
51
|
+
}
|
|
52
|
+
const n = Number(trimmed);
|
|
53
|
+
return Number.isFinite(n) ? (n / 100) * containerPx : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- ResizablePanelGroup ---
|
|
57
|
+
|
|
58
|
+
export interface ResizablePanelGroupProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
59
|
+
orientation?: Orientation;
|
|
60
|
+
children: JSX.Element;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ResizablePanelGroup(props: ResizablePanelGroupProps) {
|
|
64
|
+
const [local, rest] = splitProps(props, ['orientation', 'children', 'class']);
|
|
65
|
+
const orientation = () => local.orientation ?? 'horizontal';
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ResizableContext.Provider value={{ orientation: orientation() }}>
|
|
69
|
+
<div
|
|
70
|
+
class={cn(
|
|
71
|
+
'flex h-full w-full',
|
|
72
|
+
orientation() === 'vertical' ? 'flex-col' : 'flex-row',
|
|
73
|
+
local.class
|
|
74
|
+
)}
|
|
75
|
+
data-orientation={orientation()}
|
|
76
|
+
{...rest}
|
|
77
|
+
>
|
|
78
|
+
{local.children}
|
|
79
|
+
</div>
|
|
80
|
+
</ResizableContext.Provider>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --- ResizablePanel ---
|
|
85
|
+
|
|
86
|
+
export interface ResizablePanelProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
87
|
+
/** Initial main-axis size: number/`"25%"` (percent) or `"280px"` (pixels). Omitted → flexible. */
|
|
88
|
+
defaultSize?: SizeValue;
|
|
89
|
+
/** Minimum size during resize (px or %). */
|
|
90
|
+
minSize?: SizeValue;
|
|
91
|
+
/** Maximum size during resize (px or %). */
|
|
92
|
+
maxSize?: SizeValue;
|
|
93
|
+
/** When true, the panel's size is fixed and adjacent handles are non-draggable. */
|
|
94
|
+
locked?: boolean;
|
|
95
|
+
/** When true, the panel is not visible (used by the `Resizable` convenience to drop dividers). */
|
|
96
|
+
hidden?: boolean;
|
|
97
|
+
children: JSX.Element;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function ResizablePanel(props: ResizablePanelProps) {
|
|
101
|
+
const [local, rest] = splitProps(props, [
|
|
102
|
+
'defaultSize', 'minSize', 'maxSize', 'locked', 'hidden', 'children', 'class', 'style',
|
|
103
|
+
]);
|
|
104
|
+
// GRID-FILL model: the panel sizes itself on the MAIN axis via flex-basis (or
|
|
105
|
+
// flex:1 when flexible) as a flex item of the group — the handle rewrites that
|
|
106
|
+
// basis, so the drag math is plain flex. For the FILL it is itself a
|
|
107
|
+
// `display:grid` with a single `minmax(0,1fr)` cell on BOTH axes: a grid item
|
|
108
|
+
// (the child) stretches to fill its cell on both axes by default, and `1fr` of
|
|
109
|
+
// a definite-sized grid is a *definite* length — so arbitrary child content
|
|
110
|
+
// fills the panel on width AND height without needing `height:100%`, in both
|
|
111
|
+
// orientations. (A flex panel only stretches the CROSS axis, collapsing the
|
|
112
|
+
// main axis to content size — the bug this replaces.) Mirrors the
|
|
113
|
+
// `<kai-resizable>` web-component panel and the Shoelace/Web Awesome grid layout.
|
|
114
|
+
// min:0 on BOTH axes enables shrink-to-scroll; overflow hidden.
|
|
115
|
+
const sizeStyle = (): Record<string, string> => {
|
|
116
|
+
const basis = normalizeSize(local.defaultSize);
|
|
117
|
+
const base: Record<string, string> = basis !== undefined
|
|
118
|
+
? { 'flex-basis': basis, 'flex-grow': '0', 'flex-shrink': '0' }
|
|
119
|
+
: { flex: '1 1 0%' };
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
display: 'grid',
|
|
123
|
+
'grid-template-rows': 'minmax(0, 1fr)',
|
|
124
|
+
'grid-template-columns': 'minmax(0, 1fr)',
|
|
125
|
+
'min-width': '0',
|
|
126
|
+
'min-height': '0',
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Reflect min/max to data-* in pixels where statically resolvable. The handle
|
|
131
|
+
// reads `data-min-size`/`data-max-size` (as px) at drag time. Percent values
|
|
132
|
+
// are resolved against the container by the handle at drag time when expressed
|
|
133
|
+
// as `data-min-size-pct` / `data-max-size-pct`; pixel values go straight to
|
|
134
|
+
// `data-min-size` / `data-max-size`.
|
|
135
|
+
const dataAttrs = () => {
|
|
136
|
+
const out: Record<string, string | undefined> = {};
|
|
137
|
+
const setBound = (val: SizeValue | undefined, pxKey: string, pctKey: string) => {
|
|
138
|
+
if (val === undefined || val === null || val === '') return;
|
|
139
|
+
if (typeof val === 'number') { out[pctKey] = String(val); return; }
|
|
140
|
+
const t = val.trim();
|
|
141
|
+
if (t.endsWith('px')) out[pxKey] = String(parseFloat(t));
|
|
142
|
+
else if (t.endsWith('%')) out[pctKey] = String(parseFloat(t));
|
|
143
|
+
else if (Number.isFinite(Number(t))) out[pctKey] = t;
|
|
144
|
+
};
|
|
145
|
+
setBound(local.minSize, 'data-min-size', 'data-min-size-pct');
|
|
146
|
+
setBound(local.maxSize, 'data-max-size', 'data-max-size-pct');
|
|
147
|
+
// Reflect the DEFAULT size too, so a double-click on an adjacent handle can
|
|
148
|
+
// restore this panel to it after a drag has rewritten its inline flex-basis.
|
|
149
|
+
// A panel with no defaultSize records nothing → the handle resets it to the
|
|
150
|
+
// flexible `flex:1` state instead.
|
|
151
|
+
setBound(local.defaultSize, 'data-default-size', 'data-default-size-pct');
|
|
152
|
+
return out;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div
|
|
157
|
+
class={cn('overflow-hidden', local.class)}
|
|
158
|
+
style={{ ...sizeStyle(), ...(typeof local.style === 'object' ? local.style : {}) }}
|
|
159
|
+
data-locked={local.locked ? '' : undefined}
|
|
160
|
+
hidden={local.hidden || undefined}
|
|
161
|
+
{...dataAttrs()}
|
|
162
|
+
{...rest}
|
|
163
|
+
>
|
|
164
|
+
{local.children}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// --- ResizableHandle ---
|
|
170
|
+
|
|
171
|
+
export interface ResizableHandleProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
172
|
+
withHandle?: boolean;
|
|
173
|
+
onPanelResize?: (delta: number) => void;
|
|
174
|
+
/** Keyboard nudge step in pixels (default 16). Home/End jump to min/max. */
|
|
175
|
+
keyboardStep?: number;
|
|
176
|
+
/** Render as a static, non-interactive divider (e.g. between locked panels). */
|
|
177
|
+
static?: boolean;
|
|
178
|
+
/** Explicit axis; overrides `ResizableContext`. Needed by facades that render
|
|
179
|
+
* handles outside a context provider (e.g. `<kai-resizable>`). */
|
|
180
|
+
orientation?: Orientation;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Read a panel's min/max bound (px), resolving percent against the container. */
|
|
184
|
+
function readBound(el: HTMLElement, kind: 'min' | 'max', containerPx: number, fallback: number): number {
|
|
185
|
+
const px = el.dataset[kind === 'min' ? 'minSize' : 'maxSize'];
|
|
186
|
+
if (px !== undefined && px !== '') {
|
|
187
|
+
const n = parseFloat(px);
|
|
188
|
+
if (Number.isFinite(n)) return n;
|
|
189
|
+
}
|
|
190
|
+
const pct = el.dataset[kind === 'min' ? 'minSizePct' : 'maxSizePct'];
|
|
191
|
+
if (pct !== undefined && pct !== '') {
|
|
192
|
+
const n = parseFloat(pct);
|
|
193
|
+
if (Number.isFinite(n)) return (n / 100) * containerPx;
|
|
194
|
+
}
|
|
195
|
+
return fallback;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function ResizableHandle(props: ResizableHandleProps) {
|
|
199
|
+
const [local, rest] = splitProps(props, [
|
|
200
|
+
'withHandle', 'onPanelResize', 'class', 'keyboardStep', 'static', 'orientation',
|
|
201
|
+
]);
|
|
202
|
+
const ctx = useContext(ResizableContext);
|
|
203
|
+
const orientation = () => local.orientation ?? ctx?.orientation ?? 'horizontal';
|
|
204
|
+
const [isDragging, setIsDragging] = createSignal(false);
|
|
205
|
+
const isStatic = () => !!local.static;
|
|
206
|
+
|
|
207
|
+
let startPos = 0;
|
|
208
|
+
let prevEl: HTMLElement | null = null;
|
|
209
|
+
let nextEl: HTMLElement | null = null;
|
|
210
|
+
let prevSize = 0;
|
|
211
|
+
let nextSize = 0;
|
|
212
|
+
|
|
213
|
+
const isHoriz = () => orientation() === 'horizontal';
|
|
214
|
+
const dim = (): 'width' | 'height' => (isHoriz() ? 'width' : 'height');
|
|
215
|
+
|
|
216
|
+
const handlePointerDown = (e: PointerEvent) => {
|
|
217
|
+
if (isStatic()) return;
|
|
218
|
+
const handle = e.currentTarget as HTMLElement;
|
|
219
|
+
prevEl = handle.previousElementSibling as HTMLElement;
|
|
220
|
+
nextEl = handle.nextElementSibling as HTMLElement;
|
|
221
|
+
|
|
222
|
+
if (!prevEl || !nextEl) return;
|
|
223
|
+
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
setIsDragging(true);
|
|
226
|
+
handle.setPointerCapture(e.pointerId);
|
|
227
|
+
|
|
228
|
+
startPos = isHoriz() ? e.clientX : e.clientY;
|
|
229
|
+
prevSize = prevEl.getBoundingClientRect()[dim()];
|
|
230
|
+
nextSize = nextEl.getBoundingClientRect()[dim()];
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const handlePointerMove = (e: PointerEvent) => {
|
|
234
|
+
if (!isDragging() || !prevEl || !nextEl) return;
|
|
235
|
+
|
|
236
|
+
const currentPos = isHoriz() ? e.clientX : e.clientY;
|
|
237
|
+
const delta = currentPos - startPos;
|
|
238
|
+
applyDelta(delta);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Apply a pixel delta to the adjacent panels. The delta is CLAMPED (not
|
|
243
|
+
* rejected) so the dragged panel lands exactly on the nearest min/max bound
|
|
244
|
+
* — this avoids the stair-step where a step that would cross a bound was
|
|
245
|
+
* dropped wholesale, leaving the panel short of its limit.
|
|
246
|
+
*/
|
|
247
|
+
function applyDelta(delta: number): boolean {
|
|
248
|
+
if (!prevEl || !nextEl) return false;
|
|
249
|
+
const container = prevEl.parentElement;
|
|
250
|
+
const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
|
|
251
|
+
|
|
252
|
+
const prevMin = readBound(prevEl, 'min', containerPx, 0);
|
|
253
|
+
const prevMax = readBound(prevEl, 'max', containerPx, 999999);
|
|
254
|
+
const nextMin = readBound(nextEl, 'min', containerPx, 0);
|
|
255
|
+
const nextMax = readBound(nextEl, 'max', containerPx, 999999);
|
|
256
|
+
|
|
257
|
+
// Clamp the delta to the tightest bound across both panels. prev grows by
|
|
258
|
+
// +delta, next shrinks by -delta (and vice versa), so each bound maps to a
|
|
259
|
+
// limit on delta. Intersect them all, then clamp the requested delta.
|
|
260
|
+
let lo = -Infinity; // most-negative allowed delta
|
|
261
|
+
let hi = Infinity; // most-positive allowed delta
|
|
262
|
+
// prev: prevSize + delta in [prevMin, prevMax]
|
|
263
|
+
lo = Math.max(lo, prevMin - prevSize);
|
|
264
|
+
hi = Math.min(hi, prevMax - prevSize);
|
|
265
|
+
// next: nextSize - delta in [nextMin, nextMax] → delta in [nextSize-nextMax, nextSize-nextMin]
|
|
266
|
+
lo = Math.max(lo, nextSize - nextMax);
|
|
267
|
+
hi = Math.min(hi, nextSize - nextMin);
|
|
268
|
+
|
|
269
|
+
if (lo > hi) return false; // no feasible delta (contradictory bounds)
|
|
270
|
+
const clamped = Math.max(lo, Math.min(hi, delta));
|
|
271
|
+
|
|
272
|
+
const newPrevSize = prevSize + clamped;
|
|
273
|
+
const newNextSize = nextSize - clamped;
|
|
274
|
+
|
|
275
|
+
prevEl.style.flexBasis = `${newPrevSize}px`;
|
|
276
|
+
prevEl.style.flexGrow = '0';
|
|
277
|
+
prevEl.style.flexShrink = '0';
|
|
278
|
+
nextEl.style.flexBasis = `${newNextSize}px`;
|
|
279
|
+
nextEl.style.flexGrow = '0';
|
|
280
|
+
nextEl.style.flexShrink = '0';
|
|
281
|
+
|
|
282
|
+
local.onPanelResize?.(clamped);
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Convert the pixel flex-basis on the TWO adjacent panels to percentages of
|
|
288
|
+
* the container, INDEPENDENTLY of one another. With >2 panels, `nextPct` is
|
|
289
|
+
* NOT `100 - prevPct` (that would steal the other panels' space and overflow
|
|
290
|
+
* the container) — each panel's percent is its own pixel size over the total.
|
|
291
|
+
* All other panels are left untouched.
|
|
292
|
+
*/
|
|
293
|
+
function settleToPercent() {
|
|
294
|
+
if (!prevEl || !nextEl) return;
|
|
295
|
+
const container = prevEl.parentElement;
|
|
296
|
+
if (!container) return;
|
|
297
|
+
const total = container.getBoundingClientRect()[dim()];
|
|
298
|
+
if (total <= 0) return;
|
|
299
|
+
const prevPct = (prevEl.getBoundingClientRect()[dim()] / total) * 100;
|
|
300
|
+
const nextPct = (nextEl.getBoundingClientRect()[dim()] / total) * 100;
|
|
301
|
+
prevEl.style.flexBasis = `${prevPct}%`;
|
|
302
|
+
nextEl.style.flexBasis = `${nextPct}%`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const handlePointerUp = () => {
|
|
306
|
+
settleToPercent();
|
|
307
|
+
setIsDragging(false);
|
|
308
|
+
prevEl = null;
|
|
309
|
+
nextEl = null;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Restore one adjacent panel to its DEFAULT size. Reads the panel's reflected
|
|
314
|
+
* `data-default-size` (px) / `data-default-size-pct` (percent); if neither is
|
|
315
|
+
* present the panel had no explicit default → return it to the flexible
|
|
316
|
+
* `flex: 1 1 0%` state (clear inline basis, grow:1) so it reclaims free space.
|
|
317
|
+
*/
|
|
318
|
+
function resetPanelToDefault(el: HTMLElement) {
|
|
319
|
+
const px = el.dataset.defaultSize;
|
|
320
|
+
const pct = el.dataset.defaultSizePct;
|
|
321
|
+
if (px !== undefined && px !== '') {
|
|
322
|
+
el.style.flexBasis = `${px}px`;
|
|
323
|
+
el.style.flexGrow = '0';
|
|
324
|
+
el.style.flexShrink = '0';
|
|
325
|
+
} else if (pct !== undefined && pct !== '') {
|
|
326
|
+
el.style.flexBasis = `${pct}%`;
|
|
327
|
+
el.style.flexGrow = '0';
|
|
328
|
+
el.style.flexShrink = '0';
|
|
329
|
+
} else {
|
|
330
|
+
// No declared default → flexible panel: clear the dragged basis and grow.
|
|
331
|
+
el.style.flexBasis = '';
|
|
332
|
+
el.style.flexGrow = '1';
|
|
333
|
+
el.style.flexShrink = '1';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Double-clicking the divider restores BOTH adjacent panels to their default
|
|
339
|
+
* sizes — a fast "snap back" after a drag. No-op on a static (locked) handle.
|
|
340
|
+
*/
|
|
341
|
+
const handleDblClick = (e: MouseEvent) => {
|
|
342
|
+
if (isStatic()) return;
|
|
343
|
+
const handle = e.currentTarget as HTMLElement;
|
|
344
|
+
const prev = handle.previousElementSibling as HTMLElement | null;
|
|
345
|
+
const next = handle.nextElementSibling as HTMLElement | null;
|
|
346
|
+
if (!prev || !next) return;
|
|
347
|
+
e.preventDefault();
|
|
348
|
+
resetPanelToDefault(prev);
|
|
349
|
+
resetPanelToDefault(next);
|
|
350
|
+
// Re-emit so consumers (and the element facade) observe the new sizes.
|
|
351
|
+
local.onPanelResize?.(0);
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// --- Keyboard resize ---
|
|
355
|
+
const aria = createSignal(50);
|
|
356
|
+
const [valueNow, setValueNow] = aria;
|
|
357
|
+
|
|
358
|
+
/** Seed prev/next refs + sizes for a keyboard nudge starting from a key event. */
|
|
359
|
+
function beginKeyboard(handle: HTMLElement) {
|
|
360
|
+
prevEl = handle.previousElementSibling as HTMLElement;
|
|
361
|
+
nextEl = handle.nextElementSibling as HTMLElement;
|
|
362
|
+
if (!prevEl || !nextEl) return false;
|
|
363
|
+
prevSize = prevEl.getBoundingClientRect()[dim()];
|
|
364
|
+
nextSize = nextEl.getBoundingClientRect()[dim()];
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function updateAria() {
|
|
369
|
+
if (!prevEl) return;
|
|
370
|
+
const container = prevEl.parentElement;
|
|
371
|
+
if (!container) return;
|
|
372
|
+
const total = container.getBoundingClientRect()[dim()];
|
|
373
|
+
if (total <= 0) return;
|
|
374
|
+
const pct = (prevEl.getBoundingClientRect()[dim()] / total) * 100;
|
|
375
|
+
setValueNow(Math.round(pct));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
379
|
+
if (isStatic()) return;
|
|
380
|
+
const handle = e.currentTarget as HTMLElement;
|
|
381
|
+
const step = local.keyboardStep ?? 16;
|
|
382
|
+
const horiz = isHoriz();
|
|
383
|
+
const decKey = horiz ? 'ArrowLeft' : 'ArrowUp';
|
|
384
|
+
const incKey = horiz ? 'ArrowRight' : 'ArrowDown';
|
|
385
|
+
|
|
386
|
+
let delta: number | 'min' | 'max' | null = null;
|
|
387
|
+
if (e.key === decKey) delta = -step;
|
|
388
|
+
else if (e.key === incKey) delta = step;
|
|
389
|
+
else if (e.key === 'Home') delta = 'min';
|
|
390
|
+
else if (e.key === 'End') delta = 'max';
|
|
391
|
+
else return;
|
|
392
|
+
|
|
393
|
+
e.preventDefault();
|
|
394
|
+
if (!beginKeyboard(handle)) return;
|
|
395
|
+
|
|
396
|
+
if (delta === 'min') {
|
|
397
|
+
// Shrink prev to its minimum.
|
|
398
|
+
const container = prevEl!.parentElement;
|
|
399
|
+
const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
|
|
400
|
+
const prevMin = readBound(prevEl!, 'min', containerPx, 0);
|
|
401
|
+
applyDelta(prevMin - prevSize);
|
|
402
|
+
} else if (delta === 'max') {
|
|
403
|
+
const container = prevEl!.parentElement;
|
|
404
|
+
const containerPx = container ? container.getBoundingClientRect()[dim()] : 0;
|
|
405
|
+
const prevMax = readBound(prevEl!, 'max', containerPx, 999999);
|
|
406
|
+
applyDelta(prevMax - prevSize);
|
|
407
|
+
} else {
|
|
408
|
+
applyDelta(delta);
|
|
409
|
+
}
|
|
410
|
+
updateAria();
|
|
411
|
+
settleToPercent();
|
|
412
|
+
prevEl = null;
|
|
413
|
+
nextEl = null;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return (
|
|
417
|
+
<div
|
|
418
|
+
class={cn('relative flex items-center justify-center', local.class)}
|
|
419
|
+
style={{
|
|
420
|
+
cursor: isStatic() ? 'default' : isHoriz() ? 'col-resize' : 'row-resize',
|
|
421
|
+
[isHoriz() ? 'width' : 'height']: '8px',
|
|
422
|
+
'background': isDragging() ? 'var(--color-muted-foreground, #98989f)' : 'transparent',
|
|
423
|
+
'opacity': isDragging() ? '0.3' : '1',
|
|
424
|
+
}}
|
|
425
|
+
onPointerDown={handlePointerDown}
|
|
426
|
+
onPointerMove={handlePointerMove}
|
|
427
|
+
onPointerUp={handlePointerUp}
|
|
428
|
+
onDblClick={handleDblClick}
|
|
429
|
+
onKeyDown={handleKeyDown}
|
|
430
|
+
role="separator"
|
|
431
|
+
tabIndex={isStatic() ? undefined : 0}
|
|
432
|
+
data-orientation={orientation()}
|
|
433
|
+
data-static={isStatic() ? '' : undefined}
|
|
434
|
+
aria-orientation={isHoriz() ? 'vertical' : 'horizontal'}
|
|
435
|
+
aria-valuemin={0}
|
|
436
|
+
aria-valuemax={100}
|
|
437
|
+
aria-valuenow={valueNow()}
|
|
438
|
+
{...rest}
|
|
439
|
+
>
|
|
440
|
+
<Show when={local.withHandle}>
|
|
441
|
+
<div
|
|
442
|
+
class={cn(
|
|
443
|
+
'z-10 flex items-center justify-center',
|
|
444
|
+
isHoriz() ? 'h-6 w-3 flex-col' : 'h-3 w-6 flex-row',
|
|
445
|
+
)}
|
|
446
|
+
>
|
|
447
|
+
<svg
|
|
448
|
+
class={cn(
|
|
449
|
+
'text-muted-foreground/40',
|
|
450
|
+
isHoriz() ? 'h-3 w-2' : 'h-2 w-3 rotate-90'
|
|
451
|
+
)}
|
|
452
|
+
viewBox="0 0 4 8"
|
|
453
|
+
fill="currentColor"
|
|
454
|
+
>
|
|
455
|
+
<circle cx="1" cy="1.5" r="0.6" />
|
|
456
|
+
<circle cx="3" cy="1.5" r="0.6" />
|
|
457
|
+
<circle cx="1" cy="4" r="0.6" />
|
|
458
|
+
<circle cx="3" cy="4" r="0.6" />
|
|
459
|
+
<circle cx="1" cy="6.5" r="0.6" />
|
|
460
|
+
<circle cx="3" cy="6.5" r="0.6" />
|
|
461
|
+
</svg>
|
|
462
|
+
</div>
|
|
463
|
+
</Show>
|
|
464
|
+
</div>
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// --- Resizable (convenience: auto-inserts handles between visible panels) ---
|
|
469
|
+
|
|
470
|
+
export interface ResizableProps {
|
|
471
|
+
orientation?: Orientation;
|
|
472
|
+
/** Fired on drag-end / keyboard resize / visibility change with the current panel sizes (percent). */
|
|
473
|
+
onChange?: (sizes: number[]) => void;
|
|
474
|
+
/** Show a visible grip on each interactive handle. */
|
|
475
|
+
withHandle?: boolean;
|
|
476
|
+
class?: string;
|
|
477
|
+
/** Which panel index is maximized (null = none). Hides the others. */
|
|
478
|
+
maximizedIndex?: number | null;
|
|
479
|
+
/** Fired when the maximized panel changes (index, or null on restore). */
|
|
480
|
+
onMaximizeChange?: (index: number | null) => void;
|
|
481
|
+
/** `ResizablePanel` children. */
|
|
482
|
+
children: JSX.Element;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Convenience group that takes `ResizablePanel` children and AUTO-INSERTS a
|
|
487
|
+
* `ResizableHandle` between each pair of visible (non-`hidden`) panels. A handle
|
|
488
|
+
* is interactive only between two unlocked neighbors; otherwise it renders as a
|
|
489
|
+
* static divider. Power users who need manual control can keep using
|
|
490
|
+
* `ResizablePanelGroup` + explicit `ResizableHandle`s.
|
|
491
|
+
*/
|
|
492
|
+
function Resizable(props: ResizableProps) {
|
|
493
|
+
const [local] = splitProps(props, [
|
|
494
|
+
'orientation', 'onChange', 'withHandle', 'class', 'children', 'maximizedIndex', 'onMaximizeChange',
|
|
495
|
+
]);
|
|
496
|
+
const orientation = () => local.orientation ?? 'horizontal';
|
|
497
|
+
|
|
498
|
+
// Resolve children to the actual panel elements so we can read their props.
|
|
499
|
+
const resolved = resolveChildren(() => local.children);
|
|
500
|
+
|
|
501
|
+
const panels = (): { el: Element; locked: boolean; hidden: boolean }[] => {
|
|
502
|
+
const arr = resolved.toArray().filter((c): c is Element => c instanceof Element);
|
|
503
|
+
return arr.map((el) => ({
|
|
504
|
+
el,
|
|
505
|
+
locked: el.hasAttribute('data-locked'),
|
|
506
|
+
hidden: (el as HTMLElement).hidden || el.hasAttribute('hidden'),
|
|
507
|
+
}));
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
const visible = () => panels().filter((p) => !p.hidden);
|
|
511
|
+
|
|
512
|
+
const maxIdx = () => local.maximizedIndex ?? null;
|
|
513
|
+
// When maximized, only the maximized panel is "visible" for layout; siblings drop
|
|
514
|
+
// (mirrors the web-component facade hiding siblings). Indices are over all panels.
|
|
515
|
+
// Note: stash/restore of sizes is handled by the panels' own defaultSize/flex —
|
|
516
|
+
// since the convenience re-renders from the unchanged ResizablePanel children on
|
|
517
|
+
// restore, sizes return to their declared values. The post-drag-live-size stash
|
|
518
|
+
// fidelity is a web-component-only concern; the Solid story uses declarative sizes.
|
|
519
|
+
const renderPanels = () => {
|
|
520
|
+
const all = panels();
|
|
521
|
+
const m = maxIdx();
|
|
522
|
+
if (m == null) return all.filter((p) => !p.hidden);
|
|
523
|
+
const target = all[m];
|
|
524
|
+
return target && !target.hidden ? [target] : all.filter((p) => !p.hidden);
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// Notify on change of the maximized index (defer the initial null run).
|
|
528
|
+
let prevMax: number | null | undefined;
|
|
529
|
+
createEffect(() => {
|
|
530
|
+
const m = maxIdx();
|
|
531
|
+
if (prevMax === undefined) { prevMax = m; return; }
|
|
532
|
+
if (m !== prevMax) { prevMax = m; local.onMaximizeChange?.(m); }
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
function emitChange() {
|
|
536
|
+
if (!local.onChange) return;
|
|
537
|
+
const sizes = visible().map((p) => {
|
|
538
|
+
const r = (p.el as HTMLElement).getBoundingClientRect();
|
|
539
|
+
const parent = (p.el as HTMLElement).parentElement;
|
|
540
|
+
const total = parent ? parent.getBoundingClientRect()[orientation() === 'horizontal' ? 'width' : 'height'] : 0;
|
|
541
|
+
const dimVal = r[orientation() === 'horizontal' ? 'width' : 'height'];
|
|
542
|
+
return total > 0 ? Math.round((dimVal / total) * 100) : 0;
|
|
543
|
+
});
|
|
544
|
+
local.onChange(sizes);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return (
|
|
548
|
+
<ResizableContext.Provider value={{ orientation: orientation() }}>
|
|
549
|
+
<div
|
|
550
|
+
class={cn(
|
|
551
|
+
'flex h-full w-full',
|
|
552
|
+
orientation() === 'vertical' ? 'flex-col' : 'flex-row',
|
|
553
|
+
local.class,
|
|
554
|
+
)}
|
|
555
|
+
data-orientation={orientation()}
|
|
556
|
+
>
|
|
557
|
+
<For each={renderPanels()}>
|
|
558
|
+
{(panel, i) => (
|
|
559
|
+
<>
|
|
560
|
+
<Show when={i() > 0}>
|
|
561
|
+
<ResizableHandle
|
|
562
|
+
withHandle={local.withHandle}
|
|
563
|
+
static={panel.locked || renderPanels()[i() - 1]?.locked}
|
|
564
|
+
onPanelResize={() => emitChange()}
|
|
565
|
+
/>
|
|
566
|
+
</Show>
|
|
567
|
+
{panel.el as unknown as JSX.Element}
|
|
568
|
+
</>
|
|
569
|
+
)}
|
|
570
|
+
</For>
|
|
571
|
+
</div>
|
|
572
|
+
</ResizableContext.Provider>
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export { ResizablePanelGroup, ResizablePanel, ResizableHandle, Resizable };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { For } from 'solid-js';
|
|
3
|
+
import { ScrollArea } from './scroll-area';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Solid (Advanced)/Primitives/ScrollArea',
|
|
8
|
+
component: ScrollArea,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'padded',
|
|
12
|
+
docs: {
|
|
13
|
+
description: componentDescription([
|
|
14
|
+
'A vertically scrollable container with thin, themed scrollbars (`scrollbar-thin` + muted thumb, transparent track). A thin styling layer over native overflow — no custom scroll hijacking, so momentum, keyboard, and accessibility behave exactly like the platform expects. Constrain it with a height (or let a flex parent bound it) and overflow content scrolls.',
|
|
15
|
+
'**When to use:** any bounded region whose content can exceed its height — the conversation/history sidebar, a long menu, a tall card body.',
|
|
16
|
+
'**How to use:** set a height via `class` and drop the scrollable content inside. All other div props (e.g. `aria-label`) are forwarded.',
|
|
17
|
+
]),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
render: () => (
|
|
21
|
+
<ScrollArea class="h-56 w-72 rounded-lg border border-border p-2">
|
|
22
|
+
<ul class="space-y-1">
|
|
23
|
+
<For each={Array.from({ length: 24 }, (_, i) => i + 1)}>
|
|
24
|
+
{(n) => (
|
|
25
|
+
<li class="rounded-md px-3 py-2 text-sm text-foreground hover:bg-muted">
|
|
26
|
+
Conversation {n}
|
|
27
|
+
</li>
|
|
28
|
+
)}
|
|
29
|
+
</For>
|
|
30
|
+
</ul>
|
|
31
|
+
</ScrollArea>
|
|
32
|
+
),
|
|
33
|
+
} satisfies Meta<typeof ScrollArea>;
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
type Story = StoryObj<typeof meta>;
|
|
37
|
+
|
|
38
|
+
const IMPORT = `import { ScrollArea } from '@kitn.ai/ui';`;
|
|
39
|
+
|
|
40
|
+
/** A bounded list that scrolls. Note macOS hides overlay scrollbars until you scroll. */
|
|
41
|
+
export const Playground: Story = {
|
|
42
|
+
parameters: {
|
|
43
|
+
docs: {
|
|
44
|
+
source: {
|
|
45
|
+
code: `${IMPORT}\n\n<ScrollArea class="h-56 w-72 rounded-lg border p-2">\n <For each={conversations}>{(c) => <Row {...c} />}</For>\n</ScrollArea>`,
|
|
46
|
+
language: 'tsx',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
export interface ScrollAreaProps extends JSX.HTMLAttributes<HTMLDivElement> { children: JSX.Element; }
|
|
5
|
+
|
|
6
|
+
export function ScrollArea(props: ScrollAreaProps) {
|
|
7
|
+
const [local, rest] = splitProps(props, ['children', 'class']);
|
|
8
|
+
return (
|
|
9
|
+
// tabindex=0 keeps the scroll region reachable by keyboard when it has no
|
|
10
|
+
// focusable descendants (WCAG 2.1.1 — axe `scrollable-region-focusable`).
|
|
11
|
+
<div tabindex={0} class={cn('overflow-y-auto scrollbar-thin', local.class)} {...rest}>
|
|
12
|
+
{local.children}
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|