intelicoreact 0.0.6 → 0.0.9
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/CheckboxInput/CheckboxInput.js +6 -2
- package/dist/Atomic/FormElements/CheckboxInput/CheckboxInput.scss +91 -60
- package/dist/Atomic/FormElements/CheckboxInput/CheckboxInput.stories.js +2 -1
- package/dist/Atomic/FormElements/Dropdown/Dropdown.js +84 -28
- package/dist/Atomic/FormElements/Dropdown/Dropdown.scss +27 -3
- package/dist/Atomic/FormElements/Dropdown/Dropdown.stories.js +50 -7
- package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.js +20 -0
- package/dist/Atomic/FormElements/Dropdown/components/Loader.scss +57 -0
- package/dist/Atomic/FormElements/Input/Input.js +124 -50
- package/dist/Atomic/FormElements/Input/Input.stories.js +19 -15
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +33 -31
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +29 -19
- package/dist/Atomic/FormElements/InputDateRange/{components/InputDateRange.js → InputDateRange.js} +54 -62
- package/dist/Atomic/FormElements/InputDateRange/{components/InputDateRange.scss → InputDateRange.scss} +254 -228
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +15 -160
- package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +72 -34
- package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +26 -11
- package/dist/Atomic/FormElements/InputDateRange/components/SelectItem.js +14 -6
- package/dist/Atomic/FormElements/InputDateRange/{index.js → dependencies.js} +19 -18
- package/dist/Atomic/FormElements/NumericInput/NumericInput.js +292 -0
- package/dist/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
- package/dist/Atomic/FormElements/NumericInput/NumericInput.stories.js +117 -0
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +10 -3
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +4 -4
- package/dist/Atomic/FormElements/Table/Table.scss +1 -1
- package/dist/Atomic/FormElements/Textarea/Textarea.scss +1 -1
- package/dist/Atomic/MainMenu/MainMenu.scss +2 -2
- package/dist/Atomic/UI/Accordion/Accordion.scss +2 -2
- package/dist/Atomic/UI/Arrow/Arrow.js +6 -6
- package/dist/Atomic/UI/Arrow/Arrow.scss +0 -3
- package/dist/Atomic/UI/Calendar/Calendar.js +8 -5
- package/dist/Atomic/UI/Calendar/Calendar.scss +19 -3
- package/dist/Atomic/UI/Calendar/Calendar.stories.js +3 -2
- package/dist/Atomic/UI/Status/Status.scss +1 -1
- package/dist/Constants/index.constants.js +8 -0
- package/dist/Functions/inputExecutor.js +58 -0
- package/dist/Molecular/Datepicker/Datepicker.js +451 -0
- package/dist/Molecular/Datepicker/Datepicker.scss +8 -0
- package/dist/Molecular/Datepicker/Datepicker.stories.js +44 -0
- package/dist/{Atomic/FormElements/Calendar → Molecular/Datepicker/components}/Calendar.js +50 -39
- package/dist/scss/_vars.scss +3 -1
- package/dist/scss/main.scss +1 -1
- package/package.json +5 -4
- package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.js +12 -2
- package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.scss +91 -60
- package/src/Atomic/FormElements/CheckboxInput/CheckboxInput.stories.js +4 -3
- package/src/Atomic/FormElements/Dropdown/Dropdown.js +104 -39
- package/src/Atomic/FormElements/Dropdown/Dropdown.scss +27 -3
- package/src/Atomic/FormElements/Dropdown/Dropdown.stories.js +42 -15
- package/src/Atomic/FormElements/Dropdown/components/DropdownLoader.js +16 -0
- package/src/Atomic/FormElements/Dropdown/components/Loader.scss +57 -0
- package/src/Atomic/FormElements/Input/Input.js +108 -37
- package/src/Atomic/FormElements/Input/Input.stories.js +43 -22
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +18 -17
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +17 -14
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +219 -0
- package/src/Atomic/FormElements/InputDateRange/{components/InputDateRange.scss → InputDateRange.scss} +254 -228
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +38 -117
- package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +92 -53
- package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +14 -5
- package/src/Atomic/FormElements/InputDateRange/components/SelectItem.js +5 -3
- package/src/Atomic/FormElements/InputDateRange/{index.js → dependencies.js} +16 -12
- package/src/Atomic/FormElements/NumericInput/NumericInput.js +263 -0
- package/src/Atomic/FormElements/NumericInput/NumericInput.scss +135 -0
- package/src/Atomic/FormElements/NumericInput/NumericInput.stories.js +78 -0
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +6 -3
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +4 -4
- package/src/Atomic/FormElements/Table/Table.scss +1 -1
- package/src/Atomic/FormElements/Textarea/Textarea.scss +1 -1
- package/src/Atomic/MainMenu/MainMenu.scss +2 -2
- package/src/Atomic/UI/Accordion/Accordion.scss +2 -2
- package/src/Atomic/UI/Arrow/Arrow.js +4 -4
- package/src/Atomic/UI/Arrow/Arrow.scss +0 -3
- package/src/Atomic/UI/Calendar/Calendar.js +4 -4
- package/src/Atomic/UI/Calendar/Calendar.scss +19 -3
- package/src/Atomic/UI/Calendar/Calendar.stories.js +2 -1
- package/src/Atomic/UI/Status/Status.scss +1 -1
- package/src/Constants/index.constants.js +41 -0
- package/src/Functions/inputExecutor.js +53 -0
- package/src/Functions/utils.js +4 -1
- package/src/Molecular/Datepicker/Datepicker.js +346 -0
- package/src/Molecular/Datepicker/Datepicker.scss +8 -0
- package/src/Molecular/Datepicker/Datepicker.stories.js +27 -0
- package/src/Molecular/Datepicker/components/Calendar.js +118 -0
- package/src/scss/_vars.scss +3 -1
- package/src/scss/main.scss +1 -1
- package/dist/Atomic/FormElements/Calendar/Calendar.scss +0 -543
- package/dist/Atomic/FormElements/Calendar/Calendar.stories.js +0 -33
- package/dist/scss/anme/_anme-bootstrap-grid.scss +0 -748
- package/dist/scss/anme/_anme-elements.scss +0 -269
- package/dist/scss/anme/_anme-grid.scss +0 -111
- package/dist/scss/anme/_anme-justify.scss +0 -111
- package/dist/scss/anme/_anme-mixins-media.scss +0 -116
- package/dist/scss/anme/_anme-mixins.scss +0 -166
- package/dist/scss/anme/_anme-normalize.scss +0 -8
- package/dist/scss/anme/_anme-overall.scss +0 -34
- package/dist/scss/anme/_anme-padding-margins.scss +0 -419
- package/dist/scss/anme/_anme-table.scss +0 -81
- package/dist/scss/anme/_anme-theme.scss +0 -275
- package/dist/scss/anme/_anme-vars.scss +0 -91
- package/dist/scss/anme/_code-styling.scss +0 -23
- package/dist/scss/anme/styles.scss +0 -12
- package/src/Atomic/FormElements/InputDateRange/components/InputDateRange.js +0 -230
- package/src/scss/anme/_anme-bootstrap-grid.scss +0 -748
- package/src/scss/anme/_anme-elements.scss +0 -269
- package/src/scss/anme/_anme-grid.scss +0 -111
- package/src/scss/anme/_anme-justify.scss +0 -111
- package/src/scss/anme/_anme-mixins-media.scss +0 -116
- package/src/scss/anme/_anme-mixins.scss +0 -166
- package/src/scss/anme/_anme-normalize.scss +0 -8
- package/src/scss/anme/_anme-overall.scss +0 -34
- package/src/scss/anme/_anme-padding-margins.scss +0 -419
- package/src/scss/anme/_anme-table.scss +0 -81
- package/src/scss/anme/_anme-theme.scss +0 -275
- package/src/scss/anme/_anme-vars.scss +0 -91
- package/src/scss/anme/_code-styling.scss +0 -23
- package/src/scss/anme/styles.scss +0 -12
|
@@ -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
|
+
}
|
|
@@ -1,62 +1,132 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import { Minus, Plus } from 'react-feather';
|
|
4
3
|
import InputMask from 'react-input-mask';
|
|
4
|
+
import { KEYBOARD_SERVICE_KEYS } from '../../../Constants/index.constants';
|
|
5
|
+
import { formatInput } from '../../../Functions/inputExecutor';
|
|
5
6
|
|
|
6
7
|
import './Input.scss';
|
|
7
8
|
|
|
8
9
|
const Input = ({
|
|
9
10
|
onChange,
|
|
11
|
+
onBlur,
|
|
12
|
+
onFocus,
|
|
13
|
+
onKeyUp,
|
|
14
|
+
isNotBlinkErrors,
|
|
15
|
+
isPriceInput,
|
|
16
|
+
isOnlyNumber,
|
|
17
|
+
isOnlyString,
|
|
18
|
+
isTwoDigitAfterDot,
|
|
10
19
|
disabled,
|
|
11
20
|
withDelete,
|
|
12
|
-
isNumeric,
|
|
13
|
-
numStep = 1,
|
|
14
|
-
min = 0,
|
|
15
|
-
max,
|
|
16
21
|
value,
|
|
17
22
|
placeholder,
|
|
18
23
|
className,
|
|
19
24
|
type = 'text',
|
|
20
|
-
onBlur,
|
|
21
|
-
onFocus,
|
|
22
|
-
onKeyUp,
|
|
23
25
|
mask,
|
|
26
|
+
maskChar,
|
|
27
|
+
formatChars,
|
|
24
28
|
error,
|
|
25
29
|
icon,
|
|
26
30
|
symbolsLimit,
|
|
31
|
+
blinkTime,
|
|
32
|
+
isFocusDefault = false,
|
|
27
33
|
}) => {
|
|
34
|
+
const DEFAULT_BLINK_TIME = 100;
|
|
28
35
|
// STATES
|
|
29
36
|
const [isFocused, setIsFocused] = useState(false);
|
|
30
37
|
const [isEditing, setEditing] = useState(false);
|
|
31
38
|
const inputRef = useRef(null);
|
|
39
|
+
const previousValueRef = useRef(value);
|
|
40
|
+
const [isAttemptToChange, setIsAttemptToChange] = useState(false);
|
|
41
|
+
const [isToHighlightError, setIsToHighlightError] = useState(false);
|
|
42
|
+
|
|
43
|
+
const { onlyNumbers, onlyString } = formatInput;
|
|
44
|
+
const { addCommas, removeComma } = formatInput.priceInput;
|
|
45
|
+
const isUseErrorsBlink = !isNotBlinkErrors && !mask;
|
|
46
|
+
|
|
32
47
|
// HANDLES
|
|
33
48
|
const handle = {
|
|
34
|
-
change: e => {
|
|
49
|
+
change: (e) => {
|
|
35
50
|
let inputValue = e.target ? e.target.value : e;
|
|
36
|
-
if (
|
|
37
|
-
inputValue =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
if (symbolsLimit && inputValue.length > +symbolsLimit) {
|
|
52
|
+
inputValue = inputValue.substring(0, +symbolsLimit);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isOnlyNumber && !isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue);
|
|
56
|
+
if (isTwoDigitAfterDot) inputValue = onlyNumbers(inputValue, true);
|
|
57
|
+
if (isOnlyString) inputValue = onlyString(inputValue);
|
|
58
|
+
|
|
42
59
|
onChange(inputValue.toString());
|
|
43
60
|
},
|
|
44
61
|
toggleEdit: () => {
|
|
45
62
|
setEditing(!isEditing);
|
|
46
63
|
onChange('');
|
|
47
64
|
},
|
|
48
|
-
focus: e => {
|
|
65
|
+
focus: (e) => {
|
|
49
66
|
setIsFocused(true);
|
|
67
|
+
if (isPriceInput && isOnlyNumber) onChange(removeComma(value));
|
|
68
|
+
|
|
50
69
|
if (onFocus) onFocus(e);
|
|
51
70
|
},
|
|
52
|
-
blur: e => {
|
|
71
|
+
blur: (e) => {
|
|
53
72
|
setIsFocused(false);
|
|
54
73
|
setEditing(false);
|
|
74
|
+
if (isTwoDigitAfterDot) {
|
|
75
|
+
onChange(cutOffsingleDot(value));
|
|
76
|
+
}
|
|
77
|
+
if (isPriceInput && isOnlyNumber) {
|
|
78
|
+
onChange(addCommas(value));
|
|
79
|
+
}
|
|
55
80
|
if (onBlur) onBlur(e);
|
|
56
81
|
},
|
|
57
|
-
keyUp:
|
|
82
|
+
keyUp: (e) => {
|
|
83
|
+
if (isUseErrorsBlink) {
|
|
84
|
+
const changedValue = '' + (value ?? '');
|
|
85
|
+
const previousValue = '' + (previousValueRef.current ?? '');
|
|
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();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (onKeyUp) onKeyUp(e.keyCode, e);
|
|
123
|
+
},
|
|
58
124
|
};
|
|
59
125
|
|
|
126
|
+
function cutOffsingleDot(value) {
|
|
127
|
+
return value.toString().slice(-1) === '.' ? value.slice(0, -1) : value;
|
|
128
|
+
}
|
|
129
|
+
|
|
60
130
|
useEffect(() => {
|
|
61
131
|
if (isEditing) inputRef.current.focus();
|
|
62
132
|
}, [isEditing, isFocused]);
|
|
@@ -70,8 +140,8 @@ const Input = ({
|
|
|
70
140
|
onFocus: handle.focus,
|
|
71
141
|
onBlur: handle.blur,
|
|
72
142
|
onKeyUp: handle.keyUp,
|
|
73
|
-
|
|
74
|
-
|
|
143
|
+
...(maskChar ? { maskChar } : {}),
|
|
144
|
+
...(formatChars ? { formatChars } : {}),
|
|
75
145
|
};
|
|
76
146
|
|
|
77
147
|
function renderInput() {
|
|
@@ -79,35 +149,36 @@ const Input = ({
|
|
|
79
149
|
return <InputMask {...uniProps} ref={inputRef} mask={mask} />;
|
|
80
150
|
}
|
|
81
151
|
|
|
82
|
-
return
|
|
83
|
-
<>
|
|
84
|
-
<input {...uniProps} ref={inputRef} type={isNumeric ? 'number' : type} />
|
|
85
|
-
{isNumeric && (
|
|
86
|
-
<div className="input__nums">
|
|
87
|
-
<button onClick={() => handle.change(value - numStep)} className={cn(`input__num-btn`, { disabled: value <= min })}>
|
|
88
|
-
<Minus />
|
|
89
|
-
</button>
|
|
90
|
-
<button onClick={() => handle.change(+value + +numStep)} className={cn(`input__num-btn`, { disabled: value >= max })}>
|
|
91
|
-
<Plus />
|
|
92
|
-
</button>
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
</>
|
|
96
|
-
);
|
|
152
|
+
return <input {...uniProps} ref={inputRef} type={isPriceInput ? 'text' : type} />;
|
|
97
153
|
}
|
|
98
154
|
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (isUseErrorsBlink && isAttemptToChange) {
|
|
157
|
+
setIsAttemptToChange(null);
|
|
158
|
+
setIsToHighlightError(true);
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
setIsToHighlightError(false);
|
|
161
|
+
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
162
|
+
}
|
|
163
|
+
}, [isAttemptToChange]);
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (inputRef?.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
167
|
+
setEditing(isFocusDefault);
|
|
168
|
+
}, [inputRef, isFocusDefault]);
|
|
169
|
+
|
|
99
170
|
return (
|
|
100
171
|
<div
|
|
101
172
|
className={cn(
|
|
102
173
|
`input__wrap`,
|
|
103
174
|
{ [`input__wrap_focus`]: isFocused },
|
|
104
|
-
{ [`input__wrap_error`]: error },
|
|
175
|
+
{ [`input__wrap_error`]: error || isToHighlightError },
|
|
105
176
|
{ [`input__wrap_disabled`]: disabled }
|
|
106
177
|
)}
|
|
107
178
|
>
|
|
108
179
|
{renderInput()}
|
|
109
180
|
{icon}
|
|
110
|
-
{withDelete &&
|
|
181
|
+
{withDelete && <span className={cn(`input__close`, { hidden: !value })} onClick={handle.toggleEdit} />}
|
|
111
182
|
</div>
|
|
112
183
|
);
|
|
113
184
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {User} from 'react-feather';
|
|
2
|
+
import { User } from 'react-feather';
|
|
3
3
|
import Input from './Input';
|
|
4
4
|
|
|
5
5
|
global.lng = 'en';
|
|
@@ -9,48 +9,68 @@ export default {
|
|
|
9
9
|
component: Input,
|
|
10
10
|
argTypes: {
|
|
11
11
|
disabled: {
|
|
12
|
-
description: 'boolean'
|
|
12
|
+
description: 'boolean'
|
|
13
13
|
},
|
|
14
14
|
error: {
|
|
15
15
|
description: 'text - coloring input if is errored'
|
|
16
16
|
},
|
|
17
|
+
isPriceInput: {
|
|
18
|
+
description: 'boolean - if true, the input will be styled as PriceInput'
|
|
19
|
+
},
|
|
17
20
|
withDelete: {
|
|
18
21
|
description: 'boolean - add clear-cross by hover'
|
|
19
22
|
},
|
|
20
|
-
|
|
21
|
-
description: 'boolean -
|
|
23
|
+
isOnlyNumber: {
|
|
24
|
+
description: 'boolean - only numbers'
|
|
22
25
|
},
|
|
23
|
-
|
|
24
|
-
description: '
|
|
26
|
+
isOnlyString: {
|
|
27
|
+
description: 'boolean - only strings'
|
|
25
28
|
},
|
|
26
|
-
|
|
27
|
-
description: '
|
|
29
|
+
isTwoDigitAfterDot: {
|
|
30
|
+
description: 'boolean - only two digits after dot'
|
|
28
31
|
},
|
|
29
|
-
|
|
30
|
-
description: '
|
|
32
|
+
isFocusDefault: {
|
|
33
|
+
description: 'boolean - if true, input will be focused on mount'
|
|
31
34
|
},
|
|
32
35
|
placeholder: {
|
|
33
36
|
description: 'text'
|
|
34
37
|
},
|
|
35
38
|
type: {
|
|
36
|
-
description:
|
|
39
|
+
description:
|
|
40
|
+
"'text', 'number', 'password', 'color', 'date', 'datetime-local', 'month', 'time', 'email', 'range'",
|
|
37
41
|
control: {
|
|
38
42
|
type: 'select',
|
|
39
|
-
options: [
|
|
43
|
+
options: [
|
|
44
|
+
'text',
|
|
45
|
+
'number',
|
|
46
|
+
'password',
|
|
47
|
+
'color',
|
|
48
|
+
'date',
|
|
49
|
+
'datetime-local',
|
|
50
|
+
'month',
|
|
51
|
+
'time',
|
|
52
|
+
'email',
|
|
53
|
+
'range'
|
|
54
|
+
]
|
|
40
55
|
}
|
|
41
56
|
},
|
|
42
57
|
icon: { description: 'JSX' },
|
|
43
58
|
value: { description: '(* - required prop)' },
|
|
44
59
|
className: { description: 'string' },
|
|
45
|
-
mask: {
|
|
46
|
-
|
|
60
|
+
mask: {
|
|
61
|
+
description:
|
|
62
|
+
'string: force input to masked https://www.npmjs.com/package/react-input-mask'
|
|
63
|
+
},
|
|
64
|
+
symbolsLimit: {
|
|
65
|
+
description: 'Set limit of symbols in input, overhead will be ignored'
|
|
66
|
+
},
|
|
47
67
|
onBlur: { description: 'custom callback on blur' },
|
|
48
68
|
onFocus: { description: 'custom callback on focus' },
|
|
49
69
|
onKeyUp: { description: 'custom callback on keyup, returns event keyCode' }
|
|
50
70
|
}
|
|
51
71
|
};
|
|
52
72
|
|
|
53
|
-
const Template = args => {
|
|
73
|
+
const Template = (args) => {
|
|
54
74
|
const [value, setValue] = useState('');
|
|
55
75
|
return <Input {...args} value={value} onChange={setValue} />;
|
|
56
76
|
};
|
|
@@ -59,15 +79,16 @@ export const InputTemplate = Template.bind({});
|
|
|
59
79
|
|
|
60
80
|
InputTemplate.args = {
|
|
61
81
|
type: 'text',
|
|
82
|
+
isFocusDefault: false,
|
|
83
|
+
isOnlyNumber: false,
|
|
84
|
+
isOnlyString: false,
|
|
85
|
+
isPriceInput: false,
|
|
86
|
+
isTwoDigitAfterDot: false,
|
|
62
87
|
disabled: false,
|
|
63
88
|
error: '',
|
|
89
|
+
mask: '',
|
|
64
90
|
withDelete: true,
|
|
65
|
-
|
|
66
|
-
numStep: 1,
|
|
67
|
-
min: '0',
|
|
68
|
-
max: '5',
|
|
91
|
+
symbolsLimit: 255,
|
|
69
92
|
placeholder: 'Placeholder',
|
|
70
|
-
|
|
71
|
-
icon: <User />,
|
|
72
|
-
symbolsLimit: 225
|
|
93
|
+
icon: <User />
|
|
73
94
|
};
|
|
@@ -4,38 +4,39 @@ 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(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 =
|
|
16
|
-
if (
|
|
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 =
|
|
25
|
-
|
|
26
|
-
setInputValue(value);
|
|
17
|
+
const changeCalendarDay = val => {
|
|
18
|
+
if (onChange) onChange(val);
|
|
27
19
|
};
|
|
28
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
|
+
|
|
29
29
|
return (
|
|
30
|
-
<div className=
|
|
30
|
+
<div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
|
|
31
31
|
<InputMask
|
|
32
|
-
mask=
|
|
33
|
-
|
|
32
|
+
mask={mask}
|
|
33
|
+
placeholder={placeholder}
|
|
34
|
+
value={value}
|
|
34
35
|
onChange={e => changeInputValue(e.target.value)}
|
|
35
36
|
className="calendar-dropdown"
|
|
36
37
|
onFocus={() => setIsOpened(!isOpened)}
|
|
37
38
|
/>
|
|
38
|
-
{isOpened ? <Calendar date={
|
|
39
|
+
{isOpened ? <Calendar date={getCalendarValue(value)} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
|
|
39
40
|
</div>
|
|
40
41
|
);
|
|
41
42
|
};
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { ref } from 'yup';
|
|
1
|
+
import React, { useState } from 'react';
|
|
3
2
|
import InputCalendar from './InputCalendar';
|
|
4
3
|
|
|
5
4
|
global.lng = 'en';
|
|
6
5
|
|
|
6
|
+
|
|
7
7
|
export default {
|
|
8
|
-
title: 'Form Elements/
|
|
8
|
+
title: 'Form Elements/Input Calendar',
|
|
9
9
|
component: InputCalendar,
|
|
10
|
+
argTypes: {
|
|
11
|
+
value: {
|
|
12
|
+
description: 'string (mm.dd.yyyy)'
|
|
13
|
+
},
|
|
14
|
+
}
|
|
10
15
|
};
|
|
11
16
|
|
|
12
|
-
const Template =
|
|
13
|
-
const
|
|
14
|
-
minDate: args?.minDate,
|
|
15
|
-
maxDate: args?.maxDate,
|
|
16
|
-
};
|
|
17
|
+
const Template = args => {
|
|
18
|
+
const [date, setDate] = useState('');
|
|
17
19
|
|
|
18
|
-
return <InputCalendar
|
|
20
|
+
return <InputCalendar {...args} value={date} onChange={val => setDate(val)} />;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export const
|
|
23
|
+
export const CalendarTemplate = Template.bind({});
|
|
24
|
+
|
|
25
|
+
CalendarTemplate.args = {
|
|
26
|
+
value: '',
|
|
27
|
+
minDate: '10/14/2020',
|
|
28
|
+
maxDate: '10/14/2022',
|
|
22
29
|
|
|
23
|
-
Calendar.args = {
|
|
24
|
-
date: '10/14/2021',
|
|
25
|
-
minDate: '10/11/2021',
|
|
26
|
-
maxDate: '10/25/2021',
|
|
27
30
|
};
|