@seekalfred/primitives 0.6.0 → 0.7.3
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/README.md +214 -15
- package/dist/activity-heatmap/activity-heatmap.d.ts +92 -0
- package/dist/activity-heatmap/activity-heatmap.js +699 -0
- package/dist/activity-heatmap/activity-heatmap.js.map +1 -0
- package/dist/activity-heatmap/index.d.ts +2 -0
- package/dist/activity-heatmap/index.js +2 -0
- package/dist/alert/alert.d.ts +53 -4
- package/dist/alert/alert.js +100 -11
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +58 -18
- package/dist/alert-dialog/alert-dialog.js +152 -9
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/alert-dialog/index.d.ts +2 -2
- package/dist/alert-dialog/index.js +2 -2
- package/dist/animated-counter/animated-counter.d.ts +38 -0
- package/dist/animated-counter/animated-counter.js +230 -0
- package/dist/animated-counter/animated-counter.js.map +1 -0
- package/dist/animated-counter/index.d.ts +2 -0
- package/dist/animated-counter/index.js +2 -0
- package/dist/announcement-bar/announcement-bar.d.ts +67 -0
- package/dist/announcement-bar/announcement-bar.js +364 -0
- package/dist/announcement-bar/announcement-bar.js.map +1 -0
- package/dist/announcement-bar/index.d.ts +2 -0
- package/dist/announcement-bar/index.js +2 -0
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart.d.ts +51 -0
- package/dist/bar-chart/bar-chart.js +565 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/index.d.ts +2 -0
- package/dist/bar-chart/index.js +2 -0
- package/dist/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/breadcrumb/breadcrumb.js +12 -3
- package/dist/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/brush-chart/brush-chart.d.ts +64 -0
- package/dist/brush-chart/brush-chart.js +1056 -0
- package/dist/brush-chart/brush-chart.js.map +1 -0
- package/dist/brush-chart/index.d.ts +2 -0
- package/dist/brush-chart/index.js +2 -0
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button.js +31 -21
- package/dist/button/button.js.map +1 -1
- package/dist/button-group/button-group.js +3 -4
- package/dist/button-group/button-group.js.map +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/card-stack/card-stack.d.ts +54 -0
- package/dist/card-stack/card-stack.js +492 -0
- package/dist/card-stack/card-stack.js.map +1 -0
- package/dist/card-stack/index.d.ts +2 -0
- package/dist/card-stack/index.js +2 -0
- package/dist/carousel/carousel.d.ts +77 -0
- package/dist/carousel/carousel.js +415 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/carousel/index.d.ts +2 -0
- package/dist/carousel/index.js +2 -0
- package/dist/checkbox/checkbox.js +4 -4
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +37 -0
- package/dist/chip-group/chip-group.js +148 -0
- package/dist/chip-group/chip-group.js.map +1 -0
- package/dist/chip-group/index.d.ts +2 -0
- package/dist/chip-group/index.js +2 -0
- package/dist/copy-button/copy-button.d.ts +18 -2
- package/dist/copy-button/copy-button.js +29 -8
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/countdown/countdown.d.ts +45 -0
- package/dist/countdown/countdown.js +298 -0
- package/dist/countdown/countdown.js.map +1 -0
- package/dist/countdown/index.d.ts +2 -0
- package/dist/countdown/index.js +2 -0
- package/dist/date-picker/picker-parts.js +1 -1
- package/dist/date-picker/picker-parts.js.map +1 -1
- package/dist/dialog/dialog.js +1 -1
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +86 -0
- package/dist/donut-chart/donut-chart.js +593 -0
- package/dist/donut-chart/donut-chart.js.map +1 -0
- package/dist/donut-chart/index.d.ts +2 -0
- package/dist/donut-chart/index.js +2 -0
- package/dist/empty-state/empty-state.d.ts +42 -10
- package/dist/empty-state/empty-state.js +44 -26
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.js +1 -1
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +50 -26
- package/dist/filter-bar/filter-bar.js +317 -157
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +45 -0
- package/dist/gauge/gauge.js +219 -0
- package/dist/gauge/gauge.js.map +1 -0
- package/dist/gauge/index.d.ts +2 -0
- package/dist/gauge/index.js +2 -0
- package/dist/in-view-title/in-view-title.d.ts +33 -0
- package/dist/in-view-title/in-view-title.js +119 -0
- package/dist/in-view-title/in-view-title.js.map +1 -0
- package/dist/in-view-title/index.d.ts +2 -0
- package/dist/in-view-title/index.js +2 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.js +52 -12
- package/dist/input/input.js +4 -4
- package/dist/input/input.js.map +1 -1
- package/dist/lib/cn.js +11 -1
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/field-message.js +28 -10
- package/dist/lib/field-message.js.map +1 -1
- package/dist/lib/field-shell.js +10 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +31 -9
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/flag-emoji.js +50 -0
- package/dist/lib/flag-emoji.js.map +1 -0
- package/dist/lib/flip.js +11 -3
- package/dist/lib/flip.js.map +1 -1
- package/dist/lib/menu-highlight.js +64 -0
- package/dist/lib/menu-highlight.js.map +1 -0
- package/dist/lib/motion.js +9 -2
- package/dist/lib/motion.js.map +1 -1
- package/dist/lib/rolling-value.js +1 -1
- package/dist/lib/rolling-value.js.map +1 -1
- package/dist/lib/spring-tween.js +500 -0
- package/dist/lib/spring-tween.js.map +1 -0
- package/dist/lib/swap-text.js +3 -1
- package/dist/lib/swap-text.js.map +1 -1
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -0
- package/dist/line-chart/index.js +2 -0
- package/dist/line-chart/line-chart.d.ts +116 -0
- package/dist/line-chart/line-chart.js +740 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/mention-input/index.d.ts +2 -0
- package/dist/mention-input/index.js +2 -0
- package/dist/mention-input/mention-input.d.ts +98 -0
- package/dist/mention-input/mention-input.js +576 -0
- package/dist/mention-input/mention-input.js.map +1 -0
- package/dist/menu/menu.d.ts +2 -0
- package/dist/menu/menu.js +23 -12
- package/dist/menu/menu.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -0
- package/dist/money-input/index.js +2 -0
- package/dist/money-input/money-input.d.ts +86 -0
- package/dist/money-input/money-input.js +613 -0
- package/dist/money-input/money-input.js.map +1 -0
- package/dist/morph-select/index.d.ts +2 -0
- package/dist/morph-select/index.js +2 -0
- package/dist/morph-select/morph-select.d.ts +89 -0
- package/dist/morph-select/morph-select.js +712 -0
- package/dist/morph-select/morph-select.js.map +1 -0
- package/dist/multi-select/index.d.ts +2 -0
- package/dist/multi-select/index.js +2 -0
- package/dist/multi-select/multi-select.d.ts +77 -0
- package/dist/multi-select/multi-select.js +209 -0
- package/dist/multi-select/multi-select.js.map +1 -0
- package/dist/number-field/index.d.ts +2 -0
- package/dist/number-field/index.js +2 -0
- package/dist/number-field/number-field.d.ts +42 -0
- package/dist/number-field/number-field.js +199 -0
- package/dist/number-field/number-field.js.map +1 -0
- package/dist/onboarding-checklist/index.d.ts +2 -0
- package/dist/onboarding-checklist/index.js +2 -0
- package/dist/onboarding-checklist/onboarding-checklist.d.ts +55 -0
- package/dist/onboarding-checklist/onboarding-checklist.js +577 -0
- package/dist/onboarding-checklist/onboarding-checklist.js.map +1 -0
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +39 -10
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/phone-input/index.d.ts +3 -0
- package/dist/phone-input/index.js +3 -0
- package/dist/phone-input/phone-countries.d.ts +29 -0
- package/dist/phone-input/phone-countries.js +170 -0
- package/dist/phone-input/phone-countries.js.map +1 -0
- package/dist/phone-input/phone-input.d.ts +66 -0
- package/dist/phone-input/phone-input.js +440 -0
- package/dist/phone-input/phone-input.js.map +1 -0
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +51 -2
- package/dist/popover/popover.js +59 -8
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/progress.d.ts +16 -2
- package/dist/progress/progress.js +16 -9
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +110 -10
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/reactions/index.d.ts +2 -0
- package/dist/reactions/index.js +2 -0
- package/dist/reactions/reactions.d.ts +50 -0
- package/dist/reactions/reactions.js +315 -0
- package/dist/reactions/reactions.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +3 -0
- package/dist/rich-text-editor/index.js +2 -0
- package/dist/rich-text-editor/rich-text-editor.d.ts +70 -0
- package/dist/rich-text-editor/rich-text-editor.js +909 -0
- package/dist/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/rich-text-editor/rich-text-engine.d.ts +16 -0
- package/dist/rich-text-editor/rich-text-engine.js +366 -0
- package/dist/rich-text-editor/rich-text-engine.js.map +1 -0
- package/dist/rich-text-editor/rich-text-html.js +174 -0
- package/dist/rich-text-editor/rich-text-html.js.map +1 -0
- package/dist/rich-text-editor/rich-text-icons.js +43 -0
- package/dist/rich-text-editor/rich-text-icons.js.map +1 -0
- package/dist/ridgeline/index.d.ts +2 -0
- package/dist/ridgeline/index.js +2 -0
- package/dist/ridgeline/ridgeline.d.ts +55 -0
- package/dist/ridgeline/ridgeline.js +701 -0
- package/dist/ridgeline/ridgeline.js.map +1 -0
- package/dist/scroll-area/index.d.ts +2 -2
- package/dist/scroll-area/index.js +2 -2
- package/dist/scroll-area/scroll-area.d.ts +68 -31
- package/dist/scroll-area/scroll-area.js +212 -62
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/evaluate.d.ts +14 -0
- package/dist/scrub-input/evaluate.js +72 -0
- package/dist/scrub-input/evaluate.js.map +1 -0
- package/dist/scrub-input/index.d.ts +3 -0
- package/dist/scrub-input/index.js +3 -0
- package/dist/scrub-input/scrub-input.d.ts +74 -0
- package/dist/scrub-input/scrub-input.js +486 -0
- package/dist/scrub-input/scrub-input.js.map +1 -0
- package/dist/search-field/search-field.d.ts +24 -2
- package/dist/search-field/search-field.js +24 -9
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +3 -1
- package/dist/select/select.js +28 -14
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +22 -10
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sheet/sheet.js +2 -1
- package/dist/sheet/sheet.js.map +1 -1
- package/dist/shortcut-recorder/index.d.ts +3 -0
- package/dist/shortcut-recorder/index.js +3 -0
- package/dist/shortcut-recorder/shortcut-model.d.ts +27 -0
- package/dist/shortcut-recorder/shortcut-model.js +206 -0
- package/dist/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/shortcut-recorder/shortcut-recorder.d.ts +93 -0
- package/dist/shortcut-recorder/shortcut-recorder.js +489 -0
- package/dist/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/slider/index.d.ts +2 -2
- package/dist/slider/slider.d.ts +46 -14
- package/dist/slider/slider.js +151 -67
- package/dist/slider/slider.js.map +1 -1
- package/dist/slope-chart/index.d.ts +2 -0
- package/dist/slope-chart/index.js +2 -0
- package/dist/slope-chart/slope-chart.d.ts +54 -0
- package/dist/slope-chart/slope-chart.js +568 -0
- package/dist/slope-chart/slope-chart.js.map +1 -0
- package/dist/sparkline/index.d.ts +2 -0
- package/dist/sparkline/index.js +2 -0
- package/dist/sparkline/sparkline.d.ts +46 -0
- package/dist/sparkline/sparkline.js +390 -0
- package/dist/sparkline/sparkline.js.map +1 -0
- package/dist/split-bar/index.d.ts +2 -0
- package/dist/split-bar/index.js +2 -0
- package/dist/split-bar/split-bar.d.ts +62 -0
- package/dist/split-bar/split-bar.js +513 -0
- package/dist/split-bar/split-bar.js.map +1 -0
- package/dist/split-button/split-button.d.ts +1 -1
- package/dist/split-button/split-button.js +12 -11
- package/dist/split-button/split-button.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +58 -5
- package/dist/stat-card/stat-card.js +144 -17
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/stepper/index.d.ts +2 -0
- package/dist/stepper/index.js +2 -0
- package/dist/stepper/stepper.d.ts +51 -0
- package/dist/stepper/stepper.js +215 -0
- package/dist/stepper/stepper.js.map +1 -0
- package/dist/streamgraph/index.d.ts +2 -0
- package/dist/streamgraph/index.js +2 -0
- package/dist/streamgraph/streamgraph.d.ts +70 -0
- package/dist/streamgraph/streamgraph.js +613 -0
- package/dist/streamgraph/streamgraph.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/swipe-actions/index.d.ts +2 -0
- package/dist/swipe-actions/index.js +2 -0
- package/dist/swipe-actions/swipe-actions.d.ts +67 -0
- package/dist/swipe-actions/swipe-actions.js +552 -0
- package/dist/swipe-actions/swipe-actions.js.map +1 -0
- package/dist/switch/switch.js +2 -2
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +55 -3
- package/dist/table/table.js +340 -165
- package/dist/table/table.js.map +1 -1
- package/dist/tabs/tabs.js +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tag-input/index.d.ts +2 -0
- package/dist/tag-input/index.js +2 -0
- package/dist/tag-input/tag-input.d.ts +40 -0
- package/dist/tag-input/tag-input.js +269 -0
- package/dist/tag-input/tag-input.js.map +1 -0
- package/dist/text-morph/index.d.ts +2 -0
- package/dist/text-morph/index.js +2 -0
- package/dist/text-morph/text-morph.d.ts +23 -0
- package/dist/text-morph/text-morph.js +21 -0
- package/dist/text-morph/text-morph.js.map +1 -0
- package/dist/text-reveal/index.d.ts +2 -0
- package/dist/text-reveal/index.js +2 -0
- package/dist/text-reveal/text-reveal.d.ts +27 -0
- package/dist/text-reveal/text-reveal.js +51 -0
- package/dist/text-reveal/text-reveal.js.map +1 -0
- package/dist/text-shimmer/index.d.ts +2 -0
- package/dist/text-shimmer/index.js +2 -0
- package/dist/text-shimmer/text-shimmer.d.ts +29 -0
- package/dist/text-shimmer/text-shimmer.js +29 -0
- package/dist/text-shimmer/text-shimmer.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +35 -7
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/index.d.ts +2 -2
- package/dist/toast/index.js +2 -2
- package/dist/toast/toast.d.ts +7 -1
- package/dist/toast/toast.js +82 -40
- package/dist/toast/toast.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +9 -2
- package/dist/tooltip/tooltip.js +7 -7
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/treemap/index.d.ts +2 -0
- package/dist/treemap/index.js +2 -0
- package/dist/treemap/treemap.d.ts +53 -0
- package/dist/treemap/treemap.js +699 -0
- package/dist/treemap/treemap.js.map +1 -0
- package/dist/usage-meter/index.d.ts +2 -0
- package/dist/usage-meter/index.js +2 -0
- package/dist/usage-meter/usage-meter.d.ts +80 -0
- package/dist/usage-meter/usage-meter.js +458 -0
- package/dist/usage-meter/usage-meter.js.map +1 -0
- package/dist/waffle-chart/index.d.ts +2 -0
- package/dist/waffle-chart/index.js +2 -0
- package/dist/waffle-chart/waffle-chart.d.ts +57 -0
- package/dist/waffle-chart/waffle-chart.js +426 -0
- package/dist/waffle-chart/waffle-chart.js.map +1 -0
- package/package.json +165 -3
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn, cnAll } from "../lib/cn.js";
|
|
3
|
+
import { useIsomorphicLayoutEffect, useMorphWidth } from "../lib/motion.js";
|
|
4
|
+
import { Button as Button$1 } from "../button/button.js";
|
|
5
|
+
import { SwapText } from "../lib/swap-text.js";
|
|
6
|
+
import { fieldSurfaceVariants } from "../lib/field-surface.js";
|
|
7
|
+
import { FieldMessage, RollingNumber } from "../lib/field-message.js";
|
|
8
|
+
import { FieldShell, useFieldWiring } from "../lib/field-shell.js";
|
|
9
|
+
import { SelectItem, selectPopoverVariants } from "../select/select.js";
|
|
10
|
+
import { forwardRef, useCallback, useId, useImperativeHandle, useMemo, useReducer, useRef, useState } from "react";
|
|
11
|
+
import { Button, Group, Input, ListBox, Popover, Select, SelectValue } from "react-aria-components";
|
|
12
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
//#region src/money-input/money-input.tsx
|
|
14
|
+
const MAX_INTEGER_DIGITS = 12;
|
|
15
|
+
/** How far, in px, the amount is pushed toward a limit it just met. */
|
|
16
|
+
const STRAIN_PX = 6;
|
|
17
|
+
const infoCache = /* @__PURE__ */ new Map();
|
|
18
|
+
function currencyInfo(code, locale) {
|
|
19
|
+
const cacheKey = `${locale}:${code}`;
|
|
20
|
+
const cached = infoCache.get(cacheKey);
|
|
21
|
+
if (cached) return cached;
|
|
22
|
+
const full = new Intl.NumberFormat(locale, {
|
|
23
|
+
style: "currency",
|
|
24
|
+
currency: code,
|
|
25
|
+
currencyDisplay: "narrowSymbol",
|
|
26
|
+
numberingSystem: "latn"
|
|
27
|
+
});
|
|
28
|
+
const parts = full.formatToParts(1);
|
|
29
|
+
const symbolAt = parts.findIndex((part) => part.type === "currency");
|
|
30
|
+
const numberAt = parts.findIndex((part) => part.type === "integer");
|
|
31
|
+
const digits = full.resolvedOptions().maximumFractionDigits ?? 2;
|
|
32
|
+
let name = code;
|
|
33
|
+
try {
|
|
34
|
+
name = new Intl.DisplayNames([locale], { type: "currency" }).of(code) ?? code;
|
|
35
|
+
} catch {}
|
|
36
|
+
const info = {
|
|
37
|
+
code,
|
|
38
|
+
symbol: parts[symbolAt]?.value ?? code,
|
|
39
|
+
position: symbolAt < numberAt ? "prefix" : "suffix",
|
|
40
|
+
digits,
|
|
41
|
+
name: name.charAt(0).toUpperCase() + name.slice(1),
|
|
42
|
+
full,
|
|
43
|
+
whole: new Intl.NumberFormat(locale, {
|
|
44
|
+
style: "currency",
|
|
45
|
+
currency: code,
|
|
46
|
+
currencyDisplay: "narrowSymbol",
|
|
47
|
+
maximumFractionDigits: 0,
|
|
48
|
+
numberingSystem: "latn"
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
infoCache.set(cacheKey, info);
|
|
52
|
+
return info;
|
|
53
|
+
}
|
|
54
|
+
function localeSymbols(locale) {
|
|
55
|
+
const parts = new Intl.NumberFormat(locale, { numberingSystem: "latn" }).formatToParts(12345.6);
|
|
56
|
+
return {
|
|
57
|
+
group: parts.find((part) => part.type === "group")?.value ?? ",",
|
|
58
|
+
decimal: parts.find((part) => part.type === "decimal")?.value ?? "."
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const pow10 = (digits) => 10 ** digits;
|
|
62
|
+
function toMinor(draft, digits) {
|
|
63
|
+
if (!draft) return null;
|
|
64
|
+
const [whole, fraction = ""] = draft.split(".");
|
|
65
|
+
return Number(whole || "0") * pow10(digits) + Number(fraction.padEnd(digits, "0").slice(0, digits) || "0");
|
|
66
|
+
}
|
|
67
|
+
function fromMinor(minor, digits) {
|
|
68
|
+
if (minor === null || minor === void 0 || !Number.isFinite(minor)) return "";
|
|
69
|
+
const text = String(Math.round(Math.abs(minor))).padStart(digits + 1, "0");
|
|
70
|
+
return digits ? `${text.slice(0, text.length - digits)}.${text.slice(text.length - digits)}` : text;
|
|
71
|
+
}
|
|
72
|
+
/** Settles a draft the way it will be read back: fraction padded to the currency, leading zeros gone. */
|
|
73
|
+
function settle(draft, digits) {
|
|
74
|
+
return draft ? fromMinor(toMinor(draft, digits), digits) : "";
|
|
75
|
+
}
|
|
76
|
+
/** Carries an amount across currencies with different minor units, keeping the major amount. */
|
|
77
|
+
function convertDraft(draft, digits) {
|
|
78
|
+
if (!draft) return "";
|
|
79
|
+
const [whole = "", fraction] = draft.split(".");
|
|
80
|
+
if (!digits) return whole || "0";
|
|
81
|
+
return fraction === void 0 ? whole : `${whole}.${fraction.slice(0, digits)}`;
|
|
82
|
+
}
|
|
83
|
+
const groupInteger = (whole, group) => whole.replace(/\B(?=(\d{3})+(?!\d))/g, group);
|
|
84
|
+
function displayOf(draft, symbols) {
|
|
85
|
+
if (!draft) return "";
|
|
86
|
+
const [whole = "", fraction] = draft.split(".");
|
|
87
|
+
return groupInteger(whole, symbols.group) + (fraction !== void 0 ? symbols.decimal + fraction : "");
|
|
88
|
+
}
|
|
89
|
+
const isSignificant = (char, decimal) => /\d/.test(char) || char === decimal;
|
|
90
|
+
function positionAfter(text, count, decimal) {
|
|
91
|
+
if (count <= 0) return 0;
|
|
92
|
+
let seen = 0;
|
|
93
|
+
for (let index = 0; index < text.length; index++) if (isSignificant(text[index], decimal) && ++seen === count) return index + 1;
|
|
94
|
+
return text.length;
|
|
95
|
+
}
|
|
96
|
+
/** The currency symbol swaps with a short rise while its slot springs to the new width. */
|
|
97
|
+
function SymbolSlot({ symbol, side }) {
|
|
98
|
+
const content = useRef(null);
|
|
99
|
+
useMorphWidth(content, symbol);
|
|
100
|
+
return /* @__PURE__ */ jsx("span", {
|
|
101
|
+
"aria-hidden": "true",
|
|
102
|
+
"data-slot": "money-input-symbol",
|
|
103
|
+
className: cnAll("button-slot text-text-secondary", side === "prefix" ? "me-1" : "ms-1.5"),
|
|
104
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
105
|
+
ref: content,
|
|
106
|
+
className: "inline-flex flex-none items-center whitespace-pre",
|
|
107
|
+
children: /* @__PURE__ */ jsx(SwapText, {
|
|
108
|
+
swapKey: symbol,
|
|
109
|
+
motion: "rise",
|
|
110
|
+
className: "inline-block",
|
|
111
|
+
children: symbol
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** The amount the eye sees: whole part, separator and the cents, with the missing ones as muted ghosts. */
|
|
117
|
+
function Amount({ draft, digits, symbols, direction, still }) {
|
|
118
|
+
const [whole = "", fraction] = draft ? draft.split(".") : [];
|
|
119
|
+
const typed = fraction ?? "";
|
|
120
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
121
|
+
"data-ghost": !whole || void 0,
|
|
122
|
+
className: "inline-flex data-[ghost]:text-muted-foreground",
|
|
123
|
+
children: /* @__PURE__ */ jsx(RollingNumber, {
|
|
124
|
+
word: groupInteger(whole || "0", symbols.group),
|
|
125
|
+
direction,
|
|
126
|
+
still
|
|
127
|
+
})
|
|
128
|
+
}), digits > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
129
|
+
/* @__PURE__ */ jsx("span", {
|
|
130
|
+
"data-ghost": fraction === void 0 || void 0,
|
|
131
|
+
className: "data-[ghost]:text-muted-foreground",
|
|
132
|
+
children: symbols.decimal
|
|
133
|
+
}),
|
|
134
|
+
typed ? /* @__PURE__ */ jsx("span", {
|
|
135
|
+
className: "inline-flex",
|
|
136
|
+
children: /* @__PURE__ */ jsx(RollingNumber, {
|
|
137
|
+
word: typed,
|
|
138
|
+
direction,
|
|
139
|
+
still
|
|
140
|
+
})
|
|
141
|
+
}) : null,
|
|
142
|
+
typed.length < digits ? /* @__PURE__ */ jsx("span", {
|
|
143
|
+
className: "text-muted-foreground",
|
|
144
|
+
children: "0".repeat(digits - typed.length)
|
|
145
|
+
}) : null
|
|
146
|
+
] }) : null] });
|
|
147
|
+
}
|
|
148
|
+
const triggerClass = "inline-flex h-9 flex-none cursor-pointer items-center gap-1 rounded-pill border-0 bg-transparent ps-3 pe-2 font-sans text-sm font-medium tabular-nums text-foreground outline-none motion-safe:transition-[background-color] motion-safe:duration-(--duration-quick) motion-safe:ease-settle data-[hovered]:bg-muted data-[pressed]:bg-muted data-[disabled]:cursor-not-allowed data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring)";
|
|
149
|
+
const shellClass = cnAll(fieldSurfaceVariants(), "flex h-19 items-center gap-2 rounded-panel ps-4.5 pe-2", "has-[input:focus]:not-data-[invalid]:border-foreground", "forced-colors:has-[input:focus]:outline-solid forced-colors:has-[input:focus]:outline-(length:--focus-ring-width) forced-colors:has-[input:focus]:outline-offset-(--focus-ring-offset)");
|
|
150
|
+
const MoneyInput = forwardRef(function MoneyInput({ label, labelHidden = false, value, defaultValue = null, onValueChange, currency: currencyProp, defaultCurrency = "USD", onCurrencyChange, currencies = [
|
|
151
|
+
"USD",
|
|
152
|
+
"EUR",
|
|
153
|
+
"GBP",
|
|
154
|
+
"JPY",
|
|
155
|
+
"CAD",
|
|
156
|
+
"AUD",
|
|
157
|
+
"CHF",
|
|
158
|
+
"INR"
|
|
159
|
+
], min, max, quickAdd = [
|
|
160
|
+
10,
|
|
161
|
+
50,
|
|
162
|
+
100
|
|
163
|
+
], step: stepProp, locale = "en-US", description, error, isInvalid = false, errorMessage, disabled = false, name, id, className, onBlur }, forwardedRef) {
|
|
164
|
+
const generated = useId();
|
|
165
|
+
const inputId = id ?? `${generated}-amount`;
|
|
166
|
+
const rangeId = `${inputId}-range`;
|
|
167
|
+
const [innerCurrency, setInnerCurrency] = useState(defaultCurrency);
|
|
168
|
+
const code = currencyProp ?? innerCurrency;
|
|
169
|
+
const info = useMemo(() => currencyInfo(code, locale), [code, locale]);
|
|
170
|
+
const symbols = useMemo(() => localeSymbols(locale), [locale]);
|
|
171
|
+
const step = stepProp && stepProp > 0 ? stepProp : pow10(info.digits);
|
|
172
|
+
const [draft, setDraft] = useState(() => fromMinor(value !== void 0 ? value : defaultValue, info.digits));
|
|
173
|
+
const minor = toMinor(draft, info.digits);
|
|
174
|
+
const [seenValue, setSeenValue] = useState(value);
|
|
175
|
+
const [source, setSource] = useState("external");
|
|
176
|
+
const [direction, setDirection] = useState(1);
|
|
177
|
+
if (value !== seenValue) {
|
|
178
|
+
setSeenValue(value);
|
|
179
|
+
if (value !== void 0 && value !== minor) {
|
|
180
|
+
setDraft(fromMinor(value, info.digits));
|
|
181
|
+
setSource("external");
|
|
182
|
+
setDirection((value ?? 0) >= (minor ?? 0) ? 1 : -1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const [focused, setFocused] = useState(false);
|
|
186
|
+
const [touched, setTouched] = useState(false);
|
|
187
|
+
const [flash, setFlash] = useState(false);
|
|
188
|
+
const [announcement, setAnnouncement] = useState("");
|
|
189
|
+
const [, rerender] = useReducer((count) => count + 1, 0);
|
|
190
|
+
const inputRef = useRef(null);
|
|
191
|
+
useImperativeHandle(forwardedRef, () => inputRef.current);
|
|
192
|
+
const pendingCaret = useRef(null);
|
|
193
|
+
const latest = useRef({
|
|
194
|
+
minor,
|
|
195
|
+
draft
|
|
196
|
+
});
|
|
197
|
+
useIsomorphicLayoutEffect(() => {
|
|
198
|
+
latest.current = {
|
|
199
|
+
minor,
|
|
200
|
+
draft
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
const money = useCallback((amount) => amount === null ? "" : info.full.format(amount / pow10(info.digits)), [info]);
|
|
204
|
+
const groupRef = useRef(null);
|
|
205
|
+
const flashTimer = useRef(void 0);
|
|
206
|
+
function refuse(toward, limit) {
|
|
207
|
+
const node = groupRef.current;
|
|
208
|
+
if (node) {
|
|
209
|
+
node.style.setProperty("--strain-x", `${toward * STRAIN_PX}px`);
|
|
210
|
+
node.removeAttribute("data-strain");
|
|
211
|
+
node.offsetWidth;
|
|
212
|
+
node.setAttribute("data-strain", "");
|
|
213
|
+
}
|
|
214
|
+
setFlash(true);
|
|
215
|
+
window.clearTimeout(flashTimer.current);
|
|
216
|
+
flashTimer.current = window.setTimeout(() => setFlash(false), 1400);
|
|
217
|
+
setAnnouncement(`${toward > 0 ? "Maximum" : "Minimum"} is ${money(limit)}`);
|
|
218
|
+
}
|
|
219
|
+
function emit(nextMinor, nextInfo = info) {
|
|
220
|
+
onValueChange?.(nextMinor, {
|
|
221
|
+
currency: nextInfo.code,
|
|
222
|
+
major: nextMinor === null ? null : nextMinor / pow10(nextInfo.digits),
|
|
223
|
+
formatted: nextMinor === null ? "" : nextInfo.full.format(nextMinor / pow10(nextInfo.digits))
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function setAmount(nextDraft, nextSource) {
|
|
227
|
+
const nextMinor = toMinor(nextDraft, info.digits);
|
|
228
|
+
setDirection((nextMinor ?? 0) >= (latest.current.minor ?? 0) ? 1 : -1);
|
|
229
|
+
setSource(nextSource);
|
|
230
|
+
setDraft(nextDraft);
|
|
231
|
+
latest.current = {
|
|
232
|
+
minor: nextMinor,
|
|
233
|
+
draft: nextDraft
|
|
234
|
+
};
|
|
235
|
+
if (nextMinor !== minor) emit(nextMinor);
|
|
236
|
+
if (nextSource !== "type") setAnnouncement(money(nextMinor));
|
|
237
|
+
}
|
|
238
|
+
/** Reads what the input holds into a draft and counts the digits and decimal before the caret, so the caret can return to the same spot. */
|
|
239
|
+
function sanitize(raw, caret) {
|
|
240
|
+
let out = "";
|
|
241
|
+
let before = 0;
|
|
242
|
+
let dot = false;
|
|
243
|
+
for (let index = 0; index < raw.length; index++) {
|
|
244
|
+
const char = raw[index];
|
|
245
|
+
let kept = "";
|
|
246
|
+
if (/\d/.test(char)) kept = char;
|
|
247
|
+
else if ((char === symbols.decimal || char === "." && symbols.group !== ".") && info.digits > 0 && !dot) {
|
|
248
|
+
kept = ".";
|
|
249
|
+
dot = true;
|
|
250
|
+
}
|
|
251
|
+
if (!kept) continue;
|
|
252
|
+
out += kept;
|
|
253
|
+
if (index < caret) before++;
|
|
254
|
+
}
|
|
255
|
+
const pieces = out.split(".");
|
|
256
|
+
let whole = pieces[0];
|
|
257
|
+
const fraction = pieces[1];
|
|
258
|
+
const stripped = whole.length - whole.replace(/^0+/, "").length;
|
|
259
|
+
whole = whole.replace(/^0+/, "");
|
|
260
|
+
let shift = -Math.min(stripped, before);
|
|
261
|
+
if (fraction !== void 0 && !whole) {
|
|
262
|
+
whole = "0";
|
|
263
|
+
shift += 1;
|
|
264
|
+
}
|
|
265
|
+
if (fraction === void 0 && !whole && stripped) {
|
|
266
|
+
whole = "0";
|
|
267
|
+
shift += 1;
|
|
268
|
+
}
|
|
269
|
+
if (fraction !== void 0 && fraction.length > info.digits) return null;
|
|
270
|
+
if (whole.length > MAX_INTEGER_DIGITS) return null;
|
|
271
|
+
return {
|
|
272
|
+
draft: fraction !== void 0 ? `${whole}.${fraction}` : whole,
|
|
273
|
+
before: Math.max(0, before + shift)
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function applyRaw(raw, caret) {
|
|
277
|
+
const result = sanitize(raw, caret);
|
|
278
|
+
if (!result) {
|
|
279
|
+
pendingCaret.current = Math.max(0, [...raw.slice(0, caret)].filter((char) => isSignificant(char, symbols.decimal) || char === ".").length - 1);
|
|
280
|
+
rerender();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const nextMinor = toMinor(result.draft, info.digits);
|
|
284
|
+
if (max !== void 0 && nextMinor !== null && nextMinor > max) {
|
|
285
|
+
pendingCaret.current = Math.max(0, result.before - 1);
|
|
286
|
+
refuse(1, max);
|
|
287
|
+
rerender();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
pendingCaret.current = result.before;
|
|
291
|
+
setAmount(result.draft, "type");
|
|
292
|
+
}
|
|
293
|
+
useIsomorphicLayoutEffect(() => {
|
|
294
|
+
const input = inputRef.current;
|
|
295
|
+
const count = pendingCaret.current;
|
|
296
|
+
pendingCaret.current = null;
|
|
297
|
+
if (!input || count === null || document.activeElement !== input) return;
|
|
298
|
+
const position = positionAfter(input.value, count, symbols.decimal);
|
|
299
|
+
input.setSelectionRange(position, position);
|
|
300
|
+
});
|
|
301
|
+
function nudge(amount, nextSource) {
|
|
302
|
+
const from = latest.current.minor ?? 0;
|
|
303
|
+
const floor = min ?? 0;
|
|
304
|
+
const ceiling = max ?? Number.MAX_SAFE_INTEGER;
|
|
305
|
+
let next = from + amount;
|
|
306
|
+
if (next > ceiling) {
|
|
307
|
+
if (from >= ceiling) {
|
|
308
|
+
refuse(1, ceiling);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
next = ceiling;
|
|
312
|
+
refuse(1, ceiling);
|
|
313
|
+
}
|
|
314
|
+
if (next < floor) {
|
|
315
|
+
if (from <= floor && latest.current.minor !== null) {
|
|
316
|
+
refuse(-1, floor);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
next = floor;
|
|
320
|
+
}
|
|
321
|
+
pendingCaret.current = Number.MAX_SAFE_INTEGER;
|
|
322
|
+
setAmount(fromMinor(next, info.digits), nextSource);
|
|
323
|
+
}
|
|
324
|
+
function onKeyDown(event) {
|
|
325
|
+
const input = event.currentTarget;
|
|
326
|
+
const moves = {
|
|
327
|
+
ArrowUp: 1,
|
|
328
|
+
ArrowDown: -1,
|
|
329
|
+
PageUp: 10,
|
|
330
|
+
PageDown: -10
|
|
331
|
+
};
|
|
332
|
+
if (event.key in moves) {
|
|
333
|
+
event.preventDefault();
|
|
334
|
+
const unit = moves[event.key];
|
|
335
|
+
nudge(unit * step * (event.shiftKey && Math.abs(unit) === 1 ? 10 : 1), "key");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (event.key === "Enter") {
|
|
339
|
+
setDraft(settle(draft, info.digits));
|
|
340
|
+
pendingCaret.current = Number.MAX_SAFE_INTEGER;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const start = input.selectionStart ?? 0;
|
|
344
|
+
if (start !== (input.selectionEnd ?? 0) || event.metaKey || event.ctrlKey || event.altKey) return;
|
|
345
|
+
if (event.key === "Backspace" && start > 1 && input.value[start - 1] === symbols.group) {
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
applyRaw(input.value.slice(0, start - 2) + input.value.slice(start - 1), start - 2);
|
|
348
|
+
}
|
|
349
|
+
if (event.key === "Delete" && input.value[start] === symbols.group) {
|
|
350
|
+
event.preventDefault();
|
|
351
|
+
applyRaw(input.value.slice(0, start + 1) + input.value.slice(start + 2), start);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function onPaste(event) {
|
|
355
|
+
const text = event.clipboardData.getData("text").trim();
|
|
356
|
+
if (!text) return;
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
const match = /[.,](\d{1,2})\s*\D*$/.exec(text);
|
|
359
|
+
const whole = (match ? text.slice(0, match.index) : text).replace(/\D/g, "");
|
|
360
|
+
const pasted = match && info.digits ? `${whole}.${match[1]}` : whole;
|
|
361
|
+
if (!/\d/.test(pasted)) return;
|
|
362
|
+
const input = event.currentTarget;
|
|
363
|
+
const start = input.selectionStart ?? 0;
|
|
364
|
+
const end = input.selectionEnd ?? 0;
|
|
365
|
+
const inserted = pasted.replace(".", symbols.decimal);
|
|
366
|
+
const replaceAll = start === 0 && end === input.value.length || !input.value;
|
|
367
|
+
const raw = replaceAll ? inserted : input.value.slice(0, start) + inserted + input.value.slice(end);
|
|
368
|
+
applyRaw(raw, replaceAll ? raw.length : start + inserted.length);
|
|
369
|
+
}
|
|
370
|
+
const wrapRef = useRef(null);
|
|
371
|
+
useIsomorphicLayoutEffect(() => {
|
|
372
|
+
const wrap = wrapRef.current;
|
|
373
|
+
const group = groupRef.current;
|
|
374
|
+
if (!wrap || !group || typeof ResizeObserver === "undefined") return;
|
|
375
|
+
const fit = () => {
|
|
376
|
+
const natural = group.offsetWidth;
|
|
377
|
+
const room = wrap.clientWidth;
|
|
378
|
+
group.style.scale = String(natural > 0 && room > 0 ? Math.min(1, room / natural) : 1);
|
|
379
|
+
if (!group.hasAttribute("data-ready")) {
|
|
380
|
+
group.offsetWidth;
|
|
381
|
+
group.setAttribute("data-ready", "");
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
fit();
|
|
385
|
+
const observer = new ResizeObserver(fit);
|
|
386
|
+
observer.observe(wrap);
|
|
387
|
+
observer.observe(group);
|
|
388
|
+
return () => observer.disconnect();
|
|
389
|
+
}, []);
|
|
390
|
+
const options = useMemo(() => currencies.map((entry) => currencyInfo(entry, locale)), [currencies, locale]);
|
|
391
|
+
function chooseCurrency(next) {
|
|
392
|
+
if (next.code === code) return;
|
|
393
|
+
const nextDraft = focused ? convertDraft(draft, next.digits) : settle(convertDraft(draft, next.digits), next.digits);
|
|
394
|
+
const nextMinor = toMinor(nextDraft, next.digits);
|
|
395
|
+
if (currencyProp === void 0) setInnerCurrency(next.code);
|
|
396
|
+
onCurrencyChange?.(next.code);
|
|
397
|
+
setSource("external");
|
|
398
|
+
setDraft(nextDraft);
|
|
399
|
+
latest.current = {
|
|
400
|
+
minor: nextMinor,
|
|
401
|
+
draft: nextDraft
|
|
402
|
+
};
|
|
403
|
+
emit(nextMinor, next);
|
|
404
|
+
setAnnouncement(`${next.name}${nextMinor === null ? "" : `, ${next.full.format(nextMinor / pow10(next.digits))}`}`);
|
|
405
|
+
}
|
|
406
|
+
const range = min !== void 0 && max !== void 0 ? `${money(min)} to ${money(max)}` : max !== void 0 ? `Up to ${money(max)}` : min !== void 0 ? `At least ${money(min)}` : "";
|
|
407
|
+
const belowMin = minor !== null && min !== void 0 && minor < min;
|
|
408
|
+
const builtIn = touched && !focused && (belowMin || minor !== null && max !== void 0 && minor > max) ? belowMin ? `The minimum is ${money(min ?? 0)}` : `The maximum is ${money(max ?? 0)}` : void 0;
|
|
409
|
+
const invalid = isInvalid || builtIn !== void 0;
|
|
410
|
+
const message = error ?? (invalid ? errorMessage ?? builtIn : void 0);
|
|
411
|
+
const chips = quickAdd.filter((amount) => amount > 0);
|
|
412
|
+
const field = useFieldWiring({
|
|
413
|
+
enabled: true,
|
|
414
|
+
id: inputId,
|
|
415
|
+
describedBy: range ? rangeId : void 0,
|
|
416
|
+
invalid: invalid || void 0,
|
|
417
|
+
description,
|
|
418
|
+
error: message
|
|
419
|
+
});
|
|
420
|
+
const typing = source === "type";
|
|
421
|
+
const display = displayOf(draft, symbols);
|
|
422
|
+
const canSwitch = options.length > 1;
|
|
423
|
+
const control = /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
424
|
+
/* @__PURE__ */ jsxs(Group, {
|
|
425
|
+
role: "presentation",
|
|
426
|
+
isDisabled: disabled,
|
|
427
|
+
isInvalid: invalid || Boolean(message),
|
|
428
|
+
"data-slot": "money-input-shell",
|
|
429
|
+
className: shellClass,
|
|
430
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
431
|
+
ref: wrapRef,
|
|
432
|
+
className: "relative flex h-full min-w-0 flex-1 cursor-text items-center overflow-hidden",
|
|
433
|
+
onMouseDown: (event) => {
|
|
434
|
+
if (event.target !== inputRef.current) event.preventDefault();
|
|
435
|
+
},
|
|
436
|
+
onClick: (event) => {
|
|
437
|
+
if (disabled || event.target === inputRef.current) return;
|
|
438
|
+
const input = inputRef.current;
|
|
439
|
+
input?.focus();
|
|
440
|
+
input?.setSelectionRange(input.value.length, input.value.length);
|
|
441
|
+
},
|
|
442
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
443
|
+
ref: groupRef,
|
|
444
|
+
"data-slot": "money-input-amount",
|
|
445
|
+
className: "inline-flex flex-none origin-left items-baseline whitespace-nowrap font-display text-h2 font-medium tabular-nums text-foreground data-[ready]:motion-safe:transition-[scale] data-[ready]:motion-safe:duration-(--duration-smooth) data-[ready]:motion-safe:ease-smooth data-[strain]:motion-safe:animate-field-strain",
|
|
446
|
+
children: [
|
|
447
|
+
info.position === "prefix" ? /* @__PURE__ */ jsx(SymbolSlot, {
|
|
448
|
+
symbol: info.symbol,
|
|
449
|
+
side: "prefix"
|
|
450
|
+
}) : null,
|
|
451
|
+
/* @__PURE__ */ jsxs("span", {
|
|
452
|
+
className: "relative inline-flex",
|
|
453
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
454
|
+
"aria-hidden": "true",
|
|
455
|
+
"data-slot": "money-input-display",
|
|
456
|
+
className: "inline-flex",
|
|
457
|
+
children: /* @__PURE__ */ jsx(Amount, {
|
|
458
|
+
draft,
|
|
459
|
+
digits: info.digits,
|
|
460
|
+
symbols,
|
|
461
|
+
direction,
|
|
462
|
+
still: typing
|
|
463
|
+
})
|
|
464
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
465
|
+
ref: inputRef,
|
|
466
|
+
...field.controlProps,
|
|
467
|
+
"data-slot": "money-input-input",
|
|
468
|
+
type: "text",
|
|
469
|
+
role: "spinbutton",
|
|
470
|
+
inputMode: info.digits ? "decimal" : "numeric",
|
|
471
|
+
autoComplete: "off",
|
|
472
|
+
spellCheck: false,
|
|
473
|
+
value: display,
|
|
474
|
+
disabled,
|
|
475
|
+
"aria-label": labelHidden ? label : void 0,
|
|
476
|
+
"aria-valuenow": minor === null ? void 0 : minor / pow10(info.digits),
|
|
477
|
+
"aria-valuetext": minor === null ? "Empty" : money(minor),
|
|
478
|
+
"aria-valuemin": min === void 0 ? void 0 : min / pow10(info.digits),
|
|
479
|
+
"aria-valuemax": max === void 0 ? void 0 : max / pow10(info.digits),
|
|
480
|
+
onChange: (event) => applyRaw(event.currentTarget.value, event.currentTarget.selectionStart ?? event.currentTarget.value.length),
|
|
481
|
+
onKeyDown,
|
|
482
|
+
onPaste,
|
|
483
|
+
onFocus: () => setFocused(true),
|
|
484
|
+
onBlur: (event) => {
|
|
485
|
+
setFocused(false);
|
|
486
|
+
setTouched(true);
|
|
487
|
+
if (draft) setDraft(settle(draft, info.digits));
|
|
488
|
+
onBlur?.(event);
|
|
489
|
+
},
|
|
490
|
+
className: "absolute top-0 left-0 z-10 m-0 h-full w-[calc(100%+0.5em)] border-0 bg-transparent p-0 [font:inherit] text-transparent caret-foreground outline-none selection:bg-primary/20 selection:text-transparent data-[disabled]:cursor-not-allowed"
|
|
491
|
+
})]
|
|
492
|
+
}),
|
|
493
|
+
info.position === "suffix" ? /* @__PURE__ */ jsx(SymbolSlot, {
|
|
494
|
+
symbol: info.symbol,
|
|
495
|
+
side: "suffix"
|
|
496
|
+
}) : null
|
|
497
|
+
]
|
|
498
|
+
})
|
|
499
|
+
}), canSwitch ? /* @__PURE__ */ jsxs(Select, {
|
|
500
|
+
"aria-label": "Currency",
|
|
501
|
+
selectedKey: code,
|
|
502
|
+
isDisabled: disabled,
|
|
503
|
+
onSelectionChange: (key) => {
|
|
504
|
+
const next = options.find((option) => option.code === key);
|
|
505
|
+
if (next) chooseCurrency(next);
|
|
506
|
+
},
|
|
507
|
+
"data-slot": "money-input-currency",
|
|
508
|
+
className: "flex-none",
|
|
509
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
510
|
+
className: cnAll(triggerClass, "group/trigger"),
|
|
511
|
+
children: [/* @__PURE__ */ jsx(SelectValue, { children: () => code }), /* @__PURE__ */ jsx("svg", {
|
|
512
|
+
"aria-hidden": "true",
|
|
513
|
+
viewBox: "0 0 16 16",
|
|
514
|
+
fill: "none",
|
|
515
|
+
stroke: "currentColor",
|
|
516
|
+
strokeWidth: "1.75",
|
|
517
|
+
strokeLinecap: "round",
|
|
518
|
+
strokeLinejoin: "round",
|
|
519
|
+
className: "size-4 text-muted-foreground motion-safe:transition-[rotate] motion-safe:duration-(--duration-gentle) motion-safe:ease-gentle group-aria-expanded/trigger:rotate-180",
|
|
520
|
+
children: /* @__PURE__ */ jsx("path", { d: "m4 6 4 4 4-4" })
|
|
521
|
+
})]
|
|
522
|
+
}), /* @__PURE__ */ jsx(Popover, {
|
|
523
|
+
placement: "bottom end",
|
|
524
|
+
offset: 12,
|
|
525
|
+
"data-slot": "money-input-currency-popover",
|
|
526
|
+
className: cnAll(selectPopoverVariants(), "w-64"),
|
|
527
|
+
children: /* @__PURE__ */ jsx(ListBox, {
|
|
528
|
+
"aria-label": "Currency",
|
|
529
|
+
className: "outline-none",
|
|
530
|
+
children: options.map((option) => /* @__PURE__ */ jsxs(SelectItem, {
|
|
531
|
+
id: option.code,
|
|
532
|
+
textValue: option.code,
|
|
533
|
+
children: [
|
|
534
|
+
/* @__PURE__ */ jsx("span", {
|
|
535
|
+
"aria-hidden": "true",
|
|
536
|
+
className: "w-6 flex-none text-center text-muted-foreground",
|
|
537
|
+
children: option.symbol
|
|
538
|
+
}),
|
|
539
|
+
/* @__PURE__ */ jsx("span", {
|
|
540
|
+
className: "flex-none font-medium tabular-nums",
|
|
541
|
+
children: option.code
|
|
542
|
+
}),
|
|
543
|
+
/* @__PURE__ */ jsx("span", {
|
|
544
|
+
className: "min-w-0 flex-1 truncate text-xs text-muted-foreground",
|
|
545
|
+
children: option.name
|
|
546
|
+
})
|
|
547
|
+
]
|
|
548
|
+
}, option.code))
|
|
549
|
+
})
|
|
550
|
+
})]
|
|
551
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
552
|
+
"data-slot": "money-input-currency",
|
|
553
|
+
className: "flex-none px-2.5 text-sm font-medium text-text-secondary",
|
|
554
|
+
children: code
|
|
555
|
+
})]
|
|
556
|
+
}),
|
|
557
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
558
|
+
id: field.errorId,
|
|
559
|
+
text: message,
|
|
560
|
+
tone: "error"
|
|
561
|
+
}),
|
|
562
|
+
chips.length > 0 || range ? /* @__PURE__ */ jsxs("div", {
|
|
563
|
+
className: "flex flex-wrap items-center justify-between gap-x-3 gap-y-2 pt-3",
|
|
564
|
+
children: [chips.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
565
|
+
role: "group",
|
|
566
|
+
"aria-label": "Quick add",
|
|
567
|
+
className: "flex flex-wrap gap-1.5",
|
|
568
|
+
children: chips.map((amount) => /* @__PURE__ */ jsxs(Button$1, {
|
|
569
|
+
variant: "outlineNeutral",
|
|
570
|
+
size: "sm",
|
|
571
|
+
isDisabled: disabled || max !== void 0 && (minor ?? 0) >= max,
|
|
572
|
+
"aria-controls": inputId,
|
|
573
|
+
"aria-label": `Add ${info.whole.format(amount)}`,
|
|
574
|
+
onPress: () => nudge(amount * pow10(info.digits), "chip"),
|
|
575
|
+
children: ["+", info.whole.format(amount)]
|
|
576
|
+
}, amount))
|
|
577
|
+
}) : null, range ? /* @__PURE__ */ jsx("span", {
|
|
578
|
+
id: rangeId,
|
|
579
|
+
"data-flash": flash || void 0,
|
|
580
|
+
className: "text-xs tabular-nums text-muted-foreground motion-safe:transition-colors motion-safe:duration-(--duration-standard) data-[flash]:text-destructive-strong motion-safe:data-[flash]:duration-(--duration-instant)",
|
|
581
|
+
children: range
|
|
582
|
+
}) : null]
|
|
583
|
+
}) : null,
|
|
584
|
+
name ? /* @__PURE__ */ jsx("input", {
|
|
585
|
+
type: "hidden",
|
|
586
|
+
name,
|
|
587
|
+
value: minor ?? ""
|
|
588
|
+
}) : null,
|
|
589
|
+
/* @__PURE__ */ jsx("span", {
|
|
590
|
+
className: "sr-only",
|
|
591
|
+
role: "status",
|
|
592
|
+
"aria-live": "polite",
|
|
593
|
+
children: announcement
|
|
594
|
+
})
|
|
595
|
+
] });
|
|
596
|
+
return /* @__PURE__ */ jsx("div", {
|
|
597
|
+
className: cn("w-full min-w-0 font-sans", className),
|
|
598
|
+
"data-slot": "money-input",
|
|
599
|
+
children: /* @__PURE__ */ jsx(FieldShell, {
|
|
600
|
+
label: labelHidden ? null : label,
|
|
601
|
+
controlId: field.controlId,
|
|
602
|
+
description,
|
|
603
|
+
hintId: field.hintId,
|
|
604
|
+
error: void 0,
|
|
605
|
+
errorId: void 0,
|
|
606
|
+
children: control
|
|
607
|
+
})
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
//#endregion
|
|
611
|
+
export { MoneyInput };
|
|
612
|
+
|
|
613
|
+
//# sourceMappingURL=money-input.js.map
|