@helpdice/ui 2.6.1-beta.0 → 2.6.1-beta.2
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/dist/auto-complete/index.js +128 -68
- package/dist/index.js +128 -68
- package/dist/input/index.js +128 -68
- package/dist/input/input-currency-props.d.ts +1 -1
- package/dist/input/input-currency-range.d.ts +18 -3
- package/dist/table/index.js +128 -68
- package/esm/input/input-currency-props.d.ts +1 -1
- package/esm/input/input-currency-range.d.ts +18 -3
- package/esm/input/input-currency-range.js +64 -57
- package/esm/input/input-currency.js +66 -14
- package/package.json +1 -1
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { CurrencyInputProps } from "./input-currency-props";
|
|
2
2
|
import React from "react";
|
|
3
3
|
type Override<T, U> = Omit<T, keyof U> & U;
|
|
4
|
+
type RangeValue = {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
};
|
|
8
|
+
type CurrencyRangeOutput = {
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
currency: string;
|
|
12
|
+
};
|
|
4
13
|
type CurrencyRangeProps = Override<CurrencyInputProps, {
|
|
5
|
-
|
|
14
|
+
value?: RangeValue;
|
|
15
|
+
defaultValue?: RangeValue;
|
|
16
|
+
onChange?: (val: CurrencyRangeOutput) => void;
|
|
17
|
+
debounce?: number;
|
|
18
|
+
error?: boolean;
|
|
19
|
+
helperText?: string;
|
|
6
20
|
}>;
|
|
7
|
-
declare function CurrencyRangeInput({ prefix, allowDecimals, onChange,
|
|
8
|
-
|
|
21
|
+
declare function CurrencyRangeInput({ prefix, allowDecimals, intlConfig, children, value, defaultValue, onChange, debounce, error: externalError, helperText: externalHelperText, }: CurrencyRangeProps): React.JSX.Element;
|
|
22
|
+
declare const _default: React.MemoExoticComponent<typeof CurrencyRangeInput>;
|
|
23
|
+
export default _default;
|
|
@@ -2,82 +2,89 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import Grid from "../grid";
|
|
4
4
|
import Input from ".";
|
|
5
|
-
import React, { useEffect } from "react";
|
|
6
|
-
import InputBlockLabel from "./input-block-label";
|
|
7
|
-
function parseCurrency(value) {
|
|
8
|
-
var _trimmed$match;
|
|
9
|
-
var trimmed = value.trim();
|
|
10
|
-
|
|
11
|
-
// Extract currency symbol
|
|
12
|
-
var currencySymbol = ((_trimmed$match = trimmed.match(/[^\d.,\s]/)) === null || _trimmed$match === void 0 ? void 0 : _trimmed$match[0]) || "";
|
|
13
|
-
|
|
14
|
-
// Remove everything except digits, comma, dot
|
|
15
|
-
var numericPart = trimmed.replace(/[^\d.,]/g, "");
|
|
16
|
-
|
|
17
|
-
// Convert comma to dot if needed
|
|
18
|
-
var normalized = numericPart.replace(",", ".");
|
|
19
|
-
return {
|
|
20
|
-
amount: Number(normalized),
|
|
21
|
-
currency: currencySymbol
|
|
22
|
-
};
|
|
23
|
-
}
|
|
5
|
+
import React, { useMemo, useState, useEffect, useCallback } from "react";
|
|
6
|
+
import InputBlockLabel, { InputError } from "./input-block-label";
|
|
24
7
|
function CurrencyRangeInput(_ref) {
|
|
25
8
|
var prefix = _ref.prefix,
|
|
26
9
|
allowDecimals = _ref.allowDecimals,
|
|
27
|
-
onChange = _ref.onChange,
|
|
28
10
|
intlConfig = _ref.intlConfig,
|
|
29
|
-
children = _ref.children
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
11
|
+
children = _ref.children,
|
|
12
|
+
value = _ref.value,
|
|
13
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
14
|
+
defaultValue = _ref$defaultValue === void 0 ? {
|
|
15
|
+
min: 0,
|
|
16
|
+
max: 0
|
|
17
|
+
} : _ref$defaultValue,
|
|
18
|
+
onChange = _ref.onChange,
|
|
19
|
+
_ref$debounce = _ref.debounce,
|
|
20
|
+
debounce = _ref$debounce === void 0 ? 300 : _ref$debounce,
|
|
21
|
+
externalError = _ref.error,
|
|
22
|
+
externalHelperText = _ref.helperText;
|
|
23
|
+
var isControlled = value !== undefined;
|
|
24
|
+
var _useState = useState(defaultValue),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
internalValue = _useState2[0],
|
|
27
|
+
setInternalValue = _useState2[1];
|
|
28
|
+
var currentValue = isControlled ? value : internalValue;
|
|
29
|
+
var setValue = useCallback(function (val) {
|
|
30
|
+
if (!isControlled) {
|
|
31
|
+
setInternalValue(val);
|
|
51
32
|
}
|
|
52
|
-
}, [
|
|
33
|
+
}, [isControlled]);
|
|
34
|
+
|
|
35
|
+
// Validation
|
|
36
|
+
var isInvalid = useMemo(function () {
|
|
37
|
+
if (!currentValue.min || !currentValue.max) return false;
|
|
38
|
+
return currentValue.max <= currentValue.min;
|
|
39
|
+
}, [currentValue]);
|
|
40
|
+
|
|
41
|
+
// Debounced onChange
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
if (!onChange || isInvalid) return;
|
|
44
|
+
var handler = setTimeout(function () {
|
|
45
|
+
if (currentValue.min && currentValue.max) {
|
|
46
|
+
onChange({
|
|
47
|
+
min: currentValue.min,
|
|
48
|
+
max: currentValue.max,
|
|
49
|
+
currency: ''
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, debounce);
|
|
53
|
+
return function () {
|
|
54
|
+
return clearTimeout(handler);
|
|
55
|
+
};
|
|
56
|
+
}, [isInvalid, onChange, debounce, currentValue]);
|
|
57
|
+
var finalError = externalError !== null && externalError !== void 0 ? externalError : isInvalid;
|
|
58
|
+
var finalHelperText = externalHelperText !== null && externalHelperText !== void 0 ? externalHelperText : isInvalid ? "Max must be greater than min" : undefined;
|
|
53
59
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
60
|
className: "with-label"
|
|
55
61
|
}, children && /*#__PURE__*/React.createElement(InputBlockLabel, null, children), /*#__PURE__*/React.createElement(Grid.Container, {
|
|
56
62
|
gap: 2
|
|
57
63
|
}, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Input.Currency, {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
+
value: currentValue.min,
|
|
65
|
+
onChange: function onChange(val) {
|
|
66
|
+
return setValue(_extends({}, currentValue, {
|
|
67
|
+
min: Number(val)
|
|
68
|
+
}));
|
|
64
69
|
},
|
|
65
70
|
intlConfig: intlConfig,
|
|
66
71
|
prefix: prefix,
|
|
67
72
|
placeholder: "Min",
|
|
68
73
|
allowDecimals: allowDecimals
|
|
69
74
|
})), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Input.Currency, {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
75
|
+
value: currentValue.max,
|
|
76
|
+
onChange: function onChange(val) {
|
|
77
|
+
return setValue(_extends({}, currentValue, {
|
|
78
|
+
max: Number(val)
|
|
79
|
+
}));
|
|
76
80
|
},
|
|
77
81
|
intlConfig: intlConfig,
|
|
78
82
|
prefix: prefix,
|
|
79
83
|
placeholder: "Max",
|
|
80
84
|
allowDecimals: allowDecimals
|
|
81
|
-
})))
|
|
85
|
+
}))), finalHelperText && /*#__PURE__*/React.createElement(InputError, {
|
|
86
|
+
error: finalError,
|
|
87
|
+
text: finalHelperText
|
|
88
|
+
}));
|
|
82
89
|
}
|
|
83
|
-
export default CurrencyRangeInput;
|
|
90
|
+
export default /*#__PURE__*/React.memo(CurrencyRangeInput);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "
|
|
4
|
+
var _excluded = ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "fixedDecimalLength", "placeholder", "decimalScale", "prefix", "suffix", "intlConfig", "fullWidth", "step", "min", "max", "disableGroupSeparators", "disableAbbreviations", "decimalSeparator", "groupSeparator", "onChange", "onFocus", "onBlur", "onKeyDown", "onKeyUp", "transformRawValue", "formatValueOnBlur", "children"];
|
|
5
5
|
import _JSXStyle from "../styled-jsx.es.js";
|
|
6
6
|
import React, { useState, useEffect, useRef, forwardRef, useMemo, useImperativeHandle } from 'react';
|
|
7
7
|
import { isNumber, cleanValue, fixedDecimalValue, formatValue, getLocaleConfig, padTrimValue, getSuffix, repositionCursor } from './utils';
|
|
@@ -23,7 +23,6 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
23
23
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
24
24
|
userMaxLength = _ref.maxLength,
|
|
25
25
|
userValue = _ref.value,
|
|
26
|
-
onValueChange = _ref.onValueChange,
|
|
27
26
|
fixedDecimalLength = _ref.fixedDecimalLength,
|
|
28
27
|
placeholder = _ref.placeholder,
|
|
29
28
|
decimalScale = _ref.decimalScale,
|
|
@@ -136,11 +135,15 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
136
135
|
var stringValue = cleanValue(_extends({
|
|
137
136
|
value: modifiedValue
|
|
138
137
|
}, cleanValueOptions));
|
|
138
|
+
|
|
139
|
+
// console.log("Before clean:", modifiedValue);
|
|
140
|
+
// console.log("After clean:", stringValue);
|
|
141
|
+
|
|
139
142
|
if (userMaxLength && stringValue.replace(/-/g, '').length > userMaxLength) {
|
|
140
143
|
return;
|
|
141
144
|
}
|
|
142
145
|
if (stringValue === '' || stringValue === '-' || stringValue === decimalSeparator) {
|
|
143
|
-
|
|
146
|
+
onChange && onChange(undefined, name, {
|
|
144
147
|
"float": null,
|
|
145
148
|
formatted: '',
|
|
146
149
|
value: ''
|
|
@@ -152,9 +155,15 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
152
155
|
}
|
|
153
156
|
var stringValueWithoutSeparator = decimalSeparator ? stringValue.replace(decimalSeparator, '.') : stringValue;
|
|
154
157
|
var numberValue = parseFloat(stringValueWithoutSeparator);
|
|
158
|
+
|
|
159
|
+
// console.log('Number Value', numberValue);
|
|
160
|
+
|
|
155
161
|
var formattedValue = formatValue(_extends({
|
|
156
162
|
value: stringValue
|
|
157
163
|
}, formatValueOptions));
|
|
164
|
+
|
|
165
|
+
// console.log('Formatted Value', numberValue);
|
|
166
|
+
|
|
158
167
|
if (cursorPosition != null) {
|
|
159
168
|
// Prevent cursor jumping
|
|
160
169
|
var newCursor = cursorPosition + (formattedValue.length - value.length);
|
|
@@ -162,15 +171,25 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
162
171
|
setCursor(newCursor);
|
|
163
172
|
setChangeCount(changeCount + 1);
|
|
164
173
|
}
|
|
174
|
+
|
|
175
|
+
// console.log({
|
|
176
|
+
// inputValue: value,
|
|
177
|
+
// modifiedValue,
|
|
178
|
+
// stateValue,
|
|
179
|
+
// selectionStart,
|
|
180
|
+
// lastKeyStroke
|
|
181
|
+
// });
|
|
182
|
+
|
|
165
183
|
setStateValue(formattedValue);
|
|
166
|
-
if (
|
|
184
|
+
if (onChange) {
|
|
167
185
|
var values = {
|
|
168
186
|
"float": numberValue,
|
|
169
187
|
formatted: formattedValue,
|
|
170
188
|
value: stringValue
|
|
171
189
|
};
|
|
172
|
-
|
|
190
|
+
onChange(stringValue, name, values);
|
|
173
191
|
}
|
|
192
|
+
// onChange && onChange(stringValue);
|
|
174
193
|
};
|
|
175
194
|
|
|
176
195
|
/**
|
|
@@ -181,7 +200,6 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
181
200
|
value = _event$target.value,
|
|
182
201
|
selectionStart = _event$target.selectionStart;
|
|
183
202
|
processChange(value, selectionStart);
|
|
184
|
-
onChange && onChange(event);
|
|
185
203
|
};
|
|
186
204
|
|
|
187
205
|
/**
|
|
@@ -213,8 +231,8 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
213
231
|
var formattedValue = formatValue(_extends({}, formatValueOptions, {
|
|
214
232
|
value: newValue
|
|
215
233
|
}));
|
|
216
|
-
if (
|
|
217
|
-
|
|
234
|
+
if (onChange && formatValueOnBlur) {
|
|
235
|
+
onChange(newValue, name, {
|
|
218
236
|
"float": numberValue,
|
|
219
237
|
formatted: formattedValue,
|
|
220
238
|
value: newValue
|
|
@@ -251,6 +269,34 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
251
269
|
onKeyDown && onKeyDown(event);
|
|
252
270
|
};
|
|
253
271
|
|
|
272
|
+
// const handleOnKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
273
|
+
// lastKeyStrokeRef.current = event.key;
|
|
274
|
+
|
|
275
|
+
// // Handle arrow up/down with step
|
|
276
|
+
// if (step && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
|
|
277
|
+
// event.preventDefault();
|
|
278
|
+
|
|
279
|
+
// const currentValue =
|
|
280
|
+
// parseFloat(
|
|
281
|
+
// userValue != null
|
|
282
|
+
// ? String(userValue).replace(decimalSeparator, '.')
|
|
283
|
+
// : cleanValue({ value: stateValue, ...cleanValueOptions })
|
|
284
|
+
// ) || 0;
|
|
285
|
+
|
|
286
|
+
// const newValue = event.key === 'ArrowUp' ? currentValue + step : currentValue - step;
|
|
287
|
+
|
|
288
|
+
// if ((min !== undefined && newValue < Number(min)) || (max !== undefined && newValue > Number(max))) return;
|
|
289
|
+
|
|
290
|
+
// const fixedLength = String(step).includes('.') ? String(step).split('.')[1].length : undefined;
|
|
291
|
+
|
|
292
|
+
// processChange(
|
|
293
|
+
// (fixedLength ? newValue.toFixed(fixedLength) : newValue).replace('.', decimalSeparator)
|
|
294
|
+
// );
|
|
295
|
+
// }
|
|
296
|
+
|
|
297
|
+
// onKeyDown && onKeyDown(event);
|
|
298
|
+
// };
|
|
299
|
+
|
|
254
300
|
/**
|
|
255
301
|
* Handle key up event
|
|
256
302
|
*
|
|
@@ -292,13 +338,19 @@ export var InputCurrency = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
292
338
|
* If user has only entered "-" or decimal separator,
|
|
293
339
|
* keep the char to allow them to enter next value
|
|
294
340
|
*/
|
|
341
|
+
// const getRenderValue = () => {
|
|
342
|
+
// if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
343
|
+
// // console.log('User Value', userValue);
|
|
344
|
+
// return formatValue({
|
|
345
|
+
// ...formatValueOptions,
|
|
346
|
+
// decimalScale: dirty ? undefined : decimalScale,
|
|
347
|
+
// value: String(userValue)
|
|
348
|
+
// });
|
|
349
|
+
// }
|
|
350
|
+
|
|
351
|
+
// return stateValue;
|
|
352
|
+
// };
|
|
295
353
|
var getRenderValue = function getRenderValue() {
|
|
296
|
-
if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
297
|
-
return formatValue(_extends({}, formatValueOptions, {
|
|
298
|
-
decimalScale: dirty ? undefined : decimalScale,
|
|
299
|
-
value: String(userValue)
|
|
300
|
-
}));
|
|
301
|
-
}
|
|
302
354
|
return stateValue;
|
|
303
355
|
};
|
|
304
356
|
var inputProps = _extends({
|