intelicoreact 0.0.53 → 0.0.64
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/DateTime/DateTime.stories.js +1 -1
- package/dist/Atomic/FormElements/Input/Input.js +5 -5
- package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +4 -4
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +265 -0
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.scss +569 -0
- package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +243 -0
- package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +486 -0
- package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +154 -0
- package/dist/Atomic/FormElements/InputDateRange/components/SelectItem.js +46 -0
- package/dist/Atomic/FormElements/InputDateRange/dependencies.js +249 -0
- package/dist/Atomic/FormElements/Modal/Modal.stories.js +64 -18
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +162 -0
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +81 -0
- package/dist/Atomic/UI/Arrow/Arrow.js +80 -0
- package/dist/Atomic/UI/Arrow/Arrow.scss +19 -0
- package/dist/Atomic/UI/Arrow/Arrow.stories.js +46 -0
- package/dist/Atomic/UI/Button/Button.js +4 -2
- package/dist/Atomic/UI/Button/Button.scss +26 -0
- package/dist/Atomic/UI/Button/Button.stories.js +2 -2
- package/dist/Atomic/{FormElements → UI}/Calendar/Calendar.js +0 -0
- package/dist/Atomic/UI/Calendar/Calendar.scss +544 -0
- package/dist/Atomic/{FormElements → UI}/Calendar/Calendar.stories.js +5 -1
- package/dist/Functions/utils.js +10 -2
- package/package.json +7 -5
- package/src/Atomic/FormElements/DateTime/DateTime.stories.js +1 -1
- package/src/Atomic/FormElements/Input/Input.js +5 -5
- package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +6 -6
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +247 -0
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.scss +569 -0
- package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +148 -0
- package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +406 -0
- package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +112 -0
- package/src/Atomic/FormElements/InputDateRange/components/SelectItem.js +24 -0
- package/src/Atomic/FormElements/InputDateRange/dependencies.js +161 -0
- package/src/Atomic/FormElements/Modal/Modal.stories.js +60 -15
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +143 -0
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
- package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +54 -0
- package/src/Atomic/UI/Arrow/Arrow.js +41 -0
- package/src/Atomic/UI/Arrow/Arrow.scss +19 -0
- package/src/Atomic/UI/Arrow/Arrow.stories.js +32 -0
- package/src/Atomic/UI/Button/Button.js +3 -3
- package/src/Atomic/UI/Button/Button.scss +26 -0
- package/src/Atomic/UI/Button/Button.stories.js +4 -3
- package/src/Atomic/{FormElements → UI}/Calendar/Calendar.js +0 -0
- package/src/Atomic/UI/Calendar/Calendar.scss +544 -0
- package/src/Atomic/{FormElements → UI}/Calendar/Calendar.stories.js +5 -1
- package/src/Functions/utils.js +6 -0
- package/dist/Atomic/FormElements/Calendar/Calendar.scss +0 -543
- package/src/Atomic/FormElements/Calendar/Calendar.scss +0 -543
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import moment from 'moment-timezone';
|
|
4
|
+
|
|
5
|
+
import { useClickOutside, useToggle, getActualDateRange, INTERVALS, ALL_TIME_KEY, CUSTOM_INTERVAL_KEY_TEXT } from './dependencies';
|
|
6
|
+
|
|
7
|
+
import OpenedPart from './components/OpenedPart';
|
|
8
|
+
import Arrow from '../../UI/Arrow/Arrow';
|
|
9
|
+
|
|
10
|
+
import './InputDateRange.scss'
|
|
11
|
+
|
|
12
|
+
const InputDateRange = props => {
|
|
13
|
+
const {
|
|
14
|
+
txt,
|
|
15
|
+
id,
|
|
16
|
+
label,
|
|
17
|
+
className,
|
|
18
|
+
buttonsTypes,
|
|
19
|
+
value,
|
|
20
|
+
onChange = () => {},
|
|
21
|
+
error,
|
|
22
|
+
disabled,
|
|
23
|
+
isHoverable,
|
|
24
|
+
short,
|
|
25
|
+
isCompact = false,
|
|
26
|
+
// isFocused = false,
|
|
27
|
+
isIntervalsHidden = false,
|
|
28
|
+
isCompareHidden = false,
|
|
29
|
+
hideArrows = false,
|
|
30
|
+
isOptionsRight,
|
|
31
|
+
limitRange,
|
|
32
|
+
isUseAbs,
|
|
33
|
+
absTooltip,
|
|
34
|
+
} = props;
|
|
35
|
+
|
|
36
|
+
const actualValues = getActualDateRange(value);
|
|
37
|
+
const { isToggled, toggle, toggleOn, toggleOff } = useToggle(false);
|
|
38
|
+
const [current, setCurrent] = useState(actualValues?.intervalKey);
|
|
39
|
+
const [isCompare, setIsCompare] = useState(actualValues?.compare);
|
|
40
|
+
|
|
41
|
+
const ref = !isUseAbs ? useClickOutside(toggleOff) : useRef(null);
|
|
42
|
+
const internalContainerRef = useRef(null);
|
|
43
|
+
const isEndDateNearFuture = moment(actualValues?.end).isSameOrAfter(moment());
|
|
44
|
+
|
|
45
|
+
const handleChange = input => {
|
|
46
|
+
const newValue = getActualDateRange(input);
|
|
47
|
+
const formatedValue = {
|
|
48
|
+
intervalKey: newValue.intervalKey,
|
|
49
|
+
start: newValue.start ? moment(newValue.start).format('YYYY-MM-DDTHH:mm') : newValue.start,
|
|
50
|
+
end: newValue.end ? moment(newValue.end).format('YYYY-MM-DDTHH:mm') : newValue.end,
|
|
51
|
+
...(newValue.compare ? {compare: newValue.compare} : {}),
|
|
52
|
+
...(newValue.startPrevDate ? {startPrevDate: moment(newValue.startPrevDate).format('YYYY-MM-DDTHH:mm')} : {}),
|
|
53
|
+
...(newValue.endPrevDate ? {endPrevDate: moment(newValue.endPrevDate).format('YYYY-MM-DDTHH:mm')} : {}),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
onChange(formatedValue);
|
|
57
|
+
return formatedValue;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const Range = () => {
|
|
61
|
+
const SYMBOLS_QUANTITY_IF_TIME_ADDED = 13;
|
|
62
|
+
const { start, end } = actualValues;
|
|
63
|
+
if (!start || !end) return null;
|
|
64
|
+
|
|
65
|
+
const startTime = moment(start).format('HH:mm');
|
|
66
|
+
const endTime = moment(end).format('HH:mm');
|
|
67
|
+
|
|
68
|
+
const firstPart = `${moment(start).format('ll')} ${startTime !== '00:00' ? `(${startTime})` : ''}`;
|
|
69
|
+
const secondPart = `${(endTime !== '00:00' ? moment(end) : moment(end).subtract(1, 'days')).format('ll')} ${
|
|
70
|
+
endTime !== '00:00' ? `(${endTime})` : ''
|
|
71
|
+
}`;
|
|
72
|
+
|
|
73
|
+
const getClasses = base => cn('date-range-input__range-text', {
|
|
74
|
+
'date-range-input__range-text_little': base.length > SYMBOLS_QUANTITY_IF_TIME_ADDED
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<span className={getClasses(firstPart)}>
|
|
80
|
+
{firstPart}
|
|
81
|
+
{endTime === '00:00' && moment(end).isSame(moment(start).add(1, 'days'), 'day') ? '' : ` - `}
|
|
82
|
+
</span>
|
|
83
|
+
{endTime === '00:00' && moment(end).isSame(moment(start).add(1, 'days'), 'day')
|
|
84
|
+
? null
|
|
85
|
+
:<span className={getClasses(secondPart)}>{secondPart}</span>
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const slideInterval = (direction = 'forward') => {
|
|
93
|
+
const { start, end } = actualValues;
|
|
94
|
+
const intervalHoursCount = moment(end).diff(start, 'hours');
|
|
95
|
+
let newEnd, newStart;
|
|
96
|
+
const endHours = moment(end).hours();
|
|
97
|
+
const startHours = moment(start).hours();
|
|
98
|
+
if (direction === 'forward') {
|
|
99
|
+
newStart = moment(end)
|
|
100
|
+
.add(endHours === 0 ? 0 : 1, 'day')
|
|
101
|
+
.hours(startHours)
|
|
102
|
+
.toDate();
|
|
103
|
+
newEnd = moment(newStart).add(intervalHoursCount, 'hours');
|
|
104
|
+
} else {
|
|
105
|
+
newEnd = moment(start)
|
|
106
|
+
.subtract(endHours === 0 ? 0 : 1, 'day')
|
|
107
|
+
.hours(endHours)
|
|
108
|
+
.toDate();
|
|
109
|
+
newStart = moment(newEnd).subtract(intervalHoursCount, 'hours');
|
|
110
|
+
}
|
|
111
|
+
const startPrevDate = moment(newStart).subtract(intervalHoursCount, 'hours').subtract(1, 'seconds');
|
|
112
|
+
const endPrevDate = moment(newEnd).subtract(1, 'seconds');
|
|
113
|
+
handleChange({
|
|
114
|
+
...value,
|
|
115
|
+
intervalKey: getActualDateRange({
|
|
116
|
+
start: newStart,
|
|
117
|
+
end: newEnd,
|
|
118
|
+
})?.intervalKey,
|
|
119
|
+
start: newStart,
|
|
120
|
+
end: newEnd,
|
|
121
|
+
startPrevDate,
|
|
122
|
+
endPrevDate,
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleArrowClick = type => {
|
|
127
|
+
slideInterval(type === 'right' ? 'forward' : 'back');
|
|
128
|
+
toggleOff();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// const absData = useMemo(
|
|
132
|
+
// () => ({
|
|
133
|
+
// body: OpenedPart,
|
|
134
|
+
// props: {
|
|
135
|
+
// ...props,
|
|
136
|
+
// key: `${actualValues.start}-${actualValues.end}-${actualValues.intervalKey}-${current}-${isCompare}`,
|
|
137
|
+
// actualValues,
|
|
138
|
+
// current,
|
|
139
|
+
// setCurrent,
|
|
140
|
+
// isCompare,
|
|
141
|
+
// setIsCompare,
|
|
142
|
+
// toggleOff,
|
|
143
|
+
// onChange,
|
|
144
|
+
// },
|
|
145
|
+
// clickOutsideCallback: () => toggleOff(),
|
|
146
|
+
// top: internalContainerRef.current?.getBoundingClientRect()?.bottom || 0,
|
|
147
|
+
// left: internalContainerRef.current?.getBoundingClientRect()?.left || 0,
|
|
148
|
+
// }),
|
|
149
|
+
// [isToggled, value, actualValues, current, isCompare],
|
|
150
|
+
// );
|
|
151
|
+
|
|
152
|
+
// useEffect(() => {
|
|
153
|
+
// if (current && isUseAbs && absTooltip) onChange(current, 'absTooltip/props/current');
|
|
154
|
+
// }, [current]);
|
|
155
|
+
|
|
156
|
+
// useEffect(() => {
|
|
157
|
+
// if (isUseAbs) onChange(isToggled ? absData : null, 'absTooltip');
|
|
158
|
+
// }, [isToggled]);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div
|
|
162
|
+
ref={internalContainerRef}
|
|
163
|
+
className={cn('date-range-input', className, {
|
|
164
|
+
'date-range-input_compact': isCompact,
|
|
165
|
+
'date-range-input_hide-arrows': hideArrows,
|
|
166
|
+
'date-range-input_focused': isToggled,
|
|
167
|
+
'date-range-input_error': error,
|
|
168
|
+
'date-range-input_disabled': disabled,
|
|
169
|
+
})}
|
|
170
|
+
>
|
|
171
|
+
<span className="date-range-input__label" >{label}</span>
|
|
172
|
+
<div
|
|
173
|
+
className="date-range-input__wraper"
|
|
174
|
+
ref={ref}
|
|
175
|
+
onMouseEnter={isHoverable && toggleOn}
|
|
176
|
+
onMouseLeave={isHoverable && toggleOff}
|
|
177
|
+
>
|
|
178
|
+
<div className={cn('date-range-input__absolut-wraper', {
|
|
179
|
+
'date-range-input__absolut-wraper_right-position': isOptionsRight,
|
|
180
|
+
})}>
|
|
181
|
+
<div className={cn('date-range-input__static-part')}>
|
|
182
|
+
<button
|
|
183
|
+
id={id}
|
|
184
|
+
className={cn('date-range-input__toggle-button')}
|
|
185
|
+
// className={cn(
|
|
186
|
+
// 'date-range-input__toggle-button',
|
|
187
|
+
// { 'form-select__input--disabled': disabled },
|
|
188
|
+
// { 'form-select__input--opened': isToggled },
|
|
189
|
+
// { 'form-select__input--focused': isToggled },
|
|
190
|
+
// className,
|
|
191
|
+
// )}
|
|
192
|
+
disabled={disabled}
|
|
193
|
+
onClick={!disabled && !isHoverable ? toggle : undefined}
|
|
194
|
+
>
|
|
195
|
+
<div className="date-range-input__interval-key">
|
|
196
|
+
<span>
|
|
197
|
+
{(txt?.labels && txt.labels[actualValues?.intervalKey]) ?? (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
|
|
198
|
+
</span>
|
|
199
|
+
{current !== ALL_TIME_KEY && <span>:</span>}
|
|
200
|
+
</div>
|
|
201
|
+
{!isCompact && <div className={cn('date-range-input__range', {})}><Range /></div>}
|
|
202
|
+
</button>
|
|
203
|
+
{!isCompact && !hideArrows && (
|
|
204
|
+
<div className={cn('date-range-input__arrows-block')}>
|
|
205
|
+
<Arrow
|
|
206
|
+
type="left"
|
|
207
|
+
className="date-range-input__arrow"
|
|
208
|
+
onClick={() => handleArrowClick("left")}
|
|
209
|
+
disabled={disabled || actualValues?.intervalKey === ALL_TIME_KEY}
|
|
210
|
+
/>
|
|
211
|
+
<Arrow
|
|
212
|
+
type="right"
|
|
213
|
+
className="date-range-input__arrow"
|
|
214
|
+
onClick={() => handleArrowClick("right")}
|
|
215
|
+
disabled={
|
|
216
|
+
disabled ||
|
|
217
|
+
actualValues?.intervalKey === ALL_TIME_KEY ||
|
|
218
|
+
actualValues?.intervalKey === 'today' ||
|
|
219
|
+
moment(actualValues?.end)
|
|
220
|
+
.add(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
|
|
221
|
+
.isAfter(moment().add(1, 'day').startOf('day'))
|
|
222
|
+
}
|
|
223
|
+
/>
|
|
224
|
+
</div>
|
|
225
|
+
)}
|
|
226
|
+
</div>
|
|
227
|
+
{isToggled && !isUseAbs && (
|
|
228
|
+
<OpenedPart
|
|
229
|
+
{...props}
|
|
230
|
+
ref={internalContainerRef}
|
|
231
|
+
actualValues={actualValues}
|
|
232
|
+
current={current}
|
|
233
|
+
setCurrent={setCurrent}
|
|
234
|
+
isCompare={isCompare}
|
|
235
|
+
setIsCompare={setIsCompare}
|
|
236
|
+
toggleOff={toggleOff}
|
|
237
|
+
onChange={handleChange}
|
|
238
|
+
/>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
{error && <span className="date-range-input__error-block">{error}</span>}
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export default React.memo(InputDateRange);
|