@alfalab/core-components-calendar-input 6.4.0 → 6.5.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.5.2](https://github.com/core-ds/core-components/compare/@alfalab/core-components-calendar-input@6.5.1...@alfalab/core-components-calendar-input@6.5.2) (2022-07-01)
7
+
8
+ **Note:** Version bump only for package @alfalab/core-components-calendar-input
9
+
10
+
11
+
12
+
13
+
14
+ ## [6.5.1](https://github.com/core-ds/core-components/compare/@alfalab/core-components-calendar-input@6.5.0...@alfalab/core-components-calendar-input@6.5.1) (2022-06-30)
15
+
16
+ **Note:** Version bump only for package @alfalab/core-components-calendar-input
17
+
18
+
19
+
20
+
21
+
22
+ # [6.5.0](https://github.com/core-ds/core-components/compare/@alfalab/core-components-calendar-input@6.4.0...@alfalab/core-components-calendar-input@6.5.0) (2022-06-29)
23
+
24
+
25
+ ### Features
26
+
27
+ * **calendar:** implement calendar mobile ([#54](https://github.com/core-ds/core-components/issues/54)) ([730f51d](https://github.com/core-ds/core-components/commit/730f51d35823273f122fe84a0369f95745fd2878))
28
+
29
+
30
+
31
+
32
+
6
33
  # [6.4.0](https://github.com/core-ds/core-components/compare/@alfalab/core-components-calendar-input@6.3.3...@alfalab/core-components-calendar-input@6.4.0) (2022-06-28)
7
34
 
8
35
 
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { ChangeEvent, MouseEvent, ElementType } from "react";
4
4
  import { PopoverProps } from "@alfalab/core-components-popover";
5
5
  import { DateInputProps } from "@alfalab/core-components-date-input";
6
- import { CalendarProps } from "@alfalab/core-components-calendar";
6
+ import { CalendarProps, CalendarMobileProps } from "@alfalab/core-components-calendar";
7
7
  type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
8
8
  /**
9
9
  * Дополнительный класс
@@ -20,7 +20,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
20
20
  /**
21
21
  * Доп. пропсы для календаря
22
22
  */
23
- calendarProps?: CalendarProps & Record<string, unknown>;
23
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarMobileProps & Record<string, unknown>);
24
24
  /**
25
25
  * Значение инпута (используется и для календаря)
26
26
  */
@@ -117,7 +117,17 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
117
117
  /**
118
118
  * Доп. пропсы для календаря
119
119
  */
120
- calendarProps?: (CalendarProps & Record<string, unknown>) | undefined;
120
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarProps & {
121
+ open: boolean;
122
+ title?: string | undefined;
123
+ onClose?: (() => void) | undefined;
124
+ yearsAmount?: number | undefined;
125
+ /**
126
+ * Дополнительный класс для инпута
127
+ */
128
+ hasHeader?: boolean | undefined;
129
+ allowSelectionFromEmptyRange?: boolean | undefined;
130
+ } & Record<string, unknown>) | undefined;
121
131
  /**
122
132
  * Значение инпута (используется и для календаря)
123
133
  */
@@ -184,7 +194,7 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
184
194
  /**
185
195
  * Обработчик изменения календаря
186
196
  */
187
- onCalendarChange?: ((date: number) => void) | undefined;
197
+ onCalendarChange?: ((date?: number | undefined) => void) | undefined;
188
198
  /**
189
199
  * Позиционирование поповера с календарем
190
200
  */
package/dist/Component.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var cn = require('classnames');
7
7
  var mergeRefs = require('react-merge-refs');
8
+ var hooks = require('@alfalab/hooks');
8
9
  var coreComponentsPopover = require('@alfalab/core-components-popover');
9
10
  var CalendarMIcon = require('@alfalab/icons-glyph/CalendarMIcon');
10
11
  var coreComponentsDateInput = require('@alfalab/core-components-date-input');
@@ -59,18 +60,25 @@ function __rest(s, e) {
59
60
  return t;
60
61
  }
61
62
 
62
- var styles = {"component":"calendar-input__component_15x5q","block":"calendar-input__block_15x5q","calendarContainer":"calendar-input__calendarContainer_15x5q","calendarIcon":"calendar-input__calendarIcon_15x5q","nativeInput":"calendar-input__nativeInput_15x5q"};
63
+ var styles = {"component":"calendar-input__component_1i7k6","block":"calendar-input__block_1i7k6","calendarContainer":"calendar-input__calendarContainer_1i7k6","calendarResponsive":"calendar-input__calendarResponsive_1i7k6","calendarIcon":"calendar-input__calendarIcon_1i7k6","nativeInput":"calendar-input__nativeInput_1i7k6"};
63
64
  require('./index.css')
64
65
 
65
66
  var CalendarInput = React.forwardRef(function (_a, ref) {
66
- var _b;
67
- var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, _l = _a.events, events = _l === void 0 ? calendarProps.events || [] : _l, preventFlip = _a.preventFlip, _m = _a.mobileMode, mobileMode = _m === void 0 ? 'popover' : _m, _o = _a.wrapperRef, wrapperRef = _o === void 0 ? null : _o, disabled = _a.disabled, _p = _a.onChange, onChange = _p === void 0 ? function () { return null; } : _p, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _q = _a.Calendar, Calendar = _q === void 0 ? coreComponentsCalendar.Calendar : _q, _r = _a.popoverPosition, popoverPosition = _r === void 0 ? 'bottom-start' : _r, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
67
+ var _b, _c;
68
+ var _d;
69
+ var _e = _a.block, block = _e === void 0 ? false : _e, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _f = _a.defaultOpen, defaultOpen = _f === void 0 ? false : _f, defaultMonth = _a.defaultMonth, _g = _a.defaultValue, defaultValue = _g === void 0 ? '' : _g, _h = _a.calendarPosition, calendarPosition = _h === void 0 ? 'popover' : _h, value = _a.value, dataTestId = _a.dataTestId, _j = _a.calendarProps, calendarProps = _j === void 0 ? {} : _j, _k = _a.minDate, minDate = _k === void 0 ? calendarProps.minDate : _k, _l = _a.maxDate, maxDate = _l === void 0 ? calendarProps.maxDate : _l, _m = _a.offDays, offDays = _m === void 0 ? calendarProps.offDays || [] : _m, _o = _a.events, events = _o === void 0 ? calendarProps.events || [] : _o, preventFlip = _a.preventFlip, _p = _a.mobileMode, mobileMode = _p === void 0 ? 'popover' : _p, _q = _a.wrapperRef, wrapperRef = _q === void 0 ? null : _q, disabled = _a.disabled, _r = _a.onChange, onChange = _r === void 0 ? function () { return null; } : _r, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _s = _a.Calendar, Calendar = _s === void 0 ? coreComponentsCalendar.Calendar : _s, _t = _a.popoverPosition, popoverPosition = _t === void 0 ? 'bottom-start' : _t, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
70
+ var view = hooks.useMedia([
71
+ ['mobile', '(max-width: 1023px)'],
72
+ ['desktop', '(min-width: 1024px)'],
73
+ ], 'desktop')[0];
74
+ var CalendarComponent = view === 'desktop' ? Calendar : coreComponentsCalendar.CalendarMobile;
75
+ var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
68
76
  var shouldRenderNative = utils.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
69
77
  var shouldRenderOnlyInput = mobileMode === 'input';
70
78
  var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
71
79
  var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
72
- var _s = React.useState(false), open = _s[0], setOpen = _s[1];
73
- var _t = React.useState(value || defaultValue), inputValue = _t[0], setInputValue = _t[1];
80
+ var _u = React.useState(false), open = _u[0], setOpen = _u[1];
81
+ var _v = React.useState(value || defaultValue), inputValue = _v[0], setInputValue = _v[1];
74
82
  var calendarValue = inputValue ? coreComponentsDateInput.parseDateString(inputValue).getTime() : undefined;
75
83
  var checkInputValueIsValid = React.useCallback(function (newInputValue) {
76
84
  if (!newInputValue || error)
@@ -97,17 +105,21 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
97
105
  setOpen(true);
98
106
  }, [open]);
99
107
  var handleFocus = React.useCallback(function (event) {
100
- setOpen(true);
101
- if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
102
- calendarRef.current.focus();
108
+ if (view === 'desktop') {
109
+ setOpen(true);
110
+ if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
111
+ calendarRef.current.focus();
112
+ }
103
113
  }
104
- }, [open]);
114
+ }, [open, view]);
105
115
  var handleBlur = React.useCallback(function (event) {
106
- var target = (event.relatedTarget || document.activeElement);
107
- if (calendarRef.current && calendarRef.current.contains(target) === false) {
108
- setOpen(false);
116
+ if (view === 'desktop') {
117
+ var target = (event.relatedTarget || document.activeElement);
118
+ if (calendarRef.current && calendarRef.current.contains(target) === false) {
119
+ setOpen(false);
120
+ }
109
121
  }
110
- }, []);
122
+ }, [view]);
111
123
  var handleInputKeyDown = React.useCallback(function (event) {
112
124
  if (['ArrowDown', 'ArrowUp'].includes(event.key) && calendarRef.current) {
113
125
  event.preventDefault();
@@ -134,13 +146,20 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
134
146
  changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
135
147
  }, [changeHandler, checkInputValueIsValid]);
136
148
  var handleCalendarChange = React.useCallback(function (date) {
137
- changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
138
- setOpen(false);
139
- }, [changeHandler]);
149
+ if (date) {
150
+ changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
151
+ }
152
+ if (view === 'desktop') {
153
+ setOpen(false);
154
+ }
155
+ }, [changeHandler, view]);
140
156
  var handleCalendarWrapperMouseDown = React.useCallback(function (event) {
141
157
  // Не дает инпуту терять фокус при выборе даты
142
158
  event.preventDefault();
143
159
  }, []);
160
+ var handleCalendarClose = React.useCallback(function () {
161
+ setOpen(false);
162
+ }, []);
144
163
  React.useEffect(function () {
145
164
  setOpen(defaultOpen);
146
165
  }, [defaultOpen]);
@@ -149,22 +168,10 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
149
168
  setInputValue(value);
150
169
  }
151
170
  }, [value]);
152
- var renderCalendar = React.useCallback(function () { return (
171
+ var renderCalendar = function () { return (
153
172
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
154
173
  React__default['default'].createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
155
- React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); }, [
156
- calendarProps,
157
- calendarValue,
158
- checkInputValueIsValid,
159
- defaultMonth,
160
- events,
161
- handleCalendarChange,
162
- handleCalendarWrapperMouseDown,
163
- inputValue,
164
- maxDate,
165
- minDate,
166
- offDays,
167
- ]);
174
+ React__default['default'].createElement(CalendarComponent, __assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); };
168
175
  return (
169
176
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
170
177
  React__default['default'].createElement("div", { className: cn__default['default'](styles.component, className, (_b = {},
@@ -174,7 +181,9 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
174
181
  rightAddons,
175
182
  shouldRenderPopover && (React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles.calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
176
183
  shouldRenderStatic && renderCalendar(),
177
- shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles.calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
184
+ shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: cn__default['default'](styles.calendarContainer, (_c = {},
185
+ _c[styles.calendarResponsive] = calendarResponsive,
186
+ _c)), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
178
187
  });
179
188
 
180
189
  exports.CalendarInput = CalendarInput;
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { ChangeEvent, MouseEvent, ElementType } from "react";
4
4
  import { PopoverProps } from "@alfalab/core-components-popover";
5
5
  import { DateInputProps } from "@alfalab/core-components-date-input";
6
- import { CalendarProps } from "@alfalab/core-components-calendar";
6
+ import { CalendarProps, CalendarMobileProps } from "@alfalab/core-components-calendar";
7
7
  type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
8
8
  /**
9
9
  * Дополнительный класс
@@ -20,7 +20,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
20
20
  /**
21
21
  * Доп. пропсы для календаря
22
22
  */
23
- calendarProps?: CalendarProps & Record<string, unknown>;
23
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarMobileProps & Record<string, unknown>);
24
24
  /**
25
25
  * Значение инпута (используется и для календаря)
26
26
  */
@@ -117,7 +117,17 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
117
117
  /**
118
118
  * Доп. пропсы для календаря
119
119
  */
120
- calendarProps?: (CalendarProps & Record<string, unknown>) | undefined;
120
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarProps & {
121
+ open: boolean;
122
+ title?: string | undefined;
123
+ onClose?: (() => void) | undefined;
124
+ yearsAmount?: number | undefined;
125
+ /**
126
+ * Дополнительный класс для инпута
127
+ */
128
+ hasHeader?: boolean | undefined;
129
+ allowSelectionFromEmptyRange?: boolean | undefined;
130
+ } & Record<string, unknown>) | undefined;
121
131
  /**
122
132
  * Значение инпута (используется и для календаря)
123
133
  */
@@ -184,7 +194,7 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
184
194
  /**
185
195
  * Обработчик изменения календаря
186
196
  */
187
- onCalendarChange?: ((date: number) => void) | undefined;
197
+ onCalendarChange?: ((date?: number | undefined) => void) | undefined;
188
198
  /**
189
199
  * Позиционирование поповера с календарем
190
200
  */
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var cn = require('classnames');
7
7
  var mergeRefs = require('react-merge-refs');
8
+ var hooks = require('@alfalab/hooks');
8
9
  var coreComponentsPopover = require('@alfalab/core-components-popover/dist/cssm');
9
10
  var CalendarMIcon = require('@alfalab/icons-glyph/CalendarMIcon');
10
11
  var coreComponentsDateInput = require('@alfalab/core-components-date-input/dist/cssm');
@@ -62,14 +63,21 @@ function __rest(s, e) {
62
63
  }
63
64
 
64
65
  var CalendarInput = React.forwardRef(function (_a, ref) {
65
- var _b;
66
- var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, _l = _a.events, events = _l === void 0 ? calendarProps.events || [] : _l, preventFlip = _a.preventFlip, _m = _a.mobileMode, mobileMode = _m === void 0 ? 'popover' : _m, _o = _a.wrapperRef, wrapperRef = _o === void 0 ? null : _o, disabled = _a.disabled, _p = _a.onChange, onChange = _p === void 0 ? function () { return null; } : _p, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _q = _a.Calendar, Calendar = _q === void 0 ? coreComponentsCalendar.Calendar : _q, _r = _a.popoverPosition, popoverPosition = _r === void 0 ? 'bottom-start' : _r, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
66
+ var _b, _c;
67
+ var _d;
68
+ var _e = _a.block, block = _e === void 0 ? false : _e, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _f = _a.defaultOpen, defaultOpen = _f === void 0 ? false : _f, defaultMonth = _a.defaultMonth, _g = _a.defaultValue, defaultValue = _g === void 0 ? '' : _g, _h = _a.calendarPosition, calendarPosition = _h === void 0 ? 'popover' : _h, value = _a.value, dataTestId = _a.dataTestId, _j = _a.calendarProps, calendarProps = _j === void 0 ? {} : _j, _k = _a.minDate, minDate = _k === void 0 ? calendarProps.minDate : _k, _l = _a.maxDate, maxDate = _l === void 0 ? calendarProps.maxDate : _l, _m = _a.offDays, offDays = _m === void 0 ? calendarProps.offDays || [] : _m, _o = _a.events, events = _o === void 0 ? calendarProps.events || [] : _o, preventFlip = _a.preventFlip, _p = _a.mobileMode, mobileMode = _p === void 0 ? 'popover' : _p, _q = _a.wrapperRef, wrapperRef = _q === void 0 ? null : _q, disabled = _a.disabled, _r = _a.onChange, onChange = _r === void 0 ? function () { return null; } : _r, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _s = _a.Calendar, Calendar = _s === void 0 ? coreComponentsCalendar.Calendar : _s, _t = _a.popoverPosition, popoverPosition = _t === void 0 ? 'bottom-start' : _t, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
69
+ var view = hooks.useMedia([
70
+ ['mobile', '(max-width: 1023px)'],
71
+ ['desktop', '(min-width: 1024px)'],
72
+ ], 'desktop')[0];
73
+ var CalendarComponent = view === 'desktop' ? Calendar : coreComponentsCalendar.CalendarMobile;
74
+ var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
67
75
  var shouldRenderNative = utils.SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
68
76
  var shouldRenderOnlyInput = mobileMode === 'input';
69
77
  var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
70
78
  var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
71
- var _s = React.useState(false), open = _s[0], setOpen = _s[1];
72
- var _t = React.useState(value || defaultValue), inputValue = _t[0], setInputValue = _t[1];
79
+ var _u = React.useState(false), open = _u[0], setOpen = _u[1];
80
+ var _v = React.useState(value || defaultValue), inputValue = _v[0], setInputValue = _v[1];
73
81
  var calendarValue = inputValue ? coreComponentsDateInput.parseDateString(inputValue).getTime() : undefined;
74
82
  var checkInputValueIsValid = React.useCallback(function (newInputValue) {
75
83
  if (!newInputValue || error)
@@ -96,17 +104,21 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
96
104
  setOpen(true);
97
105
  }, [open]);
98
106
  var handleFocus = React.useCallback(function (event) {
99
- setOpen(true);
100
- if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
101
- calendarRef.current.focus();
107
+ if (view === 'desktop') {
108
+ setOpen(true);
109
+ if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
110
+ calendarRef.current.focus();
111
+ }
102
112
  }
103
- }, [open]);
113
+ }, [open, view]);
104
114
  var handleBlur = React.useCallback(function (event) {
105
- var target = (event.relatedTarget || document.activeElement);
106
- if (calendarRef.current && calendarRef.current.contains(target) === false) {
107
- setOpen(false);
115
+ if (view === 'desktop') {
116
+ var target = (event.relatedTarget || document.activeElement);
117
+ if (calendarRef.current && calendarRef.current.contains(target) === false) {
118
+ setOpen(false);
119
+ }
108
120
  }
109
- }, []);
121
+ }, [view]);
110
122
  var handleInputKeyDown = React.useCallback(function (event) {
111
123
  if (['ArrowDown', 'ArrowUp'].includes(event.key) && calendarRef.current) {
112
124
  event.preventDefault();
@@ -133,13 +145,20 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
133
145
  changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
134
146
  }, [changeHandler, checkInputValueIsValid]);
135
147
  var handleCalendarChange = React.useCallback(function (date) {
136
- changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
137
- setOpen(false);
138
- }, [changeHandler]);
148
+ if (date) {
149
+ changeHandler(null, coreComponentsDateInput.formatDate(date), new Date(date), 'calendar');
150
+ }
151
+ if (view === 'desktop') {
152
+ setOpen(false);
153
+ }
154
+ }, [changeHandler, view]);
139
155
  var handleCalendarWrapperMouseDown = React.useCallback(function (event) {
140
156
  // Не дает инпуту терять фокус при выборе даты
141
157
  event.preventDefault();
142
158
  }, []);
159
+ var handleCalendarClose = React.useCallback(function () {
160
+ setOpen(false);
161
+ }, []);
143
162
  React.useEffect(function () {
144
163
  setOpen(defaultOpen);
145
164
  }, [defaultOpen]);
@@ -148,22 +167,10 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
148
167
  setInputValue(value);
149
168
  }
150
169
  }, [value]);
151
- var renderCalendar = React.useCallback(function () { return (
170
+ var renderCalendar = function () { return (
152
171
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
153
172
  React__default['default'].createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
154
- React__default['default'].createElement(Calendar, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); }, [
155
- calendarProps,
156
- calendarValue,
157
- checkInputValueIsValid,
158
- defaultMonth,
159
- events,
160
- handleCalendarChange,
161
- handleCalendarWrapperMouseDown,
162
- inputValue,
163
- maxDate,
164
- minDate,
165
- offDays,
166
- ]);
173
+ React__default['default'].createElement(CalendarComponent, __assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); };
167
174
  return (
168
175
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
169
176
  React__default['default'].createElement("div", { className: cn__default['default'](styles__default['default'].component, className, (_b = {},
@@ -173,7 +180,9 @@ var CalendarInput = React.forwardRef(function (_a, ref) {
173
180
  rightAddons,
174
181
  shouldRenderPopover && (React__default['default'].createElement(CalendarMIcon.CalendarMIcon, { className: styles__default['default'].calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
175
182
  shouldRenderStatic && renderCalendar(),
176
- shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles__default['default'].calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
183
+ shouldRenderPopover && (React__default['default'].createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: cn__default['default'](styles__default['default'].calendarContainer, (_c = {},
184
+ _c[styles__default['default'].calendarResponsive] = calendarResponsive,
185
+ _c)), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
177
186
  });
178
187
 
179
188
  exports.CalendarInput = CalendarInput;
@@ -6,6 +6,7 @@ var Component = require('./Component.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('react-merge-refs');
9
+ require('@alfalab/hooks');
9
10
  require('@alfalab/core-components-popover/dist/cssm');
10
11
  require('@alfalab/icons-glyph/CalendarMIcon');
11
12
  require('@alfalab/core-components-date-input/dist/cssm');
@@ -11,11 +11,13 @@
11
11
  }
12
12
  :root {
13
13
  --gap-2xs: 4px;
14
+ --gap-m: 16px;
14
15
  }
15
16
  :root {
16
17
  --border-radius-s: 4px;
17
18
  }
18
19
  :root {
20
+ --calendar-width: 344px;
19
21
 
20
22
  /* Кнопки выбора месяцев и годов */
21
23
 
@@ -27,6 +29,8 @@
27
29
 
28
30
  /* highlighted */
29
31
 
32
+ /* holidays */
33
+
30
34
  /* range */
31
35
 
32
36
  /* selected */
@@ -58,6 +62,10 @@
58
62
  min-width: 288px
59
63
  }
60
64
  }
65
+ .calendarResponsive {
66
+ width: var(--calendar-width);
67
+ padding: 0 var(--gap-m);
68
+ }
61
69
  .calendarIcon {
62
70
  width: 24px;
63
71
  height: 24px;
@@ -18,6 +18,8 @@
18
18
 
19
19
  /* highlighted */
20
20
 
21
+ /* holidays */
22
+
21
23
  /* range */
22
24
 
23
25
  /* selected */
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { ChangeEvent, MouseEvent, ElementType } from "react";
4
4
  import { PopoverProps } from "@alfalab/core-components-popover";
5
5
  import { DateInputProps } from "@alfalab/core-components-date-input";
6
- import { CalendarProps } from "@alfalab/core-components-calendar";
6
+ import { CalendarProps, CalendarMobileProps } from "@alfalab/core-components-calendar";
7
7
  type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
8
8
  /**
9
9
  * Дополнительный класс
@@ -20,7 +20,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
20
20
  /**
21
21
  * Доп. пропсы для календаря
22
22
  */
23
- calendarProps?: CalendarProps & Record<string, unknown>;
23
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarMobileProps & Record<string, unknown>);
24
24
  /**
25
25
  * Значение инпута (используется и для календаря)
26
26
  */
@@ -117,7 +117,17 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
117
117
  /**
118
118
  * Доп. пропсы для календаря
119
119
  */
120
- calendarProps?: (CalendarProps & Record<string, unknown>) | undefined;
120
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarProps & {
121
+ open: boolean;
122
+ title?: string | undefined;
123
+ onClose?: (() => void) | undefined;
124
+ yearsAmount?: number | undefined;
125
+ /**
126
+ * Дополнительный класс для инпута
127
+ */
128
+ hasHeader?: boolean | undefined;
129
+ allowSelectionFromEmptyRange?: boolean | undefined;
130
+ } & Record<string, unknown>) | undefined;
121
131
  /**
122
132
  * Значение инпута (используется и для календаря)
123
133
  */
@@ -184,7 +194,7 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
184
194
  /**
185
195
  * Обработчик изменения календаря
186
196
  */
187
- onCalendarChange?: ((date: number) => void) | undefined;
197
+ onCalendarChange?: ((date?: number | undefined) => void) | undefined;
188
198
  /**
189
199
  * Позиционирование поповера с календарем
190
200
  */
@@ -1,10 +1,11 @@
1
1
  import React, { forwardRef, useState, useCallback, useRef, useEffect } from 'react';
2
2
  import cn from 'classnames';
3
3
  import mergeRefs from 'react-merge-refs';
4
+ import { useMedia } from '@alfalab/hooks';
4
5
  import { Popover } from '@alfalab/core-components-popover/dist/esm';
5
6
  import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
6
7
  import { parseDateString, isCompleteDateInput, formatDate, DateInput } from '@alfalab/core-components-date-input/dist/esm';
7
- import { dateInLimits, Calendar } from '@alfalab/core-components-calendar/dist/esm';
8
+ import { dateInLimits, CalendarMobile, Calendar } from '@alfalab/core-components-calendar/dist/esm';
8
9
  import 'date-fns/parse';
9
10
  import 'date-fns/format';
10
11
  import 'date-fns/isSameDay';
@@ -49,18 +50,25 @@ function __rest(s, e) {
49
50
  return t;
50
51
  }
51
52
 
52
- var styles = {"component":"calendar-input__component_15x5q","block":"calendar-input__block_15x5q","calendarContainer":"calendar-input__calendarContainer_15x5q","calendarIcon":"calendar-input__calendarIcon_15x5q","nativeInput":"calendar-input__nativeInput_15x5q"};
53
+ var styles = {"component":"calendar-input__component_1i7k6","block":"calendar-input__block_1i7k6","calendarContainer":"calendar-input__calendarContainer_1i7k6","calendarResponsive":"calendar-input__calendarResponsive_1i7k6","calendarIcon":"calendar-input__calendarIcon_1i7k6","nativeInput":"calendar-input__nativeInput_1i7k6"};
53
54
  require('./index.css')
54
55
 
55
56
  var CalendarInput = forwardRef(function (_a, ref) {
56
- var _b;
57
- var _c = _a.block, block = _c === void 0 ? false : _c, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _d = _a.defaultOpen, defaultOpen = _d === void 0 ? false : _d, defaultMonth = _a.defaultMonth, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, _f = _a.calendarPosition, calendarPosition = _f === void 0 ? 'popover' : _f, value = _a.value, dataTestId = _a.dataTestId, _g = _a.calendarProps, calendarProps = _g === void 0 ? {} : _g, _h = _a.minDate, minDate = _h === void 0 ? calendarProps.minDate : _h, _j = _a.maxDate, maxDate = _j === void 0 ? calendarProps.maxDate : _j, _k = _a.offDays, offDays = _k === void 0 ? calendarProps.offDays || [] : _k, _l = _a.events, events = _l === void 0 ? calendarProps.events || [] : _l, preventFlip = _a.preventFlip, _m = _a.mobileMode, mobileMode = _m === void 0 ? 'popover' : _m, _o = _a.wrapperRef, wrapperRef = _o === void 0 ? null : _o, disabled = _a.disabled, _p = _a.onChange, onChange = _p === void 0 ? function () { return null; } : _p, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _q = _a.Calendar, Calendar$1 = _q === void 0 ? Calendar : _q, _r = _a.popoverPosition, popoverPosition = _r === void 0 ? 'bottom-start' : _r, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
57
+ var _b, _c;
58
+ var _d;
59
+ var _e = _a.block, block = _e === void 0 ? false : _e, className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, _f = _a.defaultOpen, defaultOpen = _f === void 0 ? false : _f, defaultMonth = _a.defaultMonth, _g = _a.defaultValue, defaultValue = _g === void 0 ? '' : _g, _h = _a.calendarPosition, calendarPosition = _h === void 0 ? 'popover' : _h, value = _a.value, dataTestId = _a.dataTestId, _j = _a.calendarProps, calendarProps = _j === void 0 ? {} : _j, _k = _a.minDate, minDate = _k === void 0 ? calendarProps.minDate : _k, _l = _a.maxDate, maxDate = _l === void 0 ? calendarProps.maxDate : _l, _m = _a.offDays, offDays = _m === void 0 ? calendarProps.offDays || [] : _m, _o = _a.events, events = _o === void 0 ? calendarProps.events || [] : _o, preventFlip = _a.preventFlip, _p = _a.mobileMode, mobileMode = _p === void 0 ? 'popover' : _p, _q = _a.wrapperRef, wrapperRef = _q === void 0 ? null : _q, disabled = _a.disabled, _r = _a.onChange, onChange = _r === void 0 ? function () { return null; } : _r, onInputChange = _a.onInputChange, onCalendarChange = _a.onCalendarChange, onKeyDown = _a.onKeyDown, readOnly = _a.readOnly, _s = _a.Calendar, Calendar$1 = _s === void 0 ? Calendar : _s, _t = _a.popoverPosition, popoverPosition = _t === void 0 ? 'bottom-start' : _t, zIndexPopover = _a.zIndexPopover, useAnchorWidth = _a.useAnchorWidth, rightAddons = _a.rightAddons, error = _a.error, restProps = __rest(_a, ["block", "className", "inputClassName", "popoverClassName", "defaultOpen", "defaultMonth", "defaultValue", "calendarPosition", "value", "dataTestId", "calendarProps", "minDate", "maxDate", "offDays", "events", "preventFlip", "mobileMode", "wrapperRef", "disabled", "onChange", "onInputChange", "onCalendarChange", "onKeyDown", "readOnly", "Calendar", "popoverPosition", "zIndexPopover", "useAnchorWidth", "rightAddons", "error"]);
60
+ var view = useMedia([
61
+ ['mobile', '(max-width: 1023px)'],
62
+ ['desktop', '(min-width: 1024px)'],
63
+ ], 'desktop')[0];
64
+ var CalendarComponent = view === 'desktop' ? Calendar$1 : CalendarMobile;
65
+ var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
58
66
  var shouldRenderNative = SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
59
67
  var shouldRenderOnlyInput = mobileMode === 'input';
60
68
  var shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
61
69
  var shouldRenderPopover = calendarPosition === 'popover' && !shouldRenderNative && !shouldRenderOnlyInput;
62
- var _s = useState(false), open = _s[0], setOpen = _s[1];
63
- var _t = useState(value || defaultValue), inputValue = _t[0], setInputValue = _t[1];
70
+ var _u = useState(false), open = _u[0], setOpen = _u[1];
71
+ var _v = useState(value || defaultValue), inputValue = _v[0], setInputValue = _v[1];
64
72
  var calendarValue = inputValue ? parseDateString(inputValue).getTime() : undefined;
65
73
  var checkInputValueIsValid = useCallback(function (newInputValue) {
66
74
  if (!newInputValue || error)
@@ -87,17 +95,21 @@ var CalendarInput = forwardRef(function (_a, ref) {
87
95
  setOpen(true);
88
96
  }, [open]);
89
97
  var handleFocus = useCallback(function (event) {
90
- setOpen(true);
91
- if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
92
- calendarRef.current.focus();
98
+ if (view === 'desktop') {
99
+ setOpen(true);
100
+ if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
101
+ calendarRef.current.focus();
102
+ }
93
103
  }
94
- }, [open]);
104
+ }, [open, view]);
95
105
  var handleBlur = useCallback(function (event) {
96
- var target = (event.relatedTarget || document.activeElement);
97
- if (calendarRef.current && calendarRef.current.contains(target) === false) {
98
- setOpen(false);
106
+ if (view === 'desktop') {
107
+ var target = (event.relatedTarget || document.activeElement);
108
+ if (calendarRef.current && calendarRef.current.contains(target) === false) {
109
+ setOpen(false);
110
+ }
99
111
  }
100
- }, []);
112
+ }, [view]);
101
113
  var handleInputKeyDown = useCallback(function (event) {
102
114
  if (['ArrowDown', 'ArrowUp'].includes(event.key) && calendarRef.current) {
103
115
  event.preventDefault();
@@ -124,13 +136,20 @@ var CalendarInput = forwardRef(function (_a, ref) {
124
136
  changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
125
137
  }, [changeHandler, checkInputValueIsValid]);
126
138
  var handleCalendarChange = useCallback(function (date) {
127
- changeHandler(null, formatDate(date), new Date(date), 'calendar');
128
- setOpen(false);
129
- }, [changeHandler]);
139
+ if (date) {
140
+ changeHandler(null, formatDate(date), new Date(date), 'calendar');
141
+ }
142
+ if (view === 'desktop') {
143
+ setOpen(false);
144
+ }
145
+ }, [changeHandler, view]);
130
146
  var handleCalendarWrapperMouseDown = useCallback(function (event) {
131
147
  // Не дает инпуту терять фокус при выборе даты
132
148
  event.preventDefault();
133
149
  }, []);
150
+ var handleCalendarClose = useCallback(function () {
151
+ setOpen(false);
152
+ }, []);
134
153
  useEffect(function () {
135
154
  setOpen(defaultOpen);
136
155
  }, [defaultOpen]);
@@ -139,22 +158,10 @@ var CalendarInput = forwardRef(function (_a, ref) {
139
158
  setInputValue(value);
140
159
  }
141
160
  }, [value]);
142
- var renderCalendar = useCallback(function () { return (
161
+ var renderCalendar = function () { return (
143
162
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
144
163
  React.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
145
- React.createElement(Calendar$1, __assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); }, [
146
- calendarProps,
147
- calendarValue,
148
- checkInputValueIsValid,
149
- defaultMonth,
150
- events,
151
- handleCalendarChange,
152
- handleCalendarWrapperMouseDown,
153
- inputValue,
154
- maxDate,
155
- minDate,
156
- offDays,
157
- ]);
164
+ React.createElement(CalendarComponent, __assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); };
158
165
  return (
159
166
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
160
167
  React.createElement("div", { className: cn(styles.component, className, (_b = {},
@@ -164,7 +171,9 @@ var CalendarInput = forwardRef(function (_a, ref) {
164
171
  rightAddons,
165
172
  shouldRenderPopover && (React.createElement(CalendarMIcon, { className: styles.calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
166
173
  shouldRenderStatic && renderCalendar(),
167
- shouldRenderPopover && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles.calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
174
+ shouldRenderPopover && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: cn(styles.calendarContainer, (_c = {},
175
+ _c[styles.calendarResponsive] = calendarResponsive,
176
+ _c)), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
168
177
  });
169
178
 
170
179
  export { CalendarInput };
@@ -1,4 +1,4 @@
1
- /* hash: acokf */
1
+ /* hash: 1s50e */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -12,11 +12,13 @@
12
12
  }
13
13
  :root {
14
14
  --gap-2xs: 4px;
15
+ --gap-m: 16px;
15
16
  }
16
17
  :root {
17
18
  --border-radius-s: 4px;
18
19
  }
19
20
  :root {
21
+ --calendar-width: 344px;
20
22
 
21
23
  /* Кнопки выбора месяцев и годов */
22
24
 
@@ -28,6 +30,8 @@
28
30
 
29
31
  /* highlighted */
30
32
 
33
+ /* holidays */
34
+
31
35
  /* range */
32
36
 
33
37
  /* selected */
@@ -40,35 +44,39 @@
40
44
  --calendar-input-icon-color: var(--color-light-graphic-primary);
41
45
  --calendar-input-popover-border-radius: 0 0 var(--border-radius-s) var(--border-radius-s);
42
46
  }
43
- .calendar-input__component_15x5q {
47
+ .calendar-input__component_1i7k6 {
44
48
  display: inline-block;
45
49
  outline: none;
46
50
  position: relative;
47
51
  }
48
- .calendar-input__block_15x5q {
52
+ .calendar-input__block_1i7k6 {
49
53
  width: 100%;
50
54
  }
51
- .calendar-input__calendarContainer_15x5q {
55
+ .calendar-input__calendarContainer_1i7k6 {
52
56
  display: inline-block;
53
57
  box-sizing: border-box;
54
58
  border-radius: var(--calendar-input-popover-border-radius)
55
59
  }
56
60
  @media (max-width: 374px) {
57
- .calendar-input__calendarContainer_15x5q {
61
+ .calendar-input__calendarContainer_1i7k6 {
58
62
  width: 100%;
59
63
  min-width: 288px
60
64
  }
61
65
  }
62
- .calendar-input__calendarIcon_15x5q {
66
+ .calendar-input__calendarResponsive_1i7k6 {
67
+ width: var(--calendar-width);
68
+ padding: 0 var(--gap-m);
69
+ }
70
+ .calendar-input__calendarIcon_1i7k6 {
63
71
  width: 24px;
64
72
  height: 24px;
65
73
  display: block;
66
74
  color: var(--calendar-input-icon-color)
67
75
  }
68
- .calendar-input__calendarIcon_15x5q:not(:only-child) {
76
+ .calendar-input__calendarIcon_1i7k6:not(:only-child) {
69
77
  margin-right: var(--gap-2xs);
70
78
  }
71
- .calendar-input__nativeInput_15x5q {
79
+ .calendar-input__nativeInput_1i7k6 {
72
80
  opacity: 0;
73
81
  position: absolute;
74
82
  top: 0;
@@ -79,9 +87,9 @@
79
87
  appearance: none;
80
88
  z-index: 1
81
89
  }
82
- .calendar-input__nativeInput_15x5q::-webkit-calendar-picker-indicator {
90
+ .calendar-input__nativeInput_1i7k6::-webkit-calendar-picker-indicator {
83
91
  display: none;
84
92
  }
85
- .calendar-input__nativeInput_15x5q::-webkit-inner-spin-button {
93
+ .calendar-input__nativeInput_1i7k6::-webkit-inner-spin-button {
86
94
  display: none;
87
95
  }
package/dist/esm/index.js CHANGED
@@ -2,6 +2,7 @@ export { CalendarInput } from './Component.js';
2
2
  import 'react';
3
3
  import 'classnames';
4
4
  import 'react-merge-refs';
5
+ import '@alfalab/hooks';
5
6
  import '@alfalab/core-components-popover/dist/esm';
6
7
  import '@alfalab/icons-glyph/CalendarMIcon';
7
8
  import '@alfalab/core-components-date-input/dist/esm';
package/dist/index.css CHANGED
@@ -1,4 +1,4 @@
1
- /* hash: acokf */
1
+ /* hash: 1s50e */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -12,11 +12,13 @@
12
12
  }
13
13
  :root {
14
14
  --gap-2xs: 4px;
15
+ --gap-m: 16px;
15
16
  }
16
17
  :root {
17
18
  --border-radius-s: 4px;
18
19
  }
19
20
  :root {
21
+ --calendar-width: 344px;
20
22
 
21
23
  /* Кнопки выбора месяцев и годов */
22
24
 
@@ -28,6 +30,8 @@
28
30
 
29
31
  /* highlighted */
30
32
 
33
+ /* holidays */
34
+
31
35
  /* range */
32
36
 
33
37
  /* selected */
@@ -40,35 +44,39 @@
40
44
  --calendar-input-icon-color: var(--color-light-graphic-primary);
41
45
  --calendar-input-popover-border-radius: 0 0 var(--border-radius-s) var(--border-radius-s);
42
46
  }
43
- .calendar-input__component_15x5q {
47
+ .calendar-input__component_1i7k6 {
44
48
  display: inline-block;
45
49
  outline: none;
46
50
  position: relative;
47
51
  }
48
- .calendar-input__block_15x5q {
52
+ .calendar-input__block_1i7k6 {
49
53
  width: 100%;
50
54
  }
51
- .calendar-input__calendarContainer_15x5q {
55
+ .calendar-input__calendarContainer_1i7k6 {
52
56
  display: inline-block;
53
57
  box-sizing: border-box;
54
58
  border-radius: var(--calendar-input-popover-border-radius)
55
59
  }
56
60
  @media (max-width: 374px) {
57
- .calendar-input__calendarContainer_15x5q {
61
+ .calendar-input__calendarContainer_1i7k6 {
58
62
  width: 100%;
59
63
  min-width: 288px
60
64
  }
61
65
  }
62
- .calendar-input__calendarIcon_15x5q {
66
+ .calendar-input__calendarResponsive_1i7k6 {
67
+ width: var(--calendar-width);
68
+ padding: 0 var(--gap-m);
69
+ }
70
+ .calendar-input__calendarIcon_1i7k6 {
63
71
  width: 24px;
64
72
  height: 24px;
65
73
  display: block;
66
74
  color: var(--calendar-input-icon-color)
67
75
  }
68
- .calendar-input__calendarIcon_15x5q:not(:only-child) {
76
+ .calendar-input__calendarIcon_1i7k6:not(:only-child) {
69
77
  margin-right: var(--gap-2xs);
70
78
  }
71
- .calendar-input__nativeInput_15x5q {
79
+ .calendar-input__nativeInput_1i7k6 {
72
80
  opacity: 0;
73
81
  position: absolute;
74
82
  top: 0;
@@ -79,9 +87,9 @@
79
87
  appearance: none;
80
88
  z-index: 1
81
89
  }
82
- .calendar-input__nativeInput_15x5q::-webkit-calendar-picker-indicator {
90
+ .calendar-input__nativeInput_1i7k6::-webkit-calendar-picker-indicator {
83
91
  display: none;
84
92
  }
85
- .calendar-input__nativeInput_15x5q::-webkit-inner-spin-button {
93
+ .calendar-input__nativeInput_1i7k6::-webkit-inner-spin-button {
86
94
  display: none;
87
95
  }
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var Component = require('./Component.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('react-merge-refs');
9
+ require('@alfalab/hooks');
9
10
  require('@alfalab/core-components-popover');
10
11
  require('@alfalab/icons-glyph/CalendarMIcon');
11
12
  require('@alfalab/core-components-date-input');
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { ChangeEvent, MouseEvent, ElementType } from "react";
4
4
  import { PopoverProps } from "@alfalab/core-components-popover";
5
5
  import { DateInputProps } from "@alfalab/core-components-date-input";
6
- import { CalendarProps } from "@alfalab/core-components-calendar";
6
+ import { CalendarProps, CalendarMobileProps } from "@alfalab/core-components-calendar";
7
7
  type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
8
8
  /**
9
9
  * Дополнительный класс
@@ -20,7 +20,7 @@ type CalendarInputProps = Omit<DateInputProps, 'onChange' | 'mobileMode'> & {
20
20
  /**
21
21
  * Доп. пропсы для календаря
22
22
  */
23
- calendarProps?: CalendarProps & Record<string, unknown>;
23
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarMobileProps & Record<string, unknown>);
24
24
  /**
25
25
  * Значение инпута (используется и для календаря)
26
26
  */
@@ -117,7 +117,17 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
117
117
  /**
118
118
  * Доп. пропсы для календаря
119
119
  */
120
- calendarProps?: (CalendarProps & Record<string, unknown>) | undefined;
120
+ calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarProps & {
121
+ open: boolean;
122
+ title?: string | undefined;
123
+ onClose?: (() => void) | undefined;
124
+ yearsAmount?: number | undefined;
125
+ /**
126
+ * Дополнительный класс для инпута
127
+ */
128
+ hasHeader?: boolean | undefined;
129
+ allowSelectionFromEmptyRange?: boolean | undefined;
130
+ } & Record<string, unknown>) | undefined;
121
131
  /**
122
132
  * Значение инпута (используется и для календаря)
123
133
  */
@@ -184,7 +194,7 @@ declare const CalendarInput: React.ForwardRefExoticComponent<Pick<DateInputProps
184
194
  /**
185
195
  * Обработчик изменения календаря
186
196
  */
187
- onCalendarChange?: ((date: number) => void) | undefined;
197
+ onCalendarChange?: ((date?: number | undefined) => void) | undefined;
188
198
  /**
189
199
  * Позиционирование поповера с календарем
190
200
  */
@@ -1,19 +1,26 @@
1
1
  import React, { forwardRef, useState, useCallback, useRef, useEffect } from 'react';
2
2
  import cn from 'classnames';
3
3
  import mergeRefs from 'react-merge-refs';
4
+ import { useMedia } from '@alfalab/hooks';
4
5
  import { Popover } from '@alfalab/core-components-popover/dist/modern';
5
6
  import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
6
7
  import { parseDateString, isCompleteDateInput, formatDate, DateInput } from '@alfalab/core-components-date-input/dist/modern';
7
- import { Calendar, dateInLimits } from '@alfalab/core-components-calendar/dist/modern';
8
+ import { Calendar, dateInLimits, CalendarMobile } from '@alfalab/core-components-calendar/dist/modern';
8
9
  import 'date-fns/parse';
9
10
  import 'date-fns/format';
10
11
  import 'date-fns/isSameDay';
11
12
  import { SUPPORTS_INPUT_TYPE_DATE } from './utils.js';
12
13
 
13
- var styles = {"component":"calendar-input__component_15x5q","block":"calendar-input__block_15x5q","calendarContainer":"calendar-input__calendarContainer_15x5q","calendarIcon":"calendar-input__calendarIcon_15x5q","nativeInput":"calendar-input__nativeInput_15x5q"};
14
+ var styles = {"component":"calendar-input__component_1i7k6","block":"calendar-input__block_1i7k6","calendarContainer":"calendar-input__calendarContainer_1i7k6","calendarResponsive":"calendar-input__calendarResponsive_1i7k6","calendarIcon":"calendar-input__calendarIcon_1i7k6","nativeInput":"calendar-input__nativeInput_1i7k6"};
14
15
  require('./index.css')
15
16
 
16
17
  const CalendarInput = forwardRef(({ block = false, className, inputClassName, popoverClassName, defaultOpen = false, defaultMonth, defaultValue = '', calendarPosition = 'popover', value, dataTestId, calendarProps = {}, minDate = calendarProps.minDate, maxDate = calendarProps.maxDate, offDays = calendarProps.offDays || [], events = calendarProps.events || [], preventFlip, mobileMode = 'popover', wrapperRef = null, disabled, onChange = () => null, onInputChange, onCalendarChange, onKeyDown, readOnly, Calendar: Calendar$1 = Calendar, popoverPosition = 'bottom-start', zIndexPopover, useAnchorWidth, rightAddons, error, ...restProps }, ref) => {
18
+ const [view] = useMedia([
19
+ ['mobile', '(max-width: 1023px)'],
20
+ ['desktop', '(min-width: 1024px)'],
21
+ ], 'desktop');
22
+ const CalendarComponent = view === 'desktop' ? Calendar$1 : CalendarMobile;
23
+ const calendarResponsive = calendarProps?.responsive ?? true;
17
24
  const shouldRenderNative = SUPPORTS_INPUT_TYPE_DATE && mobileMode === 'native';
18
25
  const shouldRenderOnlyInput = mobileMode === 'input';
19
26
  const shouldRenderStatic = calendarPosition === 'static' && !shouldRenderOnlyInput;
@@ -46,17 +53,21 @@ const CalendarInput = forwardRef(({ block = false, className, inputClassName, po
46
53
  setOpen(true);
47
54
  }, [open]);
48
55
  const handleFocus = useCallback((event) => {
49
- setOpen(true);
50
- if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
51
- calendarRef.current.focus();
56
+ if (view === 'desktop') {
57
+ setOpen(true);
58
+ if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
59
+ calendarRef.current.focus();
60
+ }
52
61
  }
53
- }, [open]);
62
+ }, [open, view]);
54
63
  const handleBlur = useCallback((event) => {
55
- const target = (event.relatedTarget || document.activeElement);
56
- if (calendarRef.current && calendarRef.current.contains(target) === false) {
57
- setOpen(false);
64
+ if (view === 'desktop') {
65
+ const target = (event.relatedTarget || document.activeElement);
66
+ if (calendarRef.current && calendarRef.current.contains(target) === false) {
67
+ setOpen(false);
68
+ }
58
69
  }
59
- }, []);
70
+ }, [view]);
60
71
  const handleInputKeyDown = useCallback((event) => {
61
72
  if (['ArrowDown', 'ArrowUp'].includes(event.key) && calendarRef.current) {
62
73
  event.preventDefault();
@@ -80,14 +91,21 @@ const CalendarInput = forwardRef(({ block = false, className, inputClassName, po
80
91
  const handleInputChange = useCallback((event, payload) => {
81
92
  changeHandler(event, payload.value, payload.date, 'input', !payload.value || checkInputValueIsValid(payload.value));
82
93
  }, [changeHandler, checkInputValueIsValid]);
83
- const handleCalendarChange = useCallback(date => {
84
- changeHandler(null, formatDate(date), new Date(date), 'calendar');
85
- setOpen(false);
86
- }, [changeHandler]);
94
+ const handleCalendarChange = useCallback((date) => {
95
+ if (date) {
96
+ changeHandler(null, formatDate(date), new Date(date), 'calendar');
97
+ }
98
+ if (view === 'desktop') {
99
+ setOpen(false);
100
+ }
101
+ }, [changeHandler, view]);
87
102
  const handleCalendarWrapperMouseDown = useCallback((event) => {
88
103
  // Не дает инпуту терять фокус при выборе даты
89
104
  event.preventDefault();
90
105
  }, []);
106
+ const handleCalendarClose = useCallback(() => {
107
+ setOpen(false);
108
+ }, []);
91
109
  useEffect(() => {
92
110
  setOpen(defaultOpen);
93
111
  }, [defaultOpen]);
@@ -96,22 +114,10 @@ const CalendarInput = forwardRef(({ block = false, className, inputClassName, po
96
114
  setInputValue(value);
97
115
  }
98
116
  }, [value]);
99
- const renderCalendar = useCallback(() => (
117
+ const renderCalendar = () => (
100
118
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
101
119
  React.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
102
- React.createElement(Calendar$1, Object.assign({}, calendarProps, { ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))), [
103
- calendarProps,
104
- calendarValue,
105
- checkInputValueIsValid,
106
- defaultMonth,
107
- events,
108
- handleCalendarChange,
109
- handleCalendarWrapperMouseDown,
110
- inputValue,
111
- maxDate,
112
- minDate,
113
- offDays,
114
- ]);
120
+ React.createElement(CalendarComponent, Object.assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, value: checkInputValueIsValid(inputValue) ? calendarValue : undefined, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events }))));
115
121
  return (
116
122
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
117
123
  React.createElement("div", { className: cn(styles.component, className, {
@@ -121,7 +127,9 @@ const CalendarInput = forwardRef(({ block = false, className, inputClassName, po
121
127
  rightAddons,
122
128
  shouldRenderPopover && (React.createElement(CalendarMIcon, { className: styles.calendarIcon }))), onKeyDown: handleInputKeyDown, onChange: handleInputChange, block: true })),
123
129
  shouldRenderStatic && renderCalendar(),
124
- shouldRenderPopover && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: styles.calendarContainer, className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
130
+ shouldRenderPopover && (React.createElement(Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputWrapperRef.current, popperClassName: cn(styles.calendarContainer, {
131
+ [styles.calendarResponsive]: calendarResponsive,
132
+ }), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
125
133
  });
126
134
 
127
135
  export { CalendarInput };
@@ -1,4 +1,4 @@
1
- /* hash: acokf */
1
+ /* hash: 1s50e */
2
2
  :root {
3
3
  --color-light-graphic-primary: #0b1f35;
4
4
  }
@@ -12,11 +12,13 @@
12
12
  }
13
13
  :root {
14
14
  --gap-2xs: 4px;
15
+ --gap-m: 16px;
15
16
  }
16
17
  :root {
17
18
  --border-radius-s: 4px;
18
19
  }
19
20
  :root {
21
+ --calendar-width: 344px;
20
22
 
21
23
  /* Кнопки выбора месяцев и годов */
22
24
 
@@ -28,6 +30,8 @@
28
30
 
29
31
  /* highlighted */
30
32
 
33
+ /* holidays */
34
+
31
35
  /* range */
32
36
 
33
37
  /* selected */
@@ -40,35 +44,39 @@
40
44
  --calendar-input-icon-color: var(--color-light-graphic-primary);
41
45
  --calendar-input-popover-border-radius: 0 0 var(--border-radius-s) var(--border-radius-s);
42
46
  }
43
- .calendar-input__component_15x5q {
47
+ .calendar-input__component_1i7k6 {
44
48
  display: inline-block;
45
49
  outline: none;
46
50
  position: relative;
47
51
  }
48
- .calendar-input__block_15x5q {
52
+ .calendar-input__block_1i7k6 {
49
53
  width: 100%;
50
54
  }
51
- .calendar-input__calendarContainer_15x5q {
55
+ .calendar-input__calendarContainer_1i7k6 {
52
56
  display: inline-block;
53
57
  box-sizing: border-box;
54
58
  border-radius: var(--calendar-input-popover-border-radius)
55
59
  }
56
60
  @media (max-width: 374px) {
57
- .calendar-input__calendarContainer_15x5q {
61
+ .calendar-input__calendarContainer_1i7k6 {
58
62
  width: 100%;
59
63
  min-width: 288px
60
64
  }
61
65
  }
62
- .calendar-input__calendarIcon_15x5q {
66
+ .calendar-input__calendarResponsive_1i7k6 {
67
+ width: var(--calendar-width);
68
+ padding: 0 var(--gap-m);
69
+ }
70
+ .calendar-input__calendarIcon_1i7k6 {
63
71
  width: 24px;
64
72
  height: 24px;
65
73
  display: block;
66
74
  color: var(--calendar-input-icon-color)
67
75
  }
68
- .calendar-input__calendarIcon_15x5q:not(:only-child) {
76
+ .calendar-input__calendarIcon_1i7k6:not(:only-child) {
69
77
  margin-right: var(--gap-2xs);
70
78
  }
71
- .calendar-input__nativeInput_15x5q {
79
+ .calendar-input__nativeInput_1i7k6 {
72
80
  opacity: 0;
73
81
  position: absolute;
74
82
  top: 0;
@@ -79,9 +87,9 @@
79
87
  appearance: none;
80
88
  z-index: 1
81
89
  }
82
- .calendar-input__nativeInput_15x5q::-webkit-calendar-picker-indicator {
90
+ .calendar-input__nativeInput_1i7k6::-webkit-calendar-picker-indicator {
83
91
  display: none;
84
92
  }
85
- .calendar-input__nativeInput_15x5q::-webkit-inner-spin-button {
93
+ .calendar-input__nativeInput_1i7k6::-webkit-inner-spin-button {
86
94
  display: none;
87
95
  }
@@ -1,6 +1,7 @@
1
1
  import 'react';
2
2
  import 'classnames';
3
3
  import 'react-merge-refs';
4
+ import '@alfalab/hooks';
4
5
  import '@alfalab/core-components-popover/dist/modern';
5
6
  import '@alfalab/icons-glyph/CalendarMIcon';
6
7
  import '@alfalab/core-components-date-input/dist/modern';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-calendar-input",
3
- "version": "6.4.0",
3
+ "version": "6.5.2",
4
4
  "description": "Calendar input component",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -19,12 +19,13 @@
19
19
  "react-dom": "^16.9.0 || ^17.0.1"
20
20
  },
21
21
  "dependencies": {
22
- "@alfalab/core-components-calendar": "^5.4.0",
22
+ "@alfalab/core-components-calendar": "^5.5.2",
23
23
  "@alfalab/core-components-date-input": "^2.3.0",
24
- "@alfalab/core-components-popover": "^5.7.0",
24
+ "@alfalab/core-components-popover": "^5.7.1",
25
+ "@alfalab/hooks": "^1.7.0",
25
26
  "classnames": "^2.2.6",
26
27
  "date-fns": "^2.16.1",
27
28
  "react-merge-refs": "^1.1.0"
28
29
  },
29
- "gitHead": "dcd5c0c8e25b7c374ff9311505ccf738a82e22c0"
30
+ "gitHead": "a1e54f5b2894447f4a6c80347706c27f855d5710"
30
31
  }