intelicoreact 0.0.85 → 0.0.91
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/Dropdown/Dropdown.js +43 -19
- package/dist/Atomic/FormElements/Dropdown/Dropdown.scss +6 -0
- package/dist/Atomic/FormElements/Dropdown/Dropdown.stories.js +34 -7
- package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.js +23 -0
- package/dist/Atomic/FormElements/Dropdown/components/Loader.scss +57 -0
- package/dist/Atomic/FormElements/Input/Input.js +30 -10
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +7 -1
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +21 -20
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +8 -2
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +2 -0
- package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +35 -20
- package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +8 -2
- package/dist/Atomic/FormElements/InputDateRange/dependencies.js +1 -1
- package/dist/Atomic/FormElements/NumericInput/NumericInput.js +1 -0
- package/dist/Atomic/UI/Calendar/Calendar.js +1 -1
- package/dist/Atomic/UI/Calendar/Calendar.scss +7 -0
- package/package.json +1 -2
- package/src/Atomic/FormElements/Dropdown/Dropdown.js +66 -35
- package/src/Atomic/FormElements/Dropdown/Dropdown.scss +6 -0
- package/src/Atomic/FormElements/Dropdown/Dropdown.stories.js +22 -8
- package/src/Atomic/FormElements/Dropdown/components/DropdownLoader.js +17 -0
- package/src/Atomic/FormElements/Dropdown/components/Loader.scss +57 -0
- package/src/Atomic/FormElements/Input/Input.js +46 -33
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +9 -1
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +14 -10
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +5 -0
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +2 -0
- package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +41 -20
- package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +5 -1
- package/src/Atomic/FormElements/InputDateRange/dependencies.js +1 -1
- package/src/Atomic/FormElements/NumericInput/NumericInput.js +1 -0
- package/src/Atomic/UI/Calendar/Calendar.js +1 -1
- package/src/Atomic/UI/Calendar/Calendar.scss +7 -0
|
@@ -429,6 +429,12 @@
|
|
|
429
429
|
display: flex;
|
|
430
430
|
justify-content: center;
|
|
431
431
|
align-items: center;
|
|
432
|
+
|
|
433
|
+
&__prev,
|
|
434
|
+
&__next{
|
|
435
|
+
display: flex;
|
|
436
|
+
height: auto;
|
|
437
|
+
}
|
|
432
438
|
}
|
|
433
439
|
.calendar {
|
|
434
440
|
background: #ffffff;
|
|
@@ -515,6 +521,7 @@
|
|
|
515
521
|
position: relative;
|
|
516
522
|
.calendar {
|
|
517
523
|
position: absolute;
|
|
524
|
+
z-index: 9;
|
|
518
525
|
top: 100%;
|
|
519
526
|
padding: 10px 16px;
|
|
520
527
|
border: 1px solid var(--border-color);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intelicoreact",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.91",
|
|
4
4
|
"description": "fix input-calendar",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,5 @@
|
|
|
23
23
|
"@babel/polyfill": "^7.12.1",
|
|
24
24
|
"@babel/preset-env": "^7.15.6",
|
|
25
25
|
"anme": "^1.0.0"
|
|
26
|
-
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect } from 'react';
|
|
1
|
+
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { Check, ChevronDown, ChevronUp } from 'react-feather';
|
|
4
4
|
|
|
5
|
+
import DropdownLoader from './components/DropdownLoader';
|
|
6
|
+
|
|
5
7
|
import './Dropdown.scss';
|
|
6
8
|
|
|
7
9
|
const RC = 'dropdown';
|
|
8
10
|
|
|
9
|
-
const Dropdown = ({ options = [], value, error, onChange, placeholder, className, isSearchable, entity }) => {
|
|
11
|
+
const Dropdown = ({ options = [], value, error, disabled, onChange, placeholder, className, isSearchable, entity, scrollReactionObj }) => {
|
|
10
12
|
const [isOpen, setIsOpen] = useState(false);
|
|
11
|
-
const [searchValue, setSearchValue] = useState(
|
|
13
|
+
const [searchValue, setSearchValue] = useState();
|
|
12
14
|
const dropdownRef = useRef(null);
|
|
15
|
+
const dropdownListRef = useRef(null);
|
|
16
|
+
|
|
13
17
|
if (!options) return null;
|
|
14
18
|
const filteredGroups = options
|
|
15
|
-
.filter(item => item.items?.length)
|
|
16
|
-
.map(item => ({ ...item, items: item.items.filter(el => el?.label?.toLowerCase().includes(searchValue?.toLowerCase() || '')) }))
|
|
17
|
-
.filter(item => item.items?.length > 0);
|
|
19
|
+
.filter((item) => item.items?.length)
|
|
20
|
+
.map((item) => ({ ...item, items: item.items.filter((el) => el?.label?.toLowerCase().includes(searchValue?.toLowerCase() || '')) }))
|
|
21
|
+
.filter((item) => item.items?.length > 0);
|
|
18
22
|
|
|
19
23
|
const filteredItems = options
|
|
20
|
-
.filter(item => !item.items?.length)
|
|
21
|
-
.filter(item => item?.label?.toLowerCase().includes(searchValue?.toLowerCase() || ''));
|
|
24
|
+
.filter((item) => !item.items?.length)
|
|
25
|
+
.filter((item) => item?.label?.toLowerCase().includes(searchValue?.toLowerCase() || ''));
|
|
22
26
|
|
|
23
27
|
const filteredOptions = [...filteredItems, ...filteredGroups];
|
|
24
28
|
|
|
25
29
|
const modalBtnTrigger = entity && entity !== '' && typeof entity === 'string';
|
|
26
|
-
const onChangeHandler = item => {
|
|
30
|
+
const onChangeHandler = (item) => {
|
|
27
31
|
setIsOpen(false);
|
|
28
32
|
setSearchValue(null);
|
|
29
33
|
onChange(item.value);
|
|
30
34
|
};
|
|
31
35
|
// decorator
|
|
32
|
-
const getDepends = getDependsTrigger => {
|
|
33
|
-
const newOnChange = e => {
|
|
36
|
+
const getDepends = (getDependsTrigger) => {
|
|
37
|
+
const newOnChange = (e) => {
|
|
34
38
|
if (e.value === 'open_modal') {
|
|
35
39
|
onChange('open_modal');
|
|
36
40
|
} else {
|
|
@@ -43,34 +47,34 @@ const Dropdown = ({ options = [], value, error, onChange, placeholder, className
|
|
|
43
47
|
{
|
|
44
48
|
label: `New ${entity}`,
|
|
45
49
|
value: 'open_modal',
|
|
46
|
-
className: 'dropdown__list-item--modal'
|
|
50
|
+
className: 'dropdown__list-item--modal',
|
|
47
51
|
},
|
|
48
|
-
...filteredOptions
|
|
52
|
+
...filteredOptions,
|
|
49
53
|
];
|
|
50
54
|
|
|
51
55
|
return {
|
|
52
|
-
onChange: changeItem => (getDependsTrigger ? newOnChange(changeItem) : onChangeHandler(changeItem)),
|
|
53
|
-
options: getDependsTrigger ? newOptions : options
|
|
56
|
+
onChange: (changeItem) => (getDependsTrigger ? newOnChange(changeItem) : onChangeHandler(changeItem)),
|
|
57
|
+
options: getDependsTrigger ? newOptions : options,
|
|
54
58
|
};
|
|
55
59
|
};
|
|
56
60
|
|
|
57
|
-
const handleClickOutside = event => {
|
|
61
|
+
const handleClickOutside = (event) => {
|
|
58
62
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
59
63
|
setIsOpen(false);
|
|
60
64
|
setSearchValue(null);
|
|
61
65
|
}
|
|
62
66
|
};
|
|
63
67
|
|
|
64
|
-
const onSearchHandler = name => {
|
|
68
|
+
const onSearchHandler = (name) => {
|
|
65
69
|
setSearchValue(name);
|
|
66
70
|
};
|
|
67
71
|
|
|
68
|
-
const hightlightedText = text =>
|
|
69
|
-
searchValue ? text?.replace(new RegExp(searchValue, 'i'), match => `<span class="bg--yellow">${match}</span>`) : text;
|
|
72
|
+
const hightlightedText = (text) =>
|
|
73
|
+
searchValue ? text?.replace(new RegExp(searchValue, 'i'), (match) => `<span class="bg--yellow">${match}</span>`) : text;
|
|
70
74
|
|
|
71
75
|
const depend = getDepends(modalBtnTrigger);
|
|
72
76
|
|
|
73
|
-
const getMarkupForElement = item =>
|
|
77
|
+
const getMarkupForElement = (item) =>
|
|
74
78
|
item.label.toLowerCase().includes(searchValue?.toLowerCase() || '') ? (
|
|
75
79
|
<button
|
|
76
80
|
key={item.value}
|
|
@@ -84,25 +88,51 @@ const Dropdown = ({ options = [], value, error, onChange, placeholder, className
|
|
|
84
88
|
</button>
|
|
85
89
|
) : null;
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
if (!value) setSearchValue(null);
|
|
89
|
-
document.addEventListener('click', handleClickOutside, true);
|
|
90
|
-
return () => document.removeEventListener('click', handleClickOutside, true);
|
|
91
|
-
}, [value]);
|
|
92
|
-
|
|
93
|
-
const filteredOptionList = filteredOption =>
|
|
91
|
+
const filteredOptionList = (filteredOption) =>
|
|
94
92
|
filteredOption.items?.length > 0 ? (
|
|
95
93
|
<div key={filteredOption.value} className={`${RC}-group`}>
|
|
96
94
|
<div className={`${RC}-group__name`}>{filteredOption.label}</div>
|
|
97
|
-
{filteredOption.items.map(el => getMarkupForElement(el))}
|
|
95
|
+
{filteredOption.items.map((el) => getMarkupForElement(el))}
|
|
98
96
|
</div>
|
|
99
97
|
) : null;
|
|
100
98
|
|
|
101
99
|
const selectedLabel =
|
|
102
|
-
options.find(el => el.value === value)?.label ||
|
|
100
|
+
options.find((el) => el.value === value)?.label ||
|
|
101
|
+
options.reduce((acc, item) => acc || item.items?.find((el) => el.value === value)?.label, null);
|
|
102
|
+
|
|
103
|
+
const doScrollCallback = useCallback(
|
|
104
|
+
(e) => {
|
|
105
|
+
const { callback, isWithAnyScrolling } = scrollReactionObj;
|
|
106
|
+
if (callback && typeof callback === 'function') {
|
|
107
|
+
if (isWithAnyScrolling) callback(e);
|
|
108
|
+
else if (e.target.clientHeight + e.target.scrollTop >= e.target.scrollHeight) callback(e);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[filteredOptions]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!value) setSearchValue(null);
|
|
116
|
+
document.addEventListener('click', handleClickOutside, true);
|
|
117
|
+
return () => document.removeEventListener('click', handleClickOutside, true);
|
|
118
|
+
}, [value]);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (scrollReactionObj && typeof scrollReactionObj === 'object' && isOpen && dropdownListRef && dropdownListRef.current) {
|
|
122
|
+
dropdownListRef.current.addEventListener('scroll', doScrollCallback);
|
|
123
|
+
}
|
|
124
|
+
return () => {
|
|
125
|
+
if (scrollReactionObj && typeof scrollReactionObj === 'object') removeEventListener('scroll', doScrollCallback);
|
|
126
|
+
};
|
|
127
|
+
}, [isOpen, dropdownListRef]);
|
|
103
128
|
|
|
104
129
|
return (
|
|
105
|
-
<div
|
|
130
|
+
<div
|
|
131
|
+
className={cn(RC, className, {
|
|
132
|
+
disabled: disabled,
|
|
133
|
+
})}
|
|
134
|
+
ref={dropdownRef}
|
|
135
|
+
>
|
|
106
136
|
<button
|
|
107
137
|
className={`${RC}__trigger input__wrap ${!value ? 'placeholder' : ''} ${error ? 'error' : ''}`}
|
|
108
138
|
onClick={() => (!isSearchable ? setIsOpen(!isOpen) : null)}
|
|
@@ -110,12 +140,12 @@ const Dropdown = ({ options = [], value, error, onChange, placeholder, className
|
|
|
110
140
|
{isSearchable ? (
|
|
111
141
|
<input
|
|
112
142
|
className={`${RC}__input`}
|
|
113
|
-
value={searchValue ||
|
|
114
|
-
onChange={e => {
|
|
143
|
+
value={searchValue || selectedLabel || ''}
|
|
144
|
+
onChange={(e) => {
|
|
115
145
|
onSearchHandler(e.target.value);
|
|
116
146
|
}}
|
|
117
147
|
placeholder={placeholder}
|
|
118
|
-
onFocus={e => {
|
|
148
|
+
onFocus={(e) => {
|
|
119
149
|
e.target.select();
|
|
120
150
|
setIsOpen(true);
|
|
121
151
|
}}
|
|
@@ -128,10 +158,11 @@ const Dropdown = ({ options = [], value, error, onChange, placeholder, className
|
|
|
128
158
|
</span>
|
|
129
159
|
</button>
|
|
130
160
|
{isOpen && filteredOptions.length > 0 && (
|
|
131
|
-
<div className={`${RC}__list`}>
|
|
132
|
-
{depend.options.map(filteredOption =>
|
|
161
|
+
<div className={`${RC}__list`} ref={dropdownListRef}>
|
|
162
|
+
{depend.options.map((filteredOption) =>
|
|
133
163
|
filteredOption.items?.length ? filteredOptionList(filteredOption) : getMarkupForElement(filteredOption)
|
|
134
164
|
)}
|
|
165
|
+
{disabled && isOpen && <DropdownLoader />}
|
|
135
166
|
</div>
|
|
136
167
|
)}
|
|
137
168
|
</div>
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
&__list {
|
|
48
|
+
position: relative;
|
|
48
49
|
background: #ffffff;
|
|
49
50
|
border: 1px solid #e2e5ec;
|
|
50
51
|
box-shadow: 0 5px 20px rgb(0 0 0 / 15%);
|
|
@@ -177,4 +178,9 @@
|
|
|
177
178
|
font-size: 10px;
|
|
178
179
|
color: $color--secondary;
|
|
179
180
|
}
|
|
181
|
+
|
|
182
|
+
&.disabled {
|
|
183
|
+
pointer-events: none;
|
|
184
|
+
opacity: 0.5;
|
|
185
|
+
}
|
|
180
186
|
}
|
|
@@ -20,20 +20,34 @@ export default {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const blockStyles = {
|
|
24
|
+
display: 'flex',
|
|
25
|
+
flexFlow: 'row no-wrap',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const buttonStyles = {
|
|
24
30
|
border: 'solid 1px #000',
|
|
25
|
-
padding: '5px'
|
|
31
|
+
padding: '5px',
|
|
32
|
+
margin: '0 0 0 50px',
|
|
26
33
|
};
|
|
27
34
|
|
|
28
35
|
const Template = (args) => {
|
|
29
|
-
const [value, setValue] = useState(
|
|
36
|
+
const [value, setValue] = useState(args.value);
|
|
37
|
+
const [disabled, setDisabled] = useState(false);
|
|
30
38
|
return (
|
|
31
|
-
|
|
32
|
-
<div style={{ width: 200 }}>
|
|
33
|
-
<Dropdown {...args} value={value} onChange={setValue} />
|
|
39
|
+
<div style={blockStyles}>
|
|
40
|
+
<div key="dropdown" style={{ width: 200 }}>
|
|
41
|
+
<Dropdown {...args} value={value} onChange={setValue} disabled={disabled} scrollReactionObj={{ callback: (e) => setDisabled(true) }} />
|
|
34
42
|
</div>
|
|
35
|
-
<button style={buttonStyles} className=
|
|
36
|
-
|
|
43
|
+
<button key="reset" style={buttonStyles} className="mt10" onClick={() => setValue('')}>
|
|
44
|
+
Reset
|
|
45
|
+
</button>
|
|
46
|
+
|
|
47
|
+
<button key="enable/disable" style={buttonStyles} className="mt10" onClick={() => setDisabled(!disabled)}>
|
|
48
|
+
{disabled ? 'enable' : 'disable'}
|
|
49
|
+
</button>
|
|
50
|
+
</div>
|
|
37
51
|
);
|
|
38
52
|
};
|
|
39
53
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Loader.scss';
|
|
3
|
+
|
|
4
|
+
const DropdownLoader = function () {
|
|
5
|
+
return (
|
|
6
|
+
<div className="dropdown-loader-box j5">
|
|
7
|
+
<div className={`lds-ring${variant === 'little' ? ' lds-ring_little' : ''}`}>
|
|
8
|
+
<div />
|
|
9
|
+
<div />
|
|
10
|
+
<div />
|
|
11
|
+
<div />
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default DropdownLoader;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
@mixin fill-parent {
|
|
2
|
+
left: 0;
|
|
3
|
+
top: 0;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dropdown-loader-box {
|
|
9
|
+
position: absolute;
|
|
10
|
+
@include fill-parent;
|
|
11
|
+
background: #fff;
|
|
12
|
+
opacity: 0.1;
|
|
13
|
+
z-index: 100;
|
|
14
|
+
}
|
|
15
|
+
.lds-ring {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
position: relative;
|
|
18
|
+
width: 100px;
|
|
19
|
+
height: 100px;
|
|
20
|
+
}
|
|
21
|
+
.lds-ring.lds-ring_little {
|
|
22
|
+
width: 20px;
|
|
23
|
+
height: 20px;
|
|
24
|
+
}
|
|
25
|
+
.lds-ring div {
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
display: block;
|
|
28
|
+
position: absolute;
|
|
29
|
+
width: 84px;
|
|
30
|
+
height: 84px;
|
|
31
|
+
margin: 8px;
|
|
32
|
+
border: 8px solid #000;
|
|
33
|
+
border-radius: 50%;
|
|
34
|
+
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
35
|
+
border-color: #000 transparent transparent transparent;
|
|
36
|
+
}
|
|
37
|
+
.lds-ring_little div {
|
|
38
|
+
width: 20px;
|
|
39
|
+
height: 20px;
|
|
40
|
+
}
|
|
41
|
+
.lds-ring div:nth-child(1) {
|
|
42
|
+
animation-delay: -0.45s;
|
|
43
|
+
}
|
|
44
|
+
.lds-ring div:nth-child(2) {
|
|
45
|
+
animation-delay: -0.3s;
|
|
46
|
+
}
|
|
47
|
+
.lds-ring div:nth-child(3) {
|
|
48
|
+
animation-delay: -0.15s;
|
|
49
|
+
}
|
|
50
|
+
@keyframes lds-ring {
|
|
51
|
+
0% {
|
|
52
|
+
transform: rotate(0deg);
|
|
53
|
+
}
|
|
54
|
+
100% {
|
|
55
|
+
transform: rotate(360deg);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -29,7 +29,7 @@ const Input = ({
|
|
|
29
29
|
icon,
|
|
30
30
|
symbolsLimit,
|
|
31
31
|
blinkTime,
|
|
32
|
-
isFocusDefault = false
|
|
32
|
+
isFocusDefault = false,
|
|
33
33
|
}) => {
|
|
34
34
|
const DEFAULT_BLINK_TIME = 100;
|
|
35
35
|
// STATES
|
|
@@ -42,6 +42,8 @@ const Input = ({
|
|
|
42
42
|
|
|
43
43
|
const { onlyNumbers, onlyString } = formatInput;
|
|
44
44
|
const { addCommas, removeComma } = formatInput.priceInput;
|
|
45
|
+
const isUseErrorsBlink = !isNotBlinkErrors && !mask;
|
|
46
|
+
|
|
45
47
|
// HANDLES
|
|
46
48
|
const handle = {
|
|
47
49
|
change: (e) => {
|
|
@@ -50,8 +52,7 @@ const Input = ({
|
|
|
50
52
|
inputValue = inputValue.substring(0, +symbolsLimit);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
if (isOnlyNumber && !isTwoDigitAfterDot)
|
|
54
|
-
inputValue = onlyNumbers(inputValue);
|
|
55
|
+
if (isOnlyNumber && !isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue);
|
|
55
56
|
if (isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue, true);
|
|
56
57
|
if (isOnlyString) inputValue = onlyString(inputValue);
|
|
57
58
|
|
|
@@ -79,28 +80,47 @@ const Input = ({
|
|
|
79
80
|
if (onBlur) onBlur(e);
|
|
80
81
|
},
|
|
81
82
|
keyUp: (e) => {
|
|
82
|
-
if (
|
|
83
|
+
if (isUseErrorsBlink) {
|
|
83
84
|
const changedValue = '' + (value ?? '');
|
|
84
85
|
const previousValue = '' + (previousValueRef.current ?? '');
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
|
|
87
|
+
const short = previousValue.length <= changedValue.length ? previousValue : changedValue;
|
|
88
|
+
const long = previousValue.length > changedValue.length ? previousValue : changedValue;
|
|
89
|
+
|
|
90
|
+
const infoAboutDifferencesSameness = short.split('').reduce(
|
|
91
|
+
(acc, symbol, idx) => {
|
|
92
|
+
if (acc.countOn && symbol === long[idx]) acc.same.push(symbol);
|
|
93
|
+
else {
|
|
94
|
+
acc.countOn = false;
|
|
95
|
+
acc.differences.push([idx, symbol]);
|
|
96
|
+
}
|
|
97
|
+
return acc;
|
|
98
|
+
},
|
|
99
|
+
{ same: [], countOn: true, differences: [] }
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const samePart = infoAboutDifferencesSameness.same.join('');
|
|
103
|
+
const differencesLength = infoAboutDifferencesSameness.differences.length;
|
|
104
|
+
const currentSet = changedValue.replace(samePart, '');
|
|
105
|
+
|
|
106
|
+
const getNext = (inputPartToAdd, correctedSamePart) => {
|
|
107
|
+
const partToAdd = inputPartToAdd || currentSet;
|
|
108
|
+
const currentSamePart = correctedSamePart || samePart;
|
|
109
|
+
return changedValue.includes(e.key) && e.key !== changedValue[changedValue.length - 1]
|
|
110
|
+
? currentSamePart + (partToAdd[0] || '')
|
|
111
|
+
: changedValue;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (!KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue)
|
|
115
|
+
setIsAttemptToChange(!(!differencesLength && e.key === changedValue[changedValue.length - 2]));
|
|
116
|
+
|
|
117
|
+
if (!previousValueRef.current || KEYBOARD_SERVICE_KEYS.includes(e.key)) previousValueRef.current = getNext();
|
|
118
|
+
else if (changedValue === samePart) previousValueRef.current = getNext(changedValue, changedValue.slice(0, -1));
|
|
119
|
+
else previousValueRef.current = getNext();
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
if (onKeyUp) onKeyUp(e.keyCode, e);
|
|
103
|
-
}
|
|
123
|
+
},
|
|
104
124
|
};
|
|
105
125
|
|
|
106
126
|
function cutOffsingleDot(value) {
|
|
@@ -121,7 +141,7 @@ const Input = ({
|
|
|
121
141
|
onBlur: handle.blur,
|
|
122
142
|
onKeyUp: handle.keyUp,
|
|
123
143
|
...(maskChar ? { maskChar } : {}),
|
|
124
|
-
...(formatChars ? { formatChars } : {})
|
|
144
|
+
...(formatChars ? { formatChars } : {}),
|
|
125
145
|
};
|
|
126
146
|
|
|
127
147
|
function renderInput() {
|
|
@@ -129,13 +149,11 @@ const Input = ({
|
|
|
129
149
|
return <InputMask {...uniProps} ref={inputRef} mask={mask} />;
|
|
130
150
|
}
|
|
131
151
|
|
|
132
|
-
return
|
|
133
|
-
<input {...uniProps} ref={inputRef} type={isPriceInput ? 'text' : type} />
|
|
134
|
-
);
|
|
152
|
+
return <input {...uniProps} ref={inputRef} type={isPriceInput ? 'text' : type} />;
|
|
135
153
|
}
|
|
136
154
|
|
|
137
155
|
useEffect(() => {
|
|
138
|
-
if (
|
|
156
|
+
if (isUseErrorsBlink && isAttemptToChange) {
|
|
139
157
|
setIsAttemptToChange(null);
|
|
140
158
|
setIsToHighlightError(true);
|
|
141
159
|
setTimeout(() => {
|
|
@@ -145,8 +163,8 @@ const Input = ({
|
|
|
145
163
|
}, [isAttemptToChange]);
|
|
146
164
|
|
|
147
165
|
useEffect(() => {
|
|
148
|
-
if (inputRef?.current && typeof isFocusDefault === 'boolean')
|
|
149
|
-
|
|
166
|
+
if (inputRef?.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
167
|
+
setEditing(isFocusDefault);
|
|
150
168
|
}, [inputRef, isFocusDefault]);
|
|
151
169
|
|
|
152
170
|
return (
|
|
@@ -160,12 +178,7 @@ const Input = ({
|
|
|
160
178
|
>
|
|
161
179
|
{renderInput()}
|
|
162
180
|
{icon}
|
|
163
|
-
{withDelete && (
|
|
164
|
-
<span
|
|
165
|
-
className={cn(`input__close`, { hidden: !value })}
|
|
166
|
-
onClick={handle.toggleEdit}
|
|
167
|
-
/>
|
|
168
|
-
)}
|
|
181
|
+
{withDelete && <span className={cn(`input__close`, { hidden: !value })} onClick={handle.toggleEdit} />}
|
|
169
182
|
</div>
|
|
170
183
|
);
|
|
171
184
|
};
|
|
@@ -18,6 +18,14 @@ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', plac
|
|
|
18
18
|
if (onChange) onChange(val);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
const getCalendarValue = (value) => {
|
|
22
|
+
const date = moment(value).format('L');
|
|
23
|
+
|
|
24
|
+
if(date !== "Invalid date") return date;
|
|
25
|
+
|
|
26
|
+
return moment(new Date()).format('L');
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
return (
|
|
22
30
|
<div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
|
|
23
31
|
<InputMask
|
|
@@ -28,7 +36,7 @@ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', plac
|
|
|
28
36
|
className="calendar-dropdown"
|
|
29
37
|
onFocus={() => setIsOpened(!isOpened)}
|
|
30
38
|
/>
|
|
31
|
-
{isOpened ? <Calendar date={
|
|
39
|
+
{isOpened ? <Calendar date={getCalendarValue(value)} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
|
|
32
40
|
</div>
|
|
33
41
|
);
|
|
34
42
|
};
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { useRef, useState } from 'react';
|
|
3
|
-
import { ref } from 'yup';
|
|
1
|
+
import React, { useState } from 'react';
|
|
4
2
|
import InputCalendar from './InputCalendar';
|
|
5
3
|
|
|
6
4
|
global.lng = 'en';
|
|
7
5
|
|
|
6
|
+
|
|
8
7
|
export default {
|
|
9
|
-
title: 'Form Elements/
|
|
8
|
+
title: 'Form Elements/Input Calendar',
|
|
10
9
|
component: InputCalendar,
|
|
10
|
+
argTypes: {
|
|
11
|
+
value: {
|
|
12
|
+
description: 'string (mm.dd.yyyy)'
|
|
13
|
+
},
|
|
14
|
+
}
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
const [date, setDate] = useState('');
|
|
14
|
-
|
|
15
17
|
const Template = args => {
|
|
16
|
-
|
|
18
|
+
const [date, setDate] = useState('');
|
|
19
|
+
|
|
20
|
+
return <InputCalendar {...args} value={date} onChange={val => setDate(val)} />;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
|
-
export const
|
|
23
|
+
export const CalendarTemplate = Template.bind({});
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
CalendarTemplate.args = {
|
|
22
26
|
value: '',
|
|
23
27
|
minDate: '10/14/2020',
|
|
24
28
|
maxDate: '10/14/2022',
|
|
25
|
-
|
|
29
|
+
|
|
26
30
|
};
|
|
@@ -24,6 +24,8 @@ const InputDateRange = props => {
|
|
|
24
24
|
hideArrows = false,
|
|
25
25
|
isOptionsRight,
|
|
26
26
|
isUseAbs,
|
|
27
|
+
minDate = null,
|
|
28
|
+
maxDate = null,
|
|
27
29
|
} = props;
|
|
28
30
|
|
|
29
31
|
const actualValues = getActualDateRange(value);
|
|
@@ -35,6 +37,7 @@ const InputDateRange = props => {
|
|
|
35
37
|
const internalContainerRef = useRef(null);
|
|
36
38
|
|
|
37
39
|
const handleChange = input => {
|
|
40
|
+
|
|
38
41
|
const newValue = getActualDateRange(input);
|
|
39
42
|
const formatedValue = {
|
|
40
43
|
intervalKey: newValue.intervalKey,
|
|
@@ -202,6 +205,8 @@ const InputDateRange = props => {
|
|
|
202
205
|
setIsCompare={setIsCompare}
|
|
203
206
|
toggleOff={toggleOff}
|
|
204
207
|
onChange={handleChange}
|
|
208
|
+
minDate={minDate ? moment(minDate) : null}
|
|
209
|
+
maxDate={maxDate ? moment(maxDate) : null}
|
|
205
210
|
/>
|
|
206
211
|
)}
|
|
207
212
|
</div>
|