@alfalab/core-components-date-range-input 2.2.0 → 2.2.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/{Component-105ad648.d.ts → Component-fd7fd8ef.d.ts} +0 -0
- package/{Component-105ad648.js → Component-fd7fd8ef.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.d.ts +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-e59830f5.d.ts → Component-550f221e.d.ts} +0 -0
- package/esm/{Component-e59830f5.js → Component-550f221e.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.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/mobile.js +2 -1
- package/esm/responsive.js +2 -2
- package/index.d.ts +2 -1
- 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/index.d.ts +2 -1
- package/modern/mobile.js +1 -0
- package/package.json +4 -3
- package/responsive.js +2 -2
|
@@ -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_a0llm","calendarContainer":"date-range-input__calendarContainer_a0llm","calendarResponsive":"date-range-input__calendarResponsive_a0llm","block":"date-range-input__block_a0llm"};
|
|
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' }))) }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: lj7cp */
|
|
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_a0llm {
|
|
43
43
|
display: inline-block;
|
|
44
44
|
outline: none;
|
|
45
45
|
position: relative;
|
|
46
46
|
}
|
|
47
|
-
.date-range-
|
|
47
|
+
.date-range-input__calendarContainer_a0llm {
|
|
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_a0llm {
|
|
54
54
|
width: 100%;
|
|
55
55
|
min-width: 288px
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
.date-range-
|
|
58
|
+
.date-range-input__calendarResponsive_a0llm {
|
|
59
59
|
width: var(--calendar-width);
|
|
60
60
|
padding: 0 var(--gap-m);
|
|
61
61
|
}
|
|
62
|
-
.date-range-
|
|
62
|
+
.date-range-input__block_a0llm {
|
|
63
63
|
width: 100%;
|
|
64
64
|
}
|
|
@@ -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';
|
package/modern/desktop.js
CHANGED
|
@@ -8,6 +8,7 @@ import '@alfalab/core-components-calendar/modern';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/modern';
|
|
9
9
|
import '@alfalab/core-components-input/modern';
|
|
10
10
|
import '@alfalab/core-components-popover/modern';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
package/modern/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { DateRangeInputResponsive as DateRangeInput
|
|
1
|
+
export { DateRangeInputResponsive as DateRangeInput } from "./responsive";
|
|
2
|
+
export type { DateRangeInputResponsiveProps as DateRangeInputProps } from "./responsive";
|
package/modern/mobile.js
CHANGED
|
@@ -8,6 +8,7 @@ import 'date-fns/isValid';
|
|
|
8
8
|
import '@alfalab/core-components-icon-button/modern';
|
|
9
9
|
import '@alfalab/core-components-input/modern';
|
|
10
10
|
import '@alfalab/core-components-popover/modern';
|
|
11
|
+
import '@alfalab/hooks';
|
|
11
12
|
import '@alfalab/icons-glyph/CalendarMIcon';
|
|
12
13
|
import './utils/format.js';
|
|
13
14
|
import 'date-fns/parse';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-date-range-input",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@alfalab/core-components-input": "^11.1.
|
|
18
|
+
"@alfalab/core-components-input": "^11.1.3",
|
|
19
19
|
"@alfalab/core-components-icon-button": "^6.0.2",
|
|
20
|
-
"@alfalab/core-components-calendar": "^6.2.
|
|
20
|
+
"@alfalab/core-components-calendar": "^6.2.2",
|
|
21
21
|
"@alfalab/core-components-popover": "^6.0.5",
|
|
22
|
+
"@alfalab/hooks": "^1.13.0",
|
|
22
23
|
"classnames": "^2.3.1"
|
|
23
24
|
}
|
|
24
25
|
}
|
package/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-fd7fd8ef.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
|
|