@servicetitan/form 23.3.0 → 23.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/demo/number-input.d.ts.map +1 -1
- package/dist/demo/number-input.js +6 -2
- package/dist/demo/number-input.js.map +1 -1
- package/dist/number-input/number-input.d.ts.map +1 -1
- package/dist/number-input/number-input.js +6 -2
- package/dist/number-input/number-input.js.map +1 -1
- package/dist/number-input/process-value.js +1 -6
- package/dist/number-input/process-value.js.map +1 -1
- package/package.json +8 -8
- package/src/demo/number-input.tsx +53 -1
- package/src/number-input/__tests__/process-value.test.ts +2 -2
- package/src/number-input/number-input.tsx +8 -2
- package/src/number-input/process-value.ts +1 -8
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../src/demo/number-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,EAAE,EAAE,MAAM,OAAO,CAAC;AAc7C,eAAO,MAAM,kBAAkB,EAAE,
|
1
|
+
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../src/demo/number-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,EAAE,EAAE,MAAM,OAAO,CAAC;AAc7C,eAAO,MAAM,kBAAkB,EAAE,EAuG/B,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { useRef, Fragment } from 'react';
|
3
3
|
import { observer } from 'mobx-react';
|
4
|
-
import { Text } from '@servicetitan/design-system';
|
4
|
+
import { Stack, Text } from '@servicetitan/design-system';
|
5
5
|
import { NumberInput } from '..';
|
6
6
|
import { FieldState } from 'formstate';
|
7
7
|
function useNumberField(initial) {
|
@@ -13,6 +13,10 @@ export const NumberInputExample = observer(() => {
|
|
13
13
|
const precisionField = useNumberField(undefined);
|
14
14
|
const limitedRangeField = useNumberField(undefined);
|
15
15
|
const withoutThousandsSeparator = useNumberField(undefined);
|
16
|
-
|
16
|
+
const limitedRangeFieldPreset = useNumberField(100);
|
17
|
+
const precisionFieldPreset = useNumberField(3.6666666);
|
18
|
+
const precisionFieldPresetExtreme = useNumberField(3.6666666);
|
19
|
+
return (_jsxs(Fragment, { children: [_jsx(Text, Object.assign({ size: 4, className: "m-b-half" }, { children: "Default" })), _jsx(NumberInput, { value: defaultField.value, onChange: defaultField.onChange, emptyValue: undefined }), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Zero as empty value" })), _jsx(NumberInput, { value: zeroEmptyValueField.value, onChange: zeroEmptyValueField.onChange, emptyValue: 0 }), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Precision" })), _jsx(NumberInput, { value: precisionField.value, onChange: precisionField.onChange, emptyValue: undefined, decimalPlaces: 3 }), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Limited range" })), _jsx(NumberInput, { value: limitedRangeField.value, onChange: limitedRangeField.onChange, emptyValue: undefined, min: 3, max: 7 }), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Without thousands separator" })), _jsx(NumberInput, { value: withoutThousandsSeparator.value, onChange: withoutThousandsSeparator.onChange, emptyValue: undefined, decimalPlaces: 0, useEmptyThousandsSeparator: true }), _jsx("hr", { className: "m-y-4" }), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Preset value out of range" })), _jsx(StoredValueWrapper, Object.assign({ value: limitedRangeFieldPreset.value }, { children: _jsx(NumberInput, { value: limitedRangeFieldPreset.value, onChange: limitedRangeFieldPreset.onChange, emptyValue: undefined, min: 3, max: 7 }) })), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Preset value with precision out of limit" })), _jsx(StoredValueWrapper, Object.assign({ value: precisionFieldPreset.value }, { children: _jsx(NumberInput, { value: precisionFieldPreset.value, onChange: precisionFieldPreset.onChange, emptyValue: undefined, decimalPlaces: 3 }) })), _jsx(Text, Object.assign({ size: 4, className: "m-t-4 m-b-half" }, { children: "Preset value with precision out of limit (zero decimals allowed)" })), _jsx(StoredValueWrapper, Object.assign({ value: precisionFieldPresetExtreme.value }, { children: _jsx(NumberInput, { value: precisionFieldPresetExtreme.value, onChange: precisionFieldPresetExtreme.onChange, emptyValue: undefined, decimalPlaces: 0 }) }))] }));
|
17
20
|
});
|
21
|
+
const StoredValueWrapper = ({ children, value }) => (_jsxs(Stack, Object.assign({ alignItems: "baseline" }, { children: [children, _jsxs(Text, Object.assign({ size: 3, className: "m-l-3" }, { children: ["Stored value: ", value] }))] })));
|
18
22
|
//# sourceMappingURL=number-input.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"number-input.js","sourceRoot":"","sources":["../../src/demo/number-input.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;
|
1
|
+
{"version":3,"file":"number-input.js","sourceRoot":"","sources":["../../src/demo/number-input.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAM,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,SAAS,cAAc,CAA+B,OAAU;IAC5D,OAAO,MAAM,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAO,QAAQ,CAAC,GAAG,EAAE;IAChD,MAAM,YAAY,GAAG,cAAc,CAAqB,SAAS,CAAC,CAAC;IACnE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C,GAClB,IACe,IACd,CACd,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAA2B,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CACxE,MAAC,KAAK,kBAAC,UAAU,EAAC,UAAU,iBACvB,QAAQ,EACT,MAAC,IAAI,kBAAC,IAAI,EAAE,CAAC,EAAE,SAAS,EAAC,OAAO,mCACb,KAAK,KACjB,KACH,CACX,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../src/number-input/number-input.tsx"],"names":[],"mappings":";AAYA,OAAO,EAAS,UAAU,EAAqB,MAAM,6BAA6B,CAAC;AAInF,OAAO,EAAE,YAAY,EAAsB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAS9D,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,UAAU,CACvD,SAAQ,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,CAAC;IAC9C,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;CAC9C;AAED,eAAO,MAAM,WAAW,
|
1
|
+
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../src/number-input/number-input.tsx"],"names":[],"mappings":";AAYA,OAAO,EAAS,UAAU,EAAqB,MAAM,6BAA6B,CAAC;AAInF,OAAO,EAAE,YAAY,EAAsB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAS9D,MAAM,WAAW,gBAAgB,CAAC,MAAM,SAAS,UAAU,CACvD,SAAQ,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,CAAC;IAC9C,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;CAC9C;AAED,eAAO,MAAM,WAAW,4NAoMvB,CAAC"}
|
@@ -125,8 +125,12 @@ export const NumberInput = (_a) => {
|
|
125
125
|
(_a = updateClampedValueDebounced.current) === null || _a === void 0 ? void 0 : _a.call(updateClampedValueDebounced, value, silent);
|
126
126
|
};
|
127
127
|
const handleFocus = (event) => {
|
128
|
-
if (state.
|
129
|
-
updateValue(
|
128
|
+
if (state.stringValue.length) {
|
129
|
+
updateValue(
|
130
|
+
// prepare the value which user does see (rounded), but without trailing zeroes after decimal and separator
|
131
|
+
decimalPlaces
|
132
|
+
? state.stringValue.replace(new RegExp(`[${decimalSeparator}]?0+$`), '')
|
133
|
+
: state.stringValue, true);
|
130
134
|
}
|
131
135
|
setIsFocused(true);
|
132
136
|
if (onFocus) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"number-input.js","sourceRoot":"","sources":["../../src/number-input/number-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACH,WAAW,EACX,QAAQ,EACR,SAAS,EACT,MAA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C,CAAC;SACjB;IACL,CAAC,CAAC;IAEF,OAAO,CACH,KAAC,KAAK,oBACE,KAAK,IACT,KAAK,EAAE,KAAK,CAAC,WAAW,EACxB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,IAC9D,CACL,CAAC;AACN,CAAC,CAAC"}
|
@@ -43,12 +43,7 @@ function trimDecimalPlace(value, separator, formatNumber, precision) {
|
|
43
43
|
const intPart = (isNegative ? '-' : '') + String(Math.abs(+splitValue[0]));
|
44
44
|
let fracPart = splitValue[1];
|
45
45
|
if (fracPart && fracPart.length > precision) {
|
46
|
-
fracPart =
|
47
|
-
// 0.9(9) will be rounded to 1.0
|
48
|
-
if (fracPart.startsWith('1.')) {
|
49
|
-
fracPart = `0.${splitValue[1].substring(0, precision)}`;
|
50
|
-
}
|
51
|
-
fracPart = fracPart.slice(2);
|
46
|
+
fracPart = fracPart.slice(0, precision);
|
52
47
|
}
|
53
48
|
return `${intPart}.${fracPart}`;
|
54
49
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"process-value.js","sourceRoot":"","sources":["../../src/number-input/process-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAYjE,MAAM,UAAU,YAAY,CACxB,KAAa,EACb,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,GAAG,EAAE,EAA+B,EAC9E,eAA6B,mBAAmB;IAEhD,IAAI,UAAU,GAAG,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAE/C,sBAAsB;IACtB,IAAI,UAAU,KAAK,EAAE,IAAI,UAAU,KAAK,GAAG,EAAE;QACzC,IAAI,aAAa,GAAG,UAAgC,CAAC;QACrD,IAAI,aAAa,GAAG,UAAU,CAAC;QAC/B,IAA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CAAC;QACnD,+BAA+B;SAC9B,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAE1C,OAAO,YAAY,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@servicetitan/form",
|
3
|
-
"version": "23.3.
|
3
|
+
"version": "23.3.1",
|
4
4
|
"description": "",
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/form",
|
6
6
|
"repository": {
|
@@ -16,10 +16,10 @@
|
|
16
16
|
"src"
|
17
17
|
],
|
18
18
|
"devDependencies": {
|
19
|
-
"@servicetitan/confirm": "^23.3.
|
20
|
-
"@servicetitan/culture": "^23.3.
|
19
|
+
"@servicetitan/confirm": "^23.3.1",
|
20
|
+
"@servicetitan/culture": "^23.3.1",
|
21
21
|
"@servicetitan/design-system": ">=12.4.1",
|
22
|
-
"@servicetitan/form-state": "^23.3.
|
22
|
+
"@servicetitan/form-state": "^23.3.1",
|
23
23
|
"@servicetitan/react-ioc": "^21.6.0",
|
24
24
|
"@servicetitan/tokens": ">=12.1.11",
|
25
25
|
"@types/react": "~17.0.38",
|
@@ -35,10 +35,10 @@
|
|
35
35
|
"resumablejs": "~1.0.2"
|
36
36
|
},
|
37
37
|
"peerDependencies": {
|
38
|
-
"@servicetitan/confirm": "^23.3.
|
39
|
-
"@servicetitan/culture": "^23.3.
|
38
|
+
"@servicetitan/confirm": "^23.3.1",
|
39
|
+
"@servicetitan/culture": "^23.3.1",
|
40
40
|
"@servicetitan/design-system": ">=12.4.1",
|
41
|
-
"@servicetitan/form-state": "^23.3.
|
41
|
+
"@servicetitan/form-state": "^23.3.1",
|
42
42
|
"@servicetitan/react-ioc": ">21.0.0",
|
43
43
|
"@servicetitan/tokens": ">=12.1.11",
|
44
44
|
"accounting": "~0.4.1",
|
@@ -66,5 +66,5 @@
|
|
66
66
|
"less": true,
|
67
67
|
"webpack": false
|
68
68
|
},
|
69
|
-
"gitHead": "
|
69
|
+
"gitHead": "7e7249314331ad1cd1762f226b679294c0b39667"
|
70
70
|
}
|
@@ -2,7 +2,7 @@ import { useRef, Fragment, FC } from 'react';
|
|
2
2
|
|
3
3
|
import { observer } from 'mobx-react';
|
4
4
|
|
5
|
-
import { Text } from '@servicetitan/design-system';
|
5
|
+
import { Stack, Text } from '@servicetitan/design-system';
|
6
6
|
|
7
7
|
import { NumberInput } from '..';
|
8
8
|
|
@@ -19,6 +19,10 @@ export const NumberInputExample: FC = observer(() => {
|
|
19
19
|
const limitedRangeField = useNumberField<number | undefined>(undefined);
|
20
20
|
const withoutThousandsSeparator = useNumberField<number | undefined>(undefined);
|
21
21
|
|
22
|
+
const limitedRangeFieldPreset = useNumberField<number | undefined>(100);
|
23
|
+
const precisionFieldPreset = useNumberField<number | undefined>(3.6666666);
|
24
|
+
const precisionFieldPresetExtreme = useNumberField<number | undefined>(3.6666666);
|
25
|
+
|
22
26
|
return (
|
23
27
|
<Fragment>
|
24
28
|
<Text size={4} className="m-b-half">
|
@@ -70,6 +74,54 @@ export const NumberInputExample: FC = observer(() => {
|
|
70
74
|
decimalPlaces={0}
|
71
75
|
useEmptyThousandsSeparator
|
72
76
|
/>
|
77
|
+
|
78
|
+
<hr className="m-y-4" />
|
79
|
+
|
80
|
+
<Text size={4} className="m-t-4 m-b-half">
|
81
|
+
Preset value out of range
|
82
|
+
</Text>
|
83
|
+
<StoredValueWrapper value={limitedRangeFieldPreset.value}>
|
84
|
+
<NumberInput
|
85
|
+
value={limitedRangeFieldPreset.value}
|
86
|
+
onChange={limitedRangeFieldPreset.onChange}
|
87
|
+
emptyValue={undefined}
|
88
|
+
min={3}
|
89
|
+
max={7}
|
90
|
+
/>
|
91
|
+
</StoredValueWrapper>
|
92
|
+
|
93
|
+
<Text size={4} className="m-t-4 m-b-half">
|
94
|
+
Preset value with precision out of limit
|
95
|
+
</Text>
|
96
|
+
<StoredValueWrapper value={precisionFieldPreset.value}>
|
97
|
+
<NumberInput
|
98
|
+
value={precisionFieldPreset.value}
|
99
|
+
onChange={precisionFieldPreset.onChange}
|
100
|
+
emptyValue={undefined}
|
101
|
+
decimalPlaces={3}
|
102
|
+
/>
|
103
|
+
</StoredValueWrapper>
|
104
|
+
|
105
|
+
<Text size={4} className="m-t-4 m-b-half">
|
106
|
+
Preset value with precision out of limit (zero decimals allowed)
|
107
|
+
</Text>
|
108
|
+
<StoredValueWrapper value={precisionFieldPresetExtreme.value}>
|
109
|
+
<NumberInput
|
110
|
+
value={precisionFieldPresetExtreme.value}
|
111
|
+
onChange={precisionFieldPresetExtreme.onChange}
|
112
|
+
emptyValue={undefined}
|
113
|
+
decimalPlaces={0}
|
114
|
+
/>
|
115
|
+
</StoredValueWrapper>
|
73
116
|
</Fragment>
|
74
117
|
);
|
75
118
|
});
|
119
|
+
|
120
|
+
const StoredValueWrapper: FC<{ value?: number }> = ({ children, value }) => (
|
121
|
+
<Stack alignItems="baseline">
|
122
|
+
{children}
|
123
|
+
<Text size={3} className="m-l-3">
|
124
|
+
Stored value: {value}
|
125
|
+
</Text>
|
126
|
+
</Stack>
|
127
|
+
);
|
@@ -278,8 +278,8 @@ describe('processValue', () => {
|
|
278
278
|
stringValue: '5.55',
|
279
279
|
});
|
280
280
|
expect(processValue('5.555', options)).toEqual({
|
281
|
-
numberValue: 5.
|
282
|
-
stringValue: '5.
|
281
|
+
numberValue: 5.55,
|
282
|
+
stringValue: '5.55',
|
283
283
|
});
|
284
284
|
expect(processValue('5.999', options)).toEqual({
|
285
285
|
numberValue: 5.99,
|
@@ -193,8 +193,14 @@ export const NumberInput = <TEmpty extends EmptyValue>({
|
|
193
193
|
};
|
194
194
|
|
195
195
|
const handleFocus = (event: FocusEvent<HTMLInputElement>) => {
|
196
|
-
if (state.
|
197
|
-
updateValue(
|
196
|
+
if (state.stringValue.length) {
|
197
|
+
updateValue(
|
198
|
+
// prepare the value which user does see (rounded), but without trailing zeroes after decimal and separator
|
199
|
+
decimalPlaces
|
200
|
+
? state.stringValue.replace(new RegExp(`[${decimalSeparator}]?0+$`), '')
|
201
|
+
: state.stringValue,
|
202
|
+
true
|
203
|
+
);
|
198
204
|
}
|
199
205
|
|
200
206
|
setIsFocused(true);
|
@@ -69,14 +69,7 @@ function trimDecimalPlace(
|
|
69
69
|
const intPart = (isNegative ? '-' : '') + String(Math.abs(+splitValue[0]));
|
70
70
|
let fracPart = splitValue[1];
|
71
71
|
if (fracPart && fracPart.length > precision) {
|
72
|
-
fracPart =
|
73
|
-
|
74
|
-
// 0.9(9) will be rounded to 1.0
|
75
|
-
if (fracPart.startsWith('1.')) {
|
76
|
-
fracPart = `0.${splitValue[1].substring(0, precision)}`;
|
77
|
-
}
|
78
|
-
|
79
|
-
fracPart = fracPart.slice(2);
|
72
|
+
fracPart = fracPart.slice(0, precision);
|
80
73
|
}
|
81
74
|
return `${intPart}.${fracPart}`;
|
82
75
|
}
|