@zonsh/ui 0.2.0 → 0.5.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 +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Radio as BaseRadio } from "@base-ui/react/radio";
|
|
4
|
+
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
|
|
5
|
+
import { StarIcon } from "lucide-react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { cn } from "../lib/cn.js";
|
|
8
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
9
|
+
const defaultMessages = {
|
|
10
|
+
item: (value, count) => (count === 1 ? `${value} star` : `${value} stars`),
|
|
11
|
+
value: (value, max) => `${value} out of ${max}`,
|
|
12
|
+
empty: "Not rated",
|
|
13
|
+
};
|
|
14
|
+
const sizes = {
|
|
15
|
+
sm: { row: "h-(--control-h-sm)", item: "px-px", icon: "size-4" },
|
|
16
|
+
default: { row: "h-(--control-h)", item: "px-0.5", icon: "size-5" },
|
|
17
|
+
lg: { row: "h-(--control-h-lg)", item: "px-0.5", icon: "size-6" },
|
|
18
|
+
};
|
|
19
|
+
function useControllable(value, defaultValue) {
|
|
20
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
21
|
+
const controlled = value !== undefined;
|
|
22
|
+
return [controlled ? value : inner, setInner];
|
|
23
|
+
}
|
|
24
|
+
/** One star: the outline, with the filled star over it clipped to `fill` (0…1) from the start. */
|
|
25
|
+
function Star({ icon, fill, size, preview, }) {
|
|
26
|
+
const iconClass = cn(sizes[size].icon, "shrink-0");
|
|
27
|
+
return (_jsxs("span", { "aria-hidden": true, className: "relative flex", children: [React.cloneElement(icon, {
|
|
28
|
+
className: cn(iconClass, "text-control-muted transition-colors duration-(--duration) ease-(--ease)", "group-data-invalid/rating:text-destructive"),
|
|
29
|
+
strokeWidth: 1.5,
|
|
30
|
+
}), fill > 0 && (_jsx("span", { "data-slot": "rating-fill", className: cn("absolute inset-y-0 start-0 flex overflow-hidden transition-colors duration-(--duration) ease-(--ease)", preview ? "text-foreground-soft" : "text-foreground"), style: { width: `${Math.round(fill * 100)}%` }, children: React.cloneElement(icon, { className: iconClass, fill: "currentColor", strokeWidth: 1.5 }) }))] }));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Rating — a score of 1 to 5 (or `max`) as a row of stars, in the foreground ink.
|
|
34
|
+
*
|
|
35
|
+
* A radio group under the hood: arrow keys move the rating and pick it, a pointer previews the
|
|
36
|
+
* stars it would set, and with `allowHalf` each star takes two picks. In a `Field` it submits
|
|
37
|
+
* its number under the field's name and takes `required` and the Field's invalid state. With
|
|
38
|
+
* `readOnly` it is a picture of a score, read out as "4.5 out of 5".
|
|
39
|
+
*
|
|
40
|
+
* The rule people break: yellow stars. The stars are ink like every other mark; a rating is a
|
|
41
|
+
* value, not a status. And put the count next to an average ("4.5 · 128 reviews"): five stars
|
|
42
|
+
* from one review is not the same thing.
|
|
43
|
+
*/
|
|
44
|
+
export function Rating({ value: valueProp, defaultValue = null, onValueChange, max: maxProp = 5, allowHalf = false, clearable = false, readOnly = false, disabled, size = "default", icon = _jsx(StarIcon, {}), labels, className, ref, onKeyDown, ...props }) {
|
|
45
|
+
const text = useMessages("rating", defaultMessages, labels);
|
|
46
|
+
const locale = useLocale();
|
|
47
|
+
const number = React.useMemo(() => {
|
|
48
|
+
try {
|
|
49
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 2 });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return new Intl.NumberFormat("en", { maximumFractionDigits: 2 });
|
|
53
|
+
}
|
|
54
|
+
}, [locale]);
|
|
55
|
+
const max = Math.max(1, Math.floor(maxProp));
|
|
56
|
+
const [value, setValue] = useControllable(valueProp, defaultValue);
|
|
57
|
+
const [hover, setHover] = React.useState(null);
|
|
58
|
+
const pressedChecked = React.useRef(false);
|
|
59
|
+
const id = React.useId();
|
|
60
|
+
const commit = (next) => {
|
|
61
|
+
if (next === value)
|
|
62
|
+
return;
|
|
63
|
+
setValue(next);
|
|
64
|
+
onValueChange?.(next);
|
|
65
|
+
};
|
|
66
|
+
// A form's reset puts an uncontrolled rating back where it started.
|
|
67
|
+
const latestReset = React.useRef(() => { });
|
|
68
|
+
latestReset.current = () => {
|
|
69
|
+
if (valueProp === undefined)
|
|
70
|
+
setValue(defaultValue);
|
|
71
|
+
};
|
|
72
|
+
const formRef = React.useCallback((node) => {
|
|
73
|
+
const form = node?.closest("form");
|
|
74
|
+
if (!form)
|
|
75
|
+
return;
|
|
76
|
+
const reset = () => latestReset.current();
|
|
77
|
+
form.addEventListener("reset", reset);
|
|
78
|
+
return () => form.removeEventListener("reset", reset);
|
|
79
|
+
}, []);
|
|
80
|
+
const refs = React.useCallback((node) => {
|
|
81
|
+
const cleanup = formRef(node);
|
|
82
|
+
if (typeof ref === "function")
|
|
83
|
+
ref(node);
|
|
84
|
+
else if (ref)
|
|
85
|
+
ref.current = node;
|
|
86
|
+
return () => {
|
|
87
|
+
cleanup?.();
|
|
88
|
+
if (typeof ref === "function")
|
|
89
|
+
ref(null);
|
|
90
|
+
else if (ref)
|
|
91
|
+
ref.current = null;
|
|
92
|
+
};
|
|
93
|
+
}, [formRef, ref]);
|
|
94
|
+
const shown = hover ?? value ?? 0;
|
|
95
|
+
const stars = Array.from({ length: max }, (_, i) => i + 1);
|
|
96
|
+
if (readOnly) {
|
|
97
|
+
const v = value == null ? null : Math.min(Math.max(value, 0), max);
|
|
98
|
+
// What only a radio group takes (a name, a form) has no place on a picture of a score.
|
|
99
|
+
const { name: _name, required: _required, form: _form, inputRef: _inputRef, render: _render, style, ...rest } = props;
|
|
100
|
+
return (_jsx("span", { ref: refs, role: "img", "aria-label": v == null ? text.empty : text.value(number.format(v), number.format(max)), "data-slot": "rating", "data-size": size, "data-readonly": "", className: cn("inline-flex shrink-0 items-center", sizes[size].row, className), style: typeof style === "function" ? undefined : style, ...rest, children: stars.map((star) => (_jsx("span", { "data-slot": "rating-item", className: cn("flex shrink-0", sizes[size].item), children: _jsx(Star, { icon: icon, fill: Math.min(Math.max((v ?? 0) - (star - 1), 0), 1), size: size, preview: false }) }, star))) }));
|
|
101
|
+
}
|
|
102
|
+
const choicesOf = (star) => (allowHalf ? [star - 0.5, star] : [star]);
|
|
103
|
+
return (_jsx(BaseRadioGroup, { ref: refs, "data-slot": "rating", "data-size": size, value: value, onValueChange: (next) => commit(next), disabled: disabled, onKeyDown: (event) => {
|
|
104
|
+
onKeyDown?.(event);
|
|
105
|
+
if (clearable && (event.key === "Backspace" || event.key === "Delete") && value != null) {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
commit(null);
|
|
108
|
+
}
|
|
109
|
+
}, onPointerLeave: () => setHover(null), className: (state) => cn("group/rating inline-flex shrink-0 items-center", "data-disabled:cursor-not-allowed data-disabled:opacity-55", sizes[size].row, typeof className === "function" ? className(state) : className), ...props, children: stars.map((star) => {
|
|
110
|
+
const fill = Math.min(Math.max(shown - (star - 1), 0), 1);
|
|
111
|
+
return (_jsxs("span", { "data-slot": "rating-item", className: cn("relative flex h-full shrink-0 items-center rounded-item", "has-[[data-slot=rating-radio]:focus-visible]:outline-2 has-[[data-slot=rating-radio]:focus-visible]:outline-control-focus has-[[data-slot=rating-radio]:focus-visible]:outline-solid", sizes[size].item), children: [_jsx(Star, { icon: icon, fill: fill, size: size, preview: hover != null && hover !== value }), choicesOf(star).map((choice, i, all) => {
|
|
112
|
+
const labelId = `${id}-${choice}`;
|
|
113
|
+
return (_jsxs(React.Fragment, { children: [_jsx("span", { id: labelId, className: "sr-only", children: text.item(number.format(choice), choice) }), _jsx(BaseRadio.Root, { value: choice, "data-slot": "rating-radio", "aria-labelledby": labelId, onPointerDown: () => (pressedChecked.current = choice === value), onPointerMove: (event) => {
|
|
114
|
+
if (event.pointerType === "mouse" && !disabled)
|
|
115
|
+
setHover(choice);
|
|
116
|
+
}, onClick: () => {
|
|
117
|
+
if (clearable && pressedChecked.current && choice === value) {
|
|
118
|
+
pressedChecked.current = false;
|
|
119
|
+
commit(null);
|
|
120
|
+
}
|
|
121
|
+
}, className: cn("absolute inset-y-0 cursor-pointer outline-none data-disabled:cursor-not-allowed", all.length === 1 ? "inset-x-0" : i === 0 ? "start-0 w-1/2" : "end-0 w-1/2") })] }, choice));
|
|
122
|
+
})] }, star));
|
|
123
|
+
}) }));
|
|
124
|
+
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { type CollapsibleTriggerProps } from "./collapsible.js";
|
|
4
|
+
export interface ReasoningMessages {
|
|
5
|
+
/** While the model thinks. */
|
|
6
|
+
thinking: string;
|
|
7
|
+
/** Done, when the time is not known. */
|
|
8
|
+
thoughtBriefly: string;
|
|
9
|
+
/** Done, after `seconds` seconds. */
|
|
10
|
+
thoughtFor: (seconds: number) => string;
|
|
11
|
+
}
|
|
12
|
+
declare module "./locale" {
|
|
13
|
+
interface Messages {
|
|
14
|
+
reasoning: ReasoningMessages;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
4
17
|
export interface ReasoningProps extends BaseCollapsible.Root.Props {
|
|
5
18
|
/** The model is thinking right now: the label shimmers and the panel opens. */
|
|
6
19
|
streaming?: boolean;
|
|
@@ -18,12 +31,14 @@ export interface ReasoningProps extends BaseCollapsible.Root.Props {
|
|
|
18
31
|
*/
|
|
19
32
|
export declare function Reasoning({ streaming, duration: durationProp, open: openProp, defaultOpen, onOpenChange, className, ...props }: ReasoningProps): React.JSX.Element;
|
|
20
33
|
export interface ReasoningTriggerProps extends Omit<CollapsibleTriggerProps, "showIcon"> {
|
|
34
|
+
/** The default label's words; a LocaleProvider sets them for every ReasoningTrigger. */
|
|
35
|
+
labels?: Partial<ReasoningMessages>;
|
|
21
36
|
}
|
|
22
37
|
/**
|
|
23
38
|
* The trigger: a brain, the label and a chevron, in mono. Children replace the label;
|
|
24
39
|
* the default reads "Thinking…", then "Thought for n seconds".
|
|
25
40
|
*/
|
|
26
|
-
export declare function ReasoningTrigger({ className, children, ...props }: ReasoningTriggerProps): React.JSX.Element;
|
|
41
|
+
export declare function ReasoningTrigger({ labels, className, children, ...props }: ReasoningTriggerProps): React.JSX.Element;
|
|
27
42
|
/**
|
|
28
43
|
* The reasoning itself, muted and set in from a hairline. Plain text keeps its line breaks;
|
|
29
44
|
* a `Response` inside renders markdown.
|
|
@@ -4,6 +4,12 @@ import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { cn, sx } from "../lib/cn.js";
|
|
6
6
|
import { Collapsible, CollapsiblePanel, CollapsibleTrigger, } from "./collapsible.js";
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
8
|
+
const defaultMessages = {
|
|
9
|
+
thinking: "Thinking…",
|
|
10
|
+
thoughtBriefly: "Thought for a few seconds",
|
|
11
|
+
thoughtFor: (seconds) => `Thought for ${seconds} ${seconds === 1 ? "second" : "seconds"}`,
|
|
12
|
+
};
|
|
7
13
|
const ReasoningContext = React.createContext({
|
|
8
14
|
streaming: false,
|
|
9
15
|
duration: undefined,
|
|
@@ -51,14 +57,11 @@ export function Reasoning({ streaming = false, duration: durationProp, open: ope
|
|
|
51
57
|
* The trigger: a brain, the label and a chevron, in mono. Children replace the label;
|
|
52
58
|
* the default reads "Thinking…", then "Thought for n seconds".
|
|
53
59
|
*/
|
|
54
|
-
export function ReasoningTrigger({ className, children, ...props }) {
|
|
60
|
+
export function ReasoningTrigger({ labels, className, children, ...props }) {
|
|
55
61
|
const { streaming, duration } = React.useContext(ReasoningContext);
|
|
62
|
+
const text = useMessages("reasoning", defaultMessages, labels);
|
|
56
63
|
const label = children ??
|
|
57
|
-
(streaming
|
|
58
|
-
? "Thinking…"
|
|
59
|
-
: duration == null
|
|
60
|
-
? "Thought for a few seconds"
|
|
61
|
-
: `Thought for ${duration} ${duration === 1 ? "second" : "seconds"}`);
|
|
64
|
+
(streaming ? text.thinking : duration == null ? text.thoughtBriefly : text.thoughtFor(duration));
|
|
62
65
|
return (_jsxs(CollapsibleTrigger, { "data-slot": "reasoning-trigger", showIcon: false, className: sx("gap-1.5 text-muted-foreground", className), ...props, children: [_jsx(BrainIcon, { "aria-hidden": true, className: "size-3.5 shrink-0" }), _jsx("span", { "data-slot": "reasoning-label", "data-streaming": streaming ? "" : undefined, children: label }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 transition-[rotate] duration-(--duration) ease-(--ease) group-data-panel-open/collapsible-trigger:rotate-180" })] }));
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
@@ -66,5 +69,5 @@ export function ReasoningTrigger({ className, children, ...props }) {
|
|
|
66
69
|
* a `Response` inside renders markdown.
|
|
67
70
|
*/
|
|
68
71
|
export function ReasoningContent({ className, children, ...props }) {
|
|
69
|
-
return (_jsx(CollapsiblePanel, { "data-slot": "reasoning-content", children: _jsx("div", { className: cn("
|
|
72
|
+
return (_jsx(CollapsiblePanel, { "data-slot": "reasoning-content", className: "duration-(--duration-glide) ease-(--ease-glide)", children: _jsx("div", { className: cn("ms-1.5 border-s border-border/60 py-1 ps-4 text-sm leading-relaxed text-muted-foreground", typeof children === "string" && "whitespace-pre-wrap", className), ...props, children: children }) }));
|
|
70
73
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type GroupProps, type PanelProps, type SeparatorProps } from "react-resizable-panels";
|
|
3
|
+
export interface ResizableMessages {
|
|
4
|
+
/** The handle's name, when it has no `aria-label` of its own. */
|
|
5
|
+
handle: string;
|
|
6
|
+
}
|
|
7
|
+
declare module "./locale" {
|
|
8
|
+
interface Messages {
|
|
9
|
+
resizable: ResizableMessages;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
export interface ResizablePanelGroupProps extends GroupProps {
|
|
4
13
|
/** `horizontal` lays panels side by side (a vertical handle); `vertical` stacks them. */
|
|
5
14
|
orientation?: "horizontal" | "vertical";
|
|
@@ -27,7 +36,7 @@ export declare function ResizablePanel({ className, ...props }: ResizablePanelPr
|
|
|
27
36
|
export interface ResizableHandleProps extends SeparatorProps {
|
|
28
37
|
/** Show a small raised grip with mono dots in the middle of the hairline. */
|
|
29
38
|
withHandle?: boolean;
|
|
30
|
-
/** Accessible name of the separator. Defaults to "Resize". */
|
|
39
|
+
/** Accessible name of the separator. Defaults to "Resize", or `messages.resizable.handle`. */
|
|
31
40
|
"aria-label"?: string;
|
|
32
41
|
}
|
|
33
42
|
/**
|
|
@@ -3,6 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Group, Panel, Separator, } from "react-resizable-panels";
|
|
5
5
|
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { useMessages } from "./locale.js";
|
|
7
|
+
const defaultMessages = { handle: "Resize" };
|
|
6
8
|
const OrientationContext = React.createContext("horizontal");
|
|
7
9
|
/**
|
|
8
10
|
* ResizablePanelGroup — split panes the user can resize: an editor beside its preview, a list
|
|
@@ -33,7 +35,8 @@ export function ResizablePanel({ className, ...props }) {
|
|
|
33
35
|
*/
|
|
34
36
|
export function ResizableHandle({ withHandle = false, className, children, ...props }) {
|
|
35
37
|
const orientation = React.useContext(OrientationContext);
|
|
36
|
-
|
|
38
|
+
const text = useMessages("resizable", defaultMessages);
|
|
39
|
+
return (_jsxs(Separator, { "data-slot": "resizable-handle", "data-orientation": orientation, "aria-label": text.handle, className: cn("group/handle relative z-10 flex shrink-0 items-center justify-center bg-border outline-none", "transition-[background-color] duration-(--duration) ease-brand", orientation === "horizontal" ? "w-px self-stretch" : "h-px w-full", "data-[separator=active]:bg-control-focus data-[separator=focus]:bg-control-focus data-[separator=hover]:bg-control-focus",
|
|
37
40
|
// The visible line is 1px; the focus outline is drawn on a 3px band so it stays legible.
|
|
38
41
|
"focus-visible:outline-none focus-visible:after:absolute focus-visible:after:bg-control-focus focus-visible:after:content-['']", orientation === "horizontal"
|
|
39
42
|
? "focus-visible:after:inset-y-0 focus-visible:after:left-1/2 focus-visible:after:w-[2px] focus-visible:after:-translate-x-1/2"
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
export interface ResponseMessages {
|
|
3
|
+
/** A task list item's ticked box. */
|
|
4
|
+
done: string;
|
|
5
|
+
/** A task list item's empty box. */
|
|
6
|
+
todo: string;
|
|
7
|
+
}
|
|
8
|
+
declare module "./locale" {
|
|
9
|
+
interface Messages {
|
|
10
|
+
response: ResponseMessages;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
export interface ResponseProps extends Omit<React.ComponentProps<"div">, "children"> {
|
|
3
14
|
/** The reply, as markdown. */
|
|
4
15
|
children: string;
|
|
@@ -6,22 +17,23 @@ export interface ResponseProps extends Omit<React.ComponentProps<"div">, "childr
|
|
|
6
17
|
streaming?: boolean;
|
|
7
18
|
/**
|
|
8
19
|
* Reveal the text at an even pace, a word at a time with each word coming into focus, instead
|
|
9
|
-
* of in the bursts it arrives in. Default `true`;
|
|
20
|
+
* of in the bursts it arrives in. Default `true`; under reduced motion, on a phone or a touch
|
|
21
|
+
* screen the words fade in without the blur.
|
|
10
22
|
*/
|
|
11
23
|
smooth?: boolean;
|
|
12
24
|
/**
|
|
13
|
-
* Colour fenced code by the language its fence names, in the zon theme.
|
|
14
|
-
*
|
|
25
|
+
* Colour fenced code by the language its fence names, in the zon theme. Default `true`; a fence
|
|
26
|
+
* without a language, or one Shiki does not know, stays mono either way.
|
|
15
27
|
*/
|
|
16
28
|
highlight?: boolean;
|
|
17
29
|
}
|
|
18
30
|
/**
|
|
19
31
|
* Response — an assistant's reply, rendered from markdown in the brand's reading type: Licht Sans at
|
|
20
32
|
* 15px, Licht Light headings, mono inline code, hairline tables and rules, and fenced code as a
|
|
21
|
-
* `CodeBlock
|
|
33
|
+
* `CodeBlock`, coloured by its language.
|
|
22
34
|
*
|
|
23
35
|
* While `streaming`, the reply writes itself out evenly at the pace it is arriving, a word at a
|
|
24
|
-
* time, each word coming into focus from a soft blur
|
|
36
|
+
* time, each word coming into focus from a soft blur; half-written
|
|
25
37
|
* markdown renders as it will end up. Raw HTML in the markdown is shown as text, unsafe link
|
|
26
38
|
* targets are dropped and images become links, because model output is untrusted; a paragraph that
|
|
27
39
|
* would take the parser too long shows as plain text.
|
|
@@ -5,6 +5,16 @@ import * as React from "react";
|
|
|
5
5
|
import { cn } from "../lib/cn.js";
|
|
6
6
|
import { capNesting, overBudget } from "../lib/markdown-guard.js";
|
|
7
7
|
import { CodeBlock } from "./code-block.js";
|
|
8
|
+
import { useMessages } from "./locale.js";
|
|
9
|
+
const defaultMessages = { done: "Done", todo: "To do" };
|
|
10
|
+
/** The task boxes the renderer writes, named in English (see `checkbox` below). */
|
|
11
|
+
const TASK_BOX = /<input type="checkbox" disabled( checked)? aria-label="(?:Done|To do)">/g;
|
|
12
|
+
/** A block's HTML with its task boxes named in `text`'s words. */
|
|
13
|
+
function nameTaskBoxes(html, text) {
|
|
14
|
+
if (text === defaultMessages || !html.includes('type="checkbox"'))
|
|
15
|
+
return html;
|
|
16
|
+
return html.replace(TASK_BOX, (_, checked) => `<input type="checkbox" disabled${checked ?? ""} aria-label="${escapeHtml(checked ? text.done : text.todo)}">`);
|
|
17
|
+
}
|
|
8
18
|
/* ── Rendering ─────────────────────────────────────────────────────────────── */
|
|
9
19
|
const ESCAPES = {
|
|
10
20
|
"&": "&",
|
|
@@ -276,9 +286,14 @@ const ResponseCode = React.memo(CodeBlock);
|
|
|
276
286
|
* Models stream in bursts: forty characters, a pause, eighty more. Shown as they arrive, the text
|
|
277
287
|
* jerks. Instead the reply is revealed at an even pace on every frame — the pace the text has been
|
|
278
288
|
* arriving at (an average of the last bursts) plus a share of whatever is waiting, so it never
|
|
279
|
-
* falls far behind — a whole word at a time. Each new word comes into focus: from transparent
|
|
280
|
-
* blurred
|
|
281
|
-
*
|
|
289
|
+
* falls far behind — a whole word at a time. Each new word comes into focus: from transparent and
|
|
290
|
+
* softly blurred to sharp, over BLUR_MS. When the stream ends, what is left is revealed quickly.
|
|
291
|
+
*
|
|
292
|
+
* Up to 360 characters are drawn every frame, so a frame writes as little as it can: opacity
|
|
293
|
+
* always, a blur of at most 2px only with a fine pointer on a wide screen. A phone, a touch
|
|
294
|
+
* screen or reduced motion get the fade alone — still paced, so the text does not jerk. The words
|
|
295
|
+
* do not rise: they are inline, where a transform does nothing, and moving them with `top` would
|
|
296
|
+
* lay the line out again every frame.
|
|
282
297
|
*
|
|
283
298
|
* The timing follows what is on screen, not the markdown source: after every frame that drew
|
|
284
299
|
* more, it notes how many visible characters there are and when. Syntax (`**`, `|`, a code
|
|
@@ -290,7 +305,12 @@ const BLUR_MS = 520;
|
|
|
290
305
|
const BLUR_CHARS = 360;
|
|
291
306
|
/** The slowest pace, in characters per second, so a slow stream still flows. */
|
|
292
307
|
const MIN_PACE = 32;
|
|
293
|
-
|
|
308
|
+
/** The most a new word is blurred, in px, where it is blurred at all. */
|
|
309
|
+
const BLUR_PX = 2;
|
|
310
|
+
/** Whether new words may blur: a fine pointer on a screen 768px or wider, and motion allowed. */
|
|
311
|
+
const canBlur = () => typeof window !== "undefined" &&
|
|
312
|
+
!!window.matchMedia?.("(pointer: fine) and (min-width: 48rem) and (prefers-reduced-motion: no-preference)")
|
|
313
|
+
.matches;
|
|
294
314
|
const commonPrefix = (a, b) => {
|
|
295
315
|
let i = 0;
|
|
296
316
|
while (i < a.length && i < b.length && a[i] === b[i])
|
|
@@ -299,6 +319,8 @@ const commonPrefix = (a, b) => {
|
|
|
299
319
|
};
|
|
300
320
|
/** How many characters of a text the reveal counts: spaces are left out. */
|
|
301
321
|
const visibleLength = (text) => text.replace(/\s/g, "").length;
|
|
322
|
+
/** Each markdown block's visible length, with the text it was counted from. */
|
|
323
|
+
const blockLengths = new WeakMap();
|
|
302
324
|
const smoothstep = (t) => t * t * (3 - 2 * t);
|
|
303
325
|
const graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl
|
|
304
326
|
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
@@ -363,16 +385,16 @@ function wrapWords(nodes, total, from) {
|
|
|
363
385
|
/**
|
|
364
386
|
* Response — an assistant's reply, rendered from markdown in the brand's reading type: Licht Sans at
|
|
365
387
|
* 15px, Licht Light headings, mono inline code, hairline tables and rules, and fenced code as a
|
|
366
|
-
* `CodeBlock
|
|
388
|
+
* `CodeBlock`, coloured by its language.
|
|
367
389
|
*
|
|
368
390
|
* While `streaming`, the reply writes itself out evenly at the pace it is arriving, a word at a
|
|
369
|
-
* time, each word coming into focus from a soft blur
|
|
391
|
+
* time, each word coming into focus from a soft blur; half-written
|
|
370
392
|
* markdown renders as it will end up. Raw HTML in the markdown is shown as text, unsafe link
|
|
371
393
|
* targets are dropped and images become links, because model output is untrusted; a paragraph that
|
|
372
394
|
* would take the parser too long shows as plain text.
|
|
373
395
|
* The rule people break: rendering the reply with their own `dangerouslySetInnerHTML` and none of these rules.
|
|
374
396
|
*/
|
|
375
|
-
export function Response({ children, streaming = false, smooth = true, highlight =
|
|
397
|
+
export function Response({ children, streaming = false, smooth = true, highlight = true, className, ...props }) {
|
|
376
398
|
const root = React.useRef(null);
|
|
377
399
|
const [shown, setShown] = React.useState(children.length);
|
|
378
400
|
const pace = React.useRef({
|
|
@@ -389,7 +411,10 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
389
411
|
const words = React.useRef([]);
|
|
390
412
|
/** What the last render parsed: kept, and grown from, while the reply grows. */
|
|
391
413
|
const parsed = React.useRef(null);
|
|
392
|
-
|
|
414
|
+
// Pacing is not movement: it stays under reduced motion, where the words only fade in.
|
|
415
|
+
const paced = smooth;
|
|
416
|
+
/** Read when a reveal starts (see `run`): blur the new words, or only fade them in. */
|
|
417
|
+
const blur = React.useRef(false);
|
|
393
418
|
/** Draws each new word for the time since it appeared. */
|
|
394
419
|
const paint = React.useCallback((now) => {
|
|
395
420
|
const { stamps, settled } = pace.current;
|
|
@@ -406,10 +431,8 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
406
431
|
continue;
|
|
407
432
|
}
|
|
408
433
|
style.opacity = String(e);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
style.position = "relative";
|
|
412
|
-
style.top = `${((1 - e) * 0.3).toFixed(3)}em`;
|
|
434
|
+
if (blur.current)
|
|
435
|
+
style.filter = `blur(${((1 - e) * BLUR_PX).toFixed(2)}px)`;
|
|
413
436
|
}
|
|
414
437
|
}, []);
|
|
415
438
|
const tick = React.useCallback((now) => {
|
|
@@ -446,6 +469,7 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
446
469
|
const p = pace.current;
|
|
447
470
|
if (p.frame)
|
|
448
471
|
return;
|
|
472
|
+
blur.current = canBlur();
|
|
449
473
|
p.last = 0;
|
|
450
474
|
p.frame = requestAnimationFrame(tick);
|
|
451
475
|
}, [tick]);
|
|
@@ -495,6 +519,7 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
495
519
|
const visible = paced ? children.slice(0, limit) : children;
|
|
496
520
|
const live = streaming || visible.length < children.length;
|
|
497
521
|
const blocks = React.useMemo(() => render(visible, live, parsed), [visible, live]);
|
|
522
|
+
const text = useMessages("response", defaultMessages);
|
|
498
523
|
// After each render: count what is on screen, stamp what is new, wrap the new words and paint them.
|
|
499
524
|
React.useLayoutEffect(() => {
|
|
500
525
|
const el = root.current;
|
|
@@ -509,10 +534,19 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
509
534
|
p.settled = -1;
|
|
510
535
|
return;
|
|
511
536
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
537
|
+
// Counted block by block, each counted once while its text stays the same: a long reply's
|
|
538
|
+
// settled blocks cost nothing per frame.
|
|
539
|
+
const markdownBlocks = [...el.querySelectorAll(':scope > [data-slot="response-markdown"]')];
|
|
540
|
+
const lengths = markdownBlocks.map((block) => {
|
|
541
|
+
const text = block.textContent ?? "";
|
|
542
|
+
const known = blockLengths.get(block);
|
|
543
|
+
if (known && known.text === text)
|
|
544
|
+
return known.length;
|
|
545
|
+
const length = visibleLength(text);
|
|
546
|
+
blockLengths.set(block, { text, length });
|
|
547
|
+
return length;
|
|
548
|
+
});
|
|
549
|
+
const total = lengths.reduce((sum, length) => sum + length, 0);
|
|
516
550
|
const drawn = p.stamps.at(-1)?.count ?? p.settled;
|
|
517
551
|
// The first frame counted: what is there is already written.
|
|
518
552
|
if (p.settled < 0)
|
|
@@ -527,12 +561,18 @@ export function Response({ children, streaming = false, smooth = true, highlight
|
|
|
527
561
|
}
|
|
528
562
|
if (!p.stamps.length)
|
|
529
563
|
return;
|
|
530
|
-
|
|
564
|
+
// Only the blocks the new words are in.
|
|
565
|
+
const from = Math.max(p.settled, total - BLUR_CHARS);
|
|
566
|
+
let first = markdownBlocks.length;
|
|
567
|
+
for (let tail = 0; first > 0 && tail < total - from;)
|
|
568
|
+
tail += lengths[--first];
|
|
569
|
+
const nodes = markdownBlocks.slice(first).flatMap(textNodes);
|
|
570
|
+
words.current = wrapWords(nodes, total, from);
|
|
531
571
|
paint(performance.now());
|
|
532
572
|
run();
|
|
533
573
|
});
|
|
534
574
|
return (_jsx("div", { ref: root, "data-slot": "response", "data-streaming": live ? "" : undefined, "aria-busy": live || undefined, className: cn("min-w-0 text-[15px] leading-relaxed text-foreground-soft", className), ...props, children: blocks.map((block, index) => block.kind === "code" ? (_jsx(ResponseCode, { code: block.text, language: block.lang, highlight: highlight, className: "my-4 first:mt-0 last:mb-0" }, index)) : (_jsx("div", { "data-slot": "response-markdown", "data-table": block.table ? "" : undefined,
|
|
535
575
|
// A table is a block of its own that scrolls sideways when it is wider than the reply,
|
|
536
576
|
// so its cells never break inside a word. Focusable, so the keyboard can scroll it.
|
|
537
|
-
tabIndex: block.table ? 0 : undefined, className: block.table ? "focus-ring" : "contents", dangerouslySetInnerHTML: { __html: block.html } }, index))) }));
|
|
577
|
+
tabIndex: block.table ? 0 : undefined, className: block.table ? "focus-ring" : "contents", dangerouslySetInnerHTML: { __html: nameTaskBoxes(block.html, text) } }, index))) }));
|
|
538
578
|
}
|
|
@@ -16,7 +16,7 @@ export interface ScrollAreaProps extends BaseScrollArea.Root.Props {
|
|
|
16
16
|
/**
|
|
17
17
|
* Render the viewport as another part, so that part is the element that scrolls: a Select,
|
|
18
18
|
* Combobox or Autocomplete list, which scrolls its highlighted item into view itself. Give it
|
|
19
|
-
* `data-has-overflow-y:
|
|
19
|
+
* `data-has-overflow-y:pe-3` so its rows stop beside the bar instead of running under it.
|
|
20
20
|
*/
|
|
21
21
|
viewportRender?: BaseScrollArea.Viewport.Props["render"];
|
|
22
22
|
}
|
|
@@ -18,8 +18,19 @@ export function Select({ inputRef, ...props }) {
|
|
|
18
18
|
// A form's reset remounts it from its defaults (lib/form-reset); its hidden input finds the form.
|
|
19
19
|
const [resetKey, formRef] = useFormReset();
|
|
20
20
|
const refs = React.useMemo(() => mergeRefs(formRef, inputRef), [formRef, inputRef]);
|
|
21
|
+
const items = props.items;
|
|
22
|
+
const count = Array.isArray(items) ? items.length : items ? Object.keys(items).length : 0;
|
|
23
|
+
if (process.env.NODE_ENV !== "production" && count > MANY_OPTIONS && !warned) {
|
|
24
|
+
warned = true;
|
|
25
|
+
console.warn(`Select: ${count} options. A Select draws every option each time it opens, which takes most of ` +
|
|
26
|
+
"a second from about a thousand. Use a Combobox: people can type to narrow the list, and it " +
|
|
27
|
+
"draws only the options in view.");
|
|
28
|
+
}
|
|
21
29
|
return _jsx(BaseSelect.Root, { inputRef: refs, ...props }, resetKey);
|
|
22
30
|
}
|
|
31
|
+
/** Past this many options, development warns once (see Select). */
|
|
32
|
+
const MANY_OPTIONS = 500;
|
|
33
|
+
let warned = false;
|
|
23
34
|
const triggerSizes = {
|
|
24
35
|
sm: "min-h-(--control-h-sm) px-2.5 text-[13px]",
|
|
25
36
|
default: "min-h-(--control-h) ps-3.5 pe-2.5 text-[15px]",
|
|
@@ -28,7 +39,7 @@ export function SelectTrigger({ size = "default", className, children, ...props
|
|
|
28
39
|
return (_jsxs(BaseSelect.Trigger, { "data-slot": "select-trigger", "data-size": size, className: sx([
|
|
29
40
|
"group/trigger inline-flex w-full min-w-40 material-field cursor-pointer items-center justify-between gap-3 rounded-control font-body leading-none whitespace-nowrap outline-none select-none",
|
|
30
41
|
triggerSizes[size],
|
|
31
|
-
], className), ...props, children: [children, _jsx(BaseSelect.Icon, { className: "flex text-muted-foreground transition-colors group-hover/trigger:not-group-data-disabled/trigger:text-foreground", children: _jsx(ChevronsUpDownIcon, { className: "size-4" }) })] }));
|
|
42
|
+
], className), ...props, children: [children, _jsx(BaseSelect.Icon, { className: "flex text-muted-foreground transition-colors duration-(--duration) ease-(--ease) group-hover/trigger:not-group-data-disabled/trigger:text-foreground", children: _jsx(ChevronsUpDownIcon, { className: "size-4" }) })] }));
|
|
32
43
|
}
|
|
33
44
|
export function SelectValue({ className, ...props }) {
|
|
34
45
|
return (_jsx(BaseSelect.Value, { "data-slot": "select-value", className: sx(["truncate data-placeholder:text-control-muted"], className), ...props }));
|
|
@@ -39,11 +50,11 @@ export function SelectContent({ className, children, alignItemWithTrigger = fals
|
|
|
39
50
|
// As wide as the trigger, or wider for long options — up to 24rem (or the trigger, if
|
|
40
51
|
// wider) and never past the window, so the popup never spans the screen.
|
|
41
52
|
"relative max-w-[min(var(--available-width),max(var(--anchor-width),24rem))] min-w-(--anchor-width) popup-motion overflow-hidden rounded-button material-menu p-1 font-body outline-none",
|
|
42
|
-
], className), ...props, children: [_jsx(BaseSelect.ScrollUpArrow, { className: "
|
|
53
|
+
], className), ...props, children: [_jsx(BaseSelect.ScrollUpArrow, { className: "start-0 top-0 z-1 hidden h-6 w-full cursor-default items-center justify-center bg-control-menu text-muted-foreground data-[side=none]:flex", children: _jsx(ChevronUpIcon, { className: "size-3.5" }) }), _jsx(ScrollArea, { className: "h-full max-h-[calc(var(--available-height)-0.625rem)] in-data-[side=none]:max-h-none", viewportRender: _jsx(BaseSelect.List, { "data-slot": "select-list", role: "listbox", className: "scroll-py-1 data-has-overflow-y:pe-3" }), children: children }), _jsx(BaseSelect.ScrollDownArrow, { className: "start-0 bottom-0 z-1 hidden h-6 w-full cursor-default items-center justify-center bg-control-menu text-muted-foreground data-[side=none]:flex", children: _jsx(ChevronDownIcon, { className: "size-3.5" }) })] }) }) }));
|
|
43
54
|
}
|
|
44
55
|
export function SelectItem({ className, children, ...props }) {
|
|
45
56
|
return (_jsxs(BaseSelect.Item, { "data-slot": "select-item", className: sx([
|
|
46
|
-
"grid min-h-(--control-h) cursor-pointer grid-cols-[1fr_1rem] items-center gap-3 rounded-item border border-transparent
|
|
57
|
+
"grid min-h-(--control-h) cursor-pointer grid-cols-[1fr_1rem] items-center gap-3 rounded-item border border-transparent px-2.5 py-[clamp(0px,calc((var(--control-h)-22px)/2),6px)] text-sm text-foreground-soft outline-none select-none",
|
|
47
58
|
"data-highlighted:border-control-inner-edge data-highlighted:bg-control-hover data-highlighted:text-foreground data-highlighted:shadow-highlight",
|
|
48
59
|
"data-disabled:pointer-events-none data-disabled:opacity-50 data-selected:text-foreground",
|
|
49
60
|
], className), ...props, children: [_jsx(BaseSelect.ItemText, { className: "col-start-1 line-clamp-2 [overflow-wrap:anywhere]", children: children }), _jsx(BaseSelect.ItemIndicator, { className: "col-start-2 flex", children: _jsx(CheckIcon, { className: "size-4" }) })] }));
|
|
@@ -11,7 +11,7 @@ import { sx } from "../lib/cn.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export function Separator({ orientation = "horizontal", label, className, ...props }) {
|
|
13
13
|
if (label != null && orientation === "horizontal") {
|
|
14
|
-
return (_jsx(BaseSeparator, { "data-slot": "separator", "data-labelled": "", orientation: orientation, className: sx("flex w-full items-center gap-4 eyebrow text-[11px] before:h-px before:flex-1 before:bg-border/60 before:content-[''] after:h-px after:flex-1 after:bg-border/60 after:content-['']", className), ...props, children: _jsx("span", { className: "shrink-0", children: label }) }));
|
|
14
|
+
return (_jsx(BaseSeparator, { "data-slot": "separator", "data-labelled": "", "aria-label": typeof label === "string" ? label : undefined, orientation: orientation, className: sx("flex w-full items-center gap-4 eyebrow text-[11px] before:h-px before:flex-1 before:bg-border/60 before:content-[''] after:h-px after:flex-1 after:bg-border/60 after:content-['']", className), ...props, children: _jsx("span", { className: "shrink-0", children: label }) }));
|
|
15
15
|
}
|
|
16
16
|
return (_jsx(BaseSeparator, { "data-slot": "separator", orientation: orientation, className: sx("shrink-0 bg-border/60 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:min-h-4 data-[orientation=vertical]:w-px data-[orientation=vertical]:self-stretch", className), ...props }));
|
|
17
17
|
}
|
|
@@ -3,6 +3,17 @@ import * as React from "react";
|
|
|
3
3
|
import { type ButtonProps } from "./button.js";
|
|
4
4
|
import { type ScrollAreaProps } from "./scroll-area.js";
|
|
5
5
|
import { type SeparatorProps } from "./separator.js";
|
|
6
|
+
export interface SidebarMessages {
|
|
7
|
+
/** The mobile sheet's title, when the sidebar has no `aria-label`. */
|
|
8
|
+
navigation: string;
|
|
9
|
+
/** SidebarTrigger's and SidebarRail's name. */
|
|
10
|
+
toggle: string;
|
|
11
|
+
}
|
|
12
|
+
declare module "./locale" {
|
|
13
|
+
interface Messages {
|
|
14
|
+
sidebar: SidebarMessages;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
6
17
|
/**
|
|
7
18
|
* How the sidebar collapses on desktop. `offcanvas` slides it away entirely, `icon` shrinks it to
|
|
8
19
|
* a rail of 38px icon squares with tooltips, `none` keeps it open. On mobile, `offcanvas` and
|
|
@@ -75,13 +86,18 @@ export interface SidebarProps extends React.ComponentProps<"nav"> {
|
|
|
75
86
|
* button in the header) take the 30px height too.
|
|
76
87
|
*/
|
|
77
88
|
size?: "default" | "sm";
|
|
89
|
+
/**
|
|
90
|
+
* What hovering a row does: `text` (default) only brightens its label; `glide` also lays one
|
|
91
|
+
* soft fill under it that follows the pointer from row to row.
|
|
92
|
+
*/
|
|
93
|
+
hover?: "text" | "glide";
|
|
78
94
|
}
|
|
79
95
|
/**
|
|
80
96
|
* Sidebar — section navigation for docs, settings and dashboards.
|
|
81
97
|
*
|
|
82
98
|
* A `<nav>` of `SidebarGroup`s, each with an eyebrow `SidebarGroupLabel` and 38px
|
|
83
|
-
* `SidebarItem` rows at 12px radius. Rows are flat at rest,
|
|
84
|
-
*
|
|
99
|
+
* `SidebarItem` rows at 12px radius. Rows are flat at rest, only their label brightens on hover
|
|
100
|
+
* (`hover="glide"` adds one soft fill that follows the pointer), and take the raised material when current. The rule people break: marking the current page with a flat fill or
|
|
85
101
|
* a bold weight. Set `current` (it writes `aria-current="page"`) and let the material show it.
|
|
86
102
|
* A sidebar never shows a scrollbar: a long one goes in `<ScrollArea scrollbar={false}>`.
|
|
87
103
|
*
|
|
@@ -89,7 +105,7 @@ export interface SidebarProps extends React.ComponentProps<"nav"> {
|
|
|
89
105
|
* the page by a hairline, holding `SidebarHeader`, `SidebarContent` and `SidebarFooter`. It
|
|
90
106
|
* collapses on desktop and turns into a sheet on mobile.
|
|
91
107
|
*/
|
|
92
|
-
export declare function Sidebar({ side, variant, size, className, children, ...props }: SidebarProps): React.JSX.Element;
|
|
108
|
+
export declare function Sidebar({ side, variant, size, hover, className, children, ...props }: SidebarProps): React.JSX.Element;
|
|
93
109
|
/** The top of an app-shell sidebar: a logo, a workspace switcher, a search row. Never scrolls. */
|
|
94
110
|
export declare function SidebarHeader({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
95
111
|
/** The bottom of an app-shell sidebar: the account, settings, help. Never scrolls. */
|
|
@@ -123,7 +139,7 @@ export interface SidebarItemProps extends useRender.ComponentProps<"a"> {
|
|
|
123
139
|
/**
|
|
124
140
|
* One navigation row. Renders an `<a>`; pass `render={<Link to="…" />}` for router links.
|
|
125
141
|
* Leading icons are 16px; a trailing `Kbd`, `Tag` or `SidebarMenuBadge` is pushed to the end
|
|
126
|
-
* with `
|
|
142
|
+
* with `ms-auto`. In an icon-collapsed app shell it shrinks to a 38px square with a tooltip.
|
|
127
143
|
*/
|
|
128
144
|
export declare function SidebarItem({ current, tooltip, render, ref, className, children, onClick, ...props }: SidebarItemProps): React.JSX.Element;
|
|
129
145
|
/** A count at the end of a row ("12"): mono, tabular, muted. Hidden in the icon rail. */
|