intelicoreact 0.0.84 → 0.0.87

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 (25) hide show
  1. package/dist/Atomic/FormElements/Input/Input.js +1 -0
  2. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.js +23 -29
  3. package/dist/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +28 -11
  4. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.js +8 -2
  5. package/dist/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +2 -0
  6. package/dist/Atomic/FormElements/InputDateRange/components/Datepicker.js +35 -20
  7. package/dist/Atomic/FormElements/InputDateRange/components/OpenedPart.js +8 -2
  8. package/dist/Atomic/FormElements/InputDateRange/dependencies.js +1 -1
  9. package/dist/Atomic/FormElements/NumericInput/NumericInput.js +1 -0
  10. package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +4 -4
  11. package/dist/Atomic/UI/Calendar/Calendar.js +2 -2
  12. package/dist/Atomic/UI/Calendar/Calendar.scss +15 -3
  13. package/package.json +1 -1
  14. package/src/Atomic/FormElements/Input/Input.js +1 -0
  15. package/src/Atomic/FormElements/InputCalendar/InputCalendar.js +15 -16
  16. package/src/Atomic/FormElements/InputCalendar/InputCalendar.stories.js +16 -8
  17. package/src/Atomic/FormElements/InputDateRange/InputDateRange.js +5 -0
  18. package/src/Atomic/FormElements/InputDateRange/InputDateRange.stories.js +2 -0
  19. package/src/Atomic/FormElements/InputDateRange/components/Datepicker.js +41 -20
  20. package/src/Atomic/FormElements/InputDateRange/components/OpenedPart.js +5 -1
  21. package/src/Atomic/FormElements/InputDateRange/dependencies.js +1 -1
  22. package/src/Atomic/FormElements/NumericInput/NumericInput.js +1 -0
  23. package/src/Atomic/FormElements/RangeCalendar/RangeCalendar.scss +4 -4
  24. package/src/Atomic/UI/Calendar/Calendar.js +2 -2
  25. package/src/Atomic/UI/Calendar/Calendar.scss +15 -3
@@ -195,6 +195,7 @@ var Input = function Input(_ref) {
195
195
  }, [isAttemptToChange]);
196
196
  (0, _react.useEffect)(function () {
197
197
  if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
198
+ setEditing(isFocusDefault);
198
199
  }, [inputRef, isFocusDefault]);
199
200
  return /*#__PURE__*/_react.default.createElement("div", {
200
201
  className: (0, _classnames.default)("input__wrap", (0, _defineProperty2.default)({}, "input__wrap_focus", isFocused), (0, _defineProperty2.default)({}, "input__wrap_error", error || isToHighlightError), (0, _defineProperty2.default)({}, "input__wrap_disabled", disabled))
@@ -29,22 +29,18 @@ var InputCalendar = function InputCalendar(_ref) {
29
29
  var value = _ref.value,
30
30
  minDate = _ref.minDate,
31
31
  maxDate = _ref.maxDate,
32
- onChange = _ref.onChange;
33
-
34
- var _useState = (0, _react.useState)(value),
32
+ onChange = _ref.onChange,
33
+ _ref$className = _ref.className,
34
+ className = _ref$className === void 0 ? '' : _ref$className,
35
+ _ref$placeholder = _ref.placeholder,
36
+ placeholder = _ref$placeholder === void 0 ? 'mm/dd/yyyy' : _ref$placeholder,
37
+ _ref$mask = _ref.mask,
38
+ mask = _ref$mask === void 0 ? '99/99/9999' : _ref$mask;
39
+
40
+ var _useState = (0, _react.useState)(false),
35
41
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
36
- date = _useState2[0],
37
- setDate = _useState2[1];
38
-
39
- var _useState3 = (0, _react.useState)(date),
40
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
41
- inputValue = _useState4[0],
42
- setInputValue = _useState4[1];
43
-
44
- var _useState5 = (0, _react.useState)(false),
45
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
46
- isOpened = _useState6[0],
47
- setIsOpened = _useState6[1];
42
+ isOpened = _useState2[0],
43
+ setIsOpened = _useState2[1];
48
44
 
49
45
  var calendarRef = (0, _react.useRef)(null);
50
46
  (0, _useClickOutside.useClickOutside)(calendarRef, function () {
@@ -52,28 +48,26 @@ var InputCalendar = function InputCalendar(_ref) {
52
48
  });
53
49
 
54
50
  var changeInputValue = function changeInputValue(val) {
55
- if (!val.includes('_') && val) {
56
- setDate((0, _moment.default)(val).format('L'));
57
- setInputValue((0, _moment.default)(val).format('L'));
58
- } else {
59
- setInputValue(val);
60
- }
61
-
62
- if (onChange) onChange();
51
+ if (onChange) onChange(val);
63
52
  };
64
53
 
65
54
  var changeCalendarDay = function changeCalendarDay(val) {
66
- setDate(val);
67
- setInputValue(val);
68
55
  if (onChange) onChange(val);
69
56
  };
70
57
 
58
+ var getCalendarValue = function getCalendarValue(value) {
59
+ var date = (0, _moment.default)(value).format('L');
60
+ if (date !== "Invalid date") return date;
61
+ return (0, _moment.default)(new Date()).format('L');
62
+ };
63
+
71
64
  return /*#__PURE__*/_react.default.createElement("div", {
72
- className: "calendar-container",
65
+ className: "input__wrap calendar-container ".concat(className),
73
66
  ref: calendarRef
74
67
  }, /*#__PURE__*/_react.default.createElement(_reactInputMask.default, {
75
- mask: "99/99/9999",
76
- value: inputValue,
68
+ mask: mask,
69
+ placeholder: placeholder,
70
+ value: value,
77
71
  onChange: function onChange(e) {
78
72
  return changeInputValue(e.target.value);
79
73
  },
@@ -82,7 +76,7 @@ var InputCalendar = function InputCalendar(_ref) {
82
76
  return setIsOpened(!isOpened);
83
77
  }
84
78
  }), isOpened ? /*#__PURE__*/_react.default.createElement(_Calendar.default, {
85
- date: date,
79
+ date: getCalendarValue(value),
86
80
  setDate: function setDate(newDate) {
87
81
  return changeCalendarDay(newDate);
88
82
  },
@@ -7,11 +7,13 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.Calendar = exports.default = void 0;
10
+ exports.CalendarTemplate = exports.default = void 0;
11
11
 
12
- var _react = _interopRequireWildcard(require("react"));
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
15
 
14
- var _yup = require("yup");
16
+ var _react = _interopRequireWildcard(require("react"));
15
17
 
16
18
  var _InputCalendar = _interopRequireDefault(require("./InputCalendar"));
17
19
 
@@ -21,19 +23,34 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
21
23
 
22
24
  global.lng = 'en';
23
25
  var _default = {
24
- title: 'Form Elements/InputCalendar',
25
- component: _InputCalendar.default
26
+ title: 'Form Elements/Input Calendar',
27
+ component: _InputCalendar.default,
28
+ argTypes: {
29
+ value: {
30
+ description: 'string (mm.dd.yyyy)'
31
+ }
32
+ }
26
33
  };
27
34
  exports.default = _default;
28
35
 
29
36
  var Template = function Template(args) {
30
- return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, args);
37
+ var _useState = (0, _react.useState)(''),
38
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
39
+ date = _useState2[0],
40
+ setDate = _useState2[1];
41
+
42
+ return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, (0, _extends2.default)({}, args, {
43
+ value: date,
44
+ onChange: function onChange(val) {
45
+ return setDate(val);
46
+ }
47
+ }));
31
48
  };
32
49
 
33
- var Calendar = Template.bind({});
34
- exports.Calendar = Calendar;
35
- Calendar.args = {
36
- value: '10/14/2021',
50
+ var CalendarTemplate = Template.bind({});
51
+ exports.CalendarTemplate = CalendarTemplate;
52
+ CalendarTemplate.args = {
53
+ value: '',
37
54
  minDate: '10/14/2020',
38
- maxDate: '10/14/2023'
55
+ maxDate: '10/14/2022'
39
56
  };
@@ -55,7 +55,11 @@ var InputDateRange = function InputDateRange(props) {
55
55
  _props$hideArrows = props.hideArrows,
56
56
  hideArrows = _props$hideArrows === void 0 ? false : _props$hideArrows,
57
57
  isOptionsRight = props.isOptionsRight,
58
- isUseAbs = props.isUseAbs;
58
+ isUseAbs = props.isUseAbs,
59
+ _props$minDate = props.minDate,
60
+ minDate = _props$minDate === void 0 ? null : _props$minDate,
61
+ _props$maxDate = props.maxDate,
62
+ maxDate = _props$maxDate === void 0 ? null : _props$maxDate;
59
63
  var actualValues = (0, _dependencies.getActualDateRange)(value);
60
64
 
61
65
  var _useToggle = (0, _dependencies.useToggle)(false),
@@ -223,7 +227,9 @@ var InputDateRange = function InputDateRange(props) {
223
227
  isCompare: isCompare,
224
228
  setIsCompare: setIsCompare,
225
229
  toggleOff: toggleOff,
226
- onChange: handleChange
230
+ onChange: handleChange,
231
+ minDate: minDate ? (0, _momentTimezone.default)(minDate) : null,
232
+ maxDate: maxDate ? (0, _momentTimezone.default)(maxDate) : null
227
233
  })))), error && /*#__PURE__*/_react.default.createElement("span", {
228
234
  className: "date-range-input__error-block"
229
235
  }, error));
@@ -77,6 +77,8 @@ InputDateRangeTemplate.args = {
77
77
  error: false,
78
78
  disabled: false,
79
79
  isHoverable: false,
80
+ minDate: "",
81
+ maxDate: "",
80
82
  // short: true,
81
83
  isCompact: false,
82
84
  // isFocused: true,
@@ -67,7 +67,11 @@ var Datepicker = function Datepicker(props) {
67
67
  limitRange = props.limitRange,
68
68
  handleItemClick = props.handleItemClick,
69
69
  setActiveInterval = props.setActiveInterval,
70
- isShortWeekNames = props.isShortWeekNames;
70
+ isShortWeekNames = props.isShortWeekNames,
71
+ _props$minDate = props.minDate,
72
+ minDate = _props$minDate === void 0 ? null : _props$minDate,
73
+ _props$maxDate = props.maxDate,
74
+ maxDate = _props$maxDate === void 0 ? null : _props$maxDate;
71
75
  var _values$start = values.start,
72
76
  start = _values$start === void 0 ? null : _values$start,
73
77
  _values$end = values.end,
@@ -275,20 +279,20 @@ var Datepicker = function Datepicker(props) {
275
279
 
276
280
  var handleChangeStartHour = function handleChangeStartHour(val) {
277
281
  setStartHour(+val);
278
- setStartDate((0, _momentTimezone.default)(startDate).set('hour', +val).toDate());
282
+ setStartDate((0, _momentTimezone.default)(startDate || (0, _momentTimezone.default)()).set('hour', +val).toDate());
279
283
  };
280
284
 
281
285
  var handleChangeEndHour = function handleChangeEndHour(val) {
282
286
  var newHour = +val;
283
287
  setEndHour(newHour);
284
- var newEndDate;
288
+ var newEndDate = (0, _momentTimezone.default)();
285
289
 
286
- if (prevEndHour.current === 0 && newHour !== 0) {
287
- newEndDate = (0, _momentTimezone.default)(endDate).subtract(1, 'days');
288
- } else if (prevEndHour.current !== 0 && newHour === 0) {
289
- newEndDate = (0, _momentTimezone.default)(endDate).add(1, 'days');
290
- } else {
291
- newEndDate = endDate;
290
+ if (endDate) {
291
+ if (prevEndHour.current === 0 && newHour !== 0) {
292
+ newEndDate = (0, _momentTimezone.default)(endDate).subtract(1, 'days');
293
+ } else if (prevEndHour.current !== 0 && newHour === 0) {
294
+ newEndDate = (0, _momentTimezone.default)(endDate).add(1, 'days');
295
+ }
292
296
  }
293
297
 
294
298
  prevEndHour.current = newHour;
@@ -343,14 +347,20 @@ var Datepicker = function Datepicker(props) {
343
347
  var handleStartDateBlur = function handleStartDateBlur(e) {
344
348
  var newDate;
345
349
 
346
- if ((0, _momentTimezone.default)(startDateInput).isValid()) {
347
- newDate = (0, _momentTimezone.default)(startDateInput).set('hour', parseInt(startHour, 10)).toDate();
348
- setStartDate(newDate);
349
- } else {
350
+ if (!(0, _momentTimezone.default)(startDateInput).isValid()) {
350
351
  newDate = startDate;
351
- setStartDateInput(newDate);
352
+ } else {
353
+ if (minDate && !(0, _momentTimezone.default)(startDateInput).isSameOrAfter(minDate)) {
354
+ newDate = minDate;
355
+ } else if (maxDate && !(0, _momentTimezone.default)(startDateInput).isSameOrBefore(maxDate)) {
356
+ newDate = maxDate;
357
+ } else {
358
+ newDate = (0, _momentTimezone.default)(startDateInput);
359
+ }
352
360
  }
353
361
 
362
+ setStartDateInput(newDate);
363
+ setStartDate(newDate.set('hour', parseInt(startHour, 10)).toDate());
354
364
  doBlur('start', e);
355
365
  setDate1((0, _momentTimezone.default)(newDate).isSameOrAfter((0, _momentTimezone.default)(date2), 'month') ? (0, _momentTimezone.default)(date2).subtract(1, 'month') : (0, _momentTimezone.default)(newDate));
356
366
  };
@@ -366,17 +376,22 @@ var Datepicker = function Datepicker(props) {
366
376
  var handleEndDateBlur = function handleEndDateBlur(e) {
367
377
  var newDate;
368
378
 
369
- if ((0, _momentTimezone.default)(endDateInput).isValid()) {
370
- newDate = (0, _momentTimezone.default)(endDateInput).set('hour', parseInt(endHour, 10)).toDate();
371
- setEndDate(addDay(newDate));
372
- } else {
379
+ if (!(0, _momentTimezone.default)(endDateInput).isValid()) {
373
380
  newDate = endDate;
374
- setEndDateInput(newDate);
381
+ } else {
382
+ if (minDate && !(0, _momentTimezone.default)(endDateInput).isSameOrAfter(minDate)) {
383
+ newDate = minDate;
384
+ } else if (maxDate && !(0, _momentTimezone.default)(endDateInput).isSameOrBefore(maxDate)) {
385
+ newDate = maxDate;
386
+ } else {
387
+ newDate = (0, _momentTimezone.default)(endDateInput);
388
+ }
375
389
  }
376
390
 
391
+ setEndDate(addDay(newDate.set('hour', parseInt(endHour, 10)).toDate()));
392
+ setEndDateInput(newDate);
377
393
  doBlur('end', e);
378
394
  setDate2(newDate);
379
- setEndDateInput();
380
395
  };
381
396
 
382
397
  var handleKeyPressed = function handleKeyPressed(code, e, type) {
@@ -56,7 +56,11 @@ var OpenedPart = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
56
56
  isCompare = props.isCompare,
57
57
  setIsCompare = props.setIsCompare,
58
58
  toggleOff = props.toggleOff,
59
- isShortWeekNames = props.isShortWeekNames;
59
+ isShortWeekNames = props.isShortWeekNames,
60
+ _props$minDate = props.minDate,
61
+ minDate = _props$minDate === void 0 ? null : _props$minDate,
62
+ _props$maxDate = props.maxDate,
63
+ maxDate = _props$maxDate === void 0 ? null : _props$maxDate;
60
64
 
61
65
  var items = isCompact ? (0, _toConsumableArray2.default)(Object.keys(_dependencies.INTERVALS)) : [].concat((0, _toConsumableArray2.default)(Object.keys(_dependencies.INTERVALS)), [_dependencies.CUSTOM_INTERVAL_KEY]);
62
66
 
@@ -148,7 +152,9 @@ var OpenedPart = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
148
152
  isCompareHidden: isCompareHidden,
149
153
  limitRange: limitRange,
150
154
  setActiveInterval: setActiveInterval,
151
- isShortWeekNames: isShortWeekNames
155
+ isShortWeekNames: isShortWeekNames,
156
+ minDate: minDate,
157
+ maxDate: maxDate
152
158
  })));
153
159
  });
154
160
 
@@ -154,7 +154,7 @@ var INTERVALS = {
154
154
  }
155
155
  },
156
156
  last6Months: {
157
- label: 'Last 6 Months',
157
+ label: '6 Months',
158
158
  start: function start() {
159
159
  return (0, _momentTimezone.default)().subtract(6, 'month').startOf('month');
160
160
  },
@@ -225,6 +225,7 @@ var NumericInput = function NumericInput(_ref) {
225
225
  }, [isFocused]);
226
226
  (0, _react.useEffect)(function () {
227
227
  if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
228
+ setEditing(isFocusDefault);
228
229
  }, [inputRef, isFocusDefault]);
229
230
 
230
231
  function renderInput() {
@@ -1,4 +1,4 @@
1
- .range-calendar {
1
+ .range-calendar, .calendar {
2
2
  width: 195px;
3
3
  min-height: 195px;
4
4
  display: flex;
@@ -12,7 +12,7 @@
12
12
  display: flex;
13
13
  justify-content: space-between;
14
14
  align-items: center;
15
-
15
+
16
16
  &__title {
17
17
  line-height: 20px;
18
18
  font-weight: 500;
@@ -27,7 +27,7 @@
27
27
  &__next, &__prev {
28
28
  width: 16px;
29
29
  height: 16px;
30
- background-color: #E2E6F8;
30
+ //background-color: #E2E6F8;
31
31
  border-radius: 5px;
32
32
  color: #171D33;
33
33
  }
@@ -98,4 +98,4 @@
98
98
  }
99
99
  }
100
100
  }
101
- }
101
+ }
@@ -115,7 +115,7 @@ function _default(props) {
115
115
  };
116
116
 
117
117
  return /*#__PURE__*/_react.default.createElement("div", {
118
- className: "calendar ".concat(className)
118
+ className: "calendar ".concat(className ? className : "")
119
119
  }, /*#__PURE__*/_react.default.createElement("div", {
120
120
  className: "calendar-header"
121
121
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -134,7 +134,7 @@ function _default(props) {
134
134
  return /*#__PURE__*/_react.default.createElement("div", {
135
135
  key: "day-of-week_".concat(dayOfWeek),
136
136
  className: "calendar__day calendar__day--title"
137
- }, (0, _moment.default)().weekday(dayOfWeek).format('dd').charAt(0));
137
+ }, (0, _moment.default)().weekday(dayOfWeek).format('dd'));
138
138
  })), Object.keys(days).map(function (week, index) {
139
139
  return /*#__PURE__*/_react.default.createElement("div", {
140
140
  key: "week_".concat(index),
@@ -429,6 +429,12 @@
429
429
  display: flex;
430
430
  justify-content: center;
431
431
  align-items: center;
432
+
433
+ &__prev,
434
+ &__next{
435
+ display: flex;
436
+ height: auto;
437
+ }
432
438
  }
433
439
  .calendar {
434
440
  background: #ffffff;
@@ -511,15 +517,21 @@
511
517
  }
512
518
 
513
519
  &-container {
514
- width: 200px;
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
+ }
515
529
  }
516
530
 
517
531
  &-dropdown {
518
532
  appearance: none;
519
533
  background-color: white;
520
534
  cursor: pointer;
521
- color: gray;
522
-
523
535
  width: 100%;
524
536
  height: 28px;
525
537
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "0.0.84",
3
+ "version": "0.0.87",
4
4
  "description": "fix input-calendar",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -147,6 +147,7 @@ const Input = ({
147
147
  useEffect(() => {
148
148
  if (inputRef?.current && typeof isFocusDefault === 'boolean')
149
149
  setIsFocused(isFocusDefault);
150
+ setEditing(isFocusDefault);
150
151
  }, [inputRef, isFocusDefault]);
151
152
 
152
153
  return (
@@ -4,40 +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 = ({ value, minDate, maxDate, onChange }) => {
8
- const [date, setDate] = useState(value);
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
13
  const changeInputValue = val => {
16
- if (!val.includes('_') && val) {
17
- setDate(moment(val).format('L'));
18
- setInputValue(moment(val).format('L'));
19
- } else {
20
- setInputValue(val);
21
- }
22
- if(onChange) onChange();
14
+ if (onChange) onChange(val);
23
15
  };
24
16
 
25
17
  const changeCalendarDay = val => {
26
- setDate(val);
27
- setInputValue(val);
28
18
  if (onChange) onChange(val);
29
19
  };
30
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
+
31
29
  return (
32
- <div className="calendar-container" ref={calendarRef}>
30
+ <div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
33
31
  <InputMask
34
- mask="99/99/9999"
35
- value={inputValue}
32
+ mask={mask}
33
+ placeholder={placeholder}
34
+ value={value}
36
35
  onChange={e => changeInputValue(e.target.value)}
37
36
  className="calendar-dropdown"
38
37
  onFocus={() => setIsOpened(!isOpened)}
39
38
  />
40
- {isOpened ? <Calendar date={date} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
39
+ {isOpened ? <Calendar date={getCalendarValue(value)} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
41
40
  </div>
42
41
  );
43
42
  };
@@ -1,22 +1,30 @@
1
- import React, { useRef, useState } from '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/InputCalendar',
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
17
  const Template = args => {
13
- return <InputCalendar {...args} />;
18
+ const [date, setDate] = useState('');
19
+
20
+ return <InputCalendar {...args} value={date} onChange={val => setDate(val)} />;
14
21
  };
15
22
 
16
- export const Calendar = Template.bind({});
23
+ export const CalendarTemplate = Template.bind({});
17
24
 
18
- Calendar.args = {
19
- value: '10/14/2021',
25
+ CalendarTemplate.args = {
26
+ value: '',
20
27
  minDate: '10/14/2020',
21
- maxDate: '10/14/2023',
28
+ maxDate: '10/14/2022',
29
+
22
30
  };
@@ -24,6 +24,8 @@ const InputDateRange = props => {
24
24
  hideArrows = false,
25
25
  isOptionsRight,
26
26
  isUseAbs,
27
+ minDate = null,
28
+ maxDate = null,
27
29
  } = props;
28
30
 
29
31
  const actualValues = getActualDateRange(value);
@@ -35,6 +37,7 @@ const InputDateRange = props => {
35
37
  const internalContainerRef = useRef(null);
36
38
 
37
39
  const handleChange = input => {
40
+
38
41
  const newValue = getActualDateRange(input);
39
42
  const formatedValue = {
40
43
  intervalKey: newValue.intervalKey,
@@ -202,6 +205,8 @@ const InputDateRange = props => {
202
205
  setIsCompare={setIsCompare}
203
206
  toggleOff={toggleOff}
204
207
  onChange={handleChange}
208
+ minDate={minDate ? moment(minDate) : null}
209
+ maxDate={maxDate ? moment(maxDate) : null}
205
210
  />
206
211
  )}
207
212
  </div>
@@ -47,6 +47,8 @@ InputDateRangeTemplate.args = {
47
47
  error: false,
48
48
  disabled: false,
49
49
  isHoverable: false,
50
+ minDate: "",
51
+ maxDate: "",
50
52
  // short: true,
51
53
  isCompact: false,
52
54
  // isFocused: true,
@@ -41,7 +41,9 @@ const Datepicker = props => {
41
41
  limitRange,
42
42
  handleItemClick,
43
43
  setActiveInterval,
44
- isShortWeekNames
44
+ isShortWeekNames,
45
+ minDate = null,
46
+ maxDate = null
45
47
  } = props;
46
48
  const { start = null, end = null, compare = false } = values;
47
49
  const startDateInputRef = useRef(null);
@@ -191,7 +193,7 @@ const Datepicker = props => {
191
193
  const handleChangeStartHour = val => {
192
194
  setStartHour(+val);
193
195
  setStartDate(
194
- moment(startDate)
196
+ moment(startDate || moment())
195
197
  .set('hour', +val)
196
198
  .toDate(),
197
199
  );
@@ -200,14 +202,16 @@ const Datepicker = props => {
200
202
  const handleChangeEndHour = val => {
201
203
  const newHour = +val;
202
204
  setEndHour(newHour);
203
- let newEndDate;
204
- if (prevEndHour.current === 0 && newHour !== 0) {
205
- newEndDate = moment(endDate).subtract(1, 'days');
206
- } else if (prevEndHour.current !== 0 && newHour === 0) {
207
- newEndDate = moment(endDate).add(1, 'days');
208
- } else {
209
- newEndDate = endDate;
205
+ let newEndDate = moment();
206
+
207
+ if(endDate){
208
+ if (prevEndHour.current === 0 && newHour !== 0) {
209
+ newEndDate = moment(endDate).subtract(1, 'days');
210
+ } else if (prevEndHour.current !== 0 && newHour === 0) {
211
+ newEndDate = moment(endDate).add(1, 'days');
212
+ }
210
213
  }
214
+
211
215
  prevEndHour.current = newHour;
212
216
  setEndDate(moment(newEndDate).set('hour', newHour).toDate());
213
217
  };
@@ -256,13 +260,22 @@ const Datepicker = props => {
256
260
 
257
261
  const handleStartDateBlur = e => {
258
262
  let newDate;
259
- if (moment(startDateInput).isValid()) {
260
- newDate = moment(startDateInput).set('hour', parseInt(startHour, 10)).toDate();
261
- setStartDate(newDate);
263
+
264
+ if(!moment(startDateInput).isValid()){
265
+ newDate = startDate;
262
266
  } else {
263
- newDate = startDate;
264
- setStartDateInput(newDate);
267
+ if(minDate && !moment(startDateInput).isSameOrAfter(minDate)){
268
+ newDate = minDate;
269
+ } else if(maxDate && !moment(startDateInput).isSameOrBefore(maxDate)){
270
+ newDate = maxDate;
271
+ } else {
272
+ newDate = moment(startDateInput);
273
+ }
265
274
  }
275
+
276
+ setStartDateInput(newDate);
277
+ setStartDate(newDate.set('hour', parseInt(startHour, 10)).toDate());
278
+
266
279
  doBlur('start', e);
267
280
  setDate1(
268
281
  moment(newDate).isSameOrAfter(moment(date2), 'month') ? moment(date2).subtract(1, 'month') : moment(newDate),
@@ -277,16 +290,24 @@ const Datepicker = props => {
277
290
 
278
291
  const handleEndDateBlur = e => {
279
292
  let newDate;
280
- if (moment(endDateInput).isValid()) {
281
- newDate = moment(endDateInput).set('hour', parseInt(endHour, 10)).toDate();
282
- setEndDate(addDay(newDate));
293
+
294
+ if(!moment(endDateInput).isValid()){
295
+ newDate = endDate;
283
296
  } else {
284
- newDate = endDate;
285
- setEndDateInput(newDate);
297
+ if(minDate && !moment(endDateInput).isSameOrAfter(minDate)){
298
+ newDate = minDate;
299
+ } else if(maxDate && !moment(endDateInput).isSameOrBefore(maxDate)){
300
+ newDate = maxDate;
301
+ } else {
302
+ newDate = moment(endDateInput);
303
+ }
286
304
  }
305
+
306
+ setEndDate(addDay(newDate.set('hour', parseInt(endHour, 10)).toDate()));
307
+ setEndDateInput(newDate);
308
+
287
309
  doBlur('end', e);
288
310
  setDate2(newDate);
289
- setEndDateInput();
290
311
  };
291
312
 
292
313
  const handleKeyPressed = (code, e, type) => {
@@ -25,7 +25,9 @@ const OpenedPart = React.forwardRef((props, ref) => {
25
25
  isCompare,
26
26
  setIsCompare,
27
27
  toggleOff,
28
- isShortWeekNames
28
+ isShortWeekNames,
29
+ minDate = null,
30
+ maxDate = null
29
31
  } = props;
30
32
 
31
33
  const items = isCompact ? [...Object.keys(intervals)] : [...Object.keys(intervals), customKey];
@@ -105,6 +107,8 @@ const OpenedPart = React.forwardRef((props, ref) => {
105
107
  limitRange={limitRange}
106
108
  setActiveInterval={setActiveInterval}
107
109
  isShortWeekNames={isShortWeekNames}
110
+ minDate={minDate}
111
+ maxDate={maxDate}
108
112
  />
109
113
  )}
110
114
  </div>
@@ -89,7 +89,7 @@ export const INTERVALS = {
89
89
  end: () => moment().startOf('month'),
90
90
  },
91
91
  last6Months: {
92
- label: 'Last 6 Months',
92
+ label: '6 Months',
93
93
  start: () => moment().subtract(6, 'month').startOf('month'),
94
94
  end: () => moment().startOf('month'),
95
95
  },
@@ -192,6 +192,7 @@ const NumericInput = ({
192
192
  useEffect(() => {
193
193
  if (inputRef?.current && typeof isFocusDefault === 'boolean')
194
194
  setIsFocused(isFocusDefault);
195
+ setEditing(isFocusDefault)
195
196
  }, [inputRef, isFocusDefault]);
196
197
 
197
198
  function renderInput() {
@@ -1,4 +1,4 @@
1
- .range-calendar {
1
+ .range-calendar, .calendar {
2
2
  width: 195px;
3
3
  min-height: 195px;
4
4
  display: flex;
@@ -12,7 +12,7 @@
12
12
  display: flex;
13
13
  justify-content: space-between;
14
14
  align-items: center;
15
-
15
+
16
16
  &__title {
17
17
  line-height: 20px;
18
18
  font-weight: 500;
@@ -27,7 +27,7 @@
27
27
  &__next, &__prev {
28
28
  width: 16px;
29
29
  height: 16px;
30
- background-color: #E2E6F8;
30
+ //background-color: #E2E6F8;
31
31
  border-radius: 5px;
32
32
  color: #171D33;
33
33
  }
@@ -98,4 +98,4 @@
98
98
  }
99
99
  }
100
100
  }
101
- }
101
+ }
@@ -70,7 +70,7 @@ export default function (props) {
70
70
  };
71
71
 
72
72
  return (
73
- <div className={`calendar ${className}`}>
73
+ <div className={`calendar ${className ? className : ""}`}>
74
74
  <div className="calendar-header">
75
75
  <div className="calendar-header__prev">
76
76
  {allowPrev && (
@@ -92,7 +92,7 @@ export default function (props) {
92
92
  {[...Array(7).keys()].map((dayOfWeek) => {
93
93
  return (
94
94
  <div key={`day-of-week_${dayOfWeek}`} className="calendar__day calendar__day--title">
95
- {moment().weekday(dayOfWeek).format('dd').charAt(0)}
95
+ {moment().weekday(dayOfWeek).format('dd')}
96
96
  </div>
97
97
  );
98
98
  })}
@@ -429,6 +429,12 @@
429
429
  display: flex;
430
430
  justify-content: center;
431
431
  align-items: center;
432
+
433
+ &__prev,
434
+ &__next{
435
+ display: flex;
436
+ height: auto;
437
+ }
432
438
  }
433
439
  .calendar {
434
440
  background: #ffffff;
@@ -511,15 +517,21 @@
511
517
  }
512
518
 
513
519
  &-container {
514
- width: 200px;
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
+ }
515
529
  }
516
530
 
517
531
  &-dropdown {
518
532
  appearance: none;
519
533
  background-color: white;
520
534
  cursor: pointer;
521
- color: gray;
522
-
523
535
  width: 100%;
524
536
  height: 28px;
525
537