@alfalab/core-components-calendar-range 4.3.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/dist/Component.d.ts +25 -3
- package/dist/Component.js +19 -185
- package/dist/cssm/Component.d.ts +25 -3
- package/dist/cssm/Component.js +20 -184
- package/dist/cssm/hooks.d.ts +27 -0
- package/dist/cssm/hooks.js +149 -0
- package/dist/cssm/index.js +15 -6
- package/dist/cssm/tslib.es6-ce870b46.d.ts +32 -0
- package/dist/cssm/tslib.es6-ce870b46.js +42 -0
- package/dist/cssm/utils.d.ts +1 -10
- package/dist/cssm/utils.js +0 -15
- package/dist/cssm/{index.module.css → views/index.module.css} +30 -0
- package/dist/cssm/views/popover.d.ts +5 -0
- package/dist/cssm/views/popover.js +118 -0
- package/dist/cssm/views/static.d.ts +5 -0
- package/dist/cssm/views/static.js +170 -0
- package/dist/esm/Component.d.ts +25 -3
- package/dist/esm/Component.js +20 -185
- package/dist/esm/hooks.d.ts +27 -0
- package/dist/esm/hooks.js +134 -0
- package/dist/esm/index.js +14 -5
- package/dist/esm/index.module-87a4536c.d.ts +32 -0
- package/dist/esm/index.module-87a4536c.js +43 -0
- package/dist/esm/utils.d.ts +1 -10
- package/dist/esm/utils.js +1 -14
- package/dist/esm/views/index.css +66 -0
- package/dist/esm/views/popover.d.ts +5 -0
- package/dist/esm/views/popover.js +106 -0
- package/dist/esm/views/static.d.ts +5 -0
- package/dist/esm/views/static.js +154 -0
- package/dist/hooks.d.ts +27 -0
- package/dist/hooks.js +149 -0
- package/dist/index.js +14 -5
- package/dist/index.module-f4db2833.d.ts +32 -0
- package/dist/index.module-f4db2833.js +46 -0
- package/dist/modern/Component.d.ts +25 -3
- package/dist/modern/Component.js +20 -168
- package/dist/modern/hooks.d.ts +27 -0
- package/dist/modern/hooks.js +130 -0
- package/dist/modern/index.js +13 -4
- package/dist/modern/index.module-ac929490.js +4 -0
- package/dist/modern/utils.d.ts +1 -10
- package/dist/modern/utils.js +1 -14
- package/dist/modern/views/index.css +66 -0
- package/dist/modern/views/popover.d.ts +5 -0
- package/dist/modern/views/popover.js +115 -0
- package/dist/modern/views/static.d.ts +5 -0
- package/dist/modern/views/static.js +154 -0
- package/dist/utils.d.ts +1 -10
- package/dist/utils.js +0 -15
- package/dist/views/index.css +66 -0
- package/dist/views/popover.d.ts +5 -0
- package/dist/views/popover.js +116 -0
- package/dist/views/static.d.ts +5 -0
- package/dist/views/static.js +168 -0
- package/package.json +6 -6
- package/dist/cssm/useCalendarMaxMinDates.d.ts +0 -16
- package/dist/cssm/useCalendarMaxMinDates.js +0 -22
- package/dist/cssm/useCalendarMonthes.d.ts +0 -14
- package/dist/cssm/useCalendarMonthes.js +0 -54
- package/dist/esm/index.css +0 -36
- package/dist/esm/useCalendarMaxMinDates.d.ts +0 -16
- package/dist/esm/useCalendarMaxMinDates.js +0 -18
- package/dist/esm/useCalendarMonthes.d.ts +0 -14
- package/dist/esm/useCalendarMonthes.js +0 -50
- package/dist/index.css +0 -36
- package/dist/modern/index.css +0 -36
- package/dist/modern/useCalendarMaxMinDates.d.ts +0 -16
- package/dist/modern/useCalendarMaxMinDates.js +0 -17
- package/dist/modern/useCalendarMonthes.d.ts +0 -14
- package/dist/modern/useCalendarMonthes.js +0 -49
- package/dist/useCalendarMaxMinDates.d.ts +0 -16
- package/dist/useCalendarMaxMinDates.js +0 -22
- package/dist/useCalendarMonthes.d.ts +0 -14
- package/dist/useCalendarMonthes.js +0 -54
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import startOfMonth from 'date-fns/startOfMonth';
|
|
4
|
+
import { isValidInputValue, parseDateString, formatDate } from '@alfalab/core-components-calendar-input/dist/modern';
|
|
5
|
+
import { isCompleteDateInput, DateInput } from '@alfalab/core-components-date-input/dist/modern';
|
|
6
|
+
import addMonths from 'date-fns/addMonths';
|
|
7
|
+
import subMonths from 'date-fns/subMonths';
|
|
8
|
+
import max from 'date-fns/max';
|
|
9
|
+
import 'date-fns/min';
|
|
10
|
+
import 'date-fns/isEqual';
|
|
11
|
+
import { useStaticViewMonthes, useSelectionProps } from '../hooks.js';
|
|
12
|
+
import { s as styles } from '../index.module-ac929490.js';
|
|
13
|
+
import endOfMonth from 'date-fns/endOfMonth';
|
|
14
|
+
import { usePeriodWithReset, Calendar } from '@alfalab/core-components-calendar/dist/modern';
|
|
15
|
+
import { isDayButton } from '../utils.js';
|
|
16
|
+
|
|
17
|
+
/* eslint-disable complexity */
|
|
18
|
+
const CalendarRangeStatic = ({ className, defaultMonth = startOfMonth(new Date()).getTime(), minDate, maxDate, valueFrom = '', valueTo = '', onDateFromChange = () => null, onDateToChange = () => null, onChange = () => null, inputFromProps = {}, inputToProps = {}, offDays, events, dataTestId, }) => {
|
|
19
|
+
const [inputFromValue, setInputFromValue] = useState(valueFrom);
|
|
20
|
+
const [inputToValue, setInputToValue] = useState(valueTo);
|
|
21
|
+
let dateFrom = isValidInputValue(inputFromValue, minDate, maxDate, offDays)
|
|
22
|
+
? parseDateString(inputFromValue).getTime()
|
|
23
|
+
: null;
|
|
24
|
+
const dateTo = isValidInputValue(inputToValue, dateFrom || minDate, maxDate, offDays)
|
|
25
|
+
? parseDateString(inputToValue).getTime()
|
|
26
|
+
: null;
|
|
27
|
+
if (isCompleteDateInput(inputToValue) && !dateTo) {
|
|
28
|
+
dateFrom = null;
|
|
29
|
+
}
|
|
30
|
+
const bothInvalid = isCompleteDateInput(inputFromValue) &&
|
|
31
|
+
isCompleteDateInput(inputToValue) &&
|
|
32
|
+
parseDateString(inputFromValue).getTime() > parseDateString(inputToValue).getTime();
|
|
33
|
+
const [highlightedDate, setHighlightedDate] = useState(undefined);
|
|
34
|
+
const period = usePeriodWithReset({
|
|
35
|
+
initialSelectedFrom: dateFrom ? parseDateString(inputFromValue).getTime() : undefined,
|
|
36
|
+
initialSelectedTo: dateTo ? parseDateString(inputToValue).getTime() : undefined,
|
|
37
|
+
});
|
|
38
|
+
const validateInputFromValue = useCallback((value) => isValidInputValue(value, minDate, dateFrom || maxDate, offDays), [dateFrom, maxDate, minDate, offDays]);
|
|
39
|
+
const validateInputToValue = useCallback((value) => isValidInputValue(value, dateFrom || minDate, maxDate, offDays), [dateFrom, minDate, maxDate, offDays]);
|
|
40
|
+
const [inputFromInvalid, setInputFromInvalid] = useState(validateInputFromValue(inputFromValue) === false);
|
|
41
|
+
const [inputToInvalid, setInputToInvalid] = useState(validateInputToValue(inputToValue) === false);
|
|
42
|
+
const { monthFrom, monthTo, handleMonthFromChange, handleMonthToChange } = useStaticViewMonthes({
|
|
43
|
+
selectedFrom: period.selectedFrom,
|
|
44
|
+
selectedTo: period.selectedTo,
|
|
45
|
+
defaultMonth,
|
|
46
|
+
});
|
|
47
|
+
const handleValidInputFrom = useCallback(() => {
|
|
48
|
+
setInputFromInvalid(inputFromValue !== '' && !validateInputFromValue(inputFromValue));
|
|
49
|
+
}, [inputFromValue, validateInputFromValue]);
|
|
50
|
+
const handleValidInputTo = useCallback(() => {
|
|
51
|
+
setInputToInvalid(inputToValue !== '' && !validateInputToValue(inputToValue));
|
|
52
|
+
}, [inputToValue, validateInputToValue]);
|
|
53
|
+
const handleInputFromChange = useCallback((_, payload) => {
|
|
54
|
+
setInputFromValue(payload.value);
|
|
55
|
+
}, []);
|
|
56
|
+
const handleInputToChange = useCallback((_, payload) => {
|
|
57
|
+
setInputToValue(payload.value);
|
|
58
|
+
}, []);
|
|
59
|
+
const handleMouseOver = useCallback((event) => {
|
|
60
|
+
const target = event.target;
|
|
61
|
+
const mouseOverDayButton = isDayButton(target) || isDayButton(target.parentElement);
|
|
62
|
+
let date;
|
|
63
|
+
if (mouseOverDayButton) {
|
|
64
|
+
const button = target.tagName === 'BUTTON' ? target : target.parentElement;
|
|
65
|
+
if (button.dataset.date) {
|
|
66
|
+
date = +button.dataset.date;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
setHighlightedDate(date);
|
|
70
|
+
}, []);
|
|
71
|
+
const handleClearFrom = useCallback(() => {
|
|
72
|
+
setInputFromValue('');
|
|
73
|
+
}, []);
|
|
74
|
+
const handleClearTo = useCallback(() => {
|
|
75
|
+
setInputToValue('');
|
|
76
|
+
}, []);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
setInputFromValue(period.selectedFrom ? formatDate(period.selectedFrom) : '');
|
|
79
|
+
}, [period.selectedFrom]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setInputToValue(period.selectedTo ? formatDate(period.selectedTo) : '');
|
|
82
|
+
}, [period.selectedTo]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
setInputFromValue(valueFrom);
|
|
85
|
+
}, [valueFrom]);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
setInputToValue(valueTo);
|
|
88
|
+
}, [valueTo]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!inputFromValue || isCompleteDateInput(inputFromValue)) {
|
|
91
|
+
handleValidInputFrom();
|
|
92
|
+
}
|
|
93
|
+
period.setStart(dateFrom || undefined);
|
|
94
|
+
if (dateTo) {
|
|
95
|
+
period.setEnd(dateTo);
|
|
96
|
+
}
|
|
97
|
+
if (inputFromValue !== valueFrom) {
|
|
98
|
+
onDateFromChange({
|
|
99
|
+
value: inputFromValue,
|
|
100
|
+
date: dateFrom,
|
|
101
|
+
});
|
|
102
|
+
onChange({
|
|
103
|
+
valueFrom: inputFromValue,
|
|
104
|
+
valueTo: inputToValue,
|
|
105
|
+
dateFrom,
|
|
106
|
+
dateTo,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
+
}, [inputFromValue]);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!inputToValue || isCompleteDateInput(inputToValue)) {
|
|
113
|
+
handleValidInputTo();
|
|
114
|
+
}
|
|
115
|
+
period.setEnd(dateTo || undefined);
|
|
116
|
+
if (dateFrom) {
|
|
117
|
+
period.setStart(dateFrom);
|
|
118
|
+
}
|
|
119
|
+
if (inputToValue !== valueTo) {
|
|
120
|
+
onDateToChange({
|
|
121
|
+
value: inputToValue,
|
|
122
|
+
date: dateTo,
|
|
123
|
+
});
|
|
124
|
+
onChange({
|
|
125
|
+
valueFrom: inputFromValue,
|
|
126
|
+
valueTo: inputToValue,
|
|
127
|
+
dateFrom,
|
|
128
|
+
dateTo,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
132
|
+
}, [inputToValue]);
|
|
133
|
+
const rangeProps = useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
|
|
134
|
+
const { calendarProps: calendarFromProps, ...dateInputFromProps } = inputFromProps;
|
|
135
|
+
const { calendarProps: calendarToProps, ...dateInputToProps } = inputToProps;
|
|
136
|
+
const CalendarFromComponent = dateInputFromProps.Calendar || Calendar;
|
|
137
|
+
const CalendarToComponent = dateInputToProps.Calendar || Calendar;
|
|
138
|
+
return (
|
|
139
|
+
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
|
|
140
|
+
React.createElement("div", { className: cn(styles.component, styles.static, className), onMouseOver: handleMouseOver, "data-test-id": dataTestId },
|
|
141
|
+
React.createElement("div", null,
|
|
142
|
+
React.createElement(DateInput, Object.assign({}, dateInputFromProps, { mobileMode: dateInputFromProps.mobileMode === 'popover'
|
|
143
|
+
? 'input'
|
|
144
|
+
: dateInputFromProps.mobileMode, value: inputFromValue, onChange: handleInputFromChange, onClear: handleClearFrom, onBlur: handleValidInputFrom, error: bothInvalid || inputFromInvalid || dateInputFromProps.error, clear: true, block: true })),
|
|
145
|
+
React.createElement(CalendarFromComponent, Object.assign({}, calendarFromProps, { className: cn(styles.calendar, calendarFromProps?.className), month: monthFrom, selectorView: 'month-only', offDays: offDays, events: events, onChange: period.updatePeriod, onMonthChange: handleMonthFromChange, minDate: minDate, maxDate: maxDate && max([maxDate, endOfMonth(subMonths(maxDate, 1))]).getTime() }, rangeProps))),
|
|
146
|
+
React.createElement("span", { className: styles.divider }),
|
|
147
|
+
React.createElement("div", null,
|
|
148
|
+
React.createElement(DateInput, Object.assign({}, dateInputToProps, { mobileMode: dateInputToProps.mobileMode === 'popover'
|
|
149
|
+
? 'input'
|
|
150
|
+
: dateInputToProps.mobileMode, value: inputToValue, onChange: handleInputToChange, onClear: handleClearTo, onBlur: handleValidInputTo, error: bothInvalid || inputToInvalid, clear: true, block: true })),
|
|
151
|
+
React.createElement(CalendarToComponent, Object.assign({}, calendarToProps, { className: cn(styles.calendar, calendarToProps?.className), month: monthTo, selectorView: 'month-only', offDays: offDays, events: events, onChange: period.updatePeriod, onMonthChange: handleMonthToChange, minDate: minDate && startOfMonth(addMonths(minDate, 1)).getTime(), maxDate: maxDate }, rangeProps)))));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export { CalendarRangeStatic };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
type ValueState = {
|
|
2
|
-
date: number | null;
|
|
3
|
-
value: string;
|
|
4
|
-
};
|
|
5
|
-
declare const initialValueState: {
|
|
6
|
-
date: null;
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
declare const getCorrectValueState: (stateValue: ValueState, propValue?: string | undefined, minDate?: number | undefined, maxDate?: number | undefined) => ValueState;
|
|
10
1
|
declare const isDayButton: (node: HTMLElement | null) => string | false | null | undefined;
|
|
11
|
-
export {
|
|
2
|
+
export { isDayButton };
|
package/dist/utils.js
CHANGED
|
@@ -2,23 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var coreComponentsCalendar = require('@alfalab/core-components-calendar');
|
|
6
|
-
var coreComponentsCalendarInput = require('@alfalab/core-components-calendar-input');
|
|
7
|
-
|
|
8
|
-
var initialValueState = { date: null, value: '' };
|
|
9
|
-
var getCorrectValueState = function (stateValue, propValue, minDate, maxDate) {
|
|
10
|
-
var state = propValue === undefined
|
|
11
|
-
? stateValue
|
|
12
|
-
: { value: propValue, date: coreComponentsCalendarInput.parseDateString(propValue).getTime() };
|
|
13
|
-
if (!coreComponentsCalendar.dateInLimits(state.date, minDate, maxDate)) {
|
|
14
|
-
state.date = null;
|
|
15
|
-
}
|
|
16
|
-
return state;
|
|
17
|
-
};
|
|
18
5
|
var isDayButton = function (node) {
|
|
19
6
|
return node && node.tagName === 'BUTTON' && node.dataset.date;
|
|
20
7
|
};
|
|
21
8
|
|
|
22
|
-
exports.getCorrectValueState = getCorrectValueState;
|
|
23
|
-
exports.initialValueState = initialValueState;
|
|
24
9
|
exports.isDayButton = isDayButton;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* hash: 1fz84 */
|
|
2
|
+
:root {
|
|
3
|
+
--color-light-graphic-primary: #0b1f35;
|
|
4
|
+
}
|
|
5
|
+
:root {
|
|
6
|
+
|
|
7
|
+
/* Hard */
|
|
8
|
+
|
|
9
|
+
/* Up */
|
|
10
|
+
|
|
11
|
+
/* Hard up */
|
|
12
|
+
}
|
|
13
|
+
:root {
|
|
14
|
+
--gap-xs: 8px;
|
|
15
|
+
}
|
|
16
|
+
:root {
|
|
17
|
+
--calendar-inner-width: 280px;
|
|
18
|
+
|
|
19
|
+
/* Кнопки выбора месяцев и годов */
|
|
20
|
+
|
|
21
|
+
/* Шапка */
|
|
22
|
+
|
|
23
|
+
/* День */
|
|
24
|
+
|
|
25
|
+
/* today */
|
|
26
|
+
|
|
27
|
+
/* highlighted */
|
|
28
|
+
|
|
29
|
+
/* range */
|
|
30
|
+
|
|
31
|
+
/* selected */
|
|
32
|
+
|
|
33
|
+
/* disabled */
|
|
34
|
+
|
|
35
|
+
/* marker */
|
|
36
|
+
}
|
|
37
|
+
.calendar-range__component_3pyrv {
|
|
38
|
+
display: flex
|
|
39
|
+
}
|
|
40
|
+
.calendar-range__component_3pyrv button[aria-selected='true'] {
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
}
|
|
43
|
+
.calendar-range__component_3pyrv *[class*='errorIcon_'] {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
46
|
+
.calendar-range__component_3pyrv *[class*='calendarIcon_'] {
|
|
47
|
+
margin-right: 0;
|
|
48
|
+
}
|
|
49
|
+
.calendar-range__divider_3pyrv {
|
|
50
|
+
height: 48px;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
width: 16px;
|
|
55
|
+
margin: 0 var(--gap-xs)
|
|
56
|
+
}
|
|
57
|
+
.calendar-range__divider_3pyrv:after {
|
|
58
|
+
content: '';
|
|
59
|
+
display: block;
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 1px;
|
|
62
|
+
background-color: var(--color-light-graphic-primary);
|
|
63
|
+
}
|
|
64
|
+
.calendar-range__static_3pyrv .calendar-range__calendar_3pyrv {
|
|
65
|
+
width: var(--calendar-inner-width);
|
|
66
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { CalendarRangeProps } from "../Component";
|
|
3
|
+
type CalendarRangePopoverProps = Omit<CalendarRangeProps, 'calendarPosition'>;
|
|
4
|
+
declare const CalendarRangePopover: FC<CalendarRangePopoverProps>;
|
|
5
|
+
export { CalendarRangePopoverProps, CalendarRangePopover };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index_module = require('../index.module-f4db2833.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var cn = require('classnames');
|
|
8
|
+
var startOfMonth = require('date-fns/startOfMonth');
|
|
9
|
+
var coreComponentsCalendarInput = require('@alfalab/core-components-calendar-input');
|
|
10
|
+
var coreComponentsDateInput = require('@alfalab/core-components-date-input');
|
|
11
|
+
require('date-fns/addMonths');
|
|
12
|
+
require('date-fns/subMonths');
|
|
13
|
+
require('date-fns/max');
|
|
14
|
+
require('date-fns/min');
|
|
15
|
+
require('date-fns/isEqual');
|
|
16
|
+
var hooks = require('../hooks.js');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
21
|
+
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
|
22
|
+
var startOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(startOfMonth);
|
|
23
|
+
|
|
24
|
+
var CalendarRangePopover = function (_a) {
|
|
25
|
+
var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
|
|
26
|
+
var _k = React.useState(valueFrom), inputFromValue = _k[0], setInputFromValue = _k[1];
|
|
27
|
+
var _l = React.useState(valueTo), inputToValue = _l[0], setInputToValue = _l[1];
|
|
28
|
+
/**
|
|
29
|
+
* Ключ для сброса календарей
|
|
30
|
+
* Пользователь открыл календарь, изменил месяц, но ничего не выбрал
|
|
31
|
+
* — при следующем открытии в календаре будет установлен начальный месяц
|
|
32
|
+
*/
|
|
33
|
+
var _m = React.useState(0), resetKey = _m[0], setResetKey = _m[1];
|
|
34
|
+
var dateFrom = coreComponentsCalendarInput.isValidInputValue(inputFromValue, minDate, maxDate, offDays)
|
|
35
|
+
? coreComponentsCalendarInput.parseDateString(inputFromValue).getTime()
|
|
36
|
+
: null;
|
|
37
|
+
var dateTo = coreComponentsCalendarInput.isValidInputValue(inputToValue, dateFrom || minDate, maxDate, offDays)
|
|
38
|
+
? coreComponentsCalendarInput.parseDateString(inputToValue).getTime()
|
|
39
|
+
: null;
|
|
40
|
+
var _o = React.useState(coreComponentsDateInput.isCompleteDateInput(inputFromValue) && dateFrom === null), inputFromInvalid = _o[0], setInputFromInvalid = _o[1];
|
|
41
|
+
var _p = React.useState(coreComponentsDateInput.isCompleteDateInput(inputToValue) && dateTo === null), inputToInvalid = _p[0], setInputToInvalid = _p[1];
|
|
42
|
+
var bothInvalid = coreComponentsDateInput.isCompleteDateInput(inputFromValue) &&
|
|
43
|
+
coreComponentsDateInput.isCompleteDateInput(inputToValue) &&
|
|
44
|
+
coreComponentsCalendarInput.parseDateString(inputFromValue).getTime() > coreComponentsCalendarInput.parseDateString(inputToValue).getTime();
|
|
45
|
+
var _q = hooks.usePopoverViewMonthes({
|
|
46
|
+
dateFrom: dateFrom,
|
|
47
|
+
dateTo: dateTo,
|
|
48
|
+
defaultMonth: defaultMonth,
|
|
49
|
+
resetKey: resetKey,
|
|
50
|
+
}), monthFrom = _q.monthFrom, monthTo = _q.monthTo, handleMonthFromChange = _q.handleMonthFromChange, handleMonthToChange = _q.handleMonthToChange;
|
|
51
|
+
var handleValidInputFrom = React.useCallback(function () {
|
|
52
|
+
setInputFromInvalid(inputFromValue !== '' && !coreComponentsCalendarInput.isValidInputValue(inputFromValue, minDate, maxDate, offDays));
|
|
53
|
+
}, [inputFromValue, maxDate, minDate, offDays]);
|
|
54
|
+
var handleValidInputTo = React.useCallback(function () {
|
|
55
|
+
setInputToInvalid(inputToValue !== '' &&
|
|
56
|
+
!coreComponentsCalendarInput.isValidInputValue(inputToValue, dateFrom || minDate, maxDate, offDays));
|
|
57
|
+
}, [dateFrom, inputToValue, maxDate, minDate, offDays]);
|
|
58
|
+
var handleInputFromChange = React.useCallback(function (_, payload) {
|
|
59
|
+
setInputFromValue(payload.value);
|
|
60
|
+
}, []);
|
|
61
|
+
var handleInputToChange = React.useCallback(function (_, payload) {
|
|
62
|
+
setInputToValue(payload.value);
|
|
63
|
+
}, []);
|
|
64
|
+
var handleInputFromBlur = React.useCallback(function () {
|
|
65
|
+
handleValidInputFrom();
|
|
66
|
+
setResetKey(+new Date());
|
|
67
|
+
}, [handleValidInputFrom]);
|
|
68
|
+
var handleInputToBlur = React.useCallback(function () {
|
|
69
|
+
handleValidInputTo();
|
|
70
|
+
setResetKey(+new Date());
|
|
71
|
+
}, [handleValidInputTo]);
|
|
72
|
+
var handleFromChange = React.useCallback(function (_, payload) {
|
|
73
|
+
setInputFromValue(payload.value);
|
|
74
|
+
}, []);
|
|
75
|
+
var handleToChange = React.useCallback(function (_, payload) {
|
|
76
|
+
setInputToValue(payload.value);
|
|
77
|
+
}, []);
|
|
78
|
+
React.useEffect(function () {
|
|
79
|
+
setInputFromValue(valueFrom);
|
|
80
|
+
}, [valueFrom]);
|
|
81
|
+
React.useEffect(function () {
|
|
82
|
+
setInputToValue(valueTo);
|
|
83
|
+
}, [valueTo]);
|
|
84
|
+
React.useEffect(function () {
|
|
85
|
+
onDateFromChange({ value: inputFromValue, date: dateFrom });
|
|
86
|
+
onChange({
|
|
87
|
+
valueFrom: inputFromValue,
|
|
88
|
+
valueTo: inputToValue,
|
|
89
|
+
dateFrom: dateFrom,
|
|
90
|
+
dateTo: dateTo,
|
|
91
|
+
});
|
|
92
|
+
if (!inputFromValue || coreComponentsDateInput.isCompleteDateInput(inputFromValue)) {
|
|
93
|
+
handleValidInputFrom();
|
|
94
|
+
}
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, [inputFromValue]);
|
|
97
|
+
React.useEffect(function () {
|
|
98
|
+
onDateToChange({ value: inputToValue, date: dateTo });
|
|
99
|
+
onChange({
|
|
100
|
+
valueFrom: inputFromValue,
|
|
101
|
+
valueTo: inputToValue,
|
|
102
|
+
dateFrom: dateFrom,
|
|
103
|
+
dateTo: dateTo,
|
|
104
|
+
});
|
|
105
|
+
if (!inputToValue || coreComponentsDateInput.isCompleteDateInput(inputToValue)) {
|
|
106
|
+
handleValidInputTo();
|
|
107
|
+
}
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
}, [inputToValue]);
|
|
110
|
+
return (React__default['default'].createElement("div", { className: cn__default['default'](index_module.styles.component, className), "data-test-id": dataTestId },
|
|
111
|
+
React__default['default'].createElement(coreComponentsCalendarInput.CalendarInput, index_module.__assign({}, inputFromProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-start', error: inputFromInvalid || bothInvalid || inputFromProps.error, onChange: handleFromChange, onInputChange: handleInputFromChange, onBlur: handleInputFromBlur, value: inputFromValue, minDate: minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: index_module.__assign(index_module.__assign({}, inputFromProps.calendarProps), { month: monthFrom, onMonthChange: handleMonthFromChange, selectorView: 'full' }) })),
|
|
112
|
+
React__default['default'].createElement("span", { className: index_module.styles.divider }),
|
|
113
|
+
React__default['default'].createElement(coreComponentsCalendarInput.CalendarInput, index_module.__assign({}, inputToProps, { useAnchorWidth: false, calendarPosition: 'popover', popoverPosition: 'bottom-end', error: inputToInvalid || bothInvalid || inputToProps.error, onChange: handleToChange, onInputChange: handleInputToChange, onBlur: handleInputToBlur, value: inputToValue, minDate: dateFrom || minDate, maxDate: maxDate, offDays: offDays, events: events, calendarProps: index_module.__assign(index_module.__assign({}, inputToProps.calendarProps), { month: monthTo, onMonthChange: handleMonthToChange, selectorView: 'full' }) }))));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.CalendarRangePopover = CalendarRangePopover;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { CalendarRangeProps } from "../Component";
|
|
3
|
+
type CalendarRangeStaticProps = Omit<CalendarRangeProps, 'calendarPosition'>;
|
|
4
|
+
declare const CalendarRangeStatic: FC<CalendarRangeStaticProps>;
|
|
5
|
+
export { CalendarRangeStaticProps, CalendarRangeStatic };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index_module = require('../index.module-f4db2833.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var cn = require('classnames');
|
|
8
|
+
var startOfMonth = require('date-fns/startOfMonth');
|
|
9
|
+
var coreComponentsCalendarInput = require('@alfalab/core-components-calendar-input');
|
|
10
|
+
var coreComponentsDateInput = require('@alfalab/core-components-date-input');
|
|
11
|
+
var addMonths = require('date-fns/addMonths');
|
|
12
|
+
var subMonths = require('date-fns/subMonths');
|
|
13
|
+
var max = require('date-fns/max');
|
|
14
|
+
require('date-fns/min');
|
|
15
|
+
require('date-fns/isEqual');
|
|
16
|
+
var hooks = require('../hooks.js');
|
|
17
|
+
var endOfMonth = require('date-fns/endOfMonth');
|
|
18
|
+
var coreComponentsCalendar = require('@alfalab/core-components-calendar');
|
|
19
|
+
var utils = require('../utils.js');
|
|
20
|
+
|
|
21
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
24
|
+
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
|
25
|
+
var startOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(startOfMonth);
|
|
26
|
+
var addMonths__default = /*#__PURE__*/_interopDefaultLegacy(addMonths);
|
|
27
|
+
var subMonths__default = /*#__PURE__*/_interopDefaultLegacy(subMonths);
|
|
28
|
+
var max__default = /*#__PURE__*/_interopDefaultLegacy(max);
|
|
29
|
+
var endOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(endOfMonth);
|
|
30
|
+
|
|
31
|
+
var CalendarRangeStatic = function (_a) {
|
|
32
|
+
var className = _a.className, _b = _a.defaultMonth, defaultMonth = _b === void 0 ? startOfMonth__default['default'](new Date()).getTime() : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.valueFrom, valueFrom = _c === void 0 ? '' : _c, _d = _a.valueTo, valueTo = _d === void 0 ? '' : _d, _e = _a.onDateFromChange, onDateFromChange = _e === void 0 ? function () { return null; } : _e, _f = _a.onDateToChange, onDateToChange = _f === void 0 ? function () { return null; } : _f, _g = _a.onChange, onChange = _g === void 0 ? function () { return null; } : _g, _h = _a.inputFromProps, inputFromProps = _h === void 0 ? {} : _h, _j = _a.inputToProps, inputToProps = _j === void 0 ? {} : _j, offDays = _a.offDays, events = _a.events, dataTestId = _a.dataTestId;
|
|
33
|
+
var _k = React.useState(valueFrom), inputFromValue = _k[0], setInputFromValue = _k[1];
|
|
34
|
+
var _l = React.useState(valueTo), inputToValue = _l[0], setInputToValue = _l[1];
|
|
35
|
+
var dateFrom = coreComponentsCalendarInput.isValidInputValue(inputFromValue, minDate, maxDate, offDays)
|
|
36
|
+
? coreComponentsCalendarInput.parseDateString(inputFromValue).getTime()
|
|
37
|
+
: null;
|
|
38
|
+
var dateTo = coreComponentsCalendarInput.isValidInputValue(inputToValue, dateFrom || minDate, maxDate, offDays)
|
|
39
|
+
? coreComponentsCalendarInput.parseDateString(inputToValue).getTime()
|
|
40
|
+
: null;
|
|
41
|
+
if (coreComponentsDateInput.isCompleteDateInput(inputToValue) && !dateTo) {
|
|
42
|
+
dateFrom = null;
|
|
43
|
+
}
|
|
44
|
+
var bothInvalid = coreComponentsDateInput.isCompleteDateInput(inputFromValue) &&
|
|
45
|
+
coreComponentsDateInput.isCompleteDateInput(inputToValue) &&
|
|
46
|
+
coreComponentsCalendarInput.parseDateString(inputFromValue).getTime() > coreComponentsCalendarInput.parseDateString(inputToValue).getTime();
|
|
47
|
+
var _m = React.useState(undefined), highlightedDate = _m[0], setHighlightedDate = _m[1];
|
|
48
|
+
var period = coreComponentsCalendar.usePeriodWithReset({
|
|
49
|
+
initialSelectedFrom: dateFrom ? coreComponentsCalendarInput.parseDateString(inputFromValue).getTime() : undefined,
|
|
50
|
+
initialSelectedTo: dateTo ? coreComponentsCalendarInput.parseDateString(inputToValue).getTime() : undefined,
|
|
51
|
+
});
|
|
52
|
+
var validateInputFromValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, minDate, dateFrom || maxDate, offDays); }, [dateFrom, maxDate, minDate, offDays]);
|
|
53
|
+
var validateInputToValue = React.useCallback(function (value) { return coreComponentsCalendarInput.isValidInputValue(value, dateFrom || minDate, maxDate, offDays); }, [dateFrom, minDate, maxDate, offDays]);
|
|
54
|
+
var _o = React.useState(validateInputFromValue(inputFromValue) === false), inputFromInvalid = _o[0], setInputFromInvalid = _o[1];
|
|
55
|
+
var _p = React.useState(validateInputToValue(inputToValue) === false), inputToInvalid = _p[0], setInputToInvalid = _p[1];
|
|
56
|
+
var _q = hooks.useStaticViewMonthes({
|
|
57
|
+
selectedFrom: period.selectedFrom,
|
|
58
|
+
selectedTo: period.selectedTo,
|
|
59
|
+
defaultMonth: defaultMonth,
|
|
60
|
+
}), monthFrom = _q.monthFrom, monthTo = _q.monthTo, handleMonthFromChange = _q.handleMonthFromChange, handleMonthToChange = _q.handleMonthToChange;
|
|
61
|
+
var handleValidInputFrom = React.useCallback(function () {
|
|
62
|
+
setInputFromInvalid(inputFromValue !== '' && !validateInputFromValue(inputFromValue));
|
|
63
|
+
}, [inputFromValue, validateInputFromValue]);
|
|
64
|
+
var handleValidInputTo = React.useCallback(function () {
|
|
65
|
+
setInputToInvalid(inputToValue !== '' && !validateInputToValue(inputToValue));
|
|
66
|
+
}, [inputToValue, validateInputToValue]);
|
|
67
|
+
var handleInputFromChange = React.useCallback(function (_, payload) {
|
|
68
|
+
setInputFromValue(payload.value);
|
|
69
|
+
}, []);
|
|
70
|
+
var handleInputToChange = React.useCallback(function (_, payload) {
|
|
71
|
+
setInputToValue(payload.value);
|
|
72
|
+
}, []);
|
|
73
|
+
var handleMouseOver = React.useCallback(function (event) {
|
|
74
|
+
var target = event.target;
|
|
75
|
+
var mouseOverDayButton = utils.isDayButton(target) || utils.isDayButton(target.parentElement);
|
|
76
|
+
var date;
|
|
77
|
+
if (mouseOverDayButton) {
|
|
78
|
+
var button = target.tagName === 'BUTTON' ? target : target.parentElement;
|
|
79
|
+
if (button.dataset.date) {
|
|
80
|
+
date = +button.dataset.date;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
setHighlightedDate(date);
|
|
84
|
+
}, []);
|
|
85
|
+
var handleClearFrom = React.useCallback(function () {
|
|
86
|
+
setInputFromValue('');
|
|
87
|
+
}, []);
|
|
88
|
+
var handleClearTo = React.useCallback(function () {
|
|
89
|
+
setInputToValue('');
|
|
90
|
+
}, []);
|
|
91
|
+
React.useEffect(function () {
|
|
92
|
+
setInputFromValue(period.selectedFrom ? coreComponentsCalendarInput.formatDate(period.selectedFrom) : '');
|
|
93
|
+
}, [period.selectedFrom]);
|
|
94
|
+
React.useEffect(function () {
|
|
95
|
+
setInputToValue(period.selectedTo ? coreComponentsCalendarInput.formatDate(period.selectedTo) : '');
|
|
96
|
+
}, [period.selectedTo]);
|
|
97
|
+
React.useEffect(function () {
|
|
98
|
+
setInputFromValue(valueFrom);
|
|
99
|
+
}, [valueFrom]);
|
|
100
|
+
React.useEffect(function () {
|
|
101
|
+
setInputToValue(valueTo);
|
|
102
|
+
}, [valueTo]);
|
|
103
|
+
React.useEffect(function () {
|
|
104
|
+
if (!inputFromValue || coreComponentsDateInput.isCompleteDateInput(inputFromValue)) {
|
|
105
|
+
handleValidInputFrom();
|
|
106
|
+
}
|
|
107
|
+
period.setStart(dateFrom || undefined);
|
|
108
|
+
if (dateTo) {
|
|
109
|
+
period.setEnd(dateTo);
|
|
110
|
+
}
|
|
111
|
+
if (inputFromValue !== valueFrom) {
|
|
112
|
+
onDateFromChange({
|
|
113
|
+
value: inputFromValue,
|
|
114
|
+
date: dateFrom,
|
|
115
|
+
});
|
|
116
|
+
onChange({
|
|
117
|
+
valueFrom: inputFromValue,
|
|
118
|
+
valueTo: inputToValue,
|
|
119
|
+
dateFrom: dateFrom,
|
|
120
|
+
dateTo: dateTo,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
|
+
}, [inputFromValue]);
|
|
125
|
+
React.useEffect(function () {
|
|
126
|
+
if (!inputToValue || coreComponentsDateInput.isCompleteDateInput(inputToValue)) {
|
|
127
|
+
handleValidInputTo();
|
|
128
|
+
}
|
|
129
|
+
period.setEnd(dateTo || undefined);
|
|
130
|
+
if (dateFrom) {
|
|
131
|
+
period.setStart(dateFrom);
|
|
132
|
+
}
|
|
133
|
+
if (inputToValue !== valueTo) {
|
|
134
|
+
onDateToChange({
|
|
135
|
+
value: inputToValue,
|
|
136
|
+
date: dateTo,
|
|
137
|
+
});
|
|
138
|
+
onChange({
|
|
139
|
+
valueFrom: inputFromValue,
|
|
140
|
+
valueTo: inputToValue,
|
|
141
|
+
dateFrom: dateFrom,
|
|
142
|
+
dateTo: dateTo,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
+
}, [inputToValue]);
|
|
147
|
+
var rangeProps = hooks.useSelectionProps(period.selectedFrom, period.selectedTo, highlightedDate);
|
|
148
|
+
var calendarFromProps = inputFromProps.calendarProps, dateInputFromProps = index_module.__rest(inputFromProps, ["calendarProps"]);
|
|
149
|
+
var calendarToProps = inputToProps.calendarProps, dateInputToProps = index_module.__rest(inputToProps, ["calendarProps"]);
|
|
150
|
+
var CalendarFromComponent = dateInputFromProps.Calendar || coreComponentsCalendar.Calendar;
|
|
151
|
+
var CalendarToComponent = dateInputToProps.Calendar || coreComponentsCalendar.Calendar;
|
|
152
|
+
return (
|
|
153
|
+
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
|
|
154
|
+
React__default['default'].createElement("div", { className: cn__default['default'](index_module.styles.component, index_module.styles.static, className), onMouseOver: handleMouseOver, "data-test-id": dataTestId },
|
|
155
|
+
React__default['default'].createElement("div", null,
|
|
156
|
+
React__default['default'].createElement(coreComponentsDateInput.DateInput, index_module.__assign({}, dateInputFromProps, { mobileMode: dateInputFromProps.mobileMode === 'popover'
|
|
157
|
+
? 'input'
|
|
158
|
+
: dateInputFromProps.mobileMode, value: inputFromValue, onChange: handleInputFromChange, onClear: handleClearFrom, onBlur: handleValidInputFrom, error: bothInvalid || inputFromInvalid || dateInputFromProps.error, clear: true, block: true })),
|
|
159
|
+
React__default['default'].createElement(CalendarFromComponent, index_module.__assign({}, calendarFromProps, { className: cn__default['default'](index_module.styles.calendar, calendarFromProps === null || calendarFromProps === void 0 ? void 0 : calendarFromProps.className), month: monthFrom, selectorView: 'month-only', offDays: offDays, events: events, onChange: period.updatePeriod, onMonthChange: handleMonthFromChange, minDate: minDate, maxDate: maxDate && max__default['default']([maxDate, endOfMonth__default['default'](subMonths__default['default'](maxDate, 1))]).getTime() }, rangeProps))),
|
|
160
|
+
React__default['default'].createElement("span", { className: index_module.styles.divider }),
|
|
161
|
+
React__default['default'].createElement("div", null,
|
|
162
|
+
React__default['default'].createElement(coreComponentsDateInput.DateInput, index_module.__assign({}, dateInputToProps, { mobileMode: dateInputToProps.mobileMode === 'popover'
|
|
163
|
+
? 'input'
|
|
164
|
+
: dateInputToProps.mobileMode, value: inputToValue, onChange: handleInputToChange, onClear: handleClearTo, onBlur: handleValidInputTo, error: bothInvalid || inputToInvalid, clear: true, block: true })),
|
|
165
|
+
React__default['default'].createElement(CalendarToComponent, index_module.__assign({}, calendarToProps, { className: cn__default['default'](index_module.styles.calendar, calendarToProps === null || calendarToProps === void 0 ? void 0 : calendarToProps.className), month: monthTo, selectorView: 'month-only', offDays: offDays, events: events, onChange: period.updatePeriod, onMonthChange: handleMonthToChange, minDate: minDate && startOfMonth__default['default'](addMonths__default['default'](minDate, 1)).getTime(), maxDate: maxDate }, rangeProps)))));
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
exports.CalendarRangeStatic = CalendarRangeStatic;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-calendar-range",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Calendar range component",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"react-dom": "^16.9.0 || ^17.0.1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@alfalab/core-components-calendar": "^
|
|
23
|
-
"@alfalab/core-components-calendar-input": "^
|
|
22
|
+
"@alfalab/core-components-calendar": "^5.0.0",
|
|
23
|
+
"@alfalab/core-components-calendar-input": "^6.1.0",
|
|
24
|
+
"@alfalab/core-components-date-input": "^2.0.0",
|
|
24
25
|
"classnames": "^2.2.6",
|
|
25
|
-
"date-fns": "^2.16.1"
|
|
26
|
-
"react-merge-refs": "^1.1.0"
|
|
26
|
+
"date-fns": "^2.16.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "ddf4fab6035139cf412e0acb7174ef388f23e4f2"
|
|
29
29
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
type useMaxMinDatesProps = {
|
|
2
|
-
isPopover: boolean;
|
|
3
|
-
monthTo: number;
|
|
4
|
-
monthFrom: number;
|
|
5
|
-
selectedTo?: number;
|
|
6
|
-
selectedFrom?: number;
|
|
7
|
-
maxDate?: number;
|
|
8
|
-
minDate?: number;
|
|
9
|
-
};
|
|
10
|
-
declare function useCalendarMaxMinDates({ isPopover, monthTo, monthFrom, selectedTo, selectedFrom, maxDate, minDate, }: useMaxMinDatesProps): {
|
|
11
|
-
fromMinDate: number | undefined;
|
|
12
|
-
toMaxDate: number | undefined;
|
|
13
|
-
fromMaxDate: number | undefined;
|
|
14
|
-
toMinDate: number | undefined;
|
|
15
|
-
};
|
|
16
|
-
export { useCalendarMaxMinDates };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var dateFns = require('date-fns');
|
|
6
|
-
var coreComponentsCalendar = require('@alfalab/core-components-calendar/dist/cssm');
|
|
7
|
-
|
|
8
|
-
function useCalendarMaxMinDates(_a) {
|
|
9
|
-
var isPopover = _a.isPopover, monthTo = _a.monthTo, monthFrom = _a.monthFrom, selectedTo = _a.selectedTo, selectedFrom = _a.selectedFrom, maxDate = _a.maxDate, minDate = _a.minDate;
|
|
10
|
-
var popoverFromMaxDate = selectedTo || maxDate;
|
|
11
|
-
var fromMaxDate = coreComponentsCalendar.limitDate(dateFns.endOfMonth(monthFrom), minDate, maxDate).getTime();
|
|
12
|
-
var popoverToMinDate = selectedFrom || minDate;
|
|
13
|
-
var toMinDate = coreComponentsCalendar.limitDate(dateFns.startOfMonth(monthTo), minDate, maxDate).getTime();
|
|
14
|
-
return {
|
|
15
|
-
fromMinDate: minDate,
|
|
16
|
-
toMaxDate: maxDate,
|
|
17
|
-
fromMaxDate: isPopover ? popoverFromMaxDate : fromMaxDate,
|
|
18
|
-
toMinDate: isPopover ? popoverToMinDate : toMinDate,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
exports.useCalendarMaxMinDates = useCalendarMaxMinDates;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ValueState } from "./utils";
|
|
2
|
-
type useMonthProps = {
|
|
3
|
-
defaultMonth: number;
|
|
4
|
-
isPopover: boolean;
|
|
5
|
-
inputValueFrom: ValueState;
|
|
6
|
-
inputValueTo: ValueState;
|
|
7
|
-
};
|
|
8
|
-
declare function useCalendarMonthes({ inputValueFrom, inputValueTo, defaultMonth, isPopover, }: useMonthProps): {
|
|
9
|
-
monthFrom: number;
|
|
10
|
-
monthTo: number;
|
|
11
|
-
handleMonthFromChange: (newMonthFrom: number) => void;
|
|
12
|
-
handleMonthToChange: (newMonthTo: number) => void;
|
|
13
|
-
};
|
|
14
|
-
export { useCalendarMonthes };
|