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.
@@ -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: 4px 8px 4px 32px;
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: var(--font-size);
233
- line-height: var(--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: 100%;
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,262 @@
1
+ import React, { useState, useEffect, useRef } from 'react';
2
+ import cn from 'classnames';
3
+ import { Minus, Plus } from 'react-feather';
4
+ import InputMask from 'react-input-mask';
5
+ import { KEYBOARD_SERVICE_KEYS } from '../../../Constants/index.constants';
6
+ import { formatInput } from '../../../Functions/inputExecutor';
7
+
8
+ import './NumericInput.scss';
9
+
10
+ let timerOutside;
11
+ let timerFocus;
12
+
13
+ const NumericInput = ({
14
+ onChange,
15
+ disabled,
16
+ withDelete,
17
+ numStep = 1,
18
+ min = 0,
19
+ max,
20
+ value,
21
+ placeholder,
22
+ className,
23
+ onBlur,
24
+ onFocus,
25
+ onKeyUp,
26
+ mask,
27
+ maskChar,
28
+ formatChars,
29
+ error,
30
+ icon,
31
+ symbolsLimit,
32
+ isNotBlinkErrors,
33
+ blinkTime,
34
+ isPriceInput,
35
+ isFocusDefault = false
36
+ }) => {
37
+ const DEFAULT_BLINK_TIME = 200;
38
+
39
+ //REFS
40
+ const inputRef = useRef(null);
41
+ const decRef = useRef(null);
42
+ const incRef = useRef(null);
43
+ const wrapRef = useRef(null);
44
+
45
+ const previousValueRef = useRef(value);
46
+
47
+ // STATES
48
+ const [inputValue, setInputValue] = useState(value || min || '');
49
+ const [inputValueFormated, setInputValueFormated] = useState(inputValue);
50
+ const [intMemoVal, setIntMemoVal] = useState(0);
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
+
58
+ const { onlyNumbers } = formatInput;
59
+ const { addCommas, removeComma } = formatInput.priceInput;
60
+
61
+ // HANDLES
62
+ const handle = {
63
+ change: (e) => {
64
+ let inputValue = e.target ? onlyNumbers(e.target.value) : e;
65
+
66
+ if (
67
+ inputValue &&
68
+ (decRef.current.contains(e.target) || incRef.current.contains(e.target))
69
+ ) {
70
+ inputValue = parseFloat(inputValue);
71
+ if (min && +min > inputValue) {
72
+ inputValue = min;
73
+ } else if (max && +max < inputValue) inputValue = max;
74
+ }
75
+ if (symbolsLimit) {
76
+ inputValue = inputValue.toString().substring(0, +symbolsLimit);
77
+ }
78
+ setInputValue(inputValue.toString());
79
+ },
80
+ clear: () => {
81
+ handle.change(min || '');
82
+ },
83
+ focus: (e) => {
84
+ if (isFocused) return;
85
+ setIsFocused(true);
86
+ if (onFocus) onFocus(e);
87
+ },
88
+ blur: (e) => {
89
+ if (!isFocused) return;
90
+
91
+ setIsFocused(false);
92
+ setEditing(false);
93
+
94
+ if (onBlur) onBlur(e);
95
+ },
96
+ keyUp: (e) => {
97
+ if (!isNotBlinkErrors) {
98
+ const changedValue = '' + (value ?? '');
99
+ const previousValue = '' + (previousValueRef.current ?? '');
100
+ const currentSet = (() => {
101
+ if (previousValue.length < changedValue.length)
102
+ return value
103
+ .toString()
104
+ .slice(previousValue.length - changedValue.length);
105
+ else return changedValue.toString().includes(e.key) ? e.key : '';
106
+ })();
107
+
108
+ if (
109
+ !KEYBOARD_SERVICE_KEYS.includes(e.key) &&
110
+ changedValue === previousValue
111
+ )
112
+ setIsAttemptToChange(true);
113
+
114
+ if (KEYBOARD_SERVICE_KEYS.includes(e.key) || !currentSet)
115
+ previousValueRef.current = value;
116
+ else previousValueRef.current = previousValue + currentSet[0];
117
+ }
118
+
119
+ if (onKeyUp) onKeyUp(e.keyCode, e.target.value);
120
+ },
121
+ decrement: (e) => {
122
+ handle.change(intMemoVal - +numStep);
123
+ },
124
+ increment: (e) => {
125
+ handle.change(intMemoVal + +numStep);
126
+ }
127
+ };
128
+
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
+ }, []);
141
+
142
+ useEffect(() => {
143
+ if (!isNotBlinkErrors && isAttemptToChange) {
144
+ setIsAttemptToChange(false);
145
+ setIsToHighlightError(true);
146
+ setTimeout(() => {
147
+ setIsToHighlightError(false);
148
+ }, blinkTime || DEFAULT_BLINK_TIME);
149
+ }
150
+ }, [isAttemptToChange]);
151
+
152
+ //On Input Value Change
153
+ useEffect(() => {
154
+ if (inputValue !== value) setIsFocused(true);
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
169
+ useEffect(() => {
170
+ if (isNaN(intMemoVal)) setIntMemoVal(min || 0);
171
+ }, [intMemoVal]);
172
+
173
+ //On Focuse Change
174
+ useEffect(() => {
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]);
196
+
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
+
216
+ return (
217
+ <>
218
+ <input {...uniProps} ref={inputRef} type='text' />
219
+
220
+ <div className='input__nums'>
221
+ <button
222
+ ref={decRef}
223
+ onMouseDown={(e) => handle.decrement(e)}
224
+ className={cn(`input__num-btn`, { disabled: +value <= min })}
225
+ >
226
+ <Minus />
227
+ </button>
228
+ <button
229
+ ref={incRef}
230
+ onMouseDown={(e) => handle.increment(e)}
231
+ className={cn(`input__num-btn`, { disabled: +value >= max })}
232
+ >
233
+ <Plus />
234
+ </button>
235
+ </div>
236
+ </>
237
+ );
238
+ }
239
+
240
+ return (
241
+ <div
242
+ ref={wrapRef}
243
+ className={cn(
244
+ `input__wrap`,
245
+ { [`input__wrap_focus`]: isFocused },
246
+ { [`input__wrap_error`]: error || isToHighlightError },
247
+ { [`input__wrap_disabled`]: disabled }
248
+ )}
249
+ >
250
+ {renderInput()}
251
+ {icon}
252
+ {withDelete && (
253
+ <span
254
+ className={cn(`input__close`, { hidden: !inputValue })}
255
+ onClick={() => handle.clear()}
256
+ />
257
+ )}
258
+ </div>
259
+ );
260
+ };
261
+
262
+ export default NumericInput;
@@ -0,0 +1,135 @@
1
+ .input {
2
+ position: relative;
3
+ word-break: break-all;
4
+ border: none;
5
+ background: none;
6
+ padding: 0 10px;
7
+ width: 100%;
8
+ &::-webkit-outer-spin-button,
9
+ &::-webkit-inner-spin-button {
10
+ -webkit-appearance: none;
11
+ }
12
+
13
+ &__wrap {
14
+ display: flex;
15
+ align-items: center;
16
+ border: 1px solid #e2e5ec;
17
+ box-sizing: border-box;
18
+ background-color: #fff;
19
+ height: 28px;
20
+ border-radius: 4px;
21
+
22
+ &_focus {
23
+ border-color: #6b81dd;
24
+ filter: drop-shadow(0px 0px 4px rgba(93, 120, 255, 0.5));
25
+ }
26
+
27
+ &_disabled {
28
+ background: #f7f8fa;
29
+ opacity: 0.5;
30
+ border-color: #a6acb1;
31
+ pointer-events: none;
32
+ }
33
+
34
+ &_error {
35
+ border-color: #f06d8d;
36
+ }
37
+ }
38
+
39
+ &_disabled {
40
+ background: #f7f8fa;
41
+ opacity: 0.5;
42
+ border-color: #a6acb1;
43
+ pointer-events: none;
44
+ }
45
+
46
+ &_error {
47
+ border-color: #f06d8d;
48
+ }
49
+
50
+ svg {
51
+ margin-right: 4px;
52
+ }
53
+
54
+ &__input {
55
+ width: 100%;
56
+ height: 100%;
57
+ box-sizing: border-box;
58
+ font-size: 13px;
59
+ font-weight: 400;
60
+ color: #1e1e2d;
61
+ border: none;
62
+ padding: 0 5px;
63
+ border-radius: 4px;
64
+ }
65
+
66
+ &__close {
67
+ position: relative;
68
+ opacity: 0.6;
69
+ width: 14px;
70
+ height: 14px;
71
+ background: none;
72
+ cursor: pointer;
73
+ margin-right: 4px;
74
+ visibility: hidden;
75
+ pointer-events: none;
76
+ &:hover {
77
+ opacity: 1;
78
+ }
79
+
80
+ &:before,
81
+ &:after {
82
+ content: '';
83
+ position: absolute;
84
+ top: 0;
85
+ left: 0;
86
+ right: 0;
87
+ margin: auto;
88
+ height: 14px;
89
+ width: 2px;
90
+ background-color: #9aa0b9;
91
+ }
92
+
93
+ &:before {
94
+ transform: rotate(45deg);
95
+ }
96
+
97
+ &:after {
98
+ transform: rotate(-45deg);
99
+ }
100
+ }
101
+
102
+ &__nums {
103
+ display: flex;
104
+ align-items: center;
105
+ height: 100%;
106
+ }
107
+
108
+ &__num-btn {
109
+ cursor: pointer;
110
+ display: flex;
111
+ align-items: center;
112
+ justify-content: center;
113
+ height: 100%;
114
+ width: 24px;
115
+ border-left: 1px solid #e2e5ec;
116
+ background: none;
117
+ font-size: 20px;
118
+ user-select: none;
119
+ &.disabled {
120
+ opacity: 0.3;
121
+ }
122
+ svg {
123
+ margin-right: 0;
124
+ }
125
+ }
126
+
127
+ &-label {
128
+ margin-bottom: 5px;
129
+ }
130
+ }
131
+
132
+ .input__wrap:hover .input__close {
133
+ visibility: visible;
134
+ pointer-events: all;
135
+ }
@@ -0,0 +1,78 @@
1
+ import React, { useState } from 'react';
2
+ import { User } from 'react-feather';
3
+ import NumericInput from './NumericInput';
4
+
5
+ global.lng = 'en';
6
+
7
+ export default {
8
+ title: 'Form Elements/NumericInput',
9
+ component: NumericInput,
10
+ argTypes: {
11
+ disabled: {
12
+ description: 'boolean'
13
+ },
14
+ isFocusDefault: {
15
+ description: 'boolean - if true, input will be focused on mount'
16
+ },
17
+ isInitialFocus: {
18
+ description: 'boolean - if true, the input will be focused on mount'
19
+ },
20
+ error: {
21
+ description: 'text - coloring input if is errored'
22
+ },
23
+ isPriceInput: {
24
+ description: 'boolean - if true, the input will be styled as PriceInput'
25
+ },
26
+ withDelete: {
27
+ description: 'boolean - add clear-cross by hover'
28
+ },
29
+ numStep: {
30
+ description: 'number/text - plus/minus buttons factor (default: 1)'
31
+ },
32
+ min: {
33
+ description: 'number/text - minimal number for numeric input'
34
+ },
35
+ max: {
36
+ description: 'number/text - maximal number for numeric input'
37
+ },
38
+ placeholder: {
39
+ description: 'text'
40
+ },
41
+ icon: { description: 'JSX' },
42
+ value: { description: '(* - required prop)' },
43
+ className: { description: 'string' },
44
+ mask: {
45
+ description:
46
+ 'string: force input to masked https://www.npmjs.com/package/react-input-mask'
47
+ },
48
+ symbolsLimit: {
49
+ description: 'Set limit of symbols in input, overhead will be ignored'
50
+ },
51
+ onBlur: { description: 'custom callback on blur' },
52
+ onFocus: { description: 'custom callback on focus' },
53
+ onKeyUp: { description: 'custom callback on keyup, returns event keyCode' }
54
+ }
55
+ };
56
+
57
+ const Template = (args) => {
58
+ const [value, setValue] = useState('15000');
59
+ return <NumericInput {...args} value={value} onChange={setValue} />;
60
+ };
61
+
62
+ export const NumericInputTemplate = Template.bind({});
63
+
64
+ NumericInputTemplate.args = {
65
+ disabled: false,
66
+ isFocusDefault: false,
67
+ error: '',
68
+ isPriceInput: false,
69
+ mask: '',
70
+ withDelete: true,
71
+ isNumeric: false,
72
+ numStep: 100,
73
+ min: '0',
74
+ max: '15000',
75
+ symbolsLimit: 5,
76
+ placeholder: 'Placeholder',
77
+ icon: <User />
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
  };
@@ -0,0 +1,53 @@
1
+ export const formatInput = {
2
+ priceInput: {
3
+ addCommas: (value) => {
4
+ value = value.toString();
5
+ const isFraction = value.includes('.');
6
+
7
+ const valueBeforeDot = isFraction ? value.slice(0, value.indexOf('.')) : value;
8
+
9
+ const intPart = valueBeforeDot
10
+ .split('')
11
+ .reverse()
12
+ .reduce((acc, item, idx) => (idx % 3 === 0 && idx !== 0 ? [...acc, ',', item] : [...acc, item]), [])
13
+ .reverse()
14
+ .join('');
15
+
16
+ return isFraction ? intPart + value.slice(value.indexOf('.')) : intPart;
17
+ },
18
+ removeComma: (value) => {
19
+ return parseInt(value.toString().replace(/\,/g, ''));
20
+ },
21
+ },
22
+ onlyNumbers: (value, isDot = false) => {
23
+ const val = value.slice(0, 1) !== '0' && value.slice(0, 1) !== '.' ? value : value.slice(1);
24
+ if (isDot) return twoDigitAfterDot(val.replace(/[^0-9.]/g, ''));
25
+ else return +val.toString().replace(/\D/g, '');
26
+ },
27
+ onlyString: (value) => {
28
+ return value.toString().replace(/[^a-z]/gi, '');
29
+ },
30
+ };
31
+
32
+ //обрезает числа после точки до 2х
33
+ // 342.23423432 -> 342.23
34
+ const twoDigitAfterDot = (value) => {
35
+ if (value.includes('.')) {
36
+ const valueAfterDot = value.slice(0, value.indexOf('.') + 3);
37
+ let rest = value.slice(value.indexOf('.') + 1, value.indexOf('.') + 3);
38
+
39
+ return allButTheFirstDotCutter(valueAfterDot);
40
+ } else {
41
+ return value;
42
+ }
43
+ };
44
+
45
+ //обрезает все точки кроме первой.
46
+ //для фомата "2 цифры после точки"
47
+ // нельзя = 123...
48
+ // можно 123.99
49
+ function allButTheFirstDotCutter(str) {
50
+ return str.replace(/^([^.]*\.)(.*)$/, function (a, b, c) {
51
+ return b + c.replace(/\./g, '');
52
+ });
53
+ }
@@ -5,7 +5,10 @@ export const handleObjectChange =
5
5
  (data, prop = '', isNumber) => {
6
6
  let value;
7
7
  if (data?.target) {
8
- value = data.target.type === 'checkbox' ? data.target.checked : data.target.value;
8
+ value =
9
+ data.target.type === 'checkbox'
10
+ ? data.target.checked
11
+ : data.target.value;
9
12
  } else value = data;
10
13
 
11
14
  value = isNumber ? +value : value;