@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
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useDirection } from "@base-ui/react/direction-provider";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { Field as BaseField } from "@base-ui/react/field";
|
|
5
4
|
import { CircleAlertIcon, XIcon } from "lucide-react";
|
|
6
5
|
import * as React from "react";
|
|
7
6
|
import { cn } from "../lib/cn.js";
|
|
8
7
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { useMessages } from "./locale.js";
|
|
9
9
|
/* The field and chips are ComboboxChips' own: the same group, the same raised 30px chips with 7px
|
|
10
10
|
corners and a round remove button, so a multiple Combobox and a TagsInput read as one family. */
|
|
11
11
|
const groupSizes = {
|
|
12
12
|
sm: "min-h-(--control-h-sm) p-0.5",
|
|
13
13
|
default: "min-h-(--control-h) p-[3px]",
|
|
14
14
|
};
|
|
15
|
+
// `leading-none` after the text size, which would drop it: a chip as small as a compact theme's
|
|
16
|
+
// dense field has no room for a line box.
|
|
15
17
|
const chipSizes = {
|
|
16
|
-
sm: "min-h-(--control-inset-sm) pe-0.5 ps-2 text-xs",
|
|
17
|
-
default: "min-h-(--control-h-sm) pe-[3px] ps-2.5 text-[13px]",
|
|
18
|
+
sm: "min-h-(--control-inset-sm) pe-0.5 ps-2 text-xs leading-none",
|
|
19
|
+
default: "min-h-(--control-h-sm) pe-[3px] ps-2.5 text-[13px] leading-none",
|
|
18
20
|
};
|
|
19
21
|
const removeSizes = {
|
|
20
|
-
sm: "size-[18px] [&_svg]:size-3",
|
|
22
|
+
sm: "size-[min(18px,calc(var(--control-inset-sm)-2px))] [&_svg]:size-3",
|
|
21
23
|
default: "size-(--control-inset-sm) [&_svg]:size-3.5",
|
|
22
24
|
};
|
|
23
25
|
const inputSizes = {
|
|
24
|
-
sm: "min-h-(--control-inset-sm) text-[13px]",
|
|
26
|
+
sm: "min-h-(--control-inset-sm) text-[13px] pointer-coarse:text-base",
|
|
25
27
|
default: "min-h-(--control-h-sm) text-base sm:text-[15px]",
|
|
26
28
|
};
|
|
29
|
+
const defaultMessages = {
|
|
30
|
+
remove: (tag) => `Remove ${tag}`,
|
|
31
|
+
invalid: "(invalid)",
|
|
32
|
+
};
|
|
27
33
|
/** Split typed or pasted text into tags: commas, semicolons, tabs and new lines. */
|
|
28
34
|
const splitTags = (text) => text
|
|
29
35
|
.split(/[,;\t\n]+/)
|
|
@@ -39,7 +45,8 @@ const splitTags = (text) => text
|
|
|
39
45
|
* (letter case aside). Pass `validate` to mark the tags that don't fit, and say why under the
|
|
40
46
|
* field. The rule people break: colouring tags by kind — they are raised secondary surfaces.
|
|
41
47
|
*/
|
|
42
|
-
export function TagsInput({ value: valueProp, defaultValue, onValueChange, size = "default", validate, max, name, removeLabel
|
|
48
|
+
export function TagsInput({ value: valueProp, defaultValue, onValueChange, size = "default", validate, max, name, removeLabel, labels, className, placeholder, disabled, readOnly, required, id, ref, onKeyDown, onPaste, onFocus, onBlur, ...props }) {
|
|
49
|
+
const messages = useMessages("tagsInput", defaultMessages, labels);
|
|
43
50
|
const [valueState, setValueState] = React.useState(defaultValue ?? []);
|
|
44
51
|
const tags = valueProp ?? valueState;
|
|
45
52
|
const [text, setText] = React.useState("");
|
|
@@ -52,16 +59,20 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
52
59
|
// Disabled by the prop or by a disabled Field, which Base UI sets on the input.
|
|
53
60
|
const locked = () => !!input.current?.disabled || !!readOnly;
|
|
54
61
|
// The chips run before the input: to its left, or to its right in a right-to-left page.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
62
|
+
// The chips run the way the field is laid out — a DirectionProvider, or only dir="rtl" on the
|
|
63
|
+
// page — so the arrows are read from the element's own direction when pressed, as Tree does.
|
|
64
|
+
const arrows = (el) => getComputedStyle(el).direction === "rtl"
|
|
65
|
+
? { towardChips: "ArrowRight", awayFromChips: "ArrowLeft" }
|
|
66
|
+
: { towardChips: "ArrowLeft", awayFromChips: "ArrowRight" };
|
|
58
67
|
// Tags are unique, but a value passed in may repeat one: a repeat gets a key of its own.
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const keys = React.useMemo(() => {
|
|
69
|
+
const counts = new Map();
|
|
70
|
+
return tags.map((tag) => {
|
|
71
|
+
const n = counts.get(tag) ?? 0;
|
|
72
|
+
counts.set(tag, n + 1);
|
|
73
|
+
return n ? `${tag}\u0000${n}` : tag;
|
|
74
|
+
});
|
|
75
|
+
}, [tags]);
|
|
65
76
|
/* A form's reset puts back the tags it started with, as it does a native input's text. */
|
|
66
77
|
const initial = React.useRef(defaultValue);
|
|
67
78
|
initial.current = defaultValue;
|
|
@@ -147,7 +158,9 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
147
158
|
else if (event.key === ",") {
|
|
148
159
|
event.preventDefault();
|
|
149
160
|
}
|
|
150
|
-
else if (
|
|
161
|
+
else if (
|
|
162
|
+
// Backspace only from an empty input, so it never jumps away while editing the text's start.
|
|
163
|
+
((event.key === "Backspace" && text === "") || event.key === arrows(el).towardChips) &&
|
|
151
164
|
el.selectionStart === 0 &&
|
|
152
165
|
el.selectionEnd === 0 &&
|
|
153
166
|
tags.length > 0) {
|
|
@@ -155,10 +168,24 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
155
168
|
chips.current[tags.length - 1]?.focus();
|
|
156
169
|
}
|
|
157
170
|
};
|
|
171
|
+
// The chips' handlers, current at each render, for the chips that are not drawn again.
|
|
172
|
+
const actions = React.useRef({
|
|
173
|
+
keyDown: (_index, _event) => { },
|
|
174
|
+
remove: (_index) => { },
|
|
175
|
+
});
|
|
176
|
+
React.useLayoutEffect(() => {
|
|
177
|
+
actions.current.keyDown = (index, event) => handleChipKeyDown(index)(event);
|
|
178
|
+
actions.current.remove = (index) => {
|
|
179
|
+
if (locked())
|
|
180
|
+
return;
|
|
181
|
+
remove(index, "input");
|
|
182
|
+
};
|
|
183
|
+
});
|
|
158
184
|
const handleChipKeyDown = (index) => (event) => {
|
|
159
185
|
if (event.target !== event.currentTarget)
|
|
160
186
|
return;
|
|
161
187
|
const { key } = event;
|
|
188
|
+
const { towardChips, awayFromChips } = arrows(event.currentTarget);
|
|
162
189
|
if (key === towardChips) {
|
|
163
190
|
event.preventDefault();
|
|
164
191
|
chips.current[Math.max(0, index - 1)]?.focus();
|
|
@@ -198,7 +225,7 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
198
225
|
// validity; a native form gets one hidden input per tag under the name, ours or the Field's.
|
|
199
226
|
render: (control) => {
|
|
200
227
|
const { ref: fieldRef, id: controlId, name: formName, value: formValue, disabled: off, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, onKeyDown: _onKeyDown, className: _className, defaultValue: _defaultValue, autoFocus: _autoFocus, "aria-invalid": fieldInvalid, ...field } = control;
|
|
201
|
-
return (_jsxs("div", { "data-slot": "tags-input", "data-size": size, "data-readonly": readOnly ? "" : undefined, "data-full": full ? "" : undefined, className: cn("group/tags-input flex w-full material-field cursor-text items-center rounded-control font-body", groupSizes[size], "has-[[data-slot=tags-input-input][aria-invalid=true]]:border-destructive has-[[data-slot=tags-input-input][aria-invalid=true]]:shadow-invalid", "
|
|
228
|
+
return (_jsxs("div", { "data-slot": "tags-input", "data-size": size, "data-readonly": readOnly ? "" : undefined, "data-full": full ? "" : undefined, "data-disabled": off ? "" : undefined, className: cn("group/tags-input flex w-full material-field cursor-text items-center rounded-control font-body", groupSizes[size], "has-[[data-slot=tags-input-input][aria-invalid=true]]:border-destructive has-[[data-slot=tags-input-input][aria-invalid=true]]:shadow-invalid", "data-disabled:cursor-not-allowed data-disabled:opacity-55", className), onMouseDown: (event) => {
|
|
202
229
|
// A press on the field's empty space puts the caret in the input, as on a text field.
|
|
203
230
|
if (event.target.closest("input, button, [data-slot=tags-input-chip]"))
|
|
204
231
|
return;
|
|
@@ -213,22 +240,7 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
213
240
|
fieldBlur?.({
|
|
214
241
|
currentTarget: fieldInput.current,
|
|
215
242
|
});
|
|
216
|
-
}, children: [_jsxs("div", { "data-slot": "tags-input-chips", role: tags.length > 0 ? "toolbar" : undefined, className: "flex w-full flex-wrap items-center gap-[3px]", children: [tags.
|
|
217
|
-
const invalid = validate ? !validate(tag) : false;
|
|
218
|
-
return (_jsxs("div", { ref: (el) => {
|
|
219
|
-
chips.current[index] = el;
|
|
220
|
-
}, "data-slot": "tags-input-chip", "data-invalid": invalid ? "" : undefined, "data-repeat": repeat === tag ? "" : undefined, tabIndex: -1, onKeyDown: handleChipKeyDown(index), className: cn("inline-flex max-w-full cursor-default items-center gap-1 rounded-item border border-transparent leading-none font-medium text-foreground", "bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-raised", "transition-[box-shadow,border-color,color] duration-(--duration) ease-(--ease)", "group-has-[[data-slot=tags-input-input]:disabled]/tags-input:pointer-events-none", chipSizes[size], readOnly && "pe-2.5 group-data-[size=sm]/tags-input:pe-2",
|
|
221
|
-
// Not valid: a 1px red edge, red ink and an alert icon, read out as "invalid".
|
|
222
|
-
"data-invalid:border-destructive/60 data-invalid:text-destructive",
|
|
223
|
-
// The tag that was typed again is marked with a current item's edge for a moment.
|
|
224
|
-
"data-repeat:shadow-raised-current"), children: [invalid && _jsx(CircleAlertIcon, { "aria-hidden": true, className: "size-3.5 shrink-0" }), _jsxs("span", { className: "truncate", children: [tag, invalid && _jsx("span", { className: "sr-only", children: " (invalid)" })] }), !readOnly && (_jsx("button", { type: "button", tabIndex: -1, "data-slot": "tags-input-chip-remove", "aria-label": removeLabel(tag),
|
|
225
|
-
// Keep focus where it is: a click removes the tag, then returns to the input.
|
|
226
|
-
onMouseDown: (event) => event.preventDefault(), onClick: () => {
|
|
227
|
-
if (locked())
|
|
228
|
-
return;
|
|
229
|
-
remove(index, "input");
|
|
230
|
-
}, className: cn("inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-[background-color,color] duration-(--duration) ease-brand hover:bg-control-hover hover:text-foreground", "group-has-[[data-slot=tags-input-input]:disabled]/tags-input:pointer-events-none", removeSizes[size]), children: _jsx(XIcon, {}) }))] }, keys[index]));
|
|
231
|
-
}), _jsx("input", { ...field, ...props, ref: refs, id: controlId, "data-slot": "tags-input-input", value: text, onChange: (event) => setText(event.currentTarget.value), onKeyDown: handleInputKeyDown, onPaste: handlePaste, onFocus: onFocus, onBlur: (event) => {
|
|
243
|
+
}, children: [_jsxs("div", { "data-slot": "tags-input-chips", role: tags.length > 0 ? "toolbar" : undefined, className: "flex w-full flex-wrap items-center gap-[3px]", children: [_jsx(TagChips, { tags: tags, keys: keys, repeat: repeat, size: size, readOnly: readOnly, validate: validate, removeLabel: removeLabel ?? messages.remove, invalidLabel: messages.invalid, chips: chips, actions: actions }), _jsx("input", { ...field, ...props, ref: refs, id: controlId, "data-slot": "tags-input-input", value: text, onChange: (event) => setText(event.currentTarget.value), onKeyDown: handleInputKeyDown, onPaste: handlePaste, onFocus: onFocus, onBlur: (event) => {
|
|
232
244
|
onBlur?.(event);
|
|
233
245
|
// What was typed and not yet added is added on leaving, so a submit never loses it.
|
|
234
246
|
if (text.trim() && !locked())
|
|
@@ -237,3 +249,23 @@ export function TagsInput({ value: valueProp, defaultValue, onValueChange, size
|
|
|
237
249
|
tags.map((tag, index) => (_jsx("input", { type: "hidden", name: formName, value: tag, form: props.form, disabled: off }, keys[index])))] }), _jsx("input", { ref: fieldRef, value: formValue ?? "", onChange: fieldChange, required: required, disabled: off, readOnly: readOnly, form: props.form, "aria-hidden": true, tabIndex: -1, autoComplete: "off", onFocus: () => input.current?.focus(), className: "sr-only" })] }));
|
|
238
250
|
} }));
|
|
239
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* The chips, drawn again only when the tags (or how they look) change — not at each key typed in
|
|
254
|
+
* the input, which with hundreds of tags would redraw them all.
|
|
255
|
+
*/
|
|
256
|
+
const TagChips = React.memo(function TagChips({ tags, keys, repeat, size, readOnly, validate, removeLabel, invalidLabel, chips, actions, }) {
|
|
257
|
+
return (_jsx(_Fragment, { children: tags.map((tag, index) => {
|
|
258
|
+
const invalid = validate ? !validate(tag) : false;
|
|
259
|
+
return (_jsxs("div", { ref: (el) => {
|
|
260
|
+
chips.current[index] = el;
|
|
261
|
+
}, "data-slot": "tags-input-chip", "data-invalid": invalid ? "" : undefined, "data-repeat": repeat === tag ? "" : undefined, tabIndex: -1, onKeyDown: (event) => actions.current.keyDown(index, event), className: cn("inline-flex max-w-full cursor-default items-center gap-1 rounded-item border border-transparent leading-none font-medium text-foreground", "bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-raised", "transition-[box-shadow,border-color,color] duration-(--duration) ease-(--ease)", "group-data-disabled/tags-input:pointer-events-none", chipSizes[size], readOnly && "pe-2.5 group-data-[size=sm]/tags-input:pe-2",
|
|
262
|
+
// Not valid: a 1px red edge, red ink and an alert icon, read out as "invalid".
|
|
263
|
+
"data-invalid:border-destructive/60 data-invalid:text-destructive",
|
|
264
|
+
// The tag that was typed again is marked with a current item's edge for a moment.
|
|
265
|
+
"data-repeat:shadow-raised-current"), children: [invalid && _jsx(CircleAlertIcon, { "aria-hidden": true, className: "size-3.5 shrink-0" }), _jsxs("span", { className: "truncate", children: [tag, invalid && _jsxs("span", { className: "sr-only", children: [" ", invalidLabel] })] }), !readOnly && (_jsx("button", { type: "button", tabIndex: -1, "data-slot": "tags-input-chip-remove", "aria-label": removeLabel(tag),
|
|
266
|
+
// Keep focus where it is: a click removes the tag, then returns to the input.
|
|
267
|
+
onMouseDown: (event) => event.preventDefault(), onClick: () => {
|
|
268
|
+
actions.current.remove(index);
|
|
269
|
+
}, className: cn("inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-[background-color,color] duration-(--duration) ease-brand hover:bg-control-hover hover:text-foreground", "group-data-disabled/tags-input:pointer-events-none", removeSizes[size]), children: _jsx(XIcon, {}) }))] }, keys[index]));
|
|
270
|
+
}) }));
|
|
271
|
+
});
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type ThemeMode } from "../lib/theme-script.js";
|
|
3
3
|
import { type ButtonProps } from "./button.js";
|
|
4
|
-
export
|
|
4
|
+
export interface ThemeMessages {
|
|
5
|
+
/** ThemeToggle's name. */
|
|
6
|
+
toggle: string;
|
|
7
|
+
}
|
|
8
|
+
declare module "./locale" {
|
|
9
|
+
interface Messages {
|
|
10
|
+
theme: ThemeMessages;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY, type ThemeMode, } from "../lib/theme-script.js";
|
|
5
14
|
export type ResolvedTheme = "light" | "dark";
|
|
6
15
|
export interface ThemeContextValue {
|
|
7
16
|
/** The stored preference: `light`, `dark` or `system`. */
|
|
@@ -16,6 +25,11 @@ export interface ThemeProviderProps {
|
|
|
16
25
|
defaultTheme?: ThemeMode;
|
|
17
26
|
/** localStorage key. Default `zon-theme`. */
|
|
18
27
|
storageKey?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Keep `<meta name="theme-color">` at the theme's page tone (`PAGE_TONE`), so a phone's
|
|
30
|
+
* status bar and toolbar match the page. Default `true`; pass the same to `createThemeScript`.
|
|
31
|
+
*/
|
|
32
|
+
themeColor?: boolean;
|
|
19
33
|
}
|
|
20
34
|
/**
|
|
21
35
|
* ThemeProvider — light, dark or system theme for the whole document. It toggles `.dark` on
|
|
@@ -26,7 +40,7 @@ export interface ThemeProviderProps {
|
|
|
26
40
|
* already correct. The rule people break: forgetting the script, which flashes light
|
|
27
41
|
* before React hydrates.
|
|
28
42
|
*/
|
|
29
|
-
export declare function ThemeProvider({ children, defaultTheme, storageKey, }: ThemeProviderProps): import("react").JSX.Element;
|
|
43
|
+
export declare function ThemeProvider({ children, defaultTheme, storageKey, themeColor, }: ThemeProviderProps): import("react").JSX.Element;
|
|
30
44
|
/** Read and change the theme. Must be used inside `ThemeProvider`. */
|
|
31
45
|
export declare function useTheme(): ThemeContextValue;
|
|
32
46
|
export interface ThemeToggleProps extends Omit<ButtonProps, "children" | "variant" | "size"> {
|
package/dist/components/theme.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { MoonIcon, SunIcon } from "lucide-react";
|
|
4
4
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
5
|
-
import { DARK_QUERY, THEME_STORAGE_KEY } from "../lib/theme-script.js";
|
|
5
|
+
import { DARK_QUERY, setThemeColor, THEME_STORAGE_KEY } from "../lib/theme-script.js";
|
|
6
6
|
import { Button } from "./button.js";
|
|
7
|
-
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
8
|
+
const defaultMessages = { toggle: "Toggle light and dark theme" };
|
|
9
|
+
export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY, } from "../lib/theme-script.js";
|
|
8
10
|
const ThemeContext = createContext(null);
|
|
9
11
|
const isMode = (v) => v === "light" || v === "dark" || v === "system";
|
|
10
12
|
function readStored(key) {
|
|
@@ -41,7 +43,7 @@ function systemDark() {
|
|
|
41
43
|
* already correct. The rule people break: forgetting the script, which flashes light
|
|
42
44
|
* before React hydrates.
|
|
43
45
|
*/
|
|
44
|
-
export function ThemeProvider({ children, defaultTheme = "system", storageKey = THEME_STORAGE_KEY, }) {
|
|
46
|
+
export function ThemeProvider({ children, defaultTheme = "system", storageKey = THEME_STORAGE_KEY, themeColor = true, }) {
|
|
45
47
|
const [theme, setThemeState] = useState(defaultTheme);
|
|
46
48
|
const [prefersDark, setPrefersDark] = useState(false);
|
|
47
49
|
const [mounted, setMounted] = useState(false);
|
|
@@ -76,18 +78,41 @@ export function ThemeProvider({ children, defaultTheme = "system", storageKey =
|
|
|
76
78
|
useEffect(() => {
|
|
77
79
|
if (!mounted)
|
|
78
80
|
return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
applyDark(resolvedTheme === "dark");
|
|
82
|
+
if (themeColor)
|
|
83
|
+
setThemeColor(resolvedTheme === "dark");
|
|
84
|
+
}, [mounted, resolvedTheme, themeColor]);
|
|
81
85
|
const setTheme = useCallback((next) => {
|
|
82
86
|
setThemeState(next);
|
|
83
87
|
writeStored(storageKey, next);
|
|
84
88
|
// Applied at once too: the effect above runs only when the resolved theme changes, and
|
|
85
89
|
// something outside this provider may have changed the class since.
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
const dark = next === "dark" || (next === "system" && systemDark());
|
|
91
|
+
applyDark(dark);
|
|
92
|
+
if (themeColor)
|
|
93
|
+
setThemeColor(dark);
|
|
94
|
+
}, [storageKey, themeColor]);
|
|
88
95
|
const value = useMemo(() => ({ theme, resolvedTheme, setTheme }), [theme, resolvedTheme, setTheme]);
|
|
89
96
|
return _jsx(ThemeContext.Provider, { value: value, children: children });
|
|
90
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Flip `.dark` on <html> in one frame. The page's colours change at once, but every material
|
|
100
|
+
* transitions its background and shadows over `--duration`, so for a moment half the page would
|
|
101
|
+
* show each theme. Transitions are off for the flip — a style read commits it — and come back on
|
|
102
|
+
* the next frame, before anything else moves.
|
|
103
|
+
*/
|
|
104
|
+
function applyDark(dark) {
|
|
105
|
+
const root = document.documentElement;
|
|
106
|
+
if (root.classList.contains("dark") === dark)
|
|
107
|
+
return;
|
|
108
|
+
const style = document.createElement("style");
|
|
109
|
+
style.textContent = "*,*::before,*::after{transition:none!important}";
|
|
110
|
+
document.head.appendChild(style);
|
|
111
|
+
root.classList.toggle("dark", dark);
|
|
112
|
+
// Read a style so the browser applies the new theme while transitions are off.
|
|
113
|
+
void getComputedStyle(root).colorScheme;
|
|
114
|
+
requestAnimationFrame(() => style.remove());
|
|
115
|
+
}
|
|
91
116
|
/** Read and change the theme. Must be used inside `ThemeProvider`. */
|
|
92
117
|
export function useTheme() {
|
|
93
118
|
const ctx = useContext(ThemeContext);
|
|
@@ -104,7 +129,8 @@ export function useTheme() {
|
|
|
104
129
|
*/
|
|
105
130
|
export function ThemeToggle({ onClick, ...props }) {
|
|
106
131
|
const { setTheme } = useTheme();
|
|
107
|
-
|
|
132
|
+
const text = useMessages("theme", defaultMessages);
|
|
133
|
+
return (_jsxs(Button, { "data-slot": "theme-toggle", type: "button", variant: "secondary", size: "icon", "aria-label": text.toggle, ...props, onClick: (e) => {
|
|
108
134
|
onClick?.(e);
|
|
109
135
|
// Read the applied class rather than state: it is correct even before hydration.
|
|
110
136
|
setTheme(document.documentElement.classList.contains("dark") ? "light" : "dark");
|
|
@@ -14,7 +14,7 @@ export interface TimeFieldProps extends Omit<React.ComponentProps<"div">, "defau
|
|
|
14
14
|
size?: keyof typeof groupSizes;
|
|
15
15
|
/** `12` adds an AM/PM segment, `24` leaves it out. Default: the locale's own clock. */
|
|
16
16
|
hourCycle?: 12 | 24;
|
|
17
|
-
/** A BCP 47 locale for the clock, the separator and the AM/PM labels. Default: the browser's. */
|
|
17
|
+
/** A BCP 47 locale for the clock, the separator and the AM/PM labels. Default: the LocaleProvider's, else the browser's. */
|
|
18
18
|
locale?: string;
|
|
19
19
|
/** Show a seconds segment. Default: when the initial value has seconds. */
|
|
20
20
|
seconds?: boolean;
|
|
@@ -34,18 +34,38 @@ export interface TimeFieldProps extends Omit<React.ComponentProps<"div">, "defau
|
|
|
34
34
|
readOnly?: boolean;
|
|
35
35
|
/** The clock icon at the end of the field. */
|
|
36
36
|
icon?: boolean;
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Names for each segment, read out with the field's label.
|
|
39
|
+
* @deprecated Use `labels`, which takes the same keys.
|
|
40
|
+
*/
|
|
38
41
|
segmentLabels?: Partial<Record<SegmentType, string>>;
|
|
42
|
+
/** Names for each segment and the empty one's value; a LocaleProvider sets them for every TimeField. */
|
|
43
|
+
labels?: Partial<TimeFieldMessages>;
|
|
44
|
+
/**
|
|
45
|
+
* The field's hidden input, which holds the value; focused, it puts the caret in the first empty
|
|
46
|
+
* segment. Hand it a form library's ref (React Hook Form's `field.ref`) so it can focus the field.
|
|
47
|
+
*/
|
|
48
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
49
|
+
}
|
|
50
|
+
/** Each segment's name, read out with the field's label, and what an empty segment reads. */
|
|
51
|
+
export interface TimeFieldMessages extends Record<SegmentType, string> {
|
|
52
|
+
empty: string;
|
|
53
|
+
}
|
|
54
|
+
declare module "./locale" {
|
|
55
|
+
interface Messages {
|
|
56
|
+
timeField: TimeFieldMessages;
|
|
57
|
+
}
|
|
39
58
|
}
|
|
40
59
|
/**
|
|
41
60
|
* TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
|
|
42
61
|
* mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
|
|
43
62
|
*
|
|
44
|
-
* Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField
|
|
63
|
+
* Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField;
|
|
64
|
+
* a held key counts in place rather than restarting the roll on every repeat),
|
|
45
65
|
* typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
|
|
46
66
|
* string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
|
|
47
67
|
* departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
|
|
48
68
|
* of 96 quarter hours. Set `step={15}` instead, and let people type.
|
|
49
69
|
*/
|
|
50
|
-
export declare function TimeField({ value: valueProp, defaultValue, onValueChange, size, hourCycle, locale, seconds: secondsProp, step, min, max, name, required, disabled: disabledProp, readOnly, icon, segmentLabels, id: idProp, className, onBlur, onMouseDown, onPaste, ...props }: TimeFieldProps): React.JSX.Element;
|
|
70
|
+
export declare function TimeField({ value: valueProp, defaultValue, onValueChange, size, hourCycle, locale: localeProp, seconds: secondsProp, step, min, max, name, required, disabled: disabledProp, readOnly, icon, segmentLabels, labels: labelsProp, id: idProp, className, onBlur, onMouseDown, onPaste, inputRef, ...props }: TimeFieldProps): React.JSX.Element;
|
|
51
71
|
export {};
|
|
@@ -4,7 +4,9 @@ import { Field as BaseField } from "@base-ui/react/field";
|
|
|
4
4
|
import { ClockIcon } from "lucide-react";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { cssDuration } from "../lib/motion.js";
|
|
7
8
|
import { DigitRoll, reducedMotion } from "../lib/digit-roll.js";
|
|
9
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
8
10
|
const groupSizes = {
|
|
9
11
|
sm: "min-h-(--control-h-sm) gap-2 pe-2.5 ps-2 text-[13px] [&>svg]:size-3.5",
|
|
10
12
|
default: "min-h-(--control-h) gap-3 pe-3 ps-3 text-base sm:text-[15px] [&>svg]:size-4",
|
|
@@ -21,11 +23,12 @@ const latin = (text) => text
|
|
|
21
23
|
return String(code - DIGIT_ZEROS.find((zero) => code >= zero && code <= zero + 9));
|
|
22
24
|
});
|
|
23
25
|
const noSubscribe = () => () => { };
|
|
24
|
-
const
|
|
26
|
+
const defaultMessages = {
|
|
25
27
|
hour: "Hours",
|
|
26
28
|
minute: "Minutes",
|
|
27
29
|
second: "Seconds",
|
|
28
30
|
dayPeriod: "AM/PM",
|
|
31
|
+
empty: "Empty",
|
|
29
32
|
};
|
|
30
33
|
function parse(value, h12) {
|
|
31
34
|
const m = value ? /^(\d{1,2}):(\d{2})(?::(\d{2}))?/.exec(value) : null;
|
|
@@ -91,13 +94,16 @@ function useClock(locale, hourCycle, seconds) {
|
|
|
91
94
|
* TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
|
|
92
95
|
* mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
|
|
93
96
|
*
|
|
94
|
-
* Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField
|
|
97
|
+
* Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField;
|
|
98
|
+
* a held key counts in place rather than restarting the roll on every repeat),
|
|
95
99
|
* typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
|
|
96
100
|
* string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
|
|
97
101
|
* departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
|
|
98
102
|
* of 96 quarter hours. Set `step={15}` instead, and let people type.
|
|
99
103
|
*/
|
|
100
|
-
export function TimeField({ value: valueProp, defaultValue, onValueChange, size = "default", hourCycle, locale, seconds: secondsProp, step = 1, min, max, name, required = false, disabled: disabledProp = false, readOnly = false, icon = true, segmentLabels, id: idProp, className, onBlur, onMouseDown, onPaste, ...props }) {
|
|
104
|
+
export function TimeField({ value: valueProp, defaultValue, onValueChange, size = "default", hourCycle, locale: localeProp, seconds: secondsProp, step = 1, min, max, name, required = false, disabled: disabledProp = false, readOnly = false, icon = true, segmentLabels, labels: labelsProp, id: idProp, className, onBlur, onMouseDown, onPaste, inputRef, ...props }) {
|
|
105
|
+
const providedLocale = useLocale();
|
|
106
|
+
const locale = localeProp ?? providedLocale;
|
|
101
107
|
const initial = valueProp !== undefined ? valueProp : defaultValue;
|
|
102
108
|
// Decided by the first value: the seconds don't go when a segment is cleared and the value is null.
|
|
103
109
|
const [initialSeconds] = React.useState(() => /^\d{1,2}:\d{2}:\d{2}/.test(initial ?? ""));
|
|
@@ -107,7 +113,8 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
107
113
|
const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false);
|
|
108
114
|
const clock = useClock(locale ?? (hydrated ? undefined : "en-US"), hourCycle, seconds);
|
|
109
115
|
const { h12 } = clock;
|
|
110
|
-
const
|
|
116
|
+
const messages = useMessages("timeField", defaultMessages, labelsProp);
|
|
117
|
+
const labels = { ...messages, ...segmentLabels };
|
|
111
118
|
const generatedId = React.useId();
|
|
112
119
|
const id = idProp ?? generatedId;
|
|
113
120
|
const [segs, setSegs] = React.useState(() => parse(initial, h12));
|
|
@@ -150,6 +157,7 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
150
157
|
};
|
|
151
158
|
/* The digit roll: a step remembers the segment's text before and after, and which way it went. */
|
|
152
159
|
const [rolls, setRolls] = React.useState({});
|
|
160
|
+
const lastStep = React.useRef(-Infinity);
|
|
153
161
|
const endRoll = React.useMemo(() => {
|
|
154
162
|
const end = (type) => () => setRolls((r) => ({ ...r, [type]: undefined }));
|
|
155
163
|
return { hour: end("hour"), minute: end("minute"), second: end("second"), dayPeriod: end("dayPeriod") };
|
|
@@ -178,8 +186,15 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
178
186
|
}
|
|
179
187
|
const from = rolls[type]?.to ?? display(type, s);
|
|
180
188
|
const to = display(type, next);
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
// A held key repeats faster than a roll lasts, and a roll that restarts on every repeat never
|
|
190
|
+
// lands: a step that close to the last one shows its value in place, and the running roll gives way.
|
|
191
|
+
const now = performance.now();
|
|
192
|
+
const repeat = now - lastStep.current < cssDuration();
|
|
193
|
+
lastStep.current = now;
|
|
194
|
+
if (repeat)
|
|
195
|
+
setRolls((r) => ({ ...r, [type]: undefined }));
|
|
196
|
+
else if (from !== to && !from.includes("–") && !reducedMotion())
|
|
197
|
+
setRolls((r) => ({ ...r, [type]: { from, to, dir, key: now } }));
|
|
183
198
|
update(next);
|
|
184
199
|
};
|
|
185
200
|
const setSegment = (type, n) => {
|
|
@@ -340,6 +355,7 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
340
355
|
};
|
|
341
356
|
/** The Field's input: it holds the value the Field validates. */
|
|
342
357
|
const fieldInput = React.useRef(null);
|
|
358
|
+
React.useImperativeHandle(inputRef, () => fieldInput.current, []);
|
|
343
359
|
/*
|
|
344
360
|
* Leaving the field: a finished time outside min / max is brought back inside, as NumberField does.
|
|
345
361
|
* Then the Field hears the blur — the group's, not a segment's — with the value from its input.
|
|
@@ -415,10 +431,10 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
415
431
|
const groupLabel = labelledBy ?? (props["aria-label"] || props["aria-labelledby"] ? controlId : undefined);
|
|
416
432
|
return (_jsxs("div", { role: "group", "data-slot": "time-field", "data-size": size, "data-readonly": readOnly ? "" : undefined, "data-disabled": off ? "" : undefined, "aria-disabled": off || undefined, ...state, ...props, id: controlId, "aria-labelledby": labelledBy ?? props["aria-labelledby"], "aria-describedby": describedBy, className: cn("group/time-field flex w-full min-w-0 material-field cursor-text items-center rounded-control font-mono text-foreground tabular-nums",
|
|
417
433
|
// A focused segment gives the field the softer edge of a focused text field.
|
|
418
|
-
"not-data-invalid:has-[[data-slot=time-field-segment]:focus]:border-[color-mix(in_oklab,var(--field-edge),var(--control-focus))]", "[&>svg]:shrink-0 [&>svg]:text-muted-foreground", groupSizes[size], className), onMouseDown: handleMouseDown, onPaste: handlePaste, onFocus: (event) => {
|
|
434
|
+
"not-data-invalid:has-[[data-slot=time-field-segment]:focus]:border-[color-mix(in_oklab,var(--field-edge),var(--control-focus))]", "[&>svg]:ms-auto [&>svg]:shrink-0 [&>svg]:text-muted-foreground", groupSizes[size], className), onMouseDown: handleMouseDown, onPaste: handlePaste, onFocus: (event) => {
|
|
419
435
|
props.onFocus?.(event);
|
|
420
436
|
fieldFocus?.(event);
|
|
421
|
-
}, onBlur: (event) => handleBlur(event, fieldBlur), children: [_jsx("span", { dir: "ltr", className: "flex min-w-0
|
|
437
|
+
}, onBlur: (event) => handleBlur(event, fieldBlur), children: [_jsx("span", { dir: "ltr", className: "flex min-w-0 items-center", children: order.map((type, i) => {
|
|
422
438
|
const prev = order[i - 1];
|
|
423
439
|
const gap = prev && (type === "dayPeriod" || prev === "dayPeriod");
|
|
424
440
|
const s = segs;
|
|
@@ -426,7 +442,14 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
|
|
|
426
442
|
const text = display(type, s);
|
|
427
443
|
const roll = rolls[type];
|
|
428
444
|
const [lo, hi] = range(type);
|
|
429
|
-
return (_jsxs(React.Fragment, { children: [prev && !gap && (_jsx("span", { "aria-hidden": true, "data-slot": "time-field-separator", className: "px-px text-muted-foreground", children: clock.separator })), _jsxs("span", { className: cn("relative flex", gap && "
|
|
445
|
+
return (_jsxs(React.Fragment, { children: [prev && !gap && (_jsx("span", { "aria-hidden": true, "data-slot": "time-field-separator", className: "px-px text-muted-foreground", children: clock.separator })), _jsxs("span", { className: cn("relative flex", gap && "ms-1.5"), children: [_jsx("span", { ref: segmentRef(type), id: `${controlId}-${type}`, role: "spinbutton", "data-slot": "time-field-segment", "data-type": type, "data-placeholder": n == null ? "" : undefined, tabIndex: off ? undefined : 0, contentEditable: editable ? "true" : undefined, suppressContentEditableWarning: true, inputMode: type === "dayPeriod" ? "text" : "numeric", enterKeyHint: "next", spellCheck: false, autoCorrect: "off", autoCapitalize: "off", "aria-label": labels[type], "aria-labelledby": groupLabel ? `${groupLabel} ${controlId}-${type}` : undefined, "aria-describedby": describedBy, "aria-invalid": invalid, "aria-readonly": readOnly || undefined, "aria-required": required || undefined, "aria-disabled": off || undefined, "aria-valuemin": lo, "aria-valuemax": hi, "aria-valuenow": n ?? undefined, "aria-valuetext": n == null
|
|
446
|
+
? labels.empty
|
|
447
|
+
: type === "dayPeriod"
|
|
448
|
+
? text
|
|
449
|
+
: // A 12-hour hour reads with its half of the day: "9 PM", not a bare "9".
|
|
450
|
+
type === "hour" && h12 && s.period
|
|
451
|
+
? `${n} ${clock.periods[s.period]}`
|
|
452
|
+
: String(n), onKeyDown: handleKeyDown(type), onFocus: () => (typed.current = ""), className: cn(
|
|
430
453
|
// Focused, outline-hidden rather than none: a contrast theme drops the fill
|
|
431
454
|
// that marks the focused segment, and shows this outline instead.
|
|
432
455
|
"rounded-checkbox px-0.5 whitespace-nowrap caret-transparent outline-none focus:outline-hidden", "transition-[background-color,color] duration-(--duration) ease-(--ease) selection:bg-transparent", "focus:bg-control-hover focus:text-foreground", "data-placeholder:text-control-muted focus:data-placeholder:text-muted-foreground",
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
export interface TimelineMessages {
|
|
4
|
+
/** Read before TimelineChange's old value. */
|
|
5
|
+
from: string;
|
|
6
|
+
/** Read between the old value and the new one. */
|
|
7
|
+
to: string;
|
|
8
|
+
}
|
|
9
|
+
declare module "./locale" {
|
|
10
|
+
interface Messages {
|
|
11
|
+
timeline: TimelineMessages;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
export type TimelineVariant = "activity" | "changelog";
|
|
4
15
|
export interface TimelineProps extends React.ComponentProps<"ol"> {
|
|
5
16
|
/**
|
|
@@ -35,7 +46,10 @@ export interface TimelineItemProps extends React.ComponentProps<"li"> {
|
|
|
35
46
|
* `info`, `destructive` (failed). Say it in the entry's text too — colour is never the only sign.
|
|
36
47
|
*/
|
|
37
48
|
status?: TimelineStatus;
|
|
38
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Not happened yet — a planned milestone: a hollow dot, muted text and a dashed line to it.
|
|
51
|
+
* That is only drawn, so word the title as a plan ("3.0 release planned").
|
|
52
|
+
*/
|
|
39
53
|
upcoming?: boolean;
|
|
40
54
|
}
|
|
41
55
|
/**
|
|
@@ -70,7 +84,9 @@ export interface TimelineChangeProps extends Omit<React.ComponentProps<"p">, "ch
|
|
|
70
84
|
from?: React.ReactNode;
|
|
71
85
|
/** The new value. A string becomes a `Tag`; pass `<Tag variant="success">Won</Tag>` for a status. */
|
|
72
86
|
to: React.ReactNode;
|
|
87
|
+
/** What screen readers hear around the values; a LocaleProvider sets it for every TimelineChange. */
|
|
88
|
+
labels?: Partial<TimelineMessages>;
|
|
73
89
|
}
|
|
74
90
|
/** A field that changed, as "Stage Proposal → Won": the field muted, the values as tags. */
|
|
75
|
-
export declare function TimelineChange({ field, from, to, className, ...props }: TimelineChangeProps): React.JSX.Element;
|
|
91
|
+
export declare function TimelineChange({ field, from, to, labels, className, ...props }: TimelineChangeProps): React.JSX.Element;
|
|
76
92
|
export {};
|
|
@@ -4,7 +4,9 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
4
4
|
import { ArrowRightIcon } from "lucide-react";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
7
8
|
import { Tag } from "./tag.js";
|
|
9
|
+
const defaultMessages = { from: "from", to: "to" };
|
|
8
10
|
const TimelineContext = React.createContext("activity");
|
|
9
11
|
/**
|
|
10
12
|
* Timeline — what happened, in order, on a hairline: an activity feed, a deal's history, a
|
|
@@ -16,8 +18,14 @@ const TimelineContext = React.createContext("activity");
|
|
|
16
18
|
* entries that are a status (a failed deploy, a won deal), and the entry's text says so too.
|
|
17
19
|
*/
|
|
18
20
|
export function Timeline({ variant = "activity", className, ...props }) {
|
|
19
|
-
|
|
21
|
+
// A long feed lays out and paints only the entries near the view; they stay in the page, for
|
|
22
|
+
// find-in-page and screen readers. Each entry draws its own line, so nothing crosses between them.
|
|
23
|
+
const long = React.Children.count(props.children) > LONG_FROM;
|
|
24
|
+
return (_jsx(TimelineContext.Provider, { value: variant, children: _jsx("ol", { "data-slot": "timeline", "data-variant": variant, "data-long": long ? "" : undefined, className: cn("m-0 flex w-full list-none flex-col p-0 font-body", long &&
|
|
25
|
+
"[&>li]:[contain-intrinsic-size:auto_4rem] [&>li]:[content-visibility:auto] [&>li]:[overflow-clip-margin:12px]", className), ...props }) }));
|
|
20
26
|
}
|
|
27
|
+
/** Timelines of more entries than this skip laying out those out of view. */
|
|
28
|
+
const LONG_FROM = 100;
|
|
21
29
|
/* Status inks, spelled out so Tailwind sees every class. */
|
|
22
30
|
const dotStatus = {
|
|
23
31
|
default: "bg-muted-foreground",
|
|
@@ -74,7 +82,7 @@ export function TimelineTitle({ render, ref, className, ...props }) {
|
|
|
74
82
|
export function TimelineTime({ className, ...props }) {
|
|
75
83
|
const variant = React.useContext(TimelineContext);
|
|
76
84
|
return (_jsx("time", { "data-slot": "timeline-time", className: cn("font-mono text-xs leading-6 whitespace-nowrap text-muted-foreground tabular-nums", variant === "activity"
|
|
77
|
-
? "col-start-2 row-start-1 text-
|
|
85
|
+
? "col-start-2 row-start-1 text-end"
|
|
78
86
|
: "col-span-2 row-start-1 tracking-[0.04em]", className), ...props }));
|
|
79
87
|
}
|
|
80
88
|
/** The body under the title: a comment, a changed field, a list of what shipped. */
|
|
@@ -92,8 +100,9 @@ export function TimelineComment({ className, ...props }) {
|
|
|
92
100
|
return (_jsx("div", { "data-slot": "timeline-comment", className: cn("surface-card text-sm leading-relaxed text-foreground-soft [--card-padding:12px_16px] [&>p]:m-0", className), ...props }));
|
|
93
101
|
}
|
|
94
102
|
/** A field that changed, as "Stage Proposal → Won": the field muted, the values as tags. */
|
|
95
|
-
export function TimelineChange({ field, from, to, className, ...props }) {
|
|
103
|
+
export function TimelineChange({ field, from, to, labels, className, ...props }) {
|
|
104
|
+
const text = useMessages("timeline", defaultMessages, labels);
|
|
96
105
|
// A value longer than the line ends in an ellipsis inside its tag; the full text is still read.
|
|
97
106
|
const tag = (value, variant) => typeof value === "string" || typeof value === "number" ? (_jsx(Tag, { variant: variant, className: "max-w-full shrink", children: _jsx("span", { className: "min-w-0 truncate leading-normal", children: value }) })) : (value);
|
|
98
|
-
return (_jsxs("p", { "data-slot": "timeline-change", className: cn("m-0 flex flex-wrap items-center gap-x-2 gap-y-1 text-[13px] text-muted-foreground", className), ...props, children: [_jsx("span", { children: field }), from != null && (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children:
|
|
107
|
+
return (_jsxs("p", { "data-slot": "timeline-change", className: cn("m-0 flex flex-wrap items-center gap-x-2 gap-y-1 text-[13px] text-muted-foreground", className), ...props, children: [_jsx("span", { children: field }), from != null && (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children: text.from }), tag(from, "muted"), _jsx(ArrowRightIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 rtl:-scale-x-100" }), _jsx("span", { className: "sr-only", children: text.to })] })), tag(to, "default")] }));
|
|
99
108
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type TippyMove } from "../lib/tippy/sprite.js";
|
|
3
|
+
import type { TourGuideState } from "./tour.js";
|
|
4
|
+
export type { TippyMove };
|
|
5
|
+
/** Every move Tippy plays, for a picker or a test. */
|
|
6
|
+
export declare const tippyMoves: readonly TippyMove[];
|
|
7
|
+
export interface TippyProps extends Omit<React.ComponentProps<"canvas">, "children" | "width" | "height"> {
|
|
8
|
+
/** What Tippy does. A new move grows out of the last one. Defaults to `idle`. */
|
|
9
|
+
move?: TippyMove;
|
|
10
|
+
/** Which way it faces. Defaults to `right`. */
|
|
11
|
+
facing?: "left" | "right";
|
|
12
|
+
/**
|
|
13
|
+
* CSS pixels to one of its 64 sprite pixels, snapped to whole device pixels so it stays crisp.
|
|
14
|
+
* Defaults to `2`: about 104px wide standing, in a 256 × 208 picture.
|
|
15
|
+
*/
|
|
16
|
+
scale?: number;
|
|
17
|
+
/** A name for assistive technology. Without one Tippy is decoration, hidden from it. */
|
|
18
|
+
label?: string;
|
|
19
|
+
/** Hold the current frame. */
|
|
20
|
+
paused?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tippy — zon.sh's mascot, the mark turned over and standing on its horns, as a 64-pixel sprite on
|
|
24
|
+
* a canvas: snapped to three inks with a one-pixel outline and drawn a whole number of device
|
|
25
|
+
* pixels to a sprite pixel, light on a light page and dark on a dark one. It plays a move — `wave`,
|
|
26
|
+
* `jump`, `think`, `success` and the rest — with weight, each new move growing out of the last;
|
|
27
|
+
* off screen it stops drawing, and under reduced motion it holds the move's clearest frame.
|
|
28
|
+
*
|
|
29
|
+
* The rule people break: Tippy as decoration on every screen. Bring it in where a person is being
|
|
30
|
+
* shown around or something has happened to them — a tour, an empty state, a finished task.
|
|
31
|
+
*/
|
|
32
|
+
export declare function Tippy({ move, facing, scale, label, paused, className, style, ...props }: TippyProps): React.JSX.Element;
|
|
33
|
+
export interface TippyGuideProps extends TourGuideState {
|
|
34
|
+
/** CSS pixels to a sprite pixel, snapped to whole device pixels. Defaults to `2`. */
|
|
35
|
+
scale?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* TippyGuide — Tippy, walking a Tour through with the person and saying each step:
|
|
39
|
+
* `<Tour guide={(g) => <TippyGuide {...g} />} />`. It stands beside the step's target, on the side
|
|
40
|
+
* with room, faces it and points at it, and the step is its speech bubble — the Tour's popover with
|
|
41
|
+
* a tail to its head. When the step changes the bubble goes back into its tail, Tippy gathers
|
|
42
|
+
* itself, leaps to the next target in an arc and lands with a bump, and the next bubble comes out
|
|
43
|
+
* as it lands, its mouth going. It waves on the first step; Done ends with a happy hop and a check,
|
|
44
|
+
* Skip with a wave goodbye. It is decoration: hidden from assistive technology, taking no clicks;
|
|
45
|
+
* the bubble is still the Tour's dialog. Under reduced motion it goes to the next target at once
|
|
46
|
+
* and holds still, and the bubble just appears.
|
|
47
|
+
*/
|
|
48
|
+
export declare function TippyGuide({ scale, ...state }: TippyGuideProps): React.JSX.Element;
|