@alfalab/core-components-date-range-input 2.2.8 → 2.2.9
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.desktop.d.ts +5 -4
- package/Component.desktop.js +4 -2
- package/Component.mobile.d.ts +5 -4
- package/Component.mobile.js +4 -2
- package/Component.responsive.d.ts +5 -4
- package/Component.responsive.js +7 -5
- package/components/date-range-input/Component.d.ts +108 -0
- package/components/date-range-input/Component.js +220 -13
- package/components/date-range-input/index.css +6 -6
- package/components/date-range-input/index.d.ts +1 -1
- package/components/date-range-input/index.js +3 -1
- package/cssm/Component.desktop.d.ts +5 -4
- package/cssm/Component.desktop.js +4 -2
- package/cssm/Component.mobile.d.ts +5 -4
- package/cssm/Component.mobile.js +4 -2
- package/cssm/Component.responsive.d.ts +5 -4
- package/cssm/Component.responsive.js +7 -5
- package/cssm/components/date-range-input/Component.d.ts +108 -0
- package/cssm/components/date-range-input/Component.js +219 -14
- package/cssm/components/date-range-input/index.d.ts +1 -1
- package/cssm/components/date-range-input/index.js +3 -1
- package/cssm/desktop.js +3 -1
- package/cssm/index.js +5 -3
- package/cssm/mobile.js +4 -2
- package/cssm/responsive.js +5 -3
- package/desktop.js +3 -1
- package/esm/Component.desktop.d.ts +5 -4
- package/esm/Component.desktop.js +5 -3
- package/esm/Component.mobile.d.ts +5 -4
- package/esm/Component.mobile.js +5 -3
- package/esm/Component.responsive.d.ts +5 -4
- package/esm/Component.responsive.js +7 -5
- package/esm/components/date-range-input/Component.d.ts +108 -0
- package/esm/components/date-range-input/Component.js +216 -12
- package/esm/components/date-range-input/index.css +6 -6
- package/esm/components/date-range-input/index.d.ts +1 -1
- package/esm/components/date-range-input/index.js +3 -1
- package/esm/desktop.js +3 -1
- package/esm/index.js +5 -3
- package/esm/mobile.js +4 -2
- package/esm/responsive.js +5 -3
- package/index.js +5 -3
- package/mobile.js +4 -2
- package/modern/Component.desktop.d.ts +5 -4
- package/modern/Component.desktop.js +3 -2
- package/modern/Component.mobile.d.ts +5 -4
- package/modern/Component.mobile.js +3 -2
- package/modern/Component.responsive.d.ts +5 -4
- package/modern/Component.responsive.js +5 -4
- package/modern/components/date-range-input/Component.d.ts +16 -104
- package/modern/components/date-range-input/Component.js +65 -28
- package/modern/components/date-range-input/index.css +6 -6
- package/modern/components/date-range-input/index.js +1 -0
- package/modern/desktop.js +1 -0
- package/modern/index.js +1 -0
- package/modern/mobile.js +1 -0
- package/modern/responsive.js +1 -0
- package/package.json +7 -6
- package/responsive.js +5 -3
- package/Component-3b1e7e1b.d.ts +0 -229
- package/Component-3b1e7e1b.js +0 -225
- package/cssm/Component-540e1474.d.ts +0 -229
- package/cssm/Component-540e1474.js +0 -224
- package/esm/Component-bc49bcb7.d.ts +0 -229
- package/esm/Component-bc49bcb7.js +0 -215
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var tslib = require('tslib');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var hooks = require('@alfalab/hooks');
|
|
6
6
|
var Component_desktop = require('./Component.desktop.js');
|
|
7
7
|
var Component_mobile = require('./Component.mobile.js');
|
|
8
|
+
require('./components/date-range-input/Component.js');
|
|
8
9
|
require('react-merge-refs');
|
|
9
10
|
require('classnames');
|
|
11
|
+
require('date-fns');
|
|
10
12
|
require('date-fns/isValid');
|
|
11
13
|
require('@alfalab/core-components-calendar/cssm');
|
|
12
14
|
require('@alfalab/core-components-icon-button/cssm');
|
|
@@ -21,13 +23,13 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
21
23
|
|
|
22
24
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
23
25
|
|
|
24
|
-
var DateRangeInputResponsive = function (_a) {
|
|
25
|
-
var _b = _a.breakpoint, breakpoint = _b === void 0 ? 1024 : _b, restProps =
|
|
26
|
+
var DateRangeInputResponsive = React.forwardRef(function (_a, ref) {
|
|
27
|
+
var _b = _a.breakpoint, breakpoint = _b === void 0 ? 1024 : _b, restProps = tslib.__rest(_a, ["breakpoint"]);
|
|
26
28
|
var view = hooks.useMedia([
|
|
27
29
|
['mobile', "(max-width: ".concat(breakpoint - 1, "px)")],
|
|
28
30
|
['desktop', "(min-width: ".concat(breakpoint, "px)")],
|
|
29
31
|
], 'desktop')[0];
|
|
30
|
-
return view === 'desktop' ? (React__default.default.createElement(Component_desktop.DateRangeInputDesktop,
|
|
31
|
-
};
|
|
32
|
+
return view === 'desktop' ? (React__default.default.createElement(Component_desktop.DateRangeInputDesktop, tslib.__assign({}, restProps, { ref: ref }))) : (React__default.default.createElement(Component_mobile.DateRangeInputMobile, tslib.__assign({}, restProps, { ref: ref })));
|
|
33
|
+
});
|
|
32
34
|
|
|
33
35
|
exports.DateRangeInputResponsive = DateRangeInputResponsive;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent, ElementType } from "react";
|
|
4
|
+
import { CalendarMobileProps, CalendarProps } from "@alfalab/core-components-calendar";
|
|
5
|
+
import { InputProps } from "@alfalab/core-components-input";
|
|
6
|
+
import { PopoverProps } from "@alfalab/core-components-popover";
|
|
7
|
+
type ConditionalProps = {
|
|
8
|
+
/**
|
|
9
|
+
* Обработчик изменения значения
|
|
10
|
+
*/
|
|
11
|
+
picker: true;
|
|
12
|
+
/**
|
|
13
|
+
* Обработчик закрытия календаря
|
|
14
|
+
*/
|
|
15
|
+
onClose?: () => void;
|
|
16
|
+
} | {
|
|
17
|
+
picker?: false;
|
|
18
|
+
onClose?: never;
|
|
19
|
+
};
|
|
20
|
+
type DateRangeInputProps = Omit<InputProps, 'onChange'> & ConditionalProps & {
|
|
21
|
+
/**
|
|
22
|
+
* Дополнительный класс
|
|
23
|
+
*/
|
|
24
|
+
className?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Дополнительный класс для инпута
|
|
27
|
+
*/
|
|
28
|
+
inputClassName?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Дополнительный класс для поповера
|
|
31
|
+
*/
|
|
32
|
+
popoverClassName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Обработчик изменения значения
|
|
35
|
+
*/
|
|
36
|
+
onChange?: (payload: {
|
|
37
|
+
dateFrom?: Date;
|
|
38
|
+
dateTo?: Date;
|
|
39
|
+
value: string;
|
|
40
|
+
}, event?: ChangeEvent<HTMLInputElement>) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Обработчик окончания ввода
|
|
43
|
+
*/
|
|
44
|
+
onComplete?: (payload: {
|
|
45
|
+
dateFrom: Date;
|
|
46
|
+
dateTo: Date;
|
|
47
|
+
value: string;
|
|
48
|
+
}, event?: ChangeEvent<HTMLInputElement>) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Компонент календаря
|
|
51
|
+
*/
|
|
52
|
+
Calendar?: ElementType;
|
|
53
|
+
/**
|
|
54
|
+
* Доп. пропсы для календаря
|
|
55
|
+
*/
|
|
56
|
+
calendarProps?: (CalendarProps & Record<string, unknown>) | (CalendarMobileProps & Record<string, unknown>);
|
|
57
|
+
/**
|
|
58
|
+
* Месяц в календаре по умолчанию (timestamp)
|
|
59
|
+
*/
|
|
60
|
+
defaultMonth?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Минимальная дата, доступная для выбора (timestamp)
|
|
63
|
+
*/
|
|
64
|
+
minDate?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Максимальная дата, доступная для выбора (timestamp)
|
|
67
|
+
*/
|
|
68
|
+
maxDate?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Список событий
|
|
71
|
+
*/
|
|
72
|
+
events?: Array<Date | number>;
|
|
73
|
+
/**
|
|
74
|
+
* Список выходных
|
|
75
|
+
*/
|
|
76
|
+
offDays?: Array<Date | number>;
|
|
77
|
+
/**
|
|
78
|
+
* Состояние открытия по умолчанию
|
|
79
|
+
*/
|
|
80
|
+
defaultOpen?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Позиционирование поповера с календарем
|
|
83
|
+
*/
|
|
84
|
+
popoverPosition?: PopoverProps['position'];
|
|
85
|
+
/**
|
|
86
|
+
* z-index Popover
|
|
87
|
+
*/
|
|
88
|
+
zIndexPopover?: PopoverProps['zIndex'];
|
|
89
|
+
/**
|
|
90
|
+
* Запрещает поповеру менять свою позицию.
|
|
91
|
+
* Например, если места снизу недостаточно,то он все равно будет показан снизу
|
|
92
|
+
*/
|
|
93
|
+
preventFlip?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Календарь будет принимать ширину инпута
|
|
96
|
+
*/
|
|
97
|
+
useAnchorWidth?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Растягивает компонент на ширину контейнера
|
|
100
|
+
*/
|
|
101
|
+
block?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Отображение компонента в мобильном или десктопном виде
|
|
104
|
+
*/
|
|
105
|
+
view?: 'desktop' | 'mobile';
|
|
106
|
+
};
|
|
107
|
+
declare const DateRangeInput: React.ForwardRefExoticComponent<DateRangeInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
108
|
+
export { ConditionalProps, DateRangeInputProps, DateRangeInput };
|
|
@@ -1,20 +1,225 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('react');
|
|
5
|
-
require('react-merge-refs');
|
|
6
|
-
require('classnames');
|
|
7
|
-
require('date-fns
|
|
8
|
-
require('
|
|
9
|
-
require('@alfalab/core-components-
|
|
10
|
-
require('@alfalab/core-components-
|
|
11
|
-
require('@alfalab/core-components-
|
|
12
|
-
require('@alfalab/
|
|
13
|
-
require('@alfalab/
|
|
14
|
-
require('
|
|
15
|
-
require('
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var mergeRefs = require('react-merge-refs');
|
|
6
|
+
var cn = require('classnames');
|
|
7
|
+
var dateFns = require('date-fns');
|
|
8
|
+
var dateFnsIsValid = require('date-fns/isValid');
|
|
9
|
+
var coreComponentsCalendar = require('@alfalab/core-components-calendar/cssm');
|
|
10
|
+
var coreComponentsIconButton = require('@alfalab/core-components-icon-button/cssm');
|
|
11
|
+
var coreComponentsInput = require('@alfalab/core-components-input/cssm');
|
|
12
|
+
var coreComponentsPopover = require('@alfalab/core-components-popover/cssm');
|
|
13
|
+
var hooks = require('@alfalab/hooks');
|
|
14
|
+
var CalendarMIcon = require('@alfalab/icons-glyph/CalendarMIcon');
|
|
15
|
+
var utils_format = require('../../utils/format.js');
|
|
16
|
+
var styles = require('./index.module.css');
|
|
16
17
|
require('date-fns/parse');
|
|
17
18
|
|
|
19
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
18
20
|
|
|
21
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
22
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefaultCompat(mergeRefs);
|
|
23
|
+
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
24
|
+
var dateFnsIsValid__default = /*#__PURE__*/_interopDefaultCompat(dateFnsIsValid);
|
|
25
|
+
var styles__default = /*#__PURE__*/_interopDefaultCompat(styles);
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
/* eslint-disable no-useless-escape, jsx-a11y/click-events-have-key-events */
|
|
28
|
+
var DateRangeInput = React__default.default.forwardRef(function (_a, ref) {
|
|
29
|
+
var _b, _c;
|
|
30
|
+
var _d;
|
|
31
|
+
var className = _a.className, inputClassName = _a.inputClassName, popoverClassName = _a.popoverClassName, disabled = _a.disabled, readOnly = _a.readOnly, picker = _a.picker, _e = _a.defaultValue, defaultValue = _e === void 0 ? '' : _e, propValue = _a.value, onChange = _a.onChange, onComplete = _a.onComplete, onClose = _a.onClose, rightAddons = _a.rightAddons, useAnchorWidth = _a.useAnchorWidth, block = _a.block, _f = _a.popoverPosition, popoverPosition = _f === void 0 ? 'bottom-start' : _f, zIndexPopover = _a.zIndexPopover, preventFlip = _a.preventFlip, _g = _a.Calendar, Calendar = _g === void 0 ? coreComponentsCalendar.Calendar : _g, _h = _a.calendarProps, calendarProps = _h === void 0 ? {} : _h, defaultMonth = _a.defaultMonth, _j = _a.minDate, minDate = _j === void 0 ? calendarProps.minDate : _j, _k = _a.maxDate, maxDate = _k === void 0 ? calendarProps.maxDate : _k, _l = _a.offDays, offDays = _l === void 0 ? calendarProps.offDays || [] : _l, _m = _a.events, events = _m === void 0 ? calendarProps.events || [] : _m, _o = _a.defaultOpen, defaultOpen = _o === void 0 ? false : _o, _p = _a.view, view = _p === void 0 ? 'desktop' : _p, restProps = tslib.__rest(_a, ["className", "inputClassName", "popoverClassName", "disabled", "readOnly", "picker", "defaultValue", "value", "onChange", "onComplete", "onClose", "rightAddons", "useAnchorWidth", "block", "popoverPosition", "zIndexPopover", "preventFlip", "Calendar", "calendarProps", "defaultMonth", "minDate", "maxDate", "offDays", "events", "defaultOpen", "view"]);
|
|
32
|
+
var inputRef = React.useRef(null);
|
|
33
|
+
var iconRef = React.useRef(null);
|
|
34
|
+
var calendarRef = React.useRef(null);
|
|
35
|
+
var _q = React.useState(propValue || defaultValue), value = _q[0], setValue = _q[1];
|
|
36
|
+
var _r = React.useState(defaultOpen), open = _r[0], setOpen = _r[1];
|
|
37
|
+
var inputDisabled = disabled || readOnly;
|
|
38
|
+
var calendarResponsive = (_d = calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.responsive) !== null && _d !== void 0 ? _d : true;
|
|
39
|
+
var _s = coreComponentsCalendar.usePeriod({ onPeriodChange: handlePeriodChange }), selectedFrom = _s.selectedFrom, selectedTo = _s.selectedTo, updatePeriod = _s.updatePeriod, resetPeriod = _s.resetPeriod, setStart = _s.setStart, setEnd = _s.setEnd;
|
|
40
|
+
React.useEffect(function () {
|
|
41
|
+
if (value) {
|
|
42
|
+
setCalendarPeriod(getDates(value));
|
|
43
|
+
}
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
}, []);
|
|
46
|
+
React.useEffect(function () {
|
|
47
|
+
setValue(function (prevValue) {
|
|
48
|
+
if (selectedFrom && selectedTo) {
|
|
49
|
+
var from = utils_format.parseTimestampToDate(selectedFrom);
|
|
50
|
+
var to = utils_format.parseTimestampToDate(selectedTo);
|
|
51
|
+
return "".concat(from, " - ").concat(to);
|
|
52
|
+
}
|
|
53
|
+
if (selectedFrom && prevValue.length < utils_format.DATE_FORMAT.length) {
|
|
54
|
+
return utils_format.parseTimestampToDate(selectedFrom);
|
|
55
|
+
}
|
|
56
|
+
return prevValue;
|
|
57
|
+
});
|
|
58
|
+
}, [selectedFrom, selectedTo]);
|
|
59
|
+
hooks.useDidUpdateEffect(function () {
|
|
60
|
+
var newPropValue = propValue || '';
|
|
61
|
+
setValue(function (prevValue) {
|
|
62
|
+
if (prevValue === newPropValue) {
|
|
63
|
+
return prevValue;
|
|
64
|
+
}
|
|
65
|
+
var dates = getDates(newPropValue);
|
|
66
|
+
setCalendarPeriod(dates);
|
|
67
|
+
return dates.formattedValue;
|
|
68
|
+
});
|
|
69
|
+
}, [propValue]);
|
|
70
|
+
function getDates(val) {
|
|
71
|
+
var formattedValue = utils_format.format(val);
|
|
72
|
+
var dateArr = formattedValue.split('-').map(function (v) { return v.trim(); });
|
|
73
|
+
var dateFrom = dateArr[0] ? utils_format.parseDateString(dateArr[0]) : undefined;
|
|
74
|
+
var dateTo = dateArr[1] ? utils_format.parseDateString(dateArr[1]) : undefined;
|
|
75
|
+
return { formattedValue: formattedValue, dateFrom: dateFrom, dateTo: dateTo, dateArr: dateArr };
|
|
76
|
+
}
|
|
77
|
+
function setCalendarPeriod(_a) {
|
|
78
|
+
var dateFrom = _a.dateFrom, dateTo = _a.dateTo;
|
|
79
|
+
setStart(dateFrom === null || dateFrom === void 0 ? void 0 : dateFrom.getTime());
|
|
80
|
+
setEnd(dateTo === null || dateTo === void 0 ? void 0 : dateTo.getTime());
|
|
81
|
+
}
|
|
82
|
+
function handlePeriodChange(selectedFrom, selectedTo) {
|
|
83
|
+
if (selectedFrom && !selectedTo && value.length === utils_format.DATE_MASK.length) {
|
|
84
|
+
setValue(utils_format.parseTimestampToDate(selectedFrom));
|
|
85
|
+
}
|
|
86
|
+
else if ((!selectedFrom && !selectedTo && value.length === utils_format.DATE_FORMAT.length) ||
|
|
87
|
+
(selectedFrom === selectedTo && value.length === utils_format.DATE_MASK.length)) {
|
|
88
|
+
setValue('');
|
|
89
|
+
}
|
|
90
|
+
var dateFrom = selectedFrom ? new Date(selectedFrom) : undefined;
|
|
91
|
+
var dateTo = selectedTo ? new Date(selectedTo) : undefined;
|
|
92
|
+
var newValue = [selectedFrom, selectedTo].filter(Boolean)
|
|
93
|
+
.map(function (timestamp) { return utils_format.parseTimestampToDate(timestamp); })
|
|
94
|
+
.join(' - ');
|
|
95
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
96
|
+
dateFrom: dateFrom,
|
|
97
|
+
dateTo: dateTo,
|
|
98
|
+
value: newValue,
|
|
99
|
+
});
|
|
100
|
+
if (dateFrom && dateTo) {
|
|
101
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete({
|
|
102
|
+
dateFrom: dateFrom,
|
|
103
|
+
dateTo: dateTo,
|
|
104
|
+
value: newValue,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var handleInputWrapperFocus = function (event) {
|
|
109
|
+
if (view === 'desktop') {
|
|
110
|
+
if (picker) {
|
|
111
|
+
setOpen(true);
|
|
112
|
+
}
|
|
113
|
+
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
114
|
+
calendarRef.current.focus();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var handleBlur = function (event) {
|
|
119
|
+
var _a, _b, _c;
|
|
120
|
+
if (view === 'desktop') {
|
|
121
|
+
var target = (event.relatedTarget || document.activeElement);
|
|
122
|
+
if (((_a = calendarRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) === false &&
|
|
123
|
+
((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.contains(target)) === false &&
|
|
124
|
+
((_c = iconRef.current) === null || _c === void 0 ? void 0 : _c.contains(target)) === false) {
|
|
125
|
+
setOpen(false);
|
|
126
|
+
if (onClose) {
|
|
127
|
+
onClose();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var handleChange = function (event) {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
var newValue = event.target.value;
|
|
135
|
+
if (newValue.length > utils_format.DATE_MASK.length)
|
|
136
|
+
return;
|
|
137
|
+
// Позволяем вводить только цифры, точки, дефис и пробелы
|
|
138
|
+
if (/[^\d. -]/.test(newValue)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
var dots = newValue.match(/\./g);
|
|
142
|
+
var hyphen = newValue.match(/\-/g);
|
|
143
|
+
// Не даем вводить больше, чем 4 точки и 1 дефис
|
|
144
|
+
if ((dots && dots.length > 4) || (hyphen && hyphen.length > 1)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var _c = getDates(newValue), formattedValue = _c.formattedValue, dateFrom = _c.dateFrom, dateTo = _c.dateTo, dateArr = _c.dateArr;
|
|
148
|
+
if (!dateFrom && !dateTo) {
|
|
149
|
+
resetPeriod();
|
|
150
|
+
}
|
|
151
|
+
else if (selectedFrom && formattedValue.length < utils_format.DATE_FORMAT.length) {
|
|
152
|
+
setStart();
|
|
153
|
+
}
|
|
154
|
+
else if (selectedFrom && selectedTo) {
|
|
155
|
+
setEnd();
|
|
156
|
+
}
|
|
157
|
+
else if (dateFrom &&
|
|
158
|
+
dateFnsIsValid__default.default(dateFrom) &&
|
|
159
|
+
((_a = dateArr[0]) === null || _a === void 0 ? void 0 : _a.length) === utils_format.DATE_FORMAT.length &&
|
|
160
|
+
dateFrom.getTime() !== selectedFrom) {
|
|
161
|
+
setStart(dateFrom.getTime());
|
|
162
|
+
}
|
|
163
|
+
else if (dateTo &&
|
|
164
|
+
dateFnsIsValid__default.default(dateTo) &&
|
|
165
|
+
((_b = dateArr[1]) === null || _b === void 0 ? void 0 : _b.length) === utils_format.DATE_FORMAT.length &&
|
|
166
|
+
dateTo.getTime() !== selectedTo) {
|
|
167
|
+
setEnd(dateTo.getTime());
|
|
168
|
+
}
|
|
169
|
+
setValue(formattedValue);
|
|
170
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
171
|
+
if (utils_format.isCompleteDateInput(formattedValue)) {
|
|
172
|
+
var valid = utils_format.isValid(formattedValue, dateArr[0], dateArr[1]);
|
|
173
|
+
if (!valid)
|
|
174
|
+
return;
|
|
175
|
+
if (dateFrom && dateTo) {
|
|
176
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var handleCalendarClose = function () {
|
|
181
|
+
if (view === 'mobile' && onClose) {
|
|
182
|
+
onClose();
|
|
183
|
+
}
|
|
184
|
+
setOpen(false);
|
|
185
|
+
};
|
|
186
|
+
var handleClear = function () {
|
|
187
|
+
setValue('');
|
|
188
|
+
resetPeriod();
|
|
189
|
+
};
|
|
190
|
+
var handleCalendarChange = function (date) {
|
|
191
|
+
if (date) {
|
|
192
|
+
updatePeriod(date);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var handleCalendarWrapperMouseDown = function (event) {
|
|
196
|
+
// Не дает инпуту терять фокус при выборе даты
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
};
|
|
199
|
+
var handleIconButtonClick = function () {
|
|
200
|
+
if (!open)
|
|
201
|
+
setOpen(true);
|
|
202
|
+
if (view === 'desktop' && inputRef.current) {
|
|
203
|
+
inputRef.current.focus();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var renderCalendar = function () {
|
|
207
|
+
var activeMonth = (selectedTo && dateFns.startOfMonth(selectedTo)) ||
|
|
208
|
+
(selectedFrom && dateFns.startOfMonth(selectedFrom));
|
|
209
|
+
return (
|
|
210
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
211
|
+
React__default.default.createElement("div", { onMouseDown: handleCalendarWrapperMouseDown },
|
|
212
|
+
React__default.default.createElement(Calendar, tslib.__assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: activeMonth || defaultMonth, selectedFrom: selectedFrom, selectedTo: selectedTo, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events }))));
|
|
213
|
+
};
|
|
214
|
+
return (React__default.default.createElement("div", { className: cn__default.default(styles__default.default.component, className, (_b = {},
|
|
215
|
+
_b[styles__default.default.block] = block,
|
|
216
|
+
_b)), onFocus: inputDisabled ? undefined : handleInputWrapperFocus, onBlur: handleBlur },
|
|
217
|
+
React__default.default.createElement(coreComponentsInput.Input, tslib.__assign({}, restProps, { block: block, ref: mergeRefs__default.default([ref, inputRef]), value: value, onChange: handleChange, disabled: disabled, readOnly: readOnly, className: inputClassName, onClear: handleClear, rightAddons: React__default.default.createElement(React__default.default.Fragment, null,
|
|
218
|
+
rightAddons,
|
|
219
|
+
picker && (React__default.default.createElement(coreComponentsIconButton.IconButton, { ref: iconRef, onClick: inputDisabled ? undefined : handleIconButtonClick, icon: CalendarMIcon.CalendarMIcon, size: 'xxs' }))) })),
|
|
220
|
+
picker && (React__default.default.createElement(coreComponentsPopover.Popover, { open: open, useAnchorWidth: useAnchorWidth, anchorElement: inputRef.current, popperClassName: cn__default.default(styles__default.default.calendarContainer, (_c = {},
|
|
221
|
+
_c[styles__default.default.calendarResponsive] = calendarResponsive,
|
|
222
|
+
_c)), className: popoverClassName, position: popoverPosition, offset: [0, 8], withTransition: false, preventFlip: preventFlip, zIndex: zIndexPopover }, renderCalendar()))));
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
exports.DateRangeInput = DateRangeInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "./Component";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var components_dateRangeInput_Component = require('
|
|
3
|
+
var components_dateRangeInput_Component = require('./Component.js');
|
|
4
|
+
require('tslib');
|
|
4
5
|
require('react');
|
|
5
6
|
require('react-merge-refs');
|
|
6
7
|
require('classnames');
|
|
8
|
+
require('date-fns');
|
|
7
9
|
require('date-fns/isValid');
|
|
8
10
|
require('@alfalab/core-components-calendar/cssm');
|
|
9
11
|
require('@alfalab/core-components-icon-button/cssm');
|
package/cssm/desktop.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_desktop = require('./Component.desktop.js');
|
|
4
|
-
require('
|
|
4
|
+
require('tslib');
|
|
5
5
|
require('react');
|
|
6
|
+
require('./components/date-range-input/Component.js');
|
|
6
7
|
require('react-merge-refs');
|
|
7
8
|
require('classnames');
|
|
9
|
+
require('date-fns');
|
|
8
10
|
require('date-fns/isValid');
|
|
9
11
|
require('@alfalab/core-components-calendar/cssm');
|
|
10
12
|
require('@alfalab/core-components-icon-button/cssm');
|
package/cssm/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_responsive = require('./Component.responsive.js');
|
|
4
|
-
require('
|
|
4
|
+
require('tslib');
|
|
5
5
|
require('react');
|
|
6
|
+
require('@alfalab/hooks');
|
|
7
|
+
require('./Component.desktop.js');
|
|
8
|
+
require('./components/date-range-input/Component.js');
|
|
6
9
|
require('react-merge-refs');
|
|
7
10
|
require('classnames');
|
|
11
|
+
require('date-fns');
|
|
8
12
|
require('date-fns/isValid');
|
|
9
13
|
require('@alfalab/core-components-calendar/cssm');
|
|
10
14
|
require('@alfalab/core-components-icon-button/cssm');
|
|
11
15
|
require('@alfalab/core-components-input/cssm');
|
|
12
16
|
require('@alfalab/core-components-popover/cssm');
|
|
13
|
-
require('@alfalab/hooks');
|
|
14
17
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
15
18
|
require('./utils/format.js');
|
|
16
19
|
require('date-fns/parse');
|
|
17
20
|
require('./components/date-range-input/index.module.css');
|
|
18
|
-
require('./Component.desktop.js');
|
|
19
21
|
require('./Component.mobile.js');
|
|
20
22
|
|
|
21
23
|
|
package/cssm/mobile.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_mobile = require('./Component.mobile.js');
|
|
4
|
-
require('
|
|
4
|
+
require('tslib');
|
|
5
5
|
require('react');
|
|
6
|
+
require('@alfalab/core-components-calendar/cssm');
|
|
7
|
+
require('./components/date-range-input/Component.js');
|
|
6
8
|
require('react-merge-refs');
|
|
7
9
|
require('classnames');
|
|
10
|
+
require('date-fns');
|
|
8
11
|
require('date-fns/isValid');
|
|
9
|
-
require('@alfalab/core-components-calendar/cssm');
|
|
10
12
|
require('@alfalab/core-components-icon-button/cssm');
|
|
11
13
|
require('@alfalab/core-components-input/cssm');
|
|
12
14
|
require('@alfalab/core-components-popover/cssm');
|
package/cssm/responsive.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_responsive = require('./Component.responsive.js');
|
|
4
|
-
require('
|
|
4
|
+
require('tslib');
|
|
5
5
|
require('react');
|
|
6
|
+
require('@alfalab/hooks');
|
|
7
|
+
require('./Component.desktop.js');
|
|
8
|
+
require('./components/date-range-input/Component.js');
|
|
6
9
|
require('react-merge-refs');
|
|
7
10
|
require('classnames');
|
|
11
|
+
require('date-fns');
|
|
8
12
|
require('date-fns/isValid');
|
|
9
13
|
require('@alfalab/core-components-calendar/cssm');
|
|
10
14
|
require('@alfalab/core-components-icon-button/cssm');
|
|
11
15
|
require('@alfalab/core-components-input/cssm');
|
|
12
16
|
require('@alfalab/core-components-popover/cssm');
|
|
13
|
-
require('@alfalab/hooks');
|
|
14
17
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
15
18
|
require('./utils/format.js');
|
|
16
19
|
require('date-fns/parse');
|
|
17
20
|
require('./components/date-range-input/index.module.css');
|
|
18
|
-
require('./Component.desktop.js');
|
|
19
21
|
require('./Component.mobile.js');
|
|
20
22
|
|
|
21
23
|
|
package/desktop.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_desktop = require('./Component.desktop.js');
|
|
4
|
-
require('
|
|
4
|
+
require('tslib');
|
|
5
5
|
require('react');
|
|
6
|
+
require('./components/date-range-input/Component.js');
|
|
6
7
|
require('react-merge-refs');
|
|
7
8
|
require('classnames');
|
|
9
|
+
require('date-fns');
|
|
8
10
|
require('date-fns/isValid');
|
|
9
11
|
require('@alfalab/core-components-calendar');
|
|
10
12
|
require('@alfalab/core-components-icon-button');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { DateRangeInputProps, ConditionalProps } from "./components/date-range-input/Component";
|
|
4
|
+
type DateRangeInputDesktopProps = Omit<DateRangeInputProps, 'view' | 'picker' | 'onClose'> & ConditionalProps;
|
|
5
|
+
declare const DateRangeInputDesktop: React.ForwardRefExoticComponent<DateRangeInputDesktopProps & React.RefAttributes<HTMLInputElement>>;
|
|
5
6
|
export { DateRangeInputDesktopProps, DateRangeInputDesktop };
|
package/esm/Component.desktop.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import { DateRangeInput } from './components/date-range-input/Component.js';
|
|
3
4
|
import 'react-merge-refs';
|
|
4
5
|
import 'classnames';
|
|
6
|
+
import 'date-fns';
|
|
5
7
|
import 'date-fns/isValid';
|
|
6
8
|
import '@alfalab/core-components-calendar/esm';
|
|
7
9
|
import '@alfalab/core-components-icon-button/esm';
|
|
@@ -12,6 +14,6 @@ import '@alfalab/icons-glyph/CalendarMIcon';
|
|
|
12
14
|
import './utils/format.js';
|
|
13
15
|
import 'date-fns/parse';
|
|
14
16
|
|
|
15
|
-
var DateRangeInputDesktop = function (props) { return
|
|
17
|
+
var DateRangeInputDesktop = forwardRef(function (props, ref) { return React.createElement(DateRangeInput, __assign({}, props, { ref: ref })); });
|
|
16
18
|
|
|
17
19
|
export { DateRangeInputDesktop };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { DateRangeInputProps, ConditionalProps } from "./components/date-range-input/Component";
|
|
4
|
+
type DateRangeInputMobileProps = Omit<DateRangeInputProps, 'view' | 'picker' | 'onClose'> & ConditionalProps;
|
|
5
|
+
declare const DateRangeInputMobile: React.ForwardRefExoticComponent<DateRangeInputMobileProps & React.RefAttributes<HTMLInputElement>>;
|
|
5
6
|
export { DateRangeInputMobileProps, DateRangeInputMobile };
|
package/esm/Component.mobile.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
3
|
import { CalendarMobile } from '@alfalab/core-components-calendar/esm';
|
|
4
|
+
import { DateRangeInput } from './components/date-range-input/Component.js';
|
|
4
5
|
import 'react-merge-refs';
|
|
5
6
|
import 'classnames';
|
|
7
|
+
import 'date-fns';
|
|
6
8
|
import 'date-fns/isValid';
|
|
7
9
|
import '@alfalab/core-components-icon-button/esm';
|
|
8
10
|
import '@alfalab/core-components-input/esm';
|
|
@@ -12,6 +14,6 @@ import '@alfalab/icons-glyph/CalendarMIcon';
|
|
|
12
14
|
import './utils/format.js';
|
|
13
15
|
import 'date-fns/parse';
|
|
14
16
|
|
|
15
|
-
var DateRangeInputMobile = function (props) { return
|
|
17
|
+
var DateRangeInputMobile = forwardRef(function (props, ref) { return React.createElement(DateRangeInput, __assign({ Calendar: CalendarMobile, view: 'mobile' }, props, { ref: ref })); });
|
|
16
18
|
|
|
17
19
|
export { DateRangeInputMobile };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { DateRangeInputProps, ConditionalProps } from "./components/date-range-input/Component";
|
|
4
|
+
type DateRangeInputResponsiveProps = Omit<DateRangeInputProps, 'view' | 'picker' | 'onClose'> & ConditionalProps & {
|
|
4
5
|
/**
|
|
5
6
|
* Контрольная точка, с нее начинается desktop версия
|
|
6
7
|
* @default 1024
|
|
@@ -8,5 +9,5 @@ type DateRangeInputResponsiveProps = Omit<DateRangeInputProps, 'view'> & {
|
|
|
8
9
|
breakpoint?: number;
|
|
9
10
|
};
|
|
10
11
|
type DateRangeInputMedia = 'desktop' | 'mobile';
|
|
11
|
-
declare const DateRangeInputResponsive:
|
|
12
|
+
declare const DateRangeInputResponsive: React.ForwardRefExoticComponent<DateRangeInputResponsiveProps & React.RefAttributes<HTMLInputElement>>;
|
|
12
13
|
export { DateRangeInputResponsiveProps, DateRangeInputMedia, DateRangeInputResponsive };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
3
|
import { useMedia } from '@alfalab/hooks';
|
|
4
4
|
import { DateRangeInputDesktop } from './Component.desktop.js';
|
|
5
5
|
import { DateRangeInputMobile } from './Component.mobile.js';
|
|
6
|
+
import './components/date-range-input/Component.js';
|
|
6
7
|
import 'react-merge-refs';
|
|
7
8
|
import 'classnames';
|
|
9
|
+
import 'date-fns';
|
|
8
10
|
import 'date-fns/isValid';
|
|
9
11
|
import '@alfalab/core-components-calendar/esm';
|
|
10
12
|
import '@alfalab/core-components-icon-button/esm';
|
|
@@ -14,13 +16,13 @@ import '@alfalab/icons-glyph/CalendarMIcon';
|
|
|
14
16
|
import './utils/format.js';
|
|
15
17
|
import 'date-fns/parse';
|
|
16
18
|
|
|
17
|
-
var DateRangeInputResponsive = function (_a) {
|
|
19
|
+
var DateRangeInputResponsive = forwardRef(function (_a, ref) {
|
|
18
20
|
var _b = _a.breakpoint, breakpoint = _b === void 0 ? 1024 : _b, restProps = __rest(_a, ["breakpoint"]);
|
|
19
21
|
var view = useMedia([
|
|
20
22
|
['mobile', "(max-width: ".concat(breakpoint - 1, "px)")],
|
|
21
23
|
['desktop', "(min-width: ".concat(breakpoint, "px)")],
|
|
22
24
|
], 'desktop')[0];
|
|
23
|
-
return view === 'desktop' ? (React.createElement(DateRangeInputDesktop, __assign({}, restProps))) : (React.createElement(DateRangeInputMobile, __assign({}, restProps)));
|
|
24
|
-
};
|
|
25
|
+
return view === 'desktop' ? (React.createElement(DateRangeInputDesktop, __assign({}, restProps, { ref: ref }))) : (React.createElement(DateRangeInputMobile, __assign({}, restProps, { ref: ref })));
|
|
26
|
+
});
|
|
25
27
|
|
|
26
28
|
export { DateRangeInputResponsive };
|