intelicoreact 0.0.81 → 0.0.85

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.
@@ -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;
@@ -507,15 +511,20 @@
507
511
  }
508
512
 
509
513
  &-container {
510
- width: 200px;
514
+ min-width: 200px;
515
+ position: relative;
516
+ .calendar {
517
+ position: absolute;
518
+ top: 100%;
519
+ padding: 10px 16px;
520
+ border: 1px solid var(--border-color);
521
+ }
511
522
  }
512
523
 
513
524
  &-dropdown {
514
525
  appearance: none;
515
526
  background-color: white;
516
527
  cursor: pointer;
517
- color: gray;
518
-
519
528
  width: 100%;
520
529
  height: 28px;
521
530
 
@@ -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 parseFloat(value.toString().replace(/\,/g, ''));
24
+ return parseInt(value.toString().replace(/\,/g, ''));
25
25
  }
26
26
  },
27
27
  onlyNumbers: function onlyNumbers(value) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "0.0.81",
4
- "description": "",
3
+ "version": "0.0.85",
4
+ "description": "fix input-calendar",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -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 && !isTwoDigitAfterDot)
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 (isPriceInput && isOnlyNumber && !isTwoDigitAfterDot) {
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,38 +4,31 @@ 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 = ({ data, params }) => {
8
- const [date, setDate] = useState(data);
9
- const [inputValue, setInputValue] = useState(date);
7
+ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', placeholder = 'mm/dd/yyyy', mask = '99/99/9999' }) => {
10
8
  const [isOpened, setIsOpened] = useState(false);
11
9
  const calendarRef = useRef(null);
12
10
 
13
11
  useClickOutside(calendarRef, () => setIsOpened(false));
14
12
 
15
- const changeInputValue = value => {
16
- if (!value.includes('_') && value) {
17
- setDate(moment(value).format('L'));
18
- setInputValue(moment(value).format('L'));
19
- } else {
20
- setInputValue(value);
21
- }
13
+ const changeInputValue = val => {
14
+ if (onChange) onChange(val);
22
15
  };
23
16
 
24
- const changeCalendarDay = value => {
25
- setDate(value);
26
- setInputValue(value);
17
+ const changeCalendarDay = val => {
18
+ if (onChange) onChange(val);
27
19
  };
28
20
 
29
21
  return (
30
- <div className="calendar-container" ref={calendarRef}>
22
+ <div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
31
23
  <InputMask
32
- mask="99/99/9999"
33
- value={inputValue}
24
+ mask={mask}
25
+ placeholder={placeholder}
26
+ value={value}
34
27
  onChange={e => changeInputValue(e.target.value)}
35
28
  className="calendar-dropdown"
36
29
  onFocus={() => setIsOpened(!isOpened)}
37
30
  />
38
- {isOpened ? <Calendar date={date} setDate={(newDate) => changeCalendarDay(newDate)} params={params} /> : null}
31
+ {isOpened ? <Calendar date={moment(value).format('L')} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
39
32
  </div>
40
33
  );
41
34
  };
@@ -1,3 +1,4 @@
1
+ import moment from 'moment-timezone';
1
2
  import React, { useRef, useState } from 'react';
2
3
  import { ref } from 'yup';
3
4
  import InputCalendar from './InputCalendar';
@@ -9,19 +10,17 @@ export default {
9
10
  component: InputCalendar,
10
11
  };
11
12
 
12
- const Template = (args) => {
13
- const params = {
14
- minDate: args?.minDate,
15
- maxDate: args?.maxDate,
16
- };
13
+ const [date, setDate] = useState('');
17
14
 
18
- return <InputCalendar data={args.date} params={params} />;
15
+ const Template = args => {
16
+ return <InputCalendar {...args} value={date} />;
19
17
  };
20
18
 
21
19
  export const Calendar = Template.bind({});
22
20
 
23
21
  Calendar.args = {
24
- date: '10/14/2021',
25
- minDate: '10/11/2021',
26
- maxDate: '10/25/2021',
22
+ value: '',
23
+ minDate: '10/14/2020',
24
+ maxDate: '10/14/2022',
25
+ onChange: val => setDate(val)
27
26
  };
@@ -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
- // STATES
36
- const [isFocused, setIsFocused] = useState(false);
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
- if (inputValue !== '') {
55
- inputValue = parseFloat(inputValue) || '';
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
- toggleEdit: () => {
68
- setEditing(!isEditing);
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
- const handleClickOutside = (event) => {
122
- if (
123
- inputRef.current &&
124
- !inputRef.current.contains(event.target) &&
125
- !decRef.current.contains(event.target) &&
126
- !incRef.current.contains(event.target)
127
- ) {
128
- setTimeout(() => {
129
- inputRef.current.focus();
130
- inputRef.current.blur();
131
- }, 0);
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
- document.addEventListener('click', handleClickOutside, true);
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
- if (isEditing || isFocused) inputRef.current.focus();
157
- }, [isEditing, isFocused]);
158
-
159
- const uniProps = {
160
- className: `input ${className}`,
161
- placeholder,
162
- value: value || '',
163
- disabled,
164
- onChange: handle.change,
165
- onFocus: handle.focus,
166
- onBlur: handle.blur,
167
- onKeyUp: handle.keyUp,
168
- min,
169
- max,
170
- ...(maskChar ? { maskChar } : {}),
171
- ...(formatChars ? { formatChars } : {})
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={type} />
218
+ <input {...uniProps} ref={inputRef} type='text' />
178
219
 
179
220
  <div className='input__nums'>
180
221
  <button
181
222
  ref={decRef}
182
- onClick={() => handle.decrement()}
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
- onClick={() => handle.increment()}
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: !value })}
213
- onClick={handle.toggleEdit}
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: 2,
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
- {day && day.date.getDate()}
91
+ <span className="calendar__day-num">{day && day.date.getDate()}</span>
92
92
  </div>
93
93
  );
94
94
  };
@@ -1,4 +1,4 @@
1
- .range-calendar {
1
+ .range-calendar, .calendar {
2
2
  width: 195px;
3
3
  min-height: 195px;
4
4
  display: flex;
@@ -12,7 +12,7 @@
12
12
  display: flex;
13
13
  justify-content: space-between;
14
14
  align-items: center;
15
-
15
+
16
16
  &__title {
17
17
  line-height: 20px;
18
18
  font-weight: 500;
@@ -27,7 +27,7 @@
27
27
  &__next, &__prev {
28
28
  width: 16px;
29
29
  height: 16px;
30
- background-color: #E2E6F8;
30
+ //background-color: #E2E6F8;
31
31
  border-radius: 5px;
32
32
  color: #171D33;
33
33
  }
@@ -98,4 +98,4 @@
98
98
  }
99
99
  }
100
100
  }
101
- }
101
+ }
@@ -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
 
@@ -92,7 +92,7 @@ export default function (props) {
92
92
  {[...Array(7).keys()].map((dayOfWeek) => {
93
93
  return (
94
94
  <div key={`day-of-week_${dayOfWeek}`} className="calendar__day calendar__day--title">
95
- {moment().weekday(dayOfWeek).format('dd').charAt(0)}
95
+ {moment().weekday(dayOfWeek).format('dd')}
96
96
  </div>
97
97
  );
98
98
  })}
@@ -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;
@@ -507,15 +511,20 @@
507
511
  }
508
512
 
509
513
  &-container {
510
- width: 200px;
514
+ min-width: 200px;
515
+ position: relative;
516
+ .calendar {
517
+ position: absolute;
518
+ top: 100%;
519
+ padding: 10px 16px;
520
+ border: 1px solid var(--border-color);
521
+ }
511
522
  }
512
523
 
513
524
  &-dropdown {
514
525
  appearance: none;
515
526
  background-color: white;
516
527
  cursor: pointer;
517
- color: gray;
518
-
519
528
  width: 100%;
520
529
  height: 28px;
521
530