intelicoreact 0.0.79 → 0.0.84
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 +12 -8
- package/dist/Atomic/FormElements/Input/Input.stories.js +4 -0
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +20 -12
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +4 -11
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.scss +2 -4
- package/dist/Atomic/FormElements/NumericInput/NumericInput.js +124 -87
- package/dist/Atomic/FormElements/NumericInput/NumericInput.stories.js +6 -10
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +3 -1
- package/dist/Atomic/UI/Calendar/Calendar.js +4 -2
- package/dist/Atomic/UI/Calendar/Calendar.scss +5 -1
- package/dist/Functions/inputExecutor.js +1 -1
- package/package.json +2 -2
- package/src/Atomic/FormElements/Input/Input.js +13 -9
- package/src/Atomic/FormElements/Input/Input.stories.js +4 -0
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +13 -11
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +5 -10
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.scss +2 -4
- package/src/Atomic/FormElements/NumericInput/NumericInput.js +106 -64
- package/src/Atomic/FormElements/NumericInput/NumericInput.stories.js +6 -22
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +1 -1
- package/src/Atomic/UI/Calendar/Calendar.js +1 -1
- package/src/Atomic/UI/Calendar/Calendar.scss +5 -1
- package/src/Functions/inputExecutor.js +6 -15
|
@@ -58,7 +58,9 @@ var Input = function Input(_ref) {
|
|
|
58
58
|
error = _ref.error,
|
|
59
59
|
icon = _ref.icon,
|
|
60
60
|
symbolsLimit = _ref.symbolsLimit,
|
|
61
|
-
blinkTime = _ref.blinkTime
|
|
61
|
+
blinkTime = _ref.blinkTime,
|
|
62
|
+
_ref$isFocusDefault = _ref.isFocusDefault,
|
|
63
|
+
isFocusDefault = _ref$isFocusDefault === void 0 ? false : _ref$isFocusDefault;
|
|
62
64
|
var DEFAULT_BLINK_TIME = 100; // STATES
|
|
63
65
|
|
|
64
66
|
var _useState = (0, _react.useState)(false),
|
|
@@ -109,19 +111,19 @@ var Input = function Input(_ref) {
|
|
|
109
111
|
},
|
|
110
112
|
focus: function focus(e) {
|
|
111
113
|
setIsFocused(true);
|
|
112
|
-
if (isPriceInput && isOnlyNumber
|
|
114
|
+
if (isPriceInput && isOnlyNumber) onChange(removeComma(value));
|
|
113
115
|
if (onFocus) onFocus(e);
|
|
114
116
|
},
|
|
115
117
|
blur: function blur(e) {
|
|
116
118
|
setIsFocused(false);
|
|
117
119
|
setEditing(false);
|
|
118
120
|
|
|
119
|
-
if (
|
|
120
|
-
onChange(
|
|
121
|
+
if (isTwoDigitAfterDot) {
|
|
122
|
+
onChange(cutOffsingleDot(value));
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
if (
|
|
124
|
-
onChange(
|
|
125
|
+
if (isPriceInput && isOnlyNumber) {
|
|
126
|
+
onChange(addCommas(value));
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
if (onBlur) onBlur(e);
|
|
@@ -138,7 +140,6 @@ var Input = function Input(_ref) {
|
|
|
138
140
|
}();
|
|
139
141
|
|
|
140
142
|
if (!_index.KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) setIsAttemptToChange(true);
|
|
141
|
-
console.log(changedValue, previousValue);
|
|
142
143
|
if (_index.KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet) previousValueRef.current = value;else previousValueRef.current = previousValue + currentSet[0];
|
|
143
144
|
}
|
|
144
145
|
|
|
@@ -147,7 +148,7 @@ var Input = function Input(_ref) {
|
|
|
147
148
|
};
|
|
148
149
|
|
|
149
150
|
function cutOffsingleDot(value) {
|
|
150
|
-
return value.slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
151
|
+
return value.toString().slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
(0, _react.useEffect)(function () {
|
|
@@ -192,6 +193,9 @@ 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
201
|
}, renderInput(), icon, withDelete && /*#__PURE__*/_react.default.createElement("span", {
|
|
@@ -49,6 +49,9 @@ var _default = {
|
|
|
49
49
|
isTwoDigitAfterDot: {
|
|
50
50
|
description: 'boolean - only two digits after dot'
|
|
51
51
|
},
|
|
52
|
+
isFocusDefault: {
|
|
53
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
54
|
+
},
|
|
52
55
|
placeholder: {
|
|
53
56
|
description: 'text'
|
|
54
57
|
},
|
|
@@ -103,6 +106,7 @@ var InputTemplate = Template.bind({});
|
|
|
103
106
|
exports.InputTemplate = InputTemplate;
|
|
104
107
|
InputTemplate.args = {
|
|
105
108
|
type: 'text',
|
|
109
|
+
isFocusDefault: false,
|
|
106
110
|
isOnlyNumber: false,
|
|
107
111
|
isOnlyString: false,
|
|
108
112
|
isPriceInput: false,
|
|
@@ -26,10 +26,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
26
26
|
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; }
|
|
27
27
|
|
|
28
28
|
var InputCalendar = function InputCalendar(_ref) {
|
|
29
|
-
var
|
|
30
|
-
|
|
29
|
+
var value = _ref.value,
|
|
30
|
+
minDate = _ref.minDate,
|
|
31
|
+
maxDate = _ref.maxDate,
|
|
32
|
+
onChange = _ref.onChange;
|
|
31
33
|
|
|
32
|
-
var _useState = (0, _react.useState)(
|
|
34
|
+
var _useState = (0, _react.useState)(value),
|
|
33
35
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
34
36
|
date = _useState2[0],
|
|
35
37
|
setDate = _useState2[1];
|
|
@@ -49,18 +51,21 @@ var InputCalendar = function InputCalendar(_ref) {
|
|
|
49
51
|
return setIsOpened(false);
|
|
50
52
|
});
|
|
51
53
|
|
|
52
|
-
var changeInputValue = function changeInputValue(
|
|
53
|
-
if (!
|
|
54
|
-
setDate((0, _moment.default)(
|
|
55
|
-
setInputValue((0, _moment.default)(
|
|
54
|
+
var changeInputValue = function changeInputValue(val) {
|
|
55
|
+
if (!val.includes('_') && val) {
|
|
56
|
+
setDate((0, _moment.default)(val).format('L'));
|
|
57
|
+
setInputValue((0, _moment.default)(val).format('L'));
|
|
56
58
|
} else {
|
|
57
|
-
setInputValue(
|
|
59
|
+
setInputValue(val);
|
|
58
60
|
}
|
|
61
|
+
|
|
62
|
+
if (onChange) onChange();
|
|
59
63
|
};
|
|
60
64
|
|
|
61
|
-
var changeCalendarDay = function changeCalendarDay(
|
|
62
|
-
setDate(
|
|
63
|
-
setInputValue(
|
|
65
|
+
var changeCalendarDay = function changeCalendarDay(val) {
|
|
66
|
+
setDate(val);
|
|
67
|
+
setInputValue(val);
|
|
68
|
+
if (onChange) onChange(val);
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -81,7 +86,10 @@ var InputCalendar = function InputCalendar(_ref) {
|
|
|
81
86
|
setDate: function setDate(newDate) {
|
|
82
87
|
return changeCalendarDay(newDate);
|
|
83
88
|
},
|
|
84
|
-
params:
|
|
89
|
+
params: {
|
|
90
|
+
minDate: minDate,
|
|
91
|
+
maxDate: maxDate
|
|
92
|
+
}
|
|
85
93
|
}) : null);
|
|
86
94
|
};
|
|
87
95
|
|
|
@@ -27,20 +27,13 @@ var _default = {
|
|
|
27
27
|
exports.default = _default;
|
|
28
28
|
|
|
29
29
|
var Template = function Template(args) {
|
|
30
|
-
|
|
31
|
-
minDate: args === null || args === void 0 ? void 0 : args.minDate,
|
|
32
|
-
maxDate: args === null || args === void 0 ? void 0 : args.maxDate
|
|
33
|
-
};
|
|
34
|
-
return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, {
|
|
35
|
-
data: args.date,
|
|
36
|
-
params: params
|
|
37
|
-
});
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, args);
|
|
38
31
|
};
|
|
39
32
|
|
|
40
33
|
var Calendar = Template.bind({});
|
|
41
34
|
exports.Calendar = Calendar;
|
|
42
35
|
Calendar.args = {
|
|
43
|
-
|
|
44
|
-
minDate: '10/
|
|
45
|
-
maxDate: '10/
|
|
36
|
+
value: '10/14/2021',
|
|
37
|
+
minDate: '10/14/2020',
|
|
38
|
+
maxDate: '10/14/2023'
|
|
46
39
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
@import "~anme/scss/anme-mixins-media";
|
|
2
|
-
|
|
3
1
|
:root {
|
|
4
2
|
--input-height: 28px;
|
|
5
3
|
--label-line-height: 16px;
|
|
@@ -601,13 +599,13 @@
|
|
|
601
599
|
}
|
|
602
600
|
}
|
|
603
601
|
|
|
604
|
-
@
|
|
602
|
+
@media screen and (max-width: 992px) {
|
|
605
603
|
.opened-part__intervals-list {
|
|
606
604
|
display: none;
|
|
607
605
|
}
|
|
608
606
|
}
|
|
609
607
|
|
|
610
|
-
@
|
|
608
|
+
@media screen and (max-width: 745px) {
|
|
611
609
|
.date-picker__inputs-block {
|
|
612
610
|
flex-flow: wrap;
|
|
613
611
|
}
|
|
@@ -37,6 +37,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
37
37
|
|
|
38
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
39
|
|
|
40
|
+
var timerOutside;
|
|
41
|
+
var timerFocus;
|
|
42
|
+
|
|
40
43
|
var NumericInput = function NumericInput(_ref) {
|
|
41
44
|
var onChange = _ref.onChange,
|
|
42
45
|
disabled = _ref.disabled,
|
|
@@ -49,8 +52,6 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
49
52
|
value = _ref.value,
|
|
50
53
|
placeholder = _ref.placeholder,
|
|
51
54
|
className = _ref.className,
|
|
52
|
-
_ref$type = _ref.type,
|
|
53
|
-
type = _ref$type === void 0 ? 'number' : _ref$type,
|
|
54
55
|
onBlur = _ref.onBlur,
|
|
55
56
|
onFocus = _ref.onFocus,
|
|
56
57
|
onKeyUp = _ref.onKeyUp,
|
|
@@ -62,38 +63,51 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
62
63
|
symbolsLimit = _ref.symbolsLimit,
|
|
63
64
|
isNotBlinkErrors = _ref.isNotBlinkErrors,
|
|
64
65
|
blinkTime = _ref.blinkTime,
|
|
65
|
-
isPriceInput = _ref.isPriceInput
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var
|
|
69
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
70
|
-
isFocused = _useState2[0],
|
|
71
|
-
setIsFocused = _useState2[1];
|
|
72
|
-
|
|
73
|
-
var _useState3 = (0, _react.useState)(false),
|
|
74
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
75
|
-
isEditing = _useState4[0],
|
|
76
|
-
setEditing = _useState4[1];
|
|
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
|
|
77
70
|
|
|
78
71
|
var inputRef = (0, _react.useRef)(null);
|
|
79
72
|
var decRef = (0, _react.useRef)(null);
|
|
80
73
|
var incRef = (0, _react.useRef)(null);
|
|
81
|
-
var
|
|
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];
|
|
82
86
|
|
|
83
|
-
var _useState5 = (0, _react.useState)(
|
|
87
|
+
var _useState5 = (0, _react.useState)(0),
|
|
84
88
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
intMemoVal = _useState6[0],
|
|
90
|
+
setIntMemoVal = _useState6[1];
|
|
87
91
|
|
|
88
92
|
var _useState7 = (0, _react.useState)(false),
|
|
89
93
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
isFocused = _useState8[0],
|
|
95
|
+
setIsFocused = _useState8[1];
|
|
92
96
|
|
|
93
|
-
var _useState9 = (0, _react.useState)(
|
|
97
|
+
var _useState9 = (0, _react.useState)(false),
|
|
94
98
|
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
95
|
-
|
|
96
|
-
|
|
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];
|
|
97
111
|
|
|
98
112
|
var onlyNumbers = _inputExecutor.formatInput.onlyNumbers;
|
|
99
113
|
var _formatInput$priceInp = _inputExecutor.formatInput.priceInput,
|
|
@@ -104,8 +118,8 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
104
118
|
change: function change(e) {
|
|
105
119
|
var inputValue = e.target ? onlyNumbers(e.target.value) : e;
|
|
106
120
|
|
|
107
|
-
if (inputValue
|
|
108
|
-
inputValue = parseFloat(inputValue)
|
|
121
|
+
if (inputValue && (decRef.current.contains(e.target) || incRef.current.contains(e.target))) {
|
|
122
|
+
inputValue = parseFloat(inputValue);
|
|
109
123
|
|
|
110
124
|
if (min && +min > inputValue) {
|
|
111
125
|
inputValue = min;
|
|
@@ -116,37 +130,27 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
116
130
|
inputValue = inputValue.toString().substring(0, +symbolsLimit);
|
|
117
131
|
}
|
|
118
132
|
|
|
119
|
-
|
|
120
|
-
onChange(inputValue.toString());
|
|
133
|
+
setInputValue(inputValue.toString());
|
|
121
134
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
onChange('');
|
|
135
|
+
clear: function clear() {
|
|
136
|
+
handle.change(min || '');
|
|
125
137
|
},
|
|
126
138
|
focus: function focus(e) {
|
|
139
|
+
if (isFocused) return;
|
|
127
140
|
setIsFocused(true);
|
|
128
|
-
if (isPriceInput) onChange(removeComma(value));
|
|
129
141
|
if (onFocus) onFocus(e);
|
|
130
142
|
},
|
|
131
143
|
blur: function blur(e) {
|
|
144
|
+
if (!isFocused) return;
|
|
132
145
|
setIsFocused(false);
|
|
133
146
|
setEditing(false);
|
|
134
|
-
|
|
135
|
-
if (isPriceInput) {
|
|
136
|
-
if (!isFinite(value)) {
|
|
137
|
-
value = intMemoVal;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
onChange(addCommas(value));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
147
|
if (onBlur) onBlur(e);
|
|
144
148
|
},
|
|
145
149
|
keyUp: function keyUp(e) {
|
|
146
150
|
if (!isNotBlinkErrors) {
|
|
147
|
-
var
|
|
151
|
+
var _previousValueRef$cur;
|
|
148
152
|
|
|
149
|
-
var changedValue = '' + (
|
|
153
|
+
var changedValue = '' + (value !== null && value !== void 0 ? value : '');
|
|
150
154
|
var previousValue = '' + ((_previousValueRef$cur = previousValueRef.current) !== null && _previousValueRef$cur !== void 0 ? _previousValueRef$cur : '');
|
|
151
155
|
|
|
152
156
|
var currentSet = function () {
|
|
@@ -159,23 +163,26 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
159
163
|
|
|
160
164
|
if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
|
|
161
165
|
},
|
|
162
|
-
decrement: function decrement() {
|
|
166
|
+
decrement: function decrement(e) {
|
|
163
167
|
handle.change(intMemoVal - +numStep);
|
|
164
168
|
},
|
|
165
|
-
increment: function increment() {
|
|
169
|
+
increment: function increment(e) {
|
|
166
170
|
handle.change(intMemoVal + +numStep);
|
|
167
171
|
}
|
|
168
|
-
};
|
|
172
|
+
}; //Check Outside Click
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
};
|
|
174
|
+
(0, _react.useEffect)(function () {
|
|
175
|
+
var handleClickOutside = function handleClickOutside(event) {
|
|
176
|
+
if (!wrapRef.current.contains(event.target)) {
|
|
177
|
+
setIsFocused(false);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
178
180
|
|
|
181
|
+
document.addEventListener('mousedown', handleClickOutside, true);
|
|
182
|
+
return function () {
|
|
183
|
+
return document.removeEventListener('mousedown', handleClickOutside, true);
|
|
184
|
+
};
|
|
185
|
+
}, []);
|
|
179
186
|
(0, _react.useEffect)(function () {
|
|
180
187
|
if (!isNotBlinkErrors && isAttemptToChange) {
|
|
181
188
|
setIsAttemptToChange(false);
|
|
@@ -184,55 +191,82 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
184
191
|
setIsToHighlightError(false);
|
|
185
192
|
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
186
193
|
}
|
|
187
|
-
}, [isAttemptToChange]);
|
|
194
|
+
}, [isAttemptToChange]); //On Input Value Change
|
|
195
|
+
|
|
188
196
|
(0, _react.useEffect)(function () {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}, []);
|
|
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
|
+
|
|
194
207
|
(0, _react.useEffect)(function () {
|
|
195
|
-
|
|
196
|
-
|
|
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]);
|
|
197
226
|
(0, _react.useEffect)(function () {
|
|
198
|
-
if (
|
|
199
|
-
}, [
|
|
200
|
-
|
|
201
|
-
var uniProps = _objectSpread(_objectSpread({
|
|
202
|
-
className: "input ".concat(className),
|
|
203
|
-
placeholder: placeholder,
|
|
204
|
-
value: value || '',
|
|
205
|
-
disabled: disabled,
|
|
206
|
-
onChange: handle.change,
|
|
207
|
-
onFocus: handle.focus,
|
|
208
|
-
onBlur: handle.blur,
|
|
209
|
-
onKeyUp: handle.keyUp,
|
|
210
|
-
min: min,
|
|
211
|
-
max: max
|
|
212
|
-
}, maskChar ? {
|
|
213
|
-
maskChar: maskChar
|
|
214
|
-
} : {}), formatChars ? {
|
|
215
|
-
formatChars: formatChars
|
|
216
|
-
} : {});
|
|
227
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
228
|
+
}, [inputRef, isFocusDefault]);
|
|
217
229
|
|
|
218
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
|
+
|
|
219
253
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, uniProps, {
|
|
220
254
|
ref: inputRef,
|
|
221
|
-
type:
|
|
255
|
+
type: "text"
|
|
222
256
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
223
257
|
className: "input__nums"
|
|
224
258
|
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
225
259
|
ref: decRef,
|
|
226
|
-
|
|
227
|
-
return handle.decrement();
|
|
260
|
+
onMouseDown: function onMouseDown(e) {
|
|
261
|
+
return handle.decrement(e);
|
|
228
262
|
},
|
|
229
263
|
className: (0, _classnames.default)("input__num-btn", {
|
|
230
264
|
disabled: +value <= min
|
|
231
265
|
})
|
|
232
266
|
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Minus, null)), /*#__PURE__*/_react.default.createElement("button", {
|
|
233
267
|
ref: incRef,
|
|
234
|
-
|
|
235
|
-
return handle.increment();
|
|
268
|
+
onMouseDown: function onMouseDown(e) {
|
|
269
|
+
return handle.increment(e);
|
|
236
270
|
},
|
|
237
271
|
className: (0, _classnames.default)("input__num-btn", {
|
|
238
272
|
disabled: +value >= max
|
|
@@ -241,12 +275,15 @@ var NumericInput = function NumericInput(_ref) {
|
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
278
|
+
ref: wrapRef,
|
|
244
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))
|
|
245
280
|
}, renderInput(), icon, withDelete && /*#__PURE__*/_react.default.createElement("span", {
|
|
246
281
|
className: (0, _classnames.default)("input__close", {
|
|
247
|
-
hidden: !
|
|
282
|
+
hidden: !inputValue
|
|
248
283
|
}),
|
|
249
|
-
onClick:
|
|
284
|
+
onClick: function onClick() {
|
|
285
|
+
return handle.clear();
|
|
286
|
+
}
|
|
250
287
|
}));
|
|
251
288
|
};
|
|
252
289
|
|
|
@@ -31,6 +31,9 @@ var _default = {
|
|
|
31
31
|
disabled: {
|
|
32
32
|
description: 'boolean'
|
|
33
33
|
},
|
|
34
|
+
isFocusDefault: {
|
|
35
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
36
|
+
},
|
|
34
37
|
isInitialFocus: {
|
|
35
38
|
description: 'boolean - if true, the input will be focused on mount'
|
|
36
39
|
},
|
|
@@ -55,13 +58,6 @@ var _default = {
|
|
|
55
58
|
placeholder: {
|
|
56
59
|
description: 'text'
|
|
57
60
|
},
|
|
58
|
-
type: {
|
|
59
|
-
description: "'text', 'number', 'password', 'color', 'date', 'datetime-local', 'month', 'time', 'email', 'range'",
|
|
60
|
-
control: {
|
|
61
|
-
type: 'select',
|
|
62
|
-
options: ['text', 'number', 'password', 'color', 'date', 'datetime-local', 'month', 'time', 'email', 'range']
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
61
|
icon: {
|
|
66
62
|
description: 'JSX'
|
|
67
63
|
},
|
|
@@ -91,7 +87,7 @@ var _default = {
|
|
|
91
87
|
exports.default = _default;
|
|
92
88
|
|
|
93
89
|
var Template = function Template(args) {
|
|
94
|
-
var _useState = (0, _react.useState)(''),
|
|
90
|
+
var _useState = (0, _react.useState)('15000'),
|
|
95
91
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
96
92
|
value = _useState2[0],
|
|
97
93
|
setValue = _useState2[1];
|
|
@@ -105,8 +101,8 @@ var Template = function Template(args) {
|
|
|
105
101
|
var NumericInputTemplate = Template.bind({});
|
|
106
102
|
exports.NumericInputTemplate = NumericInputTemplate;
|
|
107
103
|
NumericInputTemplate.args = {
|
|
108
|
-
type: 'text',
|
|
109
104
|
disabled: false,
|
|
105
|
+
isFocusDefault: false,
|
|
110
106
|
error: '',
|
|
111
107
|
isPriceInput: false,
|
|
112
108
|
mask: '',
|
|
@@ -115,7 +111,7 @@ NumericInputTemplate.args = {
|
|
|
115
111
|
numStep: 100,
|
|
116
112
|
min: '0',
|
|
117
113
|
max: '15000',
|
|
118
|
-
symbolsLimit:
|
|
114
|
+
symbolsLimit: 5,
|
|
119
115
|
placeholder: 'Placeholder',
|
|
120
116
|
icon: /*#__PURE__*/_react.default.createElement(_reactFeather.User, null)
|
|
121
117
|
};
|
|
@@ -115,7 +115,9 @@ var RangeCalendar = function RangeCalendar(props) {
|
|
|
115
115
|
onMouseLeave: function onMouseLeave() {
|
|
116
116
|
return onHover(null);
|
|
117
117
|
}
|
|
118
|
-
},
|
|
118
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
119
|
+
className: "calendar__day-num"
|
|
120
|
+
}, day && day.date.getDate()));
|
|
119
121
|
};
|
|
120
122
|
|
|
121
123
|
var handlePrev = function handlePrev() {
|
|
@@ -36,8 +36,10 @@ function _default(props) {
|
|
|
36
36
|
allowNext = _props$allowNext === void 0 ? true : _props$allowNext,
|
|
37
37
|
params = props.params,
|
|
38
38
|
className = props.className;
|
|
39
|
-
var minDate = params.minDate,
|
|
40
|
-
|
|
39
|
+
var _params$minDate = params.minDate,
|
|
40
|
+
minDate = _params$minDate === void 0 ? '01/01/1900' : _params$minDate,
|
|
41
|
+
_params$maxDate = params.maxDate,
|
|
42
|
+
maxDate = _params$maxDate === void 0 ? (0, _moment.default)().format('MM/DD/YYYY') : _params$maxDate;
|
|
41
43
|
|
|
42
44
|
var _useState = (0, _react.useState)({}),
|
|
43
45
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -425,7 +425,11 @@
|
|
|
425
425
|
// box-shadow: 0 0 3px 0 rgb(0 123 255 / 50%);
|
|
426
426
|
// }
|
|
427
427
|
// }
|
|
428
|
-
|
|
428
|
+
.calendar-header {
|
|
429
|
+
display: flex;
|
|
430
|
+
justify-content: center;
|
|
431
|
+
align-items: center;
|
|
432
|
+
}
|
|
429
433
|
.calendar {
|
|
430
434
|
background: #ffffff;
|
|
431
435
|
border: 1px solid #e2e5ec;
|
|
@@ -21,7 +21,7 @@ var formatInput = {
|
|
|
21
21
|
return isFraction ? intPart + value.slice(value.indexOf('.')) : intPart;
|
|
22
22
|
},
|
|
23
23
|
removeComma: function removeComma(value) {
|
|
24
|
-
return
|
|
24
|
+
return parseInt(value.toString().replace(/\,/g, ''));
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
onlyNumbers: function onlyNumbers(value) {
|
package/package.json
CHANGED
|
@@ -28,7 +28,8 @@ const Input = ({
|
|
|
28
28
|
error,
|
|
29
29
|
icon,
|
|
30
30
|
symbolsLimit,
|
|
31
|
-
blinkTime
|
|
31
|
+
blinkTime,
|
|
32
|
+
isFocusDefault = false
|
|
32
33
|
}) => {
|
|
33
34
|
const DEFAULT_BLINK_TIME = 100;
|
|
34
35
|
// STATES
|
|
@@ -62,20 +63,19 @@ const Input = ({
|
|
|
62
63
|
},
|
|
63
64
|
focus: (e) => {
|
|
64
65
|
setIsFocused(true);
|
|
65
|
-
if (isPriceInput && isOnlyNumber
|
|
66
|
-
onChange(removeComma(value));
|
|
66
|
+
if (isPriceInput && isOnlyNumber) onChange(removeComma(value));
|
|
67
67
|
|
|
68
68
|
if (onFocus) onFocus(e);
|
|
69
69
|
},
|
|
70
70
|
blur: (e) => {
|
|
71
71
|
setIsFocused(false);
|
|
72
72
|
setEditing(false);
|
|
73
|
-
if (
|
|
74
|
-
onChange(addCommas(value));
|
|
75
|
-
}
|
|
76
|
-
if (isTwoDigitAfterDot && !isPriceInput) {
|
|
73
|
+
if (isTwoDigitAfterDot) {
|
|
77
74
|
onChange(cutOffsingleDot(value));
|
|
78
75
|
}
|
|
76
|
+
if (isPriceInput && isOnlyNumber) {
|
|
77
|
+
onChange(addCommas(value));
|
|
78
|
+
}
|
|
79
79
|
if (onBlur) onBlur(e);
|
|
80
80
|
},
|
|
81
81
|
keyUp: (e) => {
|
|
@@ -94,7 +94,6 @@ const Input = ({
|
|
|
94
94
|
)
|
|
95
95
|
setIsAttemptToChange(true);
|
|
96
96
|
|
|
97
|
-
console.log(changedValue, previousValue);
|
|
98
97
|
if (KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet)
|
|
99
98
|
previousValueRef.current = value;
|
|
100
99
|
else previousValueRef.current = previousValue + currentSet[0];
|
|
@@ -105,7 +104,7 @@ const Input = ({
|
|
|
105
104
|
};
|
|
106
105
|
|
|
107
106
|
function cutOffsingleDot(value) {
|
|
108
|
-
return value.slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
107
|
+
return value.toString().slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
useEffect(() => {
|
|
@@ -145,6 +144,11 @@ const Input = ({
|
|
|
145
144
|
}
|
|
146
145
|
}, [isAttemptToChange]);
|
|
147
146
|
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (inputRef?.current && typeof isFocusDefault === 'boolean')
|
|
149
|
+
setIsFocused(isFocusDefault);
|
|
150
|
+
}, [inputRef, isFocusDefault]);
|
|
151
|
+
|
|
148
152
|
return (
|
|
149
153
|
<div
|
|
150
154
|
className={cn(
|
|
@@ -29,6 +29,9 @@ export default {
|
|
|
29
29
|
isTwoDigitAfterDot: {
|
|
30
30
|
description: 'boolean - only two digits after dot'
|
|
31
31
|
},
|
|
32
|
+
isFocusDefault: {
|
|
33
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
34
|
+
},
|
|
32
35
|
placeholder: {
|
|
33
36
|
description: 'text'
|
|
34
37
|
},
|
|
@@ -76,6 +79,7 @@ export const InputTemplate = Template.bind({});
|
|
|
76
79
|
|
|
77
80
|
InputTemplate.args = {
|
|
78
81
|
type: 'text',
|
|
82
|
+
isFocusDefault: false,
|
|
79
83
|
isOnlyNumber: false,
|
|
80
84
|
isOnlyString: false,
|
|
81
85
|
isPriceInput: false,
|
|
@@ -4,26 +4,28 @@ import InputMask from 'react-input-mask';
|
|
|
4
4
|
import Calendar from '../../UI/Calendar/Calendar';
|
|
5
5
|
import { useClickOutside } from '../../../Functions/useClickOutside';
|
|
6
6
|
|
|
7
|
-
const InputCalendar = ({
|
|
8
|
-
const [date, setDate] = useState(
|
|
7
|
+
const InputCalendar = ({ value, minDate, maxDate, onChange }) => {
|
|
8
|
+
const [date, setDate] = useState(value);
|
|
9
9
|
const [inputValue, setInputValue] = useState(date);
|
|
10
10
|
const [isOpened, setIsOpened] = useState(false);
|
|
11
11
|
const calendarRef = useRef(null);
|
|
12
12
|
|
|
13
13
|
useClickOutside(calendarRef, () => setIsOpened(false));
|
|
14
14
|
|
|
15
|
-
const changeInputValue =
|
|
16
|
-
if (!
|
|
17
|
-
setDate(moment(
|
|
18
|
-
setInputValue(moment(
|
|
15
|
+
const changeInputValue = val => {
|
|
16
|
+
if (!val.includes('_') && val) {
|
|
17
|
+
setDate(moment(val).format('L'));
|
|
18
|
+
setInputValue(moment(val).format('L'));
|
|
19
19
|
} else {
|
|
20
|
-
setInputValue(
|
|
20
|
+
setInputValue(val);
|
|
21
21
|
}
|
|
22
|
+
if(onChange) onChange();
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
const changeCalendarDay =
|
|
25
|
-
setDate(
|
|
26
|
-
setInputValue(
|
|
25
|
+
const changeCalendarDay = val => {
|
|
26
|
+
setDate(val);
|
|
27
|
+
setInputValue(val);
|
|
28
|
+
if (onChange) onChange(val);
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
return (
|
|
@@ -35,7 +37,7 @@ const InputCalendar = ({ data, params }) => {
|
|
|
35
37
|
className="calendar-dropdown"
|
|
36
38
|
onFocus={() => setIsOpened(!isOpened)}
|
|
37
39
|
/>
|
|
38
|
-
{isOpened ? <Calendar date={date} setDate={
|
|
40
|
+
{isOpened ? <Calendar date={date} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
|
|
39
41
|
</div>
|
|
40
42
|
);
|
|
41
43
|
};
|
|
@@ -9,19 +9,14 @@ export default {
|
|
|
9
9
|
component: InputCalendar,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const Template =
|
|
13
|
-
|
|
14
|
-
minDate: args?.minDate,
|
|
15
|
-
maxDate: args?.maxDate,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return <InputCalendar data={args.date} params={params} />;
|
|
12
|
+
const Template = args => {
|
|
13
|
+
return <InputCalendar {...args} />;
|
|
19
14
|
};
|
|
20
15
|
|
|
21
16
|
export const Calendar = Template.bind({});
|
|
22
17
|
|
|
23
18
|
Calendar.args = {
|
|
24
|
-
|
|
25
|
-
minDate: '10/
|
|
26
|
-
maxDate: '10/
|
|
19
|
+
value: '10/14/2021',
|
|
20
|
+
minDate: '10/14/2020',
|
|
21
|
+
maxDate: '10/14/2023',
|
|
27
22
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
@import "~anme/scss/anme-mixins-media";
|
|
2
|
-
|
|
3
1
|
:root {
|
|
4
2
|
--input-height: 28px;
|
|
5
3
|
--label-line-height: 16px;
|
|
@@ -601,13 +599,13 @@
|
|
|
601
599
|
}
|
|
602
600
|
}
|
|
603
601
|
|
|
604
|
-
@
|
|
602
|
+
@media screen and (max-width: 992px) {
|
|
605
603
|
.opened-part__intervals-list {
|
|
606
604
|
display: none;
|
|
607
605
|
}
|
|
608
606
|
}
|
|
609
607
|
|
|
610
|
-
@
|
|
608
|
+
@media screen and (max-width: 745px) {
|
|
611
609
|
.date-picker__inputs-block {
|
|
612
610
|
flex-flow: wrap;
|
|
613
611
|
}
|
|
@@ -7,6 +7,9 @@ import { formatInput } from '../../../Functions/inputExecutor';
|
|
|
7
7
|
|
|
8
8
|
import './NumericInput.scss';
|
|
9
9
|
|
|
10
|
+
let timerOutside;
|
|
11
|
+
let timerFocus;
|
|
12
|
+
|
|
10
13
|
const NumericInput = ({
|
|
11
14
|
onChange,
|
|
12
15
|
disabled,
|
|
@@ -17,7 +20,6 @@ const NumericInput = ({
|
|
|
17
20
|
value,
|
|
18
21
|
placeholder,
|
|
19
22
|
className,
|
|
20
|
-
type = 'number',
|
|
21
23
|
onBlur,
|
|
22
24
|
onFocus,
|
|
23
25
|
onKeyUp,
|
|
@@ -29,21 +31,30 @@ const NumericInput = ({
|
|
|
29
31
|
symbolsLimit,
|
|
30
32
|
isNotBlinkErrors,
|
|
31
33
|
blinkTime,
|
|
32
|
-
isPriceInput
|
|
34
|
+
isPriceInput,
|
|
35
|
+
isFocusDefault = false
|
|
33
36
|
}) => {
|
|
34
37
|
const DEFAULT_BLINK_TIME = 200;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const [isEditing, setEditing] = useState(false);
|
|
38
|
+
|
|
39
|
+
//REFS
|
|
38
40
|
const inputRef = useRef(null);
|
|
39
41
|
const decRef = useRef(null);
|
|
40
42
|
const incRef = useRef(null);
|
|
43
|
+
const wrapRef = useRef(null);
|
|
44
|
+
|
|
41
45
|
const previousValueRef = useRef(value);
|
|
42
|
-
const [isAttemptToChange, setIsAttemptToChange] = useState(false);
|
|
43
|
-
const [isToHighlightError, setIsToHighlightError] = useState(false);
|
|
44
46
|
|
|
47
|
+
// STATES
|
|
48
|
+
const [inputValue, setInputValue] = useState(value || min || '');
|
|
49
|
+
const [inputValueFormated, setInputValueFormated] = useState(inputValue);
|
|
45
50
|
const [intMemoVal, setIntMemoVal] = useState(0);
|
|
46
51
|
|
|
52
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
53
|
+
const [isEditing, setEditing] = useState(false);
|
|
54
|
+
|
|
55
|
+
const [isAttemptToChange, setIsAttemptToChange] = useState(false);
|
|
56
|
+
const [isToHighlightError, setIsToHighlightError] = useState(false);
|
|
57
|
+
|
|
47
58
|
const { onlyNumbers } = formatInput;
|
|
48
59
|
const { addCommas, removeComma } = formatInput.priceInput;
|
|
49
60
|
|
|
@@ -51,8 +62,12 @@ const NumericInput = ({
|
|
|
51
62
|
const handle = {
|
|
52
63
|
change: (e) => {
|
|
53
64
|
let inputValue = e.target ? onlyNumbers(e.target.value) : e;
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
inputValue &&
|
|
68
|
+
(decRef.current.contains(e.target) || incRef.current.contains(e.target))
|
|
69
|
+
) {
|
|
70
|
+
inputValue = parseFloat(inputValue);
|
|
56
71
|
if (min && +min > inputValue) {
|
|
57
72
|
inputValue = min;
|
|
58
73
|
} else if (max && +max < inputValue) inputValue = max;
|
|
@@ -60,28 +75,21 @@ const NumericInput = ({
|
|
|
60
75
|
if (symbolsLimit) {
|
|
61
76
|
inputValue = inputValue.toString().substring(0, +symbolsLimit);
|
|
62
77
|
}
|
|
63
|
-
|
|
64
|
-
setIntMemoVal(parseFloat(inputValue));
|
|
65
|
-
onChange(inputValue.toString());
|
|
78
|
+
setInputValue(inputValue.toString());
|
|
66
79
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onChange('');
|
|
80
|
+
clear: () => {
|
|
81
|
+
handle.change(min || '');
|
|
70
82
|
},
|
|
71
83
|
focus: (e) => {
|
|
84
|
+
if (isFocused) return;
|
|
72
85
|
setIsFocused(true);
|
|
73
|
-
if (isPriceInput) onChange(removeComma(value));
|
|
74
86
|
if (onFocus) onFocus(e);
|
|
75
87
|
},
|
|
76
88
|
blur: (e) => {
|
|
89
|
+
if (!isFocused) return;
|
|
90
|
+
|
|
77
91
|
setIsFocused(false);
|
|
78
92
|
setEditing(false);
|
|
79
|
-
if (isPriceInput) {
|
|
80
|
-
if (!isFinite(value)) {
|
|
81
|
-
value = intMemoVal;
|
|
82
|
-
}
|
|
83
|
-
onChange(addCommas(value));
|
|
84
|
-
}
|
|
85
93
|
|
|
86
94
|
if (onBlur) onBlur(e);
|
|
87
95
|
},
|
|
@@ -110,27 +118,26 @@ const NumericInput = ({
|
|
|
110
118
|
|
|
111
119
|
if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
|
|
112
120
|
},
|
|
113
|
-
decrement: () => {
|
|
121
|
+
decrement: (e) => {
|
|
114
122
|
handle.change(intMemoVal - +numStep);
|
|
115
123
|
},
|
|
116
|
-
increment: () => {
|
|
124
|
+
increment: (e) => {
|
|
117
125
|
handle.change(intMemoVal + +numStep);
|
|
118
126
|
}
|
|
119
127
|
};
|
|
120
128
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
!
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
129
|
+
//Check Outside Click
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const handleClickOutside = (event) => {
|
|
132
|
+
if (!wrapRef.current.contains(event.target)) {
|
|
133
|
+
setIsFocused(false);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
document.addEventListener('mousedown', handleClickOutside, true);
|
|
138
|
+
return () =>
|
|
139
|
+
document.removeEventListener('mousedown', handleClickOutside, true);
|
|
140
|
+
}, []);
|
|
134
141
|
|
|
135
142
|
useEffect(() => {
|
|
136
143
|
if (!isNotBlinkErrors && isAttemptToChange) {
|
|
@@ -142,51 +149,85 @@ const NumericInput = ({
|
|
|
142
149
|
}
|
|
143
150
|
}, [isAttemptToChange]);
|
|
144
151
|
|
|
152
|
+
//On Input Value Change
|
|
145
153
|
useEffect(() => {
|
|
146
|
-
|
|
147
|
-
return () =>
|
|
148
|
-
document.removeEventListener('click', handleClickOutside, true);
|
|
149
|
-
}, []);
|
|
154
|
+
if (inputValue !== value) setIsFocused(true);
|
|
150
155
|
|
|
156
|
+
setInputValueFormated(
|
|
157
|
+
isPriceInput
|
|
158
|
+
? isFocused
|
|
159
|
+
? removeComma(inputValue)
|
|
160
|
+
: addCommas(inputValue)
|
|
161
|
+
: inputValue
|
|
162
|
+
);
|
|
163
|
+
setIntMemoVal(parseInt(inputValue));
|
|
164
|
+
|
|
165
|
+
if (typeof onChange === 'function') onChange(inputValue?.toString());
|
|
166
|
+
}, [inputValue]);
|
|
167
|
+
|
|
168
|
+
//On Integer Value Change
|
|
151
169
|
useEffect(() => {
|
|
152
|
-
if (isNaN(intMemoVal)) setIntMemoVal(min ||
|
|
170
|
+
if (isNaN(intMemoVal)) setIntMemoVal(min || 0);
|
|
153
171
|
}, [intMemoVal]);
|
|
154
172
|
|
|
173
|
+
//On Focuse Change
|
|
155
174
|
useEffect(() => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
setInputValueFormated(
|
|
176
|
+
isPriceInput
|
|
177
|
+
? isFocused
|
|
178
|
+
? removeComma(inputValue)
|
|
179
|
+
: addCommas(inputValue)
|
|
180
|
+
: inputValue
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (isFocused) {
|
|
184
|
+
if (typeof onFocus === 'function') onFocus({ target: inputRef?.current });
|
|
185
|
+
inputRef?.current?.focus();
|
|
186
|
+
} else {
|
|
187
|
+
if (typeof onBlur === 'function') onBlur({ target: inputRef?.current });
|
|
188
|
+
inputRef?.current?.blur();
|
|
189
|
+
}
|
|
190
|
+
}, [isFocused]);
|
|
191
|
+
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (inputRef?.current && typeof isFocusDefault === 'boolean')
|
|
194
|
+
setIsFocused(isFocusDefault);
|
|
195
|
+
}, [inputRef, isFocusDefault]);
|
|
173
196
|
|
|
174
197
|
function renderInput() {
|
|
198
|
+
const uniProps = {
|
|
199
|
+
className: `input ${className || ''}`,
|
|
200
|
+
placeholder,
|
|
201
|
+
value: inputValueFormated,
|
|
202
|
+
disabled,
|
|
203
|
+
onChange: handle.change,
|
|
204
|
+
onFocus: () => {
|
|
205
|
+
setIsFocused(true);
|
|
206
|
+
setEditing(true);
|
|
207
|
+
},
|
|
208
|
+
onBlur: () => setEditing(false),
|
|
209
|
+
onKeyUp: handle.keyUp,
|
|
210
|
+
min,
|
|
211
|
+
max,
|
|
212
|
+
...(maskChar ? { maskChar } : {}),
|
|
213
|
+
...(formatChars ? { formatChars } : {})
|
|
214
|
+
};
|
|
215
|
+
|
|
175
216
|
return (
|
|
176
217
|
<>
|
|
177
|
-
<input {...uniProps} ref={inputRef} type=
|
|
218
|
+
<input {...uniProps} ref={inputRef} type='text' />
|
|
178
219
|
|
|
179
220
|
<div className='input__nums'>
|
|
180
221
|
<button
|
|
181
222
|
ref={decRef}
|
|
182
|
-
|
|
223
|
+
onMouseDown={(e) => handle.decrement(e)}
|
|
183
224
|
className={cn(`input__num-btn`, { disabled: +value <= min })}
|
|
184
225
|
>
|
|
185
226
|
<Minus />
|
|
186
227
|
</button>
|
|
187
228
|
<button
|
|
188
229
|
ref={incRef}
|
|
189
|
-
|
|
230
|
+
onMouseDown={(e) => handle.increment(e)}
|
|
190
231
|
className={cn(`input__num-btn`, { disabled: +value >= max })}
|
|
191
232
|
>
|
|
192
233
|
<Plus />
|
|
@@ -198,6 +239,7 @@ const NumericInput = ({
|
|
|
198
239
|
|
|
199
240
|
return (
|
|
200
241
|
<div
|
|
242
|
+
ref={wrapRef}
|
|
201
243
|
className={cn(
|
|
202
244
|
`input__wrap`,
|
|
203
245
|
{ [`input__wrap_focus`]: isFocused },
|
|
@@ -209,8 +251,8 @@ const NumericInput = ({
|
|
|
209
251
|
{icon}
|
|
210
252
|
{withDelete && (
|
|
211
253
|
<span
|
|
212
|
-
className={cn(`input__close`, { hidden: !
|
|
213
|
-
onClick={handle.
|
|
254
|
+
className={cn(`input__close`, { hidden: !inputValue })}
|
|
255
|
+
onClick={() => handle.clear()}
|
|
214
256
|
/>
|
|
215
257
|
)}
|
|
216
258
|
</div>
|
|
@@ -11,6 +11,9 @@ export default {
|
|
|
11
11
|
disabled: {
|
|
12
12
|
description: 'boolean'
|
|
13
13
|
},
|
|
14
|
+
isFocusDefault: {
|
|
15
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
16
|
+
},
|
|
14
17
|
isInitialFocus: {
|
|
15
18
|
description: 'boolean - if true, the input will be focused on mount'
|
|
16
19
|
},
|
|
@@ -35,25 +38,6 @@ export default {
|
|
|
35
38
|
placeholder: {
|
|
36
39
|
description: 'text'
|
|
37
40
|
},
|
|
38
|
-
type: {
|
|
39
|
-
description:
|
|
40
|
-
"'text', 'number', 'password', 'color', 'date', 'datetime-local', 'month', 'time', 'email', 'range'",
|
|
41
|
-
control: {
|
|
42
|
-
type: 'select',
|
|
43
|
-
options: [
|
|
44
|
-
'text',
|
|
45
|
-
'number',
|
|
46
|
-
'password',
|
|
47
|
-
'color',
|
|
48
|
-
'date',
|
|
49
|
-
'datetime-local',
|
|
50
|
-
'month',
|
|
51
|
-
'time',
|
|
52
|
-
'email',
|
|
53
|
-
'range'
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
41
|
icon: { description: 'JSX' },
|
|
58
42
|
value: { description: '(* - required prop)' },
|
|
59
43
|
className: { description: 'string' },
|
|
@@ -71,15 +55,15 @@ export default {
|
|
|
71
55
|
};
|
|
72
56
|
|
|
73
57
|
const Template = (args) => {
|
|
74
|
-
const [value, setValue] = useState('');
|
|
58
|
+
const [value, setValue] = useState('15000');
|
|
75
59
|
return <NumericInput {...args} value={value} onChange={setValue} />;
|
|
76
60
|
};
|
|
77
61
|
|
|
78
62
|
export const NumericInputTemplate = Template.bind({});
|
|
79
63
|
|
|
80
64
|
NumericInputTemplate.args = {
|
|
81
|
-
type: 'text',
|
|
82
65
|
disabled: false,
|
|
66
|
+
isFocusDefault: false,
|
|
83
67
|
error: '',
|
|
84
68
|
isPriceInput: false,
|
|
85
69
|
mask: '',
|
|
@@ -88,7 +72,7 @@ NumericInputTemplate.args = {
|
|
|
88
72
|
numStep: 100,
|
|
89
73
|
min: '0',
|
|
90
74
|
max: '15000',
|
|
91
|
-
symbolsLimit:
|
|
75
|
+
symbolsLimit: 5,
|
|
92
76
|
placeholder: 'Placeholder',
|
|
93
77
|
icon: <User />
|
|
94
78
|
};
|
|
@@ -88,7 +88,7 @@ const RangeCalendar = props => {
|
|
|
88
88
|
onMouseOver={day && !isFutureDay ? () => onHover(day.date) : null}
|
|
89
89
|
onMouseLeave={() => onHover(null)}
|
|
90
90
|
>
|
|
91
|
-
|
|
91
|
+
<span className="calendar__day-num">{day && day.date.getDate()}</span>
|
|
92
92
|
</div>
|
|
93
93
|
);
|
|
94
94
|
};
|
|
@@ -6,7 +6,7 @@ import './Calendar.scss';
|
|
|
6
6
|
|
|
7
7
|
export default function (props) {
|
|
8
8
|
const { date, setDate, allowPrev = true, allowNext = true, params, className } = props;
|
|
9
|
-
const { minDate, maxDate } = params;
|
|
9
|
+
const { minDate = '01/01/1900', maxDate = moment().format('MM/DD/YYYY') } = params;
|
|
10
10
|
const [days, setDays] = useState({});
|
|
11
11
|
const [showDate, setShowDate] = useState(date);
|
|
12
12
|
|
|
@@ -425,7 +425,11 @@
|
|
|
425
425
|
// box-shadow: 0 0 3px 0 rgb(0 123 255 / 50%);
|
|
426
426
|
// }
|
|
427
427
|
// }
|
|
428
|
-
|
|
428
|
+
.calendar-header {
|
|
429
|
+
display: flex;
|
|
430
|
+
justify-content: center;
|
|
431
|
+
align-items: center;
|
|
432
|
+
}
|
|
429
433
|
.calendar {
|
|
430
434
|
background: #ffffff;
|
|
431
435
|
border: 1px solid #e2e5ec;
|
|
@@ -4,38 +4,29 @@ export const formatInput = {
|
|
|
4
4
|
value = value.toString();
|
|
5
5
|
const isFraction = value.includes('.');
|
|
6
6
|
|
|
7
|
-
const valueBeforeDot = isFraction
|
|
8
|
-
? value.slice(0, value.indexOf('.'))
|
|
9
|
-
: value;
|
|
7
|
+
const valueBeforeDot = isFraction ? value.slice(0, value.indexOf('.')) : value;
|
|
10
8
|
|
|
11
9
|
const intPart = valueBeforeDot
|
|
12
10
|
.split('')
|
|
13
11
|
.reverse()
|
|
14
|
-
.reduce(
|
|
15
|
-
(acc, item, idx) =>
|
|
16
|
-
idx % 3 === 0 && idx !== 0 ? [...acc, ',', item] : [...acc, item],
|
|
17
|
-
[]
|
|
18
|
-
)
|
|
12
|
+
.reduce((acc, item, idx) => (idx % 3 === 0 && idx !== 0 ? [...acc, ',', item] : [...acc, item]), [])
|
|
19
13
|
.reverse()
|
|
20
14
|
.join('');
|
|
21
15
|
|
|
22
16
|
return isFraction ? intPart + value.slice(value.indexOf('.')) : intPart;
|
|
23
17
|
},
|
|
24
18
|
removeComma: (value) => {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
19
|
+
return parseInt(value.toString().replace(/\,/g, ''));
|
|
20
|
+
},
|
|
27
21
|
},
|
|
28
22
|
onlyNumbers: (value, isDot = false) => {
|
|
29
|
-
const val =
|
|
30
|
-
value.slice(0, 1) !== '0' && value.slice(0, 1) !== '.'
|
|
31
|
-
? value
|
|
32
|
-
: value.slice(1);
|
|
23
|
+
const val = value.slice(0, 1) !== '0' && value.slice(0, 1) !== '.' ? value : value.slice(1);
|
|
33
24
|
if (isDot) return twoDigitAfterDot(val.replace(/[^0-9.]/g, ''));
|
|
34
25
|
else return +val.toString().replace(/\D/g, '');
|
|
35
26
|
},
|
|
36
27
|
onlyString: (value) => {
|
|
37
28
|
return value.toString().replace(/[^a-z]/gi, '');
|
|
38
|
-
}
|
|
29
|
+
},
|
|
39
30
|
};
|
|
40
31
|
|
|
41
32
|
//обрезает числа после точки до 2х
|