intelicoreact 0.0.73 → 0.0.77

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.
@@ -36,7 +36,8 @@ var RC = 'dropdown';
36
36
  var Dropdown = function Dropdown(_ref) {
37
37
  var _options$find, _filteredOptions$find;
38
38
 
39
- var options = _ref.options,
39
+ var _ref$options = _ref.options,
40
+ options = _ref$options === void 0 ? [] : _ref$options,
40
41
  value = _ref.value,
41
42
  error = _ref.error,
42
43
  onChange = _ref.onChange,
@@ -23,6 +23,8 @@ var _reactFeather = require("react-feather");
23
23
 
24
24
  var _reactInputMask = _interopRequireDefault(require("react-input-mask"));
25
25
 
26
+ var _index = require("../../../Constants/index.constants");
27
+
26
28
  require("./Input.scss");
27
29
 
28
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); }
@@ -56,9 +58,11 @@ var Input = function Input(_ref) {
56
58
  formatChars = _ref.formatChars,
57
59
  error = _ref.error,
58
60
  icon = _ref.icon,
59
- symbolsLimit = _ref.symbolsLimit;
61
+ symbolsLimit = _ref.symbolsLimit,
62
+ isNotBlinkErrors = _ref.isNotBlinkErrors,
63
+ blinkTime = _ref.blinkTime;
64
+ var DEFAULT_BLINK_TIME = 100; // STATES
60
65
 
61
- // STATES
62
66
  var _useState = (0, _react.useState)(false),
63
67
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
64
68
  isFocused = _useState2[0],
@@ -69,7 +73,19 @@ var Input = function Input(_ref) {
69
73
  isEditing = _useState4[0],
70
74
  setEditing = _useState4[1];
71
75
 
72
- var inputRef = (0, _react.useRef)(null); // HANDLES
76
+ var inputRef = (0, _react.useRef)(null);
77
+ var previousValueRef = (0, _react.useRef)(value);
78
+
79
+ var _useState5 = (0, _react.useState)(false),
80
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
81
+ isAttemptToChange = _useState6[0],
82
+ setIsAttemptToChange = _useState6[1];
83
+
84
+ var _useState7 = (0, _react.useState)(false),
85
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
86
+ isToHighlightError = _useState8[0],
87
+ setIsToHighlightError = _useState8[1]; // HANDLES
88
+
73
89
 
74
90
  var handle = {
75
91
  change: function change(e) {
@@ -99,7 +115,21 @@ var Input = function Input(_ref) {
99
115
  if (onBlur) onBlur(e);
100
116
  },
101
117
  keyUp: function keyUp(e) {
102
- return onKeyUp ? onKeyUp(e.keyCode, event) : null;
118
+ if (!isNotBlinkErrors) {
119
+ var _previousValueRef$cur;
120
+
121
+ var changedValue = '' + (value !== null && value !== void 0 ? value : '');
122
+ var previousValue = '' + ((_previousValueRef$cur = previousValueRef.current) !== null && _previousValueRef$cur !== void 0 ? _previousValueRef$cur : '');
123
+
124
+ var currentSet = function () {
125
+ if (previousValue.length < changedValue.length) return value.slice(previousValue.length - changedValue.length);else return changedValue.includes(e.key) ? e.key : '';
126
+ }();
127
+
128
+ if (!_index.KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) setIsAttemptToChange(true);
129
+ if (_index.KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet) previousValueRef.current = value;else previousValueRef.current = previousValue + currentSet[0];
130
+ }
131
+
132
+ if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
103
133
  }
104
134
  };
105
135
  (0, _react.useEffect)(function () {
@@ -153,8 +183,17 @@ var Input = function Input(_ref) {
153
183
  }, /*#__PURE__*/_react.default.createElement(_reactFeather.Plus, null))));
154
184
  }
155
185
 
186
+ (0, _react.useEffect)(function () {
187
+ if (!isNotBlinkErrors && isAttemptToChange) {
188
+ setIsAttemptToChange(null);
189
+ setIsToHighlightError(true);
190
+ setTimeout(function () {
191
+ setIsToHighlightError(false);
192
+ }, blinkTime || DEFAULT_BLINK_TIME);
193
+ }
194
+ }, [isAttemptToChange]);
156
195
  return /*#__PURE__*/_react.default.createElement("div", {
157
- className: (0, _classnames.default)("input__wrap", (0, _defineProperty2.default)({}, "input__wrap_focus", isFocused), (0, _defineProperty2.default)({}, "input__wrap_error", error), (0, _defineProperty2.default)({}, "input__wrap_disabled", disabled))
196
+ 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))
158
197
  }, renderInput(), icon, withDelete && !isNumeric && /*#__PURE__*/_react.default.createElement("span", {
159
198
  className: (0, _classnames.default)("input__close", {
160
199
  hidden: !value
@@ -102,14 +102,14 @@ var Template = function Template(args) {
102
102
  var InputTemplate = Template.bind({});
103
103
  exports.InputTemplate = InputTemplate;
104
104
  InputTemplate.args = {
105
- type: 'text',
105
+ type: 'number',
106
106
  disabled: false,
107
107
  error: '',
108
108
  withDelete: true,
109
109
  isNumeric: false,
110
110
  numStep: 1,
111
- min: '0',
112
- max: '5',
111
+ // min: '0',
112
+ // max: '5',
113
113
  placeholder: 'Placeholder',
114
114
  // mask: 'nnnnn0129',
115
115
  // maskChar: '_',
@@ -96,20 +96,14 @@ var InputDateRange = function InputDateRange(props) {
96
96
  return formatedValue;
97
97
  };
98
98
 
99
- var _useState5 = (0, _react.useState)(false),
100
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
101
- mountDate = _useState6[0],
102
- setMD = _useState6[1];
103
-
104
- (0, _react.useEffect)(function () {
105
- if (value && !mountDate) {
106
- setMD(true);
107
- handleChange(_objectSpread({}, value));
108
- }
109
- }, [value]);
110
-
111
99
  var Range = function Range() {
112
100
  var SYMBOLS_QUANTITY_IF_TIME_ADDED = 13;
101
+
102
+ if (!actualValues.start && value.start) {
103
+ actualValues.start = value.start;
104
+ actualValues.end = value.end || '';
105
+ }
106
+
113
107
  var start = actualValues.start,
114
108
  end = actualValues.end;
115
109
  if (!start || !end) return null;
@@ -37,7 +37,8 @@ var Arrow = function Arrow(_ref) {
37
37
  setColor = _useState2[1];
38
38
 
39
39
  (0, _react.useEffect)(function () {
40
- if (ref.current) {//setColor(getStyles(ref.current, 'color'));
40
+ if (ref.current) {
41
+ setColor((0, _utils.getStyles)(ref.current, 'color'));
41
42
  }
42
43
 
43
44
  ;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.KEYBOARD_SERVICE_KEYS = void 0;
7
+ var KEYBOARD_SERVICE_KEYS = ['Escape', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'Tab', 'CapsLock', 'Shift', 'Control', 'Meta', 'Option', 'Alt', 'ContextMenu', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'NumLock', 'Backspace', 'Delete', 'Enter', 'Return', 'Insert', 'Home', 'End', 'PageUp', 'PageDown', 'PrintScreen', 'ScrollLock', 'Pause'];
8
+ exports.KEYBOARD_SERVICE_KEYS = KEYBOARD_SERVICE_KEYS;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "0.0.73",
4
- "description": "Date range fixes and dropdown refactor",
3
+ "version": "0.0.77",
4
+ "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -6,7 +6,7 @@ import './Dropdown.scss';
6
6
 
7
7
  const RC = 'dropdown';
8
8
 
9
- const Dropdown = ({ options, value, error, onChange, placeholder, className, isSearchable, entity }) => {
9
+ const Dropdown = ({ options = [], value, error, onChange, placeholder, className, isSearchable, entity }) => {
10
10
  const [isOpen, setIsOpen] = useState(false);
11
11
  const [searchValue, setSearchValue] = useState('');
12
12
  const dropdownRef = useRef(null);
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
2
2
  import cn from 'classnames';
3
3
  import { Minus, Plus } from 'react-feather';
4
4
  import InputMask from 'react-input-mask';
5
+ import { KEYBOARD_SERVICE_KEYS } from '../../../Constants/index.constants';
5
6
 
6
7
  import './Input.scss';
7
8
 
@@ -26,11 +27,17 @@ const Input = ({
26
27
  error,
27
28
  icon,
28
29
  symbolsLimit,
30
+ isNotBlinkErrors,
31
+ blinkTime,
29
32
  }) => {
33
+ const DEFAULT_BLINK_TIME = 100;
30
34
  // STATES
31
35
  const [isFocused, setIsFocused] = useState(false);
32
36
  const [isEditing, setEditing] = useState(false);
33
37
  const inputRef = useRef(null);
38
+ const previousValueRef = useRef(value);
39
+ const [isAttemptToChange, setIsAttemptToChange] = useState(false);
40
+ const [isToHighlightError, setIsToHighlightError] = useState(false);
34
41
  // HANDLES
35
42
  const handle = {
36
43
  change: e => {
@@ -56,7 +63,22 @@ const Input = ({
56
63
  setEditing(false);
57
64
  if (onBlur) onBlur(e);
58
65
  },
59
- keyUp: e => (onKeyUp ? onKeyUp(e.keyCode, event) : null)
66
+ keyUp: e => {
67
+ if (!isNotBlinkErrors) {
68
+ const changedValue = '' + (value ?? '');
69
+ const previousValue = '' + (previousValueRef.current ?? '');
70
+ const currentSet = (() => {
71
+ if (previousValue.length < changedValue.length) return value.slice(previousValue.length - changedValue.length);
72
+ else return changedValue.includes(e.key) ? e.key : '';
73
+ })();
74
+
75
+ if(!KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) setIsAttemptToChange(true);
76
+ if (KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet) previousValueRef.current = value;
77
+ else previousValueRef.current = previousValue + currentSet[0];
78
+ }
79
+
80
+ if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
81
+ }
60
82
  };
61
83
 
62
84
  useEffect(() => {
@@ -99,13 +121,23 @@ const Input = ({
99
121
  </>
100
122
  );
101
123
  }
124
+
125
+ useEffect(() => {
126
+ if (!isNotBlinkErrors && isAttemptToChange) {
127
+ setIsAttemptToChange(null);
128
+ setIsToHighlightError(true);
129
+ setTimeout(() => {
130
+ setIsToHighlightError(false)
131
+ }, blinkTime || DEFAULT_BLINK_TIME);
132
+ }
133
+ }, [isAttemptToChange]);
102
134
 
103
135
  return (
104
136
  <div
105
137
  className={cn(
106
138
  `input__wrap`,
107
139
  { [`input__wrap_focus`]: isFocused },
108
- { [`input__wrap_error`]: error },
140
+ { [`input__wrap_error`]: error || isToHighlightError },
109
141
  { [`input__wrap_disabled`]: disabled }
110
142
  )}
111
143
  >
@@ -58,14 +58,14 @@ const Template = args => {
58
58
  export const InputTemplate = Template.bind({});
59
59
 
60
60
  InputTemplate.args = {
61
- type: 'text',
61
+ type: 'number',
62
62
  disabled: false,
63
63
  error: '',
64
64
  withDelete: true,
65
65
  isNumeric: false,
66
66
  numStep: 1,
67
- min: '0',
68
- max: '5',
67
+ // min: '0',
68
+ // max: '5',
69
69
  placeholder: 'Placeholder',
70
70
  // mask: 'nnnnn0129',
71
71
  // maskChar: '_',
@@ -49,17 +49,12 @@ const InputDateRange = props => {
49
49
  return formatedValue;
50
50
  };
51
51
 
52
- const [mountDate, setMD] = useState(false);
53
-
54
- useEffect(() => {
55
- if (value && !mountDate) {
56
- setMD(true);
57
- handleChange({ ...value });
58
- }
59
- }, [value]);
60
-
61
52
  const Range = () => {
62
53
  const SYMBOLS_QUANTITY_IF_TIME_ADDED = 13;
54
+ if (!actualValues.start && value.start) {
55
+ actualValues.start = value.start;
56
+ actualValues.end = value.end || '';
57
+ }
63
58
  const { start, end } = actualValues;
64
59
  if (!start || !end) return null;
65
60
 
@@ -162,7 +157,7 @@ const InputDateRange = props => {
162
157
  <div className="date-range-input__interval-key">
163
158
  <span>
164
159
  {(txt?.labels && txt.labels[actualValues?.intervalKey]) ??
165
- (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
160
+ (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
166
161
  </span>
167
162
  {current !== ALL_TIME_KEY && <span>:</span>}
168
163
  </div>
@@ -12,7 +12,7 @@ const Arrow = ({type, className, onClick, disabled}) => {
12
12
 
13
13
  useEffect(() => {
14
14
  if (ref.current) {
15
- //setColor(getStyles(ref.current, 'color'));
15
+ setColor(getStyles(ref.current, 'color'));
16
16
  };
17
17
  }, [ref.current]);
18
18
 
@@ -0,0 +1,41 @@
1
+
2
+ export const KEYBOARD_SERVICE_KEYS = [
3
+ 'Escape',
4
+ 'F1',
5
+ 'F2',
6
+ 'F3',
7
+ 'F4',
8
+ 'F5',
9
+ 'F6',
10
+ 'F7',
11
+ 'F8',
12
+ 'F9',
13
+ 'F10',
14
+ 'F11',
15
+ 'F12',
16
+ 'Tab',
17
+ 'CapsLock',
18
+ 'Shift',
19
+ 'Control',
20
+ 'Meta',
21
+ 'Option',
22
+ 'Alt',
23
+ 'ContextMenu',
24
+ 'ArrowLeft',
25
+ 'ArrowRight',
26
+ 'ArrowUp',
27
+ 'ArrowDown',
28
+ 'NumLock',
29
+ 'Backspace',
30
+ 'Delete',
31
+ 'Enter',
32
+ 'Return',
33
+ 'Insert',
34
+ 'Home',
35
+ 'End',
36
+ 'PageUp',
37
+ 'PageDown',
38
+ 'PrintScreen',
39
+ 'ScrollLock',
40
+ 'Pause'
41
+ ];