intelicoreact 0.0.78 → 0.0.83
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/Atomic/FormElements/Input/Input.js +48 -44
- package/dist/Atomic/FormElements/Input/Input.stories.js +20 -22
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.scss +36 -6
- package/dist/Atomic/FormElements/NumericInput/NumericInput.js +291 -0
- package/dist/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
- package/dist/Atomic/FormElements/NumericInput/NumericInput.stories.js +117 -0
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +3 -1
- package/dist/Functions/inputExecutor.js +58 -0
- package/package.json +1 -1
- package/src/Atomic/FormElements/Input/Input.js +63 -41
- package/src/Atomic/FormElements/Input/Input.stories.js +44 -29
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.scss +36 -6
- package/src/Atomic/FormElements/NumericInput/NumericInput.js +262 -0
- package/src/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
- package/src/Atomic/FormElements/NumericInput/NumericInput.stories.js +78 -0
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +1 -1
- package/src/Functions/inputExecutor.js +53 -0
- package/src/Functions/utils.js +4 -1
|
@@ -19,12 +19,12 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
21
21
|
|
|
22
|
-
var _reactFeather = require("react-feather");
|
|
23
|
-
|
|
24
22
|
var _reactInputMask = _interopRequireDefault(require("react-input-mask"));
|
|
25
23
|
|
|
26
24
|
var _index = require("../../../Constants/index.constants");
|
|
27
25
|
|
|
26
|
+
var _inputExecutor = require("../../../Functions/inputExecutor");
|
|
27
|
+
|
|
28
28
|
require("./Input.scss");
|
|
29
29
|
|
|
30
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -37,30 +37,30 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
37
37
|
|
|
38
38
|
var Input = function Input(_ref) {
|
|
39
39
|
var onChange = _ref.onChange,
|
|
40
|
+
onBlur = _ref.onBlur,
|
|
41
|
+
onFocus = _ref.onFocus,
|
|
42
|
+
onKeyUp = _ref.onKeyUp,
|
|
43
|
+
isNotBlinkErrors = _ref.isNotBlinkErrors,
|
|
44
|
+
isPriceInput = _ref.isPriceInput,
|
|
45
|
+
isOnlyNumber = _ref.isOnlyNumber,
|
|
46
|
+
isOnlyString = _ref.isOnlyString,
|
|
47
|
+
isTwoDigitAfterDot = _ref.isTwoDigitAfterDot,
|
|
40
48
|
disabled = _ref.disabled,
|
|
41
49
|
withDelete = _ref.withDelete,
|
|
42
|
-
isNumeric = _ref.isNumeric,
|
|
43
|
-
_ref$numStep = _ref.numStep,
|
|
44
|
-
numStep = _ref$numStep === void 0 ? 1 : _ref$numStep,
|
|
45
|
-
_ref$min = _ref.min,
|
|
46
|
-
min = _ref$min === void 0 ? 0 : _ref$min,
|
|
47
|
-
max = _ref.max,
|
|
48
50
|
value = _ref.value,
|
|
49
51
|
placeholder = _ref.placeholder,
|
|
50
52
|
className = _ref.className,
|
|
51
53
|
_ref$type = _ref.type,
|
|
52
54
|
type = _ref$type === void 0 ? 'text' : _ref$type,
|
|
53
|
-
onBlur = _ref.onBlur,
|
|
54
|
-
onFocus = _ref.onFocus,
|
|
55
|
-
onKeyUp = _ref.onKeyUp,
|
|
56
55
|
mask = _ref.mask,
|
|
57
56
|
maskChar = _ref.maskChar,
|
|
58
57
|
formatChars = _ref.formatChars,
|
|
59
58
|
error = _ref.error,
|
|
60
59
|
icon = _ref.icon,
|
|
61
60
|
symbolsLimit = _ref.symbolsLimit,
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
blinkTime = _ref.blinkTime,
|
|
62
|
+
_ref$isFocusDefault = _ref.isFocusDefault,
|
|
63
|
+
isFocusDefault = _ref$isFocusDefault === void 0 ? false : _ref$isFocusDefault;
|
|
64
64
|
var DEFAULT_BLINK_TIME = 100; // STATES
|
|
65
65
|
|
|
66
66
|
var _useState = (0, _react.useState)(false),
|
|
@@ -84,21 +84,25 @@ var Input = function Input(_ref) {
|
|
|
84
84
|
var _useState7 = (0, _react.useState)(false),
|
|
85
85
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
86
86
|
isToHighlightError = _useState8[0],
|
|
87
|
-
setIsToHighlightError = _useState8[1];
|
|
87
|
+
setIsToHighlightError = _useState8[1];
|
|
88
88
|
|
|
89
|
+
var onlyNumbers = _inputExecutor.formatInput.onlyNumbers,
|
|
90
|
+
onlyString = _inputExecutor.formatInput.onlyString;
|
|
91
|
+
var _formatInput$priceInp = _inputExecutor.formatInput.priceInput,
|
|
92
|
+
addCommas = _formatInput$priceInp.addCommas,
|
|
93
|
+
removeComma = _formatInput$priceInp.removeComma; // HANDLES
|
|
89
94
|
|
|
90
95
|
var handle = {
|
|
91
96
|
change: function change(e) {
|
|
92
97
|
var inputValue = e.target ? e.target.value : e;
|
|
93
98
|
|
|
94
|
-
if (
|
|
95
|
-
inputValue =
|
|
96
|
-
|
|
97
|
-
if (min && +min > inputValue) {
|
|
98
|
-
inputValue = min;
|
|
99
|
-
} else if (max && +max < inputValue) inputValue = max;
|
|
100
|
-
} else if (symbolsLimit && inputValue.length > +symbolsLimit) inputValue = inputValue.substring(0, +symbolsLimit);
|
|
99
|
+
if (symbolsLimit && inputValue.length > +symbolsLimit) {
|
|
100
|
+
inputValue = inputValue.substring(0, +symbolsLimit);
|
|
101
|
+
}
|
|
101
102
|
|
|
103
|
+
if (isOnlyNumber && !isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue);
|
|
104
|
+
if (isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue, true);
|
|
105
|
+
if (isOnlyString) inputValue = onlyString(inputValue);
|
|
102
106
|
onChange(inputValue.toString());
|
|
103
107
|
},
|
|
104
108
|
toggleEdit: function toggleEdit() {
|
|
@@ -107,11 +111,21 @@ var Input = function Input(_ref) {
|
|
|
107
111
|
},
|
|
108
112
|
focus: function focus(e) {
|
|
109
113
|
setIsFocused(true);
|
|
114
|
+
if (isPriceInput && isOnlyNumber) onChange(removeComma(value));
|
|
110
115
|
if (onFocus) onFocus(e);
|
|
111
116
|
},
|
|
112
117
|
blur: function blur(e) {
|
|
113
118
|
setIsFocused(false);
|
|
114
119
|
setEditing(false);
|
|
120
|
+
|
|
121
|
+
if (isTwoDigitAfterDot) {
|
|
122
|
+
onChange(cutOffsingleDot(value));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (isPriceInput && isOnlyNumber) {
|
|
126
|
+
onChange(addCommas(value));
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
if (onBlur) onBlur(e);
|
|
116
130
|
},
|
|
117
131
|
keyUp: function keyUp(e) {
|
|
@@ -132,6 +146,11 @@ var Input = function Input(_ref) {
|
|
|
132
146
|
if (onKeyUp) onKeyUp(e.keyCode, e);
|
|
133
147
|
}
|
|
134
148
|
};
|
|
149
|
+
|
|
150
|
+
function cutOffsingleDot(value) {
|
|
151
|
+
return value.toString().slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
152
|
+
}
|
|
153
|
+
|
|
135
154
|
(0, _react.useEffect)(function () {
|
|
136
155
|
if (isEditing) inputRef.current.focus();
|
|
137
156
|
}, [isEditing, isFocused]);
|
|
@@ -144,9 +163,7 @@ var Input = function Input(_ref) {
|
|
|
144
163
|
onChange: handle.change,
|
|
145
164
|
onFocus: handle.focus,
|
|
146
165
|
onBlur: handle.blur,
|
|
147
|
-
onKeyUp: handle.keyUp
|
|
148
|
-
min: min,
|
|
149
|
-
max: max
|
|
166
|
+
onKeyUp: handle.keyUp
|
|
150
167
|
}, maskChar ? {
|
|
151
168
|
maskChar: maskChar
|
|
152
169
|
} : {}), formatChars ? {
|
|
@@ -161,26 +178,10 @@ var Input = function Input(_ref) {
|
|
|
161
178
|
}));
|
|
162
179
|
}
|
|
163
180
|
|
|
164
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
181
|
+
return /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, uniProps, {
|
|
165
182
|
ref: inputRef,
|
|
166
|
-
type:
|
|
167
|
-
}))
|
|
168
|
-
className: "input__nums"
|
|
169
|
-
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
170
|
-
onClick: function onClick() {
|
|
171
|
-
return handle.change(value - numStep);
|
|
172
|
-
},
|
|
173
|
-
className: (0, _classnames.default)("input__num-btn", {
|
|
174
|
-
disabled: value <= min
|
|
175
|
-
})
|
|
176
|
-
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Minus, null)), /*#__PURE__*/_react.default.createElement("button", {
|
|
177
|
-
onClick: function onClick() {
|
|
178
|
-
return handle.change(+value + +numStep);
|
|
179
|
-
},
|
|
180
|
-
className: (0, _classnames.default)("input__num-btn", {
|
|
181
|
-
disabled: value >= max
|
|
182
|
-
})
|
|
183
|
-
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Plus, null))));
|
|
183
|
+
type: isPriceInput ? 'text' : type
|
|
184
|
+
}));
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
(0, _react.useEffect)(function () {
|
|
@@ -192,9 +193,12 @@ var Input = function Input(_ref) {
|
|
|
192
193
|
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
193
194
|
}
|
|
194
195
|
}, [isAttemptToChange]);
|
|
196
|
+
(0, _react.useEffect)(function () {
|
|
197
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
198
|
+
}, [inputRef, isFocusDefault]);
|
|
195
199
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
196
200
|
className: (0, _classnames.default)("input__wrap", (0, _defineProperty2.default)({}, "input__wrap_focus", isFocused), (0, _defineProperty2.default)({}, "input__wrap_error", error || isToHighlightError), (0, _defineProperty2.default)({}, "input__wrap_disabled", disabled))
|
|
197
|
-
}, renderInput(), icon, withDelete &&
|
|
201
|
+
}, renderInput(), icon, withDelete && /*#__PURE__*/_react.default.createElement("span", {
|
|
198
202
|
className: (0, _classnames.default)("input__close", {
|
|
199
203
|
hidden: !value
|
|
200
204
|
}),
|
|
@@ -34,20 +34,23 @@ var _default = {
|
|
|
34
34
|
error: {
|
|
35
35
|
description: 'text - coloring input if is errored'
|
|
36
36
|
},
|
|
37
|
+
isPriceInput: {
|
|
38
|
+
description: 'boolean - if true, the input will be styled as PriceInput'
|
|
39
|
+
},
|
|
37
40
|
withDelete: {
|
|
38
41
|
description: 'boolean - add clear-cross by hover'
|
|
39
42
|
},
|
|
40
|
-
|
|
41
|
-
description: 'boolean -
|
|
43
|
+
isOnlyNumber: {
|
|
44
|
+
description: 'boolean - only numbers'
|
|
42
45
|
},
|
|
43
|
-
|
|
44
|
-
description: '
|
|
46
|
+
isOnlyString: {
|
|
47
|
+
description: 'boolean - only strings'
|
|
45
48
|
},
|
|
46
|
-
|
|
47
|
-
description: '
|
|
49
|
+
isTwoDigitAfterDot: {
|
|
50
|
+
description: 'boolean - only two digits after dot'
|
|
48
51
|
},
|
|
49
|
-
|
|
50
|
-
description: '
|
|
52
|
+
isFocusDefault: {
|
|
53
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
51
54
|
},
|
|
52
55
|
placeholder: {
|
|
53
56
|
description: 'text'
|
|
@@ -102,22 +105,17 @@ var Template = function Template(args) {
|
|
|
102
105
|
var InputTemplate = Template.bind({});
|
|
103
106
|
exports.InputTemplate = InputTemplate;
|
|
104
107
|
InputTemplate.args = {
|
|
105
|
-
type: '
|
|
108
|
+
type: 'text',
|
|
109
|
+
isFocusDefault: false,
|
|
110
|
+
isOnlyNumber: false,
|
|
111
|
+
isOnlyString: false,
|
|
112
|
+
isPriceInput: false,
|
|
113
|
+
isTwoDigitAfterDot: false,
|
|
106
114
|
disabled: false,
|
|
107
115
|
error: '',
|
|
116
|
+
mask: '',
|
|
108
117
|
withDelete: true,
|
|
109
|
-
|
|
110
|
-
numStep: 1,
|
|
111
|
-
// min: '0',
|
|
112
|
-
// max: '5',
|
|
118
|
+
symbolsLimit: 255,
|
|
113
119
|
placeholder: 'Placeholder',
|
|
114
|
-
|
|
115
|
-
// maskChar: '_',
|
|
116
|
-
// formatChars: {
|
|
117
|
-
// 'n': '[0-9]',
|
|
118
|
-
// 's': '[A-Za-z]',
|
|
119
|
-
// '*': '[A-Za-z0-9]'
|
|
120
|
-
// },
|
|
121
|
-
icon: /*#__PURE__*/_react.default.createElement(_reactFeather.User, null),
|
|
122
|
-
symbolsLimit: 225
|
|
120
|
+
icon: /*#__PURE__*/_react.default.createElement(_reactFeather.User, null)
|
|
123
121
|
};
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
border: 1px solid var(--border-color);
|
|
206
206
|
border-radius: var(--border-radius);
|
|
207
207
|
background: #FFFFFF;
|
|
208
|
-
|
|
208
|
+
box-shadow: 0 4px 25px rgba(0, 0, 0, 0.25);
|
|
209
209
|
&_right-position-once-element {
|
|
210
210
|
justify-content: flex-end;
|
|
211
211
|
}
|
|
@@ -222,15 +222,15 @@
|
|
|
222
222
|
position: relative;
|
|
223
223
|
|
|
224
224
|
width: 100%;
|
|
225
|
-
padding:
|
|
225
|
+
padding: 0 20px 0 30px;
|
|
226
226
|
|
|
227
227
|
text-transform: capitalize;
|
|
228
228
|
white-space: nowrap;
|
|
229
229
|
font-style: normal;
|
|
230
230
|
font-weight: 300;
|
|
231
231
|
font-family: var(--font-family);
|
|
232
|
-
font-size:
|
|
233
|
-
line-height:
|
|
232
|
+
font-size: 12px;
|
|
233
|
+
line-height: 24px;
|
|
234
234
|
cursor: pointer;
|
|
235
235
|
|
|
236
236
|
display: flex;
|
|
@@ -242,6 +242,9 @@
|
|
|
242
242
|
// background-color: rgba(128, 128, 128, 0.1);
|
|
243
243
|
background-color: #F2F2F8;
|
|
244
244
|
}
|
|
245
|
+
&_active {
|
|
246
|
+
background: #f2f2f8;
|
|
247
|
+
}
|
|
245
248
|
|
|
246
249
|
&-icon-active {
|
|
247
250
|
position: absolute;
|
|
@@ -293,7 +296,7 @@
|
|
|
293
296
|
|
|
294
297
|
&>div:not(.date-picker__inputs-separator) {
|
|
295
298
|
width: 110px;
|
|
296
|
-
height: 100%;
|
|
299
|
+
min-height: 100%;
|
|
297
300
|
margin-right: 9px;
|
|
298
301
|
|
|
299
302
|
border: 1px solid var(--border-color);
|
|
@@ -323,6 +326,9 @@
|
|
|
323
326
|
.date-picker__inputs-separator {
|
|
324
327
|
margin-right: 9px;
|
|
325
328
|
}
|
|
329
|
+
input {
|
|
330
|
+
font-weight: 300;
|
|
331
|
+
}
|
|
326
332
|
}
|
|
327
333
|
|
|
328
334
|
&__date-input {
|
|
@@ -348,7 +354,7 @@
|
|
|
348
354
|
|
|
349
355
|
&>.dropdown__trigger {
|
|
350
356
|
width: 100%;
|
|
351
|
-
height:
|
|
357
|
+
height: 28px;
|
|
352
358
|
padding-left: 10px;
|
|
353
359
|
padding-right: 15px;
|
|
354
360
|
|
|
@@ -592,3 +598,27 @@
|
|
|
592
598
|
height: 100%;
|
|
593
599
|
}
|
|
594
600
|
}
|
|
601
|
+
|
|
602
|
+
@media screen and (max-width: 992px) {
|
|
603
|
+
.opened-part__intervals-list {
|
|
604
|
+
display: none;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
@media screen and (max-width: 745px) {
|
|
609
|
+
.date-picker__inputs-block {
|
|
610
|
+
flex-flow: wrap;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
.date-picker__header {
|
|
614
|
+
flex-flow: row wrap
|
|
615
|
+
}
|
|
616
|
+
.date-picker__calendars-wrapper {
|
|
617
|
+
display: block;
|
|
618
|
+
margin: auto;
|
|
619
|
+
}
|
|
620
|
+
.date-picker__calendars .range-calendar {
|
|
621
|
+
margin: 0!important;
|
|
622
|
+
width: 100%;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
+
|
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
+
|
|
20
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
21
|
+
|
|
22
|
+
var _reactFeather = require("react-feather");
|
|
23
|
+
|
|
24
|
+
var _reactInputMask = _interopRequireDefault(require("react-input-mask"));
|
|
25
|
+
|
|
26
|
+
var _index = require("../../../Constants/index.constants");
|
|
27
|
+
|
|
28
|
+
var _inputExecutor = require("../../../Functions/inputExecutor");
|
|
29
|
+
|
|
30
|
+
require("./NumericInput.scss");
|
|
31
|
+
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
39
|
+
|
|
40
|
+
var timerOutside;
|
|
41
|
+
var timerFocus;
|
|
42
|
+
|
|
43
|
+
var NumericInput = function NumericInput(_ref) {
|
|
44
|
+
var onChange = _ref.onChange,
|
|
45
|
+
disabled = _ref.disabled,
|
|
46
|
+
withDelete = _ref.withDelete,
|
|
47
|
+
_ref$numStep = _ref.numStep,
|
|
48
|
+
numStep = _ref$numStep === void 0 ? 1 : _ref$numStep,
|
|
49
|
+
_ref$min = _ref.min,
|
|
50
|
+
min = _ref$min === void 0 ? 0 : _ref$min,
|
|
51
|
+
max = _ref.max,
|
|
52
|
+
value = _ref.value,
|
|
53
|
+
placeholder = _ref.placeholder,
|
|
54
|
+
className = _ref.className,
|
|
55
|
+
onBlur = _ref.onBlur,
|
|
56
|
+
onFocus = _ref.onFocus,
|
|
57
|
+
onKeyUp = _ref.onKeyUp,
|
|
58
|
+
mask = _ref.mask,
|
|
59
|
+
maskChar = _ref.maskChar,
|
|
60
|
+
formatChars = _ref.formatChars,
|
|
61
|
+
error = _ref.error,
|
|
62
|
+
icon = _ref.icon,
|
|
63
|
+
symbolsLimit = _ref.symbolsLimit,
|
|
64
|
+
isNotBlinkErrors = _ref.isNotBlinkErrors,
|
|
65
|
+
blinkTime = _ref.blinkTime,
|
|
66
|
+
isPriceInput = _ref.isPriceInput,
|
|
67
|
+
_ref$isFocusDefault = _ref.isFocusDefault,
|
|
68
|
+
isFocusDefault = _ref$isFocusDefault === void 0 ? false : _ref$isFocusDefault;
|
|
69
|
+
var DEFAULT_BLINK_TIME = 200; //REFS
|
|
70
|
+
|
|
71
|
+
var inputRef = (0, _react.useRef)(null);
|
|
72
|
+
var decRef = (0, _react.useRef)(null);
|
|
73
|
+
var incRef = (0, _react.useRef)(null);
|
|
74
|
+
var wrapRef = (0, _react.useRef)(null);
|
|
75
|
+
var previousValueRef = (0, _react.useRef)(value); // STATES
|
|
76
|
+
|
|
77
|
+
var _useState = (0, _react.useState)(value || min || ''),
|
|
78
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
79
|
+
inputValue = _useState2[0],
|
|
80
|
+
setInputValue = _useState2[1];
|
|
81
|
+
|
|
82
|
+
var _useState3 = (0, _react.useState)(inputValue),
|
|
83
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
84
|
+
inputValueFormated = _useState4[0],
|
|
85
|
+
setInputValueFormated = _useState4[1];
|
|
86
|
+
|
|
87
|
+
var _useState5 = (0, _react.useState)(0),
|
|
88
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
89
|
+
intMemoVal = _useState6[0],
|
|
90
|
+
setIntMemoVal = _useState6[1];
|
|
91
|
+
|
|
92
|
+
var _useState7 = (0, _react.useState)(false),
|
|
93
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
94
|
+
isFocused = _useState8[0],
|
|
95
|
+
setIsFocused = _useState8[1];
|
|
96
|
+
|
|
97
|
+
var _useState9 = (0, _react.useState)(false),
|
|
98
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
99
|
+
isEditing = _useState10[0],
|
|
100
|
+
setEditing = _useState10[1];
|
|
101
|
+
|
|
102
|
+
var _useState11 = (0, _react.useState)(false),
|
|
103
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
104
|
+
isAttemptToChange = _useState12[0],
|
|
105
|
+
setIsAttemptToChange = _useState12[1];
|
|
106
|
+
|
|
107
|
+
var _useState13 = (0, _react.useState)(false),
|
|
108
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
109
|
+
isToHighlightError = _useState14[0],
|
|
110
|
+
setIsToHighlightError = _useState14[1];
|
|
111
|
+
|
|
112
|
+
var onlyNumbers = _inputExecutor.formatInput.onlyNumbers;
|
|
113
|
+
var _formatInput$priceInp = _inputExecutor.formatInput.priceInput,
|
|
114
|
+
addCommas = _formatInput$priceInp.addCommas,
|
|
115
|
+
removeComma = _formatInput$priceInp.removeComma; // HANDLES
|
|
116
|
+
|
|
117
|
+
var handle = {
|
|
118
|
+
change: function change(e) {
|
|
119
|
+
var inputValue = e.target ? onlyNumbers(e.target.value) : e;
|
|
120
|
+
|
|
121
|
+
if (inputValue && (decRef.current.contains(e.target) || incRef.current.contains(e.target))) {
|
|
122
|
+
inputValue = parseFloat(inputValue);
|
|
123
|
+
|
|
124
|
+
if (min && +min > inputValue) {
|
|
125
|
+
inputValue = min;
|
|
126
|
+
} else if (max && +max < inputValue) inputValue = max;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (symbolsLimit) {
|
|
130
|
+
inputValue = inputValue.toString().substring(0, +symbolsLimit);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setInputValue(inputValue.toString());
|
|
134
|
+
},
|
|
135
|
+
clear: function clear() {
|
|
136
|
+
handle.change(min || '');
|
|
137
|
+
},
|
|
138
|
+
focus: function focus(e) {
|
|
139
|
+
if (isFocused) return;
|
|
140
|
+
setIsFocused(true);
|
|
141
|
+
if (onFocus) onFocus(e);
|
|
142
|
+
},
|
|
143
|
+
blur: function blur(e) {
|
|
144
|
+
if (!isFocused) return;
|
|
145
|
+
setIsFocused(false);
|
|
146
|
+
setEditing(false);
|
|
147
|
+
if (onBlur) onBlur(e);
|
|
148
|
+
},
|
|
149
|
+
keyUp: function keyUp(e) {
|
|
150
|
+
if (!isNotBlinkErrors) {
|
|
151
|
+
var _previousValueRef$cur;
|
|
152
|
+
|
|
153
|
+
var changedValue = '' + (value !== null && value !== void 0 ? value : '');
|
|
154
|
+
var previousValue = '' + ((_previousValueRef$cur = previousValueRef.current) !== null && _previousValueRef$cur !== void 0 ? _previousValueRef$cur : '');
|
|
155
|
+
|
|
156
|
+
var currentSet = function () {
|
|
157
|
+
if (previousValue.length < changedValue.length) return value.toString().slice(previousValue.length - changedValue.length);else return changedValue.toString().includes(e.key) ? e.key : '';
|
|
158
|
+
}();
|
|
159
|
+
|
|
160
|
+
if (!_index.KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) setIsAttemptToChange(true);
|
|
161
|
+
if (_index.KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet) previousValueRef.current = value;else previousValueRef.current = previousValue + currentSet[0];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
|
|
165
|
+
},
|
|
166
|
+
decrement: function decrement(e) {
|
|
167
|
+
handle.change(intMemoVal - +numStep);
|
|
168
|
+
},
|
|
169
|
+
increment: function increment(e) {
|
|
170
|
+
handle.change(intMemoVal + +numStep);
|
|
171
|
+
}
|
|
172
|
+
}; //Check Outside Click
|
|
173
|
+
|
|
174
|
+
(0, _react.useEffect)(function () {
|
|
175
|
+
var handleClickOutside = function handleClickOutside(event) {
|
|
176
|
+
if (!wrapRef.current.contains(event.target)) {
|
|
177
|
+
setIsFocused(false);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
document.addEventListener('mousedown', handleClickOutside, true);
|
|
182
|
+
return function () {
|
|
183
|
+
return document.removeEventListener('mousedown', handleClickOutside, true);
|
|
184
|
+
};
|
|
185
|
+
}, []);
|
|
186
|
+
(0, _react.useEffect)(function () {
|
|
187
|
+
if (!isNotBlinkErrors && isAttemptToChange) {
|
|
188
|
+
setIsAttemptToChange(false);
|
|
189
|
+
setIsToHighlightError(true);
|
|
190
|
+
setTimeout(function () {
|
|
191
|
+
setIsToHighlightError(false);
|
|
192
|
+
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
193
|
+
}
|
|
194
|
+
}, [isAttemptToChange]); //On Input Value Change
|
|
195
|
+
|
|
196
|
+
(0, _react.useEffect)(function () {
|
|
197
|
+
if (inputValue !== value) setIsFocused(true);
|
|
198
|
+
setInputValueFormated(isPriceInput ? isFocused ? removeComma(inputValue) : addCommas(inputValue) : inputValue);
|
|
199
|
+
setIntMemoVal(parseInt(inputValue));
|
|
200
|
+
if (typeof onChange === 'function') onChange(inputValue === null || inputValue === void 0 ? void 0 : inputValue.toString());
|
|
201
|
+
}, [inputValue]); //On Integer Value Change
|
|
202
|
+
|
|
203
|
+
(0, _react.useEffect)(function () {
|
|
204
|
+
if (isNaN(intMemoVal)) setIntMemoVal(min || 0);
|
|
205
|
+
}, [intMemoVal]); //On Focuse Change
|
|
206
|
+
|
|
207
|
+
(0, _react.useEffect)(function () {
|
|
208
|
+
setInputValueFormated(isPriceInput ? isFocused ? removeComma(inputValue) : addCommas(inputValue) : inputValue);
|
|
209
|
+
|
|
210
|
+
if (isFocused) {
|
|
211
|
+
var _inputRef$current;
|
|
212
|
+
|
|
213
|
+
if (typeof onFocus === 'function') onFocus({
|
|
214
|
+
target: inputRef === null || inputRef === void 0 ? void 0 : inputRef.current
|
|
215
|
+
});
|
|
216
|
+
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
217
|
+
} else {
|
|
218
|
+
var _inputRef$current2;
|
|
219
|
+
|
|
220
|
+
if (typeof onBlur === 'function') onBlur({
|
|
221
|
+
target: inputRef === null || inputRef === void 0 ? void 0 : inputRef.current
|
|
222
|
+
});
|
|
223
|
+
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.blur();
|
|
224
|
+
}
|
|
225
|
+
}, [isFocused]);
|
|
226
|
+
(0, _react.useEffect)(function () {
|
|
227
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
228
|
+
}, [inputRef, isFocusDefault]);
|
|
229
|
+
|
|
230
|
+
function renderInput() {
|
|
231
|
+
var uniProps = _objectSpread(_objectSpread({
|
|
232
|
+
className: "input ".concat(className || ''),
|
|
233
|
+
placeholder: placeholder,
|
|
234
|
+
value: inputValueFormated,
|
|
235
|
+
disabled: disabled,
|
|
236
|
+
onChange: handle.change,
|
|
237
|
+
onFocus: function onFocus() {
|
|
238
|
+
setIsFocused(true);
|
|
239
|
+
setEditing(true);
|
|
240
|
+
},
|
|
241
|
+
onBlur: function onBlur() {
|
|
242
|
+
return setEditing(false);
|
|
243
|
+
},
|
|
244
|
+
onKeyUp: handle.keyUp,
|
|
245
|
+
min: min,
|
|
246
|
+
max: max
|
|
247
|
+
}, maskChar ? {
|
|
248
|
+
maskChar: maskChar
|
|
249
|
+
} : {}), formatChars ? {
|
|
250
|
+
formatChars: formatChars
|
|
251
|
+
} : {});
|
|
252
|
+
|
|
253
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, uniProps, {
|
|
254
|
+
ref: inputRef,
|
|
255
|
+
type: "text"
|
|
256
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
257
|
+
className: "input__nums"
|
|
258
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
259
|
+
ref: decRef,
|
|
260
|
+
onMouseDown: function onMouseDown(e) {
|
|
261
|
+
return handle.decrement(e);
|
|
262
|
+
},
|
|
263
|
+
className: (0, _classnames.default)("input__num-btn", {
|
|
264
|
+
disabled: +value <= min
|
|
265
|
+
})
|
|
266
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Minus, null)), /*#__PURE__*/_react.default.createElement("button", {
|
|
267
|
+
ref: incRef,
|
|
268
|
+
onMouseDown: function onMouseDown(e) {
|
|
269
|
+
return handle.increment(e);
|
|
270
|
+
},
|
|
271
|
+
className: (0, _classnames.default)("input__num-btn", {
|
|
272
|
+
disabled: +value >= max
|
|
273
|
+
})
|
|
274
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Plus, null))));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
278
|
+
ref: wrapRef,
|
|
279
|
+
className: (0, _classnames.default)("input__wrap", (0, _defineProperty2.default)({}, "input__wrap_focus", isFocused), (0, _defineProperty2.default)({}, "input__wrap_error", error || isToHighlightError), (0, _defineProperty2.default)({}, "input__wrap_disabled", disabled))
|
|
280
|
+
}, renderInput(), icon, withDelete && /*#__PURE__*/_react.default.createElement("span", {
|
|
281
|
+
className: (0, _classnames.default)("input__close", {
|
|
282
|
+
hidden: !inputValue
|
|
283
|
+
}),
|
|
284
|
+
onClick: function onClick() {
|
|
285
|
+
return handle.clear();
|
|
286
|
+
}
|
|
287
|
+
}));
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
var _default = NumericInput;
|
|
291
|
+
exports.default = _default;
|