@helsenorge/datepicker 9.4.1 → 9.4.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/CHANGELOG.md +17 -0
- package/components/DatePicker/DatePicker.d.ts +1 -1
- package/components/DatePicker/DatePicker.test.d.ts +0 -1
- package/components/DatePicker/DatePickerPopup.d.ts +1 -1
- package/components/DatePicker/DateTime.d.ts +1 -1
- package/components/DatePicker/DateTimePickerWrapper.d.ts +1 -1
- package/components/DatePicker/index.js +1836 -1067
- package/components/DatePicker/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,62 +1,74 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import
|
|
3
|
-
import { isSameDay
|
|
4
|
-
import { enUS
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { PopOverVariant
|
|
10
|
-
import { ZIndex
|
|
11
|
-
import { useKeyboardEvent
|
|
12
|
-
import { useOutsideEvent
|
|
13
|
-
import { usePseudoClasses
|
|
14
|
-
import { isMobileUA
|
|
15
|
-
import { isMutableRefObject
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import { useFocusTrap
|
|
19
|
-
import { useInterval
|
|
20
|
-
import { useIsVisible
|
|
21
|
-
import { useLayoutEvent
|
|
22
|
-
import { useSize
|
|
23
|
-
import { getSpacer
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import { useUuid
|
|
27
|
-
import { isComponent
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
for (var
|
|
31
|
-
|
|
32
|
-
for (var
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, forwardRef, useContext, useState, useEffect, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { isSameDay, subDays, addDays, differenceInCalendarDays, startOfMonth, endOfMonth, startOfDay, addMonths, differenceInCalendarMonths, isSameMonth, isBefore, isAfter, getUnixTime, getWeeksInMonth, addWeeks, isSameYear, setMonth, setYear, startOfYear, max, min, endOfISOWeek, endOfWeek, startOfISOWeek, startOfWeek, getISOWeek, getWeek, format, isDate, addYears, isValid, parse, isWithinInterval } from "date-fns";
|
|
4
|
+
import { enUS, nb } from "date-fns/locale";
|
|
5
|
+
import Button$1 from "@helsenorge/designsystem-react/components/Button";
|
|
6
|
+
import Icon from "@helsenorge/designsystem-react/components/Icon";
|
|
7
|
+
import Calendar from "@helsenorge/designsystem-react/components/Icons/Calendar";
|
|
8
|
+
import Input from "@helsenorge/designsystem-react/components/Input";
|
|
9
|
+
import { PopOverVariant } from "@helsenorge/designsystem-react/components/PopOver";
|
|
10
|
+
import { ZIndex, KeyboardEventKey } from "@helsenorge/designsystem-react/constants";
|
|
11
|
+
import { useKeyboardEvent } from "@helsenorge/designsystem-react/hooks/useKeyboardEvent";
|
|
12
|
+
import { useOutsideEvent } from "@helsenorge/designsystem-react/hooks/useOutsideEvent";
|
|
13
|
+
import { usePseudoClasses } from "@helsenorge/designsystem-react/hooks/usePseudoClasses";
|
|
14
|
+
import { isMobileUA } from "@helsenorge/designsystem-react/utils/mobile";
|
|
15
|
+
import { isMutableRefObject, mergeRefs } from "@helsenorge/designsystem-react/utils/refs";
|
|
16
|
+
import classNames from "classnames";
|
|
17
|
+
import reactdaypickerstyles from "react-day-picker/dist/style.module.css";
|
|
18
|
+
import { useFocusTrap } from "@helsenorge/designsystem-react/hooks/useFocusTrap";
|
|
19
|
+
import { useInterval } from "@helsenorge/designsystem-react/hooks/useInterval";
|
|
20
|
+
import { useIsVisible } from "@helsenorge/designsystem-react/hooks/useIsVisible";
|
|
21
|
+
import { useLayoutEvent } from "@helsenorge/designsystem-react/hooks/useLayoutEvent";
|
|
22
|
+
import { useSize } from "@helsenorge/designsystem-react/hooks/useSize";
|
|
23
|
+
import { getSpacer } from "@helsenorge/designsystem-react/theme/currys/spacing";
|
|
24
|
+
import styles from "./styles.module.scss";
|
|
25
|
+
import ErrorWrapper from "@helsenorge/designsystem-react/components/ErrorWrapper";
|
|
26
|
+
import { useUuid } from "@helsenorge/designsystem-react/hooks/useUuid";
|
|
27
|
+
import { isComponent } from "@helsenorge/designsystem-react/utils/component";
|
|
28
|
+
var __assign = function() {
|
|
29
|
+
__assign = Object.assign || function __assign2(t) {
|
|
30
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
31
|
+
s = arguments[i];
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
33
33
|
}
|
|
34
34
|
return t;
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
|
+
return __assign.apply(this, arguments);
|
|
36
37
|
};
|
|
37
|
-
function
|
|
38
|
-
var
|
|
39
|
-
for (var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
function __rest(s, e) {
|
|
39
|
+
var t = {};
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
41
|
+
t[p] = s[p];
|
|
42
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
43
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
44
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
45
|
+
t[p[i]] = s[p[i]];
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
44
48
|
}
|
|
45
|
-
function
|
|
46
|
-
for (var
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
+
function __spreadArray(to, from, pack) {
|
|
50
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
57
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
58
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
59
|
+
var e = new Error(message);
|
|
60
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
61
|
+
};
|
|
62
|
+
function isDayPickerMultiple(props) {
|
|
63
|
+
return props.mode === "multiple";
|
|
52
64
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
65
|
+
function isDayPickerRange(props) {
|
|
66
|
+
return props.mode === "range";
|
|
55
67
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
68
|
+
function isDayPickerSingle(props) {
|
|
69
|
+
return props.mode === "single";
|
|
58
70
|
}
|
|
59
|
-
var
|
|
71
|
+
var defaultClassNames = {
|
|
60
72
|
root: "rdp",
|
|
61
73
|
multiple_months: "rdp-multiple_months",
|
|
62
74
|
with_weeknumber: "rdp-with_weeknumber",
|
|
@@ -99,348 +111,532 @@ var Dn = {
|
|
|
99
111
|
day_range_end: "rdp-day_range_end",
|
|
100
112
|
day_range_middle: "rdp-day_range_middle"
|
|
101
113
|
};
|
|
102
|
-
function
|
|
103
|
-
return
|
|
114
|
+
function formatCaption(month, options) {
|
|
115
|
+
return format(month, "LLLL y", options);
|
|
104
116
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
117
|
+
function formatDay(day, options) {
|
|
118
|
+
return format(day, "d", options);
|
|
107
119
|
}
|
|
108
|
-
function
|
|
109
|
-
return
|
|
120
|
+
function formatMonthCaption(month, options) {
|
|
121
|
+
return format(month, "LLLL", options);
|
|
110
122
|
}
|
|
111
|
-
function
|
|
112
|
-
return "".concat(
|
|
123
|
+
function formatWeekNumber(weekNumber) {
|
|
124
|
+
return "".concat(weekNumber);
|
|
113
125
|
}
|
|
114
|
-
function
|
|
115
|
-
return
|
|
126
|
+
function formatWeekdayName(weekday, options) {
|
|
127
|
+
return format(weekday, "cccccc", options);
|
|
116
128
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
129
|
+
function formatYearCaption(year, options) {
|
|
130
|
+
return format(year, "yyyy", options);
|
|
119
131
|
}
|
|
120
|
-
var
|
|
132
|
+
var formatters = /* @__PURE__ */ Object.freeze({
|
|
121
133
|
__proto__: null,
|
|
122
|
-
formatCaption
|
|
123
|
-
formatDay
|
|
124
|
-
formatMonthCaption
|
|
125
|
-
formatWeekNumber
|
|
126
|
-
formatWeekdayName
|
|
127
|
-
formatYearCaption
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
formatCaption,
|
|
135
|
+
formatDay,
|
|
136
|
+
formatMonthCaption,
|
|
137
|
+
formatWeekNumber,
|
|
138
|
+
formatWeekdayName,
|
|
139
|
+
formatYearCaption
|
|
140
|
+
});
|
|
141
|
+
var labelDay = function(day, activeModifiers, options) {
|
|
142
|
+
return format(day, "do MMMM (EEEE)", options);
|
|
143
|
+
};
|
|
144
|
+
var labelMonthDropdown = function() {
|
|
131
145
|
return "Month: ";
|
|
132
|
-
}
|
|
146
|
+
};
|
|
147
|
+
var labelNext = function() {
|
|
133
148
|
return "Go to next month";
|
|
134
|
-
}
|
|
149
|
+
};
|
|
150
|
+
var labelPrevious = function() {
|
|
135
151
|
return "Go to previous month";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
};
|
|
153
|
+
var labelWeekday = function(day, options) {
|
|
154
|
+
return format(day, "cccc", options);
|
|
155
|
+
};
|
|
156
|
+
var labelWeekNumber = function(n) {
|
|
157
|
+
return "Week n. ".concat(n);
|
|
158
|
+
};
|
|
159
|
+
var labelYearDropdown = function() {
|
|
141
160
|
return "Year: ";
|
|
142
|
-
}
|
|
161
|
+
};
|
|
162
|
+
var labels = /* @__PURE__ */ Object.freeze({
|
|
143
163
|
__proto__: null,
|
|
144
|
-
labelDay
|
|
145
|
-
labelMonthDropdown
|
|
146
|
-
labelNext
|
|
147
|
-
labelPrevious
|
|
148
|
-
labelWeekNumber
|
|
149
|
-
labelWeekday
|
|
150
|
-
labelYearDropdown
|
|
164
|
+
labelDay,
|
|
165
|
+
labelMonthDropdown,
|
|
166
|
+
labelNext,
|
|
167
|
+
labelPrevious,
|
|
168
|
+
labelWeekNumber,
|
|
169
|
+
labelWeekday,
|
|
170
|
+
labelYearDropdown
|
|
151
171
|
});
|
|
152
|
-
function
|
|
153
|
-
var
|
|
172
|
+
function getDefaultContextValues() {
|
|
173
|
+
var captionLayout = "buttons";
|
|
174
|
+
var classNames2 = defaultClassNames;
|
|
175
|
+
var locale = enUS;
|
|
176
|
+
var modifiersClassNames = {};
|
|
177
|
+
var modifiers = {};
|
|
178
|
+
var numberOfMonths = 1;
|
|
179
|
+
var styles2 = {};
|
|
180
|
+
var today = /* @__PURE__ */ new Date();
|
|
154
181
|
return {
|
|
155
|
-
captionLayout
|
|
156
|
-
classNames:
|
|
157
|
-
formatters
|
|
158
|
-
labels
|
|
159
|
-
locale
|
|
160
|
-
modifiersClassNames
|
|
161
|
-
modifiers
|
|
162
|
-
numberOfMonths
|
|
163
|
-
styles:
|
|
164
|
-
today
|
|
182
|
+
captionLayout,
|
|
183
|
+
classNames: classNames2,
|
|
184
|
+
formatters,
|
|
185
|
+
labels,
|
|
186
|
+
locale,
|
|
187
|
+
modifiersClassNames,
|
|
188
|
+
modifiers,
|
|
189
|
+
numberOfMonths,
|
|
190
|
+
styles: styles2,
|
|
191
|
+
today,
|
|
165
192
|
mode: "default"
|
|
166
193
|
};
|
|
167
194
|
}
|
|
168
|
-
function
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
195
|
+
function parseFromToProps(props) {
|
|
196
|
+
var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
|
|
197
|
+
var fromDate = props.fromDate, toDate = props.toDate;
|
|
198
|
+
if (fromMonth) {
|
|
199
|
+
fromDate = startOfMonth(fromMonth);
|
|
200
|
+
} else if (fromYear) {
|
|
201
|
+
fromDate = new Date(fromYear, 0, 1);
|
|
202
|
+
}
|
|
203
|
+
if (toMonth) {
|
|
204
|
+
toDate = endOfMonth(toMonth);
|
|
205
|
+
} else if (toYear) {
|
|
206
|
+
toDate = new Date(toYear, 11, 31);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
fromDate: fromDate ? startOfDay(fromDate) : void 0,
|
|
210
|
+
toDate: toDate ? startOfDay(toDate) : void 0
|
|
173
211
|
};
|
|
174
212
|
}
|
|
175
|
-
var
|
|
176
|
-
function
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var
|
|
186
|
-
if (
|
|
213
|
+
var DayPickerContext = createContext(void 0);
|
|
214
|
+
function DayPickerProvider(props) {
|
|
215
|
+
var _a;
|
|
216
|
+
var initialProps = props.initialProps;
|
|
217
|
+
var defaultContextValues = getDefaultContextValues();
|
|
218
|
+
var _b = parseFromToProps(initialProps), fromDate = _b.fromDate, toDate = _b.toDate;
|
|
219
|
+
var captionLayout = (_a = initialProps.captionLayout) !== null && _a !== void 0 ? _a : defaultContextValues.captionLayout;
|
|
220
|
+
if (captionLayout !== "buttons" && (!fromDate || !toDate)) {
|
|
221
|
+
captionLayout = "buttons";
|
|
222
|
+
}
|
|
223
|
+
var onSelect;
|
|
224
|
+
if (isDayPickerSingle(initialProps) || isDayPickerMultiple(initialProps) || isDayPickerRange(initialProps)) {
|
|
225
|
+
onSelect = initialProps.onSelect;
|
|
226
|
+
}
|
|
227
|
+
var value = __assign(__assign(__assign({}, defaultContextValues), initialProps), { captionLayout, classNames: __assign(__assign({}, defaultContextValues.classNames), initialProps.classNames), components: __assign({}, initialProps.components), formatters: __assign(__assign({}, defaultContextValues.formatters), initialProps.formatters), fromDate, labels: __assign(__assign({}, defaultContextValues.labels), initialProps.labels), mode: initialProps.mode || defaultContextValues.mode, modifiers: __assign(__assign({}, defaultContextValues.modifiers), initialProps.modifiers), modifiersClassNames: __assign(__assign({}, defaultContextValues.modifiersClassNames), initialProps.modifiersClassNames), onSelect, styles: __assign(__assign({}, defaultContextValues.styles), initialProps.styles), toDate });
|
|
228
|
+
return jsx(DayPickerContext.Provider, { value, children: props.children });
|
|
229
|
+
}
|
|
230
|
+
function useDayPicker() {
|
|
231
|
+
var context = useContext(DayPickerContext);
|
|
232
|
+
if (!context) {
|
|
187
233
|
throw new Error("useDayPicker must be used within a DayPickerProvider.");
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
234
|
+
}
|
|
235
|
+
return context;
|
|
236
|
+
}
|
|
237
|
+
function CaptionLabel(props) {
|
|
238
|
+
var _a = useDayPicker(), locale = _a.locale, classNames2 = _a.classNames, styles2 = _a.styles, formatCaption2 = _a.formatters.formatCaption;
|
|
239
|
+
return jsx("div", { className: classNames2.caption_label, style: styles2.caption_label, "aria-live": "polite", role: "presentation", id: props.id, children: formatCaption2(props.displayMonth, { locale }) });
|
|
240
|
+
}
|
|
241
|
+
function IconDropdown(props) {
|
|
242
|
+
return jsx("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props, { children: jsx("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" }) }));
|
|
243
|
+
}
|
|
244
|
+
function Dropdown(props) {
|
|
245
|
+
var _a, _b;
|
|
246
|
+
var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
|
|
247
|
+
var dayPicker = useDayPicker();
|
|
248
|
+
var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
|
|
249
|
+
return jsxs("div", { className, style, children: [jsx("span", { className: dayPicker.classNames.vhidden, children: props["aria-label"] }), jsx("select", { name: props.name, "aria-label": props["aria-label"], className: dayPicker.classNames.dropdown, style: dayPicker.styles.dropdown, value, onChange, children }), jsxs("div", { className: dayPicker.classNames.caption_label, style: dayPicker.styles.caption_label, "aria-hidden": "true", children: [caption, jsx(IconDropdownComponent, { className: dayPicker.classNames.dropdown_icon, style: dayPicker.styles.dropdown_icon })] })] });
|
|
250
|
+
}
|
|
251
|
+
function MonthsDropdown(props) {
|
|
252
|
+
var _a;
|
|
253
|
+
var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, styles2 = _b.styles, locale = _b.locale, formatMonthCaption2 = _b.formatters.formatMonthCaption, classNames2 = _b.classNames, components = _b.components, labelMonthDropdown2 = _b.labels.labelMonthDropdown;
|
|
254
|
+
if (!fromDate)
|
|
255
|
+
return jsx(Fragment, {});
|
|
256
|
+
if (!toDate)
|
|
257
|
+
return jsx(Fragment, {});
|
|
258
|
+
var dropdownMonths = [];
|
|
259
|
+
if (isSameYear(fromDate, toDate)) {
|
|
260
|
+
var date = startOfMonth(fromDate);
|
|
261
|
+
for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
|
|
262
|
+
dropdownMonths.push(setMonth(date, month));
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
var date = startOfMonth(/* @__PURE__ */ new Date());
|
|
266
|
+
for (var month = 0; month <= 11; month++) {
|
|
267
|
+
dropdownMonths.push(setMonth(date, month));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
var handleChange = function(e) {
|
|
271
|
+
var selectedMonth = Number(e.target.value);
|
|
272
|
+
var newMonth = setMonth(startOfMonth(props.displayMonth), selectedMonth);
|
|
273
|
+
props.onChange(newMonth);
|
|
274
|
+
};
|
|
275
|
+
var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
|
|
276
|
+
return jsx(DropdownComponent, { name: "months", "aria-label": labelMonthDropdown2(), className: classNames2.dropdown_month, style: styles2.dropdown_month, onChange: handleChange, value: props.displayMonth.getMonth(), caption: formatMonthCaption2(props.displayMonth, { locale }), children: dropdownMonths.map(function(m) {
|
|
277
|
+
return jsx("option", { value: m.getMonth(), children: formatMonthCaption2(m, { locale }) }, m.getMonth());
|
|
220
278
|
}) });
|
|
221
279
|
}
|
|
222
|
-
function
|
|
223
|
-
var
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
280
|
+
function YearsDropdown(props) {
|
|
281
|
+
var _a;
|
|
282
|
+
var displayMonth = props.displayMonth;
|
|
283
|
+
var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, locale = _b.locale, styles2 = _b.styles, classNames2 = _b.classNames, components = _b.components, formatYearCaption2 = _b.formatters.formatYearCaption, labelYearDropdown2 = _b.labels.labelYearDropdown;
|
|
284
|
+
var years = [];
|
|
285
|
+
if (!fromDate)
|
|
286
|
+
return jsx(Fragment, {});
|
|
287
|
+
if (!toDate)
|
|
288
|
+
return jsx(Fragment, {});
|
|
289
|
+
var fromYear = fromDate.getFullYear();
|
|
290
|
+
var toYear = toDate.getFullYear();
|
|
291
|
+
for (var year = fromYear; year <= toYear; year++) {
|
|
292
|
+
years.push(setYear(startOfYear(/* @__PURE__ */ new Date()), year));
|
|
293
|
+
}
|
|
294
|
+
var handleChange = function(e) {
|
|
295
|
+
var newMonth = setYear(startOfMonth(displayMonth), Number(e.target.value));
|
|
296
|
+
props.onChange(newMonth);
|
|
297
|
+
};
|
|
298
|
+
var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
|
|
299
|
+
return jsx(DropdownComponent, { name: "years", "aria-label": labelYearDropdown2(), className: classNames2.dropdown_year, style: styles2.dropdown_year, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption2(displayMonth, { locale }), children: years.map(function(year2) {
|
|
300
|
+
return jsx("option", { value: year2.getFullYear(), children: formatYearCaption2(year2, { locale }) }, year2.getFullYear());
|
|
236
301
|
}) });
|
|
237
302
|
}
|
|
238
|
-
function
|
|
239
|
-
var
|
|
240
|
-
|
|
303
|
+
function useControlledValue(defaultValue, controlledValue) {
|
|
304
|
+
var _a = useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
|
|
305
|
+
var value = controlledValue === void 0 ? uncontrolledValue : controlledValue;
|
|
306
|
+
return [value, setValue];
|
|
307
|
+
}
|
|
308
|
+
function getInitialMonth(context) {
|
|
309
|
+
var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
|
|
310
|
+
var initialMonth = month || defaultMonth || today || /* @__PURE__ */ new Date();
|
|
311
|
+
var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
312
|
+
if (toDate && differenceInCalendarMonths(toDate, initialMonth) < 0) {
|
|
313
|
+
var offset = -1 * (numberOfMonths - 1);
|
|
314
|
+
initialMonth = addMonths(toDate, offset);
|
|
315
|
+
}
|
|
316
|
+
if (fromDate && differenceInCalendarMonths(initialMonth, fromDate) < 0) {
|
|
317
|
+
initialMonth = fromDate;
|
|
318
|
+
}
|
|
319
|
+
return startOfMonth(initialMonth);
|
|
320
|
+
}
|
|
321
|
+
function useNavigationState() {
|
|
322
|
+
var context = useDayPicker();
|
|
323
|
+
var initialMonth = getInitialMonth(context);
|
|
324
|
+
var _a = useControlledValue(initialMonth, context.month), month = _a[0], setMonth2 = _a[1];
|
|
325
|
+
var goToMonth = function(date) {
|
|
326
|
+
var _a2;
|
|
327
|
+
if (context.disableNavigation)
|
|
328
|
+
return;
|
|
329
|
+
var month2 = startOfMonth(date);
|
|
330
|
+
setMonth2(month2);
|
|
331
|
+
(_a2 = context.onMonthChange) === null || _a2 === void 0 ? void 0 : _a2.call(context, month2);
|
|
332
|
+
};
|
|
333
|
+
return [month, goToMonth];
|
|
334
|
+
}
|
|
335
|
+
function getDisplayMonths(month, _a) {
|
|
336
|
+
var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
|
|
337
|
+
var start = startOfMonth(month);
|
|
338
|
+
var end = startOfMonth(addMonths(start, numberOfMonths));
|
|
339
|
+
var monthsDiff = differenceInCalendarMonths(end, start);
|
|
340
|
+
var months = [];
|
|
341
|
+
for (var i = 0; i < monthsDiff; i++) {
|
|
342
|
+
var nextMonth = addMonths(start, i);
|
|
343
|
+
months.push(nextMonth);
|
|
344
|
+
}
|
|
345
|
+
if (reverseMonths)
|
|
346
|
+
months = months.reverse();
|
|
347
|
+
return months;
|
|
241
348
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
349
|
+
function getNextMonth(startingMonth, options) {
|
|
350
|
+
if (options.disableNavigation) {
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
353
|
+
var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
354
|
+
var offset = pagedNavigation ? numberOfMonths : 1;
|
|
355
|
+
var month = startOfMonth(startingMonth);
|
|
356
|
+
if (!toDate) {
|
|
357
|
+
return addMonths(month, offset);
|
|
247
358
|
}
|
|
248
|
-
|
|
359
|
+
var monthsDiff = differenceInCalendarMonths(toDate, startingMonth);
|
|
360
|
+
if (monthsDiff < numberOfMonths) {
|
|
361
|
+
return void 0;
|
|
362
|
+
}
|
|
363
|
+
return addMonths(month, offset);
|
|
249
364
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
365
|
+
function getPreviousMonth(startingMonth, options) {
|
|
366
|
+
if (options.disableNavigation) {
|
|
367
|
+
return void 0;
|
|
368
|
+
}
|
|
369
|
+
var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
370
|
+
var offset = pagedNavigation ? numberOfMonths : 1;
|
|
371
|
+
var month = startOfMonth(startingMonth);
|
|
372
|
+
if (!fromDate) {
|
|
373
|
+
return addMonths(month, -offset);
|
|
374
|
+
}
|
|
375
|
+
var monthsDiff = differenceInCalendarMonths(month, fromDate);
|
|
376
|
+
if (monthsDiff <= 0) {
|
|
377
|
+
return void 0;
|
|
378
|
+
}
|
|
379
|
+
return addMonths(month, -offset);
|
|
380
|
+
}
|
|
381
|
+
var NavigationContext = createContext(void 0);
|
|
382
|
+
function NavigationProvider(props) {
|
|
383
|
+
var dayPicker = useDayPicker();
|
|
384
|
+
var _a = useNavigationState(), currentMonth = _a[0], goToMonth = _a[1];
|
|
385
|
+
var displayMonths = getDisplayMonths(currentMonth, dayPicker);
|
|
386
|
+
var nextMonth = getNextMonth(currentMonth, dayPicker);
|
|
387
|
+
var previousMonth = getPreviousMonth(currentMonth, dayPicker);
|
|
388
|
+
var isDateDisplayed = function(date) {
|
|
389
|
+
return displayMonths.some(function(displayMonth) {
|
|
390
|
+
return isSameMonth(date, displayMonth);
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
var goToDate = function(date, refDate) {
|
|
394
|
+
if (isDateDisplayed(date)) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (refDate && isBefore(date, refDate)) {
|
|
398
|
+
goToMonth(addMonths(date, 1 + dayPicker.numberOfMonths * -1));
|
|
399
|
+
} else {
|
|
400
|
+
goToMonth(date);
|
|
256
401
|
}
|
|
257
402
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
function Gn(e, t) {
|
|
268
|
-
if (!t.disableNavigation) {
|
|
269
|
-
var n = t.toDate, r = t.pagedNavigation, a = t.numberOfMonths, o = a === void 0 ? 1 : a, i = r ? o : 1, l = S(e);
|
|
270
|
-
if (!n)
|
|
271
|
-
return j(l, i);
|
|
272
|
-
var d = le(n, e);
|
|
273
|
-
if (!(d < o))
|
|
274
|
-
return j(l, i);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function $n(e, t) {
|
|
278
|
-
if (!t.disableNavigation) {
|
|
279
|
-
var n = t.fromDate, r = t.pagedNavigation, a = t.numberOfMonths, o = a === void 0 ? 1 : a, i = r ? o : 1, l = S(e);
|
|
280
|
-
if (!n)
|
|
281
|
-
return j(l, -i);
|
|
282
|
-
var d = le(l, n);
|
|
283
|
-
if (!(d <= 0))
|
|
284
|
-
return j(l, -i);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
var Nt = ne(void 0);
|
|
288
|
-
function qn(e) {
|
|
289
|
-
var t = k(), n = Xn(), r = n[0], a = n[1], o = Zn(r, t), i = Gn(r, t), l = $n(r, t), d = function(f) {
|
|
290
|
-
return o.some(function(v) {
|
|
291
|
-
return Ae(f, v);
|
|
292
|
-
});
|
|
293
|
-
}, u = function(f, v) {
|
|
294
|
-
d(f) || (v && He(f, v) ? a(j(f, 1 + t.numberOfMonths * -1)) : a(f));
|
|
295
|
-
}, c = {
|
|
296
|
-
currentMonth: r,
|
|
297
|
-
displayMonths: o,
|
|
298
|
-
goToMonth: a,
|
|
299
|
-
goToDate: u,
|
|
300
|
-
previousMonth: l,
|
|
301
|
-
nextMonth: i,
|
|
302
|
-
isDateDisplayed: d
|
|
403
|
+
var value = {
|
|
404
|
+
currentMonth,
|
|
405
|
+
displayMonths,
|
|
406
|
+
goToMonth,
|
|
407
|
+
goToDate,
|
|
408
|
+
previousMonth,
|
|
409
|
+
nextMonth,
|
|
410
|
+
isDateDisplayed
|
|
303
411
|
};
|
|
304
|
-
return
|
|
412
|
+
return jsx(NavigationContext.Provider, { value, children: props.children });
|
|
305
413
|
}
|
|
306
|
-
function
|
|
307
|
-
var
|
|
308
|
-
if (!
|
|
414
|
+
function useNavigation() {
|
|
415
|
+
var context = useContext(NavigationContext);
|
|
416
|
+
if (!context) {
|
|
309
417
|
throw new Error("useNavigation must be used within a NavigationProvider");
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
418
|
+
}
|
|
419
|
+
return context;
|
|
420
|
+
}
|
|
421
|
+
function CaptionDropdowns(props) {
|
|
422
|
+
var _a;
|
|
423
|
+
var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
|
|
424
|
+
var goToMonth = useNavigation().goToMonth;
|
|
425
|
+
var handleMonthChange = function(newMonth) {
|
|
426
|
+
goToMonth(addMonths(newMonth, props.displayIndex ? -props.displayIndex : 0));
|
|
427
|
+
};
|
|
428
|
+
var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
|
|
429
|
+
var captionLabel = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
|
|
430
|
+
return jsxs("div", { className: classNames2.caption_dropdowns, style: styles2.caption_dropdowns, children: [jsx("div", { className: classNames2.vhidden, children: captionLabel }), jsx(MonthsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth }), jsx(YearsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth })] });
|
|
317
431
|
}
|
|
318
|
-
function
|
|
319
|
-
return
|
|
432
|
+
function IconLeft(props) {
|
|
433
|
+
return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" }) }));
|
|
320
434
|
}
|
|
321
|
-
function
|
|
322
|
-
return
|
|
435
|
+
function IconRight(props) {
|
|
436
|
+
return jsx("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { children: jsx("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" }) }));
|
|
323
437
|
}
|
|
324
|
-
var
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
438
|
+
var Button = forwardRef(function(props, ref) {
|
|
439
|
+
var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
|
|
440
|
+
var classNamesArr = [classNames2.button_reset, classNames2.button];
|
|
441
|
+
if (props.className) {
|
|
442
|
+
classNamesArr.push(props.className);
|
|
443
|
+
}
|
|
444
|
+
var className = classNamesArr.join(" ");
|
|
445
|
+
var style = __assign(__assign({}, styles2.button_reset), styles2.button);
|
|
446
|
+
if (props.style) {
|
|
447
|
+
Object.assign(style, props.style);
|
|
448
|
+
}
|
|
449
|
+
return jsx("button", __assign({}, props, { ref, type: "button", className, style }));
|
|
329
450
|
});
|
|
330
|
-
function
|
|
331
|
-
var
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
].join(" ")
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
},
|
|
349
|
-
|
|
451
|
+
function Navigation(props) {
|
|
452
|
+
var _a, _b;
|
|
453
|
+
var _c = useDayPicker(), dir = _c.dir, locale = _c.locale, classNames2 = _c.classNames, styles2 = _c.styles, _d = _c.labels, labelPrevious2 = _d.labelPrevious, labelNext2 = _d.labelNext, components = _c.components;
|
|
454
|
+
if (!props.nextMonth && !props.previousMonth) {
|
|
455
|
+
return jsx(Fragment, {});
|
|
456
|
+
}
|
|
457
|
+
var previousLabel = labelPrevious2(props.previousMonth, { locale });
|
|
458
|
+
var previousClassName = [
|
|
459
|
+
classNames2.nav_button,
|
|
460
|
+
classNames2.nav_button_previous
|
|
461
|
+
].join(" ");
|
|
462
|
+
var nextLabel = labelNext2(props.nextMonth, { locale });
|
|
463
|
+
var nextClassName = [
|
|
464
|
+
classNames2.nav_button,
|
|
465
|
+
classNames2.nav_button_next
|
|
466
|
+
].join(" ");
|
|
467
|
+
var IconRightComponent = (_a = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _a !== void 0 ? _a : IconRight;
|
|
468
|
+
var IconLeftComponent = (_b = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _b !== void 0 ? _b : IconLeft;
|
|
469
|
+
return jsxs("div", { className: classNames2.nav, style: styles2.nav, children: [!props.hidePrevious && jsx(Button, { name: "previous-month", "aria-label": previousLabel, className: previousClassName, style: styles2.nav_button_previous, disabled: !props.previousMonth, onClick: props.onPreviousClick, children: dir === "rtl" ? jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) }), !props.hideNext && jsx(Button, { name: "next-month", "aria-label": nextLabel, className: nextClassName, style: styles2.nav_button_next, disabled: !props.nextMonth, onClick: props.onNextClick, children: dir === "rtl" ? jsx(IconLeftComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) : jsx(IconRightComponent, { className: classNames2.nav_icon, style: styles2.nav_icon }) })] });
|
|
470
|
+
}
|
|
471
|
+
function CaptionNavigation(props) {
|
|
472
|
+
var numberOfMonths = useDayPicker().numberOfMonths;
|
|
473
|
+
var _a = useNavigation(), previousMonth = _a.previousMonth, nextMonth = _a.nextMonth, goToMonth = _a.goToMonth, displayMonths = _a.displayMonths;
|
|
474
|
+
var displayIndex = displayMonths.findIndex(function(month) {
|
|
475
|
+
return isSameMonth(props.displayMonth, month);
|
|
476
|
+
});
|
|
477
|
+
var isFirst = displayIndex === 0;
|
|
478
|
+
var isLast = displayIndex === displayMonths.length - 1;
|
|
479
|
+
var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
|
|
480
|
+
var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
|
|
481
|
+
var handlePreviousClick = function() {
|
|
482
|
+
if (!previousMonth)
|
|
483
|
+
return;
|
|
484
|
+
goToMonth(previousMonth);
|
|
350
485
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
486
|
+
var handleNextClick = function() {
|
|
487
|
+
if (!nextMonth)
|
|
488
|
+
return;
|
|
489
|
+
goToMonth(nextMonth);
|
|
490
|
+
};
|
|
491
|
+
return jsx(Navigation, { displayMonth: props.displayMonth, hideNext, hidePrevious, nextMonth, previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick });
|
|
492
|
+
}
|
|
493
|
+
function Caption(props) {
|
|
494
|
+
var _a;
|
|
495
|
+
var _b = useDayPicker(), classNames2 = _b.classNames, disableNavigation = _b.disableNavigation, styles2 = _b.styles, captionLayout = _b.captionLayout, components = _b.components;
|
|
496
|
+
var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
|
|
497
|
+
var caption;
|
|
498
|
+
if (disableNavigation) {
|
|
499
|
+
caption = jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth });
|
|
500
|
+
} else if (captionLayout === "dropdown") {
|
|
501
|
+
caption = jsx(CaptionDropdowns, { displayMonth: props.displayMonth, id: props.id });
|
|
502
|
+
} else if (captionLayout === "dropdown-buttons") {
|
|
503
|
+
caption = jsxs(Fragment, { children: [jsx(CaptionDropdowns, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id })] });
|
|
504
|
+
} else {
|
|
505
|
+
caption = jsxs(Fragment, { children: [jsx(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id })] });
|
|
365
506
|
}
|
|
366
|
-
return
|
|
507
|
+
return jsx("div", { className: classNames2.caption, style: styles2.caption, children: caption });
|
|
508
|
+
}
|
|
509
|
+
function Footer(props) {
|
|
510
|
+
var _a = useDayPicker(), footer = _a.footer, styles2 = _a.styles, tfoot = _a.classNames.tfoot;
|
|
511
|
+
if (!footer)
|
|
512
|
+
return jsx(Fragment, {});
|
|
513
|
+
return jsx("tfoot", { className: tfoot, style: styles2.tfoot, children: jsx("tr", { children: jsx("td", { colSpan: 8, children: footer }) }) });
|
|
514
|
+
}
|
|
515
|
+
function getWeekdays(locale, weekStartsOn, ISOWeek) {
|
|
516
|
+
var start = ISOWeek ? startOfISOWeek(/* @__PURE__ */ new Date()) : startOfWeek(/* @__PURE__ */ new Date(), { locale, weekStartsOn });
|
|
517
|
+
var days = [];
|
|
518
|
+
for (var i = 0; i < 7; i++) {
|
|
519
|
+
var day = addDays(start, i);
|
|
520
|
+
days.push(day);
|
|
521
|
+
}
|
|
522
|
+
return days;
|
|
367
523
|
}
|
|
368
|
-
function
|
|
369
|
-
var
|
|
370
|
-
|
|
371
|
-
|
|
524
|
+
function HeadRow() {
|
|
525
|
+
var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, weekStartsOn = _a.weekStartsOn, ISOWeek = _a.ISOWeek, formatWeekdayName2 = _a.formatters.formatWeekdayName, labelWeekday2 = _a.labels.labelWeekday;
|
|
526
|
+
var weekdays = getWeekdays(locale, weekStartsOn, ISOWeek);
|
|
527
|
+
return jsxs("tr", { style: styles2.head_row, className: classNames2.head_row, children: [showWeekNumber && jsx("td", { style: styles2.head_cell, className: classNames2.head_cell }), weekdays.map(function(weekday, i) {
|
|
528
|
+
return jsx("th", { scope: "col", className: classNames2.head_cell, style: styles2.head_cell, "aria-label": labelWeekday2(weekday, { locale }), children: formatWeekdayName2(weekday, { locale }) }, i);
|
|
372
529
|
})] });
|
|
373
530
|
}
|
|
374
|
-
function
|
|
375
|
-
var
|
|
376
|
-
|
|
531
|
+
function Head() {
|
|
532
|
+
var _a;
|
|
533
|
+
var _b = useDayPicker(), classNames2 = _b.classNames, styles2 = _b.styles, components = _b.components;
|
|
534
|
+
var HeadRowComponent = (_a = components === null || components === void 0 ? void 0 : components.HeadRow) !== null && _a !== void 0 ? _a : HeadRow;
|
|
535
|
+
return jsx("thead", { style: styles2.head, className: classNames2.head, children: jsx(HeadRowComponent, {}) });
|
|
377
536
|
}
|
|
378
|
-
function
|
|
379
|
-
var
|
|
380
|
-
return
|
|
537
|
+
function DayContent(props) {
|
|
538
|
+
var _a = useDayPicker(), locale = _a.locale, formatDay2 = _a.formatters.formatDay;
|
|
539
|
+
return jsx(Fragment, { children: formatDay2(props.date, { locale }) });
|
|
381
540
|
}
|
|
382
|
-
var
|
|
383
|
-
function
|
|
384
|
-
if (!
|
|
385
|
-
var
|
|
541
|
+
var SelectMultipleContext = createContext(void 0);
|
|
542
|
+
function SelectMultipleProvider(props) {
|
|
543
|
+
if (!isDayPickerMultiple(props.initialProps)) {
|
|
544
|
+
var emptyContextValue = {
|
|
386
545
|
selected: void 0,
|
|
387
546
|
modifiers: {
|
|
388
547
|
disabled: []
|
|
389
548
|
}
|
|
390
549
|
};
|
|
391
|
-
return
|
|
392
|
-
}
|
|
393
|
-
return
|
|
394
|
-
}
|
|
395
|
-
function
|
|
396
|
-
var
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
var
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (c.selected) {
|
|
405
|
-
var D = p.findIndex(function(M) {
|
|
406
|
-
return N(u, M);
|
|
407
|
-
});
|
|
408
|
-
p.splice(D, 1);
|
|
409
|
-
} else
|
|
410
|
-
p.push(u);
|
|
411
|
-
(m = t.onSelect) === null || m === void 0 || m.call(t, p, u, c, f);
|
|
412
|
-
}
|
|
550
|
+
return jsx(SelectMultipleContext.Provider, { value: emptyContextValue, children: props.children });
|
|
551
|
+
}
|
|
552
|
+
return jsx(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children });
|
|
553
|
+
}
|
|
554
|
+
function SelectMultipleProviderInternal(_a) {
|
|
555
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
556
|
+
var selected = initialProps.selected, min2 = initialProps.min, max2 = initialProps.max;
|
|
557
|
+
var onDayClick = function(day, activeModifiers, e) {
|
|
558
|
+
var _a2, _b;
|
|
559
|
+
(_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
|
|
560
|
+
var isMinSelected = Boolean(activeModifiers.selected && min2 && (selected === null || selected === void 0 ? void 0 : selected.length) === min2);
|
|
561
|
+
if (isMinSelected) {
|
|
562
|
+
return;
|
|
413
563
|
}
|
|
414
|
-
|
|
564
|
+
var isMaxSelected = Boolean(!activeModifiers.selected && max2 && (selected === null || selected === void 0 ? void 0 : selected.length) === max2);
|
|
565
|
+
if (isMaxSelected) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
var selectedDays = selected ? __spreadArray([], selected) : [];
|
|
569
|
+
if (activeModifiers.selected) {
|
|
570
|
+
var index = selectedDays.findIndex(function(selectedDay) {
|
|
571
|
+
return isSameDay(day, selectedDay);
|
|
572
|
+
});
|
|
573
|
+
selectedDays.splice(index, 1);
|
|
574
|
+
} else {
|
|
575
|
+
selectedDays.push(day);
|
|
576
|
+
}
|
|
577
|
+
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, selectedDays, day, activeModifiers, e);
|
|
578
|
+
};
|
|
579
|
+
var modifiers = {
|
|
415
580
|
disabled: []
|
|
416
581
|
};
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
582
|
+
if (selected) {
|
|
583
|
+
modifiers.disabled.push(function(day) {
|
|
584
|
+
var isMaxSelected = max2 && selected.length > max2 - 1;
|
|
585
|
+
var isSelected = selected.some(function(selectedDay) {
|
|
586
|
+
return isSameDay(selectedDay, day);
|
|
587
|
+
});
|
|
588
|
+
return Boolean(isMaxSelected && !isSelected);
|
|
420
589
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
modifiers: l
|
|
590
|
+
}
|
|
591
|
+
var contextValue = {
|
|
592
|
+
selected,
|
|
593
|
+
onDayClick,
|
|
594
|
+
modifiers
|
|
427
595
|
};
|
|
428
|
-
return
|
|
596
|
+
return jsx(SelectMultipleContext.Provider, { value: contextValue, children });
|
|
429
597
|
}
|
|
430
|
-
function
|
|
431
|
-
var
|
|
432
|
-
if (!
|
|
598
|
+
function useSelectMultiple() {
|
|
599
|
+
var context = useContext(SelectMultipleContext);
|
|
600
|
+
if (!context) {
|
|
433
601
|
throw new Error("useSelectMultiple must be used within a SelectMultipleProvider");
|
|
434
|
-
|
|
602
|
+
}
|
|
603
|
+
return context;
|
|
435
604
|
}
|
|
436
|
-
function
|
|
437
|
-
var
|
|
438
|
-
|
|
605
|
+
function addToRange(day, range) {
|
|
606
|
+
var _a = range || {}, from = _a.from, to = _a.to;
|
|
607
|
+
if (from && to) {
|
|
608
|
+
if (isSameDay(to, day) && isSameDay(from, day)) {
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
if (isSameDay(to, day)) {
|
|
612
|
+
return { from: to, to: void 0 };
|
|
613
|
+
}
|
|
614
|
+
if (isSameDay(from, day)) {
|
|
615
|
+
return void 0;
|
|
616
|
+
}
|
|
617
|
+
if (isAfter(from, day)) {
|
|
618
|
+
return { from: day, to };
|
|
619
|
+
}
|
|
620
|
+
return { from, to: day };
|
|
621
|
+
}
|
|
622
|
+
if (to) {
|
|
623
|
+
if (isAfter(day, to)) {
|
|
624
|
+
return { from: to, to: day };
|
|
625
|
+
}
|
|
626
|
+
return { from: day, to };
|
|
627
|
+
}
|
|
628
|
+
if (from) {
|
|
629
|
+
if (isBefore(day, from)) {
|
|
630
|
+
return { from: day, to: from };
|
|
631
|
+
}
|
|
632
|
+
return { from, to: day };
|
|
633
|
+
}
|
|
634
|
+
return { from: day, to: void 0 };
|
|
439
635
|
}
|
|
440
|
-
var
|
|
441
|
-
function
|
|
442
|
-
if (!
|
|
443
|
-
var
|
|
636
|
+
var SelectRangeContext = createContext(void 0);
|
|
637
|
+
function SelectRangeProvider(props) {
|
|
638
|
+
if (!isDayPickerRange(props.initialProps)) {
|
|
639
|
+
var emptyContextValue = {
|
|
444
640
|
selected: void 0,
|
|
445
641
|
modifiers: {
|
|
446
642
|
range_start: [],
|
|
@@ -449,866 +645,1439 @@ function dr(e) {
|
|
|
449
645
|
disabled: []
|
|
450
646
|
}
|
|
451
647
|
};
|
|
452
|
-
return
|
|
648
|
+
return jsx(SelectRangeContext.Provider, { value: emptyContextValue, children: props.children });
|
|
453
649
|
}
|
|
454
|
-
return
|
|
455
|
-
}
|
|
456
|
-
function
|
|
457
|
-
var
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
650
|
+
return jsx(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children });
|
|
651
|
+
}
|
|
652
|
+
function SelectRangeProviderInternal(_a) {
|
|
653
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
654
|
+
var selected = initialProps.selected;
|
|
655
|
+
var _b = selected || {}, selectedFrom = _b.from, selectedTo = _b.to;
|
|
656
|
+
var min2 = initialProps.min;
|
|
657
|
+
var max2 = initialProps.max;
|
|
658
|
+
var onDayClick = function(day, activeModifiers, e) {
|
|
659
|
+
var _a2, _b2;
|
|
660
|
+
(_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
|
|
661
|
+
var newRange = addToRange(day, selected);
|
|
662
|
+
(_b2 = initialProps.onSelect) === null || _b2 === void 0 ? void 0 : _b2.call(initialProps, newRange, day, activeModifiers, e);
|
|
663
|
+
};
|
|
664
|
+
var modifiers = {
|
|
463
665
|
range_start: [],
|
|
464
666
|
range_end: [],
|
|
465
667
|
range_middle: [],
|
|
466
668
|
disabled: []
|
|
467
669
|
};
|
|
468
|
-
if (
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
670
|
+
if (selectedFrom) {
|
|
671
|
+
modifiers.range_start = [selectedFrom];
|
|
672
|
+
if (!selectedTo) {
|
|
673
|
+
modifiers.range_end = [selectedFrom];
|
|
674
|
+
} else {
|
|
675
|
+
modifiers.range_end = [selectedTo];
|
|
676
|
+
if (!isSameDay(selectedFrom, selectedTo)) {
|
|
677
|
+
modifiers.range_middle = [
|
|
678
|
+
{
|
|
679
|
+
after: selectedFrom,
|
|
680
|
+
before: selectedTo
|
|
681
|
+
}
|
|
682
|
+
];
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
} else if (selectedTo) {
|
|
686
|
+
modifiers.range_start = [selectedTo];
|
|
687
|
+
modifiers.range_end = [selectedTo];
|
|
688
|
+
}
|
|
689
|
+
if (min2) {
|
|
690
|
+
if (selectedFrom && !selectedTo) {
|
|
691
|
+
modifiers.disabled.push({
|
|
692
|
+
after: subDays(selectedFrom, min2 - 1),
|
|
693
|
+
before: addDays(selectedFrom, min2 - 1)
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
if (selectedFrom && selectedTo) {
|
|
697
|
+
modifiers.disabled.push({
|
|
698
|
+
after: selectedFrom,
|
|
699
|
+
before: addDays(selectedFrom, min2 - 1)
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
if (!selectedFrom && selectedTo) {
|
|
703
|
+
modifiers.disabled.push({
|
|
704
|
+
after: subDays(selectedTo, min2 - 1),
|
|
705
|
+
before: addDays(selectedTo, min2 - 1)
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (max2) {
|
|
710
|
+
if (selectedFrom && !selectedTo) {
|
|
711
|
+
modifiers.disabled.push({
|
|
712
|
+
before: addDays(selectedFrom, -max2 + 1)
|
|
713
|
+
});
|
|
714
|
+
modifiers.disabled.push({
|
|
715
|
+
after: addDays(selectedFrom, max2 - 1)
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
if (selectedFrom && selectedTo) {
|
|
719
|
+
var selectedCount = differenceInCalendarDays(selectedTo, selectedFrom) + 1;
|
|
720
|
+
var offset = max2 - selectedCount;
|
|
721
|
+
modifiers.disabled.push({
|
|
722
|
+
before: subDays(selectedFrom, offset)
|
|
723
|
+
});
|
|
724
|
+
modifiers.disabled.push({
|
|
725
|
+
after: addDays(selectedTo, offset)
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
if (!selectedFrom && selectedTo) {
|
|
729
|
+
modifiers.disabled.push({
|
|
730
|
+
before: addDays(selectedTo, -max2 + 1)
|
|
731
|
+
});
|
|
732
|
+
modifiers.disabled.push({
|
|
733
|
+
after: addDays(selectedTo, max2 - 1)
|
|
493
734
|
});
|
|
494
735
|
}
|
|
495
|
-
!o && i && (c.disabled.push({
|
|
496
|
-
before: W(i, -d + 1)
|
|
497
|
-
}), c.disabled.push({
|
|
498
|
-
after: W(i, d - 1)
|
|
499
|
-
}));
|
|
500
736
|
}
|
|
501
|
-
return
|
|
737
|
+
return jsx(SelectRangeContext.Provider, { value: { selected, onDayClick, modifiers }, children });
|
|
502
738
|
}
|
|
503
|
-
function
|
|
504
|
-
var
|
|
505
|
-
if (!
|
|
739
|
+
function useSelectRange() {
|
|
740
|
+
var context = useContext(SelectRangeContext);
|
|
741
|
+
if (!context) {
|
|
506
742
|
throw new Error("useSelectRange must be used within a SelectRangeProvider");
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
743
|
+
}
|
|
744
|
+
return context;
|
|
745
|
+
}
|
|
746
|
+
function matcherToArray(matcher) {
|
|
747
|
+
if (Array.isArray(matcher)) {
|
|
748
|
+
return __spreadArray([], matcher);
|
|
749
|
+
} else if (matcher !== void 0) {
|
|
750
|
+
return [matcher];
|
|
751
|
+
} else {
|
|
752
|
+
return [];
|
|
753
|
+
}
|
|
511
754
|
}
|
|
512
|
-
function
|
|
513
|
-
var
|
|
514
|
-
|
|
515
|
-
var
|
|
516
|
-
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
var
|
|
535
|
-
if (
|
|
755
|
+
function getCustomModifiers(dayModifiers) {
|
|
756
|
+
var customModifiers = {};
|
|
757
|
+
Object.entries(dayModifiers).forEach(function(_a) {
|
|
758
|
+
var modifier = _a[0], matcher = _a[1];
|
|
759
|
+
customModifiers[modifier] = matcherToArray(matcher);
|
|
760
|
+
});
|
|
761
|
+
return customModifiers;
|
|
762
|
+
}
|
|
763
|
+
var InternalModifier;
|
|
764
|
+
(function(InternalModifier2) {
|
|
765
|
+
InternalModifier2["Outside"] = "outside";
|
|
766
|
+
InternalModifier2["Disabled"] = "disabled";
|
|
767
|
+
InternalModifier2["Selected"] = "selected";
|
|
768
|
+
InternalModifier2["Hidden"] = "hidden";
|
|
769
|
+
InternalModifier2["Today"] = "today";
|
|
770
|
+
InternalModifier2["RangeStart"] = "range_start";
|
|
771
|
+
InternalModifier2["RangeEnd"] = "range_end";
|
|
772
|
+
InternalModifier2["RangeMiddle"] = "range_middle";
|
|
773
|
+
})(InternalModifier || (InternalModifier = {}));
|
|
774
|
+
var Selected = InternalModifier.Selected, Disabled = InternalModifier.Disabled, Hidden = InternalModifier.Hidden, Today = InternalModifier.Today, RangeEnd = InternalModifier.RangeEnd, RangeMiddle = InternalModifier.RangeMiddle, RangeStart = InternalModifier.RangeStart, Outside = InternalModifier.Outside;
|
|
775
|
+
function getInternalModifiers(dayPicker, selectMultiple, selectRange) {
|
|
776
|
+
var _a;
|
|
777
|
+
var internalModifiers = (_a = {}, _a[Selected] = matcherToArray(dayPicker.selected), _a[Disabled] = matcherToArray(dayPicker.disabled), _a[Hidden] = matcherToArray(dayPicker.hidden), _a[Today] = [dayPicker.today], _a[RangeEnd] = [], _a[RangeMiddle] = [], _a[RangeStart] = [], _a[Outside] = [], _a);
|
|
778
|
+
if (dayPicker.fromDate) {
|
|
779
|
+
internalModifiers[Disabled].push({ before: dayPicker.fromDate });
|
|
780
|
+
}
|
|
781
|
+
if (dayPicker.toDate) {
|
|
782
|
+
internalModifiers[Disabled].push({ after: dayPicker.toDate });
|
|
783
|
+
}
|
|
784
|
+
if (isDayPickerMultiple(dayPicker)) {
|
|
785
|
+
internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectMultiple.modifiers[Disabled]);
|
|
786
|
+
} else if (isDayPickerRange(dayPicker)) {
|
|
787
|
+
internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectRange.modifiers[Disabled]);
|
|
788
|
+
internalModifiers[RangeStart] = selectRange.modifiers[RangeStart];
|
|
789
|
+
internalModifiers[RangeMiddle] = selectRange.modifiers[RangeMiddle];
|
|
790
|
+
internalModifiers[RangeEnd] = selectRange.modifiers[RangeEnd];
|
|
791
|
+
}
|
|
792
|
+
return internalModifiers;
|
|
793
|
+
}
|
|
794
|
+
var ModifiersContext = createContext(void 0);
|
|
795
|
+
function ModifiersProvider(props) {
|
|
796
|
+
var dayPicker = useDayPicker();
|
|
797
|
+
var selectMultiple = useSelectMultiple();
|
|
798
|
+
var selectRange = useSelectRange();
|
|
799
|
+
var internalModifiers = getInternalModifiers(dayPicker, selectMultiple, selectRange);
|
|
800
|
+
var customModifiers = getCustomModifiers(dayPicker.modifiers);
|
|
801
|
+
var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
|
|
802
|
+
return jsx(ModifiersContext.Provider, { value: modifiers, children: props.children });
|
|
803
|
+
}
|
|
804
|
+
function useModifiers() {
|
|
805
|
+
var context = useContext(ModifiersContext);
|
|
806
|
+
if (!context) {
|
|
536
807
|
throw new Error("useModifiers must be used within a ModifiersProvider");
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
var
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
808
|
+
}
|
|
809
|
+
return context;
|
|
810
|
+
}
|
|
811
|
+
function isDateInterval(matcher) {
|
|
812
|
+
return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
|
|
813
|
+
}
|
|
814
|
+
function isDateRange(value) {
|
|
815
|
+
return Boolean(value && typeof value === "object" && "from" in value);
|
|
816
|
+
}
|
|
817
|
+
function isDateAfterType(value) {
|
|
818
|
+
return Boolean(value && typeof value === "object" && "after" in value);
|
|
819
|
+
}
|
|
820
|
+
function isDateBeforeType(value) {
|
|
821
|
+
return Boolean(value && typeof value === "object" && "before" in value);
|
|
822
|
+
}
|
|
823
|
+
function isDayOfWeekType(value) {
|
|
824
|
+
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
|
825
|
+
}
|
|
826
|
+
function isDateInRange(date, range) {
|
|
827
|
+
var _a;
|
|
828
|
+
var from = range.from, to = range.to;
|
|
829
|
+
if (from && to) {
|
|
830
|
+
var isRangeInverted = differenceInCalendarDays(to, from) < 0;
|
|
831
|
+
if (isRangeInverted) {
|
|
832
|
+
_a = [to, from], from = _a[0], to = _a[1];
|
|
833
|
+
}
|
|
834
|
+
var isInRange = differenceInCalendarDays(date, from) >= 0 && differenceInCalendarDays(to, date) >= 0;
|
|
835
|
+
return isInRange;
|
|
836
|
+
}
|
|
837
|
+
if (to) {
|
|
838
|
+
return isSameDay(to, date);
|
|
839
|
+
}
|
|
840
|
+
if (from) {
|
|
841
|
+
return isSameDay(from, date);
|
|
842
|
+
}
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
function isDateType(value) {
|
|
846
|
+
return isDate(value);
|
|
847
|
+
}
|
|
848
|
+
function isArrayOfDates(value) {
|
|
849
|
+
return Array.isArray(value) && value.every(isDate);
|
|
850
|
+
}
|
|
851
|
+
function isMatch(day, matchers) {
|
|
852
|
+
return matchers.some(function(matcher) {
|
|
853
|
+
if (typeof matcher === "boolean") {
|
|
854
|
+
return matcher;
|
|
855
|
+
}
|
|
856
|
+
if (isDateType(matcher)) {
|
|
857
|
+
return isSameDay(day, matcher);
|
|
858
|
+
}
|
|
859
|
+
if (isArrayOfDates(matcher)) {
|
|
860
|
+
return matcher.includes(day);
|
|
861
|
+
}
|
|
862
|
+
if (isDateRange(matcher)) {
|
|
863
|
+
return isDateInRange(day, matcher);
|
|
864
|
+
}
|
|
865
|
+
if (isDayOfWeekType(matcher)) {
|
|
866
|
+
return matcher.dayOfWeek.includes(day.getDay());
|
|
867
|
+
}
|
|
868
|
+
if (isDateInterval(matcher)) {
|
|
869
|
+
var diffBefore = differenceInCalendarDays(matcher.before, day);
|
|
870
|
+
var diffAfter = differenceInCalendarDays(matcher.after, day);
|
|
871
|
+
var isDayBefore = diffBefore > 0;
|
|
872
|
+
var isDayAfter = diffAfter < 0;
|
|
873
|
+
var isClosedInterval = isAfter(matcher.before, matcher.after);
|
|
874
|
+
if (isClosedInterval) {
|
|
875
|
+
return isDayAfter && isDayBefore;
|
|
876
|
+
} else {
|
|
877
|
+
return isDayBefore || isDayAfter;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (isDateAfterType(matcher)) {
|
|
881
|
+
return differenceInCalendarDays(day, matcher.after) > 0;
|
|
882
|
+
}
|
|
883
|
+
if (isDateBeforeType(matcher)) {
|
|
884
|
+
return differenceInCalendarDays(matcher.before, day) > 0;
|
|
885
|
+
}
|
|
886
|
+
if (typeof matcher === "function") {
|
|
887
|
+
return matcher(day);
|
|
888
|
+
}
|
|
889
|
+
return false;
|
|
587
890
|
});
|
|
588
891
|
}
|
|
589
|
-
function
|
|
590
|
-
var
|
|
591
|
-
var
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
return r.forEach(function(o) {
|
|
595
|
-
return a[o] = !0;
|
|
596
|
-
}), n && !Ae(e, n) && (a.outside = !0), a;
|
|
597
|
-
}
|
|
598
|
-
function Pr(e, t) {
|
|
599
|
-
for (var n = S(e[0]), r = Fe(e[e.length - 1]), a, o, i = n; i <= r; ) {
|
|
600
|
-
var l = Ze(i, t), d = !l.disabled && !l.hidden;
|
|
601
|
-
if (!d) {
|
|
602
|
-
i = W(i, 1);
|
|
603
|
-
continue;
|
|
892
|
+
function getActiveModifiers(day, modifiers, displayMonth) {
|
|
893
|
+
var matchedModifiers = Object.keys(modifiers).reduce(function(result, key) {
|
|
894
|
+
var modifier = modifiers[key];
|
|
895
|
+
if (isMatch(day, modifier)) {
|
|
896
|
+
result.push(key);
|
|
604
897
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
var xr = 365;
|
|
612
|
-
function xt(e, t) {
|
|
613
|
-
var n = t.moveBy, r = t.direction, a = t.context, o = t.modifiers, i = t.retry, l = i === void 0 ? { count: 0, lastFocused: e } : i, d = a.weekStartsOn, u = a.fromDate, c = a.toDate, f = a.locale, v = {
|
|
614
|
-
day: W,
|
|
615
|
-
week: Ee,
|
|
616
|
-
month: j,
|
|
617
|
-
year: tn,
|
|
618
|
-
startOfWeek: function(p) {
|
|
619
|
-
return a.ISOWeek ? Ye(p) : je(p, { locale: f, weekStartsOn: d });
|
|
620
|
-
},
|
|
621
|
-
endOfWeek: function(p) {
|
|
622
|
-
return a.ISOWeek ? ht(p) : pt(p, { locale: f, weekStartsOn: d });
|
|
623
|
-
}
|
|
624
|
-
}, m = v[n](e, r === "after" ? 1 : -1);
|
|
625
|
-
r === "before" && u ? m = Jt([u, m]) : r === "after" && c && (m = Qt([c, m]));
|
|
626
|
-
var y = !0;
|
|
627
|
-
if (o) {
|
|
628
|
-
var _ = Ze(m, o);
|
|
629
|
-
y = !_.disabled && !_.hidden;
|
|
630
|
-
}
|
|
631
|
-
return y ? m : l.count > xr ? l.lastFocused : xt(m, {
|
|
632
|
-
moveBy: n,
|
|
633
|
-
direction: r,
|
|
634
|
-
context: a,
|
|
635
|
-
modifiers: o,
|
|
636
|
-
retry: g(g({}, l), { count: l.count + 1 })
|
|
898
|
+
return result;
|
|
899
|
+
}, []);
|
|
900
|
+
var activeModifiers = {};
|
|
901
|
+
matchedModifiers.forEach(function(modifier) {
|
|
902
|
+
return activeModifiers[modifier] = true;
|
|
637
903
|
});
|
|
904
|
+
if (displayMonth && !isSameMonth(day, displayMonth)) {
|
|
905
|
+
activeModifiers.outside = true;
|
|
906
|
+
}
|
|
907
|
+
return activeModifiers;
|
|
908
|
+
}
|
|
909
|
+
function getInitialFocusTarget(displayMonths, modifiers) {
|
|
910
|
+
var firstDayInMonth = startOfMonth(displayMonths[0]);
|
|
911
|
+
var lastDayInMonth = endOfMonth(displayMonths[displayMonths.length - 1]);
|
|
912
|
+
var firstFocusableDay;
|
|
913
|
+
var today;
|
|
914
|
+
var date = firstDayInMonth;
|
|
915
|
+
while (date <= lastDayInMonth) {
|
|
916
|
+
var activeModifiers = getActiveModifiers(date, modifiers);
|
|
917
|
+
var isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
|
|
918
|
+
if (!isFocusable) {
|
|
919
|
+
date = addDays(date, 1);
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (activeModifiers.selected) {
|
|
923
|
+
return date;
|
|
924
|
+
}
|
|
925
|
+
if (activeModifiers.today && !today) {
|
|
926
|
+
today = date;
|
|
927
|
+
}
|
|
928
|
+
if (!firstFocusableDay) {
|
|
929
|
+
firstFocusableDay = date;
|
|
930
|
+
}
|
|
931
|
+
date = addDays(date, 1);
|
|
932
|
+
}
|
|
933
|
+
if (today) {
|
|
934
|
+
return today;
|
|
935
|
+
} else {
|
|
936
|
+
return firstFocusableDay;
|
|
937
|
+
}
|
|
638
938
|
}
|
|
639
|
-
var
|
|
640
|
-
function
|
|
641
|
-
var
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
});
|
|
653
|
-
N(a, M) || (t.goToDate(M, a), v(M));
|
|
939
|
+
var MAX_RETRY = 365;
|
|
940
|
+
function getNextFocus(focusedDay, options) {
|
|
941
|
+
var moveBy = options.moveBy, direction = options.direction, context = options.context, modifiers = options.modifiers, _a = options.retry, retry = _a === void 0 ? { count: 0, lastFocused: focusedDay } : _a;
|
|
942
|
+
var weekStartsOn = context.weekStartsOn, fromDate = context.fromDate, toDate = context.toDate, locale = context.locale;
|
|
943
|
+
var moveFns = {
|
|
944
|
+
day: addDays,
|
|
945
|
+
week: addWeeks,
|
|
946
|
+
month: addMonths,
|
|
947
|
+
year: addYears,
|
|
948
|
+
startOfWeek: function(date) {
|
|
949
|
+
return context.ISOWeek ? startOfISOWeek(date) : startOfWeek(date, { locale, weekStartsOn });
|
|
950
|
+
},
|
|
951
|
+
endOfWeek: function(date) {
|
|
952
|
+
return context.ISOWeek ? endOfISOWeek(date) : endOfWeek(date, { locale, weekStartsOn });
|
|
654
953
|
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
954
|
+
};
|
|
955
|
+
var newFocusedDay = moveFns[moveBy](focusedDay, direction === "after" ? 1 : -1);
|
|
956
|
+
if (direction === "before" && fromDate) {
|
|
957
|
+
newFocusedDay = max([fromDate, newFocusedDay]);
|
|
958
|
+
} else if (direction === "after" && toDate) {
|
|
959
|
+
newFocusedDay = min([toDate, newFocusedDay]);
|
|
960
|
+
}
|
|
961
|
+
var isFocusable = true;
|
|
962
|
+
if (modifiers) {
|
|
963
|
+
var activeModifiers = getActiveModifiers(newFocusedDay, modifiers);
|
|
964
|
+
isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
|
|
965
|
+
}
|
|
966
|
+
if (isFocusable) {
|
|
967
|
+
return newFocusedDay;
|
|
968
|
+
} else {
|
|
969
|
+
if (retry.count > MAX_RETRY) {
|
|
970
|
+
return retry.lastFocused;
|
|
971
|
+
}
|
|
972
|
+
return getNextFocus(newFocusedDay, {
|
|
973
|
+
moveBy,
|
|
974
|
+
direction,
|
|
975
|
+
context,
|
|
976
|
+
modifiers,
|
|
977
|
+
retry: __assign(__assign({}, retry), { count: retry.count + 1 })
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
var FocusContext = createContext(void 0);
|
|
982
|
+
function FocusProvider(props) {
|
|
983
|
+
var navigation = useNavigation();
|
|
984
|
+
var modifiers = useModifiers();
|
|
985
|
+
var _a = useState(), focusedDay = _a[0], setFocusedDay = _a[1];
|
|
986
|
+
var _b = useState(), lastFocused = _b[0], setLastFocused = _b[1];
|
|
987
|
+
var initialFocusTarget = getInitialFocusTarget(navigation.displayMonths, modifiers);
|
|
988
|
+
var focusTarget = (focusedDay !== null && focusedDay !== void 0 ? focusedDay : lastFocused && navigation.isDateDisplayed(lastFocused)) ? lastFocused : initialFocusTarget;
|
|
989
|
+
var blur = function() {
|
|
990
|
+
setLastFocused(focusedDay);
|
|
991
|
+
setFocusedDay(void 0);
|
|
992
|
+
};
|
|
993
|
+
var focus = function(date) {
|
|
994
|
+
setFocusedDay(date);
|
|
995
|
+
};
|
|
996
|
+
var context = useDayPicker();
|
|
997
|
+
var moveFocus = function(moveBy, direction) {
|
|
998
|
+
if (!focusedDay)
|
|
999
|
+
return;
|
|
1000
|
+
var nextFocused = getNextFocus(focusedDay, {
|
|
1001
|
+
moveBy,
|
|
1002
|
+
direction,
|
|
1003
|
+
context,
|
|
1004
|
+
modifiers
|
|
1005
|
+
});
|
|
1006
|
+
if (isSameDay(focusedDay, nextFocused))
|
|
1007
|
+
return void 0;
|
|
1008
|
+
navigation.goToDate(nextFocused, focusedDay);
|
|
1009
|
+
focus(nextFocused);
|
|
1010
|
+
};
|
|
1011
|
+
var value = {
|
|
1012
|
+
focusedDay,
|
|
1013
|
+
focusTarget,
|
|
1014
|
+
blur,
|
|
1015
|
+
focus,
|
|
660
1016
|
focusDayAfter: function() {
|
|
661
|
-
return
|
|
1017
|
+
return moveFocus("day", "after");
|
|
662
1018
|
},
|
|
663
1019
|
focusDayBefore: function() {
|
|
664
|
-
return
|
|
1020
|
+
return moveFocus("day", "before");
|
|
665
1021
|
},
|
|
666
1022
|
focusWeekAfter: function() {
|
|
667
|
-
return
|
|
1023
|
+
return moveFocus("week", "after");
|
|
668
1024
|
},
|
|
669
1025
|
focusWeekBefore: function() {
|
|
670
|
-
return
|
|
1026
|
+
return moveFocus("week", "before");
|
|
671
1027
|
},
|
|
672
1028
|
focusMonthBefore: function() {
|
|
673
|
-
return
|
|
1029
|
+
return moveFocus("month", "before");
|
|
674
1030
|
},
|
|
675
1031
|
focusMonthAfter: function() {
|
|
676
|
-
return
|
|
1032
|
+
return moveFocus("month", "after");
|
|
677
1033
|
},
|
|
678
1034
|
focusYearBefore: function() {
|
|
679
|
-
return
|
|
1035
|
+
return moveFocus("year", "before");
|
|
680
1036
|
},
|
|
681
1037
|
focusYearAfter: function() {
|
|
682
|
-
return
|
|
1038
|
+
return moveFocus("year", "after");
|
|
683
1039
|
},
|
|
684
1040
|
focusStartOfWeek: function() {
|
|
685
|
-
return
|
|
1041
|
+
return moveFocus("startOfWeek", "before");
|
|
686
1042
|
},
|
|
687
1043
|
focusEndOfWeek: function() {
|
|
688
|
-
return
|
|
1044
|
+
return moveFocus("endOfWeek", "after");
|
|
689
1045
|
}
|
|
690
1046
|
};
|
|
691
|
-
return
|
|
1047
|
+
return jsx(FocusContext.Provider, { value, children: props.children });
|
|
692
1048
|
}
|
|
693
|
-
function
|
|
694
|
-
var
|
|
695
|
-
if (!
|
|
1049
|
+
function useFocusContext() {
|
|
1050
|
+
var context = useContext(FocusContext);
|
|
1051
|
+
if (!context) {
|
|
696
1052
|
throw new Error("useFocusContext must be used within a FocusProvider");
|
|
697
|
-
|
|
1053
|
+
}
|
|
1054
|
+
return context;
|
|
698
1055
|
}
|
|
699
|
-
function
|
|
700
|
-
var
|
|
701
|
-
|
|
1056
|
+
function useActiveModifiers(day, displayMonth) {
|
|
1057
|
+
var modifiers = useModifiers();
|
|
1058
|
+
var activeModifiers = getActiveModifiers(day, modifiers, displayMonth);
|
|
1059
|
+
return activeModifiers;
|
|
702
1060
|
}
|
|
703
|
-
var
|
|
704
|
-
function
|
|
705
|
-
if (!
|
|
706
|
-
var
|
|
1061
|
+
var SelectSingleContext = createContext(void 0);
|
|
1062
|
+
function SelectSingleProvider(props) {
|
|
1063
|
+
if (!isDayPickerSingle(props.initialProps)) {
|
|
1064
|
+
var emptyContextValue = {
|
|
707
1065
|
selected: void 0
|
|
708
1066
|
};
|
|
709
|
-
return
|
|
1067
|
+
return jsx(SelectSingleContext.Provider, { value: emptyContextValue, children: props.children });
|
|
710
1068
|
}
|
|
711
|
-
return
|
|
712
|
-
}
|
|
713
|
-
function
|
|
714
|
-
var
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
1069
|
+
return jsx(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children });
|
|
1070
|
+
}
|
|
1071
|
+
function SelectSingleProviderInternal(_a) {
|
|
1072
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
1073
|
+
var onDayClick = function(day, activeModifiers, e) {
|
|
1074
|
+
var _a2, _b, _c;
|
|
1075
|
+
(_a2 = initialProps.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(initialProps, day, activeModifiers, e);
|
|
1076
|
+
if (activeModifiers.selected && !initialProps.required) {
|
|
1077
|
+
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, void 0, day, activeModifiers, e);
|
|
718
1078
|
return;
|
|
719
1079
|
}
|
|
720
|
-
(
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
|
|
1080
|
+
(_c = initialProps.onSelect) === null || _c === void 0 ? void 0 : _c.call(initialProps, day, day, activeModifiers, e);
|
|
1081
|
+
};
|
|
1082
|
+
var contextValue = {
|
|
1083
|
+
selected: initialProps.selected,
|
|
1084
|
+
onDayClick
|
|
724
1085
|
};
|
|
725
|
-
return
|
|
1086
|
+
return jsx(SelectSingleContext.Provider, { value: contextValue, children });
|
|
726
1087
|
}
|
|
727
|
-
function
|
|
728
|
-
var
|
|
729
|
-
if (!
|
|
1088
|
+
function useSelectSingle() {
|
|
1089
|
+
var context = useContext(SelectSingleContext);
|
|
1090
|
+
if (!context) {
|
|
730
1091
|
throw new Error("useSelectSingle must be used within a SelectSingleProvider");
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
var
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
var
|
|
754
|
-
(
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
(
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
var
|
|
772
|
-
|
|
1092
|
+
}
|
|
1093
|
+
return context;
|
|
1094
|
+
}
|
|
1095
|
+
function useDayEventHandlers(date, activeModifiers) {
|
|
1096
|
+
var dayPicker = useDayPicker();
|
|
1097
|
+
var single = useSelectSingle();
|
|
1098
|
+
var multiple = useSelectMultiple();
|
|
1099
|
+
var range = useSelectRange();
|
|
1100
|
+
var _a = useFocusContext(), focusDayAfter = _a.focusDayAfter, focusDayBefore = _a.focusDayBefore, focusWeekAfter = _a.focusWeekAfter, focusWeekBefore = _a.focusWeekBefore, blur = _a.blur, focus = _a.focus, focusMonthBefore = _a.focusMonthBefore, focusMonthAfter = _a.focusMonthAfter, focusYearBefore = _a.focusYearBefore, focusYearAfter = _a.focusYearAfter, focusStartOfWeek = _a.focusStartOfWeek, focusEndOfWeek = _a.focusEndOfWeek;
|
|
1101
|
+
var onClick = function(e) {
|
|
1102
|
+
var _a2, _b, _c, _d;
|
|
1103
|
+
if (isDayPickerSingle(dayPicker)) {
|
|
1104
|
+
(_a2 = single.onDayClick) === null || _a2 === void 0 ? void 0 : _a2.call(single, date, activeModifiers, e);
|
|
1105
|
+
} else if (isDayPickerMultiple(dayPicker)) {
|
|
1106
|
+
(_b = multiple.onDayClick) === null || _b === void 0 ? void 0 : _b.call(multiple, date, activeModifiers, e);
|
|
1107
|
+
} else if (isDayPickerRange(dayPicker)) {
|
|
1108
|
+
(_c = range.onDayClick) === null || _c === void 0 ? void 0 : _c.call(range, date, activeModifiers, e);
|
|
1109
|
+
} else {
|
|
1110
|
+
(_d = dayPicker.onDayClick) === null || _d === void 0 ? void 0 : _d.call(dayPicker, date, activeModifiers, e);
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
var onFocus = function(e) {
|
|
1114
|
+
var _a2;
|
|
1115
|
+
focus(date);
|
|
1116
|
+
(_a2 = dayPicker.onDayFocus) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1117
|
+
};
|
|
1118
|
+
var onBlur = function(e) {
|
|
1119
|
+
var _a2;
|
|
1120
|
+
blur();
|
|
1121
|
+
(_a2 = dayPicker.onDayBlur) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1122
|
+
};
|
|
1123
|
+
var onMouseEnter = function(e) {
|
|
1124
|
+
var _a2;
|
|
1125
|
+
(_a2 = dayPicker.onDayMouseEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1126
|
+
};
|
|
1127
|
+
var onMouseLeave = function(e) {
|
|
1128
|
+
var _a2;
|
|
1129
|
+
(_a2 = dayPicker.onDayMouseLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1130
|
+
};
|
|
1131
|
+
var onPointerEnter = function(e) {
|
|
1132
|
+
var _a2;
|
|
1133
|
+
(_a2 = dayPicker.onDayPointerEnter) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1134
|
+
};
|
|
1135
|
+
var onPointerLeave = function(e) {
|
|
1136
|
+
var _a2;
|
|
1137
|
+
(_a2 = dayPicker.onDayPointerLeave) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1138
|
+
};
|
|
1139
|
+
var onTouchCancel = function(e) {
|
|
1140
|
+
var _a2;
|
|
1141
|
+
(_a2 = dayPicker.onDayTouchCancel) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1142
|
+
};
|
|
1143
|
+
var onTouchEnd = function(e) {
|
|
1144
|
+
var _a2;
|
|
1145
|
+
(_a2 = dayPicker.onDayTouchEnd) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1146
|
+
};
|
|
1147
|
+
var onTouchMove = function(e) {
|
|
1148
|
+
var _a2;
|
|
1149
|
+
(_a2 = dayPicker.onDayTouchMove) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1150
|
+
};
|
|
1151
|
+
var onTouchStart = function(e) {
|
|
1152
|
+
var _a2;
|
|
1153
|
+
(_a2 = dayPicker.onDayTouchStart) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1154
|
+
};
|
|
1155
|
+
var onKeyUp = function(e) {
|
|
1156
|
+
var _a2;
|
|
1157
|
+
(_a2 = dayPicker.onDayKeyUp) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1158
|
+
};
|
|
1159
|
+
var onKeyDown = function(e) {
|
|
1160
|
+
var _a2;
|
|
1161
|
+
switch (e.key) {
|
|
773
1162
|
case "ArrowLeft":
|
|
774
|
-
|
|
1163
|
+
e.preventDefault();
|
|
1164
|
+
e.stopPropagation();
|
|
1165
|
+
dayPicker.dir === "rtl" ? focusDayAfter() : focusDayBefore();
|
|
775
1166
|
break;
|
|
776
1167
|
case "ArrowRight":
|
|
777
|
-
|
|
1168
|
+
e.preventDefault();
|
|
1169
|
+
e.stopPropagation();
|
|
1170
|
+
dayPicker.dir === "rtl" ? focusDayBefore() : focusDayAfter();
|
|
778
1171
|
break;
|
|
779
1172
|
case "ArrowDown":
|
|
780
|
-
|
|
1173
|
+
e.preventDefault();
|
|
1174
|
+
e.stopPropagation();
|
|
1175
|
+
focusWeekAfter();
|
|
781
1176
|
break;
|
|
782
1177
|
case "ArrowUp":
|
|
783
|
-
|
|
1178
|
+
e.preventDefault();
|
|
1179
|
+
e.stopPropagation();
|
|
1180
|
+
focusWeekBefore();
|
|
784
1181
|
break;
|
|
785
1182
|
case "PageUp":
|
|
786
|
-
|
|
1183
|
+
e.preventDefault();
|
|
1184
|
+
e.stopPropagation();
|
|
1185
|
+
e.shiftKey ? focusYearBefore() : focusMonthBefore();
|
|
787
1186
|
break;
|
|
788
1187
|
case "PageDown":
|
|
789
|
-
|
|
1188
|
+
e.preventDefault();
|
|
1189
|
+
e.stopPropagation();
|
|
1190
|
+
e.shiftKey ? focusYearAfter() : focusMonthAfter();
|
|
790
1191
|
break;
|
|
791
1192
|
case "Home":
|
|
792
|
-
|
|
1193
|
+
e.preventDefault();
|
|
1194
|
+
e.stopPropagation();
|
|
1195
|
+
focusStartOfWeek();
|
|
793
1196
|
break;
|
|
794
1197
|
case "End":
|
|
795
|
-
|
|
1198
|
+
e.preventDefault();
|
|
1199
|
+
e.stopPropagation();
|
|
1200
|
+
focusEndOfWeek();
|
|
796
1201
|
break;
|
|
797
1202
|
}
|
|
798
|
-
(
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
1203
|
+
(_a2 = dayPicker.onDayKeyDown) === null || _a2 === void 0 ? void 0 : _a2.call(dayPicker, date, activeModifiers, e);
|
|
1204
|
+
};
|
|
1205
|
+
var eventHandlers = {
|
|
1206
|
+
onClick,
|
|
1207
|
+
onFocus,
|
|
1208
|
+
onBlur,
|
|
1209
|
+
onKeyDown,
|
|
1210
|
+
onKeyUp,
|
|
1211
|
+
onMouseEnter,
|
|
1212
|
+
onMouseLeave,
|
|
1213
|
+
onPointerEnter,
|
|
1214
|
+
onPointerLeave,
|
|
1215
|
+
onTouchCancel,
|
|
1216
|
+
onTouchEnd,
|
|
1217
|
+
onTouchMove,
|
|
1218
|
+
onTouchStart
|
|
813
1219
|
};
|
|
814
|
-
return
|
|
815
|
-
}
|
|
816
|
-
function
|
|
817
|
-
var
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
return Object.
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
function
|
|
843
|
-
var
|
|
844
|
-
|
|
845
|
-
var
|
|
846
|
-
|
|
1220
|
+
return eventHandlers;
|
|
1221
|
+
}
|
|
1222
|
+
function useSelectedDays() {
|
|
1223
|
+
var dayPicker = useDayPicker();
|
|
1224
|
+
var single = useSelectSingle();
|
|
1225
|
+
var multiple = useSelectMultiple();
|
|
1226
|
+
var range = useSelectRange();
|
|
1227
|
+
var selectedDays = isDayPickerSingle(dayPicker) ? single.selected : isDayPickerMultiple(dayPicker) ? multiple.selected : isDayPickerRange(dayPicker) ? range.selected : void 0;
|
|
1228
|
+
return selectedDays;
|
|
1229
|
+
}
|
|
1230
|
+
function isInternalModifier(modifier) {
|
|
1231
|
+
return Object.values(InternalModifier).includes(modifier);
|
|
1232
|
+
}
|
|
1233
|
+
function getDayClassNames(dayPicker, activeModifiers) {
|
|
1234
|
+
var classNames2 = [dayPicker.classNames.day];
|
|
1235
|
+
Object.keys(activeModifiers).forEach(function(modifier) {
|
|
1236
|
+
var customClassName = dayPicker.modifiersClassNames[modifier];
|
|
1237
|
+
if (customClassName) {
|
|
1238
|
+
classNames2.push(customClassName);
|
|
1239
|
+
} else if (isInternalModifier(modifier)) {
|
|
1240
|
+
var internalClassName = dayPicker.classNames["day_".concat(modifier)];
|
|
1241
|
+
if (internalClassName) {
|
|
1242
|
+
classNames2.push(internalClassName);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
return classNames2;
|
|
1247
|
+
}
|
|
1248
|
+
function getDayStyle(dayPicker, activeModifiers) {
|
|
1249
|
+
var style = __assign({}, dayPicker.styles.day);
|
|
1250
|
+
Object.keys(activeModifiers).forEach(function(modifier) {
|
|
1251
|
+
var _a;
|
|
1252
|
+
style = __assign(__assign({}, style), (_a = dayPicker.modifiersStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
|
|
1253
|
+
});
|
|
1254
|
+
return style;
|
|
1255
|
+
}
|
|
1256
|
+
function useDayRender(day, displayMonth, buttonRef) {
|
|
1257
|
+
var _a;
|
|
1258
|
+
var _b, _c;
|
|
1259
|
+
var dayPicker = useDayPicker();
|
|
1260
|
+
var focusContext = useFocusContext();
|
|
1261
|
+
var activeModifiers = useActiveModifiers(day, displayMonth);
|
|
1262
|
+
var eventHandlers = useDayEventHandlers(day, activeModifiers);
|
|
1263
|
+
var selectedDays = useSelectedDays();
|
|
1264
|
+
var isButton = Boolean(dayPicker.onDayClick || dayPicker.mode !== "default");
|
|
1265
|
+
useEffect(function() {
|
|
1266
|
+
var _a2;
|
|
1267
|
+
if (activeModifiers.outside)
|
|
1268
|
+
return;
|
|
1269
|
+
if (!focusContext.focusedDay)
|
|
1270
|
+
return;
|
|
1271
|
+
if (!isButton)
|
|
1272
|
+
return;
|
|
1273
|
+
if (isSameDay(focusContext.focusedDay, day)) {
|
|
1274
|
+
(_a2 = buttonRef.current) === null || _a2 === void 0 ? void 0 : _a2.focus();
|
|
1275
|
+
}
|
|
847
1276
|
}, [
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1277
|
+
focusContext.focusedDay,
|
|
1278
|
+
day,
|
|
1279
|
+
buttonRef,
|
|
1280
|
+
isButton,
|
|
1281
|
+
activeModifiers.outside
|
|
853
1282
|
]);
|
|
854
|
-
var
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1283
|
+
var className = getDayClassNames(dayPicker, activeModifiers).join(" ");
|
|
1284
|
+
var style = getDayStyle(dayPicker, activeModifiers);
|
|
1285
|
+
var isHidden = Boolean(activeModifiers.outside && !dayPicker.showOutsideDays || activeModifiers.hidden);
|
|
1286
|
+
var DayContentComponent = (_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent;
|
|
1287
|
+
var children = jsx(DayContentComponent, { date: day, displayMonth, activeModifiers });
|
|
1288
|
+
var divProps = {
|
|
1289
|
+
style,
|
|
1290
|
+
className,
|
|
1291
|
+
children,
|
|
858
1292
|
role: "gridcell"
|
|
859
|
-
}, M = l.focusTarget && N(l.focusTarget, e) && !d.outside, I = l.focusedDay && N(l.focusedDay, e), E = g(g(g({}, D), (r = { disabled: d.disabled, role: "gridcell" }, r["aria-selected"] = d.selected, r.tabIndex = I || M ? 0 : -1, r)), u), X = {
|
|
860
|
-
isButton: f,
|
|
861
|
-
isHidden: y,
|
|
862
|
-
activeModifiers: d,
|
|
863
|
-
selectedDays: c,
|
|
864
|
-
buttonProps: E,
|
|
865
|
-
divProps: D
|
|
866
1293
|
};
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
var
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
var f = d(Number(t), { locale: l }), v = function(m) {
|
|
878
|
-
a(t, n, m);
|
|
1294
|
+
var isFocusTarget = focusContext.focusTarget && isSameDay(focusContext.focusTarget, day) && !activeModifiers.outside;
|
|
1295
|
+
var isFocused = focusContext.focusedDay && isSameDay(focusContext.focusedDay, day);
|
|
1296
|
+
var buttonProps = __assign(__assign(__assign({}, divProps), (_a = { disabled: activeModifiers.disabled, role: "gridcell" }, _a["aria-selected"] = activeModifiers.selected, _a.tabIndex = isFocused || isFocusTarget ? 0 : -1, _a)), eventHandlers);
|
|
1297
|
+
var dayRender = {
|
|
1298
|
+
isButton,
|
|
1299
|
+
isHidden,
|
|
1300
|
+
activeModifiers,
|
|
1301
|
+
selectedDays,
|
|
1302
|
+
buttonProps,
|
|
1303
|
+
divProps
|
|
879
1304
|
};
|
|
880
|
-
return
|
|
1305
|
+
return dayRender;
|
|
881
1306
|
}
|
|
882
|
-
function
|
|
883
|
-
var
|
|
884
|
-
|
|
885
|
-
|
|
1307
|
+
function Day(props) {
|
|
1308
|
+
var buttonRef = useRef(null);
|
|
1309
|
+
var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
|
|
1310
|
+
if (dayRender.isHidden) {
|
|
1311
|
+
return jsx("div", { role: "gridcell" });
|
|
1312
|
+
}
|
|
1313
|
+
if (!dayRender.isButton) {
|
|
1314
|
+
return jsx("div", __assign({}, dayRender.divProps));
|
|
1315
|
+
}
|
|
1316
|
+
return jsx(Button, __assign({ name: "day", ref: buttonRef }, dayRender.buttonProps));
|
|
1317
|
+
}
|
|
1318
|
+
function WeekNumber(props) {
|
|
1319
|
+
var weekNumber = props.number, dates = props.dates;
|
|
1320
|
+
var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles2 = _a.styles, classNames2 = _a.classNames, locale = _a.locale, labelWeekNumber2 = _a.labels.labelWeekNumber, formatWeekNumber2 = _a.formatters.formatWeekNumber;
|
|
1321
|
+
var content = formatWeekNumber2(Number(weekNumber), { locale });
|
|
1322
|
+
if (!onWeekNumberClick) {
|
|
1323
|
+
return jsx("span", { className: classNames2.weeknumber, style: styles2.weeknumber, children: content });
|
|
1324
|
+
}
|
|
1325
|
+
var label = labelWeekNumber2(Number(weekNumber), { locale });
|
|
1326
|
+
var handleClick = function(e) {
|
|
1327
|
+
onWeekNumberClick(weekNumber, dates, e);
|
|
1328
|
+
};
|
|
1329
|
+
return jsx(Button, { name: "week-number", "aria-label": label, className: classNames2.weeknumber, style: styles2.weeknumber, onClick: handleClick, children: content });
|
|
1330
|
+
}
|
|
1331
|
+
function Row(props) {
|
|
1332
|
+
var _a, _b;
|
|
1333
|
+
var _c = useDayPicker(), styles2 = _c.styles, classNames2 = _c.classNames, showWeekNumber = _c.showWeekNumber, components = _c.components;
|
|
1334
|
+
var DayComponent = (_a = components === null || components === void 0 ? void 0 : components.Day) !== null && _a !== void 0 ? _a : Day;
|
|
1335
|
+
var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
|
|
1336
|
+
var weekNumberCell;
|
|
1337
|
+
if (showWeekNumber) {
|
|
1338
|
+
weekNumberCell = jsx("td", { className: classNames2.cell, style: styles2.cell, children: jsx(WeeknumberComponent, { number: props.weekNumber, dates: props.dates }) });
|
|
1339
|
+
}
|
|
1340
|
+
return jsxs("tr", { className: classNames2.row, style: styles2.row, children: [weekNumberCell, props.dates.map(function(date) {
|
|
1341
|
+
return jsx("td", { className: classNames2.cell, style: styles2.cell, role: "presentation", children: jsx(DayComponent, { displayMonth: props.displayMonth, date }) }, getUnixTime(date));
|
|
886
1342
|
})] });
|
|
887
1343
|
}
|
|
888
|
-
function
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
var
|
|
892
|
-
|
|
893
|
-
|
|
1344
|
+
function daysToMonthWeeks(fromDate, toDate, options) {
|
|
1345
|
+
var toWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? endOfISOWeek(toDate) : endOfWeek(toDate, options);
|
|
1346
|
+
var fromWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? startOfISOWeek(fromDate) : startOfWeek(fromDate, options);
|
|
1347
|
+
var nOfDays = differenceInCalendarDays(toWeek, fromWeek);
|
|
1348
|
+
var days = [];
|
|
1349
|
+
for (var i = 0; i <= nOfDays; i++) {
|
|
1350
|
+
days.push(addDays(fromWeek, i));
|
|
1351
|
+
}
|
|
1352
|
+
var weeksInMonth = days.reduce(function(result, date) {
|
|
1353
|
+
var weekNumber = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? getISOWeek(date) : getWeek(date, options);
|
|
1354
|
+
var existingWeek = result.find(function(value) {
|
|
1355
|
+
return value.weekNumber === weekNumber;
|
|
1356
|
+
});
|
|
1357
|
+
if (existingWeek) {
|
|
1358
|
+
existingWeek.dates.push(date);
|
|
1359
|
+
return result;
|
|
1360
|
+
}
|
|
1361
|
+
result.push({
|
|
1362
|
+
weekNumber,
|
|
1363
|
+
dates: [date]
|
|
894
1364
|
});
|
|
895
|
-
return
|
|
896
|
-
weekNumber: f,
|
|
897
|
-
dates: [c]
|
|
898
|
-
}), u);
|
|
1365
|
+
return result;
|
|
899
1366
|
}, []);
|
|
900
|
-
return
|
|
901
|
-
}
|
|
902
|
-
function
|
|
903
|
-
var
|
|
904
|
-
if (
|
|
905
|
-
var
|
|
906
|
-
if (
|
|
907
|
-
var
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
var
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
var
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
function
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1367
|
+
return weeksInMonth;
|
|
1368
|
+
}
|
|
1369
|
+
function getMonthWeeks(month, options) {
|
|
1370
|
+
var weeksInMonth = daysToMonthWeeks(startOfMonth(month), endOfMonth(month), options);
|
|
1371
|
+
if (options === null || options === void 0 ? void 0 : options.useFixedWeeks) {
|
|
1372
|
+
var nrOfMonthWeeks = getWeeksInMonth(month, options);
|
|
1373
|
+
if (nrOfMonthWeeks < 6) {
|
|
1374
|
+
var lastWeek = weeksInMonth[weeksInMonth.length - 1];
|
|
1375
|
+
var lastDate = lastWeek.dates[lastWeek.dates.length - 1];
|
|
1376
|
+
var toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks);
|
|
1377
|
+
var extraWeeks = daysToMonthWeeks(addWeeks(lastDate, 1), toDate, options);
|
|
1378
|
+
weeksInMonth.push.apply(weeksInMonth, extraWeeks);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return weeksInMonth;
|
|
1382
|
+
}
|
|
1383
|
+
function Table(props) {
|
|
1384
|
+
var _a, _b, _c;
|
|
1385
|
+
var _d = useDayPicker(), locale = _d.locale, classNames2 = _d.classNames, styles2 = _d.styles, hideHead = _d.hideHead, fixedWeeks = _d.fixedWeeks, components = _d.components, weekStartsOn = _d.weekStartsOn, firstWeekContainsDate = _d.firstWeekContainsDate, ISOWeek = _d.ISOWeek;
|
|
1386
|
+
var weeks = getMonthWeeks(props.displayMonth, {
|
|
1387
|
+
useFixedWeeks: Boolean(fixedWeeks),
|
|
1388
|
+
ISOWeek,
|
|
1389
|
+
locale,
|
|
1390
|
+
weekStartsOn,
|
|
1391
|
+
firstWeekContainsDate
|
|
1392
|
+
});
|
|
1393
|
+
var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
|
|
1394
|
+
var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
|
|
1395
|
+
var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
|
|
1396
|
+
return jsxs("table", { id: props.id, className: classNames2.table, style: styles2.table, role: "grid", "aria-labelledby": props["aria-labelledby"], children: [!hideHead && jsx(HeadComponent, {}), jsx("tbody", { className: classNames2.tbody, style: styles2.tbody, children: weeks.map(function(week) {
|
|
1397
|
+
return jsx(RowComponent, { displayMonth: props.displayMonth, dates: week.dates, weekNumber: week.weekNumber }, week.weekNumber);
|
|
1398
|
+
}) }), jsx(FooterComponent, { displayMonth: props.displayMonth })] });
|
|
1399
|
+
}
|
|
1400
|
+
function canUseDOM() {
|
|
1401
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
1402
|
+
}
|
|
1403
|
+
var useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
|
|
1404
|
+
var serverHandoffComplete = false;
|
|
1405
|
+
var id = 0;
|
|
1406
|
+
function genId() {
|
|
1407
|
+
return "react-day-picker-".concat(++id);
|
|
1408
|
+
}
|
|
1409
|
+
function useId(providedId) {
|
|
1410
|
+
var _a;
|
|
1411
|
+
var initialId = providedId !== null && providedId !== void 0 ? providedId : serverHandoffComplete ? genId() : null;
|
|
1412
|
+
var _b = useState(initialId), id2 = _b[0], setId = _b[1];
|
|
1413
|
+
useIsomorphicLayoutEffect(function() {
|
|
1414
|
+
if (id2 === null) {
|
|
1415
|
+
setId(genId());
|
|
1416
|
+
}
|
|
1417
|
+
}, []);
|
|
1418
|
+
useEffect(function() {
|
|
1419
|
+
if (serverHandoffComplete === false) {
|
|
1420
|
+
serverHandoffComplete = true;
|
|
1421
|
+
}
|
|
1422
|
+
}, []);
|
|
1423
|
+
return (_a = providedId !== null && providedId !== void 0 ? providedId : id2) !== null && _a !== void 0 ? _a : void 0;
|
|
1424
|
+
}
|
|
1425
|
+
function Month(props) {
|
|
1426
|
+
var _a;
|
|
1427
|
+
var _b;
|
|
1428
|
+
var dayPicker = useDayPicker();
|
|
1429
|
+
var dir = dayPicker.dir, classNames2 = dayPicker.classNames, styles2 = dayPicker.styles, components = dayPicker.components;
|
|
1430
|
+
var displayMonths = useNavigation().displayMonths;
|
|
1431
|
+
var captionId = useId(dayPicker.id ? "".concat(dayPicker.id, "-").concat(props.displayIndex) : void 0);
|
|
1432
|
+
var tableId = dayPicker.id ? "".concat(dayPicker.id, "-grid-").concat(props.displayIndex) : void 0;
|
|
1433
|
+
var className = [classNames2.month];
|
|
1434
|
+
var style = styles2.month;
|
|
1435
|
+
var isStart = props.displayIndex === 0;
|
|
1436
|
+
var isEnd = props.displayIndex === displayMonths.length - 1;
|
|
1437
|
+
var isCenter = !isStart && !isEnd;
|
|
1438
|
+
if (dir === "rtl") {
|
|
1439
|
+
_a = [isStart, isEnd], isEnd = _a[0], isStart = _a[1];
|
|
1440
|
+
}
|
|
1441
|
+
if (isStart) {
|
|
1442
|
+
className.push(classNames2.caption_start);
|
|
1443
|
+
style = __assign(__assign({}, style), styles2.caption_start);
|
|
1444
|
+
}
|
|
1445
|
+
if (isEnd) {
|
|
1446
|
+
className.push(classNames2.caption_end);
|
|
1447
|
+
style = __assign(__assign({}, style), styles2.caption_end);
|
|
1448
|
+
}
|
|
1449
|
+
if (isCenter) {
|
|
1450
|
+
className.push(classNames2.caption_between);
|
|
1451
|
+
style = __assign(__assign({}, style), styles2.caption_between);
|
|
1452
|
+
}
|
|
1453
|
+
var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
|
|
1454
|
+
return jsxs("div", { className: className.join(" "), style, children: [jsx(CaptionComponent, { id: captionId, displayMonth: props.displayMonth, displayIndex: props.displayIndex }), jsx(Table, { id: tableId, "aria-labelledby": captionId, displayMonth: props.displayMonth })] }, props.displayIndex);
|
|
1455
|
+
}
|
|
1456
|
+
function Months(props) {
|
|
1457
|
+
var _a = useDayPicker(), classNames2 = _a.classNames, styles2 = _a.styles;
|
|
1458
|
+
return jsx("div", { className: classNames2.months, style: styles2.months, children: props.children });
|
|
1459
|
+
}
|
|
1460
|
+
function Root(_a) {
|
|
1461
|
+
var _b, _c;
|
|
1462
|
+
var initialProps = _a.initialProps;
|
|
1463
|
+
var dayPicker = useDayPicker();
|
|
1464
|
+
var focusContext = useFocusContext();
|
|
1465
|
+
var navigation = useNavigation();
|
|
1466
|
+
var _d = useState(false), hasInitialFocus = _d[0], setHasInitialFocus = _d[1];
|
|
1467
|
+
useEffect(function() {
|
|
1468
|
+
if (!dayPicker.initialFocus)
|
|
1469
|
+
return;
|
|
1470
|
+
if (!focusContext.focusTarget)
|
|
1471
|
+
return;
|
|
1472
|
+
if (hasInitialFocus)
|
|
1473
|
+
return;
|
|
1474
|
+
focusContext.focus(focusContext.focusTarget);
|
|
1475
|
+
setHasInitialFocus(true);
|
|
954
1476
|
}, [
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1477
|
+
dayPicker.initialFocus,
|
|
1478
|
+
hasInitialFocus,
|
|
1479
|
+
focusContext.focus,
|
|
1480
|
+
focusContext.focusTarget,
|
|
1481
|
+
focusContext
|
|
960
1482
|
]);
|
|
961
|
-
var
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
return
|
|
1483
|
+
var classNames2 = [dayPicker.classNames.root, dayPicker.className];
|
|
1484
|
+
if (dayPicker.numberOfMonths > 1) {
|
|
1485
|
+
classNames2.push(dayPicker.classNames.multiple_months);
|
|
1486
|
+
}
|
|
1487
|
+
if (dayPicker.showWeekNumber) {
|
|
1488
|
+
classNames2.push(dayPicker.classNames.with_weeknumber);
|
|
1489
|
+
}
|
|
1490
|
+
var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
|
|
1491
|
+
var dataAttributes = Object.keys(initialProps).filter(function(key) {
|
|
1492
|
+
return key.startsWith("data-");
|
|
1493
|
+
}).reduce(function(attrs, key) {
|
|
1494
|
+
var _a2;
|
|
1495
|
+
return __assign(__assign({}, attrs), (_a2 = {}, _a2[key] = initialProps[key], _a2));
|
|
1496
|
+
}, {});
|
|
1497
|
+
var MonthsComponent = (_c = (_b = initialProps.components) === null || _b === void 0 ? void 0 : _b.Months) !== null && _c !== void 0 ? _c : Months;
|
|
1498
|
+
return jsx("div", __assign({ className: classNames2.join(" "), style, dir: dayPicker.dir, id: dayPicker.id, nonce: initialProps.nonce, title: initialProps.title, lang: initialProps.lang }, dataAttributes, { children: jsx(MonthsComponent, { children: navigation.displayMonths.map(function(month, i) {
|
|
1499
|
+
return jsx(Month, { displayIndex: i, displayMonth: month }, i);
|
|
971
1500
|
}) }) }));
|
|
972
1501
|
}
|
|
973
|
-
function
|
|
974
|
-
var
|
|
975
|
-
return
|
|
976
|
-
}
|
|
977
|
-
function
|
|
978
|
-
return
|
|
979
|
-
}
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1502
|
+
function RootProvider(props) {
|
|
1503
|
+
var children = props.children, initialProps = __rest(props, ["children"]);
|
|
1504
|
+
return jsx(DayPickerProvider, { initialProps, children: jsx(NavigationProvider, { children: jsx(SelectSingleProvider, { initialProps, children: jsx(SelectMultipleProvider, { initialProps, children: jsx(SelectRangeProvider, { initialProps, children: jsx(ModifiersProvider, { children: jsx(FocusProvider, { children }) }) }) }) }) }) });
|
|
1505
|
+
}
|
|
1506
|
+
function DayPicker(props) {
|
|
1507
|
+
return jsx(RootProvider, __assign({}, props, { children: jsx(Root, { initialProps: props }) }));
|
|
1508
|
+
}
|
|
1509
|
+
const BUBBLE_WIDTH_PX = 329;
|
|
1510
|
+
const WINDOW_MARGIN_PX = 12;
|
|
1511
|
+
const BUBBLE_VERTICAL_OFFSET_PX = 26;
|
|
1512
|
+
const ARROW_WIDTH_PX = 20;
|
|
1513
|
+
const ARROW_VERTICAL_OFFSET_PX = 9;
|
|
1514
|
+
const ARROW_HORIZONTAL_MARGIN_PX = 12;
|
|
1515
|
+
const getVerticalPosition = (controllerSize, bubbleSize, variant) => {
|
|
1516
|
+
if (variant !== PopOverVariant.positionautomatic && variant !== void 0) {
|
|
1517
|
+
return variant;
|
|
1518
|
+
}
|
|
1519
|
+
if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {
|
|
1520
|
+
return PopOverVariant.positionabove;
|
|
1521
|
+
} else {
|
|
1522
|
+
return PopOverVariant.positionbelow;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
const getControllerLeftEdgePx = (controllerSize) => controllerSize.left + controllerSize.width / 4;
|
|
1526
|
+
const getControllerRightEdgePx = (controllerSize) => document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 4;
|
|
1527
|
+
const getBubbleRightPx = (controllerSize, bubbleSize) => {
|
|
1528
|
+
return controllerSize.left + bubbleSize.width;
|
|
1529
|
+
};
|
|
1530
|
+
const getBubbleLeftVisible = (controllerSize) => {
|
|
1531
|
+
return controllerSize.left > WINDOW_MARGIN_PX;
|
|
1532
|
+
};
|
|
1533
|
+
const getBubbleRightIsVisible = (controllerSize, bubbleSize) => {
|
|
1534
|
+
const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);
|
|
1535
|
+
return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;
|
|
1536
|
+
};
|
|
1537
|
+
const getHorizontalPosition = (controllerSize, bubbleSize) => {
|
|
1538
|
+
if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {
|
|
1539
|
+
return "right";
|
|
1540
|
+
}
|
|
1541
|
+
if (!getBubbleLeftVisible(controllerSize)) {
|
|
1542
|
+
return "left";
|
|
1543
|
+
}
|
|
1544
|
+
return "floating";
|
|
1545
|
+
};
|
|
1546
|
+
const getBubbleAbovePx = (controllerSize, bubbleSize) => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;
|
|
1547
|
+
const getBubbleBelowPx = (controllerSize) => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;
|
|
1548
|
+
const getBubbleWidth = () => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;
|
|
1549
|
+
const getBubbleFitsInWindow = () => {
|
|
1550
|
+
return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;
|
|
1551
|
+
};
|
|
1552
|
+
const getArrowTopxPx = (controllerSize) => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX + 5;
|
|
1553
|
+
const getArrowLeftPx = (controllerSize) => getControllerLeftEdgePx(controllerSize) - ARROW_WIDTH_PX / 2;
|
|
1554
|
+
const getArrowRightPx = (controllerSize) => getControllerRightEdgePx(controllerSize) - ARROW_WIDTH_PX / 2;
|
|
1555
|
+
const getBubblePosition = (controllerSize, bubbleSize, variant) => {
|
|
1556
|
+
const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);
|
|
1557
|
+
const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);
|
|
1558
|
+
if (horizontalPosition === "left") {
|
|
1559
|
+
if (verticalPosition === PopOverVariant.positionabove) {
|
|
1560
|
+
return "leftabove";
|
|
1561
|
+
}
|
|
1562
|
+
return "leftbelow";
|
|
1563
|
+
}
|
|
1564
|
+
if (horizontalPosition === "right") {
|
|
1565
|
+
if (verticalPosition === PopOverVariant.positionabove) {
|
|
1566
|
+
return "rightabove";
|
|
1567
|
+
}
|
|
1568
|
+
return "rightbelow";
|
|
1569
|
+
}
|
|
1570
|
+
if (verticalPosition === PopOverVariant.positionabove) {
|
|
1571
|
+
return "floatingabove";
|
|
1572
|
+
}
|
|
1573
|
+
return "floatingbelow";
|
|
1574
|
+
};
|
|
1575
|
+
const getBubbleStyle = (controllerSize, bubbleSize, variant) => {
|
|
1576
|
+
const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);
|
|
1577
|
+
const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : void 0;
|
|
1578
|
+
if (bubblePosition === "leftabove") {
|
|
1579
|
+
return {
|
|
1580
|
+
left: WINDOW_MARGIN_PX,
|
|
1581
|
+
top: getBubbleAbovePx(controllerSize, bubbleSize),
|
|
1582
|
+
width: bubbleWidth
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
if (bubblePosition === "leftbelow") {
|
|
1586
|
+
return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
|
|
1587
|
+
}
|
|
1588
|
+
if (bubblePosition === "rightabove") {
|
|
1589
|
+
return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };
|
|
1590
|
+
}
|
|
1591
|
+
if (bubblePosition === "rightbelow") {
|
|
1592
|
+
return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
|
|
1593
|
+
}
|
|
1594
|
+
if (bubblePosition === "floatingbelow") {
|
|
1595
|
+
return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };
|
|
1596
|
+
}
|
|
1597
|
+
return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };
|
|
1598
|
+
};
|
|
1599
|
+
const getBubbleLeftPx = (controllerSize, bubbleSize) => {
|
|
1600
|
+
const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);
|
|
1601
|
+
return controllerHorizontalCenterPx - bubbleSize.width / 2;
|
|
1602
|
+
};
|
|
1603
|
+
const getControllerLeftCenterPx = (controllerSize) => controllerSize.left + controllerSize.width / 2;
|
|
1604
|
+
const getArrowStyle = (bubbleStyle, controllerSize, verticalPosition) => {
|
|
1605
|
+
const leftPx = getArrowLeftPx(controllerSize);
|
|
1606
|
+
const rightPx = getArrowRightPx(controllerSize);
|
|
1607
|
+
const minLeftPx = bubbleStyle.left + ARROW_HORIZONTAL_MARGIN_PX;
|
|
1608
|
+
const minRightPx = bubbleStyle.right + ARROW_HORIZONTAL_MARGIN_PX;
|
|
1609
|
+
if (bubbleStyle.right) {
|
|
1610
|
+
if (verticalPosition === PopOverVariant.positionabove) {
|
|
1611
|
+
return {
|
|
1612
|
+
right: rightPx > minRightPx ? rightPx : minRightPx,
|
|
1613
|
+
top: getArrowTopxPx(controllerSize)
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
return {
|
|
1617
|
+
right: rightPx > minRightPx ? rightPx : minRightPx,
|
|
1618
|
+
top: controllerSize.bottom + ARROW_VERTICAL_OFFSET_PX
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
if (verticalPosition === PopOverVariant.positionabove) {
|
|
1622
|
+
return {
|
|
1623
|
+
left: leftPx > minLeftPx ? leftPx : minLeftPx,
|
|
1624
|
+
top: getArrowTopxPx(controllerSize)
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
return {
|
|
1628
|
+
left: leftPx > minLeftPx ? leftPx : minLeftPx,
|
|
1629
|
+
top: controllerSize.bottom + ARROW_VERTICAL_OFFSET_PX
|
|
1004
1630
|
};
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1631
|
+
};
|
|
1632
|
+
const DatePickerPopup = (props) => {
|
|
1633
|
+
const { datepickerWrapperRef, footer, inputRef, testId, variant, zIndex, ...rest } = props;
|
|
1634
|
+
const arrowRef = useRef(null);
|
|
1635
|
+
const [controllerSize, setControllerSize] = useState();
|
|
1636
|
+
const bubbleSize = useSize(datepickerWrapperRef);
|
|
1637
|
+
const controllerisVisible = useIsVisible(inputRef, 0);
|
|
1638
|
+
useFocusTrap(datepickerWrapperRef, true);
|
|
1639
|
+
const updateControllerSize = () => {
|
|
1640
|
+
var _a;
|
|
1641
|
+
setControllerSize((_a = inputRef.current) == null ? void 0 : _a.getBoundingClientRect());
|
|
1011
1642
|
};
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}, [])
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
[
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1643
|
+
React.useEffect(() => {
|
|
1644
|
+
updateControllerSize();
|
|
1645
|
+
}, []);
|
|
1646
|
+
useInterval(updateControllerSize, 500);
|
|
1647
|
+
useLayoutEvent(updateControllerSize, ["scroll", "resize"], 10);
|
|
1648
|
+
const datepickerPopupContainerClasses = classNames(styles["datepicker-popup-container"], {
|
|
1649
|
+
[styles["datepicker-popup-container--visible"]]: controllerisVisible
|
|
1650
|
+
});
|
|
1651
|
+
const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);
|
|
1652
|
+
const popupArrowClasses = classNames(styles["datepicker-popup-arrow"], {
|
|
1653
|
+
[styles["datepicker-popup-arrow--visible"]]: controllerisVisible,
|
|
1654
|
+
[styles["datepicker-popup-arrow--over"]]: verticalPosition === PopOverVariant.positionbelow,
|
|
1655
|
+
[styles["datepicker-popup-arrow--under"]]: verticalPosition === PopOverVariant.positionabove
|
|
1656
|
+
});
|
|
1657
|
+
const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);
|
|
1658
|
+
const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);
|
|
1659
|
+
const datePickerClassNames = {
|
|
1660
|
+
...reactdaypickerstyles,
|
|
1661
|
+
...styles
|
|
1024
1662
|
};
|
|
1025
|
-
return /* @__PURE__ */
|
|
1026
|
-
/* @__PURE__ */
|
|
1027
|
-
|
|
1663
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1664
|
+
/* @__PURE__ */ jsx("div", { className: datepickerPopupContainerClasses, "data-testid": testId, ref: datepickerWrapperRef, style: { ...bubbleStyle, zIndex }, children: /* @__PURE__ */ jsx(
|
|
1665
|
+
DayPicker,
|
|
1028
1666
|
{
|
|
1029
1667
|
captionLayout: "dropdown-buttons",
|
|
1030
|
-
classNames:
|
|
1668
|
+
classNames: datePickerClassNames,
|
|
1031
1669
|
mode: "single",
|
|
1032
|
-
style: { "--rdp-cell-size":
|
|
1033
|
-
modifiersClassNames: { today:
|
|
1034
|
-
footer: /* @__PURE__ */
|
|
1035
|
-
fixedWeeks:
|
|
1036
|
-
...
|
|
1670
|
+
style: { "--rdp-cell-size": getSpacer("l") },
|
|
1671
|
+
modifiersClassNames: { today: styles["day--today"], selected: styles["day_selected"], disabled: styles["day--disabled"] },
|
|
1672
|
+
footer: /* @__PURE__ */ jsx("span", { className: styles["footer-wrapper"], children: footer }),
|
|
1673
|
+
fixedWeeks: true,
|
|
1674
|
+
...rest
|
|
1037
1675
|
}
|
|
1038
1676
|
) }),
|
|
1039
|
-
/* @__PURE__ */
|
|
1677
|
+
/* @__PURE__ */ jsx("div", { ref: arrowRef, className: popupArrowClasses, style: { ...arrowStyle, zIndex } })
|
|
1040
1678
|
] });
|
|
1041
|
-
}
|
|
1679
|
+
};
|
|
1680
|
+
const DatePicker = React.forwardRef((props, ref) => {
|
|
1042
1681
|
const {
|
|
1043
|
-
className
|
|
1044
|
-
dateButtonAriaLabel
|
|
1045
|
-
dateFormat
|
|
1046
|
-
dateValue
|
|
1047
|
-
defaultMonth
|
|
1048
|
-
dir
|
|
1049
|
-
disabled
|
|
1050
|
-
disableDays
|
|
1051
|
-
disableWeekends
|
|
1052
|
-
error
|
|
1053
|
-
errorText
|
|
1054
|
-
errorTextId
|
|
1055
|
-
errorWrapperClassName
|
|
1056
|
-
footerContent
|
|
1057
|
-
label
|
|
1058
|
-
inputId
|
|
1059
|
-
locale
|
|
1060
|
-
maxDate
|
|
1061
|
-
minDate
|
|
1062
|
-
onBlur
|
|
1063
|
-
onChange
|
|
1064
|
-
onDatePopupClosed
|
|
1065
|
-
testId
|
|
1066
|
-
autoComplete
|
|
1067
|
-
variant
|
|
1068
|
-
zIndex
|
|
1069
|
-
...
|
|
1070
|
-
} =
|
|
1682
|
+
className,
|
|
1683
|
+
dateButtonAriaLabel,
|
|
1684
|
+
dateFormat = "dd.MM.yyyy",
|
|
1685
|
+
dateValue,
|
|
1686
|
+
defaultMonth,
|
|
1687
|
+
dir,
|
|
1688
|
+
disabled,
|
|
1689
|
+
disableDays = [],
|
|
1690
|
+
disableWeekends,
|
|
1691
|
+
error,
|
|
1692
|
+
errorText,
|
|
1693
|
+
errorTextId,
|
|
1694
|
+
errorWrapperClassName,
|
|
1695
|
+
footerContent,
|
|
1696
|
+
label,
|
|
1697
|
+
inputId,
|
|
1698
|
+
locale = nb,
|
|
1699
|
+
maxDate,
|
|
1700
|
+
minDate,
|
|
1701
|
+
onBlur,
|
|
1702
|
+
onChange,
|
|
1703
|
+
onDatePopupClosed,
|
|
1704
|
+
testId,
|
|
1705
|
+
autoComplete = "off",
|
|
1706
|
+
variant = PopOverVariant.positionautomatic,
|
|
1707
|
+
zIndex = ZIndex.PopOver,
|
|
1708
|
+
...rest
|
|
1709
|
+
} = props;
|
|
1710
|
+
const [dateState, setDateState] = useState(dateValue);
|
|
1711
|
+
const [inputValue, setInputValue] = useState(dateState ? format(dateState, dateFormat) : "");
|
|
1712
|
+
const [month, setMonth2] = useState(defaultMonth);
|
|
1713
|
+
const [datePickerOpen, setDatePickerOpen] = useState(false);
|
|
1714
|
+
const [returnInputFocus, setReturnInputFocus] = useState(false);
|
|
1715
|
+
const weekendMatcher = {
|
|
1071
1716
|
dayOfWeek: [0, 6]
|
|
1072
|
-
}, Tt = c ? [...u, Bt] : u, Je = oe(null), ve = oe(null), me = oe(null), { refObject: R } = bt(gt(t) ? t : null), Qe = _t([t, R]), he = oe(!1);
|
|
1073
|
-
un(ve, (w) => {
|
|
1074
|
-
ve.current && me.current && !(w != null && w.composedPath().includes(ve.current)) && !(w != null && w.composedPath().includes(me.current)) && T(!1);
|
|
1075
|
-
}), z(() => {
|
|
1076
|
-
se(o) ? (ae(o ? O(o, a) : ""), ee(o), h(o)) : (ae(""), ee(void 0), h(void 0));
|
|
1077
|
-
}, [o, a]), z(() => {
|
|
1078
|
-
te && R.current && R.current.focus();
|
|
1079
|
-
}, [te]);
|
|
1080
|
-
const ze = () => {
|
|
1081
|
-
R != null && R.current && R.current.focus(), T(!1);
|
|
1082
1717
|
};
|
|
1083
|
-
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
if (
|
|
1092
|
-
|
|
1718
|
+
const disabledDays = disableWeekends ? [...disableDays, weekendMatcher] : disableDays;
|
|
1719
|
+
const inputWrapperRef = useRef(null);
|
|
1720
|
+
const inputContainerRef = useRef(null);
|
|
1721
|
+
const datepickerWrapperRef = useRef(null);
|
|
1722
|
+
const { refObject } = usePseudoClasses(isMutableRefObject(ref) ? ref : null);
|
|
1723
|
+
const mergedRefs = mergeRefs([ref, refObject]);
|
|
1724
|
+
const isTyping = useRef(false);
|
|
1725
|
+
useOutsideEvent(inputContainerRef, (e) => {
|
|
1726
|
+
if (inputContainerRef.current && datepickerWrapperRef.current && !(e == null ? void 0 : e.composedPath().includes(inputContainerRef.current)) && !(e == null ? void 0 : e.composedPath().includes(datepickerWrapperRef.current))) {
|
|
1727
|
+
setDatePickerOpen(false);
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
useEffect(() => {
|
|
1731
|
+
if (isValid(dateValue)) {
|
|
1732
|
+
setInputValue(dateValue ? format(dateValue, dateFormat) : "");
|
|
1733
|
+
setDateState(dateValue);
|
|
1734
|
+
setMonth2(dateValue);
|
|
1735
|
+
} else {
|
|
1736
|
+
setInputValue("");
|
|
1737
|
+
setDateState(void 0);
|
|
1738
|
+
setMonth2(void 0);
|
|
1739
|
+
}
|
|
1740
|
+
}, [dateValue, dateFormat]);
|
|
1741
|
+
useEffect(() => {
|
|
1742
|
+
if (returnInputFocus && refObject.current) {
|
|
1743
|
+
refObject.current.focus();
|
|
1744
|
+
}
|
|
1745
|
+
}, [returnInputFocus]);
|
|
1746
|
+
const handleEscapeKeyDown = () => {
|
|
1747
|
+
(refObject == null ? void 0 : refObject.current) && refObject.current.focus();
|
|
1748
|
+
setDatePickerOpen(false);
|
|
1749
|
+
};
|
|
1750
|
+
useKeyboardEvent(datepickerWrapperRef, handleEscapeKeyDown, [KeyboardEventKey.Escape]);
|
|
1751
|
+
useKeyboardEvent(inputWrapperRef, handleEscapeKeyDown, [KeyboardEventKey.Escape]);
|
|
1752
|
+
const handleInputChange = (event, inputFormat) => {
|
|
1753
|
+
setInputValue(event.currentTarget.value);
|
|
1754
|
+
const newDate = parse(event.currentTarget.value, inputFormat, /* @__PURE__ */ new Date());
|
|
1755
|
+
if (isValid(newDate)) {
|
|
1756
|
+
setDateState(newDate);
|
|
1757
|
+
setMonth2(newDate);
|
|
1758
|
+
} else {
|
|
1759
|
+
setDateState(void 0);
|
|
1760
|
+
}
|
|
1761
|
+
onChange && onChange(event, event.currentTarget.value);
|
|
1762
|
+
};
|
|
1763
|
+
const handleInputFocus = () => {
|
|
1764
|
+
if (!returnInputFocus) {
|
|
1765
|
+
setDatePickerOpen(true);
|
|
1766
|
+
} else {
|
|
1767
|
+
setReturnInputFocus(false);
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
const handleSingleDatePickerSelect = (date, _selectedDay, _activeModifiers, e) => {
|
|
1771
|
+
setReturnInputFocus(true);
|
|
1772
|
+
if (!date) {
|
|
1773
|
+
setDatePickerOpen(false);
|
|
1093
1774
|
return;
|
|
1094
1775
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1776
|
+
setDateState(date);
|
|
1777
|
+
if (refObject.current) {
|
|
1778
|
+
setInputValue(format(date, dateFormat));
|
|
1779
|
+
setDatePickerOpen(false);
|
|
1780
|
+
}
|
|
1781
|
+
onChange && onChange(e, date);
|
|
1782
|
+
triggerSyntheticInputEvents(refObject, format(date, dateFormat), date);
|
|
1783
|
+
onDatePopupClosed && onDatePopupClosed(date);
|
|
1784
|
+
};
|
|
1785
|
+
const triggerSyntheticInputEvents = (inputRef, value, date, _onChange) => {
|
|
1786
|
+
if (inputRef.current) {
|
|
1787
|
+
inputRef.current.value = value;
|
|
1788
|
+
const inputEvent = new Event("change", { bubbles: true });
|
|
1789
|
+
Object.defineProperty(inputEvent, "target", {
|
|
1790
|
+
value: inputRef.current,
|
|
1791
|
+
writable: false,
|
|
1792
|
+
enumerable: true,
|
|
1793
|
+
configurable: true
|
|
1794
|
+
});
|
|
1795
|
+
Object.defineProperty(inputEvent, "currentTarget", {
|
|
1796
|
+
value: inputRef.current,
|
|
1797
|
+
writable: false,
|
|
1798
|
+
enumerable: true,
|
|
1799
|
+
configurable: true
|
|
1800
|
+
});
|
|
1801
|
+
inputRef.current.dispatchEvent(inputEvent);
|
|
1802
|
+
if (onChange) {
|
|
1803
|
+
onChange(inputEvent, date);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1116
1806
|
};
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1807
|
+
const handleInputBlur = (e) => {
|
|
1808
|
+
if (!datePickerOpen && (typeof onDatePopupClosed === "undefined" || isTyping.current)) {
|
|
1809
|
+
onBlur && onBlur(e);
|
|
1810
|
+
}
|
|
1811
|
+
isTyping.current = false;
|
|
1812
|
+
};
|
|
1813
|
+
const handleButtonClick = (e) => {
|
|
1814
|
+
e == null ? void 0 : e.stopPropagation();
|
|
1815
|
+
setDatePickerOpen(!datePickerOpen);
|
|
1816
|
+
};
|
|
1817
|
+
useEffect(() => {
|
|
1818
|
+
const handleKeyDown = (e) => {
|
|
1819
|
+
if (!["Escape", "Enter", "Tab"].includes(e.key)) {
|
|
1820
|
+
isTyping.current = true;
|
|
1821
|
+
setDatePickerOpen(false);
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
const inputElement = refObject.current;
|
|
1825
|
+
if (inputElement) {
|
|
1826
|
+
inputElement.addEventListener("keydown", handleKeyDown);
|
|
1827
|
+
}
|
|
1828
|
+
return () => {
|
|
1829
|
+
if (inputElement) {
|
|
1830
|
+
inputElement.removeEventListener("keydown", handleKeyDown);
|
|
1831
|
+
}
|
|
1123
1832
|
};
|
|
1124
|
-
}, [
|
|
1125
|
-
const
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1833
|
+
}, [refObject]);
|
|
1834
|
+
const handleMobileInputChange = (e) => {
|
|
1835
|
+
handleInputChange(e, "yyyy-MM-dd");
|
|
1836
|
+
if (!isTyping.current) {
|
|
1837
|
+
onDatePopupClosed && onDatePopupClosed(dateState);
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
const renderMobile = /* @__PURE__ */ jsx(
|
|
1841
|
+
Input,
|
|
1129
1842
|
{
|
|
1130
|
-
disabled
|
|
1131
|
-
error
|
|
1132
|
-
errorText
|
|
1133
|
-
errorTextId
|
|
1134
|
-
inputId
|
|
1135
|
-
label
|
|
1136
|
-
max:
|
|
1137
|
-
min:
|
|
1843
|
+
disabled,
|
|
1844
|
+
error,
|
|
1845
|
+
errorText,
|
|
1846
|
+
errorTextId,
|
|
1847
|
+
inputId,
|
|
1848
|
+
label,
|
|
1849
|
+
max: maxDate ? format(maxDate, "yyyy-MM-dd") : "",
|
|
1850
|
+
min: minDate ? format(minDate, "yyyy-MM-dd") : "",
|
|
1138
1851
|
type: "date",
|
|
1139
|
-
ref:
|
|
1140
|
-
value:
|
|
1852
|
+
ref: mergedRefs,
|
|
1853
|
+
value: dateState ? format(dateState, "yyyy-MM-dd") : "",
|
|
1141
1854
|
width: 14,
|
|
1142
|
-
...
|
|
1143
|
-
onBlur:
|
|
1144
|
-
onChange:
|
|
1145
|
-
autoComplete:
|
|
1146
|
-
}
|
|
1147
|
-
)
|
|
1148
|
-
|
|
1149
|
-
|
|
1855
|
+
...rest,
|
|
1856
|
+
onBlur: handleInputBlur,
|
|
1857
|
+
onChange: handleMobileInputChange,
|
|
1858
|
+
autoComplete: autoComplete ? autoComplete : void 0
|
|
1859
|
+
}
|
|
1860
|
+
);
|
|
1861
|
+
const renderDesktop = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1862
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
1863
|
+
Input,
|
|
1150
1864
|
{
|
|
1151
|
-
errorWrapperClassName
|
|
1152
|
-
disabled
|
|
1153
|
-
error
|
|
1154
|
-
errorText
|
|
1155
|
-
errorTextId
|
|
1156
|
-
inputId
|
|
1157
|
-
inputContainerRef
|
|
1158
|
-
inputWrapperRef
|
|
1159
|
-
label
|
|
1160
|
-
onFocus:
|
|
1865
|
+
errorWrapperClassName,
|
|
1866
|
+
disabled,
|
|
1867
|
+
error,
|
|
1868
|
+
errorText,
|
|
1869
|
+
errorTextId,
|
|
1870
|
+
inputId,
|
|
1871
|
+
inputContainerRef,
|
|
1872
|
+
inputWrapperRef,
|
|
1873
|
+
label,
|
|
1874
|
+
onFocus: handleInputFocus,
|
|
1161
1875
|
type: "text",
|
|
1162
|
-
ref:
|
|
1163
|
-
value:
|
|
1876
|
+
ref: mergedRefs,
|
|
1877
|
+
value: inputValue,
|
|
1164
1878
|
width: 12,
|
|
1165
|
-
...
|
|
1166
|
-
onBlur:
|
|
1167
|
-
onChange: (
|
|
1168
|
-
rightOfInput: /* @__PURE__ */
|
|
1169
|
-
|
|
1879
|
+
...rest,
|
|
1880
|
+
onBlur: handleInputBlur,
|
|
1881
|
+
onChange: (e) => handleInputChange(e, "yyyy-MM-dd"),
|
|
1882
|
+
rightOfInput: /* @__PURE__ */ jsx(
|
|
1883
|
+
Button$1,
|
|
1170
1884
|
{
|
|
1171
|
-
disabled
|
|
1172
|
-
ariaLabel:
|
|
1173
|
-
onClick:
|
|
1174
|
-
tabIndex:
|
|
1885
|
+
disabled,
|
|
1886
|
+
ariaLabel: dateButtonAriaLabel ?? "Velg dato",
|
|
1887
|
+
onClick: handleButtonClick,
|
|
1888
|
+
tabIndex: datePickerOpen ? -1 : 0,
|
|
1175
1889
|
variant: "borderless",
|
|
1176
|
-
wrapperClassName:
|
|
1177
|
-
className:
|
|
1178
|
-
children: /* @__PURE__ */
|
|
1890
|
+
wrapperClassName: styles["date-button"],
|
|
1891
|
+
className: styles["date-button__inner"],
|
|
1892
|
+
children: /* @__PURE__ */ jsx(Icon, { color: "black", svgIcon: Calendar })
|
|
1179
1893
|
}
|
|
1180
1894
|
),
|
|
1181
|
-
autoComplete:
|
|
1895
|
+
autoComplete: autoComplete ? autoComplete : void 0
|
|
1182
1896
|
}
|
|
1183
1897
|
) }),
|
|
1184
|
-
|
|
1185
|
-
|
|
1898
|
+
datePickerOpen && !disabled && /* @__PURE__ */ jsx(
|
|
1899
|
+
DatePickerPopup,
|
|
1186
1900
|
{
|
|
1187
|
-
dir
|
|
1188
|
-
disabled:
|
|
1189
|
-
datepickerWrapperRef
|
|
1190
|
-
footer:
|
|
1191
|
-
fromDate:
|
|
1192
|
-
toDate:
|
|
1193
|
-
inputRef:
|
|
1194
|
-
locale
|
|
1195
|
-
month
|
|
1196
|
-
selected:
|
|
1197
|
-
onSelect:
|
|
1198
|
-
onMonthChange:
|
|
1199
|
-
variant
|
|
1200
|
-
zIndex
|
|
1901
|
+
dir,
|
|
1902
|
+
disabled: disabledDays,
|
|
1903
|
+
datepickerWrapperRef,
|
|
1904
|
+
footer: footerContent,
|
|
1905
|
+
fromDate: minDate,
|
|
1906
|
+
toDate: maxDate,
|
|
1907
|
+
inputRef: refObject,
|
|
1908
|
+
locale,
|
|
1909
|
+
month,
|
|
1910
|
+
selected: dateState,
|
|
1911
|
+
onSelect: handleSingleDatePickerSelect,
|
|
1912
|
+
onMonthChange: setMonth2,
|
|
1913
|
+
variant,
|
|
1914
|
+
zIndex
|
|
1201
1915
|
}
|
|
1202
1916
|
)
|
|
1203
1917
|
] });
|
|
1204
|
-
return /* @__PURE__ */
|
|
1918
|
+
return /* @__PURE__ */ jsx("div", { className, "data-testid": testId, children: isMobileUA() ? renderMobile : renderDesktop });
|
|
1205
1919
|
});
|
|
1206
|
-
|
|
1207
|
-
const
|
|
1208
|
-
const
|
|
1209
|
-
return
|
|
1210
|
-
}
|
|
1920
|
+
DatePicker.displayName = "DatePicker";
|
|
1921
|
+
const formatAsTwoDigits = (value) => {
|
|
1922
|
+
const stringValue = String(value);
|
|
1923
|
+
return stringValue.length === 1 ? "0" + stringValue : stringValue;
|
|
1924
|
+
};
|
|
1925
|
+
const isNumericString = (str) => {
|
|
1926
|
+
return !str || /^\d+$/.test(str) && str.length <= 2;
|
|
1927
|
+
};
|
|
1928
|
+
const DateTime = React.forwardRef((props, ref) => {
|
|
1211
1929
|
const {
|
|
1212
|
-
error
|
|
1213
|
-
errorText
|
|
1214
|
-
errorTextId
|
|
1215
|
-
errorWrapperClassName
|
|
1216
|
-
label
|
|
1217
|
-
onBlur
|
|
1218
|
-
onChange
|
|
1219
|
-
timeUnit
|
|
1220
|
-
testId
|
|
1221
|
-
inputId
|
|
1222
|
-
value
|
|
1223
|
-
autoComplete
|
|
1224
|
-
...
|
|
1225
|
-
} =
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1930
|
+
error,
|
|
1931
|
+
errorText,
|
|
1932
|
+
errorTextId,
|
|
1933
|
+
errorWrapperClassName,
|
|
1934
|
+
label,
|
|
1935
|
+
onBlur,
|
|
1936
|
+
onChange,
|
|
1937
|
+
timeUnit,
|
|
1938
|
+
testId,
|
|
1939
|
+
inputId,
|
|
1940
|
+
value,
|
|
1941
|
+
autoComplete = "off",
|
|
1942
|
+
...rest
|
|
1943
|
+
} = props;
|
|
1944
|
+
const [inputValue, setInputValue] = useState(
|
|
1945
|
+
typeof value !== "undefined" ? formatAsTwoDigits(value) : void 0
|
|
1946
|
+
);
|
|
1947
|
+
const { refObject } = usePseudoClasses(isMutableRefObject(ref) ? ref : null);
|
|
1948
|
+
const mergedRefs = mergeRefs([ref, refObject]);
|
|
1949
|
+
useEffect(() => {
|
|
1950
|
+
setInputValue(value ? formatAsTwoDigits(value) : void 0);
|
|
1951
|
+
}, [value]);
|
|
1952
|
+
const handleInputChange = (event) => {
|
|
1953
|
+
const value2 = event.target.value;
|
|
1954
|
+
if (isNumericString(value2)) {
|
|
1955
|
+
setInputValue(value2);
|
|
1956
|
+
onChange && onChange(event);
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
const handleInputBlur = (event) => {
|
|
1960
|
+
const formattedValue = formatAsTwoDigits(event.target.value);
|
|
1961
|
+
setInputValue(formattedValue);
|
|
1962
|
+
onChange && onChange(event);
|
|
1963
|
+
onBlur && onBlur(event);
|
|
1964
|
+
};
|
|
1965
|
+
const handleInputOnKeyDown = (event) => {
|
|
1966
|
+
const validChars = /[0-9]/;
|
|
1967
|
+
const allowedKeys = ["Backspace", " ", "Enter", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
1968
|
+
if (!validChars.test(event.key) && !allowedKeys.includes(event.key)) {
|
|
1969
|
+
event.preventDefault();
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
const renderTimeSeparator = () => {
|
|
1973
|
+
return timeUnit === "hours" && /* @__PURE__ */ jsx("span", { className: styles["time-separator"], children: ":" });
|
|
1974
|
+
};
|
|
1975
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: /* @__PURE__ */ jsx(
|
|
1976
|
+
Input,
|
|
1243
1977
|
{
|
|
1244
|
-
inputId
|
|
1245
|
-
error
|
|
1246
|
-
errorText
|
|
1247
|
-
errorTextId
|
|
1248
|
-
errorWrapperClassName
|
|
1249
|
-
label
|
|
1250
|
-
max:
|
|
1978
|
+
inputId,
|
|
1979
|
+
error,
|
|
1980
|
+
errorText,
|
|
1981
|
+
errorTextId,
|
|
1982
|
+
errorWrapperClassName,
|
|
1983
|
+
label,
|
|
1984
|
+
max: timeUnit === "hours" ? 23 : 59,
|
|
1251
1985
|
min: 0,
|
|
1252
1986
|
type: "number",
|
|
1253
|
-
ref:
|
|
1254
|
-
value:
|
|
1987
|
+
ref: mergedRefs,
|
|
1988
|
+
value: inputValue,
|
|
1255
1989
|
width: 5,
|
|
1256
|
-
defaultValue: typeof
|
|
1257
|
-
...
|
|
1258
|
-
onChange:
|
|
1259
|
-
onBlur:
|
|
1260
|
-
rightOfInput:
|
|
1261
|
-
onKeyDown:
|
|
1262
|
-
autoComplete:
|
|
1990
|
+
defaultValue: typeof props.defaultValue !== "undefined" ? formatAsTwoDigits(props.defaultValue) : void 0,
|
|
1991
|
+
...rest,
|
|
1992
|
+
onChange: handleInputChange,
|
|
1993
|
+
onBlur: handleInputBlur,
|
|
1994
|
+
rightOfInput: renderTimeSeparator(),
|
|
1995
|
+
onKeyDown: handleInputOnKeyDown,
|
|
1996
|
+
autoComplete: autoComplete ? autoComplete : void 0
|
|
1263
1997
|
}
|
|
1264
1998
|
) });
|
|
1265
1999
|
});
|
|
1266
|
-
|
|
1267
|
-
const
|
|
1268
|
-
const { children
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
2000
|
+
DateTime.displayName = "DateTime";
|
|
2001
|
+
const DateTimePickerWrapper = React.forwardRef((props, ref) => {
|
|
2002
|
+
const { children, errorWrapperClassName, errorText, legend, testId } = props;
|
|
2003
|
+
const errorTextId = useUuid();
|
|
2004
|
+
const mapDateComponents = (child) => {
|
|
2005
|
+
if (isComponent(child, DatePicker)) {
|
|
2006
|
+
return React.cloneElement(child, {
|
|
2007
|
+
className: classNames(styles["date-time-picker-wrapper__date-picker"]),
|
|
2008
|
+
error: !!errorText,
|
|
2009
|
+
errorTextId
|
|
2010
|
+
});
|
|
2011
|
+
} else if (isComponent(child, DateTime)) {
|
|
2012
|
+
return React.cloneElement(child, {
|
|
2013
|
+
error: !!errorText,
|
|
2014
|
+
errorTextId
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
return child;
|
|
2018
|
+
};
|
|
2019
|
+
return /* @__PURE__ */ jsx("div", { ref, tabIndex: -1, children: /* @__PURE__ */ jsx(ErrorWrapper, { className: errorWrapperClassName, errorText, errorTextId, children: props.legend ? /* @__PURE__ */ jsxs("fieldset", { className: styles["date-time-picker-wrapper"], "data-testid": testId, children: [
|
|
2020
|
+
props.legend && /* @__PURE__ */ jsx("legend", { className: styles["date-time-picker-wrapper__legend"], children: legend }),
|
|
2021
|
+
React.Children.map(children, mapDateComponents)
|
|
2022
|
+
] }) : /* @__PURE__ */ jsx("div", { className: styles["date-time-picker-wrapper"], children: React.Children.map(children, mapDateComponents) }) }) });
|
|
1280
2023
|
});
|
|
1281
|
-
|
|
1282
|
-
const
|
|
1283
|
-
const
|
|
1284
|
-
for (const
|
|
1285
|
-
const
|
|
1286
|
-
if (
|
|
1287
|
-
return
|
|
2024
|
+
DateTimePickerWrapper.displayName = "DateTimePickerWrapper";
|
|
2025
|
+
const parseInputDate = (dateString) => {
|
|
2026
|
+
const possibleFormats = ["yyyy-MM-dd", "dd.MM.yyyy"];
|
|
2027
|
+
for (const format2 of possibleFormats) {
|
|
2028
|
+
const parsedDate = parse(dateString, format2, /* @__PURE__ */ new Date());
|
|
2029
|
+
if (isValid(parsedDate)) {
|
|
2030
|
+
return parsedDate;
|
|
2031
|
+
}
|
|
1288
2032
|
}
|
|
1289
2033
|
return null;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
2034
|
+
};
|
|
2035
|
+
const isValidDate = (dateString) => {
|
|
2036
|
+
const date = new Date(dateString);
|
|
2037
|
+
return date instanceof Date && !isNaN(date.getTime());
|
|
2038
|
+
};
|
|
2039
|
+
const validateMinMaxDate = (date, outsideRangeErrorMessage, invalidFormatErrorMessage, minDate, maxDate) => {
|
|
2040
|
+
const formattedDate = parseInputDate(date);
|
|
2041
|
+
const hasMinDate = typeof minDate !== "undefined";
|
|
2042
|
+
const hasMaxDate = typeof maxDate !== "undefined";
|
|
2043
|
+
if (!formattedDate || hasMinDate && !isValid(minDate) || hasMaxDate && !isValid(maxDate)) {
|
|
2044
|
+
return invalidFormatErrorMessage || "Invalid date format";
|
|
2045
|
+
}
|
|
2046
|
+
if (hasMinDate && !hasMaxDate && (isSameDay(formattedDate, minDate) || isAfter(formattedDate, minDate))) return true;
|
|
2047
|
+
else if (hasMaxDate && !hasMinDate && (isSameDay(formattedDate, maxDate) || isBefore(formattedDate, maxDate))) return true;
|
|
2048
|
+
else if (hasMinDate && hasMaxDate && (isSameDay(formattedDate, minDate) || isSameDay(formattedDate, maxDate) || isWithinInterval(formattedDate, { start: minDate, end: maxDate }))) {
|
|
2049
|
+
return true;
|
|
2050
|
+
}
|
|
2051
|
+
return outsideRangeErrorMessage;
|
|
2052
|
+
};
|
|
2053
|
+
const validateDisabledDates = (date, disabledDates, isDisabledErrorMessage, invalidFormatErrorMessage) => {
|
|
2054
|
+
const formattedDate = parseInputDate(date);
|
|
2055
|
+
if (!formattedDate) {
|
|
2056
|
+
return invalidFormatErrorMessage || "Invalid date format";
|
|
2057
|
+
}
|
|
2058
|
+
if (!disabledDates.some((d) => isSameDay(d, formattedDate))) {
|
|
2059
|
+
return true;
|
|
2060
|
+
}
|
|
2061
|
+
return isDisabledErrorMessage;
|
|
2062
|
+
};
|
|
2063
|
+
const validateMinTimeMaxTime = (time, errorMessage, minTime, maxTime) => {
|
|
2064
|
+
const timeParsed = parse((time.hour + ":" + time.minute).toString(), "HH:mm", /* @__PURE__ */ new Date());
|
|
2065
|
+
const minTimeParsed = parse(((minTime == null ? void 0 : minTime.hour) + ":" + (minTime == null ? void 0 : minTime.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date());
|
|
2066
|
+
const maxTimeParsed = parse(((maxTime == null ? void 0 : maxTime.hour) + ":" + (maxTime == null ? void 0 : maxTime.minute)).toString(), "HH:mm", /* @__PURE__ */ new Date());
|
|
2067
|
+
if ((typeof minTime === "undefined" || timeParsed >= minTimeParsed) && (typeof maxTime === "undefined" || timeParsed <= maxTimeParsed)) {
|
|
2068
|
+
return true;
|
|
2069
|
+
}
|
|
2070
|
+
return errorMessage;
|
|
1302
2071
|
};
|
|
1303
2072
|
export {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
2073
|
+
DatePicker,
|
|
2074
|
+
DateTime,
|
|
2075
|
+
DateTimePickerWrapper,
|
|
2076
|
+
DatePicker as default,
|
|
2077
|
+
isValidDate,
|
|
2078
|
+
parseInputDate,
|
|
2079
|
+
validateDisabledDates,
|
|
2080
|
+
validateMinMaxDate,
|
|
2081
|
+
validateMinTimeMaxTime
|
|
1313
2082
|
};
|
|
1314
2083
|
//# sourceMappingURL=index.js.map
|