@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.
Files changed (200) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/accordion.js +1 -1
  4. package/dist/components/alert-dialog.js +1 -1
  5. package/dist/components/ascii-field.d.ts +1 -1
  6. package/dist/components/ascii-field.js +2 -1
  7. package/dist/components/bottom-nav.d.ts +86 -0
  8. package/dist/components/bottom-nav.js +175 -0
  9. package/dist/components/breadcrumb.d.ts +9 -0
  10. package/dist/components/breadcrumb.js +6 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +2 -2
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/calendar.d.ts +1 -1
  15. package/dist/components/calendar.js +18 -3
  16. package/dist/components/carousel.d.ts +22 -3
  17. package/dist/components/carousel.js +25 -7
  18. package/dist/components/chart.d.ts +20 -0
  19. package/dist/components/chart.js +52 -3
  20. package/dist/components/code-block.d.ts +20 -10
  21. package/dist/components/code-block.js +54 -12
  22. package/dist/components/collapsible.js +3 -3
  23. package/dist/components/color-picker.d.ts +30 -8
  24. package/dist/components/color-picker.js +48 -27
  25. package/dist/components/combobox.d.ts +21 -3
  26. package/dist/components/combobox.js +79 -7
  27. package/dist/components/command.d.ts +23 -3
  28. package/dist/components/command.js +63 -18
  29. package/dist/components/conversation.d.ts +10 -1
  30. package/dist/components/conversation.js +24 -7
  31. package/dist/components/copy-button.d.ts +15 -6
  32. package/dist/components/copy-button.js +27 -10
  33. package/dist/components/data-table.d.ts +66 -6
  34. package/dist/components/data-table.js +376 -23
  35. package/dist/components/date-picker.d.ts +73 -4
  36. package/dist/components/date-picker.js +138 -7
  37. package/dist/components/dialog.d.ts +10 -1
  38. package/dist/components/dialog.js +6 -3
  39. package/dist/components/drawer.d.ts +10 -1
  40. package/dist/components/drawer.js +6 -3
  41. package/dist/components/feature-list.js +2 -2
  42. package/dist/components/field.d.ts +27 -8
  43. package/dist/components/field.js +49 -4
  44. package/dist/components/file-drop.d.ts +26 -4
  45. package/dist/components/file-drop.js +125 -64
  46. package/dist/components/filter-bar.d.ts +50 -3
  47. package/dist/components/filter-bar.js +71 -33
  48. package/dist/components/form.d.ts +4 -2
  49. package/dist/components/form.js +24 -2
  50. package/dist/components/graph.d.ts +41 -0
  51. package/dist/components/graph.js +106 -50
  52. package/dist/components/illustration.js +51 -4
  53. package/dist/components/input-group.d.ts +18 -7
  54. package/dist/components/input-group.js +41 -19
  55. package/dist/components/input.d.ts +2 -2
  56. package/dist/components/input.js +3 -3
  57. package/dist/components/kbd.d.ts +17 -0
  58. package/dist/components/kbd.js +8 -1
  59. package/dist/components/layout.d.ts +2 -1
  60. package/dist/components/layout.js +55 -11
  61. package/dist/components/lightbox.d.ts +100 -0
  62. package/dist/components/lightbox.js +457 -0
  63. package/dist/components/locale.d.ts +44 -0
  64. package/dist/components/locale.js +37 -0
  65. package/dist/components/logo.js +1 -1
  66. package/dist/components/menu.js +3 -1
  67. package/dist/components/menubar.js +60 -13
  68. package/dist/components/message.d.ts +3 -3
  69. package/dist/components/message.js +12 -8
  70. package/dist/components/meter.js +3 -1
  71. package/dist/components/money-input.d.ts +80 -0
  72. package/dist/components/money-input.js +253 -0
  73. package/dist/components/navigation-menu.js +4 -2
  74. package/dist/components/number-field.d.ts +21 -2
  75. package/dist/components/number-field.js +53 -28
  76. package/dist/components/otp-field.d.ts +14 -1
  77. package/dist/components/otp-field.js +10 -2
  78. package/dist/components/pagination.d.ts +13 -7
  79. package/dist/components/pagination.js +18 -7
  80. package/dist/components/pdf-viewer.d.ts +67 -2
  81. package/dist/components/pdf-viewer.js +88 -21
  82. package/dist/components/phone-input.d.ts +79 -0
  83. package/dist/components/phone-input.js +282 -0
  84. package/dist/components/popover.js +1 -1
  85. package/dist/components/progress.js +3 -1
  86. package/dist/components/prompt-input.d.ts +34 -9
  87. package/dist/components/prompt-input.js +37 -17
  88. package/dist/components/radio-group.js +7 -2
  89. package/dist/components/rating.d.ts +73 -0
  90. package/dist/components/rating.js +124 -0
  91. package/dist/components/reasoning.d.ts +16 -1
  92. package/dist/components/reasoning.js +10 -7
  93. package/dist/components/resizable.d.ts +10 -1
  94. package/dist/components/resizable.js +4 -1
  95. package/dist/components/response.d.ts +17 -5
  96. package/dist/components/response.js +58 -18
  97. package/dist/components/scroll-area.d.ts +1 -1
  98. package/dist/components/select.js +14 -3
  99. package/dist/components/separator.js +1 -1
  100. package/dist/components/sidebar.d.ts +20 -4
  101. package/dist/components/sidebar.js +70 -35
  102. package/dist/components/site-header.d.ts +46 -12
  103. package/dist/components/site-header.js +78 -19
  104. package/dist/components/skeleton.d.ts +1 -1
  105. package/dist/components/skeleton.js +1 -1
  106. package/dist/components/slider.js +3 -1
  107. package/dist/components/sortable.d.ts +178 -0
  108. package/dist/components/sortable.js +1282 -0
  109. package/dist/components/sources.d.ts +17 -2
  110. package/dist/components/sources.js +11 -4
  111. package/dist/components/spinner.d.ts +13 -1
  112. package/dist/components/spinner.js +5 -2
  113. package/dist/components/stat.d.ts +91 -0
  114. package/dist/components/stat.js +141 -0
  115. package/dist/components/stepper.d.ts +71 -0
  116. package/dist/components/stepper.js +101 -0
  117. package/dist/components/switch.d.ts +2 -2
  118. package/dist/components/switch.js +2 -2
  119. package/dist/components/table.d.ts +13 -3
  120. package/dist/components/table.js +231 -41
  121. package/dist/components/tabs.js +8 -4
  122. package/dist/components/tags-input.d.ts +18 -2
  123. package/dist/components/tags-input.js +66 -34
  124. package/dist/components/theme.d.ts +16 -2
  125. package/dist/components/theme.js +34 -8
  126. package/dist/components/time-field.d.ts +24 -4
  127. package/dist/components/time-field.js +32 -9
  128. package/dist/components/timeline.d.ts +18 -2
  129. package/dist/components/timeline.js +13 -4
  130. package/dist/components/tippy.d.ts +48 -0
  131. package/dist/components/tippy.js +648 -0
  132. package/dist/components/toast.d.ts +18 -2
  133. package/dist/components/toast.js +12 -3
  134. package/dist/components/toggle-group.js +1 -0
  135. package/dist/components/tool-call.d.ts +19 -8
  136. package/dist/components/tool-call.js +23 -7
  137. package/dist/components/toolbar.d.ts +1 -1
  138. package/dist/components/toolbar.js +10 -2
  139. package/dist/components/tooltip.d.ts +4 -2
  140. package/dist/components/tooltip.js +10 -4
  141. package/dist/components/tour.d.ts +127 -0
  142. package/dist/components/tour.js +673 -0
  143. package/dist/components/tree.js +45 -9
  144. package/dist/components/video-player.d.ts +10 -2
  145. package/dist/components/video-player.js +134 -38
  146. package/dist/illustration.d.ts +2 -0
  147. package/dist/illustration.js +7 -0
  148. package/dist/index.d.ts +11 -3
  149. package/dist/index.js +11 -3
  150. package/dist/lib/code-highlight.d.ts +3 -16
  151. package/dist/lib/code-highlight.js +160 -10
  152. package/dist/lib/code-theme.js +3 -3
  153. package/dist/lib/digit-roll.js +8 -8
  154. package/dist/lib/field-errors.d.ts +28 -0
  155. package/dist/lib/field-errors.js +24 -0
  156. package/dist/lib/field-value.d.ts +13 -0
  157. package/dist/lib/field-value.js +44 -0
  158. package/dist/lib/glide.d.ts +5 -4
  159. package/dist/lib/glide.js +5 -4
  160. package/dist/lib/graph-layout.js +11 -2
  161. package/dist/lib/money.d.ts +73 -0
  162. package/dist/lib/money.js +343 -0
  163. package/dist/lib/phone-countries.d.ts +1 -0
  164. package/dist/lib/phone-countries.js +281 -0
  165. package/dist/lib/phone.d.ts +90 -0
  166. package/dist/lib/phone.js +286 -0
  167. package/dist/lib/platform.d.ts +8 -3
  168. package/dist/lib/platform.js +13 -6
  169. package/dist/lib/row-index.d.ts +15 -0
  170. package/dist/lib/row-index.js +136 -0
  171. package/dist/lib/table-fit.d.ts +3 -2
  172. package/dist/lib/table-fit.js +52 -23
  173. package/dist/lib/theme-script.d.ts +15 -2
  174. package/dist/lib/theme-script.js +23 -3
  175. package/dist/lib/tippy/pixels.d.ts +47 -0
  176. package/dist/lib/tippy/pixels.js +187 -0
  177. package/dist/lib/tippy/sprite.d.ts +86 -0
  178. package/dist/lib/tippy/sprite.js +753 -0
  179. package/dist/messages/de.d.ts +12 -0
  180. package/dist/messages/de.js +326 -0
  181. package/dist/styles/expressive.css +60 -26
  182. package/dist/styles/index.css +11 -2
  183. package/dist/styles/material.css +47 -23
  184. package/dist/styles/parts/ai.css +4 -2
  185. package/dist/styles/parts/controls.css +85 -32
  186. package/dist/styles/parts/data.css +33 -5
  187. package/dist/styles/parts/feedback.css +110 -13
  188. package/dist/styles/parts/foundations.css +1 -1
  189. package/dist/styles/parts/navigation.css +230 -5
  190. package/dist/styles/parts/overlays.css +98 -11
  191. package/dist/styles/parts/pdf.css +13 -7
  192. package/dist/styles/tokens.css +28 -4
  193. package/dist/vite.d.ts +0 -50
  194. package/dist/vite.js +0 -100
  195. package/package.json +28 -33
  196. package/dist/components/code-highlight.d.ts +0 -13
  197. package/dist/components/code-highlight.js +0 -107
  198. package/dist/components/whiteboard.d.ts +0 -80
  199. package/dist/components/whiteboard.js +0 -389
  200. 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 = (tag) => `Remove ${tag}`, className, placeholder, disabled, readOnly, required, id, ref, onKeyDown, onPaste, onFocus, onBlur, ...props }) {
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
- const rtl = useDirection() === "rtl";
56
- const towardChips = rtl ? "ArrowRight" : "ArrowLeft";
57
- const awayFromChips = rtl ? "ArrowLeft" : "ArrowRight";
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 counts = new Map();
60
- const keys = tags.map((tag) => {
61
- const n = counts.get(tag) ?? 0;
62
- counts.set(tag, n + 1);
63
- return n ? `${tag}\u0000${n}` : tag;
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 ((event.key === "Backspace" || event.key === towardChips) &&
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", "has-[[data-slot=tags-input-input]:disabled]:cursor-not-allowed has-[[data-slot=tags-input-input]:disabled]:opacity-55", className), onMouseDown: (event) => {
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.map((tag, index) => {
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 { createThemeScript, themeScript, THEME_STORAGE_KEY, type ThemeMode } from "../lib/theme-script.js";
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"> {
@@ -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
- export { createThemeScript, themeScript, THEME_STORAGE_KEY } from "../lib/theme-script.js";
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
- document.documentElement.classList.toggle("dark", resolvedTheme === "dark");
80
- }, [mounted, resolvedTheme]);
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
- document.documentElement.classList.toggle("dark", next === "dark" || (next === "system" && systemDark()));
87
- }, [storageKey]);
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
- return (_jsxs(Button, { "data-slot": "theme-toggle", type: "button", variant: "secondary", size: "icon", "aria-label": "Toggle light and dark theme", ...props, onClick: (e) => {
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
- /** Names for each segment, read out with the field's label. */
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 defaultSegmentLabels = {
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 labels = { ...defaultSegmentLabels, ...segmentLabels };
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
- if (from !== to && !from.includes("–") && !reducedMotion())
182
- setRolls((r) => ({ ...r, [type]: { from, to, dir, key: performance.now() } }));
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 flex-1 items-center", children: order.map((type, i) => {
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 && "ml-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 ? "Empty" : type === "dayPeriod" ? text : String(n), onKeyDown: handleKeyDown(type), onFocus: () => (typed.current = ""), className: cn(
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
- /** Not happened yet — a planned milestone: a hollow dot, muted text and a dashed line to it. */
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
- return (_jsx(TimelineContext.Provider, { value: variant, children: _jsx("ol", { "data-slot": "timeline", "data-variant": variant, className: cn("m-0 flex w-full list-none flex-col p-0 font-body", className), ...props }) }));
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-right"
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: "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: "to" })] })), tag(to, "default")] }));
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;