intelicoreact 0.0.49 → 0.0.61

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.
Files changed (60) hide show
  1. package/dist/Atomic/FormElements/DateTime/DateTime.stories.js +1 -1
  2. package/dist/Atomic/FormElements/Dropdown/Dropdown.js +5 -7
  3. package/dist/Atomic/FormElements/Input/Input.js +10 -11
  4. package/dist/Atomic/FormElements/Input/Input.stories.js +5 -1
  5. package/dist/Atomic/FormElements/{Calendar/Calendar.stories.js → InputCalendar/InputCalendar.js} +40 -26
  6. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +46 -0
  7. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +249 -0
  8. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.scss +568 -0
  9. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +87 -0
  10. package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +486 -0
  11. package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +154 -0
  12. package/dist/Atomic/FormElements/InputDateRange/components/SelectItem.js +38 -0
  13. package/dist/Atomic/FormElements/InputDateRange/dependencies.js +241 -0
  14. package/dist/Atomic/FormElements/Modal/Modal.stories.js +64 -18
  15. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +162 -0
  16. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
  17. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +81 -0
  18. package/dist/Atomic/UI/Arrow/Arrow.js +80 -0
  19. package/dist/Atomic/UI/Arrow/Arrow.scss +19 -0
  20. package/dist/Atomic/UI/Arrow/Arrow.stories.js +46 -0
  21. package/dist/Atomic/UI/Button/Button.js +4 -2
  22. package/dist/Atomic/UI/Button/Button.scss +26 -0
  23. package/dist/Atomic/UI/Button/Button.stories.js +2 -2
  24. package/dist/Atomic/{FormElements → UI}/Calendar/Calendar.js +20 -9
  25. package/dist/Atomic/UI/Calendar/Calendar.scss +544 -0
  26. package/dist/Atomic/UI/Calendar/Calendar.stories.js +37 -0
  27. package/dist/Atomic/UI/Price/Price.js +1 -0
  28. package/dist/Functions/utils.js +10 -2
  29. package/package.json +7 -5
  30. package/src/Atomic/FormElements/DateTime/DateTime.stories.js +1 -1
  31. package/src/Atomic/FormElements/Dropdown/Dropdown.js +2 -3
  32. package/src/Atomic/FormElements/Input/Input.js +10 -9
  33. package/src/Atomic/FormElements/Input/Input.stories.js +3 -1
  34. package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +43 -0
  35. package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +27 -0
  36. package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +234 -0
  37. package/src/Atomic/FormElements/InputDateRange/InputDateRange.scss +568 -0
  38. package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +58 -0
  39. package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +406 -0
  40. package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +112 -0
  41. package/src/Atomic/FormElements/InputDateRange/components/SelectItem.js +22 -0
  42. package/src/Atomic/FormElements/InputDateRange/dependencies.js +153 -0
  43. package/src/Atomic/FormElements/Modal/Modal.stories.js +60 -15
  44. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +143 -0
  45. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +101 -0
  46. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.stories.js +54 -0
  47. package/src/Atomic/UI/Arrow/Arrow.js +41 -0
  48. package/src/Atomic/UI/Arrow/Arrow.scss +19 -0
  49. package/src/Atomic/UI/Arrow/Arrow.stories.js +32 -0
  50. package/src/Atomic/UI/Button/Button.js +3 -3
  51. package/src/Atomic/UI/Button/Button.scss +26 -0
  52. package/src/Atomic/UI/Button/Button.stories.js +4 -3
  53. package/src/Atomic/{FormElements → UI}/Calendar/Calendar.js +13 -10
  54. package/src/Atomic/UI/Calendar/Calendar.scss +544 -0
  55. package/src/Atomic/UI/Calendar/Calendar.stories.js +23 -0
  56. package/src/Atomic/UI/Price/Price.js +1 -0
  57. package/src/Functions/utils.js +6 -0
  58. package/dist/Atomic/FormElements/Calendar/Calendar.scss +0 -543
  59. package/src/Atomic/FormElements/Calendar/Calendar.scss +0 -543
  60. package/src/Atomic/FormElements/Calendar/Calendar.stories.js +0 -38
@@ -23,6 +23,7 @@ const Input = ({
23
23
  mask,
24
24
  error,
25
25
  icon,
26
+ symbolsLimit,
26
27
  }) => {
27
28
  // STATES
28
29
  const [isFocused, setIsFocused] = useState(false);
@@ -30,30 +31,30 @@ const Input = ({
30
31
  const inputRef = useRef(null);
31
32
  // HANDLES
32
33
  const handle = {
33
- change: event => {
34
- let inputValue = event.target?.value || event;
34
+ change: e => {
35
+ let inputValue = e.target ? e.target.value : e;
35
36
  if (isNumeric || (type === 'number' && inputValue !== '')) {
36
37
  inputValue = parseFloat(inputValue) || '';
37
38
  if (min && +min > inputValue) {
38
39
  inputValue = min;
39
40
  } else if (max && +max < inputValue) inputValue = max;
40
- }
41
+ } else if (symbolsLimit && inputValue.length > +symbolsLimit) inputValue = inputValue.substring(0, +symbolsLimit);
41
42
  onChange(inputValue.toString());
42
43
  },
43
44
  toggleEdit: () => {
44
45
  setEditing(!isEditing);
45
46
  onChange('');
46
47
  },
47
- focus: () => {
48
+ focus: e => {
48
49
  setIsFocused(true);
49
- if (onFocus) onFocus();
50
+ if (onFocus) onFocus(e);
50
51
  },
51
- blur: () => {
52
+ blur: e => {
52
53
  setIsFocused(false);
53
54
  setEditing(false);
54
- if (onBlur) onBlur();
55
+ if (onBlur) onBlur(e);
55
56
  },
56
- keyUp: e => (onKeyUp ? onKeyUp(e.keyCode) : null)
57
+ keyUp: e => (onKeyUp ? onKeyUp(e.keyCode, event) : null)
57
58
  };
58
59
 
59
60
  useEffect(() => {
@@ -70,7 +71,7 @@ const Input = ({
70
71
  onBlur: handle.blur,
71
72
  onKeyUp: handle.keyUp,
72
73
  min,
73
- max
74
+ max,
74
75
  };
75
76
 
76
77
  function renderInput() {
@@ -43,6 +43,7 @@ export default {
43
43
  value: { description: '(* - required prop)' },
44
44
  className: { description: 'string' },
45
45
  mask: { description: 'string: force input to masked https://www.npmjs.com/package/react-input-mask' },
46
+ symbolsLimit: { description: 'Set limit of symbols in input, overhead will be ignored' },
46
47
  onBlur: { description: 'custom callback on blur' },
47
48
  onFocus: { description: 'custom callback on focus' },
48
49
  onKeyUp: { description: 'custom callback on keyup, returns event keyCode' }
@@ -67,5 +68,6 @@ InputTemplate.args = {
67
68
  max: '5',
68
69
  placeholder: 'Placeholder',
69
70
  mask: '',
70
- icon: <User />
71
+ icon: <User />,
72
+ symbolsLimit: 225
71
73
  };
@@ -0,0 +1,43 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import moment from 'moment';
3
+ import InputMask from 'react-input-mask';
4
+ import Calendar from '../../UI/Calendar/Calendar';
5
+ import { useClickOutside } from '../../../Functions/useClickOutside';
6
+
7
+ const InputCalendar = ({ data, params }) => {
8
+ const [date, setDate] = useState(data);
9
+ const [inputValue, setInputValue] = useState(date);
10
+ const [isOpened, setIsOpened] = useState(false);
11
+ const calendarRef = useRef(null);
12
+
13
+ useClickOutside(calendarRef, () => setIsOpened(false));
14
+
15
+ const changeInputValue = value => {
16
+ if (!value.includes('_') && value) {
17
+ setDate(moment(value).format('L'));
18
+ setInputValue(moment(value).format('L'));
19
+ } else {
20
+ setInputValue(value);
21
+ }
22
+ };
23
+
24
+ const changeCalendarDay = value => {
25
+ setDate(value);
26
+ setInputValue(value);
27
+ };
28
+
29
+ return (
30
+ <div className="calendar-container" ref={calendarRef}>
31
+ <InputMask
32
+ mask="99/99/9999"
33
+ value={inputValue}
34
+ onChange={e => changeInputValue(e.target.value)}
35
+ className="calendar-dropdown"
36
+ onFocus={() => setIsOpened(!isOpened)}
37
+ />
38
+ {isOpened ? <Calendar date={date} setDate={(newDate) => changeCalendarDay(newDate)} params={params} /> : null}
39
+ </div>
40
+ );
41
+ };
42
+
43
+ export default InputCalendar;
@@ -0,0 +1,27 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { ref } from 'yup';
3
+ import InputCalendar from './InputCalendar';
4
+
5
+ global.lng = 'en';
6
+
7
+ export default {
8
+ title: 'Form Elements/InputCalendar',
9
+ component: InputCalendar,
10
+ };
11
+
12
+ const Template = (args) => {
13
+ const params = {
14
+ minDate: args?.minDate,
15
+ maxDate: args?.maxDate,
16
+ };
17
+
18
+ return <InputCalendar data={args.date} params={params} />;
19
+ };
20
+
21
+ export const Calendar = Template.bind({});
22
+
23
+ Calendar.args = {
24
+ date: '10/14/2021',
25
+ minDate: '10/11/2021',
26
+ maxDate: '10/25/2021',
27
+ };
@@ -0,0 +1,234 @@
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 Range = () => {
46
+ const SYMBOLS_QUANTITY_IF_TIME_ADDED = 13;
47
+ const { start, end } = actualValues;
48
+ if (!start || !end) return null;
49
+
50
+ const startTime = moment(start).format('HH:mm');
51
+ const endTime = moment(end).format('HH:mm');
52
+
53
+ const firstPart = `${moment(start).format('ll')} ${startTime !== '00:00' ? `(${startTime})` : ''}`;
54
+ const secondPart = `${(endTime !== '00:00' ? moment(end) : moment(end).subtract(1, 'days')).format('ll')} ${
55
+ endTime !== '00:00' ? `(${endTime})` : ''
56
+ }`;
57
+
58
+ const getClasses = base =>
59
+ cn('date-range-input__range-text', {
60
+ 'date-range-input__range-text_little': base.length > SYMBOLS_QUANTITY_IF_TIME_ADDED
61
+ });
62
+
63
+ return (
64
+ <>
65
+ <span className={getClasses(firstPart)}>
66
+ {firstPart}
67
+ {endTime === '00:00' && moment(end).isSame(moment(start).add(1, 'days'), 'day') ? '' : ` - `}
68
+ </span>
69
+ {endTime === '00:00' && moment(end).isSame(moment(start).add(1, 'days'), 'day') ? null : (
70
+ <span className={getClasses(secondPart)}>{secondPart}</span>
71
+ )}
72
+ </>
73
+ );
74
+ };
75
+
76
+ const slideInterval = (direction = 'forward') => {
77
+ const { start, end } = actualValues;
78
+ const intervalHoursCount = moment(end).diff(start, 'hours');
79
+ let newEnd;
80
+ let newStart;
81
+ const endHours = moment(end).hours();
82
+ const startHours = moment(start).hours();
83
+ if (direction === 'forward') {
84
+ newStart = moment(end)
85
+ .add(endHours === 0 ? 0 : 1, 'day')
86
+ .hours(startHours)
87
+ .toDate();
88
+ newEnd = moment(newStart).add(intervalHoursCount, 'hours');
89
+ } else {
90
+ newEnd = moment(start)
91
+ .subtract(endHours === 0 ? 0 : 1, 'day')
92
+ .hours(endHours)
93
+ .toDate();
94
+ newStart = moment(newEnd).subtract(intervalHoursCount, 'hours');
95
+ }
96
+ const startPrevDate = moment(newStart).subtract(intervalHoursCount, 'hours').subtract(1, 'seconds');
97
+ const endPrevDate = moment(newEnd).subtract(1, 'seconds');
98
+ onChange({
99
+ ...value,
100
+ intervalKey: getActualDateRange({
101
+ start: newStart,
102
+ end: newEnd
103
+ })?.intervalKey,
104
+ start: newStart,
105
+ end: newEnd,
106
+ startPrevDate,
107
+ endPrevDate
108
+ });
109
+ };
110
+
111
+ const handleArrowClick = type => {
112
+ slideInterval(type === 'right' ? 'forward' : 'back');
113
+ toggleOff();
114
+ };
115
+
116
+ const absData = useMemo(
117
+ () => ({
118
+ body: OpenedPart,
119
+ props: {
120
+ ...props,
121
+ key: `${actualValues.start}-${actualValues.end}-${actualValues.intervalKey}-${current}-${isCompare}`,
122
+ actualValues,
123
+ current,
124
+ setCurrent,
125
+ isCompare,
126
+ setIsCompare,
127
+ toggleOff,
128
+ onChange
129
+ },
130
+ clickOutsideCallback: () => toggleOff(),
131
+ top: internalContainerRef.current?.getBoundingClientRect()?.bottom || 0,
132
+ left: internalContainerRef.current?.getBoundingClientRect()?.left || 0
133
+ }),
134
+ [isToggled, value, actualValues, current, isCompare]
135
+ );
136
+
137
+ useEffect(() => {
138
+ if (current && isUseAbs && absTooltip) onChange(current, 'absTooltip/props/current');
139
+ }, [current]);
140
+
141
+ useEffect(() => {
142
+ if (isUseAbs) onChange(isToggled ? absData : null, 'absTooltip');
143
+ }, [isToggled]);
144
+
145
+ return (
146
+ <div
147
+ ref={internalContainerRef}
148
+ className={cn('date-range-input', className, {
149
+ 'date-range-input_compact': isCompact,
150
+ 'date-range-input_hide-arrows': hideArrows,
151
+ 'date-range-input_focused': isToggled,
152
+ 'date-range-input_error': error,
153
+ 'date-range-input_disabled': disabled
154
+ })}
155
+ >
156
+ <span className="date-range-input__label">{label}</span>
157
+ <div className="date-range-input__wraper" ref={ref} onMouseEnter={isHoverable && toggleOn} onMouseLeave={isHoverable && toggleOff}>
158
+ <div
159
+ className={cn('date-range-input__absolut-wraper', {
160
+ 'date-range-input__absolut-wraper_right-position': isOptionsRight
161
+ })}
162
+ >
163
+ <div className={cn('date-range-input__static-part')}>
164
+ <button
165
+ id={id}
166
+ className={cn('date-range-input__toggle-button')}
167
+ // className={cn(
168
+ // 'date-range-input__toggle-button',
169
+ // { 'form-select__input--disabled': disabled },
170
+ // { 'form-select__input--opened': isToggled },
171
+ // { 'form-select__input--focused': isToggled },
172
+ // className,
173
+ // )}
174
+ disabled={disabled}
175
+ onClick={!disabled && !isHoverable ? toggle : undefined}
176
+ >
177
+ <div className="date-range-input__interval-key">
178
+ <span>
179
+ {(txt?.labels && txt.labels[actualValues?.intervalKey]) ??
180
+ (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
181
+ </span>
182
+ {current !== ALL_TIME_KEY && <span>:</span>}
183
+ </div>
184
+ {!isCompact && (
185
+ <div className={cn('date-range-input__range', {})}>
186
+ <Range />
187
+ </div>
188
+ )}
189
+ </button>
190
+ {!isCompact && !hideArrows && (
191
+ <div className={cn('date-range-input__arrows-block')}>
192
+ <Arrow
193
+ type="left"
194
+ className="date-range-input__arrow"
195
+ onClick={() => handleArrowClick('left')}
196
+ disabled={disabled || actualValues?.intervalKey === ALL_TIME_KEY}
197
+ />
198
+ <Arrow
199
+ type="right"
200
+ className="date-range-input__arrow"
201
+ onClick={() => handleArrowClick('right')}
202
+ disabled={
203
+ disabled ||
204
+ actualValues?.intervalKey === ALL_TIME_KEY ||
205
+ actualValues?.intervalKey === 'today' ||
206
+ moment(actualValues?.end)
207
+ .add(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
208
+ .isAfter(moment().add(1, 'day').startOf('day'))
209
+ }
210
+ />
211
+ </div>
212
+ )}
213
+ </div>
214
+ {isToggled && !isUseAbs && (
215
+ <OpenedPart
216
+ {...props}
217
+ ref={internalContainerRef}
218
+ actualValues={actualValues}
219
+ current={current}
220
+ setCurrent={setCurrent}
221
+ isCompare={isCompare}
222
+ setIsCompare={setIsCompare}
223
+ toggleOff={toggleOff}
224
+ onChange={onChange}
225
+ />
226
+ )}
227
+ </div>
228
+ </div>
229
+ {error && <span className="date-range-input__error-block">{error}</span>}
230
+ </div>
231
+ );
232
+ };
233
+
234
+ export default React.memo(InputDateRange);