intelicoreact 0.0.92 → 0.0.95

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 (48) hide show
  1. package/dist/Atomic/FormElements/Dropdown/Dropdown.stories.js +1 -1
  2. package/dist/Atomic/FormElements/Dropdown/components/DropdownLoader.js +1 -1
  3. package/dist/Atomic/FormElements/Dropdown/components/{Loader.scss → DropdownLoader.scss} +0 -0
  4. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +35 -6
  5. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.scss +23 -0
  6. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +28 -6
  7. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +20 -9
  8. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +7 -5
  9. package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +29 -24
  10. package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +13 -7
  11. package/dist/Atomic/FormElements/MobileCalendar/MobileCalendar.js +427 -0
  12. package/dist/Atomic/FormElements/MobileCalendar/MobileCalendar.scss +120 -0
  13. package/dist/{Molecular/Datepicker/Datepicker.stories.js → Atomic/FormElements/MobileCalendar/MobileCalendar.stories.js} +33 -21
  14. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.js +11 -8
  15. package/dist/Atomic/UI/Calendar/Calendar.js +23 -22
  16. package/dist/Atomic/UI/Calendar/Calendar.scss +23 -23
  17. package/dist/Functions/customEventListener.js +66 -0
  18. package/package.json +1 -1
  19. package/src/Atomic/FormElements/Dropdown/Dropdown.stories.js +1 -1
  20. package/src/Atomic/FormElements/Dropdown/components/DropdownLoader.js +1 -1
  21. package/src/Atomic/FormElements/Dropdown/components/{Loader.scss → DropdownLoader.scss} +0 -0
  22. package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +58 -5
  23. package/src/Atomic/FormElements/InputCalendar/InputCalendar.scss +23 -0
  24. package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +16 -6
  25. package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +57 -22
  26. package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +10 -8
  27. package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +391 -392
  28. package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +11 -3
  29. package/src/Atomic/FormElements/MobileCalendar/MobileCalendar.js +315 -0
  30. package/src/Atomic/FormElements/MobileCalendar/MobileCalendar.scss +120 -0
  31. package/src/Atomic/FormElements/MobileCalendar/MobileCalendar.stories.js +30 -0
  32. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.js +132 -126
  33. package/src/Atomic/UI/Calendar/Calendar.js +35 -23
  34. package/src/Atomic/UI/Calendar/Calendar.scss +23 -23
  35. package/src/Functions/customEventListener.js +58 -0
  36. package/src/Functions/useMouseUpOutside.js +14 -0
  37. package/dist/Functions/useToggle.js +0 -40
  38. package/dist/Functions/utils.js +0 -66
  39. package/dist/Molecular/Datepicker/Datepicker.js +0 -451
  40. package/dist/Molecular/Datepicker/Datepicker.scss +0 -8
  41. package/dist/Molecular/Datepicker/components/Calendar.js +0 -156
  42. package/dist/Molecular/FormElements/FormElement.js +0 -40
  43. package/dist/Molecular/FormElements/FormElement.scss +0 -8
  44. package/dist/Molecular/FormElements/FormElement.stories.js +0 -73
  45. package/dist/index.js +0 -15
  46. package/dist/scss/_fonts.scss +0 -109
  47. package/dist/scss/_vars.scss +0 -48
  48. package/dist/scss/main.scss +0 -40
@@ -32,16 +32,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
32
32
  function _default(props) {
33
33
  var date = props.date,
34
34
  setDate = props.setDate,
35
+ setIsOpened = props.setIsOpened,
35
36
  _props$allowPrev = props.allowPrev,
36
37
  allowPrev = _props$allowPrev === void 0 ? true : _props$allowPrev,
37
38
  _props$allowNext = props.allowNext,
38
39
  allowNext = _props$allowNext === void 0 ? true : _props$allowNext,
39
40
  params = props.params,
40
41
  className = props.className,
41
- dontLimitFuture = props.dontLimitFuture; // const { minDate = '01/01/1900', maxDate = moment().format('MM/DD/YYYY') } = params;
42
+ isListTop = props.isListTop; // const { minDate = '01/01/1900', maxDate = moment().format('MM/DD/YYYY') } = params;
42
43
 
43
- var minDate = params.minDate,
44
- maxDate = params.maxDate;
44
+ var format = params.format,
45
+ minDate = params.minDate,
46
+ maxDate = params.maxDate,
47
+ momentMinDate = params.momentMinDate,
48
+ momentMaxDate = params.momentMaxDate,
49
+ isDontLimitFuture = params.isDontLimitFuture;
45
50
 
46
51
  var _useState = (0, _react.useState)({}),
47
52
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -65,19 +70,15 @@ function _default(props) {
65
70
 
66
71
  var yearInputRef = (0, _react.useRef)(null);
67
72
  var selectedDay = (0, _moment.default)(showDate);
68
- var isError = 'Invalid date'; // const title = useMemo(
69
- // () => (selectedDay.format('MMM') === isError ? isError : `${selectedDay.format('MMM')} ${moment(showDate).format('YYYY')}`),
70
- // [date, showDate]
71
- // );
72
-
73
+ var isError = 'Invalid date';
73
74
  var showMonth = (0, _react.useMemo)(function () {
74
75
  return (0, _moment.default)(showDate).format('MMM');
75
76
  }, [date, showDate]);
76
77
  var showYear = (0, _react.useMemo)(function () {
77
78
  return (0, _moment.default)(showDate).format('YYYY');
78
79
  }, [date, showDate]);
79
- console.log('date - ', date);
80
- console.log('showDate - ', showDate);
80
+ var isShovPrevArrow = allowPrev && !(minDate && (0, _moment.default)(showDate).startOf('month').isSameOrBefore(momentMinDate, 'months'));
81
+ var isShovNextArrow = allowNext && (isDontLimitFuture || !(0, _moment.default)(showDate).startOf('month').isSameOrAfter(maxDate ? momentMaxDate : (0, _moment.default)().add(1, 'day').startOf('day'), 'months'));
81
82
  (0, _react.useEffect)(function () {
82
83
  var result = {};
83
84
  var day = selectedDay.startOf('month');
@@ -106,14 +107,12 @@ function _default(props) {
106
107
  if (!day) return /*#__PURE__*/_react.default.createElement("div", {
107
108
  className: "calendar__day"
108
109
  });
109
- var isFutureDay = day && maxDate ? (0, _moment.default)(day.date).isAfter((0, _moment.default)(maxDate || ''), 'day') : (0, _moment.default)(day.date).isAfter((0, _moment.default)(), 'day');
110
- var isBeforeDay = day && (0, _moment.default)(day.date).isBefore((0, _moment.default)(minDate || ''), 'day');
111
- console.log('isFutureDay - ', isFutureDay);
112
- console.log('isBeforeDay - ', isBeforeDay);
110
+ var isFutureDay = day && !isDontLimitFuture && maxDate ? (0, _moment.default)(day.date).isAfter(momentMaxDate || (0, _moment.default)().add(1, 'days'), 'day') : (0, _moment.default)(day.date).isAfter((0, _moment.default)(), 'day');
111
+ var isBeforeDay = day && (0, _moment.default)(day.date).isBefore(momentMinDate || '', 'day');
113
112
  var classNames = (0, _classnames.default)('calendar__day', {
114
113
  'calendar__day--clickable': day
115
114
  }, {
116
- 'calendar__day--disabled': !dontLimitFuture && isFutureDay
115
+ 'calendar__day--disabled': !isDontLimitFuture && isFutureDay
117
116
  }, {
118
117
  'calendar__day--disabled': isBeforeDay
119
118
  }, {
@@ -122,8 +121,9 @@ function _default(props) {
122
121
  return /*#__PURE__*/_react.default.createElement("div", {
123
122
  key: "".concat(week, "_").concat(dayOfWeek),
124
123
  className: classNames,
125
- onClick: day && (dontLimitFuture || !isFutureDay) ? function () {
126
- return setDate((0, _moment.default)(day.date).format('L'));
124
+ onClick: day && (isDontLimitFuture || !isFutureDay) ? function () {
125
+ setDate((0, _moment.default)(day.date).format('L'));
126
+ setIsOpened(false);
127
127
  } : null // onMouseOver={day && !isFutureDay ? () => onHover(day.date) : null}
128
128
  // onMouseLeave={() => onHover(null)}
129
129
 
@@ -164,12 +164,14 @@ function _default(props) {
164
164
  }
165
165
  }, [isChangeYear]);
166
166
  return /*#__PURE__*/_react.default.createElement("div", {
167
- className: "calendar ".concat(className ? className : '')
167
+ className: (0, _classnames.default)('calendar', className, {
168
+ 'calendar_list-top': isListTop
169
+ })
168
170
  }, /*#__PURE__*/_react.default.createElement("div", {
169
171
  className: "calendar-header"
170
172
  }, /*#__PURE__*/_react.default.createElement("div", {
171
173
  className: "calendar-header__prev"
172
- }, allowPrev && /*#__PURE__*/_react.default.createElement("div", {
174
+ }, isShovPrevArrow && /*#__PURE__*/_react.default.createElement("div", {
173
175
  onClick: handlePrev
174
176
  }, /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronLeft, null))), /*#__PURE__*/_react.default.createElement("div", {
175
177
  className: (0, _classnames.default)('calendar-header__title'),
@@ -195,12 +197,11 @@ function _default(props) {
195
197
  if (e.key === 'Enter') closeYearInput();
196
198
  },
197
199
  onChange: function onChange(e) {
198
- console.log(e.target.value);
199
- setInputYearValue(e.target.value);
200
+ return setInputYearValue(e.target.value);
200
201
  }
201
202
  }) : "".concat(showYear))), /*#__PURE__*/_react.default.createElement("div", {
202
203
  className: "calendar-header__next"
203
- }, allowNext && /*#__PURE__*/_react.default.createElement("div", {
204
+ }, isShovNextArrow && /*#__PURE__*/_react.default.createElement("div", {
204
205
  onClick: handleNext
205
206
  }, /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronRight, null)))), /*#__PURE__*/_react.default.createElement("div", {
206
207
  className: "calendar__week"
@@ -425,18 +425,19 @@
425
425
  // box-shadow: 0 0 3px 0 rgb(0 123 255 / 50%);
426
426
  // }
427
427
  // }
428
- .calendar-header {
429
- display: flex;
430
- justify-content: center;
431
- align-items: center;
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
- cursor: pointer;
438
- }
439
- }
440
441
  .calendar {
441
442
  background: #ffffff;
442
443
  border: 1px solid #e2e5ec;
@@ -451,6 +452,10 @@
451
452
  user-select: none;
452
453
 
453
454
  &-header {
455
+ display: flex;
456
+ justify-content: center;
457
+ align-items: center;
458
+
454
459
  box-sizing: border-box;
455
460
  &__title {
456
461
  &-month {
@@ -494,6 +499,13 @@
494
499
  }
495
500
  }
496
501
  }
502
+
503
+ &__prev,
504
+ &__next {
505
+ display: flex;
506
+ height: auto;
507
+ cursor: pointer;
508
+ }
497
509
  }
498
510
 
499
511
  &__week {
@@ -563,18 +575,6 @@
563
575
  }
564
576
  }
565
577
 
566
- &-container {
567
- min-width: 200px;
568
- position: relative;
569
- .calendar {
570
- position: absolute;
571
- z-index: 9;
572
- top: 100%;
573
- padding: 10px 16px;
574
- border: 1px solid var(--border-color);
575
- }
576
- }
577
-
578
578
  &-dropdown {
579
579
  appearance: none;
580
580
  background-color: white;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ (function () {
4
+ Element.prototype._addEventListener = Element.prototype.addEventListener;
5
+
6
+ Element.prototype.addEventListener = function (a, b, c) {
7
+ if (c == undefined) c = false;
8
+
9
+ this._addEventListener(a, b, c);
10
+
11
+ if (!this.eventListenerList) this.eventListenerList = {};
12
+ if (!this.eventListenerList[a]) this.eventListenerList[a] = []; //this.removeEventListener(a,b,c); // TODO - handle duplicates..
13
+
14
+ this.eventListenerList[a].push({
15
+ listener: b,
16
+ useCapture: c
17
+ });
18
+ };
19
+
20
+ Element.prototype.getEventListeners = function (a) {
21
+ if (!this.eventListenerList) this.eventListenerList = {};
22
+ if (a == undefined) return this.eventListenerList;
23
+ return this.eventListenerList[a];
24
+ };
25
+
26
+ Element.prototype.clearEventListeners = function (a) {
27
+ if (!this.eventListenerList) this.eventListenerList = {};
28
+
29
+ if (a == undefined) {
30
+ for (var x in this.getEventListeners()) {
31
+ this.clearEventListeners(x);
32
+ }
33
+
34
+ return;
35
+ }
36
+
37
+ var el = this.getEventListeners(a);
38
+ if (el == undefined) return;
39
+
40
+ for (var i = el.length - 1; i >= 0; --i) {
41
+ var ev = el[i];
42
+ this.removeEventListener(a, ev.listener, ev.useCapture);
43
+ }
44
+ };
45
+
46
+ Element.prototype._removeEventListener = Element.prototype.removeEventListener;
47
+
48
+ Element.prototype.removeEventListener = function (a, b, c) {
49
+ if (c == undefined) c = false;
50
+
51
+ this._removeEventListener(a, b, c);
52
+
53
+ if (!this.eventListenerList) this.eventListenerList = {};
54
+ if (!this.eventListenerList[a]) this.eventListenerList[a] = []; // Find the event in the list
55
+
56
+ for (var i = 0; i < this.eventListenerList[a].length; i++) {
57
+ if (this.eventListenerList[a][i].listener == b, this.eventListenerList[a][i].useCapture == c) {
58
+ // Hmm..
59
+ this.eventListenerList[a].splice(i, 1);
60
+ break;
61
+ }
62
+ }
63
+
64
+ if (this.eventListenerList[a].length == 0) delete this.eventListenerList[a];
65
+ };
66
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "0.0.92",
3
+ "version": "0.0.95",
4
4
  "description": "fix input-calendar",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -54,7 +54,7 @@ const Template = (args) => {
54
54
  export const DropdownTemplate = Template.bind({});
55
55
 
56
56
  DropdownTemplate.args = {
57
- isListTop: true,
57
+ // isListTop: true,
58
58
  entity: 'entity',
59
59
  value: 'drop6',
60
60
  placeholder: 'Placeholder',
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import './Loader.scss';
2
+ import './DropdownLoader.scss';
3
3
 
4
4
  const DropdownLoader = function ({ variant }) {
5
5
  return (
@@ -1,13 +1,40 @@
1
1
  import React, { useState, useRef } from 'react';
2
2
  import moment from 'moment';
3
3
  import InputMask from 'react-input-mask';
4
+ import cn from 'classnames';
5
+
4
6
  import Calendar from '../../UI/Calendar/Calendar';
5
7
  import { useClickOutside } from '../../../Functions/useClickOutside';
6
8
 
7
- const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', placeholder = 'mm/dd/yyyy', mask = '99/99/9999', dontLimitFuture }) => {
9
+ import './InputCalendar.scss';
10
+
11
+ const InputCalendar = ({
12
+ value,
13
+ minDate,
14
+ maxDate,
15
+ format = 'MM/DD/YYYY',
16
+ isDontLimitFuture,
17
+ onChange,
18
+ className = '',
19
+ placeholder = 'mm/dd/yyyy',
20
+ mask = '99/99/9999',
21
+ isListTop,
22
+ disabled,
23
+ }) => {
8
24
  const [isOpened, setIsOpened] = useState(false);
9
25
  const calendarRef = useRef(null);
10
26
 
27
+ const formatedMinDate = moment(minDate).format(format) !== 'Invalid date'
28
+ ? moment(minDate).format(format)
29
+ : null;
30
+
31
+ const formatedMaxDate = moment(maxDate).format(format) !== 'Invalid date'
32
+ ? moment(maxDate).format(format)
33
+ : null;
34
+
35
+ const momentMinDate = moment(formatedMinDate, format).startOf('day');
36
+ const momentMaxDate = moment(formatedMaxDate, format).startOf('day');
37
+
11
38
  useClickOutside(calendarRef, () => setIsOpened(false));
12
39
 
13
40
  const changeInputValue = (val) => {
@@ -26,22 +53,48 @@ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', plac
26
53
  return moment(new Date()).format('L');
27
54
  };
28
55
 
56
+ const handleBlur = (e) => {
57
+ const value = e.target.value;
58
+ if (moment(value).format(format) === 'Invalid date') onChange('');
59
+ else if (moment(value).startOf('day').isBefore(momentMinDate, 'days')) onChange(formatedMinDate);
60
+ else if (moment(value).endOf('day').isAfter(momentMaxDate, 'days')) onChange(formatedMaxDate);
61
+ else onChange(moment(value).format(format));
62
+ };
63
+
29
64
  return (
30
- <div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
65
+ <div
66
+ className={cn('input__wrap calendar-container', className, {
67
+ 'calendar-container_disabled': disabled,
68
+ })}
69
+ ref={calendarRef}
70
+ >
31
71
  <InputMask
32
72
  mask={mask}
33
73
  placeholder={placeholder}
34
74
  value={value}
35
75
  onChange={(e) => changeInputValue(e.target.value)}
36
76
  className="calendar-dropdown"
37
- onFocus={() => setIsOpened(!isOpened)}
77
+ onFocus={() => setIsOpened(true)}
78
+ onBlur={!isOpened ? handleBlur : () => {}}
79
+ onKeyUp={e => {
80
+ if (e.key === 'Enter') e.target.blur();
81
+ setIsOpened(false);
82
+ }}
38
83
  />
39
84
  {isOpened ? (
40
85
  <Calendar
41
86
  date={getCalendarValue(value)}
42
87
  setDate={(newDate) => changeCalendarDay(newDate)}
43
- params={{ minDate, maxDate }}
44
- dontLimitFuture={dontLimitFuture}
88
+ params={{
89
+ format,
90
+ minDate: formatedMinDate,
91
+ maxDate: formatedMaxDate,
92
+ momentMinDate,
93
+ momentMaxDate,
94
+ isDontLimitFuture
95
+ }}
96
+ isListTop={isListTop}
97
+ setIsOpened={setIsOpened}
45
98
  />
46
99
  ) : null}
47
100
  </div>
@@ -0,0 +1,23 @@
1
+ .calendar-container {
2
+ min-width: 200px;
3
+ position: relative;
4
+
5
+ &_disabled {
6
+ pointer-events: none;
7
+ opacity: 0.5;
8
+ }
9
+
10
+ .calendar {
11
+ position: absolute;
12
+ z-index: 9;
13
+ top: 100%;
14
+ padding: 10px 16px;
15
+ border: 1px solid var(--border-color);
16
+
17
+ &_list-top {
18
+ bottom: calc(100% + 4px);
19
+ top: auto;
20
+ box-shadow: 0 -3px 15px rgb(0 0 0 / 15%);
21
+ }
22
+ }
23
+ }
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import InputCalendar from './InputCalendar';
3
3
 
4
4
  global.lng = 'en';
@@ -15,15 +15,25 @@ export default {
15
15
 
16
16
  const Template = (args) => {
17
17
  const [date, setDate] = useState('');
18
+ const [disabled, setDisabled] = useState(false);
18
19
 
19
- return <InputCalendar {...args} value={date} onChange={(val) => setDate(val)} />;
20
+ return (
21
+ <>
22
+ <InputCalendar {...args} value={date} onChange={(val) => setDate(val)} disabled={disabled} />
23
+ <div style={{ display: 'flex', flexFlow: 'row nowrap', justifyContent: 'flex-end', marginTop: '10px' }}>
24
+ <button style={{ border: 'solid 1px black', padding: '10px', width: '80px' }} onClick={() => setDisabled(!disabled)}>
25
+ {disabled ? 'Enable' : 'Disable'}
26
+ </button>
27
+ </div>
28
+ </>
29
+ );
20
30
  };
21
31
 
22
32
  export const CalendarTemplate = Template.bind({});
23
33
 
24
34
  CalendarTemplate.args = {
25
- value: '',
26
- // minDate: '10/14/2020',
27
- // maxDate: '10/14/2022',
28
- dontLimitFuture: true,
35
+ minDate: '01/10/2022',
36
+ maxDate: '04/20/2022',
37
+ // isDontLimitFuture: true,
38
+ // isListTop: true,
29
39
  };
@@ -9,7 +9,7 @@ import Arrow from '../../UI/Arrow/Arrow';
9
9
 
10
10
  import './InputDateRange.scss';
11
11
 
12
- const InputDateRange = props => {
12
+ const InputDateRange = (props) => {
13
13
  const {
14
14
  txt,
15
15
  id,
@@ -26,8 +26,21 @@ const InputDateRange = props => {
26
26
  isUseAbs,
27
27
  minDate = null,
28
28
  maxDate = null,
29
+ format = 'MM/DD/YYYY',
30
+ isDontLimitFuture,
29
31
  } = props;
30
32
 
33
+ const formatedMinDate = moment(minDate).format(format) !== 'Invalid date'
34
+ ? moment(minDate).format(format)
35
+ : null;
36
+
37
+ const formatedMaxDate = moment(maxDate).format(format) !== 'Invalid date'
38
+ ? moment(maxDate).format(format)
39
+ : null;
40
+
41
+ const momentMinDate = moment(formatedMinDate, format).startOf('day');
42
+ const momentMaxDate = moment(formatedMaxDate, format).startOf('day');
43
+
31
44
  const actualValues = getActualDateRange(value);
32
45
  const { isToggled, toggle, toggleOn, toggleOff } = useToggle(false);
33
46
  const [current, setCurrent] = useState(actualValues?.intervalKey);
@@ -36,16 +49,15 @@ const InputDateRange = props => {
36
49
  const ref = !isUseAbs ? useClickOutside(toggleOff) : useRef(null);
37
50
  const internalContainerRef = useRef(null);
38
51
 
39
- const handleChange = input => {
40
-
52
+ const handleChange = (input) => {
41
53
  const newValue = getActualDateRange(input);
42
54
  const formatedValue = {
43
55
  intervalKey: newValue.intervalKey,
44
- start: newValue.start ? moment(newValue.start).format('YYYY-MM-DDTHH:mm') : newValue.start,
45
- end: newValue.end ? moment(newValue.end).format('YYYY-MM-DDTHH:mm') : newValue.end,
56
+ start: newValue.start ? moment(newValue.start).format(format || 'YYYY-MM-DDTHH:mm') : newValue.start,
57
+ end: newValue.end ? moment(newValue.end).format(format || 'YYYY-MM-DDTHH:mm') : newValue.end,
46
58
  ...(newValue.compare ? { compare: newValue.compare } : {}),
47
- ...(newValue.startPrevDate ? { startPrevDate: moment(newValue.startPrevDate).format('YYYY-MM-DDTHH:mm') } : {}),
48
- ...(newValue.endPrevDate ? { endPrevDate: moment(newValue.endPrevDate).format('YYYY-MM-DDTHH:mm') } : {})
59
+ ...(newValue.startPrevDate ? { startPrevDate: moment(newValue.startPrevDate).format(format || 'YYYY-MM-DDTHH:mm') } : {}),
60
+ ...(newValue.endPrevDate ? { endPrevDate: moment(newValue.endPrevDate).format(format || 'YYYY-MM-DDTHH:mm') } : {}),
49
61
  };
50
62
 
51
63
  onChange(formatedValue);
@@ -69,9 +81,9 @@ const InputDateRange = props => {
69
81
  endTime !== '00:00' ? `(${endTime})` : ''
70
82
  }`;
71
83
 
72
- const getClasses = base =>
84
+ const getClasses = (base) =>
73
85
  cn('date-range-input__range-text', {
74
- 'date-range-input__range-text_little': base.length > SYMBOLS_QUANTITY_IF_TIME_ADDED
86
+ 'date-range-input__range-text_little': base.length > SYMBOLS_QUANTITY_IF_TIME_ADDED,
75
87
  });
76
88
 
77
89
  return (
@@ -113,16 +125,16 @@ const InputDateRange = props => {
113
125
  ...value,
114
126
  intervalKey: getActualDateRange({
115
127
  start: newStart,
116
- end: newEnd
128
+ end: newEnd,
117
129
  })?.intervalKey,
118
130
  start: newStart,
119
131
  end: newEnd,
120
132
  startPrevDate,
121
- endPrevDate
133
+ endPrevDate,
122
134
  });
123
135
  };
124
136
 
125
- const handleArrowClick = type => {
137
+ const handleArrowClick = (type) => {
126
138
  slideInterval(type === 'right' ? 'forward' : 'back');
127
139
  toggleOff();
128
140
  };
@@ -135,7 +147,7 @@ const InputDateRange = props => {
135
147
  'date-range-input_hide-arrows': hideArrows,
136
148
  'date-range-input_focused': isToggled,
137
149
  'date-range-input_error': error,
138
- 'date-range-input_disabled': disabled
150
+ 'date-range-input_disabled': disabled,
139
151
  })}
140
152
  >
141
153
  <span className="date-range-input__label">{label}</span>
@@ -147,7 +159,7 @@ const InputDateRange = props => {
147
159
  >
148
160
  <div
149
161
  className={cn('date-range-input__absolut-wraper', {
150
- 'date-range-input__absolut-wraper_right-position': isOptionsRight
162
+ 'date-range-input__absolut-wraper_right-position': isOptionsRight,
151
163
  })}
152
164
  >
153
165
  <div className={cn('date-range-input__static-part')}>
@@ -160,7 +172,7 @@ const InputDateRange = props => {
160
172
  <div className="date-range-input__interval-key">
161
173
  <span>
162
174
  {(txt?.labels && txt.labels[actualValues?.intervalKey]) ??
163
- (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
175
+ (INTERVALS[actualValues?.intervalKey]?.label || CUSTOM_INTERVAL_KEY_TEXT)}
164
176
  </span>
165
177
  {current !== ALL_TIME_KEY && <span>:</span>}
166
178
  </div>
@@ -176,7 +188,15 @@ const InputDateRange = props => {
176
188
  type="left"
177
189
  className="date-range-input__arrow"
178
190
  onClick={() => handleArrowClick('left')}
179
- disabled={disabled || actualValues?.intervalKey === ALL_TIME_KEY}
191
+ disabled={
192
+ disabled ||
193
+ actualValues?.intervalKey === ALL_TIME_KEY ||
194
+ (formatedMinDate &&
195
+ moment(actualValues?.start)
196
+ .subtract(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
197
+ .isBefore(momentMinDate)
198
+ )
199
+ }
180
200
  />
181
201
  <Arrow
182
202
  type="right"
@@ -185,10 +205,21 @@ const InputDateRange = props => {
185
205
  disabled={
186
206
  disabled ||
187
207
  actualValues?.intervalKey === ALL_TIME_KEY ||
188
- actualValues?.intervalKey === 'today' ||
189
- moment(actualValues?.end)
190
- .add(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
191
- .isAfter(moment().add(1, 'day').startOf('day'))
208
+ (!isDontLimitFuture &&
209
+ (formatedMaxDate
210
+ ? (
211
+ moment(actualValues?.end)
212
+ .endOf('day')
213
+ .subtract(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
214
+ .isAfter(momentMaxDate.startOf('day'))
215
+ )
216
+ : (
217
+ moment(actualValues?.end)
218
+ .add(moment(actualValues?.end).diff(actualValues?.start, 'hours'), 'hours')
219
+ .isAfter(moment().add(1, 'day').startOf('day'))
220
+ )
221
+ )
222
+ )
192
223
  }
193
224
  />
194
225
  </div>
@@ -205,8 +236,12 @@ const InputDateRange = props => {
205
236
  setIsCompare={setIsCompare}
206
237
  toggleOff={toggleOff}
207
238
  onChange={handleChange}
208
- minDate={minDate ? moment(minDate) : null}
209
- maxDate={maxDate ? moment(maxDate) : null}
239
+ minDate={formatedMinDate}
240
+ maxDate={formatedMaxDate}
241
+ format={format}
242
+ momentMinDate={momentMinDate}
243
+ momentMaxDate={momentMaxDate}
244
+ isDontLimitFuture={isDontLimitFuture}
210
245
  />
211
246
  )}
212
247
  </div>
@@ -1,4 +1,6 @@
1
1
  import React, { /* useEffect, */ useState } from 'react';
2
+ import moment from 'moment-timezone';
3
+
2
4
  import InputDateRange from './InputDateRange';
3
5
  import Table from '../Table/Table';
4
6
 
@@ -14,15 +16,13 @@ export default {
14
16
  // options: ['admin', 'user']
15
17
  // }
16
18
  // }
17
- }
19
+ },
18
20
  };
19
21
 
20
- const Template = args => {
22
+ const Template = (args) => {
21
23
  const { dateRange, ...restOfProps } = args;
22
24
  const [value, setValue] = useState(dateRange);
23
- // useEffect(() => console.log(value), [value]);
24
25
 
25
- // return <InputDateRange {...restOfProps} value={value} onChange={setValue} />;
26
26
  return (
27
27
  <div>
28
28
  <div className="mb20">
@@ -38,7 +38,7 @@ InputDateRangeTemplate.args = {
38
38
  txt: {},
39
39
  buttonsTypes: {
40
40
  // apply: 'ellipse-apply',
41
- cancel: 'bark-outline'
41
+ cancel: 'bark-outline',
42
42
  },
43
43
  label: 'Date Range',
44
44
  dateRange: { intervalKey: 'today' },
@@ -47,8 +47,10 @@ InputDateRangeTemplate.args = {
47
47
  error: false,
48
48
  disabled: false,
49
49
  isHoverable: false,
50
- minDate: "",
51
- maxDate: "",
50
+ // format: 'DD/MM/YYYY',
51
+ minDate: '01/10/2022',
52
+ maxDate: '04/20/2022',
53
+ // isDontLimitFuture: true,
52
54
  // short: true,
53
55
  isCompact: false,
54
56
  // isFocused: true,
@@ -56,7 +58,7 @@ InputDateRangeTemplate.args = {
56
58
  isCompareHidden: true,
57
59
  hideArrows: false,
58
60
  isOptionsRight: false,
59
- isShortWeekNames: false
61
+ isShortWeekNames: false,
60
62
  // limitRange,
61
63
  // isUseAbs,
62
64
  // absTooltip