@alfalab/core-components-number-input 1.2.6 → 2.0.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.
- package/Component.desktop.d.ts +1 -1
- package/Component.desktop.js +9 -1
- package/Component.mobile.d.ts +1 -1
- package/Component.mobile.js +9 -1
- package/Component.responsive.d.ts +1 -1
- package/Component.responsive.js +14 -1
- package/components/number-input/Component.d.ts +21 -46
- package/components/number-input/Component.js +87 -84
- package/components/number-input/index.css +30 -0
- package/components/number-input/index.js +8 -0
- package/components/steppers/Component.d.ts +14 -0
- package/components/steppers/Component.js +33 -0
- package/components/steppers/index.css +32 -0
- package/components/steppers/index.d.ts +1 -0
- package/components/steppers/index.js +15 -0
- package/cssm/Component.desktop.d.ts +1 -1
- package/cssm/Component.desktop.js +11 -1
- package/cssm/Component.mobile.d.ts +1 -1
- package/cssm/Component.mobile.js +11 -1
- package/cssm/Component.responsive.d.ts +1 -1
- package/cssm/Component.responsive.js +16 -1
- package/cssm/components/number-input/Component.d.ts +21 -46
- package/cssm/components/number-input/Component.js +87 -84
- package/cssm/components/number-input/index.js +10 -0
- package/cssm/components/number-input/index.module.css +29 -0
- package/cssm/components/steppers/Component.d.ts +14 -0
- package/cssm/components/steppers/Component.js +32 -0
- package/cssm/components/steppers/index.d.ts +1 -0
- package/cssm/components/steppers/index.js +16 -0
- package/cssm/components/steppers/index.module.css +31 -0
- package/cssm/desktop/index.d.ts +2 -0
- package/cssm/desktop/index.js +25 -0
- package/cssm/index.js +11 -0
- package/cssm/mobile/index.d.ts +2 -0
- package/cssm/mobile/index.js +25 -0
- package/cssm/utils.d.ts +19 -9
- package/cssm/utils.js +244 -21
- package/desktop/index.d.ts +2 -0
- package/desktop/index.js +23 -0
- package/desktop/package.json +3 -0
- package/esm/Component.desktop.d.ts +1 -1
- package/esm/Component.desktop.js +9 -1
- package/esm/Component.mobile.d.ts +1 -1
- package/esm/Component.mobile.js +9 -1
- package/esm/Component.responsive.d.ts +1 -1
- package/esm/Component.responsive.js +15 -2
- package/esm/components/number-input/Component.d.ts +21 -46
- package/esm/components/number-input/Component.js +88 -86
- package/esm/components/number-input/index.css +30 -0
- package/esm/components/number-input/index.js +8 -0
- package/esm/components/steppers/Component.d.ts +14 -0
- package/esm/components/steppers/Component.js +24 -0
- package/esm/components/steppers/index.css +32 -0
- package/esm/components/steppers/index.d.ts +1 -0
- package/esm/components/steppers/index.js +7 -0
- package/esm/desktop/index.d.ts +2 -0
- package/esm/desktop/index.js +15 -0
- package/esm/index.js +9 -0
- package/esm/mobile/index.d.ts +2 -0
- package/esm/mobile/index.js +15 -0
- package/esm/utils.d.ts +19 -9
- package/esm/utils.js +236 -19
- package/index.js +9 -0
- package/mobile/index.d.ts +2 -0
- package/mobile/index.js +23 -0
- package/mobile/package.json +3 -0
- package/modern/Component.desktop.d.ts +1 -1
- package/modern/Component.desktop.js +9 -1
- package/modern/Component.mobile.d.ts +1 -1
- package/modern/Component.mobile.js +9 -1
- package/modern/Component.responsive.d.ts +1 -1
- package/modern/Component.responsive.js +13 -1
- package/modern/components/number-input/Component.d.ts +21 -46
- package/modern/components/number-input/Component.js +84 -86
- package/modern/components/number-input/index.css +30 -0
- package/modern/components/number-input/index.js +8 -0
- package/modern/components/steppers/Component.d.ts +14 -0
- package/modern/components/steppers/Component.js +23 -0
- package/modern/components/steppers/index.css +32 -0
- package/modern/components/steppers/index.d.ts +1 -0
- package/modern/components/steppers/index.js +7 -0
- package/modern/desktop/index.d.ts +2 -0
- package/modern/desktop/index.js +14 -0
- package/modern/index.js +9 -0
- package/modern/mobile/index.d.ts +2 -0
- package/modern/mobile/index.js +14 -0
- package/modern/utils.d.ts +19 -9
- package/modern/utils.js +223 -18
- package/package.json +9 -2
- package/src/Component.desktop.tsx +2 -2
- package/src/Component.mobile.tsx +2 -2
- package/src/Component.responsive.tsx +16 -2
- package/src/components/number-input/Component.tsx +195 -129
- package/src/components/number-input/index.module.css +18 -0
- package/src/components/steppers/Component.tsx +64 -0
- package/src/components/steppers/index.module.css +21 -0
- package/src/components/steppers/index.ts +1 -0
- package/src/desktop/index.ts +1 -0
- package/src/desktop/package.json +3 -0
- package/src/mobile/index.ts +1 -0
- package/src/mobile/package.json +3 -0
- package/src/utils.ts +302 -24
- package/utils.d.ts +19 -9
- package/utils.js +244 -21
- package/Component-10db897e.d.ts +0 -38
- package/Component-72dda473.d.ts +0 -53
- package/Component.desktop-785df74d.d.ts +0 -6
- package/Component.mobile-d7e9f69d.d.ts +0 -6
- package/Component.mobile-ebda875c.d.ts +0 -7
- package/Component.responsive-785df74d.d.ts +0 -26
- package/cssm/Component-10db897e.d.ts +0 -38
- package/cssm/Component-72dda473.d.ts +0 -53
- package/cssm/Component.desktop-785df74d.d.ts +0 -6
- package/cssm/Component.mobile-d7e9f69d.d.ts +0 -6
- package/cssm/Component.mobile-ebda875c.d.ts +0 -7
- package/cssm/Component.responsive-785df74d.d.ts +0 -26
- package/cssm/desktop.d.ts +0 -2
- package/cssm/desktop.js +0 -15
- package/cssm/index-10db897e.d.ts +0 -50
- package/cssm/index-3109f463.d.ts +0 -62
- package/cssm/index-72dda473.d.ts +0 -12
- package/cssm/index-ebda875c.d.ts +0 -145
- package/cssm/mobile.d.ts +0 -2
- package/cssm/mobile.js +0 -15
- package/cssm/typings-89f0cb07.d.ts +0 -93
- package/desktop.d.ts +0 -2
- package/desktop.js +0 -15
- package/esm/Component-10db897e.d.ts +0 -38
- package/esm/Component-72dda473.d.ts +0 -53
- package/esm/Component.desktop-785df74d.d.ts +0 -6
- package/esm/Component.mobile-d7e9f69d.d.ts +0 -6
- package/esm/Component.mobile-ebda875c.d.ts +0 -7
- package/esm/Component.responsive-785df74d.d.ts +0 -26
- package/esm/desktop.d.ts +0 -2
- package/esm/desktop.js +0 -7
- package/esm/index-10db897e.d.ts +0 -50
- package/esm/index-3109f463.d.ts +0 -62
- package/esm/index-72dda473.d.ts +0 -12
- package/esm/index-ebda875c.d.ts +0 -145
- package/esm/mobile.d.ts +0 -2
- package/esm/mobile.js +0 -7
- package/esm/typings-89f0cb07.d.ts +0 -93
- package/index-10db897e.d.ts +0 -50
- package/index-3109f463.d.ts +0 -62
- package/index-72dda473.d.ts +0 -12
- package/index-ebda875c.d.ts +0 -145
- package/mobile.d.ts +0 -2
- package/mobile.js +0 -15
- package/modern/Component-10db897e.d.ts +0 -38
- package/modern/Component-72dda473.d.ts +0 -53
- package/modern/Component.desktop-785df74d.d.ts +0 -6
- package/modern/Component.mobile-d7e9f69d.d.ts +0 -6
- package/modern/Component.mobile-ebda875c.d.ts +0 -7
- package/modern/Component.responsive-785df74d.d.ts +0 -26
- package/modern/desktop.d.ts +0 -2
- package/modern/desktop.js +0 -6
- package/modern/index-10db897e.d.ts +0 -50
- package/modern/index-3109f463.d.ts +0 -62
- package/modern/index-72dda473.d.ts +0 -12
- package/modern/index-ebda875c.d.ts +0 -145
- package/modern/mobile.d.ts +0 -2
- package/modern/mobile.js +0 -6
- package/modern/typings-89f0cb07.d.ts +0 -93
- package/src/desktop.ts +0 -1
- package/src/mobile.ts +0 -1
- package/typings-89f0cb07.d.ts +0 -93
package/cssm/utils.js
CHANGED
|
@@ -2,35 +2,258 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var core = require('@maskito/core');
|
|
6
|
+
var coreComponentsShared = require('@alfalab/core-components-shared/cssm');
|
|
7
|
+
|
|
8
|
+
/* eslint-disable no-param-reassign */
|
|
9
|
+
var MINUS_SIGN = '-';
|
|
6
10
|
var SEPARATORS = [',', '.'];
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
|
12
|
+
var MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
|
|
13
|
+
var MAX_DIGITS = 15; // с 16 уже упираемся в MAX_SAFE_INTEGER
|
|
14
|
+
function parseNumber(value) {
|
|
15
|
+
if (value === void 0) { value = ''; }
|
|
16
|
+
if (typeof value === 'number')
|
|
17
|
+
return value;
|
|
18
|
+
var pseudoSeparatorsRegExp = new RegExp("[".concat(SEPARATORS.join(''), "]"), 'gi');
|
|
19
|
+
return value
|
|
20
|
+
? parseFloat(value
|
|
21
|
+
.replace(new RegExp("[^".concat(MINUS_SIGN).concat(SEPARATORS.join(''), "0-9]"), 'gi'), '')
|
|
22
|
+
.replace(pseudoSeparatorsRegExp, '.'))
|
|
23
|
+
: NaN;
|
|
9
24
|
}
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Преобразовать число в строку с заменой экспоненты на десятичную дробь
|
|
27
|
+
*/
|
|
28
|
+
function stringifyNumberWithoutExp(value) {
|
|
29
|
+
var valueString = String(value);
|
|
30
|
+
var _a = valueString.split('e-'), numberPart = _a[0], expPart = _a[1];
|
|
31
|
+
var valueWithoutExp = valueString;
|
|
32
|
+
if (expPart) {
|
|
33
|
+
var _b = numberPart.split('.'), fractionalPart = _b[1];
|
|
34
|
+
var decimalDigits = Number(expPart) + ((fractionalPart === null || fractionalPart === void 0 ? void 0 : fractionalPart.length) || 0);
|
|
35
|
+
valueWithoutExp = value.toFixed(decimalDigits);
|
|
36
|
+
}
|
|
37
|
+
return valueWithoutExp;
|
|
38
|
+
}
|
|
39
|
+
var getNumberRegExp = function (min, fractionLength) {
|
|
40
|
+
var reStr = '[0-9]*';
|
|
41
|
+
if (min < 0) {
|
|
42
|
+
reStr = "(\\".concat(MINUS_SIGN, ")?").concat(reStr);
|
|
43
|
+
}
|
|
12
44
|
if (fractionLength !== 0) {
|
|
13
|
-
reStr = "".concat(reStr, "[").concat(SEPARATORS.map(function (s) { return "\\".concat(s); }).join(''), "]?[0-9]{0,").concat(fractionLength ||
|
|
45
|
+
reStr = "".concat(reStr, "[").concat(SEPARATORS.map(function (s) { return "\\".concat(s); }).join(''), "]?[0-9]{0,").concat(fractionLength || MAX_DIGITS, "}");
|
|
14
46
|
}
|
|
15
47
|
return new RegExp("^".concat(reStr, "$"));
|
|
16
48
|
};
|
|
49
|
+
function createMaskOptions(_a) {
|
|
50
|
+
var separator = _a.separator, fractionLength = _a.fractionLength, min = _a.min, max = _a.max;
|
|
51
|
+
return {
|
|
52
|
+
mask: getNumberRegExp(min, fractionLength),
|
|
53
|
+
preprocessors: [
|
|
54
|
+
createPseudoSeparatorPreprocessor(separator),
|
|
55
|
+
createNotEmptyIntegerPartPreprocessor({ separator: separator, fractionLength: fractionLength }),
|
|
56
|
+
createZeroFractionLengthPreprocessor(fractionLength, separator),
|
|
57
|
+
createRepeatedSeparatorPreprocessor(separator),
|
|
58
|
+
],
|
|
59
|
+
postprocessors: [
|
|
60
|
+
createLeadingZeroesValidationPostprocessor(separator),
|
|
61
|
+
createMinMaxPostprocessor({ min: min, max: max, separator: separator }),
|
|
62
|
+
],
|
|
63
|
+
plugins: [createNotEmptyPartsPlugin(separator), createMinMaxPlugin({ min: min, max: max })],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
17
66
|
/**
|
|
18
|
-
*
|
|
67
|
+
* Заполняет целочисленную часть при вводе separator.
|
|
68
|
+
* @example Type , => 0,
|
|
19
69
|
*/
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
70
|
+
function createNotEmptyIntegerPartPreprocessor(_a) {
|
|
71
|
+
var separator = _a.separator, fractionLength = _a.fractionLength;
|
|
72
|
+
var startWithDecimalSepRegExp = new RegExp("^\\D*\\".concat(separator));
|
|
73
|
+
return function (_a) {
|
|
74
|
+
var elementState = _a.elementState, data = _a.data;
|
|
75
|
+
var value = elementState.value, selection = elementState.selection;
|
|
76
|
+
var from = selection[0];
|
|
77
|
+
if (fractionLength <= 0 ||
|
|
78
|
+
value.includes(separator) ||
|
|
79
|
+
!data.match(startWithDecimalSepRegExp)) {
|
|
80
|
+
return { elementState: elementState, data: data };
|
|
81
|
+
}
|
|
82
|
+
var digitsBeforeCursor = value.slice(0, from).match(/\d+/);
|
|
83
|
+
return {
|
|
84
|
+
elementState: elementState,
|
|
85
|
+
data: digitsBeforeCursor ? data : "0".concat(data),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Не позволяет вводить невалидный разделитель.
|
|
91
|
+
*/
|
|
92
|
+
function createPseudoSeparatorPreprocessor(separator) {
|
|
93
|
+
var pseudoSeparatorsRegExp = new RegExp("[".concat(SEPARATORS.join(''), "]"), 'gi');
|
|
94
|
+
return function (_a) {
|
|
95
|
+
var elementState = _a.elementState, data = _a.data;
|
|
96
|
+
var value = elementState.value, selection = elementState.selection;
|
|
97
|
+
return {
|
|
98
|
+
elementState: {
|
|
99
|
+
selection: selection,
|
|
100
|
+
value: value.replace(pseudoSeparatorsRegExp, separator),
|
|
101
|
+
},
|
|
102
|
+
data: data.replace(pseudoSeparatorsRegExp, separator),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Помогает верно обрезать значения при вставке, если fractionLength===0
|
|
108
|
+
* @example paste 123,123 -> 123
|
|
109
|
+
*/
|
|
110
|
+
function createZeroFractionLengthPreprocessor(fractionLength, separator) {
|
|
111
|
+
if (fractionLength > 0) {
|
|
112
|
+
return function (state) { return state; };
|
|
26
113
|
}
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
114
|
+
var decimalPartRegExp = new RegExp("\\".concat(separator, ".*$"), 'g');
|
|
115
|
+
return function (_a) {
|
|
116
|
+
var elementState = _a.elementState, data = _a.data;
|
|
117
|
+
var value = elementState.value, selection = elementState.selection;
|
|
118
|
+
var from = selection[0], to = selection[1];
|
|
119
|
+
var newValue = value.replace(decimalPartRegExp, '');
|
|
120
|
+
return {
|
|
121
|
+
elementState: {
|
|
122
|
+
selection: [Math.min(from, newValue.length), Math.min(to, newValue.length)],
|
|
123
|
+
value: newValue,
|
|
124
|
+
},
|
|
125
|
+
data: data.replace(decimalPartRegExp, ''),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Запрещает вводить второй сепаратор
|
|
131
|
+
*/
|
|
132
|
+
function createRepeatedSeparatorPreprocessor(separator) {
|
|
133
|
+
return function (_a) {
|
|
134
|
+
var elementState = _a.elementState, data = _a.data;
|
|
135
|
+
var value = elementState.value, selection = elementState.selection;
|
|
136
|
+
var from = selection[0], to = selection[1];
|
|
137
|
+
return {
|
|
138
|
+
elementState: elementState,
|
|
139
|
+
data: !value.includes(separator) || value.slice(from, to + 1).includes(separator)
|
|
140
|
+
? data
|
|
141
|
+
: data.replace(new RegExp("\\".concat(separator)), ''),
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Удаляет лишние нули в начале целой части.
|
|
147
|
+
* @example 0,|00005 => Backspace => |5
|
|
148
|
+
* @example -0,|00005 => Backspace => -|5
|
|
149
|
+
* @example "000000" => 0|
|
|
150
|
+
* @example 0| => Type "5" => 5|
|
|
151
|
+
*/
|
|
152
|
+
function createLeadingZeroesValidationPostprocessor(separator) {
|
|
153
|
+
var trimLeadingZeroes = function (value) {
|
|
154
|
+
return value
|
|
155
|
+
.replace(new RegExp('^(\\D+)?0+(?=0)'), '$1')
|
|
156
|
+
.replace(new RegExp('^(\\D+)?0+(?=[1-9])'), '$1');
|
|
157
|
+
};
|
|
158
|
+
var countTrimmedZeroesBefore = function (value, index) {
|
|
159
|
+
var valueBefore = value.slice(0, index);
|
|
160
|
+
var followedByZero = value.slice(index).startsWith('0');
|
|
161
|
+
return (valueBefore.length - trimLeadingZeroes(valueBefore).length + (followedByZero ? 1 : 0));
|
|
162
|
+
};
|
|
163
|
+
return function (_a) {
|
|
164
|
+
var value = _a.value, selection = _a.selection;
|
|
165
|
+
var from = selection[0], to = selection[1];
|
|
166
|
+
var hasSeparator = value.includes(separator);
|
|
167
|
+
var _b = value.split(separator), integerPart = _b[0], _c = _b[1], decimalPart = _c === void 0 ? '' : _c;
|
|
168
|
+
var zeroTrimmedIntegerPart = trimLeadingZeroes(integerPart);
|
|
169
|
+
if (integerPart === zeroTrimmedIntegerPart) {
|
|
170
|
+
return { value: value, selection: selection };
|
|
171
|
+
}
|
|
172
|
+
var newFrom = from - countTrimmedZeroesBefore(value, from);
|
|
173
|
+
var newTo = to - countTrimmedZeroesBefore(value, to);
|
|
174
|
+
return {
|
|
175
|
+
value: zeroTrimmedIntegerPart + (hasSeparator ? separator : '') + decimalPart,
|
|
176
|
+
selection: [Math.max(newFrom, 0), Math.max(newTo, 0)],
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Валидирует значение с учетом min max значений.
|
|
182
|
+
* Работает совместно с createMinMaxPlugin
|
|
183
|
+
*/
|
|
184
|
+
function createMinMaxPostprocessor(_a) {
|
|
185
|
+
var min = _a.min, max = _a.max, separator = _a.separator;
|
|
186
|
+
return function (_a) {
|
|
187
|
+
var value = _a.value, selection = _a.selection;
|
|
188
|
+
var parsedNumber = parseNumber(value);
|
|
189
|
+
var limitedValue =
|
|
190
|
+
/**
|
|
191
|
+
* Здесь невозможно ограничить нижнюю границу, если пользователь вводит положительное число.
|
|
192
|
+
* То же самое для верхней границы и отрицательного числа.
|
|
193
|
+
* Если min=5, то без этого условия не получится ввести 40, похожая ситуация и с отрицательным max
|
|
194
|
+
*/
|
|
195
|
+
parsedNumber > 0 ? Math.min(parsedNumber, max) : Math.max(parsedNumber, min);
|
|
196
|
+
if (!Number.isNaN(parsedNumber) && limitedValue !== parsedNumber) {
|
|
197
|
+
var newValue = "".concat(limitedValue).replace('.', separator);
|
|
198
|
+
return {
|
|
199
|
+
value: newValue,
|
|
200
|
+
selection: [newValue.length, newValue.length],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
value: value,
|
|
205
|
+
selection: selection,
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function createMinMaxPlugin(_a) {
|
|
210
|
+
var min = _a.min, max = _a.max;
|
|
211
|
+
return function (element, options) {
|
|
212
|
+
var listener = function () {
|
|
213
|
+
var parsedNumber = parseNumber(element.value);
|
|
214
|
+
var clampedNumber = coreComponentsShared.fnUtils.clamp(parsedNumber, min, max);
|
|
215
|
+
if (!Number.isNaN(parsedNumber) && parsedNumber !== clampedNumber) {
|
|
216
|
+
element.value = core.maskitoTransform(stringifyNumberWithoutExp(clampedNumber), options);
|
|
217
|
+
element.dispatchEvent(new Event('input', { bubbles: true }));
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var evListenerOptions = { capture: true };
|
|
221
|
+
element.addEventListener('blur', listener, evListenerOptions);
|
|
222
|
+
return function () { return element.removeEventListener('blur', listener, evListenerOptions); };
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function createNotEmptyPartsPlugin(separator) {
|
|
226
|
+
return function (element) {
|
|
227
|
+
var listener = function () {
|
|
228
|
+
var newValue = element.value
|
|
229
|
+
// 0,9000000 -> 0,9
|
|
230
|
+
.replace(new RegExp("(\\".concat(separator, "\\d*?)(0+$)")), '$1')
|
|
231
|
+
// ,2 => 0,2
|
|
232
|
+
.replace(new RegExp("^(\\D+)?\\".concat(separator)), "$10".concat(separator))
|
|
233
|
+
// 0, -> 0
|
|
234
|
+
.replace(new RegExp("\\".concat(separator, "$")), '')
|
|
235
|
+
// -0 -> 0
|
|
236
|
+
.replace(new RegExp("^".concat(MINUS_SIGN, "0$")), '0')
|
|
237
|
+
// - -> ''
|
|
238
|
+
.replace(new RegExp("^".concat(MINUS_SIGN, "$")), '');
|
|
239
|
+
if (newValue !== element.value) {
|
|
240
|
+
element.value = newValue;
|
|
241
|
+
element.dispatchEvent(new Event('input', { bubbles: true }));
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var evListenerOptions = { capture: true };
|
|
245
|
+
element.addEventListener('blur', listener, evListenerOptions);
|
|
246
|
+
return function () { return element.removeEventListener('blur', listener, evListenerOptions); };
|
|
247
|
+
};
|
|
248
|
+
}
|
|
32
249
|
|
|
250
|
+
exports.MAX_DIGITS = MAX_DIGITS;
|
|
251
|
+
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
|
252
|
+
exports.MINUS_SIGN = MINUS_SIGN;
|
|
253
|
+
exports.MIN_SAFE_INTEGER = MIN_SAFE_INTEGER;
|
|
33
254
|
exports.SEPARATORS = SEPARATORS;
|
|
34
|
-
exports.
|
|
35
|
-
exports.
|
|
36
|
-
exports.
|
|
255
|
+
exports.createMaskOptions = createMaskOptions;
|
|
256
|
+
exports.createMinMaxPlugin = createMinMaxPlugin;
|
|
257
|
+
exports.createNotEmptyPartsPlugin = createNotEmptyPartsPlugin;
|
|
258
|
+
exports.parseNumber = parseNumber;
|
|
259
|
+
exports.stringifyNumberWithoutExp = stringifyNumberWithoutExp;
|
package/desktop/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Component_desktop = require('../Component.desktop.js');
|
|
6
|
+
require('tslib');
|
|
7
|
+
require('react');
|
|
8
|
+
require('@alfalab/core-components-input/desktop');
|
|
9
|
+
require('../components/number-input/Component.js');
|
|
10
|
+
require('react-merge-refs');
|
|
11
|
+
require('@maskito/core');
|
|
12
|
+
require('@maskito/react');
|
|
13
|
+
require('classnames');
|
|
14
|
+
require('@alfalab/core-components-shared');
|
|
15
|
+
require('../utils.js');
|
|
16
|
+
require('../components/steppers/Component.js');
|
|
17
|
+
require('@alfalab/core-components-icon-button');
|
|
18
|
+
require('@alfalab/icons-glyph/MinusMIcon');
|
|
19
|
+
require('@alfalab/icons-glyph/PlusMediumMIcon');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
exports.NumberInputDesktop = Component_desktop.NumberInputDesktop;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { NumberInputProps } from "./components/number-input/index";
|
|
4
|
-
type NumberInputDesktopProps = Omit<NumberInputProps, 'Input' | 'breakpoint'>;
|
|
4
|
+
type NumberInputDesktopProps = Omit<NumberInputProps, 'Input' | 'breakpoint' | 'view'>;
|
|
5
5
|
declare const NumberInputDesktop: React.ForwardRefExoticComponent<NumberInputDesktopProps & React.RefAttributes<HTMLInputElement>>;
|
|
6
6
|
export { NumberInputDesktopProps, NumberInputDesktop };
|
package/esm/Component.desktop.js
CHANGED
|
@@ -3,8 +3,16 @@ import React, { forwardRef } from 'react';
|
|
|
3
3
|
import { InputDesktop } from '@alfalab/core-components-input/esm/desktop';
|
|
4
4
|
import { NumberInput } from './components/number-input/Component.js';
|
|
5
5
|
import 'react-merge-refs';
|
|
6
|
+
import '@maskito/core';
|
|
7
|
+
import '@maskito/react';
|
|
8
|
+
import 'classnames';
|
|
9
|
+
import '@alfalab/core-components-shared/esm';
|
|
6
10
|
import './utils.js';
|
|
11
|
+
import './components/steppers/Component.js';
|
|
12
|
+
import '@alfalab/core-components-icon-button/esm';
|
|
13
|
+
import '@alfalab/icons-glyph/MinusMIcon';
|
|
14
|
+
import '@alfalab/icons-glyph/PlusMediumMIcon';
|
|
7
15
|
|
|
8
|
-
var NumberInputDesktop = forwardRef(function (props, ref) { return React.createElement(NumberInput, __assign({}, props, { Input: InputDesktop, ref: ref })); });
|
|
16
|
+
var NumberInputDesktop = forwardRef(function (props, ref) { return React.createElement(NumberInput, __assign({}, props, { Input: InputDesktop, ref: ref, view: 'desktop' })); });
|
|
9
17
|
|
|
10
18
|
export { NumberInputDesktop };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { NumberInputProps } from "./components/number-input/index";
|
|
4
|
-
type NumberInputMobileProps = Omit<NumberInputProps, 'Input' | 'breakpoint'>;
|
|
4
|
+
type NumberInputMobileProps = Omit<NumberInputProps, 'Input' | 'breakpoint' | 'view'>;
|
|
5
5
|
declare const NumberInputMobile: React.ForwardRefExoticComponent<NumberInputMobileProps & React.RefAttributes<HTMLInputElement>>;
|
|
6
6
|
export { NumberInputMobileProps, NumberInputMobile };
|
package/esm/Component.mobile.js
CHANGED
|
@@ -3,8 +3,16 @@ import React, { forwardRef } from 'react';
|
|
|
3
3
|
import { InputMobile } from '@alfalab/core-components-input/esm/mobile';
|
|
4
4
|
import { NumberInput } from './components/number-input/Component.js';
|
|
5
5
|
import 'react-merge-refs';
|
|
6
|
+
import '@maskito/core';
|
|
7
|
+
import '@maskito/react';
|
|
8
|
+
import 'classnames';
|
|
9
|
+
import '@alfalab/core-components-shared/esm';
|
|
6
10
|
import './utils.js';
|
|
11
|
+
import './components/steppers/Component.js';
|
|
12
|
+
import '@alfalab/core-components-icon-button/esm';
|
|
13
|
+
import '@alfalab/icons-glyph/MinusMIcon';
|
|
14
|
+
import '@alfalab/icons-glyph/PlusMediumMIcon';
|
|
7
15
|
|
|
8
|
-
var NumberInputMobile = forwardRef(function (props, ref) { return React.createElement(NumberInput, __assign({}, props, { Input: InputMobile, ref: ref })); });
|
|
16
|
+
var NumberInputMobile = forwardRef(function (props, ref) { return React.createElement(NumberInput, __assign({}, props, { Input: InputMobile, ref: ref, view: 'mobile' })); });
|
|
9
17
|
|
|
10
18
|
export { NumberInputMobile };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { NumberInputProps } from "./components/number-input/index";
|
|
4
|
-
type NumberInputResponsiveProps = Omit<NumberInputProps, 'Input'>;
|
|
4
|
+
type NumberInputResponsiveProps = Omit<NumberInputProps, 'Input' | 'view'>;
|
|
5
5
|
declare const NumberInputResponsive: React.ForwardRefExoticComponent<NumberInputResponsiveProps & React.RefAttributes<HTMLInputElement>>;
|
|
6
6
|
export { NumberInputResponsiveProps, NumberInputResponsive };
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
2
|
import React, { forwardRef } from 'react';
|
|
3
3
|
import { Input } from '@alfalab/core-components-input/esm';
|
|
4
|
+
import { useMatchMedia } from '@alfalab/core-components-mq/esm';
|
|
4
5
|
import { NumberInput } from './components/number-input/Component.js';
|
|
5
6
|
import 'react-merge-refs';
|
|
7
|
+
import '@maskito/core';
|
|
8
|
+
import '@maskito/react';
|
|
9
|
+
import 'classnames';
|
|
10
|
+
import '@alfalab/core-components-shared/esm';
|
|
6
11
|
import './utils.js';
|
|
12
|
+
import './components/steppers/Component.js';
|
|
13
|
+
import '@alfalab/core-components-icon-button/esm';
|
|
14
|
+
import '@alfalab/icons-glyph/MinusMIcon';
|
|
15
|
+
import '@alfalab/icons-glyph/PlusMediumMIcon';
|
|
7
16
|
|
|
8
|
-
var NumberInputResponsive = forwardRef(function (
|
|
17
|
+
var NumberInputResponsive = forwardRef(function (_a, ref) {
|
|
18
|
+
var _b = _a.breakpoint, breakpoint = _b === void 0 ? 1024 : _b, defaultMatchMediaValue = _a.defaultMatchMediaValue, restProps = __rest(_a, ["breakpoint", "defaultMatchMediaValue"]);
|
|
19
|
+
var isDesktop = useMatchMedia("(min-width: ".concat(breakpoint, "px)"), defaultMatchMediaValue)[0];
|
|
20
|
+
return (React.createElement(NumberInput, __assign({}, restProps, { Input: Input, ref: ref, view: isDesktop ? 'desktop' : 'mobile', breakpoint: breakpoint, defaultMatchMediaValue: defaultMatchMediaValue })));
|
|
21
|
+
});
|
|
9
22
|
|
|
10
23
|
export { NumberInputResponsive };
|
|
@@ -1,80 +1,55 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { ChangeEvent, FC, Ref } from "react";
|
|
3
4
|
import { InputProps } from "@alfalab/core-components-input";
|
|
4
|
-
|
|
5
|
+
interface NumberInputProps extends Omit<InputProps, 'value' | 'onChange' | 'type' | 'defaultValue'> {
|
|
5
6
|
/**
|
|
6
7
|
* Значение поля ввода
|
|
7
8
|
*/
|
|
8
9
|
value?: string | number | null;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Значение по-умолчанию
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
defaultValue?: string | number | null;
|
|
13
14
|
/**
|
|
14
15
|
* Разделитель ',' или '.'
|
|
15
16
|
*/
|
|
16
17
|
separator?: '.' | ',';
|
|
17
18
|
/**
|
|
18
19
|
* Количество символов после разделителя
|
|
20
|
+
* Если указан проп step, то всегда 0
|
|
19
21
|
*/
|
|
20
22
|
fractionLength?: number;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Шаг инкремента/декремента. Используйте только целочисленные значения
|
|
23
25
|
*/
|
|
24
|
-
|
|
25
|
-
ref?: React.Ref<HTMLInputElement>;
|
|
26
|
-
}>;
|
|
26
|
+
step?: number;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Минимальное значение
|
|
29
|
+
* @default Number.MIN_SAFE_INTEGER
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Числовое значение инпута
|
|
33
|
-
*/
|
|
34
|
-
value: number | null;
|
|
35
|
-
/**
|
|
36
|
-
* Строковое значение инпута
|
|
37
|
-
* Используйте для изменения значения инпута
|
|
38
|
-
*/
|
|
39
|
-
valueString: string;
|
|
40
|
-
}) => void;
|
|
41
|
-
};
|
|
42
|
-
declare const NumberInput: React.ForwardRefExoticComponent<Omit<InputProps, "value" | "onChange" | "type"> & {
|
|
31
|
+
min?: number;
|
|
43
32
|
/**
|
|
44
|
-
*
|
|
33
|
+
* Максимальное значение
|
|
34
|
+
* @default Number.MAX_SAFE_INTEGER
|
|
45
35
|
*/
|
|
46
|
-
|
|
36
|
+
max?: number;
|
|
47
37
|
/**
|
|
48
|
-
*
|
|
38
|
+
* Отображение компонента в мобильном или десктопном виде
|
|
49
39
|
*/
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Разделитель ',' или '.'
|
|
53
|
-
*/
|
|
54
|
-
separator?: "," | "." | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Количество символов после разделителя
|
|
57
|
-
*/
|
|
58
|
-
fractionLength?: number | undefined;
|
|
40
|
+
view?: 'desktop' | 'mobile';
|
|
59
41
|
/**
|
|
60
42
|
* Компонент инпута
|
|
61
43
|
*/
|
|
62
|
-
Input:
|
|
63
|
-
ref?:
|
|
44
|
+
Input: FC<InputProps & {
|
|
45
|
+
ref?: Ref<HTMLInputElement>;
|
|
64
46
|
}>;
|
|
65
47
|
/**
|
|
66
48
|
* Обработчик события изменения значения
|
|
67
49
|
*/
|
|
68
|
-
onChange?: (
|
|
69
|
-
/**
|
|
70
|
-
* Числовое значение инпута
|
|
71
|
-
*/
|
|
50
|
+
onChange?: (e: ChangeEvent<HTMLInputElement> | null, payload: {
|
|
72
51
|
value: number | null;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
valueString: string;
|
|
78
|
-
}) => void) | undefined;
|
|
79
|
-
} & React.RefAttributes<HTMLInputElement>>;
|
|
52
|
+
}) => void;
|
|
53
|
+
}
|
|
54
|
+
declare const NumberInput: React.ForwardRefExoticComponent<NumberInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
80
55
|
export { NumberInputProps, NumberInput };
|