@homebound/beam 2.189.0 → 2.190.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.
|
@@ -28,6 +28,9 @@ export interface NumberFieldProps {
|
|
|
28
28
|
onEnter?: VoidFunction;
|
|
29
29
|
placeholder?: string;
|
|
30
30
|
errorInTooltip?: true;
|
|
31
|
+
/** Whether to show comma separation for group numbers.
|
|
32
|
+
* @default true */
|
|
33
|
+
useGrouping?: boolean;
|
|
31
34
|
}
|
|
32
35
|
export declare function NumberField(props: NumberFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
33
36
|
export declare function formatValue(value: number, factor: number, numFractionDigits: number | undefined, numIntegerDigits: number | undefined): number | undefined;
|
|
@@ -15,7 +15,7 @@ function NumberField(props) {
|
|
|
15
15
|
// Determine default alignment based on presentation context
|
|
16
16
|
const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
|
|
17
17
|
const alignment = (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.numberAlignment) === "right" ? Css_1.Css.tr.jcfe.$ : Css_1.Css.tl.jcfs.$;
|
|
18
|
-
const { disabled, required, readOnly, type, label, onBlur, onFocus, errorMsg, helperText, value, onChange, xss, displayDirection = false, numFractionDigits = type === "dollars" ? 2 : undefined, truncate = false, onEnter, numberFormatOptions, numIntegerDigits, ...otherProps } = props;
|
|
18
|
+
const { disabled, required, readOnly, type, label, onBlur, onFocus, errorMsg, helperText, value, onChange, xss, displayDirection = false, numFractionDigits = type === "dollars" ? 2 : undefined, truncate = false, onEnter, numberFormatOptions, numIntegerDigits, useGrouping = true, ...otherProps } = props;
|
|
19
19
|
const isDisabled = !!disabled;
|
|
20
20
|
const isReadOnly = !!readOnly;
|
|
21
21
|
const factor = type === "percent" || type === "cents" ? 100 : type === "basisPoints" ? 10000 : 1;
|
|
@@ -23,7 +23,9 @@ function NumberField(props) {
|
|
|
23
23
|
const defaultFormatOptions = (0, react_1.useMemo)(() => ({
|
|
24
24
|
[truncate ? "maximumFractionDigits" : "minimumFractionDigits"]: numFractionDigits,
|
|
25
25
|
...(numIntegerDigits !== undefined && { minimumIntegerDigits: numIntegerDigits }),
|
|
26
|
-
|
|
26
|
+
useGrouping,
|
|
27
|
+
signDisplay,
|
|
28
|
+
}), [truncate, numIntegerDigits, useGrouping, signDisplay]);
|
|
27
29
|
const { locale } = (0, react_aria_1.useLocale)();
|
|
28
30
|
// If formatOptions isn't memo'd, a useEffect in useNumberStateField will cause jank,
|
|
29
31
|
// see: https://github.com/adobe/react-spectrum/issues/1893.
|
|
@@ -31,17 +33,18 @@ function NumberField(props) {
|
|
|
31
33
|
if (numberFormatOptions !== undefined) {
|
|
32
34
|
return numberFormatOptions;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
? { style: "percent"
|
|
36
|
+
const typeFormat = type === "percent"
|
|
37
|
+
? { style: "percent" }
|
|
36
38
|
: type === "basisPoints"
|
|
37
|
-
? { style: "percent", minimumFractionDigits: 2
|
|
39
|
+
? { style: "percent", minimumFractionDigits: 2 }
|
|
38
40
|
: type === "cents"
|
|
39
|
-
? { style: "currency", currency: "USD", minimumFractionDigits: 2
|
|
41
|
+
? { style: "currency", currency: "USD", minimumFractionDigits: 2 }
|
|
40
42
|
: type === "dollars"
|
|
41
|
-
? { style: "currency", currency: "USD", minimumFractionDigits: numFractionDigits !== null && numFractionDigits !== void 0 ? numFractionDigits : 2
|
|
43
|
+
? { style: "currency", currency: "USD", minimumFractionDigits: numFractionDigits !== null && numFractionDigits !== void 0 ? numFractionDigits : 2 }
|
|
42
44
|
: type === "days"
|
|
43
|
-
? { style: "unit", unit: "day", unitDisplay: "long", maximumFractionDigits: 0
|
|
44
|
-
:
|
|
45
|
+
? { style: "unit", unit: "day", unitDisplay: "long", maximumFractionDigits: 0 }
|
|
46
|
+
: {};
|
|
47
|
+
return { ...defaultFormatOptions, ...typeFormat };
|
|
45
48
|
}, [type, numberFormatOptions]);
|
|
46
49
|
const numberParser = (0, react_1.useMemo)(() => new number_1.NumberParser(locale, formatOptions), [locale, formatOptions]);
|
|
47
50
|
const valueRef = (0, react_1.useRef)({ wip: false });
|