@zonsh/ui 0.2.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -7,9 +7,9 @@ export interface MessageProps extends React.ComponentProps<"div"> {
7
7
  from: MessageFrom;
8
8
  }
9
9
  /**
10
- * Message — one turn in an AI conversation. A **user** message sits on the right in a 20px
11
- * card, sized to its text; an **assistant** message runs full width on the page, with no
12
- * bubble, so long answers read like a document.
10
+ * Message — one turn in an AI conversation. A **user** message sits at the end — on the right,
11
+ * on the left in a right-to-left page — in a 20px card, sized to its text; an **assistant**
12
+ * message runs full width on the page, with no bubble, so long answers read like a document.
13
13
  *
14
14
  * Compose `MessageAvatar` (optional), `MessageContent` and `MessageActions`. The rule people
15
15
  * break: putting the assistant in a bubble too — the reply is the content, not a quote.
@@ -7,9 +7,9 @@ import { Button } from "./button.js";
7
7
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
8
8
  const MessageContext = React.createContext("assistant");
9
9
  /**
10
- * Message — one turn in an AI conversation. A **user** message sits on the right in a 20px
11
- * card, sized to its text; an **assistant** message runs full width on the page, with no
12
- * bubble, so long answers read like a document.
10
+ * Message — one turn in an AI conversation. A **user** message sits at the end — on the right,
11
+ * on the left in a right-to-left page — in a 20px card, sized to its text; an **assistant**
12
+ * message runs full width on the page, with no bubble, so long answers read like a document.
13
13
  *
14
14
  * Compose `MessageAvatar` (optional), `MessageContent` and `MessageActions`. The rule people
15
15
  * break: putting the assistant in a bubble too — the reply is the content, not a quote.
@@ -22,8 +22,11 @@ export function Message({ from, className, ...props }) {
22
22
  * the assistant is often a `LogoMark` on a raised key.
23
23
  */
24
24
  export function MessageAvatar({ className, children, ...props }) {
25
- if (children != null)
26
- return (_jsx("span", { "data-slot": "message-avatar", "aria-hidden": true, className: cn("inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent text-foreground shadow-key", className), children: children }));
25
+ if (children != null) {
26
+ // A mark is always 32px; the Avatar's own props have nothing to do, the element's are kept.
27
+ const { src: _src, name: _name, fallback: _fallback, size: _size, imageProps: _image, ...rest } = props;
28
+ return (_jsx("span", { ...rest, "data-slot": "message-avatar", "aria-hidden": true, className: cn("inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent text-foreground shadow-key", className), children: children }));
29
+ }
27
30
  return _jsx(Avatar, { "data-slot": "message-avatar", className: cn("shrink-0", className), ...props });
28
31
  }
29
32
  /**
@@ -45,10 +48,10 @@ export function MessageText({ className, ...props }) {
45
48
  /** A row of `MessageAction`s under the content: copy, retry, rate. */
46
49
  export function MessageActions({ className, ...props }) {
47
50
  const from = React.useContext(MessageContext);
48
- return (_jsx("div", { "data-slot": "message-actions", className: cn("-ml-1.5 flex items-center gap-0.5",
51
+ return (_jsx("div", { "data-slot": "message-actions", className: cn("-ms-1.5 flex items-center gap-0.5",
49
52
  // User actions appear on hover or focus, so a long thread stays quiet.
50
53
  from === "user" &&
51
- "-mr-1.5 ml-0 opacity-0 transition-opacity duration-(--duration) ease-(--ease) group-focus-within/message:opacity-100 group-hover/message:opacity-100", className), ...props }));
54
+ "ms-0 -me-1.5 opacity-0 transition-opacity duration-(--duration) ease-(--ease) group-focus-within/message:opacity-100 group-hover/message:opacity-100", className), ...props }));
52
55
  }
53
56
  /** One action under a message: a 30px ghost icon button with a tooltip. */
54
57
  export function MessageAction({ label, className, children, ...props }) {
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Meter as BaseMeter } from "@base-ui/react/meter";
4
4
  import { sx } from "../lib/cn.js";
5
+ import { useLocale } from "./locale.js";
5
6
  const toneFill = {
6
7
  default: "bg-foreground",
7
8
  success: "bg-success",
@@ -19,7 +20,8 @@ const toneFill = {
19
20
  */
20
21
  export function Meter({ label, showValue = false, tone = "default", className, children, ...props }) {
21
22
  const resolved = typeof tone === "function" ? tone(props.value) : tone;
22
- return (_jsxs(BaseMeter.Root, { "data-slot": "meter", "data-tone": resolved, className: sx("grid w-full grid-cols-[minmax(0,1fr)_auto] items-baseline gap-x-3 gap-y-2", className), ...props, children: [label != null && (_jsx(BaseMeter.Label, { "data-slot": "meter-label",
23
+ const locale = useLocale();
24
+ return (_jsxs(BaseMeter.Root, { "data-slot": "meter", "data-tone": resolved, className: sx("grid w-full grid-cols-[minmax(0,1fr)_auto] items-baseline gap-x-3 gap-y-2", className), locale: locale, ...props, children: [label != null && (_jsx(BaseMeter.Label, { "data-slot": "meter-label",
23
25
  // A long name (a file, a URL) wraps instead of pushing the track wider than its column.
24
26
  className: "col-start-1 font-mono text-[12px] [overflow-wrap:anywhere] text-foreground-soft", children: label })), showValue && (_jsx(BaseMeter.Value, { "data-slot": "meter-value", className: "col-start-2 text-end font-mono text-[12px] text-muted-foreground tabular-nums" })), _jsx(BaseMeter.Track, { "data-slot": "meter-track", className: "relative col-span-2 h-1.5 overflow-hidden rounded-full border border-field-edge bg-field-surface shadow-field", children: _jsx(BaseMeter.Indicator, { "data-slot": "meter-indicator", className: sx("block h-full rounded-full transition-[width,background-color] duration-(--duration) ease-(--ease)", toneFill[resolved]) }) }), children] }));
25
27
  }
@@ -0,0 +1,80 @@
1
+ import * as React from "react";
2
+ export interface MoneyInputMessages {
3
+ /** The text isn't an amount; `example` is one written for the locale ("1,234.56"). */
4
+ invalid: (example: string) => string;
5
+ /** More decimal places than the currency has. */
6
+ precision: (fractionDigits: number) => string;
7
+ /** A negative amount where `allowNegative` is off. */
8
+ negative: string;
9
+ /** Below `min`, formatted with the currency ("€10.00"). */
10
+ rangeUnderflow: (min: string) => string;
11
+ /** Above `max`, formatted with the currency. */
12
+ rangeOverflow: (max: string) => string;
13
+ }
14
+ declare module "./locale" {
15
+ interface Messages {
16
+ moneyInput: MoneyInputMessages;
17
+ }
18
+ }
19
+ declare const sizes: {
20
+ readonly sm: {
21
+ readonly group: "sm";
22
+ readonly className: "";
23
+ };
24
+ readonly default: {
25
+ readonly group: "default";
26
+ readonly className: "";
27
+ };
28
+ readonly lg: {
29
+ readonly group: "default";
30
+ readonly className: "min-h-(--control-h-lg) text-lg sm:text-lg";
31
+ };
32
+ };
33
+ export interface MoneyInputChangeDetails {
34
+ /** The same amount as an integer of minor units (cents): `"12.34"` → `1234n`; null with no amount. */
35
+ minorUnits: bigint | null;
36
+ }
37
+ export interface MoneyInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "size" | "min" | "max" | "type" | "children"> {
38
+ /** The ISO 4217 code: `"EUR"`, `"JPY"`, `"KWD"`. It sets the symbol and the decimal places. */
39
+ currency: string;
40
+ /**
41
+ * The amount as an exact decimal string in major units, with the currency's decimal places:
42
+ * `"1234.50"`, `"-0.05"`, `"1500"` (JPY); `null` while empty or not an amount. Never a float.
43
+ */
44
+ value?: string | null;
45
+ defaultValue?: string | null;
46
+ /** Called as the amount changes, with the same amount in minor units. */
47
+ onValueChange?: (value: string | null, details: MoneyInputChangeDetails) => void;
48
+ /** A BCP 47 locale for the separators and the symbol's side. Default: the LocaleProvider's, then the browser's. */
49
+ locale?: string;
50
+ /** `symbol` (€, US$ or $ as the locale writes it), `narrowSymbol` ($) or `code` (EUR). Default `symbol`. */
51
+ currencyDisplay?: "symbol" | "narrowSymbol" | "code";
52
+ /** Override the currency's decimal places, e.g. `0` for whole euros. */
53
+ fractionDigits?: number;
54
+ /** Let people enter amounts below zero. Off by default. */
55
+ allowNegative?: boolean;
56
+ /** The smallest and largest amounts, as decimal strings (or numbers). Outside them the field is invalid; nothing is changed for you. */
57
+ min?: string | number;
58
+ max?: string | number;
59
+ /** `sm` (30px), `default` (38px) or `lg` (46px) for an amount that is the point of the screen. */
60
+ size?: keyof typeof sizes;
61
+ /** Error messages; a LocaleProvider sets them for every MoneyInput. */
62
+ labels?: Partial<MoneyInputMessages>;
63
+ }
64
+ /**
65
+ * MoneyInput — an amount of money in one currency: a recessed field like `Input` with Licht
66
+ * Mono tabular digits and the currency's symbol or code as a mono addon, on the side the locale
67
+ * writes it (`€1,234.50` in en-US, `1.234,50 €` in de-DE).
68
+ *
69
+ * The value is an exact decimal string with the currency's decimal places — `"1234.50"`, never
70
+ * a float — and the decimal places come from the currency (JPY none, EUR two, KWD three). While
71
+ * focused, the amount is plain to edit (`1234.50`); on blur it is grouped for reading.
72
+ * The rule people break: storing the value as a JavaScript number. Keep the string, or its
73
+ * minor units from `onValueChange`, all the way to the server.
74
+ */
75
+ export declare function MoneyInput({ currency, value: valueProp, defaultValue, onValueChange, locale: localeProp, currencyDisplay, fractionDigits: digitsProp, allowNegative, min, max, size, labels, id: idProp, name, required, disabled: disabledProp, readOnly, placeholder, className, onFocus, onBlur, onPaste, "aria-describedby": describedByProp, ref: refProp, ...props }: MoneyInputProps): React.JSX.Element;
76
+ /** The amount as an integer of minor units (cents) for a currency: `toMinorUnits("12.34", "EUR")` → `1234n`. */
77
+ export declare function toMinorUnits(amount: string, currency: string): bigint;
78
+ /** An integer of minor units as the amount string: `fromMinorUnits(1234n, "EUR")` → `"12.34"`. */
79
+ export declare function fromMinorUnits(minorUnits: bigint | number | string, currency: string): string;
80
+ export {};
@@ -0,0 +1,253 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Field as BaseField } from "@base-ui/react/field";
4
+ import * as React from "react";
5
+ import { cn } from "../lib/cn.js";
6
+ import { mergeRefs } from "../lib/merge-refs.js";
7
+ import { FieldValueInput, useFormatLocale, useFormResetEffect } from "../lib/field-value.js";
8
+ import { amountFromMinor, amountToMinor, compareAmounts, currencyAffix, currencyFractionDigits, formatAmount, normalizeAmount, parseAmount, stripCurrency, } from "../lib/money.js";
9
+ import { InputGroup, InputGroupAddon, InputGroupText } from "./input-group.js";
10
+ import { useLocale, useMessages } from "./locale.js";
11
+ const defaultMessages = {
12
+ invalid: (example) => `Enter an amount, like ${example}.`,
13
+ precision: (digits) => digits === 0
14
+ ? "Enter a whole amount, without decimals."
15
+ : `Use no more than ${digits} decimal ${digits === 1 ? "place" : "places"}.`,
16
+ negative: "Enter an amount of zero or more.",
17
+ rangeUnderflow: (min) => `Enter ${min} or more.`,
18
+ rangeOverflow: (max) => `Enter ${max} or less.`,
19
+ };
20
+ const sizes = {
21
+ sm: { group: "sm", className: "" },
22
+ default: { group: "default", className: "" },
23
+ lg: { group: "default", className: "min-h-(--control-h-lg) text-lg sm:text-lg" },
24
+ };
25
+ const countDigits = (text) => text.match(/\p{Nd}/gu)?.length ?? 0;
26
+ /** Where the caret goes after the `count`-th digit of `text` (any script). */
27
+ function caretAfterDigits(text, count) {
28
+ if (count <= 0)
29
+ return /^\D*-/.test(text) ? text.indexOf("-") + 1 : 0;
30
+ let seen = 0;
31
+ const chars = [...text];
32
+ let at = 0;
33
+ for (const ch of chars) {
34
+ at += ch.length;
35
+ if (/\p{Nd}/u.test(ch) && ++seen === count)
36
+ return at;
37
+ }
38
+ return text.length;
39
+ }
40
+ /** What may be typed: digits of any script, separators, spaces and a minus. */
41
+ const TYPABLE = /^[\p{Nd}\p{Zs}.,'’٫٬\-−]*$/u;
42
+ /**
43
+ * MoneyInput — an amount of money in one currency: a recessed field like `Input` with Licht
44
+ * Mono tabular digits and the currency's symbol or code as a mono addon, on the side the locale
45
+ * writes it (`€1,234.50` in en-US, `1.234,50 €` in de-DE).
46
+ *
47
+ * The value is an exact decimal string with the currency's decimal places — `"1234.50"`, never
48
+ * a float — and the decimal places come from the currency (JPY none, EUR two, KWD three). While
49
+ * focused, the amount is plain to edit (`1234.50`); on blur it is grouped for reading.
50
+ * The rule people break: storing the value as a JavaScript number. Keep the string, or its
51
+ * minor units from `onValueChange`, all the way to the server.
52
+ */
53
+ export function MoneyInput({ currency, value: valueProp, defaultValue, onValueChange, locale: localeProp, currencyDisplay = "symbol", fractionDigits: digitsProp, allowNegative = false, min, max, size = "default", labels, id: idProp, name, required, disabled: disabledProp, readOnly, placeholder, className, onFocus, onBlur, onPaste, "aria-describedby": describedByProp, ref: refProp, ...props }) {
54
+ const locale = useFormatLocale(localeProp ?? useLocale());
55
+ const text = useMessages("moneyInput", defaultMessages, labels);
56
+ const digits = digitsProp ?? currencyFractionDigits(currency);
57
+ const generatedId = React.useId();
58
+ const id = idProp ?? generatedId;
59
+ const controlled = valueProp !== undefined;
60
+ const [own, setOwn] = React.useState(() => normalizeAmount(defaultValue, digits));
61
+ const amount = controlled ? normalizeAmount(valueProp, digits) : own;
62
+ /*
63
+ * The text being edited, or kept because it isn't an amount: null shows the amount formatted.
64
+ * Focus puts the amount in plain (no grouping), blur formats it again.
65
+ */
66
+ const [draft, setDraft] = React.useState(null);
67
+ const visible = React.useRef(null);
68
+ const visibleRefs = React.useMemo(() => mergeRefs(visible, refProp), [refProp]);
69
+ const valueInput = React.useRef(null);
70
+ // A refused keystroke re-renders, so React puts the text back and the caret follows.
71
+ const [, rerender] = React.useReducer((n) => n + 1, 0);
72
+ const caret = React.useRef(null);
73
+ const focused = React.useRef(false);
74
+ /** The last amount reported: a controlled value that differs came from outside. */
75
+ const emitted = React.useRef(amount);
76
+ const [seen, setSeen] = React.useState(amount);
77
+ if (amount !== seen) {
78
+ setSeen(amount);
79
+ if (amount !== emitted.current) {
80
+ emitted.current = amount;
81
+ setDraft(focused.current && amount !== null ? plain(amount) : null);
82
+ }
83
+ }
84
+ function plain(v) {
85
+ return formatAmount(v, { locale, fractionDigits: digits, grouping: false });
86
+ }
87
+ const emit = (next) => {
88
+ if (next === emitted.current)
89
+ return;
90
+ emitted.current = next;
91
+ if (!controlled)
92
+ setOwn(next);
93
+ onValueChange?.(next, { minorUnits: next === null ? null : amountToMinor(next, digits) });
94
+ };
95
+ const commitText = (next) => {
96
+ const parsed = parseAmount(next, { locale, fractionDigits: digits });
97
+ setDraft(next);
98
+ emit(parsed.kind === "ok" ? parsed.value : null);
99
+ };
100
+ const shown = draft ?? (amount === null ? "" : formatAmount(amount, { locale, fractionDigits: digits }));
101
+ // Put the caret back where it was after a paste or a filtered edit re-renders the text.
102
+ React.useLayoutEffect(() => {
103
+ const at = caret.current;
104
+ caret.current = null;
105
+ if (at !== null && visible.current && document.activeElement === visible.current)
106
+ visible.current.setSelectionRange(at, at);
107
+ });
108
+ /* The validity message the Field shows, for the text and the amount as they stand. */
109
+ const bounds = React.useMemo(() => ({
110
+ min: normalizeAmount(min, digits),
111
+ max: normalizeAmount(max, digits),
112
+ }), [min, max, digits]);
113
+ const withCurrency = (v) => formatAmount(v, { locale, fractionDigits: digits, currency, currencyDisplay });
114
+ let message = "";
115
+ const parsed = draft !== null ? parseAmount(draft, { locale, fractionDigits: digits }) : null;
116
+ if (parsed?.kind === "invalid")
117
+ message = text.invalid(formatAmount(`1234${digits ? "." + "5678".slice(0, digits) : ""}`, { locale, fractionDigits: digits }));
118
+ else if (parsed?.kind === "precision")
119
+ message = text.precision(digits);
120
+ else if (amount !== null) {
121
+ if (!allowNegative && amount.startsWith("-"))
122
+ message = text.negative;
123
+ else if (bounds.min !== null && compareAmounts(amount, bounds.min) < 0)
124
+ message = text.rangeUnderflow(withCurrency(bounds.min));
125
+ else if (bounds.max !== null && compareAmounts(amount, bounds.max) > 0)
126
+ message = text.rangeOverflow(withCurrency(bounds.max));
127
+ }
128
+ // The visible field carries the message too, for a plain form's own validation bubble.
129
+ React.useLayoutEffect(() => {
130
+ visible.current?.setCustomValidity(disabledProp ? "" : message);
131
+ }, [message, disabledProp]);
132
+ const affix = currencyAffix(currency, locale, currencyDisplay);
133
+ const currencyName = React.useMemo(() => {
134
+ try {
135
+ return (new Intl.DisplayNames(locale ? [locale] : undefined, { type: "currency" }).of(currency) ?? currency);
136
+ }
137
+ catch {
138
+ return currency;
139
+ }
140
+ }, [locale, currency]);
141
+ const currencyId = `${id}-currency`;
142
+ /* A form's reset puts back the default amount, as it does a native input's (uncontrolled). */
143
+ useFormResetEffect(visible, () => {
144
+ if (controlled)
145
+ return;
146
+ const initial = normalizeAmount(defaultValue, digits);
147
+ emitted.current = initial;
148
+ setOwn(initial);
149
+ setDraft(null);
150
+ });
151
+ const handleChange = (event) => {
152
+ const next = event.currentTarget.value.replace(/\p{Cf}/gu, "");
153
+ // Letters, symbols and a second minus are not typed. A minus only goes in front.
154
+ const minus = next.match(/[-−]/g)?.length ?? 0;
155
+ const signOk = minus === 0 || (allowNegative && minus === 1 && /^\s*[-−]/.test(next));
156
+ const parsedNext = parseAmount(next, { locale, fractionDigits: digits });
157
+ // A digit past the currency's decimal places is refused as it is typed — unless more digits
158
+ // could still make the separator a thousands one ("1,5" on its way to "1,500" for yen).
159
+ const tooPrecise = parsedNext.kind === "precision" && parsedNext.definite;
160
+ if (!TYPABLE.test(next) || !signOk || tooPrecise) {
161
+ // Keep the text and the caret where they were.
162
+ caret.current = Math.max(0, (event.currentTarget.selectionStart ?? 1) - (next.length - shown.length));
163
+ setDraft(shown);
164
+ rerender();
165
+ return;
166
+ }
167
+ commitText(next);
168
+ };
169
+ const handlePaste = (event) => {
170
+ onPaste?.(event);
171
+ if (event.defaultPrevented || readOnly)
172
+ return;
173
+ const pasted = event.clipboardData.getData("text/plain");
174
+ event.preventDefault();
175
+ const cleaned = stripCurrency(pasted);
176
+ if (cleaned === null || !/\p{Nd}/u.test(cleaned))
177
+ return;
178
+ const input = event.currentTarget;
179
+ const start = input.selectionStart ?? input.value.length;
180
+ const end = input.selectionEnd ?? start;
181
+ const combined = input.value.slice(0, start) + cleaned + input.value.slice(end);
182
+ const result = parseAmount(combined, { locale, fractionDigits: digits });
183
+ if (result.kind === "ok") {
184
+ // A whole amount pasted in reads as one: "€ 1.234,56" becomes 1234.56 to edit.
185
+ const next = plain(result.value);
186
+ caret.current = start === 0 && end === input.value.length ? next.length : start + cleaned.length;
187
+ setDraft(next);
188
+ emit(result.value);
189
+ }
190
+ else {
191
+ caret.current = start + cleaned.length;
192
+ commitText(combined);
193
+ }
194
+ };
195
+ const sizing = sizes[size];
196
+ return (_jsx(BaseField.Control, { id: id, name: name, value: amount ?? "", disabled: disabledProp, render: (control) => {
197
+ const { ref, id: controlId, name: controlName, value: controlValue, disabled, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, onKeyDown: _fieldKeyDown, className: _className, defaultValue: _defaultValue, autoFocus: _autoFocus, ...state } = control;
198
+ const off = Boolean(disabled);
199
+ return (_jsxs(InputGroup, { size: sizing.group, "data-slot": "money-input", "data-size": size, ...state, className: cn(sizing.className, className), children: [_jsx(InputGroupAddon, { align: affix.before ? "inline-start" : "inline-end", "aria-hidden": true, children: _jsx(InputGroupText, { "data-slot": "money-input-currency", className: size === "lg" ? "text-[15px]" : "", children: affix.symbol }) }), _jsx("input", { ...props, ref: visibleRefs, id: controlId, "data-slot": "input-group-control", type: "text", inputMode: allowNegative ? "text" : "decimal", autoCorrect: "off", spellCheck: false, value: shown, placeholder: placeholder, disabled: off, readOnly: readOnly, required: required, "aria-labelledby": labelledBy ?? props["aria-labelledby"], "aria-describedby": [describedBy, describedByProp, currencyId].filter(Boolean).join(" "), "aria-invalid": invalid, onChange: handleChange, onPaste: handlePaste, onFocus: (event) => {
200
+ focused.current = true;
201
+ if (draft === null && amount !== null && !readOnly) {
202
+ // The amount goes plain at once, in the DOM too, keeping the selection: Tab selects
203
+ // the whole text, and typing should still replace it.
204
+ const input = event.currentTarget;
205
+ const next = plain(amount);
206
+ // Focus from `select()` or `focus()` comes with the caret at 0, before a click
207
+ // puts it where it lands: select all then too.
208
+ const all = input.selectionStart === 0 &&
209
+ (input.selectionEnd === input.value.length || input.selectionEnd === 0);
210
+ const before = countDigits(input.value.slice(0, input.selectionStart ?? input.value.length));
211
+ input.value = next;
212
+ if (all)
213
+ input.setSelectionRange(0, next.length);
214
+ else {
215
+ const at = caretAfterDigits(next, before);
216
+ input.setSelectionRange(at, at);
217
+ }
218
+ setDraft(next);
219
+ }
220
+ onFocus?.(event);
221
+ fieldFocus?.(event);
222
+ }, onBlur: (event) => {
223
+ focused.current = false;
224
+ const result = parseAmount(draft ?? "", { locale, fractionDigits: digits });
225
+ if (draft !== null) {
226
+ if (result.kind === "ok") {
227
+ emit(result.value);
228
+ setDraft(null);
229
+ }
230
+ else if (result.kind === "empty") {
231
+ emit(null);
232
+ setDraft(null);
233
+ }
234
+ // Not an amount: the text stays, with its message, to be put right.
235
+ }
236
+ onBlur?.(event);
237
+ // The Field hears the blur from its own input, which holds the amount.
238
+ if (valueInput.current)
239
+ fieldBlur?.({
240
+ ...event,
241
+ currentTarget: valueInput.current,
242
+ });
243
+ }, className: cn("min-w-0 flex-1 self-stretch border-0 bg-transparent font-mono text-foreground tabular-nums shadow-none outline-none", "placeholder:text-control-muted focus-visible:outline-none disabled:cursor-not-allowed", "px-3.5 group-data-[size=sm]/input-group:px-2.5", "group-has-[>[data-align=inline-end]]/input-group:pe-2 group-has-[>[data-align=inline-start]]/input-group:ps-2", size === "lg" && "px-4") }), _jsx("span", { id: currencyId, className: "sr-only", children: currencyName }), _jsx(FieldValueInput, { ref: ref, valueRef: valueInput, "data-slot": "money-input-value", name: controlName, value: controlValue ?? "", onChange: fieldChange, required: required, disabled: off, message: off ? "" : message, onFocus: () => visible.current?.focus() })] }));
244
+ } }));
245
+ }
246
+ /** The amount as an integer of minor units (cents) for a currency: `toMinorUnits("12.34", "EUR")` → `1234n`. */
247
+ export function toMinorUnits(amount, currency) {
248
+ return amountToMinor(amount, currencyFractionDigits(currency));
249
+ }
250
+ /** An integer of minor units as the amount string: `fromMinorUnits(1234n, "EUR")` → `"12.34"`. */
251
+ export function fromMinorUnits(minorUnits, currency) {
252
+ return amountFromMinor(minorUnits, currencyFractionDigits(currency));
253
+ }
@@ -1,5 +1,18 @@
1
1
  import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
2
2
  import * as React from "react";
3
+ export interface NumberFieldMessages {
4
+ /** The − (or ▼) stepper. */
5
+ decrement: string;
6
+ /** The + (or ▲) stepper. */
7
+ increment: string;
8
+ /** What screen readers call the field instead of "text field". */
9
+ roleDescription: string;
10
+ }
11
+ declare module "./locale" {
12
+ interface Messages {
13
+ numberField: NumberFieldMessages;
14
+ }
15
+ }
3
16
  declare const groupSizes: {
4
17
  readonly sm: "min-h-(--control-h-sm) p-0.5";
5
18
  readonly default: "min-h-(--control-h) p-[3px]";
@@ -19,9 +32,15 @@ export interface NumberFieldProps extends BaseNumberField.Root.Props {
19
32
  * number at the start like an Input's text, with ▲ and ▼ stacked at the end of the field.
20
33
  */
21
34
  steppers?: "sides" | "stacked";
22
- /** Accessible names for the steppers. */
35
+ /**
36
+ * Accessible names for the steppers.
37
+ * @deprecated Use `labels.decrement` and `labels.increment`.
38
+ */
23
39
  decrementLabel?: string;
40
+ /** @deprecated Use `labels.increment`. */
24
41
  incrementLabel?: string;
42
+ /** Accessible names: the steppers and the field's role. A LocaleProvider sets them for every NumberField. */
43
+ labels?: Partial<NumberFieldMessages>;
25
44
  }
26
45
  /**
27
46
  * NumberField — a recessed field for exact numbers, with raised −/+ steppers and mono, tabular
@@ -32,5 +51,5 @@ export interface NumberFieldProps extends BaseNumberField.Root.Props {
32
51
  * The rule people break: no `min`/`max` — set the bounds so the steppers stop where the
33
52
  * business rule does.
34
53
  */
35
- export declare function NumberField({ size, steppers, label, placeholder, decrementLabel, incrementLabel, id: idProp, className, value: valueProp, defaultValue, onValueChange, ...props }: NumberFieldProps): React.JSX.Element;
54
+ export declare function NumberField({ size, steppers, label, placeholder, decrementLabel, incrementLabel, labels, id: idProp, className, value: valueProp, defaultValue, onValueChange, locale: localeProp, ...props }: NumberFieldProps): React.JSX.Element;
36
55
  export {};
@@ -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",
@@ -60,10 +60,13 @@ const STEP_REASONS = new Set(["increment-press", "decrement-press", "keyboard",
60
60
  * The rule people break: no `min`/`max` — set the bounds so the steppers stop where the
61
61
  * business rule does.
62
62
  */
63
- export function NumberField({ size = "default", steppers = "sides", label, placeholder, decrementLabel = "Decrease", incrementLabel = "Increase", id: idProp, className, value: valueProp, defaultValue, onValueChange, ...props }) {
63
+ export function NumberField({ size = "default", steppers = "sides", label, placeholder, decrementLabel, incrementLabel, labels, id: idProp, className, value: valueProp, defaultValue, onValueChange, locale: localeProp, ...props }) {
64
+ const text = useMessages("numberField", defaultMessages, labels);
65
+ const locale = useLocale();
64
66
  const generatedId = React.useId();
65
67
  const id = idProp ?? generatedId;
66
- const textSize = size === "sm" ? "text-[13px]" : "text-base sm:text-[15px]";
68
+ // A tight line, so the number fits the field in a theme with smaller controls too.
69
+ const textSize = size === "sm" ? "text-[13px] leading-[1.2]" : "text-base leading-[1.2] sm:text-[15px] sm:leading-[1.2]";
67
70
  const stacked = steppers === "stacked";
68
71
  // The roll overlay sits where the input's text does.
69
72
  const textAlign = stacked ? stackedRoll[size] : "";
@@ -132,15 +135,23 @@ export function NumberField({ size = "default", steppers = "sides", label, place
132
135
  };
133
136
  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
137
  // 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")
138
+ const decrement = (_jsx(BaseNumberField.Decrement, { "data-slot": "number-field-decrement", "aria-label": decrementLabel ?? text.decrement, onPointerDown: hideCaret, className: cn(stepper, stacked
139
+ ? cn("min-h-0 w-full flex-1 rounded-b-item",
140
+ // 12px, or half the key in a theme with smaller controls.
141
+ size === "sm"
142
+ ? "[&_svg]:size-[min(12px,calc(var(--control-inset-sm)/2))]"
143
+ : "[&_svg]:size-[min(12px,calc(var(--control-inset)/2))]", size === "sm" ? "material-row" : "material-raised")
137
144
  : 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")
145
+ const increment = (_jsx(BaseNumberField.Increment, { "data-slot": "number-field-increment", "aria-label": incrementLabel ?? text.increment, onPointerDown: hideCaret, className: cn(stepper, stacked
146
+ ? cn("min-h-0 w-full flex-1 rounded-t-item",
147
+ // 12px, or half the key in a theme with smaller controls.
148
+ size === "sm"
149
+ ? "[&_svg]:size-[min(12px,calc(var(--control-inset-sm)/2))]"
150
+ : "[&_svg]:size-[min(12px,calc(var(--control-inset)/2))]", size === "sm" ? "material-row" : "material-raised")
140
151
  : 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",
152
+ 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
153
  // 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) => {
154
+ "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
155
  // While an IME composes (229 marks it in Safari), its keys pick characters: they
145
156
  // don't step, or commit a half-typed number.
146
157
  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.