@homebound/beam 2.187.1 → 2.189.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.
|
@@ -6,6 +6,7 @@ export interface ChipProps<X> {
|
|
|
6
6
|
title?: string;
|
|
7
7
|
xss?: X;
|
|
8
8
|
type?: ChipType;
|
|
9
|
+
compact?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/** Kinda like a chip, but read-only, so no `onClick` or `hover`. */
|
|
11
12
|
export declare function Chip<X extends Only<Xss<Margin>, X>>({ type, ...props }: ChipProps<X>): import("@emotion/react/jsx-runtime").JSX.Element;
|
package/dist/components/Chip.js
CHANGED
|
@@ -16,9 +16,8 @@ exports.ChipTypes = {
|
|
|
16
16
|
};
|
|
17
17
|
/** Kinda like a chip, but read-only, so no `onClick` or `hover`. */
|
|
18
18
|
function Chip({ type = exports.ChipTypes.neutral, ...props }) {
|
|
19
|
-
const { text, title = text, xss = {} } = props;
|
|
20
19
|
const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
|
|
21
|
-
const compact = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact;
|
|
20
|
+
const { text, title = text, xss = {}, compact = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact } = props;
|
|
22
21
|
const tid = (0, useTestIds_1.useTestIds)(props, "chip");
|
|
23
22
|
return ((0, jsx_runtime_1.jsx)("span", Object.assign({ css: {
|
|
24
23
|
...Css_1.Css[compact ? "xs" : "sm"].dif.aic.br16.pl1.px1.pyPx(2).gray900.$,
|
|
@@ -28,7 +27,7 @@ function Chip({ type = exports.ChipTypes.neutral, ...props }) {
|
|
|
28
27
|
}
|
|
29
28
|
exports.Chip = Chip;
|
|
30
29
|
const typeStyles = {
|
|
31
|
-
caution: Css_1.Css.
|
|
30
|
+
caution: Css_1.Css.bgYellow400.$,
|
|
32
31
|
warning: Css_1.Css.bgRed100.$,
|
|
33
32
|
success: Css_1.Css.bgGreen100.$,
|
|
34
33
|
light: Css_1.Css.bgWhite.$,
|
|
@@ -22,9 +22,12 @@ export interface NumberFieldProps {
|
|
|
22
22
|
xss?: Xss<"textAlign" | "justifyContent">;
|
|
23
23
|
displayDirection?: boolean;
|
|
24
24
|
numFractionDigits?: number;
|
|
25
|
+
numIntegerDigits?: number;
|
|
25
26
|
numberFormatOptions?: Intl.NumberFormatOptions;
|
|
26
27
|
truncate?: boolean;
|
|
27
28
|
onEnter?: VoidFunction;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
errorInTooltip?: true;
|
|
28
31
|
}
|
|
29
32
|
export declare function NumberField(props: NumberFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
30
|
-
export declare function formatValue(value: number, factor: number, numFractionDigits: number | undefined): number | undefined;
|
|
33
|
+
export declare function formatValue(value: number, factor: number, numFractionDigits: number | undefined, numIntegerDigits: number | undefined): number | undefined;
|
|
@@ -15,21 +15,24 @@ 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, ...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, ...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;
|
|
22
22
|
const signDisplay = displayDirection ? "exceptZero" : "auto";
|
|
23
|
-
const
|
|
23
|
+
const defaultFormatOptions = (0, react_1.useMemo)(() => ({
|
|
24
|
+
[truncate ? "maximumFractionDigits" : "minimumFractionDigits"]: numFractionDigits,
|
|
25
|
+
...(numIntegerDigits !== undefined && { minimumIntegerDigits: numIntegerDigits }),
|
|
26
|
+
}), [truncate, numIntegerDigits]);
|
|
24
27
|
const { locale } = (0, react_aria_1.useLocale)();
|
|
25
28
|
// If formatOptions isn't memo'd, a useEffect in useNumberStateField will cause jank,
|
|
26
29
|
// see: https://github.com/adobe/react-spectrum/issues/1893.
|
|
27
30
|
const formatOptions = (0, react_1.useMemo)(() => {
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
31
|
+
if (numberFormatOptions !== undefined) {
|
|
32
|
+
return numberFormatOptions;
|
|
30
33
|
}
|
|
31
34
|
return type === "percent"
|
|
32
|
-
? { style: "percent", signDisplay, ...
|
|
35
|
+
? { style: "percent", signDisplay, ...defaultFormatOptions }
|
|
33
36
|
: type === "basisPoints"
|
|
34
37
|
? { style: "percent", minimumFractionDigits: 2, signDisplay }
|
|
35
38
|
: type === "cents"
|
|
@@ -38,8 +41,8 @@ function NumberField(props) {
|
|
|
38
41
|
? { style: "currency", currency: "USD", minimumFractionDigits: numFractionDigits !== null && numFractionDigits !== void 0 ? numFractionDigits : 2, signDisplay }
|
|
39
42
|
: type === "days"
|
|
40
43
|
? { style: "unit", unit: "day", unitDisplay: "long", maximumFractionDigits: 0, signDisplay }
|
|
41
|
-
:
|
|
42
|
-
}, [type]);
|
|
44
|
+
: defaultFormatOptions;
|
|
45
|
+
}, [type, numberFormatOptions]);
|
|
43
46
|
const numberParser = (0, react_1.useMemo)(() => new number_1.NumberParser(locale, formatOptions), [locale, formatOptions]);
|
|
44
47
|
const valueRef = (0, react_1.useRef)({ wip: false });
|
|
45
48
|
// We can use this for both useNumberFieldState + useNumberField
|
|
@@ -49,7 +52,7 @@ function NumberField(props) {
|
|
|
49
52
|
value: valueRef.current.wip ? valueRef.current.value : value === undefined ? Number.NaN : value / factor,
|
|
50
53
|
// // This is called on blur with the final/committed value.
|
|
51
54
|
onChange: (value) => {
|
|
52
|
-
onChange(formatValue(value, factor, numFractionDigits));
|
|
55
|
+
onChange(formatValue(value, factor, numFractionDigits, numIntegerDigits));
|
|
53
56
|
},
|
|
54
57
|
onFocus: () => {
|
|
55
58
|
valueRef.current = { wip: true, value: value === undefined ? Number.NaN : value / factor };
|
|
@@ -69,6 +72,7 @@ function NumberField(props) {
|
|
|
69
72
|
isDisabled,
|
|
70
73
|
isReadOnly,
|
|
71
74
|
formatOptions,
|
|
75
|
+
...otherProps,
|
|
72
76
|
};
|
|
73
77
|
const state = (0, react_stately_1.useNumberFieldState)(useProps);
|
|
74
78
|
const inputRef = (0, react_1.useRef)(null);
|
|
@@ -82,16 +86,28 @@ function NumberField(props) {
|
|
|
82
86
|
// This is called on each DOM change, to push the latest value into the field
|
|
83
87
|
onChange: (rawInputValue) => {
|
|
84
88
|
const parsedValue = numberParser.parse(rawInputValue || "");
|
|
85
|
-
onChange(formatValue(parsedValue, factor, numFractionDigits));
|
|
89
|
+
onChange(formatValue(parsedValue, factor, numFractionDigits, numIntegerDigits));
|
|
86
90
|
}, inputRef: inputRef, onBlur: onBlur, onFocus: onFocus, errorMsg: errorMsg, helperText: helperText, tooltip: (0, components_1.resolveTooltip)(disabled, undefined, readOnly) }, otherProps), void 0));
|
|
87
91
|
}
|
|
88
92
|
exports.NumberField = NumberField;
|
|
89
|
-
function formatValue(value, factor, numFractionDigits) {
|
|
93
|
+
function formatValue(value, factor, numFractionDigits, numIntegerDigits) {
|
|
90
94
|
// We treat percents & cents as (mostly) integers, while useNumberField wants decimals, so
|
|
91
95
|
// undo that via `* factor` and `Math.round`, but also keep any specifically-requested `numFractionDigits`,
|
|
92
96
|
// i.e. for `type=percent value=12.34`, `value` will be `0.1234` that we want turn into `12.34`.
|
|
93
97
|
const maybeAdjustForDecimals = numFractionDigits ? Math.pow(10, numFractionDigits) : 1;
|
|
94
98
|
// Reverse the integer/decimal conversion
|
|
95
|
-
|
|
99
|
+
const decimalAdjusted = Number.isNaN(value)
|
|
100
|
+
? undefined
|
|
101
|
+
: Math.round(value * factor * maybeAdjustForDecimals) / maybeAdjustForDecimals;
|
|
102
|
+
if (numIntegerDigits === undefined || decimalAdjusted === undefined) {
|
|
103
|
+
return decimalAdjusted;
|
|
104
|
+
}
|
|
105
|
+
// If `numIntegerDigits` is defined, then we must truncate that manually, so that 1234.56 can turn into 34.56
|
|
106
|
+
const fractionalValue = Math.round((decimalAdjusted % 1) * maybeAdjustForDecimals) / maybeAdjustForDecimals;
|
|
107
|
+
const maybeNegate = decimalAdjusted < 0 ? -1 : 1;
|
|
108
|
+
const trimmedInteger = Number(Math.trunc(Math.abs(decimalAdjusted))
|
|
109
|
+
.toString()
|
|
110
|
+
.slice(-1 * numIntegerDigits));
|
|
111
|
+
return (trimmedInteger + fractionalValue) * maybeNegate;
|
|
96
112
|
}
|
|
97
113
|
exports.formatValue = formatValue;
|
|
@@ -2,7 +2,7 @@ import type { NumberFieldAria } from "@react-aria/numberfield";
|
|
|
2
2
|
import { InputHTMLAttributes, LabelHTMLAttributes, MutableRefObject, ReactNode, TextareaHTMLAttributes } from "react";
|
|
3
3
|
import { Only } from "../Css";
|
|
4
4
|
import { BeamTextFieldProps, TextFieldXss } from "../interfaces";
|
|
5
|
-
export interface TextFieldBaseProps<X> extends Pick<BeamTextFieldProps<X>, "label" | "required" | "errorMsg" | "onBlur" | "onFocus" | "helperText" | "hideLabel" | "placeholder" | "compact" | "borderless" | "visuallyDisabled" | "xss">, Partial<Pick<BeamTextFieldProps<X>, "onChange">> {
|
|
5
|
+
export interface TextFieldBaseProps<X> extends Pick<BeamTextFieldProps<X>, "label" | "required" | "errorMsg" | "errorInTooltip" | "onBlur" | "onFocus" | "helperText" | "hideLabel" | "placeholder" | "compact" | "borderless" | "visuallyDisabled" | "xss">, Partial<Pick<BeamTextFieldProps<X>, "onChange">> {
|
|
6
6
|
labelProps?: LabelHTMLAttributes<HTMLLabelElement>;
|
|
7
7
|
inputProps: InputHTMLAttributes<HTMLInputElement> | TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
8
8
|
inputRef?: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null>;
|
|
@@ -17,9 +17,8 @@ const useTestIds_1 = require("../utils/useTestIds");
|
|
|
17
17
|
function TextFieldBase(props) {
|
|
18
18
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
19
|
const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
|
|
20
|
-
const { label, required, labelProps, hideLabel = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.hideLabel) !== null && _a !== void 0 ? _a : false, inputProps, inputRef, inputWrapRef, groupProps, compact = (_b = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact) !== null && _b !== void 0 ? _b : false, errorMsg, helperText, multiline = false, onChange, onBlur, onFocus, xss, endAdornment, startAdornment, inlineLabel, contrast = false, borderless = (_c = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.borderless) !== null && _c !== void 0 ? _c : false, textAreaMinHeight = 96, clearable = false, tooltip, visuallyDisabled = (_d = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.visuallyDisabled) !== null && _d !== void 0 ? _d : true, } = props;
|
|
21
|
-
const typeScale = (
|
|
22
|
-
const errorInTooltip = (_f = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.errorInTooltip) !== null && _f !== void 0 ? _f : false;
|
|
20
|
+
const { label, required, labelProps, hideLabel = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.hideLabel) !== null && _a !== void 0 ? _a : false, inputProps, inputRef, inputWrapRef, groupProps, compact = (_b = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.compact) !== null && _b !== void 0 ? _b : false, errorMsg, helperText, multiline = false, onChange, onBlur, onFocus, xss, endAdornment, startAdornment, inlineLabel, contrast = false, borderless = (_c = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.borderless) !== null && _c !== void 0 ? _c : false, textAreaMinHeight = 96, clearable = false, tooltip, visuallyDisabled = (_d = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.visuallyDisabled) !== null && _d !== void 0 ? _d : true, errorInTooltip = (_e = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.errorInTooltip) !== null && _e !== void 0 ? _e : false, } = props;
|
|
21
|
+
const typeScale = (_f = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.typeScale) !== null && _f !== void 0 ? _f : (inputProps.readOnly && !hideLabel ? "smMd" : "sm");
|
|
23
22
|
const internalProps = props.internalProps || {};
|
|
24
23
|
const { compound = false, forceFocus = false, forceHover = false } = internalProps;
|
|
25
24
|
const errorMessageId = `${inputProps.id}-error`;
|