@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
@@ -5,6 +5,12 @@ import { ChevronDownIcon, ChevronUpIcon, MinusIcon, MoveHorizontalIcon, PlusIcon
5
5
  import * as React from "react";
6
6
  import { cn, sx } from "../lib/cn.js";
7
7
  import { DigitRoll, reducedMotion } from "../lib/digit-roll.js";
8
+ import { useLocale, useMessages } from "./locale.js";
9
+ const defaultMessages = {
10
+ decrement: "Decrease",
11
+ increment: "Increase",
12
+ roleDescription: "Number field",
13
+ };
8
14
  const groupSizes = {
9
15
  sm: "min-h-(--control-h-sm) p-0.5",
10
16
  default: "min-h-(--control-h) p-[3px]",
@@ -23,14 +29,8 @@ const stackSizes = {
23
29
  * left, or at the right in a right-to-left field, with the steppers at the other end.
24
30
  */
25
31
  const stackedInput = { sm: "text-start ps-2", default: "text-start ps-[11px]" };
26
- /**
27
- * The digit roll over it. The roll is always laid out left to right, so its digits keep their
28
- * order, which leaves its start on the left: in a right-to-left field it is moved to the right.
29
- */
30
- const stackedRoll = {
31
- sm: "justify-start pl-2 [:dir(rtl)>&]:justify-end [:dir(rtl)>&]:pr-2 [:dir(rtl)>&]:pl-0",
32
- default: "justify-start pl-[11px] [:dir(rtl)>&]:justify-end [:dir(rtl)>&]:pr-[11px] [:dir(rtl)>&]:pl-0",
33
- };
32
+ /** The digit roll over it, at the same start. */
33
+ const stackedRoll = { sm: "justify-start ps-2", default: "justify-start ps-[11px]" };
34
34
  /** Keys that step the value without editing the text: they leave a hidden caret hidden. */
35
35
  const STEP_KEYS = new Set([
36
36
  "ArrowUp",
@@ -47,10 +47,12 @@ const STEP_KEYS = new Set([
47
47
  "Escape",
48
48
  ]);
49
49
  /**
50
- * Changes that step the value — the steppers, keys, wheel and scrubbing the label roll the digits;
51
- * typing, pasting and blur formatting don't.
50
+ * A step rolls the digits: a press on a stepper, an arrow key, the wheel. Steps closer together
51
+ * than a roll lasts (a held key or stepper, a fast wheel) change in place, so a held key counts up
52
+ * cleanly instead of restarting the roll on every repeat. Scrubbing follows the pointer, and
53
+ * typing, pasting and blur formatting don't roll.
52
54
  */
53
- const STEP_REASONS = new Set(["increment-press", "decrement-press", "keyboard", "wheel", "scrub"]);
55
+ const ROLL_REASONS = new Set(["increment-press", "decrement-press", "keyboard", "wheel"]);
54
56
  /**
55
57
  * NumberField — a recessed field for exact numbers, with raised −/+ steppers and mono, tabular
56
58
  * digits so values do not jitter as they change.
@@ -60,10 +62,13 @@ const STEP_REASONS = new Set(["increment-press", "decrement-press", "keyboard",
60
62
  * The rule people break: no `min`/`max` — set the bounds so the steppers stop where the
61
63
  * business rule does.
62
64
  */
63
- export function NumberField({ size = "default", steppers = "sides", label, placeholder, decrementLabel = "Decrease", incrementLabel = "Increase", id: idProp, className, value: valueProp, defaultValue, onValueChange, ...props }) {
65
+ export function NumberField({ size = "default", steppers = "sides", label, placeholder, decrementLabel, incrementLabel, labels, id: idProp, className, value: valueProp, defaultValue, onValueChange, locale: localeProp, ...props }) {
66
+ const text = useMessages("numberField", defaultMessages, labels);
67
+ const locale = useLocale();
64
68
  const generatedId = React.useId();
65
69
  const id = idProp ?? generatedId;
66
- const textSize = size === "sm" ? "text-[13px]" : "text-base sm:text-[15px]";
70
+ // A tight line, so the number fits the field in a theme with smaller controls too.
71
+ const textSize = size === "sm" ? "text-[13px] leading-[1.2]" : "text-base leading-[1.2] sm:text-[15px] sm:leading-[1.2]";
67
72
  const stacked = steppers === "stacked";
68
73
  // The roll overlay sits where the input's text does.
69
74
  const textAlign = stacked ? stackedRoll[size] : "";
@@ -94,6 +99,9 @@ export function NumberField({ size = "default", steppers = "sides", label, place
94
99
  // A step re-renders this wrapper so the effect below runs, even if a controlling parent doesn't.
95
100
  const [, setStepped] = React.useState(0);
96
101
  const endRoll = React.useCallback(() => setRoll(null), []);
102
+ // When the last step came: a held key or stepper repeats faster than a roll lasts, and a roll
103
+ // that restarts on every repeat never lands, so steps that close together just change.
104
+ const lastStep = React.useRef(-Infinity);
97
105
  React.useLayoutEffect(() => {
98
106
  const step = pending.current;
99
107
  const el = input.current;
@@ -116,15 +124,24 @@ export function NumberField({ size = "default", steppers = "sides", label, place
116
124
  const showCaret = () => setCaretHidden(false);
117
125
  const handleValueChange = (next, details) => {
118
126
  const before = value;
119
- if (input.current &&
120
- STEP_REASONS.has(details.reason) &&
121
- next != null &&
122
- before != null &&
123
- next !== before &&
124
- !reducedMotion()) {
125
- // During a running roll the input text is the value it is rolling to: the next roll starts there.
126
- pending.current = { from: input.current.value, dir: next > before ? 1 : -1 };
127
- setStepped((n) => n + 1);
127
+ if (ROLL_REASONS.has(details.reason) && input.current) {
128
+ const now = performance.now();
129
+ const rollMs = parseFloat(getComputedStyle(input.current).getPropertyValue("--duration")) || 150;
130
+ const repeat = now - lastStep.current < rollMs;
131
+ lastStep.current = now;
132
+ if (repeat) {
133
+ // Too soon after the last step: no new roll, and the one running gives way to the value.
134
+ pending.current = null;
135
+ setRoll(null);
136
+ }
137
+ else if (next != null && before != null && next !== before && !reducedMotion()) {
138
+ pending.current = { from: input.current.value, dir: next > before ? 1 : -1 };
139
+ setStepped((n) => n + 1);
140
+ }
141
+ }
142
+ else if (roll) {
143
+ // Typing or a scrub during a roll: the value shows at once.
144
+ setRoll(null);
128
145
  }
129
146
  onValueChange?.(next, details);
130
147
  if (!controlled && !details.isCanceled)
@@ -132,15 +149,23 @@ export function NumberField({ size = "default", steppers = "sides", label, place
132
149
  };
133
150
  const stepper = cn("inline-flex shrink-0 cursor-pointer items-center justify-center text-foreground focus-ring", "data-disabled:pointer-events-none data-disabled:opacity-50");
134
151
  // Stacked, the halves keep the key's 7px outer corners and meet square in the middle.
135
- const decrement = (_jsx(BaseNumberField.Decrement, { "data-slot": "number-field-decrement", "aria-label": decrementLabel, onPointerDown: hideCaret, className: cn(stepper, stacked
136
- ? cn("min-h-0 w-full flex-1 rounded-b-item [&_svg]:size-3", size === "sm" ? "material-row" : "material-raised")
152
+ const decrement = (_jsx(BaseNumberField.Decrement, { "data-slot": "number-field-decrement", "aria-label": decrementLabel ?? text.decrement, onPointerDown: hideCaret, className: cn(stepper, stacked
153
+ ? cn("min-h-0 w-full flex-1 rounded-b-item",
154
+ // 12px, or half the key in a theme with smaller controls.
155
+ size === "sm"
156
+ ? "[&_svg]:size-[min(12px,calc(var(--control-inset-sm)/2))]"
157
+ : "[&_svg]:size-[min(12px,calc(var(--control-inset)/2))]", size === "sm" ? "material-row" : "material-raised")
137
158
  : cn("rounded-full [&_svg]:size-3.5", stepperSizes[size])), children: stacked ? _jsx(ChevronDownIcon, {}) : _jsx(MinusIcon, {}) }));
138
- const increment = (_jsx(BaseNumberField.Increment, { "data-slot": "number-field-increment", "aria-label": incrementLabel, onPointerDown: hideCaret, className: cn(stepper, stacked
139
- ? cn("min-h-0 w-full flex-1 rounded-t-item [&_svg]:size-3", size === "sm" ? "material-row" : "material-raised")
159
+ const increment = (_jsx(BaseNumberField.Increment, { "data-slot": "number-field-increment", "aria-label": incrementLabel ?? text.increment, onPointerDown: hideCaret, className: cn(stepper, stacked
160
+ ? cn("min-h-0 w-full flex-1 rounded-t-item",
161
+ // 12px, or half the key in a theme with smaller controls.
162
+ size === "sm"
163
+ ? "[&_svg]:size-[min(12px,calc(var(--control-inset-sm)/2))]"
164
+ : "[&_svg]:size-[min(12px,calc(var(--control-inset)/2))]", size === "sm" ? "material-row" : "material-raised")
140
165
  : cn("rounded-full [&_svg]:size-3.5", stepperSizes[size])), children: stacked ? _jsx(ChevronUpIcon, {}) : _jsx(PlusIcon, {}) }));
141
- return (_jsxs(BaseNumberField.Root, { "data-slot": "number-field", "data-size": size, "data-steppers": steppers, id: id, className: sx("flex flex-col items-start gap-2", className), value: value, onValueChange: handleValueChange, ...props, children: [label != null && (_jsxs(BaseNumberField.ScrubArea, { "data-slot": "number-field-scrub-area", onPointerDown: hideCaret, className: "cursor-ew-resize select-none data-disabled:cursor-not-allowed data-disabled:opacity-55", children: [_jsx("label", { htmlFor: id, className: "cursor-ew-resize text-sm leading-snug font-medium text-foreground select-none", children: label }), _jsx(BaseNumberField.ScrubAreaCursor, { className: "text-foreground drop-shadow-[0_1px_1px_#0006]", children: _jsx(MoveHorizontalIcon, { className: "size-5" }) })] })), _jsxs(BaseNumberField.Group, { "data-slot": "number-field-group", className: cn("flex w-full material-field items-center gap-1 rounded-control",
166
+ return (_jsxs(BaseNumberField.Root, { "data-slot": "number-field", "data-size": size, "data-steppers": steppers, id: id, className: sx("flex flex-col items-start gap-2", className), value: value, onValueChange: handleValueChange, locale: localeProp ?? locale, ...props, children: [label != null && (_jsxs(BaseNumberField.ScrubArea, { "data-slot": "number-field-scrub-area", onPointerDown: hideCaret, className: "cursor-ew-resize select-none data-disabled:cursor-not-allowed data-disabled:opacity-55", children: [_jsx("label", { htmlFor: id, className: "cursor-ew-resize text-sm leading-snug font-medium text-foreground select-none", children: label }), _jsx(BaseNumberField.ScrubAreaCursor, { className: "text-foreground drop-shadow-[0_1px_1px_#0006]", children: _jsx(MoveHorizontalIcon, { className: "size-5" }) })] })), _jsxs(BaseNumberField.Group, { "data-slot": "number-field-group", className: cn("flex w-full material-field items-center gap-1 rounded-control",
142
167
  // The whole group already dims when disabled; do not dim the steppers twice.
143
- "data-disabled:[&_button]:opacity-100", groupSizes[size]), children: [!stacked && decrement, _jsxs("span", { className: "relative flex min-w-0 flex-1 items-center self-stretch", children: [_jsx(BaseNumberField.Input, { ref: input, "data-slot": "number-field-input", placeholder: placeholder, onPointerDown: showCaret, onBlur: showCaret, onKeyDown: (e) => {
168
+ "data-disabled:[&_button]:opacity-100", groupSizes[size]), children: [!stacked && decrement, _jsxs("span", { className: "relative flex min-w-0 flex-1 items-center self-stretch", children: [_jsx(BaseNumberField.Input, { ref: input, "data-slot": "number-field-input", placeholder: placeholder, "aria-roledescription": text.roleDescription, onPointerDown: showCaret, onBlur: showCaret, onKeyDown: (e) => {
144
169
  // While an IME composes (229 marks it in Safari), its keys pick characters: they
145
170
  // don't step, or commit a half-typed number.
146
171
  if (e.nativeEvent.isComposing || e.keyCode === 229)
@@ -1,5 +1,14 @@
1
1
  import { OTPField as BaseOTPField } from "@base-ui/react/otp-field";
2
2
  import * as React from "react";
3
+ export interface OtpFieldMessages {
4
+ /** The name of every generated slot after the first, which takes the field's label. */
5
+ character: (index: number, length: number) => string;
6
+ }
7
+ declare module "./locale" {
8
+ interface Messages {
9
+ otpField: OtpFieldMessages;
10
+ }
11
+ }
3
12
  declare const slotSizes: {
4
13
  readonly default: "h-(--control-h) max-w-(--control-h) text-base";
5
14
  readonly lg: "h-(--control-h-lg) max-w-(--control-h-lg) text-lg";
@@ -13,7 +22,11 @@ export interface OtpFieldProps extends BaseOTPField.Root.Props {
13
22
  * (`3` renders a 6-digit code as 123 – 456). Ignored when you pass your own children.
14
23
  */
15
24
  groupSize?: number;
25
+ /** The generated slots' names. A LocaleProvider sets them for every OtpField. */
26
+ labels?: Partial<OtpFieldMessages>;
16
27
  ref?: React.Ref<HTMLDivElement>;
28
+ /** The first slot's input. Hand it a form library's ref (React Hook Form's `field.ref`) so it can focus the code. */
29
+ inputRef?: React.Ref<HTMLInputElement>;
17
30
  }
18
31
  /**
19
32
  * OtpField — a one-time code entry: one recessed square per character, mono digits.
@@ -25,7 +38,7 @@ export interface OtpFieldProps extends BaseOTPField.Root.Props {
25
38
  * The focus ring is one indicator that glides from slot to slot as the code is typed or erased.
26
39
  * The slots read left to right on a right-to-left page too, as the code does in the message.
27
40
  */
28
- export declare function OtpField({ size, groupSize, length, className, children, ref, value: valueProp, defaultValue, onValueChange, ...props }: OtpFieldProps): React.JSX.Element;
41
+ export declare function OtpField({ size, groupSize, length, className, children, ref, inputRef, value: valueProp, defaultValue, onValueChange, labels, ...props }: OtpFieldProps): React.JSX.Element;
29
42
  export interface OtpFieldSlotProps extends BaseOTPField.Input.Props {
30
43
  }
31
44
  /** One character slot. Use directly only for custom layouts; `OtpField` renders them by default. */
@@ -5,6 +5,10 @@ import { OTPField as BaseOTPField } from "@base-ui/react/otp-field";
5
5
  import * as React from "react";
6
6
  import { cn, sx } from "../lib/cn.js";
7
7
  import { glideMotion, glideStyle, useGlide, useMergedRef } from "../lib/glide.js";
8
+ import { useMessages } from "./locale.js";
9
+ const defaultMessages = {
10
+ character: (index, length) => `Character ${index} of ${length}`,
11
+ };
8
12
  const SLOT = '[data-slot="otp-field-slot"]';
9
13
  const findFocused = (root) => root.querySelector(`${SLOT}:focus`);
10
14
  /* Square while there is room; narrower (never shorter) where the row has less, as on a phone. */
@@ -23,8 +27,12 @@ const SizeContext = React.createContext("default");
23
27
  * The focus ring is one indicator that glides from slot to slot as the code is typed or erased.
24
28
  * The slots read left to right on a right-to-left page too, as the code does in the message.
25
29
  */
26
- export function OtpField({ size = "default", groupSize, length, className, children, ref, value: valueProp, defaultValue, onValueChange, ...props }) {
30
+ export function OtpField({ size = "default", groupSize, length, className, children, ref, inputRef, value: valueProp, defaultValue, onValueChange, labels, ...props }) {
31
+ const text = useMessages("otpField", defaultMessages, labels);
27
32
  const [rootRef, setRootRef] = useMergedRef(ref);
33
+ React.useImperativeHandle(inputRef, () => rootRef.current.querySelector(SLOT), [
34
+ rootRef,
35
+ ]);
28
36
  const glide = useGlide(rootRef, findFocused, { events: ["focusin", "focusout"], items: SLOT });
29
37
  /*
30
38
  * Uncontrolled, the code is kept here rather than inside Base UI, which has no reset of its own:
@@ -47,7 +55,7 @@ export function OtpField({ size = "default", groupSize, length, className, child
47
55
  }, [rootRef]);
48
56
  let content = children;
49
57
  if (content == null) {
50
- const slots = Array.from({ length }, (_, index) => (_jsx(OtpFieldSlot, { "aria-label": index === 0 ? undefined : `Character ${index + 1} of ${length}` }, index)));
58
+ const slots = Array.from({ length }, (_, index) => (_jsx(OtpFieldSlot, { "aria-label": index === 0 ? undefined : text.character(index + 1, length) }, index)));
51
59
  if (groupSize && groupSize > 0 && groupSize < length) {
52
60
  const chunks = [];
53
61
  for (let start = 0; start < length; start += groupSize) {
@@ -1,4 +1,15 @@
1
1
  import * as React from "react";
2
+ export interface PaginationMessages {
3
+ nav: string;
4
+ previous: string;
5
+ next: string;
6
+ page: (page: number) => string;
7
+ }
8
+ declare module "./locale" {
9
+ interface Messages {
10
+ pagination: PaginationMessages;
11
+ }
12
+ }
2
13
  export interface PaginationProps extends Omit<React.ComponentProps<"nav">, "onChange"> {
3
14
  /** The current page, 1-based. */
4
15
  page: number;
@@ -12,13 +23,8 @@ export interface PaginationProps extends Omit<React.ComponentProps<"nav">, "onCh
12
23
  siblingCount?: number;
13
24
  /** `sm` 30px for dense tables and admin screens; `default` 38px. */
14
25
  size?: "sm" | "default";
15
- /** Accessible names. */
16
- labels?: {
17
- nav?: string;
18
- previous?: string;
19
- next?: string;
20
- page?: (page: number) => string;
21
- };
26
+ /** Accessible names; a LocaleProvider sets them for every Pagination. */
27
+ labels?: Partial<PaginationMessages>;
22
28
  }
23
29
  /**
24
30
  * Pagination — move through a long list one page at a time.
@@ -5,6 +5,13 @@ import * as React from "react";
5
5
  import { cn } from "../lib/cn.js";
6
6
  import { glideMotion, glideStyle, useGlide, useMergedRef } from "../lib/glide.js";
7
7
  import { Button } from "./button.js";
8
+ import { useMessages } from "./locale.js";
9
+ const defaultMessages = {
10
+ nav: "Pagination",
11
+ previous: "Previous page",
12
+ next: "Next page",
13
+ page: (page) => `Page ${page}`,
14
+ };
8
15
  const PAGE = '[data-slot="pagination-page"]';
9
16
  const findCurrent = (nav) => nav.querySelector(`${PAGE}[aria-current="page"]`);
10
17
  function getPages(page, count, siblings) {
@@ -46,25 +53,29 @@ export function Pagination({ page, pageCount, onPageChange, getHref, siblingCoun
46
53
  const siblings = siblingCount >= 0 ? Math.floor(siblingCount) : 1;
47
54
  const pages = getPages(current, count, siblings);
48
55
  const square = size === "sm" ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5";
49
- const pageLabel = labels?.page ?? ((p) => `Page ${p}`);
56
+ // Previous and Next are exactly square at any control height, not as wide as chevron + padding.
57
+ const arrow = size === "sm" ? "w-(--control-h-sm) px-0" : "w-(--control-h) px-0";
58
+ const text = useMessages("pagination", defaultMessages, labels);
50
59
  const control = (target, content, extra) => {
51
60
  const disabled = target < 1 || target > count;
52
61
  const asLink = getHref && !disabled;
53
62
  return (_jsx(Button, { variant: "secondary", size: size, disabled: disabled,
54
63
  // Previous and Next stay focusable when they run out, so pressing Next onto the last
55
64
  // page leaves keyboard focus on it instead of dropping it to the page.
56
- focusableWhenDisabled: true, nativeButton: !asLink, render: asLink ? _jsx("a", { href: getHref(target) }) : undefined, onClick: () => !disabled && target !== page && onPageChange?.(target), className: cn(square, "font-mono text-[13px] font-normal tabular-nums"), ...extra, children: content }));
65
+ focusableWhenDisabled: true, nativeButton: !asLink, render: asLink ? _jsx("a", { href: getHref(target) }) : undefined, onClick: () => !disabled && target !== page && onPageChange?.(target), className: cn(square, "font-mono text-[13px] leading-none font-normal tabular-nums"), ...extra, children: content }));
57
66
  };
58
- return (_jsxs("nav", { "aria-label": labels?.nav ?? "Pagination", "data-slot": "pagination", "data-size": size, "data-glide": glide.visible ? "" : undefined, ref: setNavRef, className: cn("group/pagination relative flex", className), ...props, children: [_jsx("span", { "aria-hidden": true, "data-slot": "pagination-indicator", "data-visible": glide.visible ? "" : undefined, "data-instant": glide.instant ? "" : undefined, className: cn(glideMotion, "z-10 rounded-button ring-1 ring-control-focus duration-[calc(var(--duration)*1.3)]"), style: glideStyle(glide) }), _jsxs("ul", { className: "m-0 flex list-none flex-wrap items-center gap-1.5 p-0", children: [_jsx("li", { children: control(current - 1, _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }), {
59
- "aria-label": labels?.previous ?? "Previous page",
67
+ return (_jsxs("nav", { "aria-label": text.nav, "data-slot": "pagination", "data-size": size, "data-glide": glide.visible ? "" : undefined, ref: setNavRef, className: cn("group/pagination relative flex", className), ...props, children: [_jsx("span", { "aria-hidden": true, "data-slot": "pagination-indicator", "data-visible": glide.visible ? "" : undefined, "data-instant": glide.instant ? "" : undefined, className: cn(glideMotion, "z-10 rounded-button ring-1 ring-control-focus"), style: glideStyle(glide) }), _jsxs("ul", { className: "m-0 flex list-none flex-wrap items-center gap-1.5 p-0 [&>li]:flex", children: [_jsx("li", { children: control(current - 1, _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }), {
68
+ "aria-label": text.previous,
69
+ className: arrow,
60
70
  }) }), pages.map((p) => typeof p === "number" ? (_jsx("li", { children: control(p, p, {
61
- "aria-label": pageLabel(p),
71
+ "aria-label": text.page(p),
62
72
  "aria-current": p === current ? "page" : undefined,
63
73
  "data-slot": "pagination-page",
64
- className: cn(square, "font-mono text-[13px] font-normal tabular-nums", "aria-[current=page]:bg-control-hover aria-[current=page]:shadow-raised-current",
74
+ className: cn(square, "font-mono text-[13px] leading-none font-normal tabular-nums", "aria-[current=page]:bg-control-hover aria-[current=page]:shadow-raised-current",
65
75
  // The gliding indicator carries the focus edge once it is placed.
66
76
  "group-data-glide/pagination:aria-[current=page]:shadow-raised"),
67
77
  }) }, p)) : (_jsx("li", { "aria-hidden": true, "data-slot": "pagination-ellipsis", className: cn("inline-flex items-center justify-center font-mono text-[13px] text-muted-foreground", square), children: "\u2026" }, p))), _jsx("li", { children: control(current + 1, _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }), {
68
- "aria-label": labels?.next ?? "Next page",
78
+ "aria-label": text.next,
79
+ className: arrow,
69
80
  }) })] })] }));
70
81
  }
@@ -5,6 +5,67 @@ import { type PdfSource } from "../lib/pdf.js";
5
5
  * it, `fit-page` shows whole pages, or a factor (1 = 100%, the printed size).
6
6
  */
7
7
  export type PdfZoom = "auto" | "fit-width" | "fit-page" | number;
8
+ /** Why a PDF couldn't be opened. */
9
+ export type PdfError = "password" | "invalid" | "missing" | "empty" | "unknown";
10
+ export interface PdfViewerMessages {
11
+ /** Why it couldn't be opened, under the title `cantOpen`. */
12
+ error: (reason: PdfError) => string;
13
+ cantOpen: string;
14
+ downloadFile: string;
15
+ /** The toolbar's name. */
16
+ toolbar: string;
17
+ showSidebar: string;
18
+ hideSidebar: string;
19
+ previousPage: string;
20
+ nextPage: string;
21
+ /** The page field, and what is read after it: "of 12 pages". */
22
+ pageField: string;
23
+ ofPages: (count: number) => string;
24
+ zoomIn: string;
25
+ zoomOut: string;
26
+ /** The zoom menu's button, with the zoom as a percentage. */
27
+ zoom: (percent: number) => string;
28
+ zoomAuto: string;
29
+ zoomFitWidth: string;
30
+ zoomFitPage: string;
31
+ rotate: string;
32
+ search: string;
33
+ download: string;
34
+ print: string;
35
+ fullScreen: string;
36
+ exitFullScreen: string;
37
+ /** The rail's tabs and what they hold. */
38
+ sidebar: string;
39
+ pages: string;
40
+ outline: string;
41
+ /** The scrolling pages' name. */
42
+ document: (name: string, page: number, count: number) => string;
43
+ /** A thumbnail. */
44
+ page: (page: number) => string;
45
+ /** An outline entry's toggle. */
46
+ expand: (title: string) => string;
47
+ collapse: (title: string) => string;
48
+ /** A link on a page: to a web address, or to another page. */
49
+ link: (address: string) => string;
50
+ goToPage: (page: number) => string;
51
+ /** The search field: its name and placeholder, the matches and its buttons. */
52
+ searchField: string;
53
+ matches: (index: number, total: number) => string;
54
+ noMatches: string;
55
+ previousMatch: string;
56
+ nextMatch: string;
57
+ closeSearch: string;
58
+ /** PdfPreview's line under the title, and its dialog's close button. */
59
+ previewPages: (count: number) => string;
60
+ previewError: string;
61
+ previewPdf: string;
62
+ close: string;
63
+ }
64
+ declare module "./locale" {
65
+ interface Messages {
66
+ pdfViewer: PdfViewerMessages;
67
+ }
68
+ }
8
69
  declare const viewerVariants: {
9
70
  readonly region: "surface-container";
10
71
  readonly card: "surface-card overflow-hidden [--card-padding:0]";
@@ -34,6 +95,8 @@ export interface PdfViewerProps extends Omit<React.ComponentProps<"div">, "child
34
95
  fullscreen?: boolean;
35
96
  /** Extra toolbar items at the end, e.g. a close button in a dialog. */
36
97
  toolbarEnd?: React.ReactNode;
98
+ /** The reader's words; a LocaleProvider sets them for every PdfViewer and PdfPreview. */
99
+ labels?: Partial<PdfViewerMessages>;
37
100
  }
38
101
  /**
39
102
  * PdfViewer — a full reader for PDF documents: pages drawn by pdf.js with selectable text, a
@@ -44,7 +107,7 @@ export interface PdfViewerProps extends Omit<React.ComponentProps<"div">, "child
44
107
  * The rule people break: putting a viewer where a link would do — for a document people only
45
108
  * download, link to it; for a glance, use `PdfPreview`.
46
109
  */
47
- export declare function PdfViewer({ src, fileName, variant, defaultZoom, defaultPage, onPageChange, thumbnails, defaultThumbnailsOpen, search, download, print, fullscreen: allowFullscreen, toolbarEnd, className, onKeyDown, ...props }: PdfViewerProps): React.JSX.Element;
110
+ export declare function PdfViewer(props: PdfViewerProps): React.JSX.Element;
48
111
  export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "children" | "title"> {
49
112
  src: PdfSource;
50
113
  /** Used for downloads; also the title when none is given. */
@@ -55,6 +118,8 @@ export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "c
55
118
  description?: React.ReactNode;
56
119
  /** Props for the viewer that opens. */
57
120
  viewer?: Omit<PdfViewerProps, "src" | "fileName" | "variant" | "toolbarEnd">;
121
+ /** The card's and the reader's words; a LocaleProvider sets them for every PdfPreview. */
122
+ labels?: Partial<PdfViewerMessages>;
58
123
  }
59
124
  /**
60
125
  * PdfPreview — a compact card with a document's first page, its name and its length. Clicking it
@@ -65,5 +130,5 @@ export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "c
65
130
  * people break: a grid of previews for documents nobody needs to recognise by their cover — a
66
131
  * list of names is quicker to scan.
67
132
  */
68
- export declare function PdfPreview({ src, fileName, title, description, viewer, className, ...props }: PdfPreviewProps): React.JSX.Element;
133
+ export declare function PdfPreview({ src, fileName, title, description, viewer, labels, className, ...props }: PdfPreviewProps): React.JSX.Element;
69
134
  export {};