@helpdice/ui 2.6.1-beta.1 → 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 +127 -68
- package/dist/index.js +127 -68
- package/dist/input/index.js +127 -68
- package/dist/input/input-currency-props.d.ts +1 -1
- package/dist/input/input-currency-range.d.ts +16 -3
- package/dist/table/index.js +127 -68
- package/esm/input/input-currency-props.d.ts +1 -1
- package/esm/input/input-currency-range.d.ts +16 -3
- package/esm/input/input-currency-range.js +61 -55
- package/esm/input/input-currency.js +66 -14
- package/package.json +1 -1
package/dist/input/index.js
CHANGED
|
@@ -3189,7 +3189,7 @@ var repositionCursor = function repositionCursor(_ref) {
|
|
|
3189
3189
|
};
|
|
3190
3190
|
};
|
|
3191
3191
|
|
|
3192
|
-
var _excluded$3 = ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "
|
|
3192
|
+
var _excluded$3 = ["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"];
|
|
3193
3193
|
var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
3194
3194
|
var _ref$allowDecimals = _ref.allowDecimals,
|
|
3195
3195
|
allowDecimals = _ref$allowDecimals === void 0 ? true : _ref$allowDecimals,
|
|
@@ -3205,7 +3205,6 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3205
3205
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
3206
3206
|
userMaxLength = _ref.maxLength,
|
|
3207
3207
|
userValue = _ref.value,
|
|
3208
|
-
onValueChange = _ref.onValueChange,
|
|
3209
3208
|
fixedDecimalLength = _ref.fixedDecimalLength,
|
|
3210
3209
|
placeholder = _ref.placeholder,
|
|
3211
3210
|
decimalScale = _ref.decimalScale,
|
|
@@ -3318,11 +3317,15 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3318
3317
|
var stringValue = cleanValue(_objectSpread2({
|
|
3319
3318
|
value: modifiedValue
|
|
3320
3319
|
}, cleanValueOptions));
|
|
3320
|
+
|
|
3321
|
+
// console.log("Before clean:", modifiedValue);
|
|
3322
|
+
// console.log("After clean:", stringValue);
|
|
3323
|
+
|
|
3321
3324
|
if (userMaxLength && stringValue.replace(/-/g, '').length > userMaxLength) {
|
|
3322
3325
|
return;
|
|
3323
3326
|
}
|
|
3324
3327
|
if (stringValue === '' || stringValue === '-' || stringValue === decimalSeparator) {
|
|
3325
|
-
|
|
3328
|
+
onChange && onChange(undefined, name, {
|
|
3326
3329
|
"float": null,
|
|
3327
3330
|
formatted: '',
|
|
3328
3331
|
value: ''
|
|
@@ -3334,9 +3337,15 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3334
3337
|
}
|
|
3335
3338
|
var stringValueWithoutSeparator = decimalSeparator ? stringValue.replace(decimalSeparator, '.') : stringValue;
|
|
3336
3339
|
var numberValue = parseFloat(stringValueWithoutSeparator);
|
|
3340
|
+
|
|
3341
|
+
// console.log('Number Value', numberValue);
|
|
3342
|
+
|
|
3337
3343
|
var formattedValue = formatValue(_objectSpread2({
|
|
3338
3344
|
value: stringValue
|
|
3339
3345
|
}, formatValueOptions));
|
|
3346
|
+
|
|
3347
|
+
// console.log('Formatted Value', numberValue);
|
|
3348
|
+
|
|
3340
3349
|
if (cursorPosition != null) {
|
|
3341
3350
|
// Prevent cursor jumping
|
|
3342
3351
|
var newCursor = cursorPosition + (formattedValue.length - value.length);
|
|
@@ -3344,15 +3353,25 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3344
3353
|
setCursor(newCursor);
|
|
3345
3354
|
setChangeCount(changeCount + 1);
|
|
3346
3355
|
}
|
|
3356
|
+
|
|
3357
|
+
// console.log({
|
|
3358
|
+
// inputValue: value,
|
|
3359
|
+
// modifiedValue,
|
|
3360
|
+
// stateValue,
|
|
3361
|
+
// selectionStart,
|
|
3362
|
+
// lastKeyStroke
|
|
3363
|
+
// });
|
|
3364
|
+
|
|
3347
3365
|
setStateValue(formattedValue);
|
|
3348
|
-
if (
|
|
3366
|
+
if (onChange) {
|
|
3349
3367
|
var values = {
|
|
3350
3368
|
"float": numberValue,
|
|
3351
3369
|
formatted: formattedValue,
|
|
3352
3370
|
value: stringValue
|
|
3353
3371
|
};
|
|
3354
|
-
|
|
3372
|
+
onChange(stringValue, name, values);
|
|
3355
3373
|
}
|
|
3374
|
+
// onChange && onChange(stringValue);
|
|
3356
3375
|
};
|
|
3357
3376
|
|
|
3358
3377
|
/**
|
|
@@ -3363,7 +3382,6 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3363
3382
|
value = _event$target.value,
|
|
3364
3383
|
selectionStart = _event$target.selectionStart;
|
|
3365
3384
|
processChange(value, selectionStart);
|
|
3366
|
-
onChange && onChange(event);
|
|
3367
3385
|
};
|
|
3368
3386
|
|
|
3369
3387
|
/**
|
|
@@ -3395,8 +3413,8 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3395
3413
|
var formattedValue = formatValue(_objectSpread2(_objectSpread2({}, formatValueOptions), {}, {
|
|
3396
3414
|
value: newValue
|
|
3397
3415
|
}));
|
|
3398
|
-
if (
|
|
3399
|
-
|
|
3416
|
+
if (onChange && formatValueOnBlur) {
|
|
3417
|
+
onChange(newValue, name, {
|
|
3400
3418
|
"float": numberValue,
|
|
3401
3419
|
formatted: formattedValue,
|
|
3402
3420
|
value: newValue
|
|
@@ -3433,6 +3451,34 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3433
3451
|
onKeyDown && onKeyDown(event);
|
|
3434
3452
|
};
|
|
3435
3453
|
|
|
3454
|
+
// const handleOnKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
3455
|
+
// lastKeyStrokeRef.current = event.key;
|
|
3456
|
+
|
|
3457
|
+
// // Handle arrow up/down with step
|
|
3458
|
+
// if (step && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
|
|
3459
|
+
// event.preventDefault();
|
|
3460
|
+
|
|
3461
|
+
// const currentValue =
|
|
3462
|
+
// parseFloat(
|
|
3463
|
+
// userValue != null
|
|
3464
|
+
// ? String(userValue).replace(decimalSeparator, '.')
|
|
3465
|
+
// : cleanValue({ value: stateValue, ...cleanValueOptions })
|
|
3466
|
+
// ) || 0;
|
|
3467
|
+
|
|
3468
|
+
// const newValue = event.key === 'ArrowUp' ? currentValue + step : currentValue - step;
|
|
3469
|
+
|
|
3470
|
+
// if ((min !== undefined && newValue < Number(min)) || (max !== undefined && newValue > Number(max))) return;
|
|
3471
|
+
|
|
3472
|
+
// const fixedLength = String(step).includes('.') ? String(step).split('.')[1].length : undefined;
|
|
3473
|
+
|
|
3474
|
+
// processChange(
|
|
3475
|
+
// (fixedLength ? newValue.toFixed(fixedLength) : newValue).replace('.', decimalSeparator)
|
|
3476
|
+
// );
|
|
3477
|
+
// }
|
|
3478
|
+
|
|
3479
|
+
// onKeyDown && onKeyDown(event);
|
|
3480
|
+
// };
|
|
3481
|
+
|
|
3436
3482
|
/**
|
|
3437
3483
|
* Handle key up event
|
|
3438
3484
|
*
|
|
@@ -3474,13 +3520,19 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3474
3520
|
* If user has only entered "-" or decimal separator,
|
|
3475
3521
|
* keep the char to allow them to enter next value
|
|
3476
3522
|
*/
|
|
3523
|
+
// const getRenderValue = () => {
|
|
3524
|
+
// if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
3525
|
+
// // console.log('User Value', userValue);
|
|
3526
|
+
// return formatValue({
|
|
3527
|
+
// ...formatValueOptions,
|
|
3528
|
+
// decimalScale: dirty ? undefined : decimalScale,
|
|
3529
|
+
// value: String(userValue)
|
|
3530
|
+
// });
|
|
3531
|
+
// }
|
|
3532
|
+
|
|
3533
|
+
// return stateValue;
|
|
3534
|
+
// };
|
|
3477
3535
|
var getRenderValue = function getRenderValue() {
|
|
3478
|
-
if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
3479
|
-
return formatValue(_objectSpread2(_objectSpread2({}, formatValueOptions), {}, {
|
|
3480
|
-
decimalScale: dirty ? undefined : decimalScale,
|
|
3481
|
-
value: String(userValue)
|
|
3482
|
-
}));
|
|
3483
|
-
}
|
|
3484
3536
|
return stateValue;
|
|
3485
3537
|
};
|
|
3486
3538
|
var inputProps = _objectSpread2({
|
|
@@ -3679,50 +3731,58 @@ var GridContainer = withScale(GridContainerComponent);
|
|
|
3679
3731
|
|
|
3680
3732
|
Grid.Container = GridContainer;
|
|
3681
3733
|
|
|
3682
|
-
function parseCurrency(value) {
|
|
3683
|
-
var _trimmed$match;
|
|
3684
|
-
var trimmed = value.trim();
|
|
3685
|
-
|
|
3686
|
-
// Extract currency symbol
|
|
3687
|
-
var currencySymbol = ((_trimmed$match = trimmed.match(/[^\d.,\s]/)) === null || _trimmed$match === void 0 ? void 0 : _trimmed$match[0]) || "";
|
|
3688
|
-
|
|
3689
|
-
// Remove everything except digits, comma, dot
|
|
3690
|
-
var numericPart = trimmed.replace(/[^\d.,]/g, "");
|
|
3691
|
-
|
|
3692
|
-
// Convert comma to dot if needed
|
|
3693
|
-
var normalized = numericPart.replace(",", ".");
|
|
3694
|
-
return {
|
|
3695
|
-
amount: Number(normalized),
|
|
3696
|
-
currency: currencySymbol
|
|
3697
|
-
};
|
|
3698
|
-
}
|
|
3699
3734
|
function CurrencyRangeInput(_ref) {
|
|
3700
3735
|
var prefix = _ref.prefix,
|
|
3701
3736
|
allowDecimals = _ref.allowDecimals,
|
|
3702
|
-
onChange = _ref.onChange,
|
|
3703
3737
|
intlConfig = _ref.intlConfig,
|
|
3704
3738
|
children = _ref.children,
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
min:
|
|
3709
|
-
max:
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3739
|
+
value = _ref.value,
|
|
3740
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
3741
|
+
defaultValue = _ref$defaultValue === void 0 ? {
|
|
3742
|
+
min: 0,
|
|
3743
|
+
max: 0
|
|
3744
|
+
} : _ref$defaultValue,
|
|
3745
|
+
onChange = _ref.onChange,
|
|
3746
|
+
_ref$debounce = _ref.debounce,
|
|
3747
|
+
debounce = _ref$debounce === void 0 ? 300 : _ref$debounce,
|
|
3748
|
+
externalError = _ref.error,
|
|
3749
|
+
externalHelperText = _ref.helperText;
|
|
3750
|
+
var isControlled = value !== undefined;
|
|
3751
|
+
var _useState = React.useState(defaultValue),
|
|
3752
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3753
|
+
internalValue = _useState2[0],
|
|
3754
|
+
setInternalValue = _useState2[1];
|
|
3755
|
+
var currentValue = isControlled ? value : internalValue;
|
|
3756
|
+
var setValue = React.useCallback(function (val) {
|
|
3757
|
+
if (!isControlled) {
|
|
3758
|
+
setInternalValue(val);
|
|
3724
3759
|
}
|
|
3725
|
-
}, [
|
|
3760
|
+
}, [isControlled]);
|
|
3761
|
+
|
|
3762
|
+
// Validation
|
|
3763
|
+
var isInvalid = React.useMemo(function () {
|
|
3764
|
+
if (!currentValue.min || !currentValue.max) return false;
|
|
3765
|
+
return currentValue.max <= currentValue.min;
|
|
3766
|
+
}, [currentValue]);
|
|
3767
|
+
|
|
3768
|
+
// Debounced onChange
|
|
3769
|
+
React.useEffect(function () {
|
|
3770
|
+
if (!onChange || isInvalid) return;
|
|
3771
|
+
var handler = setTimeout(function () {
|
|
3772
|
+
if (currentValue.min && currentValue.max) {
|
|
3773
|
+
onChange({
|
|
3774
|
+
min: currentValue.min,
|
|
3775
|
+
max: currentValue.max,
|
|
3776
|
+
currency: ''
|
|
3777
|
+
});
|
|
3778
|
+
}
|
|
3779
|
+
}, debounce);
|
|
3780
|
+
return function () {
|
|
3781
|
+
return clearTimeout(handler);
|
|
3782
|
+
};
|
|
3783
|
+
}, [isInvalid, onChange, debounce, currentValue]);
|
|
3784
|
+
var finalError = externalError !== null && externalError !== void 0 ? externalError : isInvalid;
|
|
3785
|
+
var finalHelperText = externalHelperText !== null && externalHelperText !== void 0 ? externalHelperText : isInvalid ? "Max must be greater than min" : undefined;
|
|
3726
3786
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
3727
3787
|
className: "with-label",
|
|
3728
3788
|
children: [children && /*#__PURE__*/jsxRuntime.jsx(InputBlockLabel, {
|
|
@@ -3731,12 +3791,11 @@ function CurrencyRangeInput(_ref) {
|
|
|
3731
3791
|
gap: 2,
|
|
3732
3792
|
children: [/*#__PURE__*/jsxRuntime.jsx(Grid, {
|
|
3733
3793
|
children: /*#__PURE__*/jsxRuntime.jsx(Input.Currency, {
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
});
|
|
3794
|
+
value: currentValue.min,
|
|
3795
|
+
onChange: function onChange(val) {
|
|
3796
|
+
return setValue(_objectSpread2(_objectSpread2({}, currentValue), {}, {
|
|
3797
|
+
min: Number(val)
|
|
3798
|
+
}));
|
|
3740
3799
|
},
|
|
3741
3800
|
intlConfig: intlConfig,
|
|
3742
3801
|
prefix: prefix,
|
|
@@ -3745,12 +3804,11 @@ function CurrencyRangeInput(_ref) {
|
|
|
3745
3804
|
})
|
|
3746
3805
|
}), /*#__PURE__*/jsxRuntime.jsx(Grid, {
|
|
3747
3806
|
children: /*#__PURE__*/jsxRuntime.jsx(Input.Currency, {
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
});
|
|
3807
|
+
value: currentValue.max,
|
|
3808
|
+
onChange: function onChange(val) {
|
|
3809
|
+
return setValue(_objectSpread2(_objectSpread2({}, currentValue), {}, {
|
|
3810
|
+
max: Number(val)
|
|
3811
|
+
}));
|
|
3754
3812
|
},
|
|
3755
3813
|
intlConfig: intlConfig,
|
|
3756
3814
|
prefix: prefix,
|
|
@@ -3758,19 +3816,20 @@ function CurrencyRangeInput(_ref) {
|
|
|
3758
3816
|
allowDecimals: allowDecimals
|
|
3759
3817
|
})
|
|
3760
3818
|
})]
|
|
3761
|
-
}),
|
|
3762
|
-
error:
|
|
3763
|
-
text:
|
|
3819
|
+
}), finalHelperText && /*#__PURE__*/jsxRuntime.jsx(InputError, {
|
|
3820
|
+
error: finalError,
|
|
3821
|
+
text: finalHelperText
|
|
3764
3822
|
})]
|
|
3765
3823
|
});
|
|
3766
3824
|
}
|
|
3825
|
+
var CurrencyRangeInput$1 = /*#__PURE__*/React.memo(CurrencyRangeInput);
|
|
3767
3826
|
|
|
3768
3827
|
/* "use client" */
|
|
3769
3828
|
Input.Textarea = Textarea;
|
|
3770
3829
|
Input.Password = InputPassword;
|
|
3771
3830
|
Input.Phone = PhoneInput$1;
|
|
3772
3831
|
Input.Currency = CurrencyInput;
|
|
3773
|
-
Input.CurrencyRange = CurrencyRangeInput;
|
|
3832
|
+
Input.CurrencyRange = CurrencyRangeInput$1;
|
|
3774
3833
|
|
|
3775
3834
|
exports.InputError = InputError;
|
|
3776
3835
|
exports.InputLabel = InputBlockLabel;
|
|
@@ -96,7 +96,7 @@ export type CurrencyInputProps = Overwrite<React.ComponentPropsWithRef<'input'>,
|
|
|
96
96
|
/**
|
|
97
97
|
* Handle change in value
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
onChange?: (value: string | undefined, name?: string, values?: CurrencyInputOnChangeValues) => void;
|
|
100
100
|
/**
|
|
101
101
|
* Placeholder if there is no value
|
|
102
102
|
*/
|
|
@@ -1,10 +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;
|
|
6
18
|
error?: boolean;
|
|
7
19
|
helperText?: string;
|
|
8
20
|
}>;
|
|
9
|
-
declare function CurrencyRangeInput({ prefix, allowDecimals,
|
|
10
|
-
|
|
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;
|
package/dist/table/index.js
CHANGED
|
@@ -3239,7 +3239,7 @@ var repositionCursor = function repositionCursor(_ref) {
|
|
|
3239
3239
|
};
|
|
3240
3240
|
};
|
|
3241
3241
|
|
|
3242
|
-
var _excluded$d = ["allowDecimals", "allowNegativeValue", "id", "name", "className", "customInput", "decimalsLimit", "defaultValue", "disabled", "maxLength", "value", "
|
|
3242
|
+
var _excluded$d = ["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"];
|
|
3243
3243
|
var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
3244
3244
|
var _ref$allowDecimals = _ref.allowDecimals,
|
|
3245
3245
|
allowDecimals = _ref$allowDecimals === void 0 ? true : _ref$allowDecimals,
|
|
@@ -3255,7 +3255,6 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3255
3255
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
3256
3256
|
userMaxLength = _ref.maxLength,
|
|
3257
3257
|
userValue = _ref.value,
|
|
3258
|
-
onValueChange = _ref.onValueChange,
|
|
3259
3258
|
fixedDecimalLength = _ref.fixedDecimalLength,
|
|
3260
3259
|
placeholder = _ref.placeholder,
|
|
3261
3260
|
decimalScale = _ref.decimalScale,
|
|
@@ -3368,11 +3367,15 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3368
3367
|
var stringValue = cleanValue(_objectSpread2({
|
|
3369
3368
|
value: modifiedValue
|
|
3370
3369
|
}, cleanValueOptions));
|
|
3370
|
+
|
|
3371
|
+
// console.log("Before clean:", modifiedValue);
|
|
3372
|
+
// console.log("After clean:", stringValue);
|
|
3373
|
+
|
|
3371
3374
|
if (userMaxLength && stringValue.replace(/-/g, '').length > userMaxLength) {
|
|
3372
3375
|
return;
|
|
3373
3376
|
}
|
|
3374
3377
|
if (stringValue === '' || stringValue === '-' || stringValue === decimalSeparator) {
|
|
3375
|
-
|
|
3378
|
+
onChange && onChange(undefined, name, {
|
|
3376
3379
|
"float": null,
|
|
3377
3380
|
formatted: '',
|
|
3378
3381
|
value: ''
|
|
@@ -3384,9 +3387,15 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3384
3387
|
}
|
|
3385
3388
|
var stringValueWithoutSeparator = decimalSeparator ? stringValue.replace(decimalSeparator, '.') : stringValue;
|
|
3386
3389
|
var numberValue = parseFloat(stringValueWithoutSeparator);
|
|
3390
|
+
|
|
3391
|
+
// console.log('Number Value', numberValue);
|
|
3392
|
+
|
|
3387
3393
|
var formattedValue = formatValue(_objectSpread2({
|
|
3388
3394
|
value: stringValue
|
|
3389
3395
|
}, formatValueOptions));
|
|
3396
|
+
|
|
3397
|
+
// console.log('Formatted Value', numberValue);
|
|
3398
|
+
|
|
3390
3399
|
if (cursorPosition != null) {
|
|
3391
3400
|
// Prevent cursor jumping
|
|
3392
3401
|
var newCursor = cursorPosition + (formattedValue.length - value.length);
|
|
@@ -3394,15 +3403,25 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3394
3403
|
setCursor(newCursor);
|
|
3395
3404
|
setChangeCount(changeCount + 1);
|
|
3396
3405
|
}
|
|
3406
|
+
|
|
3407
|
+
// console.log({
|
|
3408
|
+
// inputValue: value,
|
|
3409
|
+
// modifiedValue,
|
|
3410
|
+
// stateValue,
|
|
3411
|
+
// selectionStart,
|
|
3412
|
+
// lastKeyStroke
|
|
3413
|
+
// });
|
|
3414
|
+
|
|
3397
3415
|
setStateValue(formattedValue);
|
|
3398
|
-
if (
|
|
3416
|
+
if (onChange) {
|
|
3399
3417
|
var values = {
|
|
3400
3418
|
"float": numberValue,
|
|
3401
3419
|
formatted: formattedValue,
|
|
3402
3420
|
value: stringValue
|
|
3403
3421
|
};
|
|
3404
|
-
|
|
3422
|
+
onChange(stringValue, name, values);
|
|
3405
3423
|
}
|
|
3424
|
+
// onChange && onChange(stringValue);
|
|
3406
3425
|
};
|
|
3407
3426
|
|
|
3408
3427
|
/**
|
|
@@ -3413,7 +3432,6 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3413
3432
|
value = _event$target.value,
|
|
3414
3433
|
selectionStart = _event$target.selectionStart;
|
|
3415
3434
|
processChange(value, selectionStart);
|
|
3416
|
-
onChange && onChange(event);
|
|
3417
3435
|
};
|
|
3418
3436
|
|
|
3419
3437
|
/**
|
|
@@ -3445,8 +3463,8 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3445
3463
|
var formattedValue = formatValue(_objectSpread2(_objectSpread2({}, formatValueOptions), {}, {
|
|
3446
3464
|
value: newValue
|
|
3447
3465
|
}));
|
|
3448
|
-
if (
|
|
3449
|
-
|
|
3466
|
+
if (onChange && formatValueOnBlur) {
|
|
3467
|
+
onChange(newValue, name, {
|
|
3450
3468
|
"float": numberValue,
|
|
3451
3469
|
formatted: formattedValue,
|
|
3452
3470
|
value: newValue
|
|
@@ -3483,6 +3501,34 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3483
3501
|
onKeyDown && onKeyDown(event);
|
|
3484
3502
|
};
|
|
3485
3503
|
|
|
3504
|
+
// const handleOnKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
3505
|
+
// lastKeyStrokeRef.current = event.key;
|
|
3506
|
+
|
|
3507
|
+
// // Handle arrow up/down with step
|
|
3508
|
+
// if (step && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
|
|
3509
|
+
// event.preventDefault();
|
|
3510
|
+
|
|
3511
|
+
// const currentValue =
|
|
3512
|
+
// parseFloat(
|
|
3513
|
+
// userValue != null
|
|
3514
|
+
// ? String(userValue).replace(decimalSeparator, '.')
|
|
3515
|
+
// : cleanValue({ value: stateValue, ...cleanValueOptions })
|
|
3516
|
+
// ) || 0;
|
|
3517
|
+
|
|
3518
|
+
// const newValue = event.key === 'ArrowUp' ? currentValue + step : currentValue - step;
|
|
3519
|
+
|
|
3520
|
+
// if ((min !== undefined && newValue < Number(min)) || (max !== undefined && newValue > Number(max))) return;
|
|
3521
|
+
|
|
3522
|
+
// const fixedLength = String(step).includes('.') ? String(step).split('.')[1].length : undefined;
|
|
3523
|
+
|
|
3524
|
+
// processChange(
|
|
3525
|
+
// (fixedLength ? newValue.toFixed(fixedLength) : newValue).replace('.', decimalSeparator)
|
|
3526
|
+
// );
|
|
3527
|
+
// }
|
|
3528
|
+
|
|
3529
|
+
// onKeyDown && onKeyDown(event);
|
|
3530
|
+
// };
|
|
3531
|
+
|
|
3486
3532
|
/**
|
|
3487
3533
|
* Handle key up event
|
|
3488
3534
|
*
|
|
@@ -3524,13 +3570,19 @@ var InputCurrency = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
3524
3570
|
* If user has only entered "-" or decimal separator,
|
|
3525
3571
|
* keep the char to allow them to enter next value
|
|
3526
3572
|
*/
|
|
3573
|
+
// const getRenderValue = () => {
|
|
3574
|
+
// if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
3575
|
+
// // console.log('User Value', userValue);
|
|
3576
|
+
// return formatValue({
|
|
3577
|
+
// ...formatValueOptions,
|
|
3578
|
+
// decimalScale: dirty ? undefined : decimalScale,
|
|
3579
|
+
// value: String(userValue)
|
|
3580
|
+
// });
|
|
3581
|
+
// }
|
|
3582
|
+
|
|
3583
|
+
// return stateValue;
|
|
3584
|
+
// };
|
|
3527
3585
|
var getRenderValue = function getRenderValue() {
|
|
3528
|
-
if (userValue != null && stateValue !== '-' && (!decimalSeparator || stateValue !== decimalSeparator)) {
|
|
3529
|
-
return formatValue(_objectSpread2(_objectSpread2({}, formatValueOptions), {}, {
|
|
3530
|
-
decimalScale: dirty ? undefined : decimalScale,
|
|
3531
|
-
value: String(userValue)
|
|
3532
|
-
}));
|
|
3533
|
-
}
|
|
3534
3586
|
return stateValue;
|
|
3535
3587
|
};
|
|
3536
3588
|
var inputProps = _objectSpread2({
|
|
@@ -3729,50 +3781,58 @@ var GridContainer = withScale(GridContainerComponent);
|
|
|
3729
3781
|
|
|
3730
3782
|
Grid.Container = GridContainer;
|
|
3731
3783
|
|
|
3732
|
-
function parseCurrency(value) {
|
|
3733
|
-
var _trimmed$match;
|
|
3734
|
-
var trimmed = value.trim();
|
|
3735
|
-
|
|
3736
|
-
// Extract currency symbol
|
|
3737
|
-
var currencySymbol = ((_trimmed$match = trimmed.match(/[^\d.,\s]/)) === null || _trimmed$match === void 0 ? void 0 : _trimmed$match[0]) || "";
|
|
3738
|
-
|
|
3739
|
-
// Remove everything except digits, comma, dot
|
|
3740
|
-
var numericPart = trimmed.replace(/[^\d.,]/g, "");
|
|
3741
|
-
|
|
3742
|
-
// Convert comma to dot if needed
|
|
3743
|
-
var normalized = numericPart.replace(",", ".");
|
|
3744
|
-
return {
|
|
3745
|
-
amount: Number(normalized),
|
|
3746
|
-
currency: currencySymbol
|
|
3747
|
-
};
|
|
3748
|
-
}
|
|
3749
3784
|
function CurrencyRangeInput(_ref) {
|
|
3750
3785
|
var prefix = _ref.prefix,
|
|
3751
3786
|
allowDecimals = _ref.allowDecimals,
|
|
3752
|
-
onChange = _ref.onChange,
|
|
3753
3787
|
intlConfig = _ref.intlConfig,
|
|
3754
3788
|
children = _ref.children,
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
min:
|
|
3759
|
-
max:
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3789
|
+
value = _ref.value,
|
|
3790
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
3791
|
+
defaultValue = _ref$defaultValue === void 0 ? {
|
|
3792
|
+
min: 0,
|
|
3793
|
+
max: 0
|
|
3794
|
+
} : _ref$defaultValue,
|
|
3795
|
+
onChange = _ref.onChange,
|
|
3796
|
+
_ref$debounce = _ref.debounce,
|
|
3797
|
+
debounce = _ref$debounce === void 0 ? 300 : _ref$debounce,
|
|
3798
|
+
externalError = _ref.error,
|
|
3799
|
+
externalHelperText = _ref.helperText;
|
|
3800
|
+
var isControlled = value !== undefined;
|
|
3801
|
+
var _useState = React.useState(defaultValue),
|
|
3802
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3803
|
+
internalValue = _useState2[0],
|
|
3804
|
+
setInternalValue = _useState2[1];
|
|
3805
|
+
var currentValue = isControlled ? value : internalValue;
|
|
3806
|
+
var setValue = React.useCallback(function (val) {
|
|
3807
|
+
if (!isControlled) {
|
|
3808
|
+
setInternalValue(val);
|
|
3774
3809
|
}
|
|
3775
|
-
}, [
|
|
3810
|
+
}, [isControlled]);
|
|
3811
|
+
|
|
3812
|
+
// Validation
|
|
3813
|
+
var isInvalid = React.useMemo(function () {
|
|
3814
|
+
if (!currentValue.min || !currentValue.max) return false;
|
|
3815
|
+
return currentValue.max <= currentValue.min;
|
|
3816
|
+
}, [currentValue]);
|
|
3817
|
+
|
|
3818
|
+
// Debounced onChange
|
|
3819
|
+
React.useEffect(function () {
|
|
3820
|
+
if (!onChange || isInvalid) return;
|
|
3821
|
+
var handler = setTimeout(function () {
|
|
3822
|
+
if (currentValue.min && currentValue.max) {
|
|
3823
|
+
onChange({
|
|
3824
|
+
min: currentValue.min,
|
|
3825
|
+
max: currentValue.max,
|
|
3826
|
+
currency: ''
|
|
3827
|
+
});
|
|
3828
|
+
}
|
|
3829
|
+
}, debounce);
|
|
3830
|
+
return function () {
|
|
3831
|
+
return clearTimeout(handler);
|
|
3832
|
+
};
|
|
3833
|
+
}, [isInvalid, onChange, debounce, currentValue]);
|
|
3834
|
+
var finalError = externalError !== null && externalError !== void 0 ? externalError : isInvalid;
|
|
3835
|
+
var finalHelperText = externalHelperText !== null && externalHelperText !== void 0 ? externalHelperText : isInvalid ? "Max must be greater than min" : undefined;
|
|
3776
3836
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
3777
3837
|
className: "with-label",
|
|
3778
3838
|
children: [children && /*#__PURE__*/jsxRuntime.jsx(InputBlockLabel, {
|
|
@@ -3781,12 +3841,11 @@ function CurrencyRangeInput(_ref) {
|
|
|
3781
3841
|
gap: 2,
|
|
3782
3842
|
children: [/*#__PURE__*/jsxRuntime.jsx(Grid, {
|
|
3783
3843
|
children: /*#__PURE__*/jsxRuntime.jsx(Input.Currency, {
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
});
|
|
3844
|
+
value: currentValue.min,
|
|
3845
|
+
onChange: function onChange(val) {
|
|
3846
|
+
return setValue(_objectSpread2(_objectSpread2({}, currentValue), {}, {
|
|
3847
|
+
min: Number(val)
|
|
3848
|
+
}));
|
|
3790
3849
|
},
|
|
3791
3850
|
intlConfig: intlConfig,
|
|
3792
3851
|
prefix: prefix,
|
|
@@ -3795,12 +3854,11 @@ function CurrencyRangeInput(_ref) {
|
|
|
3795
3854
|
})
|
|
3796
3855
|
}), /*#__PURE__*/jsxRuntime.jsx(Grid, {
|
|
3797
3856
|
children: /*#__PURE__*/jsxRuntime.jsx(Input.Currency, {
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
});
|
|
3857
|
+
value: currentValue.max,
|
|
3858
|
+
onChange: function onChange(val) {
|
|
3859
|
+
return setValue(_objectSpread2(_objectSpread2({}, currentValue), {}, {
|
|
3860
|
+
max: Number(val)
|
|
3861
|
+
}));
|
|
3804
3862
|
},
|
|
3805
3863
|
intlConfig: intlConfig,
|
|
3806
3864
|
prefix: prefix,
|
|
@@ -3808,19 +3866,20 @@ function CurrencyRangeInput(_ref) {
|
|
|
3808
3866
|
allowDecimals: allowDecimals
|
|
3809
3867
|
})
|
|
3810
3868
|
})]
|
|
3811
|
-
}),
|
|
3812
|
-
error:
|
|
3813
|
-
text:
|
|
3869
|
+
}), finalHelperText && /*#__PURE__*/jsxRuntime.jsx(InputError, {
|
|
3870
|
+
error: finalError,
|
|
3871
|
+
text: finalHelperText
|
|
3814
3872
|
})]
|
|
3815
3873
|
});
|
|
3816
3874
|
}
|
|
3875
|
+
var CurrencyRangeInput$1 = /*#__PURE__*/React.memo(CurrencyRangeInput);
|
|
3817
3876
|
|
|
3818
3877
|
/* "use client" */
|
|
3819
3878
|
Input.Textarea = Textarea;
|
|
3820
3879
|
Input.Password = InputPassword;
|
|
3821
3880
|
Input.Phone = PhoneInput$1;
|
|
3822
3881
|
Input.Currency = CurrencyInput;
|
|
3823
|
-
Input.CurrencyRange = CurrencyRangeInput;
|
|
3882
|
+
Input.CurrencyRange = CurrencyRangeInput$1;
|
|
3824
3883
|
|
|
3825
3884
|
var lodash$1 = {exports: {}};
|
|
3826
3885
|
|