@alfalab/core-components-date-range-input 2.2.1 → 2.2.3
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-070df1af.d.ts → Component-9a6da64e.d.ts} +0 -0
- package/{Component-070df1af.js → Component-9a6da64e.js} +42 -29
- package/Component.desktop.d.ts +1 -1
- package/Component.desktop.js +2 -1
- package/Component.mobile.d.ts +1 -1
- package/Component.mobile.js +2 -1
- package/Component.responsive.d.ts +1 -1
- package/Component.responsive.js +1 -1
- package/components/date-range-input/Component.js +2 -1
- package/components/date-range-input/index.css +8 -8
- package/components/date-range-input/index.d.ts +1 -1
- package/components/date-range-input/index.js +2 -1
- package/cssm/{Component-a4cfbf46.d.ts → Component-540e1474.d.ts} +0 -0
- package/cssm/{Component-a4cfbf46.js → Component-540e1474.js} +41 -28
- package/cssm/Component.desktop.d.ts +1 -1
- package/cssm/Component.desktop.js +2 -1
- package/cssm/Component.mobile.d.ts +1 -1
- package/cssm/Component.mobile.js +2 -1
- package/cssm/Component.responsive.d.ts +1 -1
- package/cssm/Component.responsive.js +1 -1
- package/cssm/components/date-range-input/Component.js +2 -1
- package/cssm/components/date-range-input/index.d.ts +1 -1
- package/cssm/components/date-range-input/index.js +2 -1
- package/cssm/components/date-range-input/index.module.css +2 -2
- package/cssm/desktop.js +2 -1
- package/cssm/index.js +2 -2
- package/cssm/mobile.js +2 -1
- package/cssm/responsive.js +2 -2
- package/desktop.js +2 -1
- package/esm/{Component-3d173527.d.ts → Component-61c161e7.d.ts} +0 -0
- package/esm/{Component-3d173527.js → Component-61c161e7.js} +42 -29
- package/esm/Component.desktop.d.ts +1 -1
- package/esm/Component.desktop.js +2 -1
- package/esm/Component.mobile.d.ts +1 -1
- package/esm/Component.mobile.js +2 -1
- package/esm/Component.responsive.d.ts +1 -1
- package/esm/Component.responsive.js +1 -1
- package/esm/components/date-range-input/Component.js +2 -1
- package/esm/components/date-range-input/index.css +8 -8
- package/esm/components/date-range-input/index.d.ts +1 -1
- package/esm/components/date-range-input/index.js +2 -1
- package/esm/desktop.js +2 -1
- package/esm/index.js +2 -2
- package/esm/mobile.js +2 -1
- package/esm/responsive.js +2 -2
- package/index.js +2 -2
- package/mobile.js +2 -1
- package/modern/Component.desktop.js +1 -0
- package/modern/Component.mobile.js +1 -0
- package/modern/components/date-range-input/Component.js +42 -29
- package/modern/components/date-range-input/index.css +8 -8
- package/modern/components/date-range-input/index.js +1 -0
- package/modern/desktop.js +1 -0
- package/modern/mobile.js +1 -0
- package/package.json +5 -4
- package/responsive.js +2 -2
package/cssm/responsive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_responsive = require('./Component.responsive.js');
|
|
4
|
-
require('./Component-
|
|
4
|
+
require('./Component-540e1474.js');
|
|
5
5
|
require('react');
|
|
6
6
|
require('react-merge-refs');
|
|
7
7
|
require('classnames');
|
|
@@ -10,11 +10,11 @@ require('@alfalab/core-components-calendar/cssm');
|
|
|
10
10
|
require('@alfalab/core-components-icon-button/cssm');
|
|
11
11
|
require('@alfalab/core-components-input/cssm');
|
|
12
12
|
require('@alfalab/core-components-popover/cssm');
|
|
13
|
+
require('@alfalab/hooks');
|
|
13
14
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
14
15
|
require('./utils/format.js');
|
|
15
16
|
require('date-fns/parse');
|
|
16
17
|
require('./components/date-range-input/index.module.css');
|
|
17
|
-
require('@alfalab/hooks');
|
|
18
18
|
require('./Component.desktop.js');
|
|
19
19
|
require('./Component.mobile.js');
|
|
20
20
|
|
package/desktop.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_desktop = require('./Component.desktop.js');
|
|
4
|
-
require('./Component-
|
|
4
|
+
require('./Component-9a6da64e.js');
|
|
5
5
|
require('react');
|
|
6
6
|
require('react-merge-refs');
|
|
7
7
|
require('classnames');
|
|
@@ -10,6 +10,7 @@ require('@alfalab/core-components-calendar');
|
|
|
10
10
|
require('@alfalab/core-components-icon-button');
|
|
11
11
|
require('@alfalab/core-components-input');
|
|
12
12
|
require('@alfalab/core-components-popover');
|
|
13
|
+
require('@alfalab/hooks');
|
|
13
14
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
14
15
|
require('./utils/format.js');
|
|
15
16
|
require('date-fns/parse');
|
|
File without changes
|
|
@@ -6,6 +6,7 @@ import { usePeriod, Calendar } from '@alfalab/core-components-calendar/esm';
|
|
|
6
6
|
import { IconButton } from '@alfalab/core-components-icon-button/esm';
|
|
7
7
|
import { Input } from '@alfalab/core-components-input/esm';
|
|
8
8
|
import { Popover } from '@alfalab/core-components-popover/esm';
|
|
9
|
+
import { useDidUpdateEffect } from '@alfalab/hooks';
|
|
9
10
|
import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
11
|
import { parseTimestampToDate, DATE_FORMAT, DATE_MASK, format, parseDateString, isCompleteDateInput, isValid } from './utils/format.js';
|
|
11
12
|
|
|
@@ -48,7 +49,7 @@ function __rest(s, e) {
|
|
|
48
49
|
return t;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
var styles = {"component":"date-range-
|
|
52
|
+
var styles = {"component":"date-range-input__component_gu60y","calendarContainer":"date-range-input__calendarContainer_gu60y","calendarResponsive":"date-range-input__calendarResponsive_gu60y","block":"date-range-input__block_gu60y"};
|
|
52
53
|
require('./components/date-range-input/index.css')
|
|
53
54
|
|
|
54
55
|
/* eslint-disable no-useless-escape, jsx-a11y/click-events-have-key-events */
|
|
@@ -65,6 +66,10 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
65
66
|
useEffect(function () {
|
|
66
67
|
setOpen(defaultOpen);
|
|
67
68
|
}, [defaultOpen]);
|
|
69
|
+
useDidUpdateEffect(function () {
|
|
70
|
+
var newPropValue = propValue || '';
|
|
71
|
+
setValue(function (prevValue) { return (prevValue === newPropValue ? prevValue : newPropValue); });
|
|
72
|
+
}, [propValue]);
|
|
68
73
|
var handlePeriodChange = function (selectedFrom, selectedTo) {
|
|
69
74
|
if (selectedFrom && !selectedTo && value.length === DATE_MASK.length) {
|
|
70
75
|
setValue(parseTimestampToDate(selectedFrom));
|
|
@@ -73,24 +78,30 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
73
78
|
(selectedFrom === selectedTo && value.length === DATE_MASK.length)) {
|
|
74
79
|
setValue('');
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
var dateFrom = selectedFrom ? new Date(selectedFrom) : undefined;
|
|
82
|
+
var dateTo = selectedTo ? new Date(selectedTo) : undefined;
|
|
83
|
+
var newValue = [selectedFrom, selectedTo].filter(Boolean)
|
|
84
|
+
.map(function (timestamp) { return parseTimestampToDate(timestamp); })
|
|
85
|
+
.join(' - ');
|
|
86
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
87
|
+
dateFrom: dateFrom,
|
|
88
|
+
dateTo: dateTo,
|
|
89
|
+
value: newValue,
|
|
90
|
+
});
|
|
91
|
+
if (dateFrom && dateTo) {
|
|
92
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete({
|
|
93
|
+
dateFrom: dateFrom,
|
|
94
|
+
dateTo: dateTo,
|
|
95
|
+
value: newValue,
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
98
|
};
|
|
91
99
|
var _s = usePeriod({ onPeriodChange: handlePeriodChange }), selectedFrom = _s.selectedFrom, selectedTo = _s.selectedTo, updatePeriod = _s.updatePeriod, resetPeriod = _s.resetPeriod, setStart = _s.setStart, setEnd = _s.setEnd;
|
|
92
100
|
var handleInputWrapperFocus = function (event) {
|
|
93
101
|
if (view === 'desktop') {
|
|
102
|
+
if (picker) {
|
|
103
|
+
setOpen(true);
|
|
104
|
+
}
|
|
94
105
|
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
95
106
|
calendarRef.current.focus();
|
|
96
107
|
}
|
|
@@ -110,7 +121,7 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
110
121
|
if (newValue.length > DATE_MASK.length)
|
|
111
122
|
return;
|
|
112
123
|
// Позволяем вводить только цифры, точки, дефис и пробелы
|
|
113
|
-
if (/[^\d.
|
|
124
|
+
if (/[^\d. -]/.test(newValue)) {
|
|
114
125
|
return;
|
|
115
126
|
}
|
|
116
127
|
var dots = newValue.match(/\./g);
|
|
@@ -121,33 +132,37 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
121
132
|
}
|
|
122
133
|
var formattedValue = format(newValue);
|
|
123
134
|
var dateArr = formattedValue.split(' - ');
|
|
124
|
-
var dateFrom = parseDateString(dateArr[0]);
|
|
125
|
-
var dateTo = parseDateString(dateArr[1]);
|
|
126
|
-
if (
|
|
135
|
+
var dateFrom = dateArr[0] ? parseDateString(dateArr[0]) : undefined;
|
|
136
|
+
var dateTo = dateArr[1] ? parseDateString(dateArr[1]) : undefined;
|
|
137
|
+
if (!dateFrom && !dateTo) {
|
|
138
|
+
resetPeriod();
|
|
139
|
+
}
|
|
140
|
+
else if (selectedFrom && formattedValue.length < DATE_FORMAT.length) {
|
|
127
141
|
setStart();
|
|
128
142
|
}
|
|
129
143
|
else if (selectedFrom && selectedTo) {
|
|
130
144
|
setEnd();
|
|
131
145
|
}
|
|
132
|
-
else if (
|
|
146
|
+
else if (dateFrom &&
|
|
147
|
+
dateFnsIsValid(dateFrom) &&
|
|
133
148
|
((_a = dateArr[0]) === null || _a === void 0 ? void 0 : _a.length) === DATE_FORMAT.length &&
|
|
134
149
|
dateFrom.getTime() !== selectedFrom) {
|
|
135
150
|
setStart(dateFrom.getTime());
|
|
136
151
|
}
|
|
137
|
-
else if (
|
|
152
|
+
else if (dateTo &&
|
|
153
|
+
dateFnsIsValid(dateTo) &&
|
|
138
154
|
((_b = dateArr[1]) === null || _b === void 0 ? void 0 : _b.length) === DATE_FORMAT.length &&
|
|
139
155
|
dateTo.getTime() !== selectedTo) {
|
|
140
156
|
setEnd(dateTo.getTime());
|
|
141
157
|
}
|
|
142
158
|
setValue(formattedValue);
|
|
143
|
-
|
|
144
|
-
onChange({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
159
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
145
160
|
if (isCompleteDateInput(formattedValue)) {
|
|
146
161
|
var valid = isValid(formattedValue, dateArr[0], dateArr[1]);
|
|
147
162
|
if (!valid)
|
|
148
163
|
return;
|
|
149
|
-
if (
|
|
150
|
-
onComplete({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
164
|
+
if (dateFrom && dateTo) {
|
|
165
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete({ dateFrom: dateFrom, dateTo: dateTo, value: formattedValue }, event);
|
|
151
166
|
}
|
|
152
167
|
}
|
|
153
168
|
};
|
|
@@ -175,14 +190,12 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
175
190
|
// Не дает инпуту терять фокус при выборе даты
|
|
176
191
|
event.preventDefault();
|
|
177
192
|
};
|
|
178
|
-
var handleInputWrapperClick = function () {
|
|
179
|
-
if (view === 'desktop' && !open) {
|
|
180
|
-
setOpen(true);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
193
|
var handleIconButtonClick = function () {
|
|
184
194
|
if (!open)
|
|
185
195
|
setOpen(true);
|
|
196
|
+
if (view === 'desktop' && inputRef.current) {
|
|
197
|
+
inputRef.current.focus();
|
|
198
|
+
}
|
|
186
199
|
};
|
|
187
200
|
var renderCalendar = function () { return (
|
|
188
201
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -190,7 +203,7 @@ var DateRangeInput = React.forwardRef(function (_a, ref) {
|
|
|
190
203
|
React.createElement(Calendar$1, __assign({}, calendarProps, { responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, selectedFrom: selectedFrom, selectedTo: selectedTo, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })))); };
|
|
191
204
|
return (React.createElement("div", { className: cn(styles.component, className, (_b = {},
|
|
192
205
|
_b[styles.block] = block,
|
|
193
|
-
_b)),
|
|
206
|
+
_b)), onFocus: inputDisabled ? undefined : handleInputWrapperFocus, onBlur: handleBlur },
|
|
194
207
|
React.createElement(Input, __assign({}, restProps, { block: block, ref: mergeRefs([ref, inputRef]), value: value, onChange: handleChange, disabled: disabled, readOnly: readOnly, className: inputClassName, onClear: handleClear, rightAddons: React.createElement(React.Fragment, null,
|
|
195
208
|
rightAddons,
|
|
196
209
|
picker && (React.createElement(IconButton, { onClick: inputDisabled ? undefined : handleIconButtonClick, icon: CalendarMIcon, size: 'xxs' }))) })),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { DateRangeInputProps } from "./Component-
|
|
2
|
+
import { DateRangeInputProps } from "./Component-61c161e7";
|
|
3
3
|
type DateRangeInputDesktopProps = Omit<DateRangeInputProps, 'view'>;
|
|
4
4
|
declare const DateRangeInputDesktop: FC<DateRangeInputDesktopProps>;
|
|
5
5
|
export { DateRangeInputDesktopProps, DateRangeInputDesktop };
|
package/esm/Component.desktop.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DateRangeInput, _ as __assign } from './Component-
|
|
1
|
+
import { D as DateRangeInput, _ as __assign } from './Component-61c161e7.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import 'react-merge-refs';
|
|
4
4
|
import 'classnames';
|
|
@@ -7,6 +7,7 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/esm';
|
|
8
8
|
import '@alfalab/core-components-input/esm';
|
|
9
9
|
import '@alfalab/core-components-popover/esm';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { DateRangeInputProps } from "./Component-
|
|
2
|
+
import { DateRangeInputProps } from "./Component-61c161e7";
|
|
3
3
|
type DateRangeInputMobileProps = Omit<DateRangeInputProps, 'view'>;
|
|
4
4
|
declare const DateRangeInputMobile: FC<DateRangeInputMobileProps>;
|
|
5
5
|
export { DateRangeInputMobileProps, DateRangeInputMobile };
|
package/esm/Component.mobile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DateRangeInput, _ as __assign } from './Component-
|
|
1
|
+
import { D as DateRangeInput, _ as __assign } from './Component-61c161e7.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { CalendarMobile } from '@alfalab/core-components-calendar/esm';
|
|
4
4
|
import 'react-merge-refs';
|
|
@@ -7,6 +7,7 @@ import 'date-fns/isValid';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/esm';
|
|
8
8
|
import '@alfalab/core-components-input/esm';
|
|
9
9
|
import '@alfalab/core-components-popover/esm';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { DateRangeInputProps } from "./Component-
|
|
2
|
+
import { DateRangeInputProps } from "./Component-61c161e7";
|
|
3
3
|
type DateRangeInputResponsiveProps = Omit<DateRangeInputProps, 'view'> & {
|
|
4
4
|
/**
|
|
5
5
|
* Контрольная точка, с нее начинается desktop версия
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as __rest, _ as __assign } from './Component-
|
|
1
|
+
import { a as __rest, _ as __assign } from './Component-61c161e7.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useMedia } from '@alfalab/hooks';
|
|
4
4
|
import { DateRangeInputDesktop } from './Component.desktop.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DateRangeInput } from '../../Component-
|
|
1
|
+
export { D as DateRangeInput } from '../../Component-61c161e7.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import 'react-merge-refs';
|
|
4
4
|
import 'classnames';
|
|
@@ -7,6 +7,7 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/esm';
|
|
8
8
|
import '@alfalab/core-components-input/esm';
|
|
9
9
|
import '@alfalab/core-components-popover/esm';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import '../../utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: wjsyj */
|
|
2
2
|
:root {
|
|
3
3
|
|
|
4
4
|
/* Hard */
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
--gap-m: 16px;
|
|
12
12
|
}
|
|
13
13
|
:root {
|
|
14
|
-
--border-radius-
|
|
14
|
+
--border-radius-m: 8px;
|
|
15
15
|
}
|
|
16
16
|
:root {
|
|
17
17
|
--calendar-width: 344px;
|
|
@@ -37,28 +37,28 @@
|
|
|
37
37
|
/* marker */
|
|
38
38
|
}
|
|
39
39
|
:root {
|
|
40
|
-
--calendar-popover-border-radius:
|
|
40
|
+
--calendar-popover-border-radius: var(--border-radius-m);
|
|
41
41
|
}
|
|
42
|
-
.date-range-
|
|
42
|
+
.date-range-input__component_gu60y {
|
|
43
43
|
display: inline-block;
|
|
44
44
|
outline: none;
|
|
45
45
|
position: relative;
|
|
46
46
|
}
|
|
47
|
-
.date-range-
|
|
47
|
+
.date-range-input__calendarContainer_gu60y {
|
|
48
48
|
display: inline-block;
|
|
49
49
|
box-sizing: border-box;
|
|
50
50
|
border-radius: var(--calendar-popover-border-radius)
|
|
51
51
|
}
|
|
52
52
|
@media (max-width: 374px) {
|
|
53
|
-
.date-range-
|
|
53
|
+
.date-range-input__calendarContainer_gu60y {
|
|
54
54
|
width: 100%;
|
|
55
55
|
min-width: 288px
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
.date-range-
|
|
58
|
+
.date-range-input__calendarResponsive_gu60y {
|
|
59
59
|
width: var(--calendar-width);
|
|
60
60
|
padding: 0 var(--gap-m);
|
|
61
61
|
}
|
|
62
|
-
.date-range-
|
|
62
|
+
.date-range-input__block_gu60y {
|
|
63
63
|
width: 100%;
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "../../Component-
|
|
1
|
+
export * from "../../Component-61c161e7";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DateRangeInput } from '../../Component-
|
|
1
|
+
export { D as DateRangeInput } from '../../Component-61c161e7.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import 'react-merge-refs';
|
|
4
4
|
import 'classnames';
|
|
@@ -7,6 +7,7 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/esm';
|
|
8
8
|
import '@alfalab/core-components-input/esm';
|
|
9
9
|
import '@alfalab/core-components-popover/esm';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import '../../utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
package/esm/desktop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DateRangeInputDesktop } from './Component.desktop.js';
|
|
2
|
-
import './Component-
|
|
2
|
+
import './Component-61c161e7.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'react-merge-refs';
|
|
5
5
|
import 'classnames';
|
|
@@ -8,6 +8,7 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/esm';
|
|
9
9
|
import '@alfalab/core-components-input/esm';
|
|
10
10
|
import '@alfalab/core-components-popover/esm';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DateRangeInputResponsive as DateRangeInput } from './Component.responsive.js';
|
|
2
|
-
import './Component-
|
|
2
|
+
import './Component-61c161e7.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'react-merge-refs';
|
|
5
5
|
import 'classnames';
|
|
@@ -8,9 +8,9 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/esm';
|
|
9
9
|
import '@alfalab/core-components-input/esm';
|
|
10
10
|
import '@alfalab/core-components-popover/esm';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
|
14
|
-
import '@alfalab/hooks';
|
|
15
15
|
import './Component.desktop.js';
|
|
16
16
|
import './Component.mobile.js';
|
package/esm/mobile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DateRangeInputMobile } from './Component.mobile.js';
|
|
2
|
-
import './Component-
|
|
2
|
+
import './Component-61c161e7.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'react-merge-refs';
|
|
5
5
|
import 'classnames';
|
|
@@ -8,6 +8,7 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/esm';
|
|
9
9
|
import '@alfalab/core-components-input/esm';
|
|
10
10
|
import '@alfalab/core-components-popover/esm';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
package/esm/responsive.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DateRangeInputResponsive } from './Component.responsive.js';
|
|
2
|
-
import './Component-
|
|
2
|
+
import './Component-61c161e7.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'react-merge-refs';
|
|
5
5
|
import 'classnames';
|
|
@@ -8,9 +8,9 @@ import '@alfalab/core-components-calendar/esm';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/esm';
|
|
9
9
|
import '@alfalab/core-components-input/esm';
|
|
10
10
|
import '@alfalab/core-components-popover/esm';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
|
14
|
-
import '@alfalab/hooks';
|
|
15
15
|
import './Component.desktop.js';
|
|
16
16
|
import './Component.mobile.js';
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_responsive = require('./Component.responsive.js');
|
|
4
|
-
require('./Component-
|
|
4
|
+
require('./Component-9a6da64e.js');
|
|
5
5
|
require('react');
|
|
6
6
|
require('react-merge-refs');
|
|
7
7
|
require('classnames');
|
|
@@ -10,10 +10,10 @@ require('@alfalab/core-components-calendar');
|
|
|
10
10
|
require('@alfalab/core-components-icon-button');
|
|
11
11
|
require('@alfalab/core-components-input');
|
|
12
12
|
require('@alfalab/core-components-popover');
|
|
13
|
+
require('@alfalab/hooks');
|
|
13
14
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
14
15
|
require('./utils/format.js');
|
|
15
16
|
require('date-fns/parse');
|
|
16
|
-
require('@alfalab/hooks');
|
|
17
17
|
require('./Component.desktop.js');
|
|
18
18
|
require('./Component.mobile.js');
|
|
19
19
|
|
package/mobile.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Component_mobile = require('./Component.mobile.js');
|
|
4
|
-
require('./Component-
|
|
4
|
+
require('./Component-9a6da64e.js');
|
|
5
5
|
require('react');
|
|
6
6
|
require('react-merge-refs');
|
|
7
7
|
require('classnames');
|
|
@@ -10,6 +10,7 @@ require('@alfalab/core-components-calendar');
|
|
|
10
10
|
require('@alfalab/core-components-icon-button');
|
|
11
11
|
require('@alfalab/core-components-input');
|
|
12
12
|
require('@alfalab/core-components-popover');
|
|
13
|
+
require('@alfalab/hooks');
|
|
13
14
|
require('@alfalab/icons-glyph/CalendarMIcon');
|
|
14
15
|
require('./utils/format.js');
|
|
15
16
|
require('date-fns/parse');
|
|
@@ -7,6 +7,7 @@ import '@alfalab/core-components-calendar/modern';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/modern';
|
|
8
8
|
import '@alfalab/core-components-input/modern';
|
|
9
9
|
import '@alfalab/core-components-popover/modern';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
|
@@ -7,6 +7,7 @@ import 'date-fns/isValid';
|
|
|
7
7
|
import '@alfalab/core-components-icon-button/modern';
|
|
8
8
|
import '@alfalab/core-components-input/modern';
|
|
9
9
|
import '@alfalab/core-components-popover/modern';
|
|
10
|
+
import '@alfalab/hooks';
|
|
10
11
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
11
12
|
import './utils/format.js';
|
|
12
13
|
import 'date-fns/parse';
|
|
@@ -6,11 +6,12 @@ import { usePeriod, Calendar } from '@alfalab/core-components-calendar/modern';
|
|
|
6
6
|
import { IconButton } from '@alfalab/core-components-icon-button/modern';
|
|
7
7
|
import { Input } from '@alfalab/core-components-input/modern';
|
|
8
8
|
import { Popover } from '@alfalab/core-components-popover/modern';
|
|
9
|
+
import { useDidUpdateEffect } from '@alfalab/hooks';
|
|
9
10
|
import { CalendarMIcon } from '@alfalab/icons-glyph/CalendarMIcon';
|
|
10
11
|
import { parseTimestampToDate, DATE_FORMAT, DATE_MASK, format, parseDateString, isCompleteDateInput, isValid } from '../../utils/format.js';
|
|
11
12
|
import 'date-fns/parse';
|
|
12
13
|
|
|
13
|
-
const styles = {"component":"date-range-
|
|
14
|
+
const styles = {"component":"date-range-input__component_gu60y","calendarContainer":"date-range-input__calendarContainer_gu60y","calendarResponsive":"date-range-input__calendarResponsive_gu60y","block":"date-range-input__block_gu60y"};
|
|
14
15
|
require('./index.css')
|
|
15
16
|
|
|
16
17
|
/* eslint-disable no-useless-escape, jsx-a11y/click-events-have-key-events */
|
|
@@ -24,6 +25,10 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
24
25
|
useEffect(() => {
|
|
25
26
|
setOpen(defaultOpen);
|
|
26
27
|
}, [defaultOpen]);
|
|
28
|
+
useDidUpdateEffect(() => {
|
|
29
|
+
const newPropValue = propValue || '';
|
|
30
|
+
setValue((prevValue) => (prevValue === newPropValue ? prevValue : newPropValue));
|
|
31
|
+
}, [propValue]);
|
|
27
32
|
const handlePeriodChange = (selectedFrom, selectedTo) => {
|
|
28
33
|
if (selectedFrom && !selectedTo && value.length === DATE_MASK.length) {
|
|
29
34
|
setValue(parseTimestampToDate(selectedFrom));
|
|
@@ -32,24 +37,30 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
32
37
|
(selectedFrom === selectedTo && value.length === DATE_MASK.length)) {
|
|
33
38
|
setValue('');
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const dateFrom = selectedFrom ? new Date(selectedFrom) : undefined;
|
|
41
|
+
const dateTo = selectedTo ? new Date(selectedTo) : undefined;
|
|
42
|
+
const newValue = [selectedFrom, selectedTo].filter(Boolean)
|
|
43
|
+
.map((timestamp) => parseTimestampToDate(timestamp))
|
|
44
|
+
.join(' - ');
|
|
45
|
+
onChange?.({
|
|
46
|
+
dateFrom,
|
|
47
|
+
dateTo,
|
|
48
|
+
value: newValue,
|
|
49
|
+
});
|
|
50
|
+
if (dateFrom && dateTo) {
|
|
51
|
+
onComplete?.({
|
|
52
|
+
dateFrom,
|
|
53
|
+
dateTo,
|
|
54
|
+
value: newValue,
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
};
|
|
50
58
|
const { selectedFrom, selectedTo, updatePeriod, resetPeriod, setStart, setEnd } = usePeriod({ onPeriodChange: handlePeriodChange });
|
|
51
59
|
const handleInputWrapperFocus = (event) => {
|
|
52
60
|
if (view === 'desktop') {
|
|
61
|
+
if (picker) {
|
|
62
|
+
setOpen(true);
|
|
63
|
+
}
|
|
53
64
|
if (!open && event.target.tagName !== 'INPUT' && calendarRef.current) {
|
|
54
65
|
calendarRef.current.focus();
|
|
55
66
|
}
|
|
@@ -68,7 +79,7 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
68
79
|
if (newValue.length > DATE_MASK.length)
|
|
69
80
|
return;
|
|
70
81
|
// Позволяем вводить только цифры, точки, дефис и пробелы
|
|
71
|
-
if (/[^\d.
|
|
82
|
+
if (/[^\d. -]/.test(newValue)) {
|
|
72
83
|
return;
|
|
73
84
|
}
|
|
74
85
|
const dots = newValue.match(/\./g);
|
|
@@ -79,33 +90,37 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
79
90
|
}
|
|
80
91
|
const formattedValue = format(newValue);
|
|
81
92
|
const dateArr = formattedValue.split(' - ');
|
|
82
|
-
const dateFrom = parseDateString(dateArr[0]);
|
|
83
|
-
const dateTo = parseDateString(dateArr[1]);
|
|
84
|
-
if (
|
|
93
|
+
const dateFrom = dateArr[0] ? parseDateString(dateArr[0]) : undefined;
|
|
94
|
+
const dateTo = dateArr[1] ? parseDateString(dateArr[1]) : undefined;
|
|
95
|
+
if (!dateFrom && !dateTo) {
|
|
96
|
+
resetPeriod();
|
|
97
|
+
}
|
|
98
|
+
else if (selectedFrom && formattedValue.length < DATE_FORMAT.length) {
|
|
85
99
|
setStart();
|
|
86
100
|
}
|
|
87
101
|
else if (selectedFrom && selectedTo) {
|
|
88
102
|
setEnd();
|
|
89
103
|
}
|
|
90
|
-
else if (
|
|
104
|
+
else if (dateFrom &&
|
|
105
|
+
dateFnsIsValid(dateFrom) &&
|
|
91
106
|
dateArr[0]?.length === DATE_FORMAT.length &&
|
|
92
107
|
dateFrom.getTime() !== selectedFrom) {
|
|
93
108
|
setStart(dateFrom.getTime());
|
|
94
109
|
}
|
|
95
|
-
else if (
|
|
110
|
+
else if (dateTo &&
|
|
111
|
+
dateFnsIsValid(dateTo) &&
|
|
96
112
|
dateArr[1]?.length === DATE_FORMAT.length &&
|
|
97
113
|
dateTo.getTime() !== selectedTo) {
|
|
98
114
|
setEnd(dateTo.getTime());
|
|
99
115
|
}
|
|
100
116
|
setValue(formattedValue);
|
|
101
|
-
|
|
102
|
-
onChange({ dateFrom, dateTo, value: formattedValue }, event);
|
|
117
|
+
onChange?.({ dateFrom, dateTo, value: formattedValue }, event);
|
|
103
118
|
if (isCompleteDateInput(formattedValue)) {
|
|
104
119
|
const valid = isValid(formattedValue, dateArr[0], dateArr[1]);
|
|
105
120
|
if (!valid)
|
|
106
121
|
return;
|
|
107
|
-
if (
|
|
108
|
-
onComplete({ dateFrom, dateTo, value: formattedValue }, event);
|
|
122
|
+
if (dateFrom && dateTo) {
|
|
123
|
+
onComplete?.({ dateFrom, dateTo, value: formattedValue }, event);
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
126
|
};
|
|
@@ -133,14 +148,12 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
133
148
|
// Не дает инпуту терять фокус при выборе даты
|
|
134
149
|
event.preventDefault();
|
|
135
150
|
};
|
|
136
|
-
const handleInputWrapperClick = () => {
|
|
137
|
-
if (view === 'desktop' && !open) {
|
|
138
|
-
setOpen(true);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
151
|
const handleIconButtonClick = () => {
|
|
142
152
|
if (!open)
|
|
143
153
|
setOpen(true);
|
|
154
|
+
if (view === 'desktop' && inputRef.current) {
|
|
155
|
+
inputRef.current.focus();
|
|
156
|
+
}
|
|
144
157
|
};
|
|
145
158
|
const renderCalendar = () => (
|
|
146
159
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -148,7 +161,7 @@ const DateRangeInput = React.forwardRef(({ className, inputClassName, popoverCla
|
|
|
148
161
|
React.createElement(Calendar$1, { ...calendarProps, responsive: calendarResponsive, open: open, onClose: handleCalendarClose, ref: calendarRef, defaultMonth: defaultMonth, selectedFrom: selectedFrom, selectedTo: selectedTo, onChange: handleCalendarChange, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events })));
|
|
149
162
|
return (React.createElement("div", { className: cn(styles.component, className, {
|
|
150
163
|
[styles.block]: block,
|
|
151
|
-
}),
|
|
164
|
+
}), onFocus: inputDisabled ? undefined : handleInputWrapperFocus, onBlur: handleBlur },
|
|
152
165
|
React.createElement(Input, { ...restProps, block: block, ref: mergeRefs([ref, inputRef]), value: value, onChange: handleChange, disabled: disabled, readOnly: readOnly, className: inputClassName, onClear: handleClear, rightAddons: React.createElement(React.Fragment, null,
|
|
153
166
|
rightAddons,
|
|
154
167
|
picker && (React.createElement(IconButton, { onClick: inputDisabled ? undefined : handleIconButtonClick, icon: CalendarMIcon, size: 'xxs' }))) }),
|