@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
@@ -0,0 +1,282 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
4
+ import { Field as BaseField } from "@base-ui/react/field";
5
+ import { ChevronDownIcon } from "lucide-react";
6
+ import * as React from "react";
7
+ import { cn } from "../lib/cn.js";
8
+ import { FieldValueInput, useFormatLocale, useFormResetEffect } from "../lib/field-value.js";
9
+ import { mergeRefs } from "../lib/merge-refs.js";
10
+ import { checkPhoneLength, E164_MAX_DIGITS, formatNational, internationalDigits, nationalNumber, parsePhoneNumber, PHONE_COUNTRIES, phoneCountry, phoneDigits, regionOfLocale, splitInternational, toE164, } from "../lib/phone.js";
11
+ import { ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "./combobox.js";
12
+ import { InputGroup, InputGroupAddon, InputGroupButton } from "./input-group.js";
13
+ import { useLocale, useMessages } from "./locale.js";
14
+ const defaultMessages = {
15
+ country: "Country",
16
+ search: "Search countries",
17
+ empty: "No country matches. Try its name, or its code like +44.",
18
+ countryChanged: (country) => `Country changed to ${country}.`,
19
+ tooShort: (country, code) => `This number is too short for +${code} (${country}).`,
20
+ tooLong: (country, code) => `This number is too long for +${code} (${country}).`,
21
+ unknownCode: "This number starts with no country code we know. Check the digits after the +.",
22
+ };
23
+ const sizes = {
24
+ sm: { group: "sm", button: "sm", className: "" },
25
+ default: { group: "default", button: "default", className: "" },
26
+ lg: {
27
+ group: "default",
28
+ button: "default",
29
+ className: "min-h-(--control-h-lg) text-lg sm:text-lg",
30
+ },
31
+ };
32
+ const fold = (s) => s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
33
+ /** Where the caret goes after the `count`-th digit of `text`. */
34
+ function caretAfterDigits(text, count) {
35
+ if (count <= 0)
36
+ return text.startsWith("+") ? 1 : 0;
37
+ let seen = 0;
38
+ for (let i = 0; i < text.length; i++)
39
+ if (/\d/.test(text[i]) && ++seen === count)
40
+ return i + 1;
41
+ return text.length;
42
+ }
43
+ /**
44
+ * PhoneInput — an international phone number: a country picker joined to the number in one
45
+ * recessed field. The picker shows the ISO code and the calling code in mono (`DE +49`) and
46
+ * opens a searchable list of countries named in the locale; the number is grouped in mono as it
47
+ * is typed (`163 7568602`). Typing or pasting a full `+44 20 7946 0018` switches the country.
48
+ *
49
+ * The value is E.164 (`"+4915112345678"`), the form every SMS and voice provider takes. Lengths
50
+ * are checked per country against libphonenumber's metadata — a sanity check, not proof the number
51
+ * exists. The rule people break: storing the number as typed. Keep the E.164 value.
52
+ */
53
+ export function PhoneInput({ value: valueProp, defaultValue, onValueChange, country: countryProp, defaultCountry, onCountryChange, countries, locale: localeProp, size = "default", labels, id: idProp, name, required, disabled: disabledProp, readOnly, placeholder, className, onFocus, onBlur, onKeyDown, onPaste, ref: refProp, ...props }) {
54
+ const contextLocale = useLocale();
55
+ const locale = useFormatLocale(localeProp ?? contextLocale);
56
+ const text = useMessages("phoneInput", defaultMessages, labels);
57
+ const generatedId = React.useId();
58
+ const id = idProp ?? generatedId;
59
+ /* The countries in the picker, named in the locale and in its alphabetical order. */
60
+ const options = React.useMemo(() => {
61
+ let names = null;
62
+ try {
63
+ names = new Intl.DisplayNames(locale ? [locale] : undefined, { type: "region" });
64
+ }
65
+ catch {
66
+ /* no DisplayNames: the ISO codes */
67
+ }
68
+ const allowed = countries ? new Set(countries.map((c) => c.toUpperCase())) : null;
69
+ const collator = new Intl.Collator(locale);
70
+ return PHONE_COUNTRIES.filter((c) => !allowed || allowed.has(c.iso))
71
+ .map((c) => {
72
+ const name = names?.of(c.iso) ?? c.iso;
73
+ return { iso: c.iso, dial: c.dial, name, search: fold(name) };
74
+ })
75
+ .sort((a, b) => collator.compare(a.name, b.name));
76
+ }, [locale, countries]);
77
+ const optionOf = (iso) => options.find((o) => o.iso === iso);
78
+ /* The country: controlled, chosen here, or from the value, the default or the locale. */
79
+ const initial = valueProp !== undefined ? valueProp : defaultValue;
80
+ const [chosen, setChosen] = React.useState(() => parsePhoneNumber(initial, defaultCountry?.toUpperCase())?.country.iso ?? null);
81
+ // The locale's region: en-US until hydrated without a locale (see useFormatLocale), then the browser's.
82
+ const fallbackCountry = phoneCountry(defaultCountry)?.iso ??
83
+ regionOfLocale(locale ?? (typeof navigator === "undefined" ? undefined : navigator.language)) ??
84
+ "US";
85
+ const countryIso = (countryProp && phoneCountry(countryProp)?.iso) || chosen || fallbackCountry;
86
+ const country = phoneCountry(countryIso) ?? phoneCountry("US");
87
+ const countryName = optionOf(country.iso)?.name ?? country.iso;
88
+ /*
89
+ * What has been typed: national digits (a trunk prefix included, as typed), or while a "+" is
90
+ * typed and no calling code matches yet, that text.
91
+ */
92
+ const [typed, setTyped] = React.useState(() => parsePhoneNumber(initial, country.iso)?.national ?? "");
93
+ const [pending, setPending] = React.useState(null);
94
+ const [announce, setAnnounce] = React.useState("");
95
+ const controlled = valueProp !== undefined;
96
+ const national = nationalNumber(typed, country);
97
+ const e164 = pending !== null ? null : toE164(country, national);
98
+ /** The last value reported: a controlled value that differs came from outside. */
99
+ const emitted = React.useRef(e164);
100
+ const [seen, setSeen] = React.useState(valueProp);
101
+ if (controlled && valueProp !== seen) {
102
+ setSeen(valueProp);
103
+ if ((valueProp ?? null) !== emitted.current) {
104
+ emitted.current = valueProp ?? null;
105
+ const parsed = parsePhoneNumber(valueProp, country.iso);
106
+ setPending(null);
107
+ setTyped(parsed?.national ?? "");
108
+ if (parsed && parsed.country.iso !== country.iso)
109
+ setChosen(parsed.country.iso);
110
+ }
111
+ }
112
+ const visible = React.useRef(null);
113
+ const visibleRefs = React.useMemo(() => mergeRefs(visible, refProp), [refProp]);
114
+ const valueInput = React.useRef(null);
115
+ const groupRef = React.useRef(null);
116
+ const caret = React.useRef(null);
117
+ const [, rerender] = React.useReducer((n) => n + 1, 0);
118
+ const report = (next, digits, nextPending) => {
119
+ const nsn = nationalNumber(digits, next);
120
+ const v = nextPending !== null ? null : toE164(next, nsn);
121
+ if (next.iso !== country.iso) {
122
+ if (!countryProp)
123
+ setChosen(next.iso);
124
+ onCountryChange?.(next.iso);
125
+ }
126
+ if (v === emitted.current)
127
+ return;
128
+ emitted.current = v;
129
+ onValueChange?.(v, {
130
+ country: next.iso,
131
+ nationalNumber: nsn,
132
+ valid: v !== null && checkPhoneLength(nsn, next) === "ok",
133
+ });
134
+ };
135
+ const shown = pending ?? formatNational(typed, country);
136
+ React.useLayoutEffect(() => {
137
+ const at = caret.current;
138
+ caret.current = null;
139
+ if (at !== null && visible.current && document.activeElement === visible.current)
140
+ visible.current.setSelectionRange(at, at);
141
+ });
142
+ /** Reads the field's new text: an international number switches the country. */
143
+ const take = (raw, caretAt) => {
144
+ const intl = internationalDigits(raw, country);
145
+ if (intl !== null) {
146
+ const digits = intl.slice(0, E164_MAX_DIGITS);
147
+ const split = splitInternational(digits, country.iso);
148
+ if (split) {
149
+ const allowed = !countries || countries.some((c) => c.toUpperCase() === split.country.iso);
150
+ if (allowed) {
151
+ setPending(null);
152
+ setTyped(split.national);
153
+ if (split.country.iso !== country.iso)
154
+ setAnnounce(text.countryChanged(optionOf(split.country.iso)?.name ?? split.country.iso));
155
+ caret.current = formatNational(split.national, split.country).length;
156
+ report(split.country, split.national, null);
157
+ return;
158
+ }
159
+ }
160
+ // No calling code yet, or one outside `countries`: the "+" and its digits, as typed.
161
+ setPending(`+${digits}`);
162
+ caret.current = digits.length + 1;
163
+ report(country, typed, `+${digits}`);
164
+ return;
165
+ }
166
+ const digits = phoneDigits(raw);
167
+ if (nationalNumber(digits, country).length > E164_MAX_DIGITS - country.dial.length) {
168
+ // Longer than any number can be: the keystroke is refused.
169
+ caret.current = caretAt === null ? null : Math.max(0, caretAt - (raw.length - shown.length));
170
+ rerender();
171
+ return;
172
+ }
173
+ const before = caretAt === null ? digits.length : phoneDigits(raw.slice(0, caretAt)).length;
174
+ setPending(null);
175
+ setTyped(digits);
176
+ caret.current = caretAfterDigits(formatNational(digits, country), before);
177
+ if (digits === typed)
178
+ rerender();
179
+ report(country, digits, null);
180
+ };
181
+ /* The validity message the Field shows. */
182
+ let message = "";
183
+ if (pending !== null && pending.length > 1)
184
+ message = text.unknownCode;
185
+ else if (national) {
186
+ const fit = checkPhoneLength(national, country);
187
+ if (fit === "short")
188
+ message = text.tooShort(countryName, country.dial);
189
+ else if (fit === "long")
190
+ message = text.tooLong(countryName, country.dial);
191
+ }
192
+ React.useLayoutEffect(() => {
193
+ visible.current?.setCustomValidity(disabledProp ? "" : message);
194
+ }, [message, disabledProp]);
195
+ useFormResetEffect(visible, () => {
196
+ if (controlled)
197
+ return;
198
+ const parsed = parsePhoneNumber(defaultValue, defaultCountry?.toUpperCase());
199
+ emitted.current = parsed ? toE164(parsed.country, parsed.national) : null;
200
+ setPending(null);
201
+ setTyped(parsed?.national ?? "");
202
+ if (!countryProp)
203
+ setChosen(parsed?.country.iso ?? null);
204
+ });
205
+ const pickCountry = (option) => {
206
+ if (!option)
207
+ return;
208
+ const next = phoneCountry(option.iso);
209
+ setPending(null);
210
+ report(next, typed, null);
211
+ // Back to the number, to go on typing it.
212
+ requestAnimationFrame(() => visible.current?.focus());
213
+ };
214
+ const filter = (option, query) => {
215
+ const q = fold(query.trim());
216
+ if (!q)
217
+ return true;
218
+ if (/^\+?[\d\s]+$/.test(q))
219
+ return option.dial.startsWith(q.replace(/\D/g, ""));
220
+ return option.search.includes(q) || option.iso.toLowerCase() === q;
221
+ };
222
+ const sizing = sizes[size];
223
+ const selected = optionOf(country.iso) ?? {
224
+ iso: country.iso,
225
+ dial: country.dial,
226
+ name: countryName,
227
+ search: "",
228
+ };
229
+ return (_jsx(BaseField.Control, { id: id, name: name, value: e164 ?? "", disabled: disabledProp, render: (control) => {
230
+ 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;
231
+ const off = Boolean(disabled);
232
+ return (_jsx("div", { "data-slot": "phone-input", "data-size": size, className: cn("w-full min-w-0", className), children: _jsxs(InputGroup, { ref: groupRef, size: sizing.group, ...state, className: sizing.className, children: [_jsx(InputGroupAddon, { align: "inline-start", className: "ps-[3px] group-data-[size=sm]/input-group:ps-0.5", children: _jsx(BaseField.Root, { disabled: off || readOnly, render: _jsx("span", { className: "contents" }), children: _jsxs(BaseCombobox.Root, { items: options, value: selected, onValueChange: pickCountry, isItemEqualToValue: (a, b) => a.iso === b.iso, itemToStringLabel: (o) => o.name, filter: filter, autoHighlight: true, children: [_jsxs(BaseCombobox.Trigger
233
+ // It stays an input-group-button, so the field rounds and insets it like any.
234
+ , { "data-phone-input-country": "", "aria-label": `${text.country}: ${countryName}, +${country.dial}`, render: _jsx(InputGroupButton, { variant: "ghost", size: sizing.button, ...(size === "lg" ? { "data-size": "lg" } : {}), className: cn(
235
+ // The field already dims when disabled: not the button twice.
236
+ "gap-1.5 font-mono tabular-nums data-disabled:opacity-100", size === "lg" && "min-h-[calc(var(--control-h-lg)-8px)] px-3 text-sm", size === "sm" ? "text-xs" : "text-[13px]",
237
+ // After the text size, which would reset it: one line as tall as the type.
238
+ "leading-none") }), children: [_jsx("span", { className: "text-muted-foreground", children: country.iso }), _jsxs("span", { className: "text-foreground", children: ["+", country.dial] }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5 text-muted-foreground transition-transform duration-(--duration) ease-(--ease) in-data-popup-open:rotate-180" })] }), _jsxs(ComboboxContent, { "aria-label": text.country, positioner: { anchor: groupRef, align: "start" }, className: "min-w-[min(18rem,var(--available-width))]", children: [_jsx("div", { className: "pb-1", children: _jsx(ComboboxInput, { size: "sm", showTrigger: false, placeholder: text.search, "aria-label": text.search }) }), _jsx(ComboboxEmpty, { children: text.empty }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, "data-country": option.iso, children: _jsxs("span", { className: "flex min-w-0 items-baseline gap-3", children: [_jsx("span", { className: "w-6 shrink-0 font-mono text-xs text-muted-foreground", children: option.iso }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: option.name }), _jsxs("span", { className: "shrink-0 font-mono text-xs text-muted-foreground tabular-nums", children: ["+", option.dial] })] }) }, option.iso)) })] })] }) }) }), _jsx("input", { ...props, ref: visibleRefs, id: controlId, "data-slot": "input-group-control", type: "tel", inputMode: "tel", autoComplete: props.autoComplete ?? "tel", value: shown, placeholder: placeholder, disabled: off, readOnly: readOnly, required: required, "aria-labelledby": labelledBy ?? props["aria-labelledby"], "aria-describedby": [describedBy, props["aria-describedby"]].filter(Boolean).join(" ") || undefined, "aria-invalid": invalid, onChange: (event) => take(event.currentTarget.value, event.currentTarget.selectionStart), onPaste: (event) => {
239
+ onPaste?.(event);
240
+ if (event.defaultPrevented || readOnly)
241
+ return;
242
+ const pasted = event.clipboardData.getData("text/plain");
243
+ // A whole international number replaces the field and picks its country.
244
+ if (internationalDigits(pasted, country) !== null) {
245
+ event.preventDefault();
246
+ take(pasted, null);
247
+ }
248
+ }, onKeyDown: (event) => {
249
+ onKeyDown?.(event);
250
+ if (event.defaultPrevented)
251
+ return;
252
+ // Backspace or Delete next to a space removes the digit beyond it, not the space
253
+ // (which the grouping would put straight back).
254
+ const input = event.currentTarget;
255
+ const at = input.selectionStart ?? 0;
256
+ if (at !== input.selectionEnd || readOnly)
257
+ return;
258
+ const back = event.key === "Backspace" && input.value[at - 1] === " ";
259
+ const forward = event.key === "Delete" && input.value[at] === " ";
260
+ if (!back && !forward)
261
+ return;
262
+ event.preventDefault();
263
+ const raw = back
264
+ ? input.value.slice(0, at - 2) + input.value.slice(at)
265
+ : input.value.slice(0, at) + input.value.slice(at + 2);
266
+ take(raw, back ? at - 2 : at);
267
+ }, onFocus: (event) => {
268
+ onFocus?.(event);
269
+ fieldFocus?.(event);
270
+ }, onBlur: (event) => {
271
+ // Left as read: the national number grouped, without the trunk prefix (+44 is beside it).
272
+ if (pending === null && national !== typed)
273
+ setTyped(national);
274
+ onBlur?.(event);
275
+ if (valueInput.current)
276
+ fieldBlur?.({
277
+ ...event,
278
+ currentTarget: valueInput.current,
279
+ });
280
+ }, 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", "ps-2 pe-3.5 group-data-[size=sm]/input-group:ps-1.5 group-data-[size=sm]/input-group:pe-2.5", size === "lg" && "pe-4") }), _jsx("span", { "aria-live": "polite", className: "sr-only", children: announce }), _jsx(FieldValueInput, { ref: ref, valueRef: valueInput, "data-slot": "phone-input-value", name: controlName, value: controlValue ?? "", onChange: fieldChange, required: required, disabled: off, message: off ? "" : message, onFocus: () => visible.current?.focus() })] }) }));
281
+ } }));
282
+ }
@@ -44,5 +44,5 @@ export function PopoverDescription({ className, ...props }) {
44
44
  }
45
45
  /** Closes the popover. Compose with a button: `render={<Button variant="ghost" size="sm" />}`. */
46
46
  export function PopoverClose(props) {
47
- return _jsx(BasePopover.Close, { "data-slot": "popover-close", ...props });
47
+ return _jsx(BasePopover.Close, { ...triggerSlot("popover-close", props.render), ...props });
48
48
  }
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Progress as BaseProgress } from "@base-ui/react/progress";
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",
@@ -17,7 +18,8 @@ const toneFill = {
17
18
  * static quantity (storage used, a score). That is a `Meter`.
18
19
  */
19
20
  export function Progress({ label, showValue = false, tone = "default", className, children, ...props }) {
20
- return (_jsxs(BaseProgress.Root, { "data-slot": "progress", "data-tone": tone, 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(BaseProgress.Label, { "data-slot": "progress-label",
21
+ const locale = useLocale();
22
+ return (_jsxs(BaseProgress.Root, { "data-slot": "progress", "data-tone": tone, 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(BaseProgress.Label, { "data-slot": "progress-label",
21
23
  // A long name (a file, a URL) wraps instead of pushing the track wider than its column.
22
24
  className: "col-start-1 font-mono text-[12px] [overflow-wrap:anywhere] text-foreground-soft", children: label })), showValue && (_jsx(BaseProgress.Value, { "data-slot": "progress-value", className: "col-start-2 text-end font-mono text-[12px] text-muted-foreground tabular-nums" })), _jsx(BaseProgress.Track, { "data-slot": "progress-track", className: "relative col-span-2 h-1.5 overflow-hidden rounded-full border border-field-edge bg-field-surface shadow-field", children: _jsx(BaseProgress.Indicator, { "data-slot": "progress-indicator", className: sx("block h-full rounded-full transition-[width,background-color] duration-(--duration) ease-(--ease)", toneFill[tone]) }) }), children] }));
23
25
  }
@@ -1,5 +1,28 @@
1
1
  import * as React from "react";
2
2
  import { InputGroupAddon, type InputGroupButtonProps, type InputGroupTextareaProps } from "./input-group.js";
3
+ export interface PromptInputMessages {
4
+ /** The textarea's placeholder. */
5
+ placeholder: string;
6
+ /** PromptInputSubmit, ready to send. */
7
+ send: string;
8
+ /** PromptInputSubmit while a reply streams in and it can be stopped. */
9
+ stop: string;
10
+ /** PromptInputSubmit after sending, before the reply. */
11
+ waiting: string;
12
+ /** PromptInputAttachButton's name. */
13
+ attach: string;
14
+ /** An attachment with no name of its own. */
15
+ attachment: string;
16
+ /** An attachment's remove button. */
17
+ removeAttachment: (name: string) => string;
18
+ /** An image attachment's thumbnail, which opens the preview. */
19
+ previewAttachment: (name: string) => string;
20
+ }
21
+ declare module "./locale" {
22
+ interface Messages {
23
+ promptInput: PromptInputMessages;
24
+ }
25
+ }
3
26
  /**
4
27
  * Where the reply is: `ready` (nothing running), `submitted` (sent, nothing back yet),
5
28
  * `streaming` (the reply is coming in) or `error` (the last one failed; the prompt can be sent again).
@@ -67,7 +90,10 @@ export interface PromptInputAttachmentProps extends Omit<React.ComponentProps<"d
67
90
  type?: string;
68
91
  /** Shows a remove button. */
69
92
  onRemove?: () => void;
70
- /** Accessible names. Defaults: `Remove <name>`, `Preview <name>`. */
93
+ /**
94
+ * Accessible names. Defaults: `Remove <name>`, `Preview <name>` — `messages.promptInput`
95
+ * `removeAttachment` and `previewAttachment` from a LocaleProvider.
96
+ */
71
97
  labels?: {
72
98
  remove?: string;
73
99
  preview?: string;
@@ -86,7 +112,7 @@ export interface PromptInputAttachButtonProps extends Omit<InputGroupButtonProps
86
112
  accept?: string;
87
113
  /** Allow picking several files. Default `true`. */
88
114
  multiple?: boolean;
89
- /** Accessible name. Default `Attach files`. */
115
+ /** Accessible name. Default `Attach files` (`messages.promptInput.attach`). */
90
116
  label?: string;
91
117
  }
92
118
  /** A ghost paperclip that opens the file picker. */
@@ -99,7 +125,7 @@ export interface PromptInputTextareaProps extends Omit<InputGroupTextareaProps,
99
125
  * content up to 240px and scrolls. Enter sends; Shift+Enter adds a line, and the Enter that
100
126
  * confirms an input method's text does not send. Pasted files go to the bar's `onFiles`.
101
127
  */
102
- export declare function PromptInputTextarea({ className, ref, onChange, onKeyDown, onPaste, placeholder, ...props }: PromptInputTextareaProps): React.JSX.Element;
128
+ export declare function PromptInputTextarea({ className, ref, onChange, onKeyDown, onPaste, placeholder: placeholderProp, ...props }: PromptInputTextareaProps): React.JSX.Element;
103
129
  /**
104
130
  * The tools and the send button. On one line they sit either side of the text; stacked, they
105
131
  * form the row under it.
@@ -117,12 +143,11 @@ export declare function PromptInputTools({ side, className, ...props }: PromptIn
117
143
  /** A tool in the toolbar (attach, search, a mode): ghost and 30px. Icon-only ones need `aria-label`. */
118
144
  export declare function PromptInputButton({ variant, size, children, ...props }: InputGroupButtonProps): React.JSX.Element;
119
145
  export interface PromptInputSubmitProps extends Omit<InputGroupButtonProps, "children"> {
120
- /** Accessible names. Defaults: `Send`, `Stop`, `Waiting for the reply`. */
121
- labels?: {
122
- send?: string;
123
- stop?: string;
124
- waiting?: string;
125
- };
146
+ /**
147
+ * Accessible names. Defaults: `Send`, `Stop`, `Waiting for the reply`; a LocaleProvider sets
148
+ * them for every PromptInputSubmit (`messages.promptInput`).
149
+ */
150
+ labels?: Partial<Pick<PromptInputMessages, "send" | "stop" | "waiting">>;
126
151
  }
127
152
  /**
128
153
  * The send button: round, primary, an arrow. While the reply is on its way it shows a spinner,
@@ -7,7 +7,18 @@ import { cssDuration } from "../lib/motion.js";
7
7
  import { mergeRefs } from "../lib/merge-refs.js";
8
8
  import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "./dialog.js";
9
9
  import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea, } from "./input-group.js";
10
+ import { useMessages } from "./locale.js";
10
11
  import { Spinner } from "./spinner.js";
12
+ const defaultMessages = {
13
+ placeholder: "Ask anything",
14
+ send: "Send",
15
+ stop: "Stop",
16
+ waiting: "Waiting for the reply",
17
+ attach: "Attach files",
18
+ attachment: "Attachment",
19
+ removeAttachment: (name) => `Remove ${name}`,
20
+ previewAttachment: (name) => `Preview ${name}`,
21
+ };
11
22
  const PromptInputContext = React.createContext(null);
12
23
  function usePromptInput(part) {
13
24
  const context = React.useContext(PromptInputContext);
@@ -18,18 +29,26 @@ function usePromptInput(part) {
18
29
  /* ── Motion helpers ────────────────────────────────────────────────────────── */
19
30
  const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
20
31
  /**
21
- * The morph's timing: two and a half times `--duration` on an even ease-in-out, so the bar is seen to grow
22
- * and settle (the brand ease front-loads a glide this size into one frame); none under reduced
23
- * motion.
32
+ * The morph's timing: 4/3 of `--duration` (200ms) on `--ease-glide`, an ease-out milder than the
33
+ * brand's, which would front-load a glide this size into one frame, so the bar is seen to grow and
34
+ * settle; none under reduced motion. It answers typing, so it stays short.
24
35
  */
25
36
  function morphTiming() {
26
37
  if (typeof document === "undefined" || reducedMotion())
27
38
  return null;
28
- const duration = cssDuration() * 2.5;
39
+ const duration = (cssDuration() * 4) / 3;
29
40
  if (!duration)
30
41
  return null;
31
- return { duration, easing: "cubic-bezier(0.65, 0, 0.35, 1)" };
42
+ const easing = getComputedStyle(document.documentElement).getPropertyValue("--ease-glide").trim() ||
43
+ "cubic-bezier(0.33, 1, 0.68, 1)";
44
+ return { duration, easing };
32
45
  }
46
+ /* The send button's three faces — arrow, spinner, stop — stacked in one grid cell, as CopyButton's
47
+ are: they cross-fade and scale from 0.85 on --duration (0 under reduced motion), so the button
48
+ never changes size or jumps between them. A face out of sight stops its animation. */
49
+ const submitFace = "col-start-1 row-start-1 grid place-items-center transition-[opacity,scale] duration-(--duration) ease-(--ease)";
50
+ const submitShown = "scale-100 opacity-100";
51
+ const submitHidden = "scale-[0.85] opacity-0 [&,&_*]:animate-none";
33
52
  let measureContext;
34
53
  /** The width of `text` on one line in the textarea's own font. */
35
54
  function lineWidth(text, el) {
@@ -284,24 +303,26 @@ function usePreview(file, src, image) {
284
303
  * key with its name. Both have a remove button.
285
304
  */
286
305
  export function PromptInputAttachment({ file, name: nameProp, src, type, onRemove, labels, className, ...props }) {
287
- const name = nameProp ?? file?.name ?? "Attachment";
306
+ const text = useMessages("promptInput", defaultMessages);
307
+ const name = nameProp ?? file?.name ?? text.attachment;
288
308
  const mime = type ?? file?.type;
289
309
  // A picture with something to show: an image without its file or URL yet is a chip.
290
310
  const image = (mime ? mime.startsWith("image/") : src != null || imageName(name)) && (src != null || file != null);
291
311
  const url = usePreview(file, src, image);
292
312
  // A 24px target, the inset size of a chip's remover. On a thumbnail it is a 20px raised disc on
293
313
  // the corner, the target reaching a little past the disc.
294
- const remove = onRemove && (_jsx("button", { type: "button", "data-slot": "prompt-input-attachment-remove", "aria-label": labels?.remove ?? `Remove ${name}`, onClick: onRemove, className: cn("inline-flex size-(--control-inset-sm) shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground focus-ring transition-[background-color,color] duration-(--duration) ease-(--ease) hover:text-foreground", image ? "absolute -end-2 -top-2 z-10" : "hover:bg-control-hover"), children: image ? (_jsx("span", { className: "inline-flex size-5 items-center justify-center rounded-full material-raised", children: _jsx(XIcon, { "aria-hidden": true, className: "size-3" }) })) : (_jsx(XIcon, { "aria-hidden": true, className: "size-3.5" })) }));
314
+ const remove = onRemove && (_jsx("button", { type: "button", "data-slot": "prompt-input-attachment-remove", "aria-label": labels?.remove ?? text.removeAttachment(name), onClick: onRemove, className: cn("inline-flex size-(--control-inset-sm) shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground focus-ring transition-[background-color,color] duration-(--duration) ease-(--ease) hover:text-foreground", image ? "absolute -end-2 -top-2 z-10" : "hover:bg-control-hover"), children: image ? (_jsx("span", { className: "inline-flex size-5 items-center justify-center rounded-full material-raised", children: _jsx(XIcon, { "aria-hidden": true, className: "size-3" }) })) : (_jsx(XIcon, { "aria-hidden": true, className: "size-3.5" })) }));
295
315
  if (image)
296
- return (_jsxs("div", { "data-slot": "prompt-input-attachment", "data-kind": "image", className: cn("relative size-14 shrink-0", className), ...props, children: [_jsxs(Dialog, { children: [_jsx(DialogTrigger, { "aria-label": labels?.preview ?? `Preview ${name}`, className: "block size-full cursor-zoom-in overflow-hidden rounded-item border border-field-edge bg-control-surface focus-ring", children: url && _jsx("img", { src: url, alt: "", draggable: false, className: "size-full object-cover" }) }), _jsxs(DialogContent, { size: "xl", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { className: "truncate font-mono text-sm", children: name }) }), url && (_jsx("img", { src: url, alt: name, className: "mx-auto block h-auto max-h-[min(70vh,calc(100dvh-12rem))] min-h-0 w-auto max-w-full rounded-item" }))] })] }), remove] }));
316
+ return (_jsxs("div", { "data-slot": "prompt-input-attachment", "data-kind": "image", className: cn("relative size-14 shrink-0", className), ...props, children: [_jsxs(Dialog, { children: [_jsx(DialogTrigger, { "aria-label": labels?.preview ?? text.previewAttachment(name), className: "block size-full cursor-zoom-in overflow-hidden rounded-item border border-field-edge bg-control-surface focus-ring", children: url && _jsx("img", { src: url, alt: "", draggable: false, className: "size-full object-cover" }) }), _jsxs(DialogContent, { size: "xl", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { className: "truncate font-mono text-sm", children: name }) }), url && (_jsx("img", { src: url, alt: name, className: "mx-auto block h-auto max-h-[min(70vh,calc(100dvh-12rem))] min-h-0 w-auto max-w-full rounded-item" }))] })] }), remove] }));
297
317
  const Icon = mime === "application/pdf" || /\.pdf$/i.test(name) ? FileTextIcon : PaperclipIcon;
298
318
  return (_jsxs("div", { "data-slot": "prompt-input-attachment", "data-kind": "file", className: cn("inline-flex min-h-(--control-inset-sm) max-w-56 items-center gap-1.5 rounded-item bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent ps-2 font-mono text-[11px] text-foreground shadow-key", onRemove ? "pe-0" : "pe-2", className), ...props, children: [_jsx(Icon, { "aria-hidden": true, className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "truncate", children: name }), remove] }));
299
319
  }
300
320
  /** A ghost paperclip that opens the file picker. */
301
- export function PromptInputAttachButton({ onFiles, accept, multiple = true, label = "Attach files", disabled, ...props }) {
321
+ export function PromptInputAttachButton({ onFiles, accept, multiple = true, label, disabled, ...props }) {
322
+ const text = useMessages("promptInput", defaultMessages);
302
323
  const input = React.useRef(null);
303
324
  const context = React.useContext(PromptInputContext);
304
- return (_jsxs(_Fragment, { children: [_jsx(PromptInputButton, { "aria-label": label, disabled: disabled ?? context?.disabled, onClick: () => input.current?.click(), ...props, children: _jsx(PaperclipIcon, {}) }), _jsx("input", { ref: input, type: "file", tabIndex: -1, "aria-hidden": true, hidden: true, accept: accept, multiple: multiple, onChange: (event) => {
325
+ return (_jsxs(_Fragment, { children: [_jsx(PromptInputButton, { "aria-label": label ?? text.attach, disabled: disabled ?? context?.disabled, onClick: () => input.current?.click(), ...props, children: _jsx(PaperclipIcon, {}) }), _jsx("input", { ref: input, type: "file", tabIndex: -1, "aria-hidden": true, hidden: true, accept: accept, multiple: multiple, onChange: (event) => {
305
326
  const files = [...(event.currentTarget.files ?? [])];
306
327
  event.currentTarget.value = "";
307
328
  if (files.length)
@@ -313,8 +334,10 @@ export function PromptInputAttachButton({ onFiles, accept, multiple = true, labe
313
334
  * content up to 240px and scrolls. Enter sends; Shift+Enter adds a line, and the Enter that
314
335
  * confirms an input method's text does not send. Pasted files go to the bar's `onFiles`.
315
336
  */
316
- export function PromptInputTextarea({ className, ref, onChange, onKeyDown, onPaste, placeholder = "Ask anything", ...props }) {
337
+ export function PromptInputTextarea({ className, ref, onChange, onKeyDown, onPaste, placeholder: placeholderProp, ...props }) {
317
338
  const { value, setValue, submit, disabled, layout, onFiles, textareaRef } = usePromptInput("PromptInputTextarea");
339
+ const text = useMessages("promptInput", defaultMessages);
340
+ const placeholder = placeholderProp === undefined ? text.placeholder : placeholderProp;
318
341
  const refs = React.useMemo(() => mergeRefs(textareaRef, ref), [textareaRef, ref]);
319
342
  // One row, and no wrapping while the bar is one line (Base UI's control does not type these).
320
343
  React.useLayoutEffect(() => {
@@ -386,11 +409,8 @@ export function PromptInputSubmit({ labels, className, onClick, ...props }) {
386
409
  const { value, status, disabled, allowEmpty, onStop } = usePromptInput("PromptInputSubmit");
387
410
  const busy = status === "submitted" || status === "streaming";
388
411
  const stop = busy && onStop != null;
389
- const label = stop
390
- ? (labels?.stop ?? "Stop")
391
- : busy
392
- ? (labels?.waiting ?? "Waiting for the reply")
393
- : (labels?.send ?? "Send");
412
+ const text = useMessages("promptInput", defaultMessages, labels);
413
+ const label = stop ? text.stop : busy ? text.waiting : text.send;
394
414
  return (_jsx("span", { "data-slot": "prompt-input-submit", "data-morph": "", className: "flex", children: _jsx(InputGroupButton, { "data-status": status, variant: "primary", size: "icon", type: stop ? "button" : "submit", "aria-label": label, disabled: disabled || (busy ? !stop : !allowEmpty && value.trim() === ""), onClick: (event) => {
395
415
  onClick?.(event);
396
416
  if (!stop || event.defaultPrevented)
@@ -399,5 +419,5 @@ export function PromptInputSubmit({ labels, className, onClick, ...props }) {
399
419
  // cancel it, or the form would send whatever is in the prompt.
400
420
  event.preventDefault();
401
421
  onStop();
402
- }, className: className, ...props, children: status === "streaming" && stop ? (_jsx(SquareIcon, { "aria-hidden": true, className: "size-3 fill-current" })) : busy ? (_jsx(Spinner, { size: "sm", "aria-hidden": true })) : (_jsx(ArrowUpIcon, { "aria-hidden": true })) }) }));
422
+ }, className: className, ...props, children: _jsxs("span", { "aria-hidden": true, "data-slot": "prompt-input-submit-icon", className: "grid", children: [_jsx("span", { className: cn(submitFace, busy ? submitHidden : submitShown), children: _jsx(ArrowUpIcon, {}) }), _jsx("span", { className: cn(submitFace, busy && !(status === "streaming" && stop) ? submitShown : submitHidden), children: _jsx(Spinner, { size: "sm", "aria-hidden": true }) }), _jsx("span", { className: cn(submitFace, status === "streaming" && stop ? submitShown : submitHidden), children: _jsx(SquareIcon, { className: "size-3 fill-current" }) })] }) }) }));
403
423
  }
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { Radio as BaseRadio } from "@base-ui/react/radio";
4
4
  import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
5
5
  import * as React from "react";
6
- import { sx } from "../lib/cn.js";
6
+ import { cn, sx } from "../lib/cn.js";
7
7
  import { useFormReset } from "../lib/form-reset.js";
8
8
  import { mergeRefs } from "../lib/merge-refs.js";
9
9
  /**
@@ -30,5 +30,10 @@ export function Radio({ className, ...props }) {
30
30
  "relative inline-flex size-[18px] shrink-0 material-field cursor-pointer items-center justify-center rounded-full p-0",
31
31
  "data-checked:border-transparent data-checked:bg-primary data-checked:bg-none data-checked:text-primary-foreground data-checked:shadow-checked",
32
32
  "data-readonly:cursor-default",
33
- ], className), ...props, children: _jsx(BaseRadio.Indicator, { "data-slot": "radio-indicator", className: "pointer-events-none flex items-center justify-center before:size-1.5 before:rounded-full before:bg-current" }) }));
33
+ ], className), ...props, children: _jsx(BaseRadio.Indicator, { "data-slot": "radio-indicator", className: cn(
34
+ // Its own ink, so the dot stays drawn while it leaves after the fill has gone.
35
+ "pointer-events-none flex items-center justify-center text-primary-foreground before:size-1.5 before:rounded-full before:bg-current",
36
+ // The dot grows in from half its size as the check draws in a Checkbox, and shrinks away
37
+ // on the exit duration; reduced motion keeps the fade.
38
+ "transition-[opacity,scale] [transition-duration:var(--duration-fade),var(--duration)] ease-(--ease)", "data-starting-style:scale-50 data-starting-style:opacity-0", "data-ending-style:scale-50 data-ending-style:opacity-0 data-ending-style:[transition-duration:calc(var(--duration-fade)*0.7),var(--duration-exit)]") }) }));
34
39
  }
@@ -0,0 +1,73 @@
1
+ import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
2
+ import * as React from "react";
3
+ export interface RatingMessages {
4
+ /** Each choice's name: "1 star", "4.5 stars". `value` is formatted for the locale. */
5
+ item: (value: string, count: number) => string;
6
+ /** A read-only rating, read out whole: "4.5 out of 5". */
7
+ value: (value: string, max: string) => string;
8
+ /** A read-only rating with no value yet. */
9
+ empty: string;
10
+ }
11
+ declare module "./locale" {
12
+ interface Messages {
13
+ rating: RatingMessages;
14
+ }
15
+ }
16
+ declare const sizes: {
17
+ readonly sm: {
18
+ readonly row: "h-(--control-h-sm)";
19
+ readonly item: "px-px";
20
+ readonly icon: "size-4";
21
+ };
22
+ readonly default: {
23
+ readonly row: "h-(--control-h)";
24
+ readonly item: "px-0.5";
25
+ readonly icon: "size-5";
26
+ };
27
+ readonly lg: {
28
+ readonly row: "h-(--control-h-lg)";
29
+ readonly item: "px-0.5";
30
+ readonly icon: "size-6";
31
+ };
32
+ };
33
+ export interface RatingProps extends Omit<BaseRadioGroup.Props<number | null>, "value" | "defaultValue" | "onValueChange" | "children"> {
34
+ /** The rating, `1`…`max` (halves with `allowHalf`); `null` is none. Leave `undefined` for an uncontrolled rating. */
35
+ value?: number | null;
36
+ defaultValue?: number | null;
37
+ onValueChange?: (value: number | null) => void;
38
+ /** How many stars. Default `5`. */
39
+ max?: number;
40
+ /** Half stars: each star is two choices, its start half and its end half. */
41
+ allowHalf?: boolean;
42
+ /** Picking the current rating again clears it, as Backspace and Delete do. */
43
+ clearable?: boolean;
44
+ /**
45
+ * Shows the rating without letting it change — an average under a product, a review's score.
46
+ * Any fraction is drawn (3.7 fills most of the fourth star) and it is read out as "3.7 out of 5".
47
+ */
48
+ readOnly?: boolean;
49
+ /** `sm` 30px, `default` 38px, `lg` 46px: the row is as tall as the controls beside it. */
50
+ size?: keyof typeof sizes;
51
+ /** Another icon in place of the star — a heart, a circle. It is drawn in outline and filled. */
52
+ icon?: React.ReactElement<{
53
+ className?: string;
54
+ fill?: string;
55
+ strokeWidth?: number;
56
+ }>;
57
+ /** Interface text; a LocaleProvider sets it for every Rating. */
58
+ labels?: Partial<RatingMessages>;
59
+ }
60
+ /**
61
+ * Rating — a score of 1 to 5 (or `max`) as a row of stars, in the foreground ink.
62
+ *
63
+ * A radio group under the hood: arrow keys move the rating and pick it, a pointer previews the
64
+ * stars it would set, and with `allowHalf` each star takes two picks. In a `Field` it submits
65
+ * its number under the field's name and takes `required` and the Field's invalid state. With
66
+ * `readOnly` it is a picture of a score, read out as "4.5 out of 5".
67
+ *
68
+ * The rule people break: yellow stars. The stars are ink like every other mark; a rating is a
69
+ * value, not a status. And put the count next to an average ("4.5 · 128 reviews"): five stars
70
+ * from one review is not the same thing.
71
+ */
72
+ export declare function Rating({ value: valueProp, defaultValue, onValueChange, max: maxProp, allowHalf, clearable, readOnly, disabled, size, icon, labels, className, ref, onKeyDown, ...props }: RatingProps): React.JSX.Element;
73
+ export {};