diginet-core-ui 1.3.78 → 1.3.79
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/components/accordion/details.js +2 -6
- package/components/accordion/group.js +2 -9
- package/components/accordion/index.js +2 -15
- package/components/accordion/summary.js +4 -27
- package/components/alert/index.js +98 -137
- package/components/alert/notify.js +97 -166
- package/components/avatar/index.js +4 -63
- package/components/badge/index.js +7 -34
- package/components/button/icon.js +120 -186
- package/components/button/index.js +136 -205
- package/components/button/more.js +0 -12
- package/components/button/ripple-effect.js +46 -44
- package/components/card/body.js +2 -7
- package/components/card/extra.js +2 -7
- package/components/card/footer.js +2 -7
- package/components/card/header.js +2 -7
- package/components/card/index.js +2 -22
- package/components/chart/Pie/Circle.js +0 -1
- package/components/chart/Pie/Sector.js +0 -17
- package/components/chart/Pie/Sectors.js +0 -10
- package/components/chart/Pie/index.js +4 -36
- package/components/chart/Pie-v2/Circle.js +0 -1
- package/components/chart/Pie-v2/Sector.js +0 -13
- package/components/chart/Pie-v2/Sectors.js +0 -20
- package/components/chart/Pie-v2/index.js +11 -38
- package/components/chart/bar/Axis.js +0 -12
- package/components/chart/bar/Bar.js +13 -35
- package/components/chart/bar/Grid.js +0 -18
- package/components/chart/bar/Labels.js +0 -18
- package/components/chart/bar/Points.js +0 -17
- package/components/chart/bar/index.js +6 -26
- package/components/chart/bar-v2/Axis.js +0 -12
- package/components/chart/bar-v2/Bar.js +15 -36
- package/components/chart/bar-v2/Grid.js +0 -18
- package/components/chart/bar-v2/Labels.js +0 -18
- package/components/chart/bar-v2/Points.js +0 -17
- package/components/chart/bar-v2/index.js +6 -26
- package/components/chart/line/Axis.js +4 -16
- package/components/chart/line/Grid.js +2 -19
- package/components/chart/line/Labels.js +0 -18
- package/components/chart/line/Path.js +23 -33
- package/components/chart/line/Point.js +6 -40
- package/components/chart/line/Title.js +0 -3
- package/components/chart/line/index.js +12 -35
- package/components/chart/line-v2/Axis.js +0 -13
- package/components/chart/line-v2/Grid.js +0 -18
- package/components/chart/line-v2/Labels.js +0 -18
- package/components/chart/line-v2/Path.js +23 -33
- package/components/chart/line-v2/Point.js +6 -35
- package/components/chart/line-v2/Title.js +0 -3
- package/components/chart/line-v2/index.js +12 -30
- package/components/check-text/index.js +0 -8
- package/components/check-text/interview-confirmation.js +0 -7
- package/components/check-text/interview-status.js +0 -7
- package/components/chip/attach.js +4 -17
- package/components/chip/index.js +6 -33
- package/components/collapse/index.js +0 -13
- package/components/divider/index.js +0 -8
- package/components/form-control/attachment/index.js +24 -202
- package/components/form-control/calendar/function.js +40 -94
- package/components/form-control/calendar/index.js +5 -30
- package/components/form-control/calendar/range.js +11 -28
- package/components/form-control/checkbox/index.js +4 -37
- package/components/form-control/control/index.js +3 -13
- package/components/form-control/date-picker/index-old.js +18 -0
- package/components/form-control/date-picker/index.js +23 -99
- package/components/form-control/date-range-picker/index.js +86 -221
- package/components/form-control/dropdown/index.js +72 -289
- package/components/form-control/dropdown-box/index.js +6 -35
- package/components/form-control/form/index.js +0 -2
- package/components/form-control/form-group/index.js +1 -6
- package/components/form-control/helper-text/index.js +2 -9
- package/components/form-control/input-base/index.js +218 -399
- package/components/form-control/label/index.js +2 -12
- package/components/form-control/money-input/index.js +43 -132
- package/components/form-control/number-input/index.js +15 -113
- package/components/form-control/number-input/index2.js +78 -119
- package/components/form-control/phone-input/index.js +16 -78
- package/components/form-control/radio/index.js +4 -23
- package/components/form-control/text-input/index.js +33 -256
- package/components/form-control/time-picker/index.js +14 -71
- package/components/form-control/time-picker/swiper.js +21 -73
- package/components/form-control/toggle/index.js +4 -19
- package/components/form-view/helper-text.js +2 -2
- package/components/form-view/index.js +0 -14
- package/components/form-view/input.js +2 -13
- package/components/form-view/label.js +0 -2
- package/components/grid/Col.js +2 -15
- package/components/grid/Container.js +2 -21
- package/components/grid/Row.js +2 -21
- package/components/grid/index.js +2 -43
- package/components/image/index.js +2 -22
- package/components/index.js +62 -31
- package/components/list/list-item-action.js +0 -9
- package/components/list/list-item-icon.js +0 -9
- package/components/list/list-item-text.js +0 -5
- package/components/list/list-item.js +0 -11
- package/components/list/list.js +0 -13
- package/components/list/sub-header.js +0 -4
- package/components/modal/body.js +2 -6
- package/components/modal/footer.js +2 -11
- package/components/modal/header.js +2 -12
- package/components/modal/index.js +2 -10
- package/components/modal/modal.js +11 -52
- package/components/others/extra/index.js +3 -10
- package/components/others/import/index.js +0 -7
- package/components/others/option-wrapper/index.js +4 -7
- package/components/others/scrollbar/index.js +0 -3
- package/components/paging/page-info.js +39 -101
- package/components/paging/page-selector.js +7 -35
- package/components/paging/page-selector2.js +35 -74
- package/components/paper/index.js +0 -11
- package/components/popover/body.js +2 -6
- package/components/popover/footer.js +2 -11
- package/components/popover/header.js +2 -7
- package/components/popover/index.js +39 -123
- package/components/popup/danger_popup.js +0 -19
- package/components/popup/index.js +2 -48
- package/components/popup/proposals_popup.js +10 -49
- package/components/popup/v2/index.js +0 -31
- package/components/progress/circular.js +19 -81
- package/components/progress/linear.js +4 -20
- package/components/rating/index.js +0 -24
- package/components/slider/slider-container.js +3 -40
- package/components/slider/slider-item.js +10 -25
- package/components/status/index.js +2 -16
- package/components/tab/tab-container.js +2 -16
- package/components/tab/tab-header.js +4 -24
- package/components/tab/tab-panel.js +4 -16
- package/components/tab/tab.js +4 -28
- package/components/tooltip/index.js +12 -97
- package/components/tooltip/portal.js +0 -2
- package/components/transfer/index.js +22 -67
- package/components/tree-view/index.js +62 -202
- package/components/typography/index.js +3 -31
- package/global/index.js +0 -8
- package/icons/basic.js +0 -48
- package/icons/effect.js +17 -29
- package/icons/general/clock/clock.js +0 -2
- package/icons/general/color-handler/background.js +0 -2
- package/icons/general/color-handler/text.js +0 -2
- package/icons/general/emoji/emoji.js +0 -2
- package/icons/general/font-properties/bold.js +0 -2
- package/icons/general/font-properties/font-family.js +0 -2
- package/icons/general/font-properties/font-size.js +0 -2
- package/icons/general/font-properties/italic.js +0 -2
- package/icons/general/font-properties/underline.js +0 -2
- package/icons/general/hyperlink/hyperlink.js +0 -2
- package/icons/general/indent/decrease.js +0 -2
- package/icons/general/indent/increase.js +0 -2
- package/icons/general/list/bullets.js +0 -2
- package/icons/general/list/numbering.js +0 -2
- package/icons/general/picture/picture.js +0 -2
- package/icons/general/steps/redo.js +0 -2
- package/icons/general/steps/undo.js +0 -2
- package/icons/general/text-align/center.js +0 -2
- package/icons/general/text-align/justify.js +0 -2
- package/icons/general/text-align/left.js +0 -2
- package/icons/general/text-align/right.js +0 -2
- package/icons/menu/dhr.js +2 -1
- package/icons/menu/index.js +2 -2
- package/icons/menu/v2/index.js +0 -10
- package/package.json +1 -1
- package/readme.md +11 -1
- package/styles/animation.js +15 -58
- package/styles/color-helper.js +24 -54
- package/styles/colors.js +17 -9
- package/styles/general.js +6 -2
- package/styles/typography.js +4 -4
- package/styles/utils.js +2 -2
- package/theme/createBreakpoints.js +7 -18
- package/theme/make-styles.js +2 -5
- package/theme/set-theme.js +3 -6
- package/theme/settings.js +3 -2
- package/theme/theme-provider.js +0 -1
- package/utils/array/array.js +14 -23
- package/utils/classNames.js +0 -5
- package/utils/console.js +0 -6
- package/utils/date.js +13 -82
- package/utils/error/error.js +1 -9
- package/utils/error/errors.js +1 -48
- package/utils/getFileType.js +0 -9
- package/utils/handleBreakpoints.js +0 -5
- package/utils/intersectionObserver.js +0 -5
- package/utils/iterator.js +0 -9
- package/utils/map-parent.js +3 -10
- package/utils/object/extend.js +0 -10
- package/utils/object/object.js +12 -11
- package/utils/parseHTML.js +0 -1
- package/utils/promisify.js +0 -5
- package/utils/randomString.js +0 -7
- package/utils/remove-unicode.js +0 -1
- package/utils/render-portal.js +1 -9
- package/utils/renderHTML.js +4 -6
- package/utils/renderIcon.js +4 -14
- package/utils/sb-template.js +6 -5
- package/utils/string/capitalize.js +0 -1
- package/utils/string/capitalizeSentenceCase.js +0 -2
- package/utils/string/string.js +0 -13
- package/utils/type.js +0 -21
- package/utils/updatePosition.js +4 -5
- package/utils/useDelayUnmount.js +0 -4
- package/utils/useElementSize.js +9 -3
- package/utils/useEventListener.js +12 -6
- package/utils/useInput.js +0 -6
- package/utils/useMediaQuery.js +8 -10
- package/utils/useOnClickOutside.js +0 -2
- package/utils/usePortal.js +3 -10
- package/utils/validate.js +6 -20
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { useState, useRef, forwardRef, useMemo, useCallback, useEffect, useImperativeHandle } from 'react';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
@@ -14,10 +13,10 @@ const {
|
|
|
14
13
|
} = theme;
|
|
15
14
|
const regexValidNumber = /[^0-9.,-]/g;
|
|
16
15
|
const regexNumber = /[^0-9]/g;
|
|
17
|
-
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
16
|
+
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
18
17
|
|
|
18
|
+
// Clamp number between two values with the following line:
|
|
19
19
|
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
20
|
-
|
|
21
20
|
const NumberInput = /*#__PURE__*/forwardRef(({
|
|
22
21
|
autoFocus,
|
|
23
22
|
autoWidth,
|
|
@@ -61,10 +60,10 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
61
60
|
const pos = useRef(null);
|
|
62
61
|
const ref = useRef(null);
|
|
63
62
|
const globalRef = useRef({});
|
|
64
|
-
const [value, setValue] = useState(defaultValue);
|
|
63
|
+
const [value, setValue] = useState(defaultValue);
|
|
65
64
|
|
|
65
|
+
// nếu không cho nhập số âm mà max là âm thì remove giá trị max
|
|
66
66
|
if (max < 0 && disabledNegative) max = null;
|
|
67
|
-
|
|
68
67
|
if (thousandSymbol) {
|
|
69
68
|
thousandSymbol = useMemo(() => {
|
|
70
69
|
return typeof thousandSymbol === 'string' ? thousandSymbol : decimalSymbol === ',' ? '.' : ',';
|
|
@@ -75,21 +74,19 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
75
74
|
} else {
|
|
76
75
|
thousandSymbol = '';
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
const validateResult = validates && onValidate(value, validates, true);
|
|
80
78
|
if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
|
|
81
|
-
/**
|
|
82
|
-
* Convert number to format money
|
|
83
|
-
* @param vl {number} - value
|
|
84
|
-
* @type {function}
|
|
85
|
-
* @return {string}
|
|
86
|
-
* @example 1200300.123 => 1,200,300.123
|
|
87
|
-
* @example 1200300,123 => 1.200.300,123
|
|
88
|
-
*/
|
|
89
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Convert number to format money
|
|
82
|
+
* @param vl {number} - value
|
|
83
|
+
* @type {function}
|
|
84
|
+
* @return {string}
|
|
85
|
+
* @example 1200300.123 => 1,200,300.123
|
|
86
|
+
* @example 1200300,123 => 1.200.300,123
|
|
87
|
+
*/
|
|
90
88
|
const parseNumberToMoney = useCallback((vl, isNumber) => {
|
|
91
89
|
var _number, _number2, _number$, _number3;
|
|
92
|
-
|
|
93
90
|
const {
|
|
94
91
|
current: {
|
|
95
92
|
selectionStart
|
|
@@ -97,49 +94,44 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
97
94
|
} = inputRef;
|
|
98
95
|
let number = convertMoneyToNumber(vl, isNumber);
|
|
99
96
|
if (disabledNegative && Number(number || 0) < 0) number = clamp(number, min, max);
|
|
100
|
-
if (typeof max !== 'undefined' && Number(number) > max) number = Math.min(number, max);
|
|
97
|
+
if (typeof max !== 'undefined' && Number(number) > max) number = Math.min(number, max);
|
|
101
98
|
|
|
99
|
+
// number = Currency.format(number);
|
|
102
100
|
if (!number) return number;
|
|
103
101
|
number = (_number = number) === null || _number === void 0 ? void 0 : _number.toString().split('.');
|
|
104
|
-
|
|
105
102
|
if (number.length === 2 && !number[0]) {
|
|
106
103
|
number[0] = '0';
|
|
107
104
|
pos.current = 2;
|
|
108
105
|
}
|
|
109
|
-
|
|
110
106
|
number[0] = (_number2 = number) === null || _number2 === void 0 ? void 0 : _number2[0].replace(regexThousandNumber, '$1' + thousandSymbol); // add a thousand symbol to number
|
|
111
107
|
|
|
112
108
|
if (!decimalDigit) number.length = 1;else if (number[1]) number[1] = (_number$ = number[1]) === null || _number$ === void 0 ? void 0 : _number$.slice(0, decimalDigit || 0);
|
|
113
|
-
number = number.join(decimalSymbol);
|
|
114
|
-
|
|
109
|
+
number = number.join(decimalSymbol);
|
|
110
|
+
// keep focus position
|
|
115
111
|
if (((_number3 = number) === null || _number3 === void 0 ? void 0 : _number3.indexOf(thousandSymbol)) > -1 && selectionStart !== number.length + 1) {
|
|
116
112
|
pos.current = selectionStart + (number.toString().length - 1 === vl.toString().length ? 1 : 0);
|
|
117
113
|
}
|
|
118
|
-
|
|
119
114
|
return number;
|
|
120
115
|
}, [decimalSymbol, max, value]);
|
|
121
|
-
/**
|
|
122
|
-
* Convert money to format number
|
|
123
|
-
* @param vl {string} - value
|
|
124
|
-
* @type {function}
|
|
125
|
-
* @return {number}
|
|
126
|
-
* @example 1,200,300.123 => 1200300.123
|
|
127
|
-
* @example 1.200.300,123 => 1200300.123
|
|
128
|
-
*/
|
|
129
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Convert money to format number
|
|
119
|
+
* @param vl {string} - value
|
|
120
|
+
* @type {function}
|
|
121
|
+
* @return {number}
|
|
122
|
+
* @example 1,200,300.123 => 1200300.123
|
|
123
|
+
* @example 1.200.300,123 => 1200300.123
|
|
124
|
+
*/
|
|
130
125
|
const convertMoneyToNumber = useCallback((vl, isNumber) => {
|
|
131
126
|
var _number4, _number4$toString, _number4$toString$rep, _number4$toString$rep2, _number4$toString$rep3;
|
|
132
|
-
|
|
133
127
|
let number = vl === null || vl === void 0 ? void 0 : vl.toString().replace(regexValidNumber, ''); // allow number and , || . || -
|
|
134
|
-
// remove <thousandSymbol> and replace . to <decimalSymbol>
|
|
135
128
|
|
|
129
|
+
// remove <thousandSymbol> and replace . to <decimalSymbol>
|
|
136
130
|
if (!isNumber) number = (_number4 = number) === null || _number4 === void 0 ? void 0 : (_number4$toString = _number4.toString()) === null || _number4$toString === void 0 ? void 0 : (_number4$toString$rep = _number4$toString.replaceAll) === null || _number4$toString$rep === void 0 ? void 0 : (_number4$toString$rep2 = (_number4$toString$rep3 = _number4$toString$rep.call(_number4$toString, thousandSymbol, '')).replaceAll) === null || _number4$toString$rep2 === void 0 ? void 0 : _number4$toString$rep2.call(_number4$toString$rep3, decimalSymbol, '.');
|
|
137
131
|
return number;
|
|
138
132
|
}, [decimalSymbol]);
|
|
139
|
-
|
|
140
133
|
const _onInput = e => {
|
|
141
134
|
var _e$target$value;
|
|
142
|
-
|
|
143
135
|
let valueT = (_e$target$value = e.target.value) !== null && _e$target$value !== void 0 ? _e$target$value : e.value;
|
|
144
136
|
if (disabledNegative && Number(valueT || 0) < 0) return;
|
|
145
137
|
valueT = parseNumberToMoney(valueT);
|
|
@@ -150,32 +142,25 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
150
142
|
onInput === null || onInput === void 0 ? void 0 : onInput(e);
|
|
151
143
|
setValue(valueT);
|
|
152
144
|
};
|
|
153
|
-
|
|
154
145
|
const _onBlur = e => {
|
|
155
146
|
var _e$value;
|
|
156
|
-
|
|
157
147
|
let value = (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : e.target.value;
|
|
158
148
|
if (fixedDecimalDigit) value = Number(value).toFixed(decimalDigit);
|
|
159
|
-
|
|
160
149
|
if ((value || value === '' && typeof min !== 'undefined') && (typeof min !== 'undefined' || typeof max !== 'undefined')) {
|
|
161
150
|
value = convertMoneyToNumber(value);
|
|
162
|
-
|
|
163
151
|
if (Number(value) < min || Number(value) > max) {
|
|
164
152
|
const target = e.target;
|
|
165
153
|
target.value = clamp(value, min, max);
|
|
166
|
-
|
|
167
|
-
|
|
154
|
+
_onInput({
|
|
155
|
+
...e,
|
|
168
156
|
target
|
|
169
157
|
});
|
|
170
158
|
}
|
|
171
159
|
}
|
|
172
|
-
|
|
173
160
|
onBlur && onBlur(e);
|
|
174
161
|
};
|
|
175
|
-
|
|
176
162
|
const _onKeyDown = e => {
|
|
177
163
|
var _value$split, _value$split$;
|
|
178
|
-
|
|
179
164
|
const {
|
|
180
165
|
key,
|
|
181
166
|
keyCode,
|
|
@@ -187,64 +172,73 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
187
172
|
selectionStart,
|
|
188
173
|
selectionEnd
|
|
189
174
|
}
|
|
190
|
-
} = e;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
175
|
+
} = e;
|
|
176
|
+
|
|
177
|
+
// 0-9 only
|
|
178
|
+
const isNumber = keyCode >= 48 && keyCode <= 57 && shiftKey === false || keyCode >= 96 && keyCode <= 105 || keyCode === 231 && key >= '0' && key <= '9';
|
|
179
|
+
|
|
180
|
+
// character input type="number"
|
|
181
|
+
let allowKeyTypeNumber = isNumber || keyCode === 8 ||
|
|
182
|
+
// key backspace
|
|
183
|
+
keyCode > 34 && keyCode < 40 || key === thousandSymbol || key === decimalSymbol || (ctrlKey || metaKey) && (keyCode === 65 || keyCode === 67 || keyCode === 86) ||
|
|
184
|
+
// ctrl + A, ctrl + C, ctrl + V
|
|
185
|
+
keyCode === 46 ||
|
|
186
|
+
// key delete
|
|
187
|
+
keyCode === 189 || keyCode === 109 ||
|
|
188
|
+
// -
|
|
198
189
|
keyCode === 9; // tab
|
|
190
|
+
|
|
199
191
|
// The key is delete (|| remove) and focus after the thousand digit
|
|
192
|
+
const removeDot = keyCode === 8 && selectionEnd - selectionStart <= 1 && value.charAt(selectionEnd - 1) === thousandSymbol;
|
|
200
193
|
|
|
201
|
-
|
|
194
|
+
// Decimal
|
|
202
195
|
// Do not allow the character decimal if decimalDigit is undefined
|
|
203
|
-
|
|
204
196
|
const isDecimalSymbol = decimalSymbol === key;
|
|
205
|
-
const disabledDecimalSymbol = isDecimalSymbol && !decimalDigit;
|
|
197
|
+
const disabledDecimalSymbol = isDecimalSymbol && !decimalDigit;
|
|
206
198
|
|
|
207
|
-
|
|
199
|
+
// Accepts only one decimal separator
|
|
200
|
+
const decimalExists = value.includes(decimalSymbol) && isDecimalSymbol;
|
|
208
201
|
|
|
209
|
-
|
|
202
|
+
// Disabled typing input when decimal digit to limit and focus is last
|
|
203
|
+
const disabledTypingDecimal = ((_value$split = value.split(decimalSymbol)) === null || _value$split === void 0 ? void 0 : (_value$split$ = _value$split[1]) === null || _value$split$ === void 0 ? void 0 : _value$split$.length) >= decimalDigit &&
|
|
204
|
+
// total number after decimal symbol > {decimalDigit}
|
|
210
205
|
selectionStart === value.length; // the focus is at the end of the string
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
const target = e.target;
|
|
207
|
+
// key arrow up
|
|
214
208
|
if (keyCode === 38) {
|
|
215
209
|
target.value = Number(convertMoneyToNumber(value) || 0) + step;
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
_onInput({
|
|
211
|
+
...e,
|
|
218
212
|
target
|
|
219
213
|
});
|
|
220
|
-
|
|
221
214
|
e.preventDefault();
|
|
222
|
-
}
|
|
215
|
+
}
|
|
216
|
+
// key arrow down
|
|
223
217
|
else if (keyCode === 40) {
|
|
224
218
|
target.value = Number(convertMoneyToNumber(value) || 0) - step;
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
_onInput({
|
|
220
|
+
...e,
|
|
227
221
|
target
|
|
228
222
|
});
|
|
229
|
-
|
|
230
223
|
e.preventDefault();
|
|
231
|
-
}
|
|
232
|
-
|
|
224
|
+
}
|
|
233
225
|
|
|
234
|
-
|
|
226
|
+
// disabled negative
|
|
227
|
+
const disabled180 = (keyCode === 189 || keyCode === 109) && (disabledNegative || value.includes('-'));
|
|
235
228
|
|
|
236
|
-
|
|
229
|
+
// disabled max digit
|
|
230
|
+
const isMaxDigit = maxDigit && (value === null || value === void 0 ? void 0 : value.replace(regexNumber, '').length) === maxDigit && (isNumber || key === thousandSymbol || key === decimalSymbol) && selectionStart === selectionEnd;
|
|
237
231
|
|
|
232
|
+
// Block event if include conditions
|
|
238
233
|
if (decimalExists || removeDot || isNumber && disabledTypingDecimal || disabledDecimalSymbol || !allowKeyTypeNumber || disabled180 || isMaxDigit) {
|
|
239
234
|
e.preventDefault();
|
|
240
235
|
}
|
|
241
|
-
|
|
242
236
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
243
237
|
};
|
|
244
|
-
|
|
245
238
|
useEffect(() => {
|
|
246
|
-
inputRef.current.value = value !== null && value !== void 0 ? value : null;
|
|
239
|
+
inputRef.current.value = value !== null && value !== void 0 ? value : null;
|
|
247
240
|
|
|
241
|
+
// keep focus position
|
|
248
242
|
if (pos.current) {
|
|
249
243
|
inputRef.current.setSelectionRange(pos.current, pos.current);
|
|
250
244
|
pos.current = null;
|
|
@@ -252,7 +246,6 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
252
246
|
}, [value]);
|
|
253
247
|
useEffect(() => {
|
|
254
248
|
var _valueProps;
|
|
255
|
-
|
|
256
249
|
if (typeof valueProps !== 'undefined') if (disabledNegative && Number(valueProps || 0) < 0) {
|
|
257
250
|
// nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
|
|
258
251
|
valueProps = clamp(0, min, max);
|
|
@@ -263,9 +256,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
263
256
|
const currentRef = ref.current || {};
|
|
264
257
|
currentRef.element = ref.current;
|
|
265
258
|
const _instance = {}; // methods
|
|
266
|
-
|
|
267
259
|
_instance.__proto__ = {}; // hidden methods
|
|
268
|
-
|
|
269
260
|
currentRef.instance = _instance;
|
|
270
261
|
return currentRef;
|
|
271
262
|
});
|
|
@@ -273,7 +264,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
273
264
|
ref: ref,
|
|
274
265
|
css: NumberInputRoot,
|
|
275
266
|
className: classNames('DGN-UI-NumberInput', className)
|
|
276
|
-
}, !!label && jsx(Label, {
|
|
267
|
+
}, !!label && jsx(Label, {
|
|
268
|
+
...labelProps,
|
|
277
269
|
required: required,
|
|
278
270
|
disabled: disabled
|
|
279
271
|
}, label), jsx(InputBase, {
|
|
@@ -301,15 +293,18 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
301
293
|
const target = e.target;
|
|
302
294
|
target.value = globalRef.current.valueString;
|
|
303
295
|
target.valueString = globalRef.current.returnValue;
|
|
304
|
-
onChange({
|
|
296
|
+
onChange({
|
|
297
|
+
...e,
|
|
305
298
|
value: globalRef.current.value,
|
|
306
299
|
target
|
|
307
300
|
});
|
|
308
301
|
},
|
|
309
302
|
onBlur: e => _onBlur(e)
|
|
310
|
-
}), !!error && jsx(HelperText, {
|
|
303
|
+
}), !!error && jsx(HelperText, {
|
|
304
|
+
...helperTextProps,
|
|
311
305
|
disabled: disabled
|
|
312
|
-
}, error), !error && validateResult && jsx(HelperText, {
|
|
306
|
+
}, error), !error && validateResult && jsx(HelperText, {
|
|
307
|
+
...helperTextProps,
|
|
313
308
|
disabled: disabled
|
|
314
309
|
}, validateResult));
|
|
315
310
|
});
|
|
@@ -342,116 +337,80 @@ NumberInput.defaultProps = {
|
|
|
342
337
|
NumberInput.propTypes = {
|
|
343
338
|
/** If `true`, the `input` element is focused during the first mount. */
|
|
344
339
|
autoFocus: PropTypes.bool,
|
|
345
|
-
|
|
346
340
|
/** If `true`, width of input will resize according to content. */
|
|
347
341
|
autoWidth: PropTypes.bool,
|
|
348
|
-
|
|
349
342
|
/** Class for component. */
|
|
350
343
|
className: PropTypes.string,
|
|
351
|
-
|
|
352
344
|
/** Number of decimal places allowed. */
|
|
353
345
|
decimalDigit: PropTypes.number,
|
|
354
|
-
|
|
355
346
|
/** Separator symbol. */
|
|
356
347
|
decimalSymbol: PropTypes.oneOf([',', '.']),
|
|
357
|
-
|
|
358
348
|
/** Default value of the component. */
|
|
359
349
|
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
360
|
-
|
|
361
350
|
/** The number of milliseconds to wait before call onChange. */
|
|
362
351
|
delayOnChange: PropTypes.number,
|
|
363
|
-
|
|
364
352
|
/** If `true`, the component is disabled. */
|
|
365
353
|
disabled: PropTypes.bool,
|
|
366
|
-
|
|
367
354
|
/** If `true`, negative numbers are not allowed. */
|
|
368
355
|
disabledNegative: PropTypes.bool,
|
|
369
|
-
|
|
370
356
|
/** [Icon](https://core.diginet.com.vn/ui/?path=/story/icon-basic--basic) or element placed to the right of input. */
|
|
371
357
|
endIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
372
|
-
|
|
373
358
|
/** Error displayed below input. */
|
|
374
359
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
375
|
-
|
|
376
360
|
/** fixedDecimalDigit. */
|
|
377
361
|
fixedDecimalDigit: PropTypes.bool,
|
|
378
|
-
|
|
379
362
|
/** Props applied to the [HelperText](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) element. */
|
|
380
363
|
helperTextProps: PropTypes.object,
|
|
381
|
-
|
|
382
364
|
/** [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes) applied to the input element. */
|
|
383
365
|
inputProps: PropTypes.object,
|
|
384
|
-
|
|
385
366
|
/** Pass a ref to the input element. */
|
|
386
367
|
inputRef: ref,
|
|
387
|
-
|
|
388
368
|
/** Style inline of input element. */
|
|
389
369
|
inputStyle: PropTypes.object,
|
|
390
|
-
|
|
391
370
|
/** The label of the component. */
|
|
392
371
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
393
|
-
|
|
394
372
|
/** Props applied to the [Label](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) element. */
|
|
395
373
|
labelProps: PropTypes.object,
|
|
396
|
-
|
|
397
374
|
/** Maximum possible value. */
|
|
398
375
|
max: PropTypes.number,
|
|
399
|
-
|
|
400
376
|
/** Maximum value character (not including separator). */
|
|
401
377
|
maxDigit: PropTypes.number,
|
|
402
|
-
|
|
403
378
|
/** Minimal possible value. */
|
|
404
379
|
min: PropTypes.number,
|
|
405
|
-
|
|
406
380
|
/** If `true`, component will have no style */
|
|
407
381
|
nonStyle: PropTypes.bool,
|
|
408
|
-
|
|
409
382
|
/** Callback fired when the input is blurred. */
|
|
410
383
|
onBlur: PropTypes.func,
|
|
411
|
-
|
|
412
384
|
/** Callback fired when the value is changed. */
|
|
413
385
|
onChange: PropTypes.func,
|
|
414
|
-
|
|
415
386
|
/** Callback fired when the input is focused. */
|
|
416
387
|
onFocus: PropTypes.func,
|
|
417
|
-
|
|
418
388
|
/** Callback fired when input. */
|
|
419
389
|
onInput: PropTypes.func,
|
|
420
|
-
|
|
421
390
|
/** Callback fired when pressing a key. */
|
|
422
391
|
onKeyDown: PropTypes.func,
|
|
423
|
-
|
|
424
392
|
/** Callback fired when releases a key. */
|
|
425
393
|
onKeyUp: PropTypes.func,
|
|
426
|
-
|
|
427
394
|
/** The short hint displayed in the input before the user enters a value. */
|
|
428
395
|
placeholder: PropTypes.string,
|
|
429
|
-
|
|
430
396
|
/** If `true`, the component is readOnly. */
|
|
431
397
|
readOnly: PropTypes.bool,
|
|
432
|
-
|
|
433
398
|
/** If `true`, the input element is required. */
|
|
434
399
|
required: PropTypes.bool,
|
|
435
|
-
|
|
436
400
|
/** [Icon](https://core.diginet.com.vn/ui/?path=/story/icon-basic--basic) or element placed to the left of input. */
|
|
437
401
|
startIcon: PropTypes.any,
|
|
438
|
-
|
|
439
402
|
/** Specify how much the values should increase/decrease upon clicking on up/down button. */
|
|
440
403
|
step: PropTypes.number,
|
|
441
|
-
|
|
442
404
|
/** Thousand separator character. */
|
|
443
405
|
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
* *
|
|
447
|
-
* *
|
|
448
|
-
* * array: the validation rule list, insist object/string
|
|
406
|
+
/** Validation value, argument can:<br/>
|
|
407
|
+
* * string: the validation rule. Example required.<br/>
|
|
408
|
+
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
409
|
+
* * array: the validation rule list, insist object/string
|
|
449
410
|
*/
|
|
450
411
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
451
|
-
|
|
452
412
|
/** The value of the input element, required for a controlled component. */
|
|
453
413
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
454
|
-
|
|
455
414
|
/** The variant to use. */
|
|
456
415
|
viewType: PropTypes.oneOf(['underlined', 'outlined'])
|
|
457
416
|
};
|