intelicoreact 0.0.87 → 0.0.93
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 +44 -19
- package/dist/Atomic/FormElements/Dropdown/Dropdown.scss +12 -0
- package/dist/Atomic/FormElements/Dropdown/Dropdown.stories.js +35 -7
- package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.js +24 -0
- package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.scss +57 -0
- package/dist/Atomic/FormElements/Input/Input.js +29 -10
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +10 -3
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.scss +18 -0
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +4 -2
- package/dist/Atomic/UI/Calendar/Calendar.js +87 -15
- package/dist/Atomic/UI/Calendar/Calendar.scss +73 -26
- package/dist/Atomic/UI/Calendar/Calendar.stories.js +20 -3
- package/package.json +1 -2
- package/src/Atomic/FormElements/Dropdown/Dropdown.js +72 -35
- package/src/Atomic/FormElements/Dropdown/Dropdown.scss +12 -0
- package/src/Atomic/FormElements/Dropdown/Dropdown.stories.js +23 -8
- package/src/Atomic/FormElements/Dropdown/components/DropdownLoader.js +17 -0
- package/src/Atomic/FormElements/Dropdown/components/DropdownLoader.scss +57 -0
- package/src/Atomic/FormElements/Input/Input.js +46 -34
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +28 -7
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.scss +18 -0
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +8 -8
- package/src/Atomic/UI/Calendar/Calendar.js +75 -11
- package/src/Atomic/UI/Calendar/Calendar.scss +73 -26
- package/src/Atomic/UI/Calendar/Calendar.stories.js +9 -7
|
@@ -4,27 +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
|
-
|
|
7
|
+
import './InputCalendar.scss';
|
|
8
|
+
|
|
9
|
+
const InputCalendar = ({
|
|
10
|
+
value,
|
|
11
|
+
minDate,
|
|
12
|
+
maxDate,
|
|
13
|
+
onChange,
|
|
14
|
+
className = '',
|
|
15
|
+
placeholder = 'mm/dd/yyyy',
|
|
16
|
+
mask = '99/99/9999',
|
|
17
|
+
isDontLimitFuture,
|
|
18
|
+
isListTop,
|
|
19
|
+
}) => {
|
|
8
20
|
const [isOpened, setIsOpened] = useState(false);
|
|
9
21
|
const calendarRef = useRef(null);
|
|
10
22
|
|
|
11
23
|
useClickOutside(calendarRef, () => setIsOpened(false));
|
|
12
24
|
|
|
13
|
-
const changeInputValue = val => {
|
|
25
|
+
const changeInputValue = (val) => {
|
|
14
26
|
if (onChange) onChange(val);
|
|
15
27
|
};
|
|
16
28
|
|
|
17
|
-
const changeCalendarDay = val => {
|
|
29
|
+
const changeCalendarDay = (val) => {
|
|
18
30
|
if (onChange) onChange(val);
|
|
19
31
|
};
|
|
20
32
|
|
|
21
33
|
const getCalendarValue = (value) => {
|
|
22
34
|
const date = moment(value).format('L');
|
|
23
35
|
|
|
24
|
-
if(date !==
|
|
36
|
+
if (date !== 'Invalid date') return date;
|
|
25
37
|
|
|
26
38
|
return moment(new Date()).format('L');
|
|
27
|
-
}
|
|
39
|
+
};
|
|
28
40
|
|
|
29
41
|
return (
|
|
30
42
|
<div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
|
|
@@ -32,11 +44,20 @@ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', plac
|
|
|
32
44
|
mask={mask}
|
|
33
45
|
placeholder={placeholder}
|
|
34
46
|
value={value}
|
|
35
|
-
onChange={e => changeInputValue(e.target.value)}
|
|
47
|
+
onChange={(e) => changeInputValue(e.target.value)}
|
|
36
48
|
className="calendar-dropdown"
|
|
37
49
|
onFocus={() => setIsOpened(!isOpened)}
|
|
38
50
|
/>
|
|
39
|
-
{isOpened ?
|
|
51
|
+
{isOpened ? (
|
|
52
|
+
<Calendar
|
|
53
|
+
className={isListTop ? '' : ''}
|
|
54
|
+
date={getCalendarValue(value)}
|
|
55
|
+
setDate={(newDate) => changeCalendarDay(newDate)}
|
|
56
|
+
params={{ minDate, maxDate }}
|
|
57
|
+
isDontLimitFuture={isDontLimitFuture}
|
|
58
|
+
isListTop={isListTop}
|
|
59
|
+
/>
|
|
60
|
+
) : null}
|
|
40
61
|
</div>
|
|
41
62
|
);
|
|
42
63
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.calendar-container {
|
|
2
|
+
min-width: 200px;
|
|
3
|
+
position: relative;
|
|
4
|
+
|
|
5
|
+
.calendar {
|
|
6
|
+
position: absolute;
|
|
7
|
+
z-index: 9;
|
|
8
|
+
top: 100%;
|
|
9
|
+
padding: 10px 16px;
|
|
10
|
+
border: 1px solid var(--border-color);
|
|
11
|
+
|
|
12
|
+
&_list-top {
|
|
13
|
+
bottom: calc(100% + 4px);
|
|
14
|
+
top: auto;
|
|
15
|
+
box-shadow: 0 -3px 15px rgb(0 0 0 / 15%);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -3,28 +3,28 @@ import InputCalendar from './InputCalendar';
|
|
|
3
3
|
|
|
4
4
|
global.lng = 'en';
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
export default {
|
|
8
7
|
title: 'Form Elements/Input Calendar',
|
|
9
8
|
component: InputCalendar,
|
|
10
9
|
argTypes: {
|
|
11
10
|
value: {
|
|
12
|
-
description: 'string (mm.dd.yyyy)'
|
|
11
|
+
description: 'string (mm.dd.yyyy)',
|
|
13
12
|
},
|
|
14
|
-
}
|
|
13
|
+
},
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
const Template = args => {
|
|
16
|
+
const Template = (args) => {
|
|
18
17
|
const [date, setDate] = useState('');
|
|
19
18
|
|
|
20
|
-
return <InputCalendar {...args} value={date} onChange={val => setDate(val)} />;
|
|
19
|
+
return <InputCalendar {...args} value={date} onChange={(val) => setDate(val)} />;
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
export const CalendarTemplate = Template.bind({});
|
|
24
23
|
|
|
25
24
|
CalendarTemplate.args = {
|
|
26
25
|
value: '',
|
|
27
|
-
minDate: '
|
|
28
|
-
maxDate: '
|
|
29
|
-
|
|
26
|
+
minDate: '01/01/1900',
|
|
27
|
+
maxDate: '01/01/2100',
|
|
28
|
+
isDontLimitFuture: true,
|
|
29
|
+
// isListTop: true,
|
|
30
30
|
};
|
|
@@ -1,22 +1,31 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState, useRef } from 'react';
|
|
1
2
|
import cn from 'classnames';
|
|
2
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import moment from 'moment';
|
|
4
|
+
import InputMask from 'react-input-mask';
|
|
4
5
|
import { ChevronLeft, ChevronRight } from 'react-feather';
|
|
5
6
|
import './Calendar.scss';
|
|
6
7
|
|
|
7
8
|
export default function (props) {
|
|
8
|
-
const { date, setDate, allowPrev = true, allowNext = true, params, className } = props;
|
|
9
|
-
const { minDate = '01/01/1900', maxDate = moment().format('MM/DD/YYYY') } = params;
|
|
9
|
+
const { date, setDate, allowPrev = true, allowNext = true, params, className, isDontLimitFuture, isListTop } = props;
|
|
10
|
+
// const { minDate = '01/01/1900', maxDate = moment().format('MM/DD/YYYY') } = params;
|
|
11
|
+
const { minDate, maxDate } = params;
|
|
10
12
|
const [days, setDays] = useState({});
|
|
11
13
|
const [showDate, setShowDate] = useState(date);
|
|
14
|
+
const [isChangeYear, setIsChangeYear] = useState(false);
|
|
15
|
+
const [inputYearValue, setInputYearValue] = useState(moment(showDate).format('YYYY'));
|
|
16
|
+
const yearInputRef = useRef(null);
|
|
12
17
|
|
|
13
18
|
const selectedDay = moment(showDate);
|
|
14
19
|
const isError = 'Invalid date';
|
|
15
20
|
|
|
16
|
-
const title = useMemo(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
21
|
+
// const title = useMemo(
|
|
22
|
+
// () => (selectedDay.format('MMM') === isError ? isError : `${selectedDay.format('MMM')} ${moment(showDate).format('YYYY')}`),
|
|
23
|
+
// [date, showDate]
|
|
24
|
+
// );
|
|
25
|
+
|
|
26
|
+
const showMonth = useMemo(() => moment(showDate).format('MMM'), [date, showDate]);
|
|
27
|
+
const showYear = useMemo(() => moment(showDate).format('YYYY'), [date, showDate]);
|
|
28
|
+
|
|
20
29
|
useEffect(() => {
|
|
21
30
|
const result = {};
|
|
22
31
|
const day = selectedDay.startOf('month');
|
|
@@ -43,7 +52,7 @@ export default function (props) {
|
|
|
43
52
|
const classNames = cn(
|
|
44
53
|
'calendar__day',
|
|
45
54
|
{ 'calendar__day--clickable': day },
|
|
46
|
-
{ 'calendar__day--disabled': isFutureDay },
|
|
55
|
+
{ 'calendar__day--disabled': !isDontLimitFuture && isFutureDay },
|
|
47
56
|
{ 'calendar__day--disabled': isBeforeDay },
|
|
48
57
|
{ 'calendar__day--selected': moment(date).format() === moment(day.date).format() }
|
|
49
58
|
);
|
|
@@ -52,7 +61,7 @@ export default function (props) {
|
|
|
52
61
|
<div
|
|
53
62
|
key={`${week}_${dayOfWeek}`}
|
|
54
63
|
className={classNames}
|
|
55
|
-
onClick={day && !isFutureDay ? () => setDate(moment(day.date).format('L')) : null}
|
|
64
|
+
onClick={day && (isDontLimitFuture || !isFutureDay) ? () => setDate(moment(day.date).format('L')) : null}
|
|
56
65
|
// onMouseOver={day && !isFutureDay ? () => onHover(day.date) : null}
|
|
57
66
|
// onMouseLeave={() => onHover(null)}
|
|
58
67
|
>
|
|
@@ -69,8 +78,39 @@ export default function (props) {
|
|
|
69
78
|
setShowDate(moment(showDate).add(1, 'month').format('L'));
|
|
70
79
|
};
|
|
71
80
|
|
|
81
|
+
const closeYearInput = () => {
|
|
82
|
+
const newDate = (() => {
|
|
83
|
+
const dateArr = showDate.split('/');
|
|
84
|
+
const oldYear = dateArr[2];
|
|
85
|
+
dateArr[2] = inputYearValue;
|
|
86
|
+
return moment(dateArr.join('/')).format('MM/DD/YYYY') === isError ? showDate : moment(dateArr.join('/')).format('MM/DD/YYYY');
|
|
87
|
+
})();
|
|
88
|
+
let resultDate = newDate;
|
|
89
|
+
if (minDate && moment(minDate) > moment(newDate)) resultDate = moment(showDate).format('MM/DD/YYYY');
|
|
90
|
+
else if (maxDate && moment(maxDate) < moment(newDate)) resultDate = moment(showDate).format('MM/DD/YYYY');
|
|
91
|
+
|
|
92
|
+
setIsChangeYear(false);
|
|
93
|
+
setShowDate(resultDate);
|
|
94
|
+
setInputYearValue(resultDate);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (isChangeYear && yearInputRef.current) {
|
|
99
|
+
const input = yearInputRef.current.getElementsByTagName('input')[0];
|
|
100
|
+
setInputYearValue(showYear);
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
input.focus();
|
|
103
|
+
input.select();
|
|
104
|
+
}, 0);
|
|
105
|
+
}
|
|
106
|
+
}, [isChangeYear]);
|
|
107
|
+
|
|
72
108
|
return (
|
|
73
|
-
<div
|
|
109
|
+
<div
|
|
110
|
+
className={cn('calendar', className, {
|
|
111
|
+
'calendar_list-top': isListTop,
|
|
112
|
+
})}
|
|
113
|
+
>
|
|
74
114
|
<div className="calendar-header">
|
|
75
115
|
<div className="calendar-header__prev">
|
|
76
116
|
{allowPrev && (
|
|
@@ -79,7 +119,31 @@ export default function (props) {
|
|
|
79
119
|
</div>
|
|
80
120
|
)}
|
|
81
121
|
</div>
|
|
82
|
-
<div className=
|
|
122
|
+
<div className={cn('calendar-header__title')} ref={yearInputRef}>
|
|
123
|
+
<span className="calendar-header__title-month">{`${showMonth} `}</span>
|
|
124
|
+
<span
|
|
125
|
+
className={cn('calendar-header__title-year', {
|
|
126
|
+
'calendar-header__title-year_change-mode': isChangeYear,
|
|
127
|
+
})}
|
|
128
|
+
onClick={() => setIsChangeYear(true)}
|
|
129
|
+
>
|
|
130
|
+
{isChangeYear ? (
|
|
131
|
+
<InputMask
|
|
132
|
+
className="calendar-header__title-year-change-input"
|
|
133
|
+
value={inputYearValue}
|
|
134
|
+
mask="9999"
|
|
135
|
+
onBlur={(e) => closeYearInput()}
|
|
136
|
+
onKeyUp={(e) => {
|
|
137
|
+
if (e.key === 'Escape') setIsChangeYear(false);
|
|
138
|
+
if (e.key === 'Enter') closeYearInput();
|
|
139
|
+
}}
|
|
140
|
+
onChange={(e) => setInputYearValue(e.target.value)}
|
|
141
|
+
/>
|
|
142
|
+
) : (
|
|
143
|
+
`${showYear}`
|
|
144
|
+
)}
|
|
145
|
+
</span>
|
|
146
|
+
</div>
|
|
83
147
|
<div className="calendar-header__next">
|
|
84
148
|
{allowNext && (
|
|
85
149
|
<div onClick={handleNext}>
|
|
@@ -425,23 +425,25 @@
|
|
|
425
425
|
// box-shadow: 0 0 3px 0 rgb(0 123 255 / 50%);
|
|
426
426
|
// }
|
|
427
427
|
// }
|
|
428
|
-
.calendar-header {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
// .calendar-header {
|
|
429
|
+
// display: flex;
|
|
430
|
+
// justify-content: center;
|
|
431
|
+
// align-items: center;
|
|
432
|
+
|
|
433
|
+
// &__prev,
|
|
434
|
+
// &__next {
|
|
435
|
+
// display: flex;
|
|
436
|
+
// height: auto;
|
|
437
|
+
// cursor: pointer;
|
|
438
|
+
// }
|
|
439
|
+
// }
|
|
432
440
|
|
|
433
|
-
&__prev,
|
|
434
|
-
&__next{
|
|
435
|
-
display: flex;
|
|
436
|
-
height: auto;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
441
|
.calendar {
|
|
440
442
|
background: #ffffff;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
443
|
+
border: 1px solid #e2e5ec;
|
|
444
|
+
box-shadow: 0 5px 20px rgb(0 0 0 / 15%);
|
|
445
|
+
margin-top: 4px;
|
|
446
|
+
padding: 5px 0;
|
|
445
447
|
|
|
446
448
|
min-height: 195px;
|
|
447
449
|
width: 260px;
|
|
@@ -449,6 +451,63 @@
|
|
|
449
451
|
flex-direction: column;
|
|
450
452
|
user-select: none;
|
|
451
453
|
|
|
454
|
+
&-header {
|
|
455
|
+
display: flex;
|
|
456
|
+
justify-content: center;
|
|
457
|
+
align-items: center;
|
|
458
|
+
|
|
459
|
+
box-sizing: border-box;
|
|
460
|
+
&__title {
|
|
461
|
+
&-month {
|
|
462
|
+
margin-right: 5px;
|
|
463
|
+
}
|
|
464
|
+
&-year {
|
|
465
|
+
box-sizing: border-box;
|
|
466
|
+
width: 45px;
|
|
467
|
+
height: 100%;
|
|
468
|
+
padding: 0 5px;
|
|
469
|
+
cursor: pointer;
|
|
470
|
+
display: flex;
|
|
471
|
+
flex-flow: row nowrap;
|
|
472
|
+
justify-content: center;
|
|
473
|
+
align-items: center;
|
|
474
|
+
|
|
475
|
+
&:hover:not(.calendar-header__title-year_change-mode) {
|
|
476
|
+
text-decoration: underline;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
&.calendar-header__title-year_change-mode {
|
|
480
|
+
height: 24px;
|
|
481
|
+
padding: 0 3px;
|
|
482
|
+
border-style: solid;
|
|
483
|
+
border-width: 1px;
|
|
484
|
+
border-color: inherit;
|
|
485
|
+
border-radius: var(--border-radius);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
&-change-input {
|
|
489
|
+
box-sizing: border-box;
|
|
490
|
+
width: 100%;
|
|
491
|
+
border: none;
|
|
492
|
+
outline: none;
|
|
493
|
+
margin: 0;
|
|
494
|
+
padding: 0;
|
|
495
|
+
display: inline;
|
|
496
|
+
font-size: inherit;
|
|
497
|
+
line-height: inherit;
|
|
498
|
+
font-weight: inherit;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
&__prev,
|
|
504
|
+
&__next {
|
|
505
|
+
display: flex;
|
|
506
|
+
height: auto;
|
|
507
|
+
cursor: pointer;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
452
511
|
&__week {
|
|
453
512
|
display: flex;
|
|
454
513
|
}
|
|
@@ -516,18 +575,6 @@
|
|
|
516
575
|
}
|
|
517
576
|
}
|
|
518
577
|
|
|
519
|
-
&-container {
|
|
520
|
-
min-width: 200px;
|
|
521
|
-
position: relative;
|
|
522
|
-
.calendar {
|
|
523
|
-
position: absolute;
|
|
524
|
-
z-index: 9;
|
|
525
|
-
top: 100%;
|
|
526
|
-
padding: 10px 16px;
|
|
527
|
-
border: 1px solid var(--border-color);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
578
|
&-dropdown {
|
|
532
579
|
appearance: none;
|
|
533
580
|
background-color: white;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import Calendar from './Calendar';
|
|
3
3
|
|
|
4
4
|
global.lng = 'en';
|
|
@@ -8,16 +8,18 @@ export default {
|
|
|
8
8
|
component: Calendar,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const Template = args =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const Template = args => {
|
|
12
|
+
const [date, setDate] = useState('12/03/2021');
|
|
13
|
+
return (
|
|
14
|
+
<div style={{ width: '320px' }}>
|
|
15
|
+
<Calendar {...args} date={date} setDate={setDate} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
16
19
|
|
|
17
20
|
export const CalendarTemplate = Template.bind({});
|
|
18
21
|
|
|
19
22
|
CalendarTemplate.args = {
|
|
20
|
-
date: '12/03/2021',
|
|
21
23
|
params: {},
|
|
22
24
|
setDate: () => null,
|
|
23
25
|
className: ''
|