@zonsh/ui 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -42,14 +42,20 @@ const TRIGGER = '[data-slot="menubar-trigger"]';
|
|
|
42
42
|
const findOpen = (root) => root.querySelector(`${TRIGGER}[data-popup-open]`);
|
|
43
43
|
/** How long the surface waits for the next menu before it fades (ms). */
|
|
44
44
|
const HOLD = 90;
|
|
45
|
+
/** Frames the popup must hold still (no animation, same box) before the surface stops measuring. */
|
|
46
|
+
const SETTLED = 2;
|
|
45
47
|
const MenubarSurfaceContext = React.createContext(null);
|
|
46
48
|
/**
|
|
47
49
|
* The bar's menus share one surface, like NavigationMenu's viewport. Each menubar popup drops its
|
|
48
50
|
* own material (`data-surface`) and this fixed element, carrying the menu material, follows the
|
|
49
|
-
* open popup every frame
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* open popup. It measures every frame only while the popup moves — opening, closing, its fade on a
|
|
52
|
+
* switch, or until Base UI has placed it — and rests once the popup's box has held still with no
|
|
53
|
+
* animation running; observers on the popup's attributes, its positioner's style (Base UI moves
|
|
54
|
+
* it on scroll and resize) and its size start it again. Opening and closing it simply tracks the
|
|
55
|
+
* popup's own motion; moving to a neighbouring menu turns on `data-switching`, so position and
|
|
56
|
+
* size glide over 2 × --duration — CSS transitions start from wherever they are, which keeps quick
|
|
57
|
+
* back-and-forth smooth — while the new items fade in. Reduced motion sets --duration to 0, so it
|
|
58
|
+
* jumps.
|
|
53
59
|
*/
|
|
54
60
|
function useMenuSurface() {
|
|
55
61
|
const surfaceRef = React.useRef(null);
|
|
@@ -59,6 +65,32 @@ function useMenuSurface() {
|
|
|
59
65
|
let lostAt = 0;
|
|
60
66
|
let frame = 0;
|
|
61
67
|
let settle = 0;
|
|
68
|
+
let still = 0;
|
|
69
|
+
let last = "";
|
|
70
|
+
let observers = [];
|
|
71
|
+
const kick = () => {
|
|
72
|
+
still = 0;
|
|
73
|
+
if (!frame && typeof requestAnimationFrame === "function")
|
|
74
|
+
frame = requestAnimationFrame(follow);
|
|
75
|
+
};
|
|
76
|
+
const watch = (popup) => {
|
|
77
|
+
observers.forEach((observer) => observer.disconnect());
|
|
78
|
+
observers = [];
|
|
79
|
+
if (!popup)
|
|
80
|
+
return;
|
|
81
|
+
if (typeof MutationObserver === "function") {
|
|
82
|
+
const mutations = new MutationObserver(kick);
|
|
83
|
+
mutations.observe(popup, { attributes: true });
|
|
84
|
+
if (popup.parentElement)
|
|
85
|
+
mutations.observe(popup.parentElement, { attributes: true, attributeFilter: ["style"] });
|
|
86
|
+
observers.push(mutations);
|
|
87
|
+
}
|
|
88
|
+
if (typeof ResizeObserver === "function") {
|
|
89
|
+
const sizes = new ResizeObserver(kick);
|
|
90
|
+
sizes.observe(popup);
|
|
91
|
+
observers.push(sizes);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
62
94
|
const follow = () => {
|
|
63
95
|
frame = 0;
|
|
64
96
|
const surface = surfaceRef.current;
|
|
@@ -78,8 +110,10 @@ function useMenuSurface() {
|
|
|
78
110
|
surface.removeAttribute("data-visible");
|
|
79
111
|
if (active?.isConnected)
|
|
80
112
|
frame = requestAnimationFrame(follow);
|
|
81
|
-
else
|
|
113
|
+
else {
|
|
82
114
|
active = null;
|
|
115
|
+
watch(null);
|
|
116
|
+
}
|
|
83
117
|
return;
|
|
84
118
|
}
|
|
85
119
|
lostAt = 0;
|
|
@@ -88,16 +122,24 @@ function useMenuSurface() {
|
|
|
88
122
|
surface.style.width = `${r.width}px`;
|
|
89
123
|
surface.style.height = `${r.height}px`;
|
|
90
124
|
surface.setAttribute("data-visible", "");
|
|
91
|
-
|
|
125
|
+
// Keep measuring while the popup animates or has not yet held its box for a few frames.
|
|
126
|
+
const box = `${r.left},${r.top},${r.width},${r.height}`;
|
|
127
|
+
const moving = active.hasAttribute("data-starting-style") ||
|
|
128
|
+
(active.getAnimations?.().length ?? 0) > 0 ||
|
|
129
|
+
box !== last;
|
|
130
|
+
last = box;
|
|
131
|
+
still = moving ? 0 : still + 1;
|
|
132
|
+
if (still < SETTLED)
|
|
133
|
+
frame = requestAnimationFrame(follow);
|
|
92
134
|
};
|
|
93
135
|
return {
|
|
136
|
+
kick,
|
|
94
137
|
open(popup) {
|
|
95
138
|
const surface = surfaceRef.current;
|
|
96
139
|
popup.setAttribute("data-surface", "");
|
|
97
140
|
// Refs re-attach on re-render: the same popup again changes nothing.
|
|
98
141
|
if (popup === active) {
|
|
99
|
-
|
|
100
|
-
frame = requestAnimationFrame(follow);
|
|
142
|
+
kick();
|
|
101
143
|
return;
|
|
102
144
|
}
|
|
103
145
|
const switching = !!surface?.hasAttribute("data-visible") && !!active && active !== popup;
|
|
@@ -112,6 +154,7 @@ function useMenuSurface() {
|
|
|
112
154
|
popups.add(popup);
|
|
113
155
|
popup.style.visibility = "";
|
|
114
156
|
active = popup;
|
|
157
|
+
watch(popup);
|
|
115
158
|
lostAt = 0;
|
|
116
159
|
if (surface && switching) {
|
|
117
160
|
const duration = cssDuration(surface) * 2;
|
|
@@ -122,14 +165,13 @@ function useMenuSurface() {
|
|
|
122
165
|
popup.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
123
166
|
duration: duration * 0.6,
|
|
124
167
|
delay: duration * 0.15,
|
|
125
|
-
easing: "ease-out",
|
|
168
|
+
easing: getComputedStyle(surface).getPropertyValue("--ease").trim() || "ease-out",
|
|
126
169
|
fill: "backwards",
|
|
127
170
|
});
|
|
128
171
|
}
|
|
129
172
|
}
|
|
130
173
|
// Base UI positions the popup in a layout effect after it mounts: measure from the next frame.
|
|
131
|
-
|
|
132
|
-
frame = requestAnimationFrame(follow);
|
|
174
|
+
kick();
|
|
133
175
|
},
|
|
134
176
|
};
|
|
135
177
|
}, []);
|
|
@@ -139,8 +181,13 @@ function useMenuSurface() {
|
|
|
139
181
|
function useSurfacePopup() {
|
|
140
182
|
const surface = React.useContext(MenubarSurfaceContext);
|
|
141
183
|
return React.useCallback((node) => {
|
|
142
|
-
if (surface
|
|
143
|
-
|
|
184
|
+
if (!surface)
|
|
185
|
+
return;
|
|
186
|
+
// Leaving: the surface looks once more, sees the popup gone and fades.
|
|
187
|
+
if (!node)
|
|
188
|
+
return surface.kick();
|
|
189
|
+
surface.open(node);
|
|
190
|
+
return () => surface.kick();
|
|
144
191
|
}, [surface]);
|
|
145
192
|
}
|
|
146
193
|
/**
|
|
@@ -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
|
|
11
|
-
* card, sized to its text; an **assistant**
|
|
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
|
|
11
|
-
* card, sized to its text; an **assistant**
|
|
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
|
-
|
|
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,11 @@ 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("-
|
|
49
|
-
// User actions appear on hover or focus, so a long thread stays quiet.
|
|
51
|
+
return (_jsx("div", { "data-slot": "message-actions", className: cn("-ms-1.5 flex items-center gap-0.5",
|
|
52
|
+
// User actions appear on hover or focus, so a long thread stays quiet. A touch screen has
|
|
53
|
+
// no hover, and an invisible button would still take the tap: there they always show.
|
|
50
54
|
from === "user" &&
|
|
51
|
-
"-
|
|
55
|
+
"ms-0 -me-1.5 opacity-0 transition-opacity duration-(--duration-fade) ease-(--ease) group-focus-within/message:opacity-100 group-hover/message:opacity-100 pointer-coarse:opacity-100", className), ...props }));
|
|
52
56
|
}
|
|
53
57
|
/** One action under a message: a 30px ghost icon button with a tooltip. */
|
|
54
58
|
export function MessageAction({ label, className, children, ...props }) {
|
package/dist/components/meter.js
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|
|
@@ -20,12 +20,14 @@ export function NavigationMenu({ variant = "text", positioner, className, childr
|
|
|
20
20
|
const popupDir = usePopupDir(dir);
|
|
21
21
|
return (_jsxs(BaseNavigationMenu.Root, { "data-slot": "navigation-menu", "data-variant": variant, dir: dir, className: sx("relative", className), ...props, children: [_jsx(VariantContext.Provider, { value: variant, children: children }), _jsx(BaseNavigationMenu.Portal, { children: _jsx(BaseNavigationMenu.Positioner, { sideOffset: 8, collisionPadding: { top: 8, bottom: 8, left: 16, right: 16 }, collisionAvoidance: { side: "none" }, dir: popupDir, ...positioner, className: sx([
|
|
22
22
|
"z-50 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) outline-none",
|
|
23
|
-
|
|
23
|
+
// Moving from one item's panel to the next is a move the interface makes on its own: ease in and out.
|
|
24
|
+
"transition-[top,left,right,bottom] duration-(--duration) ease-(--ease-move) data-instant:transition-none",
|
|
24
25
|
// Hover bridge across the side offset so the pointer can travel into the popup.
|
|
25
26
|
"before:absolute before:content-[''] data-[side=bottom]:before:inset-x-0 data-[side=bottom]:before:-top-2 data-[side=bottom]:before:h-2 data-[side=top]:before:inset-x-0 data-[side=top]:before:-bottom-2 data-[side=top]:before:h-2",
|
|
26
27
|
], positioner?.className), children: _jsx(BaseNavigationMenu.Popup, { "data-slot": "navigation-menu-popup", className: [
|
|
27
28
|
"relative h-(--popup-height) w-(--popup-width) origin-(--transform-origin) overflow-hidden rounded-button material-menu outline-none",
|
|
28
|
-
|
|
29
|
+
// Opening and closing (opacity, scale) eases out; the size morph between panels eases in and out.
|
|
30
|
+
"transition-[opacity,scale,width,height] duration-(--duration) ease-[var(--ease),var(--ease),var(--ease-move),var(--ease-move)]",
|
|
29
31
|
"data-ending-style:scale-[0.97] data-ending-style:opacity-0 data-starting-style:scale-[0.97] data-starting-style:opacity-0",
|
|
30
32
|
].join(" "), children: _jsx(BaseNavigationMenu.Viewport, { "data-slot": "navigation-menu-viewport", className: "relative h-full w-full overflow-hidden" }) }) }) })] }));
|
|
31
33
|
}
|
|
@@ -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
|
-
/**
|
|
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 {};
|