@alfalab/core-components-calendar-range 6.1.0 → 6.2.1

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/Component.d.ts CHANGED
@@ -48,6 +48,10 @@ type CalendarRangeProps = {
48
48
  dateTo: number | null;
49
49
  valueTo: string;
50
50
  }) => void;
51
+ /**
52
+ * Коллбэк, срабатывающий при возникновении ошибок валидации дат внутри компонента.
53
+ */
54
+ onError?: (hasError: boolean) => void;
51
55
  /**
52
56
  * Список событий
53
57
  */
package/Component.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index_module = require('./index.module-bcd9b9e1.js');
5
+ var index_module = require('./index.module-21c6d28e.js');
6
6
  var React = require('react');
7
7
  require('classnames');
8
8
  require('date-fns/startOfMonth');
@@ -48,6 +48,10 @@ type CalendarRangeProps = {
48
48
  dateTo: number | null;
49
49
  valueTo: string;
50
50
  }) => void;
51
+ /**
52
+ * Коллбэк, срабатывающий при возникновении ошибок валидации дат внутри компонента.
53
+ */
54
+ onError?: (hasError: boolean) => void;
51
55
  /**
52
56
  * Список событий
53
57
  */
@@ -24,7 +24,7 @@ var startOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(startOfMonth);
24
24
  var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
25
25
 
26
26
  var CalendarRangePopover = function (_a) {
27
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
27
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, onError = _a.onError, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
28
28
  var _k = React.useState(valueFrom), inputFromValue = _k[0], setInputFromValue = _k[1];
29
29
  var _l = React.useState(valueTo), inputToValue = _l[0], setInputToValue = _l[1];
30
30
  /**
@@ -44,6 +44,7 @@ var CalendarRangePopover = function (_a) {
44
44
  var bothInvalid = coreComponentsDateInput.isCompleteDateInput(inputFromValue) &&
45
45
  coreComponentsDateInput.isCompleteDateInput(inputToValue) &&
46
46
  coreComponentsCalendarInput.parseDateString(inputFromValue).getTime() > coreComponentsCalendarInput.parseDateString(inputToValue).getTime();
47
+ var hasValidateError = inputFromInvalid || inputToInvalid || bothInvalid;
47
48
  var _q = hooks.usePopoverViewMonthes({
48
49
  dateFrom: dateFrom,
49
50
  dateTo: dateTo,
@@ -109,6 +110,12 @@ var CalendarRangePopover = function (_a) {
109
110
  }
110
111
  // eslint-disable-next-line react-hooks/exhaustive-deps
111
112
  }, [inputToValue]);
113
+ React.useEffect(function () {
114
+ if (onError) {
115
+ onError(hasValidateError);
116
+ }
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, [hasValidateError]);
112
119
  return (React__default['default'].createElement("div", { className: cn__default['default'](styles__default['default'].component, className), "data-test-id": dataTestId },
113
120
  React__default['default'].createElement(coreComponentsCalendarInput.CalendarInput, tslib_es6.__assign({}, inputFromProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-start', error: inputFromInvalid || bothInvalid || inputFromProps.error, onChange: handleFromChange, onInputChange: handleInputFromChange, onBlur: handleInputFromBlur, value: inputFromValue, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: tslib_es6.__assign(tslib_es6.__assign({}, inputFromProps.calendarProps), { month: monthFrom, onMonthChange: handleMonthFromChange, selectorView: 'full' }) })),
114
121
  React__default['default'].createElement("span", { className: styles__default['default'].divider }),
@@ -31,7 +31,7 @@ var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
31
31
  var endOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(endOfMonth);
32
32
 
33
33
  var CalendarRangeStatic = function (_a) {
34
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
34
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, onError = _a.onError, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
35
35
  var _l = React.useState(valueFrom), inputFromValue = _l[0], setInputFromValue = _l[1];
36
36
  var _m = React.useState(valueTo), inputToValue = _m[0], setInputToValue = _m[1];
37
37
  var dateFrom = coreComponentsCalendarInput.isValidInputValue(inputFromValue, minDate, maxDate, offDays)
@@ -53,8 +53,9 @@ var CalendarRangeStatic = function (_a) {
53
53
  });
54
54
  var validateInputFromValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, minDate, dateFrom || maxDate, offDays); }, [dateFrom, maxDate, minDate, offDays]);
55
55
  var validateInputToValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, dateFrom || minDate, maxDate, offDays); }, [dateFrom, minDate, maxDate, offDays]);
56
- var _p = React.useState(validateInputFromValue(inputFromValue) === false), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
57
- var _q = React.useState(validateInputToValue(inputToValue) === false), inputToInvalid = _q[0], setInputToInvalid = _q[1];
56
+ var _p = React.useState(coreComponentsDateInput.isCompleteDateInput(inputFromValue) && dateFrom === null), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
57
+ var _q = React.useState(coreComponentsDateInput.isCompleteDateInput(inputToValue) && dateTo === null), inputToInvalid = _q[0], setInputToInvalid = _q[1];
58
+ var hasValidateError = bothInvalid || inputFromInvalid || inputToInvalid;
58
59
  var _r = hooks.useStaticViewMonthes({
59
60
  selectedFrom: period.selectedFrom,
60
61
  selectedTo: period.selectedTo,
@@ -147,6 +148,12 @@ var CalendarRangeStatic = function (_a) {
147
148
  }
148
149
  // eslint-disable-next-line react-hooks/exhaustive-deps
149
150
  }, [inputToValue]);
151
+ React.useEffect(function () {
152
+ if (onError) {
153
+ onError(hasValidateError);
154
+ }
155
+ // eslint-disable-next-line react-hooks/exhaustive-deps
156
+ }, [hasValidateError]);
150
157
  var rangeProps = hooks.useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
151
158
  var calendarFromProps = inputFromProps.calendarProps, dateInputFromProps = tslib_es6.__rest(inputFromProps, ["calendarProps"]);
152
159
  var calendarToProps = inputToProps.calendarProps, dateInputToProps = tslib_es6.__rest(inputToProps, ["calendarProps"]);
@@ -48,6 +48,10 @@ type CalendarRangeProps = {
48
48
  dateTo: number | null;
49
49
  valueTo: string;
50
50
  }) => void;
51
+ /**
52
+ * Коллбэк, срабатывающий при возникновении ошибок валидации дат внутри компонента.
53
+ */
54
+ onError?: (hasError: boolean) => void;
51
55
  /**
52
56
  * Список событий
53
57
  */
package/esm/Component.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as __rest, a as __assign } from './index.module-a0ca67a7.js';
1
+ import { _ as __rest, a as __assign } from './index.module-5143c3f7.js';
2
2
  import React from 'react';
3
3
  import 'classnames';
4
4
  import 'date-fns/startOfMonth';
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import './index.module-a0ca67a7.js';
1
+ import './index.module-5143c3f7.js';
2
2
  import 'react';
3
3
  import 'classnames';
4
4
  import 'date-fns/startOfMonth';
@@ -37,7 +37,7 @@ function __rest(s, e) {
37
37
  return t;
38
38
  }
39
39
 
40
- var styles = {"component":"calendar-range__component_1o680","divider":"calendar-range__divider_1o680","static":"calendar-range__static_1o680","calendar":"calendar-range__calendar_1o680"};
40
+ var styles = {"component":"calendar-range__component_1a9ih","divider":"calendar-range__divider_1a9ih","static":"calendar-range__static_1a9ih","calendar":"calendar-range__calendar_1a9ih"};
41
41
  require('./views/index.css')
42
42
 
43
43
  export { __rest as _, __assign as a, styles as s };
@@ -1,4 +1,4 @@
1
- /* hash: 803om */
1
+ /* hash: hbbfm */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -36,19 +36,19 @@
36
36
 
37
37
  /* marker */
38
38
  }
39
- .calendar-range__component_1o680 {
39
+ .calendar-range__component_1a9ih {
40
40
  display: flex
41
41
  }
42
- .calendar-range__component_1o680 button[aria-selected='true'] {
42
+ .calendar-range__component_1a9ih button[aria-selected='true'] {
43
43
  cursor: pointer;
44
44
  }
45
- .calendar-range__component_1o680 *[class*='errorIcon_'] {
45
+ .calendar-range__component_1a9ih *[class*='errorIcon_'] {
46
46
  display: none;
47
47
  }
48
- .calendar-range__component_1o680 *[class*='calendarIcon_'] {
48
+ .calendar-range__component_1a9ih *[class*='calendarIcon_'] {
49
49
  margin-right: 0;
50
50
  }
51
- .calendar-range__divider_1o680 {
51
+ .calendar-range__divider_1a9ih {
52
52
  height: 48px;
53
53
  display: flex;
54
54
  align-items: center;
@@ -56,13 +56,13 @@
56
56
  width: 16px;
57
57
  margin: 0 var(--gap-xs)
58
58
  }
59
- .calendar-range__divider_1o680:after {
59
+ .calendar-range__divider_1a9ih:after {
60
60
  content: '';
61
61
  display: block;
62
62
  width: 100%;
63
63
  height: 1px;
64
64
  background-color: var(--color-light-graphic-primary);
65
65
  }
66
- .calendar-range__static_1o680 .calendar-range__calendar_1o680 {
66
+ .calendar-range__static_1a9ih .calendar-range__calendar_1a9ih {
67
67
  width: var(--calendar-inner-width);
68
68
  }
@@ -1,4 +1,4 @@
1
- import { s as styles, a as __assign } from '../index.module-a0ca67a7.js';
1
+ import { s as styles, a as __assign } from '../index.module-5143c3f7.js';
2
2
  import React, { useState, useCallback, useEffect } from 'react';
3
3
  import cn from 'classnames';
4
4
  import startOfMonth from 'date-fns/startOfMonth';
@@ -12,7 +12,7 @@ import 'date-fns/isEqual';
12
12
  import { usePopoverViewMonthes } from '../hooks.js';
13
13
 
14
14
  var CalendarRangePopover = function (_a) {
15
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth(new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
15
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth(new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, onError = _a.onError, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
16
16
  var _k = useState(valueFrom), inputFromValue = _k[0], setInputFromValue = _k[1];
17
17
  var _l = useState(valueTo), inputToValue = _l[0], setInputToValue = _l[1];
18
18
  /**
@@ -32,6 +32,7 @@ var CalendarRangePopover = function (_a) {
32
32
  var bothInvalid = isCompleteDateInput(inputFromValue) &&
33
33
  isCompleteDateInput(inputToValue) &&
34
34
  parseDateString(inputFromValue).getTime() > parseDateString(inputToValue).getTime();
35
+ var hasValidateError = inputFromInvalid || inputToInvalid || bothInvalid;
35
36
  var _q = usePopoverViewMonthes({
36
37
  dateFrom: dateFrom,
37
38
  dateTo: dateTo,
@@ -97,6 +98,12 @@ var CalendarRangePopover = function (_a) {
97
98
  }
98
99
  // eslint-disable-next-line react-hooks/exhaustive-deps
99
100
  }, [inputToValue]);
101
+ useEffect(function () {
102
+ if (onError) {
103
+ onError(hasValidateError);
104
+ }
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [hasValidateError]);
100
107
  return (React.createElement("div", { className: cn(styles.component, className), "data-test-id": dataTestId },
101
108
  React.createElement(CalendarInput, __assign({}, inputFromProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-start', error: inputFromInvalid || bothInvalid || inputFromProps.error, onChange: handleFromChange, onInputChange: handleInputFromChange, onBlur: handleInputFromBlur, value: inputFromValue, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: __assign(__assign({}, inputFromProps.calendarProps), { month: monthFrom, onMonthChange: handleMonthFromChange, selectorView: 'full' }) })),
102
109
  React.createElement("span", { className: styles.divider }),
@@ -1,4 +1,4 @@
1
- import { _ as __rest, s as styles, a as __assign } from '../index.module-a0ca67a7.js';
1
+ import { _ as __rest, s as styles, a as __assign } from '../index.module-5143c3f7.js';
2
2
  import React, { useState, useCallback, useEffect } from 'react';
3
3
  import cn from 'classnames';
4
4
  import startOfMonth from 'date-fns/startOfMonth';
@@ -15,7 +15,7 @@ import { usePeriodWithReset, Calendar } from '@alfalab/core-components-calendar/
15
15
  import { isDayButton } from '../utils.js';
16
16
 
17
17
  var CalendarRangeStatic = function (_a) {
18
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth(new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
18
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth(new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, onError = _a.onError, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
19
19
  var _l = useState(valueFrom), inputFromValue = _l[0], setInputFromValue = _l[1];
20
20
  var _m = useState(valueTo), inputToValue = _m[0], setInputToValue = _m[1];
21
21
  var dateFrom = isValidInputValue(inputFromValue, minDate, maxDate, offDays)
@@ -37,8 +37,9 @@ var CalendarRangeStatic = function (_a) {
37
37
  });
38
38
  var validateInputFromValue = useCallback(function (value) { return isValidInputValue(value, minDate, dateFrom || maxDate, offDays); }, [dateFrom, maxDate, minDate, offDays]);
39
39
  var validateInputToValue = useCallback(function (value) { return isValidInputValue(value, dateFrom || minDate, maxDate, offDays); }, [dateFrom, minDate, maxDate, offDays]);
40
- var _p = useState(validateInputFromValue(inputFromValue) === false), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
41
- var _q = useState(validateInputToValue(inputToValue) === false), inputToInvalid = _q[0], setInputToInvalid = _q[1];
40
+ var _p = useState(isCompleteDateInput(inputFromValue) && dateFrom === null), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
41
+ var _q = useState(isCompleteDateInput(inputToValue) && dateTo === null), inputToInvalid = _q[0], setInputToInvalid = _q[1];
42
+ var hasValidateError = bothInvalid || inputFromInvalid || inputToInvalid;
42
43
  var _r = useStaticViewMonthes({
43
44
  selectedFrom: period.selectedFrom,
44
45
  selectedTo: period.selectedTo,
@@ -131,6 +132,12 @@ var CalendarRangeStatic = function (_a) {
131
132
  }
132
133
  // eslint-disable-next-line react-hooks/exhaustive-deps
133
134
  }, [inputToValue]);
135
+ useEffect(function () {
136
+ if (onError) {
137
+ onError(hasValidateError);
138
+ }
139
+ // eslint-disable-next-line react-hooks/exhaustive-deps
140
+ }, [hasValidateError]);
134
141
  var rangeProps = useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
135
142
  var calendarFromProps = inputFromProps.calendarProps, dateInputFromProps = __rest(inputFromProps, ["calendarProps"]);
136
143
  var calendarToProps = inputToProps.calendarProps, dateInputToProps = __rest(inputToProps, ["calendarProps"]);
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./index.module-bcd9b9e1.js');
5
+ require('./index.module-21c6d28e.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('date-fns/startOfMonth');
@@ -39,7 +39,7 @@ function __rest(s, e) {
39
39
  return t;
40
40
  }
41
41
 
42
- var styles = {"component":"calendar-range__component_1o680","divider":"calendar-range__divider_1o680","static":"calendar-range__static_1o680","calendar":"calendar-range__calendar_1o680"};
42
+ var styles = {"component":"calendar-range__component_1a9ih","divider":"calendar-range__divider_1a9ih","static":"calendar-range__static_1a9ih","calendar":"calendar-range__calendar_1a9ih"};
43
43
  require('./views/index.css')
44
44
 
45
45
  exports.__rest = __rest;
@@ -48,6 +48,10 @@ type CalendarRangeProps = {
48
48
  dateTo: number | null;
49
49
  valueTo: string;
50
50
  }) => void;
51
+ /**
52
+ * Коллбэк, срабатывающий при возникновении ошибок валидации дат внутри компонента.
53
+ */
54
+ onError?: (hasError: boolean) => void;
51
55
  /**
52
56
  * Список событий
53
57
  */
@@ -9,7 +9,7 @@ import 'date-fns/max';
9
9
  import 'date-fns/min';
10
10
  import 'date-fns/isEqual';
11
11
  import './hooks.js';
12
- import './index.module-ff37a166.js';
12
+ import './index.module-407ef197.js';
13
13
  import { CalendarRangePopover } from './views/popover.js';
14
14
  import 'date-fns/endOfMonth';
15
15
  import '@alfalab/core-components-calendar/modern';
package/modern/index.js CHANGED
@@ -9,7 +9,7 @@ import 'date-fns/max';
9
9
  import 'date-fns/min';
10
10
  import 'date-fns/isEqual';
11
11
  import './hooks.js';
12
- import './index.module-ff37a166.js';
12
+ import './index.module-407ef197.js';
13
13
  import './views/popover.js';
14
14
  import 'date-fns/endOfMonth';
15
15
  import '@alfalab/core-components-calendar/modern';
@@ -0,0 +1,4 @@
1
+ var styles = {"component":"calendar-range__component_1a9ih","divider":"calendar-range__divider_1a9ih","static":"calendar-range__static_1a9ih","calendar":"calendar-range__calendar_1a9ih"};
2
+ require('./views/index.css')
3
+
4
+ export { styles as s };
@@ -1,4 +1,4 @@
1
- /* hash: 803om */
1
+ /* hash: hbbfm */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -36,19 +36,19 @@
36
36
 
37
37
  /* marker */
38
38
  }
39
- .calendar-range__component_1o680 {
39
+ .calendar-range__component_1a9ih {
40
40
  display: flex
41
41
  }
42
- .calendar-range__component_1o680 button[aria-selected='true'] {
42
+ .calendar-range__component_1a9ih button[aria-selected='true'] {
43
43
  cursor: pointer;
44
44
  }
45
- .calendar-range__component_1o680 *[class*='errorIcon_'] {
45
+ .calendar-range__component_1a9ih *[class*='errorIcon_'] {
46
46
  display: none;
47
47
  }
48
- .calendar-range__component_1o680 *[class*='calendarIcon_'] {
48
+ .calendar-range__component_1a9ih *[class*='calendarIcon_'] {
49
49
  margin-right: 0;
50
50
  }
51
- .calendar-range__divider_1o680 {
51
+ .calendar-range__divider_1a9ih {
52
52
  height: 48px;
53
53
  display: flex;
54
54
  align-items: center;
@@ -56,13 +56,13 @@
56
56
  width: 16px;
57
57
  margin: 0 var(--gap-xs)
58
58
  }
59
- .calendar-range__divider_1o680:after {
59
+ .calendar-range__divider_1a9ih:after {
60
60
  content: '';
61
61
  display: block;
62
62
  width: 100%;
63
63
  height: 1px;
64
64
  background-color: var(--color-light-graphic-primary);
65
65
  }
66
- .calendar-range__static_1o680 .calendar-range__calendar_1o680 {
66
+ .calendar-range__static_1a9ih .calendar-range__calendar_1a9ih {
67
67
  width: var(--calendar-inner-width);
68
68
  }
@@ -9,9 +9,9 @@ import 'date-fns/max';
9
9
  import 'date-fns/min';
10
10
  import 'date-fns/isEqual';
11
11
  import { usePopoverViewMonthes } from '../hooks.js';
12
- import { s as styles } from '../index.module-ff37a166.js';
12
+ import { s as styles } from '../index.module-407ef197.js';
13
13
 
14
- const CalendarRangePopover = ({ className, defaultMonth = startOfMonth(new Date()).getTime(), minDate, maxDate, valueFrom = '', valueTo = '', onDateFromChange = () => null, onDateToChange = () => null, onChange = () => null, inputFromProps = {}, inputToProps = {}, offDays, events, dataTestId, }) => {
14
+ const CalendarRangePopover = ({ className, defaultMonth = startOfMonth(new Date()).getTime(), minDate, maxDate, valueFrom = '', valueTo = '', onDateFromChange = () => null, onDateToChange = () => null, onChange = () => null, onError, inputFromProps = {}, inputToProps = {}, offDays, events, dataTestId, }) => {
15
15
  const [inputFromValue, setInputFromValue] = useState(valueFrom);
16
16
  const [inputToValue, setInputToValue] = useState(valueTo);
17
17
  /**
@@ -31,6 +31,7 @@ const CalendarRangePopover = ({ className, defaultMonth = startOfMonth(new Date(
31
31
  const bothInvalid = isCompleteDateInput(inputFromValue) &&
32
32
  isCompleteDateInput(inputToValue) &&
33
33
  parseDateString(inputFromValue).getTime() > parseDateString(inputToValue).getTime();
34
+ const hasValidateError = inputFromInvalid || inputToInvalid || bothInvalid;
34
35
  const { monthFrom, monthTo, handleMonthFromChange, handleMonthToChange, } = usePopoverViewMonthes({
35
36
  dateFrom,
36
37
  dateTo,
@@ -96,6 +97,12 @@ const CalendarRangePopover = ({ className, defaultMonth = startOfMonth(new Date(
96
97
  }
97
98
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
99
  }, [inputToValue]);
100
+ useEffect(() => {
101
+ if (onError) {
102
+ onError(hasValidateError);
103
+ }
104
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
+ }, [hasValidateError]);
99
106
  return (React.createElement("div", { className: cn(styles.component, className), "data-test-id": dataTestId },
100
107
  React.createElement(CalendarInput, Object.assign({}, inputFromProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-start', error: inputFromInvalid || bothInvalid || inputFromProps.error, onChange: handleFromChange, onInputChange: handleInputFromChange, onBlur: handleInputFromBlur, value: inputFromValue, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: {
101
108
  ...inputFromProps.calendarProps,
@@ -9,13 +9,13 @@ import max from 'date-fns/max';
9
9
  import 'date-fns/min';
10
10
  import 'date-fns/isEqual';
11
11
  import { useStaticViewMonthes, useSelectionProps } from '../hooks.js';
12
- import { s as styles } from '../index.module-ff37a166.js';
12
+ import { s as styles } from '../index.module-407ef197.js';
13
13
  import endOfMonth from 'date-fns/endOfMonth';
14
14
  import { usePeriodWithReset, Calendar } from '@alfalab/core-components-calendar/modern';
15
15
  import { isDayButton } from '../utils.js';
16
16
 
17
17
  /* eslint-disable complexity */
18
- const CalendarRangeStatic = ({ className, defaultMonth = startOfMonth(new Date()).getTime(), defaultMonthPosition = 'left', minDate, maxDate, valueFrom = '', valueTo = '', onDateFromChange = () => null, onDateToChange = () => null, onChange = () => null, inputFromProps = {}, inputToProps = {}, offDays, events, dataTestId, }) => {
18
+ const CalendarRangeStatic = ({ className, defaultMonth = startOfMonth(new Date()).getTime(), defaultMonthPosition = 'left', minDate, maxDate, valueFrom = '', valueTo = '', onDateFromChange = () => null, onDateToChange = () => null, onChange = () => null, onError, inputFromProps = {}, inputToProps = {}, offDays, events, dataTestId, }) => {
19
19
  const [inputFromValue, setInputFromValue] = useState(valueFrom);
20
20
  const [inputToValue, setInputToValue] = useState(valueTo);
21
21
  let dateFrom = isValidInputValue(inputFromValue, minDate, maxDate, offDays)
@@ -37,8 +37,9 @@ const CalendarRangeStatic = ({ className, defaultMonth = startOfMonth(new Date()
37
37
  });
38
38
  const validateInputFromValue = useCallback((value) => isValidInputValue(value, minDate, dateFrom || maxDate, offDays), [dateFrom, maxDate, minDate, offDays]);
39
39
  const validateInputToValue = useCallback((value) => isValidInputValue(value, dateFrom || minDate, maxDate, offDays), [dateFrom, minDate, maxDate, offDays]);
40
- const [inputFromInvalid, setInputFromInvalid] = useState(validateInputFromValue(inputFromValue) === false);
41
- const [inputToInvalid, setInputToInvalid] = useState(validateInputToValue(inputToValue) === false);
40
+ const [inputFromInvalid, setInputFromInvalid] = useState(isCompleteDateInput(inputFromValue) && dateFrom === null);
41
+ const [inputToInvalid, setInputToInvalid] = useState(isCompleteDateInput(inputToValue) && dateTo === null);
42
+ const hasValidateError = bothInvalid || inputFromInvalid || inputToInvalid;
42
43
  const { monthFrom, monthTo, handleMonthFromChange, handleMonthToChange } = useStaticViewMonthes({
43
44
  selectedFrom: period.selectedFrom,
44
45
  selectedTo: period.selectedTo,
@@ -131,6 +132,12 @@ const CalendarRangeStatic = ({ className, defaultMonth = startOfMonth(new Date()
131
132
  }
132
133
  // eslint-disable-next-line react-hooks/exhaustive-deps
133
134
  }, [inputToValue]);
135
+ useEffect(() => {
136
+ if (onError) {
137
+ onError(hasValidateError);
138
+ }
139
+ // eslint-disable-next-line react-hooks/exhaustive-deps
140
+ }, [hasValidateError]);
134
141
  const rangeProps = useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
135
142
  const { calendarProps: calendarFromProps, ...dateInputFromProps } = inputFromProps;
136
143
  const { calendarProps: calendarToProps, ...dateInputToProps } = inputToProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-calendar-range",
3
- "version": "6.1.0",
3
+ "version": "6.2.1",
4
4
  "description": "Calendar range component",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -18,9 +18,9 @@
18
18
  "react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
19
19
  },
20
20
  "dependencies": {
21
- "@alfalab/core-components-calendar": "^6.1.0",
22
- "@alfalab/core-components-calendar-input": "^7.1.0",
23
- "@alfalab/core-components-date-input": "^3.1.0",
21
+ "@alfalab/core-components-calendar": "^6.1.2",
22
+ "@alfalab/core-components-calendar-input": "^7.1.2",
23
+ "@alfalab/core-components-date-input": "^3.1.2",
24
24
  "classnames": "^2.3.1",
25
25
  "date-fns": "^2.16.1"
26
26
  }
package/views/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /* hash: 803om */
1
+ /* hash: hbbfm */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -36,19 +36,19 @@
36
36
 
37
37
  /* marker */
38
38
  }
39
- .calendar-range__component_1o680 {
39
+ .calendar-range__component_1a9ih {
40
40
  display: flex
41
41
  }
42
- .calendar-range__component_1o680 button[aria-selected='true'] {
42
+ .calendar-range__component_1a9ih button[aria-selected='true'] {
43
43
  cursor: pointer;
44
44
  }
45
- .calendar-range__component_1o680 *[class*='errorIcon_'] {
45
+ .calendar-range__component_1a9ih *[class*='errorIcon_'] {
46
46
  display: none;
47
47
  }
48
- .calendar-range__component_1o680 *[class*='calendarIcon_'] {
48
+ .calendar-range__component_1a9ih *[class*='calendarIcon_'] {
49
49
  margin-right: 0;
50
50
  }
51
- .calendar-range__divider_1o680 {
51
+ .calendar-range__divider_1a9ih {
52
52
  height: 48px;
53
53
  display: flex;
54
54
  align-items: center;
@@ -56,13 +56,13 @@
56
56
  width: 16px;
57
57
  margin: 0 var(--gap-xs)
58
58
  }
59
- .calendar-range__divider_1o680:after {
59
+ .calendar-range__divider_1a9ih:after {
60
60
  content: '';
61
61
  display: block;
62
62
  width: 100%;
63
63
  height: 1px;
64
64
  background-color: var(--color-light-graphic-primary);
65
65
  }
66
- .calendar-range__static_1o680 .calendar-range__calendar_1o680 {
66
+ .calendar-range__static_1a9ih .calendar-range__calendar_1a9ih {
67
67
  width: var(--calendar-inner-width);
68
68
  }
package/views/popover.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index_module = require('../index.module-bcd9b9e1.js');
5
+ var index_module = require('../index.module-21c6d28e.js');
6
6
  var React = require('react');
7
7
  var cn = require('classnames');
8
8
  var startOfMonth = require('date-fns/startOfMonth');
@@ -22,7 +22,7 @@ var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
22
22
  var startOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(startOfMonth);
23
23
 
24
24
  var CalendarRangePopover = function (_a) {
25
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
25
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, onError = _a.onError, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
26
26
  var _k = React.useState(valueFrom), inputFromValue = _k[0], setInputFromValue = _k[1];
27
27
  var _l = React.useState(valueTo), inputToValue = _l[0], setInputToValue = _l[1];
28
28
  /**
@@ -42,6 +42,7 @@ var CalendarRangePopover = function (_a) {
42
42
  var bothInvalid = coreComponentsDateInput.isCompleteDateInput(inputFromValue) &&
43
43
  coreComponentsDateInput.isCompleteDateInput(inputToValue) &&
44
44
  coreComponentsCalendarInput.parseDateString(inputFromValue).getTime() > coreComponentsCalendarInput.parseDateString(inputToValue).getTime();
45
+ var hasValidateError = inputFromInvalid || inputToInvalid || bothInvalid;
45
46
  var _q = hooks.usePopoverViewMonthes({
46
47
  dateFrom: dateFrom,
47
48
  dateTo: dateTo,
@@ -107,6 +108,12 @@ var CalendarRangePopover = function (_a) {
107
108
  }
108
109
  // eslint-disable-next-line react-hooks/exhaustive-deps
109
110
  }, [inputToValue]);
111
+ React.useEffect(function () {
112
+ if (onError) {
113
+ onError(hasValidateError);
114
+ }
115
+ // eslint-disable-next-line react-hooks/exhaustive-deps
116
+ }, [hasValidateError]);
110
117
  return (React__default['default'].createElement("div", { className: cn__default['default'](index_module.styles.component, className), "data-test-id": dataTestId },
111
118
  React__default['default'].createElement(coreComponentsCalendarInput.CalendarInput, index_module.__assign({}, inputFromProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-start', error: inputFromInvalid || bothInvalid || inputFromProps.error, onChange: handleFromChange, onInputChange: handleInputFromChange, onBlur: handleInputFromBlur, value: inputFromValue, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: index_module.__assign(index_module.__assign({}, inputFromProps.calendarProps), { month: monthFrom, onMonthChange: handleMonthFromChange, selectorView: 'full' }) })),
112
119
  React__default['default'].createElement("span", { className: index_module.styles.divider }),
package/views/static.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index_module = require('../index.module-bcd9b9e1.js');
5
+ var index_module = require('../index.module-21c6d28e.js');
6
6
  var React = require('react');
7
7
  var cn = require('classnames');
8
8
  var startOfMonth = require('date-fns/startOfMonth');
@@ -29,7 +29,7 @@ var max__default = /*#__PURE__*/_interopDefaultLegacy(max);
29
29
  var endOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(endOfMonth);
30
30
 
31
31
  var CalendarRangeStatic = function (_a) {
32
- var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
32
+ var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, _c = _a.defaultMonthPosition, defaultMonthPosition = _c === void 0 ? 'left' : _c, minDate = _a.minDate, maxDate = _a.maxDate, _d = _a.valueFrom, valueFrom = _d === void 0 ? '' : _d, _e = _a.valueTo, valueTo = _e === void 0 ? '' : _e, _f = _a.onDateFromChange, onDateFromChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onDateToChange, onDateToChange = _g === void 0 ? function () { return null; } : _g, _h = _a.onChange, onChange = _h === void 0 ? function () { return null; } : _h, onError = _a.onError, _j = _a.inputFromProps, inputFromProps = _j === void 0 ? {} : _j, _k = _a.inputToProps, inputToProps = _k === void 0 ? {} : _k, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
33
33
  var _l = React.useState(valueFrom), inputFromValue = _l[0], setInputFromValue = _l[1];
34
34
  var _m = React.useState(valueTo), inputToValue = _m[0], setInputToValue = _m[1];
35
35
  var dateFrom = coreComponentsCalendarInput.isValidInputValue(inputFromValue, minDate, maxDate, offDays)
@@ -51,8 +51,9 @@ var CalendarRangeStatic = function (_a) {
51
51
  });
52
52
  var validateInputFromValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, minDate, dateFrom || maxDate, offDays); }, [dateFrom, maxDate, minDate, offDays]);
53
53
  var validateInputToValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, dateFrom || minDate, maxDate, offDays); }, [dateFrom, minDate, maxDate, offDays]);
54
- var _p = React.useState(validateInputFromValue(inputFromValue) === false), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
55
- var _q = React.useState(validateInputToValue(inputToValue) === false), inputToInvalid = _q[0], setInputToInvalid = _q[1];
54
+ var _p = React.useState(coreComponentsDateInput.isCompleteDateInput(inputFromValue) && dateFrom === null), inputFromInvalid = _p[0], setInputFromInvalid = _p[1];
55
+ var _q = React.useState(coreComponentsDateInput.isCompleteDateInput(inputToValue) && dateTo === null), inputToInvalid = _q[0], setInputToInvalid = _q[1];
56
+ var hasValidateError = bothInvalid || inputFromInvalid || inputToInvalid;
56
57
  var _r = hooks.useStaticViewMonthes({
57
58
  selectedFrom: period.selectedFrom,
58
59
  selectedTo: period.selectedTo,
@@ -145,6 +146,12 @@ var CalendarRangeStatic = function (_a) {
145
146
  }
146
147
  // eslint-disable-next-line react-hooks/exhaustive-deps
147
148
  }, [inputToValue]);
149
+ React.useEffect(function () {
150
+ if (onError) {
151
+ onError(hasValidateError);
152
+ }
153
+ // eslint-disable-next-line react-hooks/exhaustive-deps
154
+ }, [hasValidateError]);
148
155
  var rangeProps = hooks.useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
149
156
  var calendarFromProps = inputFromProps.calendarProps, dateInputFromProps = index_module.__rest(inputFromProps, ["calendarProps"]);
150
157
  var calendarToProps = inputToProps.calendarProps, dateInputToProps = index_module.__rest(inputToProps, ["calendarProps"]);
@@ -1,4 +0,0 @@
1
- var styles = {"component":"calendar-range__component_1o680","divider":"calendar-range__divider_1o680","static":"calendar-range__static_1o680","calendar":"calendar-range__calendar_1o680"};
2
- require('./views/index.css')
3
-
4
- export { styles as s };