@helsenorge/datepicker 12.0.0-beta.2 → 12.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1779 -972
- package/components/DatePicker/index.js +699 -446
- package/components/DatePicker/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { createContext, useContext,
|
|
2
|
+
import React, { createContext, useContext, useCallback, useRef, useLayoutEffect, useState, useEffect, useMemo } from "react";
|
|
3
3
|
import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getYear, getWeek, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, isValid, parse, isWithinInterval } from "date-fns";
|
|
4
|
-
import {
|
|
4
|
+
import { nb } from "date-fns/locale";
|
|
5
5
|
import Button$1 from "@helsenorge/designsystem-react/components/Button";
|
|
6
6
|
import Icon from "@helsenorge/designsystem-react/components/Icon";
|
|
7
7
|
import Calendar from "@helsenorge/designsystem-react/components/Icons/Calendar";
|
|
@@ -14,7 +14,6 @@ import { usePseudoClasses } from "@helsenorge/designsystem-react/hooks/usePseudo
|
|
|
14
14
|
import { isMobileUA } from "@helsenorge/designsystem-react/utils/mobile";
|
|
15
15
|
import { isMutableRefObject, mergeRefs } from "@helsenorge/designsystem-react/utils/refs";
|
|
16
16
|
import classNames from "classnames";
|
|
17
|
-
import { enUS as enUS$1 } from "date-fns/locale/en-US";
|
|
18
17
|
import reactdaypickerstyles from "react-day-picker/dist/style.module.css";
|
|
19
18
|
import { useInterval } from "@helsenorge/designsystem-react/hooks/useInterval";
|
|
20
19
|
import { useIsVisible } from "@helsenorge/designsystem-react/hooks/useIsVisible";
|
|
@@ -22,61 +21,27 @@ import { useLayoutEvent } from "@helsenorge/designsystem-react/hooks/useLayoutEv
|
|
|
22
21
|
import { useSize } from "@helsenorge/designsystem-react/hooks/useSize";
|
|
23
22
|
import { getSpacer } from "@helsenorge/designsystem-react/theme/currys/spacing";
|
|
24
23
|
import styles from "./styles.module.scss";
|
|
24
|
+
import { enUS } from "date-fns/locale/en-US";
|
|
25
25
|
import ErrorWrapper from "@helsenorge/designsystem-react/components/ErrorWrapper";
|
|
26
26
|
import { useUuid } from "@helsenorge/designsystem-react/hooks/useUuid";
|
|
27
27
|
import { isComponent } from "@helsenorge/designsystem-react/utils/component";
|
|
28
|
-
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
UI2["Dropdown"] = "dropdown";
|
|
37
|
-
UI2["DropdownRoot"] = "dropdown_root";
|
|
38
|
-
UI2["Footer"] = "footer";
|
|
39
|
-
UI2["MonthGrid"] = "month_grid";
|
|
40
|
-
UI2["MonthCaption"] = "month_caption";
|
|
41
|
-
UI2["MonthsDropdown"] = "months_dropdown";
|
|
42
|
-
UI2["Month"] = "month";
|
|
43
|
-
UI2["Months"] = "months";
|
|
44
|
-
UI2["Nav"] = "nav";
|
|
45
|
-
UI2["NextMonthButton"] = "button_next";
|
|
46
|
-
UI2["PreviousMonthButton"] = "button_previous";
|
|
47
|
-
UI2["Week"] = "week";
|
|
48
|
-
UI2["Weeks"] = "weeks";
|
|
49
|
-
UI2["Weekday"] = "weekday";
|
|
50
|
-
UI2["Weekdays"] = "weekdays";
|
|
51
|
-
UI2["WeekNumber"] = "week_number";
|
|
52
|
-
UI2["WeekNumberHeader"] = "week_number_header";
|
|
53
|
-
UI2["YearsDropdown"] = "years_dropdown";
|
|
54
|
-
})(UI || (UI = {}));
|
|
55
|
-
var DayFlag;
|
|
56
|
-
(function(DayFlag2) {
|
|
57
|
-
DayFlag2["disabled"] = "disabled";
|
|
58
|
-
DayFlag2["hidden"] = "hidden";
|
|
59
|
-
DayFlag2["outside"] = "outside";
|
|
60
|
-
DayFlag2["focused"] = "focused";
|
|
61
|
-
DayFlag2["today"] = "today";
|
|
62
|
-
})(DayFlag || (DayFlag = {}));
|
|
63
|
-
var SelectionState;
|
|
64
|
-
(function(SelectionState2) {
|
|
65
|
-
SelectionState2["range_end"] = "range_end";
|
|
66
|
-
SelectionState2["range_middle"] = "range_middle";
|
|
67
|
-
SelectionState2["range_start"] = "range_start";
|
|
68
|
-
SelectionState2["selected"] = "selected";
|
|
69
|
-
})(SelectionState || (SelectionState = {}));
|
|
28
|
+
function tzName(timeZone, date, format2 = "long") {
|
|
29
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
30
|
+
// Enforces engine to render the time. Without the option JavaScriptCore omits it.
|
|
31
|
+
hour: "numeric",
|
|
32
|
+
timeZone,
|
|
33
|
+
timeZoneName: format2
|
|
34
|
+
}).format(date).split(/\s/g).slice(2).join(" ");
|
|
35
|
+
}
|
|
70
36
|
const offsetFormatCache = {};
|
|
71
37
|
const offsetCache = {};
|
|
72
38
|
function tzOffset(timeZone, date) {
|
|
73
39
|
try {
|
|
74
|
-
const format2 = offsetFormatCache[timeZone] || (offsetFormatCache[timeZone] = new Intl.DateTimeFormat("en-
|
|
40
|
+
const format2 = offsetFormatCache[timeZone] || (offsetFormatCache[timeZone] = new Intl.DateTimeFormat("en-US", {
|
|
75
41
|
timeZone,
|
|
76
|
-
hour: "numeric",
|
|
77
42
|
timeZoneName: "longOffset"
|
|
78
43
|
}).format);
|
|
79
|
-
const offsetStr = format2(date).split("GMT")[1]
|
|
44
|
+
const offsetStr = format2(date).split("GMT")[1];
|
|
80
45
|
if (offsetStr in offsetCache) return offsetCache[offsetStr];
|
|
81
46
|
return calcOffset(offsetStr, offsetStr.split(":"));
|
|
82
47
|
} catch {
|
|
@@ -88,9 +53,10 @@ function tzOffset(timeZone, date) {
|
|
|
88
53
|
}
|
|
89
54
|
const offsetRe = /([+-]\d\d):?(\d\d)?/;
|
|
90
55
|
function calcOffset(cacheStr, values) {
|
|
91
|
-
const hours = +values[0];
|
|
56
|
+
const hours = +(values[0] || 0);
|
|
92
57
|
const minutes = +(values[1] || 0);
|
|
93
|
-
|
|
58
|
+
const seconds = +(values[2] || 0) / 60;
|
|
59
|
+
return offsetCache[cacheStr] = hours * 60 + minutes > 0 ? hours * 60 + minutes + seconds : hours * 60 - minutes - seconds;
|
|
94
60
|
}
|
|
95
61
|
class TZDateMini extends Date {
|
|
96
62
|
//#region static
|
|
@@ -127,7 +93,8 @@ class TZDateMini extends Date {
|
|
|
127
93
|
return new TZDateMini(+this, timeZone);
|
|
128
94
|
}
|
|
129
95
|
getTimezoneOffset() {
|
|
130
|
-
|
|
96
|
+
const offset = -tzOffset(this.timeZone, this);
|
|
97
|
+
return offset > 0 ? Math.floor(offset) : Math.ceil(offset);
|
|
131
98
|
}
|
|
132
99
|
//#endregion
|
|
133
100
|
//#region time
|
|
@@ -167,7 +134,7 @@ Object.getOwnPropertyNames(Date.prototype).forEach((method) => {
|
|
|
167
134
|
});
|
|
168
135
|
function syncToInternal(date) {
|
|
169
136
|
date.internal.setTime(+date);
|
|
170
|
-
date.internal.
|
|
137
|
+
date.internal.setUTCSeconds(date.internal.getUTCSeconds() - Math.round(-tzOffset(date.timeZone, date) * 60));
|
|
171
138
|
}
|
|
172
139
|
function syncFromInternal(date) {
|
|
173
140
|
Date.prototype.setFullYear.call(date, date.internal.getUTCFullYear(), date.internal.getUTCMonth(), date.internal.getUTCDate());
|
|
@@ -175,7 +142,8 @@ function syncFromInternal(date) {
|
|
|
175
142
|
adjustToSystemTZ(date);
|
|
176
143
|
}
|
|
177
144
|
function adjustToSystemTZ(date) {
|
|
178
|
-
const
|
|
145
|
+
const baseOffset = tzOffset(date.timeZone, date);
|
|
146
|
+
const offset = baseOffset > 0 ? Math.floor(baseOffset) : Math.ceil(baseOffset);
|
|
179
147
|
const prevHour = /* @__PURE__ */ new Date(+date);
|
|
180
148
|
prevHour.setUTCHours(prevHour.getUTCHours() - 1);
|
|
181
149
|
const systemOffset = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset();
|
|
@@ -185,14 +153,24 @@ function adjustToSystemTZ(date) {
|
|
|
185
153
|
if (systemDSTChange && dstShift) date.internal.setUTCMinutes(date.internal.getUTCMinutes() + systemDSTChange);
|
|
186
154
|
const offsetDiff = systemOffset - offset;
|
|
187
155
|
if (offsetDiff) Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetDiff);
|
|
188
|
-
const
|
|
156
|
+
const systemDate = /* @__PURE__ */ new Date(+date);
|
|
157
|
+
systemDate.setUTCSeconds(0);
|
|
158
|
+
const systemSecondsOffset = systemOffset > 0 ? systemDate.getSeconds() : (systemDate.getSeconds() - 60) % 60;
|
|
159
|
+
const secondsOffset = Math.round(-(tzOffset(date.timeZone, date) * 60)) % 60;
|
|
160
|
+
if (secondsOffset || systemSecondsOffset) {
|
|
161
|
+
date.internal.setUTCSeconds(date.internal.getUTCSeconds() + secondsOffset);
|
|
162
|
+
Date.prototype.setUTCSeconds.call(date, Date.prototype.getUTCSeconds.call(date) + secondsOffset + systemSecondsOffset);
|
|
163
|
+
}
|
|
164
|
+
const postBaseOffset = tzOffset(date.timeZone, date);
|
|
165
|
+
const postOffset = postBaseOffset > 0 ? Math.floor(postBaseOffset) : Math.ceil(postBaseOffset);
|
|
189
166
|
const postSystemOffset = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset();
|
|
190
167
|
const postOffsetDiff = postSystemOffset - postOffset;
|
|
191
168
|
const offsetChanged = postOffset !== offset;
|
|
192
169
|
const postDiff = postOffsetDiff - offsetDiff;
|
|
193
170
|
if (offsetChanged && postDiff) {
|
|
194
171
|
Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + postDiff);
|
|
195
|
-
const
|
|
172
|
+
const newBaseOffset = tzOffset(date.timeZone, date);
|
|
173
|
+
const newOffset = newBaseOffset > 0 ? Math.floor(newBaseOffset) : Math.ceil(newBaseOffset);
|
|
196
174
|
const offsetChange = postOffset - newOffset;
|
|
197
175
|
if (offsetChange) {
|
|
198
176
|
date.internal.setUTCMinutes(date.internal.getUTCMinutes() + offsetChange);
|
|
@@ -261,12 +239,6 @@ class TZDate extends TZDateMini {
|
|
|
261
239
|
}
|
|
262
240
|
//#endregion
|
|
263
241
|
}
|
|
264
|
-
function tzName(tz, date) {
|
|
265
|
-
return new Intl.DateTimeFormat("en-GB", {
|
|
266
|
-
timeZone: tz,
|
|
267
|
-
timeZoneName: "long"
|
|
268
|
-
}).format(date).slice(12);
|
|
269
|
-
}
|
|
270
242
|
const FIVE_WEEKS = 5;
|
|
271
243
|
const FOUR_WEEKS = 4;
|
|
272
244
|
function getBroadcastWeeksInMonth(month, dateLib) {
|
|
@@ -296,10 +268,10 @@ function endOfBroadcastWeek(date, dateLib) {
|
|
|
296
268
|
}
|
|
297
269
|
class DateLib {
|
|
298
270
|
/**
|
|
299
|
-
* Creates an instance of DateLib
|
|
271
|
+
* Creates an instance of `DateLib`.
|
|
300
272
|
*
|
|
301
|
-
* @param options
|
|
302
|
-
* @param overrides
|
|
273
|
+
* @param options Configuration options for the date library.
|
|
274
|
+
* @param overrides Custom overrides for the date library functions.
|
|
303
275
|
*/
|
|
304
276
|
constructor(options, overrides) {
|
|
305
277
|
this.Date = Date;
|
|
@@ -324,148 +296,150 @@ class DateLib {
|
|
|
324
296
|
return new Date(year, monthIndex, date);
|
|
325
297
|
};
|
|
326
298
|
this.addDays = (date, amount) => {
|
|
327
|
-
var _a
|
|
328
|
-
return ((
|
|
299
|
+
var _a;
|
|
300
|
+
return ((_a = this.overrides) == null ? void 0 : _a.addDays) ? this.overrides.addDays(date, amount) : addDays(date, amount);
|
|
329
301
|
};
|
|
330
302
|
this.addMonths = (date, amount) => {
|
|
331
|
-
var _a
|
|
332
|
-
return ((
|
|
303
|
+
var _a;
|
|
304
|
+
return ((_a = this.overrides) == null ? void 0 : _a.addMonths) ? this.overrides.addMonths(date, amount) : addMonths(date, amount);
|
|
333
305
|
};
|
|
334
306
|
this.addWeeks = (date, amount) => {
|
|
335
|
-
var _a
|
|
336
|
-
return ((
|
|
307
|
+
var _a;
|
|
308
|
+
return ((_a = this.overrides) == null ? void 0 : _a.addWeeks) ? this.overrides.addWeeks(date, amount) : addWeeks(date, amount);
|
|
337
309
|
};
|
|
338
310
|
this.addYears = (date, amount) => {
|
|
339
|
-
var _a
|
|
340
|
-
return ((
|
|
311
|
+
var _a;
|
|
312
|
+
return ((_a = this.overrides) == null ? void 0 : _a.addYears) ? this.overrides.addYears(date, amount) : addYears(date, amount);
|
|
341
313
|
};
|
|
342
314
|
this.differenceInCalendarDays = (dateLeft, dateRight) => {
|
|
343
|
-
var _a
|
|
344
|
-
return ((
|
|
315
|
+
var _a;
|
|
316
|
+
return ((_a = this.overrides) == null ? void 0 : _a.differenceInCalendarDays) ? this.overrides.differenceInCalendarDays(dateLeft, dateRight) : differenceInCalendarDays(dateLeft, dateRight);
|
|
345
317
|
};
|
|
346
318
|
this.differenceInCalendarMonths = (dateLeft, dateRight) => {
|
|
347
|
-
var _a
|
|
348
|
-
return ((
|
|
319
|
+
var _a;
|
|
320
|
+
return ((_a = this.overrides) == null ? void 0 : _a.differenceInCalendarMonths) ? this.overrides.differenceInCalendarMonths(dateLeft, dateRight) : differenceInCalendarMonths(dateLeft, dateRight);
|
|
349
321
|
};
|
|
350
322
|
this.eachMonthOfInterval = (interval) => {
|
|
351
|
-
var _a
|
|
352
|
-
return ((
|
|
323
|
+
var _a;
|
|
324
|
+
return ((_a = this.overrides) == null ? void 0 : _a.eachMonthOfInterval) ? this.overrides.eachMonthOfInterval(interval) : eachMonthOfInterval(interval);
|
|
353
325
|
};
|
|
354
|
-
this.endOfBroadcastWeek = (date
|
|
355
|
-
var _a
|
|
356
|
-
return ((
|
|
326
|
+
this.endOfBroadcastWeek = (date) => {
|
|
327
|
+
var _a;
|
|
328
|
+
return ((_a = this.overrides) == null ? void 0 : _a.endOfBroadcastWeek) ? this.overrides.endOfBroadcastWeek(date) : endOfBroadcastWeek(date, this);
|
|
357
329
|
};
|
|
358
330
|
this.endOfISOWeek = (date) => {
|
|
359
|
-
var _a
|
|
360
|
-
return ((
|
|
331
|
+
var _a;
|
|
332
|
+
return ((_a = this.overrides) == null ? void 0 : _a.endOfISOWeek) ? this.overrides.endOfISOWeek(date) : endOfISOWeek(date);
|
|
361
333
|
};
|
|
362
334
|
this.endOfMonth = (date) => {
|
|
363
|
-
var _a
|
|
364
|
-
return ((
|
|
335
|
+
var _a;
|
|
336
|
+
return ((_a = this.overrides) == null ? void 0 : _a.endOfMonth) ? this.overrides.endOfMonth(date) : endOfMonth(date);
|
|
365
337
|
};
|
|
366
338
|
this.endOfWeek = (date, options2) => {
|
|
367
|
-
var _a
|
|
368
|
-
return ((
|
|
339
|
+
var _a;
|
|
340
|
+
return ((_a = this.overrides) == null ? void 0 : _a.endOfWeek) ? this.overrides.endOfWeek(date, options2) : endOfWeek(date, this.options);
|
|
369
341
|
};
|
|
370
342
|
this.endOfYear = (date) => {
|
|
371
|
-
var _a
|
|
372
|
-
return ((
|
|
343
|
+
var _a;
|
|
344
|
+
return ((_a = this.overrides) == null ? void 0 : _a.endOfYear) ? this.overrides.endOfYear(date) : endOfYear(date);
|
|
373
345
|
};
|
|
374
|
-
this.format = (date, formatStr,
|
|
375
|
-
var _a
|
|
376
|
-
const formatted = ((
|
|
346
|
+
this.format = (date, formatStr, _options) => {
|
|
347
|
+
var _a;
|
|
348
|
+
const formatted = ((_a = this.overrides) == null ? void 0 : _a.format) ? this.overrides.format(date, formatStr, this.options) : format(date, formatStr, this.options);
|
|
377
349
|
if (this.options.numerals && this.options.numerals !== "latn") {
|
|
378
350
|
return this.replaceDigits(formatted);
|
|
379
351
|
}
|
|
380
352
|
return formatted;
|
|
381
353
|
};
|
|
382
354
|
this.getISOWeek = (date) => {
|
|
383
|
-
var _a
|
|
384
|
-
return ((
|
|
355
|
+
var _a;
|
|
356
|
+
return ((_a = this.overrides) == null ? void 0 : _a.getISOWeek) ? this.overrides.getISOWeek(date) : getISOWeek(date);
|
|
385
357
|
};
|
|
386
|
-
this.getMonth = (date) => {
|
|
387
|
-
var _a
|
|
388
|
-
return ((
|
|
358
|
+
this.getMonth = (date, _options) => {
|
|
359
|
+
var _a;
|
|
360
|
+
return ((_a = this.overrides) == null ? void 0 : _a.getMonth) ? this.overrides.getMonth(date, this.options) : getMonth(date, this.options);
|
|
389
361
|
};
|
|
390
|
-
this.getYear = (date) => {
|
|
391
|
-
var _a
|
|
392
|
-
return ((
|
|
362
|
+
this.getYear = (date, _options) => {
|
|
363
|
+
var _a;
|
|
364
|
+
return ((_a = this.overrides) == null ? void 0 : _a.getYear) ? this.overrides.getYear(date, this.options) : getYear(date, this.options);
|
|
393
365
|
};
|
|
394
|
-
this.getWeek = (date,
|
|
395
|
-
var _a
|
|
396
|
-
return ((
|
|
366
|
+
this.getWeek = (date, _options) => {
|
|
367
|
+
var _a;
|
|
368
|
+
return ((_a = this.overrides) == null ? void 0 : _a.getWeek) ? this.overrides.getWeek(date, this.options) : getWeek(date, this.options);
|
|
397
369
|
};
|
|
398
370
|
this.isAfter = (date, dateToCompare) => {
|
|
399
|
-
var _a
|
|
400
|
-
return ((
|
|
371
|
+
var _a;
|
|
372
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isAfter) ? this.overrides.isAfter(date, dateToCompare) : isAfter(date, dateToCompare);
|
|
401
373
|
};
|
|
402
374
|
this.isBefore = (date, dateToCompare) => {
|
|
403
|
-
var _a
|
|
404
|
-
return ((
|
|
375
|
+
var _a;
|
|
376
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isBefore) ? this.overrides.isBefore(date, dateToCompare) : isBefore(date, dateToCompare);
|
|
405
377
|
};
|
|
406
378
|
this.isDate = (value) => {
|
|
407
|
-
var _a
|
|
408
|
-
return ((
|
|
379
|
+
var _a;
|
|
380
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isDate) ? this.overrides.isDate(value) : isDate(value);
|
|
409
381
|
};
|
|
410
382
|
this.isSameDay = (dateLeft, dateRight) => {
|
|
411
|
-
var _a
|
|
412
|
-
return ((
|
|
383
|
+
var _a;
|
|
384
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isSameDay) ? this.overrides.isSameDay(dateLeft, dateRight) : isSameDay(dateLeft, dateRight);
|
|
413
385
|
};
|
|
414
386
|
this.isSameMonth = (dateLeft, dateRight) => {
|
|
415
|
-
var _a
|
|
416
|
-
return ((
|
|
387
|
+
var _a;
|
|
388
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isSameMonth) ? this.overrides.isSameMonth(dateLeft, dateRight) : isSameMonth(dateLeft, dateRight);
|
|
417
389
|
};
|
|
418
390
|
this.isSameYear = (dateLeft, dateRight) => {
|
|
419
|
-
var _a
|
|
420
|
-
return ((
|
|
391
|
+
var _a;
|
|
392
|
+
return ((_a = this.overrides) == null ? void 0 : _a.isSameYear) ? this.overrides.isSameYear(dateLeft, dateRight) : isSameYear(dateLeft, dateRight);
|
|
421
393
|
};
|
|
422
394
|
this.max = (dates) => {
|
|
423
|
-
var _a
|
|
424
|
-
return ((
|
|
395
|
+
var _a;
|
|
396
|
+
return ((_a = this.overrides) == null ? void 0 : _a.max) ? this.overrides.max(dates) : max(dates);
|
|
425
397
|
};
|
|
426
398
|
this.min = (dates) => {
|
|
427
|
-
var _a
|
|
428
|
-
return ((
|
|
399
|
+
var _a;
|
|
400
|
+
return ((_a = this.overrides) == null ? void 0 : _a.min) ? this.overrides.min(dates) : min(dates);
|
|
429
401
|
};
|
|
430
402
|
this.setMonth = (date, month) => {
|
|
431
|
-
var _a
|
|
432
|
-
return ((
|
|
403
|
+
var _a;
|
|
404
|
+
return ((_a = this.overrides) == null ? void 0 : _a.setMonth) ? this.overrides.setMonth(date, month) : setMonth(date, month);
|
|
433
405
|
};
|
|
434
406
|
this.setYear = (date, year) => {
|
|
435
|
-
var _a
|
|
436
|
-
return ((
|
|
407
|
+
var _a;
|
|
408
|
+
return ((_a = this.overrides) == null ? void 0 : _a.setYear) ? this.overrides.setYear(date, year) : setYear(date, year);
|
|
437
409
|
};
|
|
438
|
-
this.startOfBroadcastWeek = (date,
|
|
439
|
-
var _a
|
|
440
|
-
return ((
|
|
410
|
+
this.startOfBroadcastWeek = (date, _dateLib) => {
|
|
411
|
+
var _a;
|
|
412
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfBroadcastWeek) ? this.overrides.startOfBroadcastWeek(date, this) : startOfBroadcastWeek(date, this);
|
|
441
413
|
};
|
|
442
414
|
this.startOfDay = (date) => {
|
|
443
|
-
var _a
|
|
444
|
-
return ((
|
|
415
|
+
var _a;
|
|
416
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfDay) ? this.overrides.startOfDay(date) : startOfDay(date);
|
|
445
417
|
};
|
|
446
418
|
this.startOfISOWeek = (date) => {
|
|
447
|
-
var _a
|
|
448
|
-
return ((
|
|
419
|
+
var _a;
|
|
420
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfISOWeek) ? this.overrides.startOfISOWeek(date) : startOfISOWeek(date);
|
|
449
421
|
};
|
|
450
422
|
this.startOfMonth = (date) => {
|
|
451
|
-
var _a
|
|
452
|
-
return ((
|
|
423
|
+
var _a;
|
|
424
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfMonth) ? this.overrides.startOfMonth(date) : startOfMonth(date);
|
|
453
425
|
};
|
|
454
|
-
this.startOfWeek = (date) => {
|
|
455
|
-
var _a
|
|
456
|
-
return ((
|
|
426
|
+
this.startOfWeek = (date, _options) => {
|
|
427
|
+
var _a;
|
|
428
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfWeek) ? this.overrides.startOfWeek(date, this.options) : startOfWeek(date, this.options);
|
|
457
429
|
};
|
|
458
430
|
this.startOfYear = (date) => {
|
|
459
|
-
var _a
|
|
460
|
-
return ((
|
|
431
|
+
var _a;
|
|
432
|
+
return ((_a = this.overrides) == null ? void 0 : _a.startOfYear) ? this.overrides.startOfYear(date) : startOfYear(date);
|
|
461
433
|
};
|
|
462
434
|
this.options = { locale: enUS, ...options };
|
|
463
435
|
this.overrides = overrides;
|
|
464
436
|
}
|
|
465
437
|
/**
|
|
466
|
-
*
|
|
438
|
+
* Generates a mapping of Arabic digits (0-9) to the target numbering system
|
|
439
|
+
* digits.
|
|
467
440
|
*
|
|
468
441
|
* @since 9.5.0
|
|
442
|
+
* @returns A record mapping Arabic digits to the target numerals.
|
|
469
443
|
*/
|
|
470
444
|
getDigitMap() {
|
|
471
445
|
const { numerals = "latn" } = this.options;
|
|
@@ -479,38 +453,57 @@ class DateLib {
|
|
|
479
453
|
return digitMap;
|
|
480
454
|
}
|
|
481
455
|
/**
|
|
482
|
-
*
|
|
456
|
+
* Replaces Arabic digits in a string with the target numbering system digits.
|
|
483
457
|
*
|
|
484
458
|
* @since 9.5.0
|
|
459
|
+
* @param input The string containing Arabic digits.
|
|
460
|
+
* @returns The string with digits replaced.
|
|
485
461
|
*/
|
|
486
462
|
replaceDigits(input) {
|
|
487
463
|
const digitMap = this.getDigitMap();
|
|
488
464
|
return input.replace(/\d/g, (digit) => digitMap[digit] || digit);
|
|
489
465
|
}
|
|
490
466
|
/**
|
|
491
|
-
*
|
|
467
|
+
* Formats a number using the configured numbering system.
|
|
492
468
|
*
|
|
493
469
|
* @since 9.5.0
|
|
494
470
|
* @param value The number to format.
|
|
495
|
-
* @returns The formatted number.
|
|
471
|
+
* @returns The formatted number as a string.
|
|
496
472
|
*/
|
|
497
473
|
formatNumber(value) {
|
|
498
474
|
return this.replaceDigits(value.toString());
|
|
499
475
|
}
|
|
500
476
|
}
|
|
501
477
|
const defaultDateLib = new DateLib();
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
478
|
+
class CalendarDay {
|
|
479
|
+
constructor(date, displayMonth, dateLib = defaultDateLib) {
|
|
480
|
+
this.date = date;
|
|
481
|
+
this.displayMonth = displayMonth;
|
|
482
|
+
this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
|
|
483
|
+
this.dateLib = dateLib;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Checks if this day is equal to another `CalendarDay`, considering both the
|
|
487
|
+
* date and the displayed month.
|
|
488
|
+
*
|
|
489
|
+
* @param day The `CalendarDay` to compare with.
|
|
490
|
+
* @returns `true` if the days are equal, otherwise `false`.
|
|
491
|
+
*/
|
|
492
|
+
isEqualTo(day) {
|
|
493
|
+
return this.dateLib.isSameDay(day.date, this.date) && this.dateLib.isSameMonth(day.displayMonth, this.displayMonth);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
class CalendarMonth {
|
|
497
|
+
constructor(month, weeks) {
|
|
498
|
+
this.date = month;
|
|
499
|
+
this.weeks = weeks;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
class CalendarWeek {
|
|
503
|
+
constructor(weekNumber, days) {
|
|
504
|
+
this.days = days;
|
|
505
|
+
this.weekNumber = weekNumber;
|
|
506
|
+
}
|
|
514
507
|
}
|
|
515
508
|
function Button(props) {
|
|
516
509
|
return React.createElement("button", { ...props });
|
|
@@ -520,13 +513,16 @@ function CaptionLabel(props) {
|
|
|
520
513
|
}
|
|
521
514
|
function Chevron(props) {
|
|
522
515
|
const { size = 24, orientation = "left", className } = props;
|
|
523
|
-
return
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
516
|
+
return (
|
|
517
|
+
// biome-ignore lint/a11y/noSvgWithoutTitle: handled by the parent component
|
|
518
|
+
React.createElement(
|
|
519
|
+
"svg",
|
|
520
|
+
{ className, width: size, height: size, viewBox: "0 0 24 24" },
|
|
521
|
+
orientation === "up" && React.createElement("polygon", { points: "6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" }),
|
|
522
|
+
orientation === "down" && React.createElement("polygon", { points: "6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72" }),
|
|
523
|
+
orientation === "left" && React.createElement("polygon", { points: "16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" }),
|
|
524
|
+
orientation === "right" && React.createElement("polygon", { points: "8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20" })
|
|
525
|
+
)
|
|
530
526
|
);
|
|
531
527
|
}
|
|
532
528
|
function Day(props) {
|
|
@@ -543,6 +539,59 @@ function DayButton(props) {
|
|
|
543
539
|
}, [modifiers.focused]);
|
|
544
540
|
return React.createElement("button", { ref, ...buttonProps });
|
|
545
541
|
}
|
|
542
|
+
var UI;
|
|
543
|
+
(function(UI2) {
|
|
544
|
+
UI2["Root"] = "root";
|
|
545
|
+
UI2["Chevron"] = "chevron";
|
|
546
|
+
UI2["Day"] = "day";
|
|
547
|
+
UI2["DayButton"] = "day_button";
|
|
548
|
+
UI2["CaptionLabel"] = "caption_label";
|
|
549
|
+
UI2["Dropdowns"] = "dropdowns";
|
|
550
|
+
UI2["Dropdown"] = "dropdown";
|
|
551
|
+
UI2["DropdownRoot"] = "dropdown_root";
|
|
552
|
+
UI2["Footer"] = "footer";
|
|
553
|
+
UI2["MonthGrid"] = "month_grid";
|
|
554
|
+
UI2["MonthCaption"] = "month_caption";
|
|
555
|
+
UI2["MonthsDropdown"] = "months_dropdown";
|
|
556
|
+
UI2["Month"] = "month";
|
|
557
|
+
UI2["Months"] = "months";
|
|
558
|
+
UI2["Nav"] = "nav";
|
|
559
|
+
UI2["NextMonthButton"] = "button_next";
|
|
560
|
+
UI2["PreviousMonthButton"] = "button_previous";
|
|
561
|
+
UI2["Week"] = "week";
|
|
562
|
+
UI2["Weeks"] = "weeks";
|
|
563
|
+
UI2["Weekday"] = "weekday";
|
|
564
|
+
UI2["Weekdays"] = "weekdays";
|
|
565
|
+
UI2["WeekNumber"] = "week_number";
|
|
566
|
+
UI2["WeekNumberHeader"] = "week_number_header";
|
|
567
|
+
UI2["YearsDropdown"] = "years_dropdown";
|
|
568
|
+
})(UI || (UI = {}));
|
|
569
|
+
var DayFlag;
|
|
570
|
+
(function(DayFlag2) {
|
|
571
|
+
DayFlag2["disabled"] = "disabled";
|
|
572
|
+
DayFlag2["hidden"] = "hidden";
|
|
573
|
+
DayFlag2["outside"] = "outside";
|
|
574
|
+
DayFlag2["focused"] = "focused";
|
|
575
|
+
DayFlag2["today"] = "today";
|
|
576
|
+
})(DayFlag || (DayFlag = {}));
|
|
577
|
+
var SelectionState;
|
|
578
|
+
(function(SelectionState2) {
|
|
579
|
+
SelectionState2["range_end"] = "range_end";
|
|
580
|
+
SelectionState2["range_middle"] = "range_middle";
|
|
581
|
+
SelectionState2["range_start"] = "range_start";
|
|
582
|
+
SelectionState2["selected"] = "selected";
|
|
583
|
+
})(SelectionState || (SelectionState = {}));
|
|
584
|
+
var Animation;
|
|
585
|
+
(function(Animation2) {
|
|
586
|
+
Animation2["weeks_before_enter"] = "weeks_before_enter";
|
|
587
|
+
Animation2["weeks_before_exit"] = "weeks_before_exit";
|
|
588
|
+
Animation2["weeks_after_enter"] = "weeks_after_enter";
|
|
589
|
+
Animation2["weeks_after_exit"] = "weeks_after_exit";
|
|
590
|
+
Animation2["caption_after_enter"] = "caption_after_enter";
|
|
591
|
+
Animation2["caption_after_exit"] = "caption_after_exit";
|
|
592
|
+
Animation2["caption_before_enter"] = "caption_before_enter";
|
|
593
|
+
Animation2["caption_before_exit"] = "caption_before_exit";
|
|
594
|
+
})(Animation || (Animation = {}));
|
|
546
595
|
function Dropdown(props) {
|
|
547
596
|
const { options, className, components: components2, classNames: classNames2, ...selectProps } = props;
|
|
548
597
|
const cssClassSelect = [classNames2[UI.Dropdown], className].join(" ");
|
|
@@ -594,17 +643,27 @@ function MonthsDropdown(props) {
|
|
|
594
643
|
function Nav(props) {
|
|
595
644
|
const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props;
|
|
596
645
|
const { components: components2, classNames: classNames2, labels: { labelPrevious: labelPrevious2, labelNext: labelNext2 } } = useDayPicker();
|
|
646
|
+
const handleNextClick = useCallback((e) => {
|
|
647
|
+
if (nextMonth) {
|
|
648
|
+
onNextClick == null ? void 0 : onNextClick(e);
|
|
649
|
+
}
|
|
650
|
+
}, [nextMonth, onNextClick]);
|
|
651
|
+
const handlePreviousClick = useCallback((e) => {
|
|
652
|
+
if (previousMonth) {
|
|
653
|
+
onPreviousClick == null ? void 0 : onPreviousClick(e);
|
|
654
|
+
}
|
|
655
|
+
}, [previousMonth, onPreviousClick]);
|
|
597
656
|
return React.createElement(
|
|
598
657
|
"nav",
|
|
599
658
|
{ ...navProps },
|
|
600
659
|
React.createElement(
|
|
601
660
|
components2.PreviousMonthButton,
|
|
602
|
-
{ type: "button", className: classNames2[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, disabled: previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick:
|
|
661
|
+
{ type: "button", className: classNames2[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, "aria-disabled": previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick: handlePreviousClick },
|
|
603
662
|
React.createElement(components2.Chevron, { disabled: previousMonth ? void 0 : true, className: classNames2[UI.Chevron], orientation: "left" })
|
|
604
663
|
),
|
|
605
664
|
React.createElement(
|
|
606
665
|
components2.NextMonthButton,
|
|
607
|
-
{ type: "button", className: classNames2[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, disabled: nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick:
|
|
666
|
+
{ type: "button", className: classNames2[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, "aria-disabled": nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick: handleNextClick },
|
|
608
667
|
React.createElement(components2.Chevron, { disabled: nextMonth ? void 0 : true, orientation: "right", className: classNames2[UI.Chevron] })
|
|
609
668
|
)
|
|
610
669
|
);
|
|
@@ -621,7 +680,8 @@ function PreviousMonthButton(props) {
|
|
|
621
680
|
return React.createElement(components2.Button, { ...props });
|
|
622
681
|
}
|
|
623
682
|
function Root(props) {
|
|
624
|
-
|
|
683
|
+
const { rootRef, ...rest } = props;
|
|
684
|
+
return React.createElement("div", { ...rest, ref: rootRef });
|
|
625
685
|
}
|
|
626
686
|
function Select(props) {
|
|
627
687
|
return React.createElement("select", { ...props });
|
|
@@ -683,6 +743,169 @@ const components = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
683
743
|
Weeks,
|
|
684
744
|
YearsDropdown
|
|
685
745
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
746
|
+
function rangeIncludesDate(range, date, excludeEnds = false, dateLib = defaultDateLib) {
|
|
747
|
+
let { from, to } = range;
|
|
748
|
+
const { differenceInCalendarDays: differenceInCalendarDays2, isSameDay: isSameDay2 } = dateLib;
|
|
749
|
+
if (from && to) {
|
|
750
|
+
const isRangeInverted = differenceInCalendarDays2(to, from) < 0;
|
|
751
|
+
if (isRangeInverted) {
|
|
752
|
+
[from, to] = [to, from];
|
|
753
|
+
}
|
|
754
|
+
const isInRange = differenceInCalendarDays2(date, from) >= (excludeEnds ? 1 : 0) && differenceInCalendarDays2(to, date) >= (excludeEnds ? 1 : 0);
|
|
755
|
+
return isInRange;
|
|
756
|
+
}
|
|
757
|
+
if (!excludeEnds && to) {
|
|
758
|
+
return isSameDay2(to, date);
|
|
759
|
+
}
|
|
760
|
+
if (!excludeEnds && from) {
|
|
761
|
+
return isSameDay2(from, date);
|
|
762
|
+
}
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
function isDateInterval(matcher) {
|
|
766
|
+
return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
|
|
767
|
+
}
|
|
768
|
+
function isDateRange(value) {
|
|
769
|
+
return Boolean(value && typeof value === "object" && "from" in value);
|
|
770
|
+
}
|
|
771
|
+
function isDateAfterType(value) {
|
|
772
|
+
return Boolean(value && typeof value === "object" && "after" in value);
|
|
773
|
+
}
|
|
774
|
+
function isDateBeforeType(value) {
|
|
775
|
+
return Boolean(value && typeof value === "object" && "before" in value);
|
|
776
|
+
}
|
|
777
|
+
function isDayOfWeekType(value) {
|
|
778
|
+
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
|
779
|
+
}
|
|
780
|
+
function isDatesArray(value, dateLib) {
|
|
781
|
+
return Array.isArray(value) && value.every(dateLib.isDate);
|
|
782
|
+
}
|
|
783
|
+
function dateMatchModifiers(date, matchers, dateLib = defaultDateLib) {
|
|
784
|
+
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
|
785
|
+
const { isSameDay: isSameDay2, differenceInCalendarDays: differenceInCalendarDays2, isAfter: isAfter2 } = dateLib;
|
|
786
|
+
return matchersArr.some((matcher) => {
|
|
787
|
+
if (typeof matcher === "boolean") {
|
|
788
|
+
return matcher;
|
|
789
|
+
}
|
|
790
|
+
if (dateLib.isDate(matcher)) {
|
|
791
|
+
return isSameDay2(date, matcher);
|
|
792
|
+
}
|
|
793
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
794
|
+
return matcher.includes(date);
|
|
795
|
+
}
|
|
796
|
+
if (isDateRange(matcher)) {
|
|
797
|
+
return rangeIncludesDate(matcher, date, false, dateLib);
|
|
798
|
+
}
|
|
799
|
+
if (isDayOfWeekType(matcher)) {
|
|
800
|
+
if (!Array.isArray(matcher.dayOfWeek)) {
|
|
801
|
+
return matcher.dayOfWeek === date.getDay();
|
|
802
|
+
}
|
|
803
|
+
return matcher.dayOfWeek.includes(date.getDay());
|
|
804
|
+
}
|
|
805
|
+
if (isDateInterval(matcher)) {
|
|
806
|
+
const diffBefore = differenceInCalendarDays2(matcher.before, date);
|
|
807
|
+
const diffAfter = differenceInCalendarDays2(matcher.after, date);
|
|
808
|
+
const isDayBefore = diffBefore > 0;
|
|
809
|
+
const isDayAfter = diffAfter < 0;
|
|
810
|
+
const isClosedInterval = isAfter2(matcher.before, matcher.after);
|
|
811
|
+
if (isClosedInterval) {
|
|
812
|
+
return isDayAfter && isDayBefore;
|
|
813
|
+
} else {
|
|
814
|
+
return isDayBefore || isDayAfter;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (isDateAfterType(matcher)) {
|
|
818
|
+
return differenceInCalendarDays2(date, matcher.after) > 0;
|
|
819
|
+
}
|
|
820
|
+
if (isDateBeforeType(matcher)) {
|
|
821
|
+
return differenceInCalendarDays2(matcher.before, date) > 0;
|
|
822
|
+
}
|
|
823
|
+
if (typeof matcher === "function") {
|
|
824
|
+
return matcher(date);
|
|
825
|
+
}
|
|
826
|
+
return false;
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
function createGetModifiers(days, props, navStart, navEnd, dateLib) {
|
|
830
|
+
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today } = props;
|
|
831
|
+
const { isSameDay: isSameDay2, isSameMonth: isSameMonth2, startOfMonth: startOfMonth2, isBefore: isBefore2, endOfMonth: endOfMonth2, isAfter: isAfter2 } = dateLib;
|
|
832
|
+
const computedNavStart = navStart && startOfMonth2(navStart);
|
|
833
|
+
const computedNavEnd = navEnd && endOfMonth2(navEnd);
|
|
834
|
+
const internalModifiersMap = {
|
|
835
|
+
[DayFlag.focused]: [],
|
|
836
|
+
[DayFlag.outside]: [],
|
|
837
|
+
[DayFlag.disabled]: [],
|
|
838
|
+
[DayFlag.hidden]: [],
|
|
839
|
+
[DayFlag.today]: []
|
|
840
|
+
};
|
|
841
|
+
const customModifiersMap = {};
|
|
842
|
+
for (const day of days) {
|
|
843
|
+
const { date, displayMonth } = day;
|
|
844
|
+
const isOutside = Boolean(displayMonth && !isSameMonth2(date, displayMonth));
|
|
845
|
+
const isBeforeNavStart = Boolean(computedNavStart && isBefore2(date, computedNavStart));
|
|
846
|
+
const isAfterNavEnd = Boolean(computedNavEnd && isAfter2(date, computedNavEnd));
|
|
847
|
+
const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
|
|
848
|
+
const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeNavStart || isAfterNavEnd || // Broadcast calendar will show outside days as default
|
|
849
|
+
!broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
|
|
850
|
+
const isToday = isSameDay2(date, today ?? dateLib.today());
|
|
851
|
+
if (isOutside)
|
|
852
|
+
internalModifiersMap.outside.push(day);
|
|
853
|
+
if (isDisabled)
|
|
854
|
+
internalModifiersMap.disabled.push(day);
|
|
855
|
+
if (isHidden)
|
|
856
|
+
internalModifiersMap.hidden.push(day);
|
|
857
|
+
if (isToday)
|
|
858
|
+
internalModifiersMap.today.push(day);
|
|
859
|
+
if (modifiers) {
|
|
860
|
+
Object.keys(modifiers).forEach((name) => {
|
|
861
|
+
const modifierValue = modifiers == null ? void 0 : modifiers[name];
|
|
862
|
+
const isMatch = modifierValue ? dateMatchModifiers(date, modifierValue, dateLib) : false;
|
|
863
|
+
if (!isMatch)
|
|
864
|
+
return;
|
|
865
|
+
if (customModifiersMap[name]) {
|
|
866
|
+
customModifiersMap[name].push(day);
|
|
867
|
+
} else {
|
|
868
|
+
customModifiersMap[name] = [day];
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return (day) => {
|
|
874
|
+
const dayFlags = {
|
|
875
|
+
[DayFlag.focused]: false,
|
|
876
|
+
[DayFlag.disabled]: false,
|
|
877
|
+
[DayFlag.hidden]: false,
|
|
878
|
+
[DayFlag.outside]: false,
|
|
879
|
+
[DayFlag.today]: false
|
|
880
|
+
};
|
|
881
|
+
const customModifiers = {};
|
|
882
|
+
for (const name in internalModifiersMap) {
|
|
883
|
+
const days2 = internalModifiersMap[name];
|
|
884
|
+
dayFlags[name] = days2.some((d) => d === day);
|
|
885
|
+
}
|
|
886
|
+
for (const name in customModifiersMap) {
|
|
887
|
+
customModifiers[name] = customModifiersMap[name].some((d) => d === day);
|
|
888
|
+
}
|
|
889
|
+
return {
|
|
890
|
+
...dayFlags,
|
|
891
|
+
// custom modifiers should override all the previous ones
|
|
892
|
+
...customModifiers
|
|
893
|
+
};
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function getClassNamesForModifiers(modifiers, classNames2, modifiersClassNames = {}) {
|
|
897
|
+
const modifierClassNames = Object.entries(modifiers).filter(([, active]) => active === true).reduce((previousValue, [key]) => {
|
|
898
|
+
if (modifiersClassNames[key]) {
|
|
899
|
+
previousValue.push(modifiersClassNames[key]);
|
|
900
|
+
} else if (classNames2[DayFlag[key]]) {
|
|
901
|
+
previousValue.push(classNames2[DayFlag[key]]);
|
|
902
|
+
} else if (classNames2[SelectionState[key]]) {
|
|
903
|
+
previousValue.push(classNames2[SelectionState[key]]);
|
|
904
|
+
}
|
|
905
|
+
return previousValue;
|
|
906
|
+
}, [classNames2[UI.Day]]);
|
|
907
|
+
return modifierClassNames;
|
|
908
|
+
}
|
|
686
909
|
function getComponents(customComponents) {
|
|
687
910
|
return {
|
|
688
911
|
...components,
|
|
@@ -695,7 +918,8 @@ function getDataAttributes(props) {
|
|
|
695
918
|
"data-required": "required" in props ? props.required : void 0,
|
|
696
919
|
"data-multiple-months": props.numberOfMonths && props.numberOfMonths > 1 || void 0,
|
|
697
920
|
"data-week-numbers": props.showWeekNumber || void 0,
|
|
698
|
-
"data-broadcast-calendar": props.broadcastCalendar || void 0
|
|
921
|
+
"data-broadcast-calendar": props.broadcastCalendar || void 0,
|
|
922
|
+
"data-nav-layout": props.navLayout || void 0
|
|
699
923
|
};
|
|
700
924
|
Object.entries(props).forEach(([key, val]) => {
|
|
701
925
|
if (key.startsWith("data-")) {
|
|
@@ -715,6 +939,9 @@ function getDefaultClassNames() {
|
|
|
715
939
|
for (const key in SelectionState) {
|
|
716
940
|
classNames2[SelectionState[key]] = `rdp-${SelectionState[key]}`;
|
|
717
941
|
}
|
|
942
|
+
for (const key in Animation) {
|
|
943
|
+
classNames2[Animation[key]] = `rdp-${Animation[key]}`;
|
|
944
|
+
}
|
|
718
945
|
return classNames2;
|
|
719
946
|
}
|
|
720
947
|
function formatCaption(month, options, dateLib) {
|
|
@@ -727,18 +954,18 @@ function formatDay(date, options, dateLib) {
|
|
|
727
954
|
function formatMonthDropdown(month, dateLib = defaultDateLib) {
|
|
728
955
|
return dateLib.format(month, "LLLL");
|
|
729
956
|
}
|
|
730
|
-
function
|
|
957
|
+
function formatWeekdayName(weekday, options, dateLib) {
|
|
958
|
+
return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
|
|
959
|
+
}
|
|
960
|
+
function formatWeekNumber(weekNumber, dateLib = defaultDateLib) {
|
|
731
961
|
if (weekNumber < 10) {
|
|
732
|
-
return `0${weekNumber.toLocaleString()}
|
|
962
|
+
return dateLib.formatNumber(`0${weekNumber.toLocaleString()}`);
|
|
733
963
|
}
|
|
734
|
-
return `${weekNumber.toLocaleString()}
|
|
964
|
+
return dateLib.formatNumber(`${weekNumber.toLocaleString()}`);
|
|
735
965
|
}
|
|
736
966
|
function formatWeekNumberHeader() {
|
|
737
967
|
return ``;
|
|
738
968
|
}
|
|
739
|
-
function formatWeekdayName(weekday, options, dateLib) {
|
|
740
|
-
return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
|
|
741
|
-
}
|
|
742
969
|
function formatYearDropdown(year, dateLib = defaultDateLib) {
|
|
743
970
|
return dateLib.format(year, "yyyy");
|
|
744
971
|
}
|
|
@@ -801,7 +1028,7 @@ function getWeekdays(dateLib, ISOWeek, broadcastCalendar) {
|
|
|
801
1028
|
}
|
|
802
1029
|
return days;
|
|
803
1030
|
}
|
|
804
|
-
function getYearOptions(navStart, navEnd, formatters, dateLib) {
|
|
1031
|
+
function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
|
|
805
1032
|
if (!navStart)
|
|
806
1033
|
return void 0;
|
|
807
1034
|
if (!navEnd)
|
|
@@ -815,6 +1042,8 @@ function getYearOptions(navStart, navEnd, formatters, dateLib) {
|
|
|
815
1042
|
years.push(year);
|
|
816
1043
|
year = addYears2(year, 1);
|
|
817
1044
|
}
|
|
1045
|
+
if (reverse)
|
|
1046
|
+
years.reverse();
|
|
818
1047
|
return years.map((year2) => {
|
|
819
1048
|
const label = formatters.formatYearDropdown(year2, dateLib);
|
|
820
1049
|
return {
|
|
@@ -824,6 +1053,15 @@ function getYearOptions(navStart, navEnd, formatters, dateLib) {
|
|
|
824
1053
|
};
|
|
825
1054
|
});
|
|
826
1055
|
}
|
|
1056
|
+
function labelDayButton(date, modifiers, options, dateLib) {
|
|
1057
|
+
let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
|
|
1058
|
+
if (modifiers.today)
|
|
1059
|
+
label = `Today, ${label}`;
|
|
1060
|
+
if (modifiers.selected)
|
|
1061
|
+
label = `${label}, selected`;
|
|
1062
|
+
return label;
|
|
1063
|
+
}
|
|
1064
|
+
const labelDay = labelDayButton;
|
|
827
1065
|
function labelGrid(date, options, dateLib) {
|
|
828
1066
|
return (dateLib ?? new DateLib(options)).format(date, "LLLL y");
|
|
829
1067
|
}
|
|
@@ -835,37 +1073,28 @@ function labelGridcell(date, modifiers, options, dateLib) {
|
|
|
835
1073
|
}
|
|
836
1074
|
return label;
|
|
837
1075
|
}
|
|
838
|
-
function
|
|
839
|
-
|
|
840
|
-
if (modifiers.today)
|
|
841
|
-
label = `Today, ${label}`;
|
|
842
|
-
if (modifiers.selected)
|
|
843
|
-
label = `${label}, selected`;
|
|
844
|
-
return label;
|
|
1076
|
+
function labelMonthDropdown(_options) {
|
|
1077
|
+
return "Choose the Month";
|
|
845
1078
|
}
|
|
846
|
-
const labelDay = labelDayButton;
|
|
847
1079
|
function labelNav() {
|
|
848
1080
|
return "";
|
|
849
1081
|
}
|
|
850
|
-
function
|
|
851
|
-
return "Choose the Month";
|
|
852
|
-
}
|
|
853
|
-
function labelNext(month) {
|
|
1082
|
+
function labelNext(_month) {
|
|
854
1083
|
return "Go to the Next Month";
|
|
855
1084
|
}
|
|
856
|
-
function labelPrevious(
|
|
1085
|
+
function labelPrevious(_month) {
|
|
857
1086
|
return "Go to the Previous Month";
|
|
858
1087
|
}
|
|
859
1088
|
function labelWeekday(date, options, dateLib) {
|
|
860
1089
|
return (dateLib ?? new DateLib(options)).format(date, "cccc");
|
|
861
1090
|
}
|
|
862
|
-
function labelWeekNumber(weekNumber,
|
|
1091
|
+
function labelWeekNumber(weekNumber, _options) {
|
|
863
1092
|
return `Week ${weekNumber}`;
|
|
864
1093
|
}
|
|
865
|
-
function labelWeekNumberHeader(
|
|
1094
|
+
function labelWeekNumberHeader(_options) {
|
|
866
1095
|
return "Week Number";
|
|
867
1096
|
}
|
|
868
|
-
function labelYearDropdown(
|
|
1097
|
+
function labelYearDropdown(_options) {
|
|
869
1098
|
return "Choose the Year";
|
|
870
1099
|
}
|
|
871
1100
|
const defaultLabels = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
@@ -884,13 +1113,136 @@ const defaultLabels = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defin
|
|
|
884
1113
|
labelWeekday,
|
|
885
1114
|
labelYearDropdown
|
|
886
1115
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1116
|
+
const asHtmlElement = (element) => {
|
|
1117
|
+
if (element instanceof HTMLElement)
|
|
1118
|
+
return element;
|
|
1119
|
+
return null;
|
|
1120
|
+
};
|
|
1121
|
+
const queryMonthEls = (element) => [
|
|
1122
|
+
...element.querySelectorAll("[data-animated-month]") ?? []
|
|
1123
|
+
];
|
|
1124
|
+
const queryMonthEl = (element) => asHtmlElement(element.querySelector("[data-animated-month]"));
|
|
1125
|
+
const queryCaptionEl = (element) => asHtmlElement(element.querySelector("[data-animated-caption]"));
|
|
1126
|
+
const queryWeeksEl = (element) => asHtmlElement(element.querySelector("[data-animated-weeks]"));
|
|
1127
|
+
const queryNavEl = (element) => asHtmlElement(element.querySelector("[data-animated-nav]"));
|
|
1128
|
+
const queryWeekdaysEl = (element) => asHtmlElement(element.querySelector("[data-animated-weekdays]"));
|
|
1129
|
+
function useAnimation(rootElRef, enabled, { classNames: classNames2, months, focused, dateLib }) {
|
|
1130
|
+
const previousRootElSnapshotRef = useRef(null);
|
|
1131
|
+
const previousMonthsRef = useRef(months);
|
|
1132
|
+
const animatingRef = useRef(false);
|
|
1133
|
+
useLayoutEffect(() => {
|
|
1134
|
+
const previousMonths = previousMonthsRef.current;
|
|
1135
|
+
previousMonthsRef.current = months;
|
|
1136
|
+
if (!enabled || !rootElRef.current || // safety check because the ref can be set to anything by consumers
|
|
1137
|
+
!(rootElRef.current instanceof HTMLElement) || // validation required for the animation to work as expected
|
|
1138
|
+
months.length === 0 || previousMonths.length === 0 || months.length !== previousMonths.length) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
const isSameMonth2 = dateLib.isSameMonth(months[0].date, previousMonths[0].date);
|
|
1142
|
+
const isAfterPreviousMonth = dateLib.isAfter(months[0].date, previousMonths[0].date);
|
|
1143
|
+
const captionAnimationClass = isAfterPreviousMonth ? classNames2[Animation.caption_after_enter] : classNames2[Animation.caption_before_enter];
|
|
1144
|
+
const weeksAnimationClass = isAfterPreviousMonth ? classNames2[Animation.weeks_after_enter] : classNames2[Animation.weeks_before_enter];
|
|
1145
|
+
const previousRootElSnapshot = previousRootElSnapshotRef.current;
|
|
1146
|
+
const rootElSnapshot = rootElRef.current.cloneNode(true);
|
|
1147
|
+
if (rootElSnapshot instanceof HTMLElement) {
|
|
1148
|
+
const currentMonthElsSnapshot = queryMonthEls(rootElSnapshot);
|
|
1149
|
+
currentMonthElsSnapshot.forEach((currentMonthElSnapshot) => {
|
|
1150
|
+
if (!(currentMonthElSnapshot instanceof HTMLElement))
|
|
1151
|
+
return;
|
|
1152
|
+
const previousMonthElSnapshot = queryMonthEl(currentMonthElSnapshot);
|
|
1153
|
+
if (previousMonthElSnapshot && currentMonthElSnapshot.contains(previousMonthElSnapshot)) {
|
|
1154
|
+
currentMonthElSnapshot.removeChild(previousMonthElSnapshot);
|
|
1155
|
+
}
|
|
1156
|
+
const captionEl = queryCaptionEl(currentMonthElSnapshot);
|
|
1157
|
+
if (captionEl) {
|
|
1158
|
+
captionEl.classList.remove(captionAnimationClass);
|
|
1159
|
+
}
|
|
1160
|
+
const weeksEl = queryWeeksEl(currentMonthElSnapshot);
|
|
1161
|
+
if (weeksEl) {
|
|
1162
|
+
weeksEl.classList.remove(weeksAnimationClass);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
previousRootElSnapshotRef.current = rootElSnapshot;
|
|
1166
|
+
} else {
|
|
1167
|
+
previousRootElSnapshotRef.current = null;
|
|
1168
|
+
}
|
|
1169
|
+
if (animatingRef.current || isSameMonth2 || // skip animation if a day is focused because it can cause issues to the animation and is better for a11y
|
|
1170
|
+
focused) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const previousMonthEls = previousRootElSnapshot instanceof HTMLElement ? queryMonthEls(previousRootElSnapshot) : [];
|
|
1174
|
+
const currentMonthEls = queryMonthEls(rootElRef.current);
|
|
1175
|
+
if ((currentMonthEls == null ? void 0 : currentMonthEls.every((el) => el instanceof HTMLElement)) && previousMonthEls && previousMonthEls.every((el) => el instanceof HTMLElement)) {
|
|
1176
|
+
animatingRef.current = true;
|
|
1177
|
+
rootElRef.current.style.isolation = "isolate";
|
|
1178
|
+
const navEl = queryNavEl(rootElRef.current);
|
|
1179
|
+
if (navEl) {
|
|
1180
|
+
navEl.style.zIndex = "1";
|
|
1181
|
+
}
|
|
1182
|
+
currentMonthEls.forEach((currentMonthEl, index) => {
|
|
1183
|
+
const previousMonthEl = previousMonthEls[index];
|
|
1184
|
+
if (!previousMonthEl) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
currentMonthEl.style.position = "relative";
|
|
1188
|
+
currentMonthEl.style.overflow = "hidden";
|
|
1189
|
+
const captionEl = queryCaptionEl(currentMonthEl);
|
|
1190
|
+
if (captionEl) {
|
|
1191
|
+
captionEl.classList.add(captionAnimationClass);
|
|
1192
|
+
}
|
|
1193
|
+
const weeksEl = queryWeeksEl(currentMonthEl);
|
|
1194
|
+
if (weeksEl) {
|
|
1195
|
+
weeksEl.classList.add(weeksAnimationClass);
|
|
1196
|
+
}
|
|
1197
|
+
const cleanUp = () => {
|
|
1198
|
+
animatingRef.current = false;
|
|
1199
|
+
if (rootElRef.current) {
|
|
1200
|
+
rootElRef.current.style.isolation = "";
|
|
1201
|
+
}
|
|
1202
|
+
if (navEl) {
|
|
1203
|
+
navEl.style.zIndex = "";
|
|
1204
|
+
}
|
|
1205
|
+
if (captionEl) {
|
|
1206
|
+
captionEl.classList.remove(captionAnimationClass);
|
|
1207
|
+
}
|
|
1208
|
+
if (weeksEl) {
|
|
1209
|
+
weeksEl.classList.remove(weeksAnimationClass);
|
|
1210
|
+
}
|
|
1211
|
+
currentMonthEl.style.position = "";
|
|
1212
|
+
currentMonthEl.style.overflow = "";
|
|
1213
|
+
if (currentMonthEl.contains(previousMonthEl)) {
|
|
1214
|
+
currentMonthEl.removeChild(previousMonthEl);
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
previousMonthEl.style.pointerEvents = "none";
|
|
1218
|
+
previousMonthEl.style.position = "absolute";
|
|
1219
|
+
previousMonthEl.style.overflow = "hidden";
|
|
1220
|
+
previousMonthEl.setAttribute("aria-hidden", "true");
|
|
1221
|
+
const previousWeekdaysEl = queryWeekdaysEl(previousMonthEl);
|
|
1222
|
+
if (previousWeekdaysEl) {
|
|
1223
|
+
previousWeekdaysEl.style.opacity = "0";
|
|
1224
|
+
}
|
|
1225
|
+
const previousCaptionEl = queryCaptionEl(previousMonthEl);
|
|
1226
|
+
if (previousCaptionEl) {
|
|
1227
|
+
previousCaptionEl.classList.add(isAfterPreviousMonth ? classNames2[Animation.caption_before_exit] : classNames2[Animation.caption_after_exit]);
|
|
1228
|
+
previousCaptionEl.addEventListener("animationend", cleanUp);
|
|
1229
|
+
}
|
|
1230
|
+
const previousWeeksEl = queryWeeksEl(previousMonthEl);
|
|
1231
|
+
if (previousWeeksEl) {
|
|
1232
|
+
previousWeeksEl.classList.add(isAfterPreviousMonth ? classNames2[Animation.weeks_before_exit] : classNames2[Animation.weeks_after_exit]);
|
|
1233
|
+
}
|
|
1234
|
+
currentMonthEl.insertBefore(previousMonthEl, currentMonthEl.firstChild);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
887
1239
|
function getDates(displayMonths, maxDate, props, dateLib) {
|
|
888
1240
|
const firstMonth = displayMonths[0];
|
|
889
1241
|
const lastMonth = displayMonths[displayMonths.length - 1];
|
|
890
1242
|
const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
|
|
891
1243
|
const { addDays: addDays2, differenceInCalendarDays: differenceInCalendarDays2, differenceInCalendarMonths: differenceInCalendarMonths2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, isAfter: isAfter2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
892
1244
|
const startWeekFirstDate = broadcastCalendar ? startOfBroadcastWeek2(firstMonth, dateLib) : ISOWeek ? startOfISOWeek2(firstMonth) : startOfWeek2(firstMonth);
|
|
893
|
-
const endWeekLastDate = broadcastCalendar ? endOfBroadcastWeek2(lastMonth
|
|
1245
|
+
const endWeekLastDate = broadcastCalendar ? endOfBroadcastWeek2(lastMonth) : ISOWeek ? endOfISOWeek2(endOfMonth2(lastMonth)) : endOfWeek2(endOfMonth2(lastMonth));
|
|
894
1246
|
const nOfDays = differenceInCalendarDays2(endWeekLastDate, startWeekFirstDate);
|
|
895
1247
|
const nOfMonths = differenceInCalendarMonths2(lastMonth, firstMonth) + 1;
|
|
896
1248
|
const dates = [];
|
|
@@ -915,12 +1267,11 @@ function getDates(displayMonths, maxDate, props, dateLib) {
|
|
|
915
1267
|
function getDays(calendarMonths) {
|
|
916
1268
|
const initialDays = [];
|
|
917
1269
|
return calendarMonths.reduce((days, month) => {
|
|
918
|
-
const initialDays2 = [];
|
|
919
1270
|
const weekDays = month.weeks.reduce((weekDays2, week) => {
|
|
920
|
-
return
|
|
921
|
-
},
|
|
922
|
-
return
|
|
923
|
-
}, initialDays);
|
|
1271
|
+
return weekDays2.concat(week.days.slice());
|
|
1272
|
+
}, initialDays.slice());
|
|
1273
|
+
return days.concat(weekDays.slice());
|
|
1274
|
+
}, initialDays.slice());
|
|
924
1275
|
}
|
|
925
1276
|
function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib) {
|
|
926
1277
|
const { numberOfMonths = 1 } = props;
|
|
@@ -934,51 +1285,24 @@ function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib)
|
|
|
934
1285
|
}
|
|
935
1286
|
return months;
|
|
936
1287
|
}
|
|
937
|
-
function getInitialMonth(props, dateLib) {
|
|
938
|
-
const { month, defaultMonth, today = dateLib.today(), numberOfMonths = 1
|
|
1288
|
+
function getInitialMonth(props, navStart, navEnd, dateLib) {
|
|
1289
|
+
const { month, defaultMonth, today = dateLib.today(), numberOfMonths = 1 } = props;
|
|
939
1290
|
let initialMonth = month || defaultMonth || today;
|
|
940
1291
|
const { differenceInCalendarMonths: differenceInCalendarMonths2, addMonths: addMonths2, startOfMonth: startOfMonth2 } = dateLib;
|
|
941
|
-
if (
|
|
1292
|
+
if (navEnd && differenceInCalendarMonths2(navEnd, initialMonth) < numberOfMonths - 1) {
|
|
942
1293
|
const offset = -1 * (numberOfMonths - 1);
|
|
943
|
-
initialMonth = addMonths2(
|
|
1294
|
+
initialMonth = addMonths2(navEnd, offset);
|
|
944
1295
|
}
|
|
945
|
-
if (
|
|
946
|
-
initialMonth =
|
|
1296
|
+
if (navStart && differenceInCalendarMonths2(initialMonth, navStart) < 0) {
|
|
1297
|
+
initialMonth = navStart;
|
|
947
1298
|
}
|
|
948
1299
|
return startOfMonth2(initialMonth);
|
|
949
1300
|
}
|
|
950
|
-
class CalendarDay {
|
|
951
|
-
constructor(date, displayMonth, dateLib = defaultDateLib) {
|
|
952
|
-
this.date = date;
|
|
953
|
-
this.displayMonth = displayMonth;
|
|
954
|
-
this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
|
|
955
|
-
this.dateLib = dateLib;
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Check if the day is the same as the given day: considering if it is in the
|
|
959
|
-
* same display month.
|
|
960
|
-
*/
|
|
961
|
-
isEqualTo(day) {
|
|
962
|
-
return this.dateLib.isSameDay(day.date, this.date) && this.dateLib.isSameMonth(day.displayMonth, this.displayMonth);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
class CalendarMonth {
|
|
966
|
-
constructor(month, weeks) {
|
|
967
|
-
this.date = month;
|
|
968
|
-
this.weeks = weeks;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
class CalendarWeek {
|
|
972
|
-
constructor(weekNumber, days) {
|
|
973
|
-
this.days = days;
|
|
974
|
-
this.weekNumber = weekNumber;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
1301
|
function getMonths(displayMonths, dates, props, dateLib) {
|
|
978
1302
|
const { addDays: addDays2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, getISOWeek: getISOWeek2, getWeek: getWeek2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
979
1303
|
const dayPickerMonths = displayMonths.reduce((months, month) => {
|
|
980
1304
|
const firstDateOfFirstWeek = props.broadcastCalendar ? startOfBroadcastWeek2(month, dateLib) : props.ISOWeek ? startOfISOWeek2(month) : startOfWeek2(month);
|
|
981
|
-
const lastDateOfLastWeek = props.broadcastCalendar ? endOfBroadcastWeek2(month
|
|
1305
|
+
const lastDateOfLastWeek = props.broadcastCalendar ? endOfBroadcastWeek2(month) : props.ISOWeek ? endOfISOWeek2(endOfMonth2(month)) : endOfWeek2(endOfMonth2(month));
|
|
982
1306
|
const monthDates = dates.filter((date) => {
|
|
983
1307
|
return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
|
|
984
1308
|
});
|
|
@@ -1084,8 +1408,8 @@ function getPreviousMonth(firstDisplayedMonth, calendarStartMonth, options, date
|
|
|
1084
1408
|
function getWeeks(months) {
|
|
1085
1409
|
const initialWeeks = [];
|
|
1086
1410
|
return months.reduce((weeks, month) => {
|
|
1087
|
-
return
|
|
1088
|
-
}, initialWeeks);
|
|
1411
|
+
return weeks.concat(month.weeks.slice());
|
|
1412
|
+
}, initialWeeks.slice());
|
|
1089
1413
|
}
|
|
1090
1414
|
function useControlledValue(defaultValue, controlledValue) {
|
|
1091
1415
|
const [uncontrolledValue, setValue] = useState(defaultValue);
|
|
@@ -1095,14 +1419,14 @@ function useControlledValue(defaultValue, controlledValue) {
|
|
|
1095
1419
|
function useCalendar(props, dateLib) {
|
|
1096
1420
|
const [navStart, navEnd] = getNavMonths(props, dateLib);
|
|
1097
1421
|
const { startOfMonth: startOfMonth2, endOfMonth: endOfMonth2 } = dateLib;
|
|
1098
|
-
const initialMonth = getInitialMonth(props, dateLib);
|
|
1422
|
+
const initialMonth = getInitialMonth(props, navStart, navEnd, dateLib);
|
|
1099
1423
|
const [firstMonth, setFirstMonth] = useControlledValue(
|
|
1100
1424
|
initialMonth,
|
|
1101
1425
|
// initialMonth is always computed from props.month if provided
|
|
1102
1426
|
props.month ? initialMonth : void 0
|
|
1103
1427
|
);
|
|
1104
1428
|
useEffect(() => {
|
|
1105
|
-
const newInitialMonth = getInitialMonth(props, dateLib);
|
|
1429
|
+
const newInitialMonth = getInitialMonth(props, navStart, navEnd, dateLib);
|
|
1106
1430
|
setFirstMonth(newInitialMonth);
|
|
1107
1431
|
}, [props.timeZone]);
|
|
1108
1432
|
const displayMonths = getDisplayMonths(firstMonth, navEnd, props, dateLib);
|
|
@@ -1147,121 +1471,42 @@ function useCalendar(props, dateLib) {
|
|
|
1147
1471
|
};
|
|
1148
1472
|
return calendar;
|
|
1149
1473
|
}
|
|
1474
|
+
var FocusTargetPriority;
|
|
1475
|
+
(function(FocusTargetPriority2) {
|
|
1476
|
+
FocusTargetPriority2[FocusTargetPriority2["Today"] = 0] = "Today";
|
|
1477
|
+
FocusTargetPriority2[FocusTargetPriority2["Selected"] = 1] = "Selected";
|
|
1478
|
+
FocusTargetPriority2[FocusTargetPriority2["LastFocused"] = 2] = "LastFocused";
|
|
1479
|
+
FocusTargetPriority2[FocusTargetPriority2["FocusedModifier"] = 3] = "FocusedModifier";
|
|
1480
|
+
})(FocusTargetPriority || (FocusTargetPriority = {}));
|
|
1481
|
+
function isFocusableDay(modifiers) {
|
|
1482
|
+
return !modifiers[DayFlag.disabled] && !modifiers[DayFlag.hidden] && !modifiers[DayFlag.outside];
|
|
1483
|
+
}
|
|
1150
1484
|
function calculateFocusTarget(days, getModifiers, isSelected, lastFocused) {
|
|
1151
1485
|
let focusTarget;
|
|
1152
|
-
let
|
|
1153
|
-
|
|
1154
|
-
while (index < days.length && !found) {
|
|
1155
|
-
const day = days[index];
|
|
1486
|
+
let foundFocusTargetPriority = -1;
|
|
1487
|
+
for (const day of days) {
|
|
1156
1488
|
const modifiers = getModifiers(day);
|
|
1157
|
-
if (
|
|
1158
|
-
if (modifiers[DayFlag.focused]) {
|
|
1489
|
+
if (isFocusableDay(modifiers)) {
|
|
1490
|
+
if (modifiers[DayFlag.focused] && foundFocusTargetPriority < FocusTargetPriority.FocusedModifier) {
|
|
1159
1491
|
focusTarget = day;
|
|
1160
|
-
|
|
1161
|
-
} else if (lastFocused == null ? void 0 : lastFocused.isEqualTo(day)) {
|
|
1492
|
+
foundFocusTargetPriority = FocusTargetPriority.FocusedModifier;
|
|
1493
|
+
} else if ((lastFocused == null ? void 0 : lastFocused.isEqualTo(day)) && foundFocusTargetPriority < FocusTargetPriority.LastFocused) {
|
|
1162
1494
|
focusTarget = day;
|
|
1163
|
-
|
|
1164
|
-
} else if (isSelected(day.date)) {
|
|
1495
|
+
foundFocusTargetPriority = FocusTargetPriority.LastFocused;
|
|
1496
|
+
} else if (isSelected(day.date) && foundFocusTargetPriority < FocusTargetPriority.Selected) {
|
|
1165
1497
|
focusTarget = day;
|
|
1166
|
-
|
|
1167
|
-
} else if (modifiers[DayFlag.today]) {
|
|
1498
|
+
foundFocusTargetPriority = FocusTargetPriority.Selected;
|
|
1499
|
+
} else if (modifiers[DayFlag.today] && foundFocusTargetPriority < FocusTargetPriority.Today) {
|
|
1168
1500
|
focusTarget = day;
|
|
1169
|
-
|
|
1501
|
+
foundFocusTargetPriority = FocusTargetPriority.Today;
|
|
1170
1502
|
}
|
|
1171
1503
|
}
|
|
1172
|
-
index++;
|
|
1173
1504
|
}
|
|
1174
1505
|
if (!focusTarget) {
|
|
1175
|
-
focusTarget = days.find((day) =>
|
|
1176
|
-
const m = getModifiers(day);
|
|
1177
|
-
return !m[DayFlag.disabled] && !m[DayFlag.hidden] && !m[DayFlag.outside];
|
|
1178
|
-
});
|
|
1506
|
+
focusTarget = days.find((day) => isFocusableDay(getModifiers(day)));
|
|
1179
1507
|
}
|
|
1180
1508
|
return focusTarget;
|
|
1181
1509
|
}
|
|
1182
|
-
function rangeIncludesDate(range, date, excludeEnds = false, dateLib = defaultDateLib) {
|
|
1183
|
-
let { from, to } = range;
|
|
1184
|
-
const { differenceInCalendarDays: differenceInCalendarDays2, isSameDay: isSameDay2 } = dateLib;
|
|
1185
|
-
if (from && to) {
|
|
1186
|
-
const isRangeInverted = differenceInCalendarDays2(to, from) < 0;
|
|
1187
|
-
if (isRangeInverted) {
|
|
1188
|
-
[from, to] = [to, from];
|
|
1189
|
-
}
|
|
1190
|
-
const isInRange = differenceInCalendarDays2(date, from) >= (excludeEnds ? 1 : 0) && differenceInCalendarDays2(to, date) >= (excludeEnds ? 1 : 0);
|
|
1191
|
-
return isInRange;
|
|
1192
|
-
}
|
|
1193
|
-
if (!excludeEnds && to) {
|
|
1194
|
-
return isSameDay2(to, date);
|
|
1195
|
-
}
|
|
1196
|
-
if (!excludeEnds && from) {
|
|
1197
|
-
return isSameDay2(from, date);
|
|
1198
|
-
}
|
|
1199
|
-
return false;
|
|
1200
|
-
}
|
|
1201
|
-
function isDateInterval(matcher) {
|
|
1202
|
-
return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
|
|
1203
|
-
}
|
|
1204
|
-
function isDateRange(value) {
|
|
1205
|
-
return Boolean(value && typeof value === "object" && "from" in value);
|
|
1206
|
-
}
|
|
1207
|
-
function isDateAfterType(value) {
|
|
1208
|
-
return Boolean(value && typeof value === "object" && "after" in value);
|
|
1209
|
-
}
|
|
1210
|
-
function isDateBeforeType(value) {
|
|
1211
|
-
return Boolean(value && typeof value === "object" && "before" in value);
|
|
1212
|
-
}
|
|
1213
|
-
function isDayOfWeekType(value) {
|
|
1214
|
-
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
|
1215
|
-
}
|
|
1216
|
-
function isDatesArray(value, dateLib) {
|
|
1217
|
-
return Array.isArray(value) && value.every(dateLib.isDate);
|
|
1218
|
-
}
|
|
1219
|
-
function dateMatchModifiers(date, matchers, dateLib = defaultDateLib) {
|
|
1220
|
-
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
|
1221
|
-
const { isSameDay: isSameDay2, differenceInCalendarDays: differenceInCalendarDays2, isAfter: isAfter2 } = dateLib;
|
|
1222
|
-
return matchersArr.some((matcher) => {
|
|
1223
|
-
if (typeof matcher === "boolean") {
|
|
1224
|
-
return matcher;
|
|
1225
|
-
}
|
|
1226
|
-
if (dateLib.isDate(matcher)) {
|
|
1227
|
-
return isSameDay2(date, matcher);
|
|
1228
|
-
}
|
|
1229
|
-
if (isDatesArray(matcher, dateLib)) {
|
|
1230
|
-
return matcher.includes(date);
|
|
1231
|
-
}
|
|
1232
|
-
if (isDateRange(matcher)) {
|
|
1233
|
-
return rangeIncludesDate(matcher, date, false, dateLib);
|
|
1234
|
-
}
|
|
1235
|
-
if (isDayOfWeekType(matcher)) {
|
|
1236
|
-
if (!Array.isArray(matcher.dayOfWeek)) {
|
|
1237
|
-
return matcher.dayOfWeek === date.getDay();
|
|
1238
|
-
}
|
|
1239
|
-
return matcher.dayOfWeek.includes(date.getDay());
|
|
1240
|
-
}
|
|
1241
|
-
if (isDateInterval(matcher)) {
|
|
1242
|
-
const diffBefore = differenceInCalendarDays2(matcher.before, date);
|
|
1243
|
-
const diffAfter = differenceInCalendarDays2(matcher.after, date);
|
|
1244
|
-
const isDayBefore = diffBefore > 0;
|
|
1245
|
-
const isDayAfter = diffAfter < 0;
|
|
1246
|
-
const isClosedInterval = isAfter2(matcher.before, matcher.after);
|
|
1247
|
-
if (isClosedInterval) {
|
|
1248
|
-
return isDayAfter && isDayBefore;
|
|
1249
|
-
} else {
|
|
1250
|
-
return isDayBefore || isDayAfter;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
if (isDateAfterType(matcher)) {
|
|
1254
|
-
return differenceInCalendarDays2(date, matcher.after) > 0;
|
|
1255
|
-
}
|
|
1256
|
-
if (isDateBeforeType(matcher)) {
|
|
1257
|
-
return differenceInCalendarDays2(matcher.before, date) > 0;
|
|
1258
|
-
}
|
|
1259
|
-
if (typeof matcher === "function") {
|
|
1260
|
-
return matcher(date);
|
|
1261
|
-
}
|
|
1262
|
-
return false;
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
1510
|
function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dateLib) {
|
|
1266
1511
|
const { ISOWeek, broadcastCalendar } = props;
|
|
1267
1512
|
const { addDays: addDays2, addMonths: addMonths2, addWeeks: addWeeks2, addYears: addYears2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfWeek: endOfWeek2, max: max2, min: min2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
@@ -1271,7 +1516,7 @@ function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dat
|
|
|
1271
1516
|
month: addMonths2,
|
|
1272
1517
|
year: addYears2,
|
|
1273
1518
|
startOfWeek: (date) => broadcastCalendar ? startOfBroadcastWeek2(date, dateLib) : ISOWeek ? startOfISOWeek2(date) : startOfWeek2(date),
|
|
1274
|
-
endOfWeek: (date) => broadcastCalendar ? endOfBroadcastWeek2(date
|
|
1519
|
+
endOfWeek: (date) => broadcastCalendar ? endOfBroadcastWeek2(date) : ISOWeek ? endOfISOWeek2(date) : endOfWeek2(date)
|
|
1275
1520
|
};
|
|
1276
1521
|
let focusableDate = moveFns[moveBy](refDate, moveDir === "after" ? 1 : -1);
|
|
1277
1522
|
if (moveDir === "before" && navStart) {
|
|
@@ -1285,16 +1530,7 @@ function getNextFocus(moveBy, moveDir, refDay, calendarStartMonth, calendarEndMo
|
|
|
1285
1530
|
if (attempt > 365) {
|
|
1286
1531
|
return void 0;
|
|
1287
1532
|
}
|
|
1288
|
-
const focusableDate = getFocusableDate(
|
|
1289
|
-
moveBy,
|
|
1290
|
-
moveDir,
|
|
1291
|
-
refDay.date,
|
|
1292
|
-
// should be refDay? or refDay.date?
|
|
1293
|
-
calendarStartMonth,
|
|
1294
|
-
calendarEndMonth,
|
|
1295
|
-
props,
|
|
1296
|
-
dateLib
|
|
1297
|
-
);
|
|
1533
|
+
const focusableDate = getFocusableDate(moveBy, moveDir, refDay.date, calendarStartMonth, calendarEndMonth, props, dateLib);
|
|
1298
1534
|
const isDisabled = Boolean(props.disabled && dateMatchModifiers(focusableDate, props.disabled, dateLib));
|
|
1299
1535
|
const isHidden = Boolean(props.hidden && dateMatchModifiers(focusableDate, props.hidden, dateLib));
|
|
1300
1536
|
const targetMonth = focusableDate;
|
|
@@ -1334,73 +1570,6 @@ function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
|
|
|
1334
1570
|
};
|
|
1335
1571
|
return useFocus2;
|
|
1336
1572
|
}
|
|
1337
|
-
function useGetModifiers(days, props, dateLib) {
|
|
1338
|
-
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today } = props;
|
|
1339
|
-
const { isSameDay: isSameDay2, isSameMonth: isSameMonth2, startOfMonth: startOfMonth2, isBefore: isBefore2, endOfMonth: endOfMonth2, isAfter: isAfter2 } = dateLib;
|
|
1340
|
-
const startMonth = props.startMonth && startOfMonth2(props.startMonth);
|
|
1341
|
-
const endMonth = props.endMonth && endOfMonth2(props.endMonth);
|
|
1342
|
-
const internalModifiersMap = {
|
|
1343
|
-
[DayFlag.focused]: [],
|
|
1344
|
-
[DayFlag.outside]: [],
|
|
1345
|
-
[DayFlag.disabled]: [],
|
|
1346
|
-
[DayFlag.hidden]: [],
|
|
1347
|
-
[DayFlag.today]: []
|
|
1348
|
-
};
|
|
1349
|
-
const customModifiersMap = {};
|
|
1350
|
-
for (const day of days) {
|
|
1351
|
-
const { date, displayMonth } = day;
|
|
1352
|
-
const isOutside = Boolean(displayMonth && !isSameMonth2(date, displayMonth));
|
|
1353
|
-
const isBeforeStartMonth = Boolean(startMonth && isBefore2(date, startMonth));
|
|
1354
|
-
const isAfterEndMonth = Boolean(endMonth && isAfter2(date, endMonth));
|
|
1355
|
-
const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
|
|
1356
|
-
const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeStartMonth || isAfterEndMonth || // Broadcast calendar will show outside days as default
|
|
1357
|
-
!broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
|
|
1358
|
-
const isToday = isSameDay2(date, today ?? dateLib.today());
|
|
1359
|
-
if (isOutside)
|
|
1360
|
-
internalModifiersMap.outside.push(day);
|
|
1361
|
-
if (isDisabled)
|
|
1362
|
-
internalModifiersMap.disabled.push(day);
|
|
1363
|
-
if (isHidden)
|
|
1364
|
-
internalModifiersMap.hidden.push(day);
|
|
1365
|
-
if (isToday)
|
|
1366
|
-
internalModifiersMap.today.push(day);
|
|
1367
|
-
if (modifiers) {
|
|
1368
|
-
Object.keys(modifiers).forEach((name) => {
|
|
1369
|
-
const modifierValue = modifiers == null ? void 0 : modifiers[name];
|
|
1370
|
-
const isMatch = modifierValue ? dateMatchModifiers(date, modifierValue, dateLib) : false;
|
|
1371
|
-
if (!isMatch)
|
|
1372
|
-
return;
|
|
1373
|
-
if (customModifiersMap[name]) {
|
|
1374
|
-
customModifiersMap[name].push(day);
|
|
1375
|
-
} else {
|
|
1376
|
-
customModifiersMap[name] = [day];
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
return (day) => {
|
|
1382
|
-
const dayFlags = {
|
|
1383
|
-
[DayFlag.focused]: false,
|
|
1384
|
-
[DayFlag.disabled]: false,
|
|
1385
|
-
[DayFlag.hidden]: false,
|
|
1386
|
-
[DayFlag.outside]: false,
|
|
1387
|
-
[DayFlag.today]: false
|
|
1388
|
-
};
|
|
1389
|
-
const customModifiers = {};
|
|
1390
|
-
for (const name in internalModifiersMap) {
|
|
1391
|
-
const days2 = internalModifiersMap[name];
|
|
1392
|
-
dayFlags[name] = days2.some((d) => d === day);
|
|
1393
|
-
}
|
|
1394
|
-
for (const name in customModifiersMap) {
|
|
1395
|
-
customModifiers[name] = customModifiersMap[name].some((d) => d === day);
|
|
1396
|
-
}
|
|
1397
|
-
return {
|
|
1398
|
-
...dayFlags,
|
|
1399
|
-
// custom modifiers should override all the previous ones
|
|
1400
|
-
...customModifiers
|
|
1401
|
-
};
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
1573
|
function useMulti(props, dateLib) {
|
|
1405
1574
|
const { selected: initiallySelected, required, onSelect } = props;
|
|
1406
1575
|
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
|
|
@@ -1447,7 +1616,9 @@ function addToRange(date, initialRange, min2 = 0, max2 = 0, required = false, da
|
|
|
1447
1616
|
range = { from: date, to: min2 > 0 ? void 0 : date };
|
|
1448
1617
|
} else if (from && !to) {
|
|
1449
1618
|
if (isSameDay2(from, date)) {
|
|
1450
|
-
if (
|
|
1619
|
+
if (min2 === 0) {
|
|
1620
|
+
range = { from, to: date };
|
|
1621
|
+
} else if (required) {
|
|
1451
1622
|
range = { from, to: void 0 };
|
|
1452
1623
|
} else {
|
|
1453
1624
|
range = void 0;
|
|
@@ -1626,9 +1797,41 @@ function useSelection(props, dateLib) {
|
|
|
1626
1797
|
return void 0;
|
|
1627
1798
|
}
|
|
1628
1799
|
}
|
|
1629
|
-
function DayPicker(
|
|
1800
|
+
function DayPicker(initialProps) {
|
|
1801
|
+
var _a;
|
|
1802
|
+
let props = initialProps;
|
|
1803
|
+
if (props.timeZone) {
|
|
1804
|
+
props = {
|
|
1805
|
+
...initialProps
|
|
1806
|
+
};
|
|
1807
|
+
if (props.today) {
|
|
1808
|
+
props.today = new TZDate(props.today, props.timeZone);
|
|
1809
|
+
}
|
|
1810
|
+
if (props.month) {
|
|
1811
|
+
props.month = new TZDate(props.month, props.timeZone);
|
|
1812
|
+
}
|
|
1813
|
+
if (props.defaultMonth) {
|
|
1814
|
+
props.defaultMonth = new TZDate(props.defaultMonth, props.timeZone);
|
|
1815
|
+
}
|
|
1816
|
+
if (props.startMonth) {
|
|
1817
|
+
props.startMonth = new TZDate(props.startMonth, props.timeZone);
|
|
1818
|
+
}
|
|
1819
|
+
if (props.endMonth) {
|
|
1820
|
+
props.endMonth = new TZDate(props.endMonth, props.timeZone);
|
|
1821
|
+
}
|
|
1822
|
+
if (props.mode === "single" && props.selected) {
|
|
1823
|
+
props.selected = new TZDate(props.selected, props.timeZone);
|
|
1824
|
+
} else if (props.mode === "multiple" && props.selected) {
|
|
1825
|
+
props.selected = (_a = props.selected) == null ? void 0 : _a.map((date) => new TZDate(date, props.timeZone));
|
|
1826
|
+
} else if (props.mode === "range" && props.selected) {
|
|
1827
|
+
props.selected = {
|
|
1828
|
+
from: props.selected.from ? new TZDate(props.selected.from, props.timeZone) : void 0,
|
|
1829
|
+
to: props.selected.to ? new TZDate(props.selected.to, props.timeZone) : void 0
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1630
1833
|
const { components: components2, formatters, labels, dateLib, locale, classNames: classNames2 } = useMemo(() => {
|
|
1631
|
-
const locale2 = { ...enUS
|
|
1834
|
+
const locale2 = { ...enUS, ...props.locale };
|
|
1632
1835
|
const dateLib2 = new DateLib({
|
|
1633
1836
|
locale: locale2,
|
|
1634
1837
|
weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn,
|
|
@@ -1661,14 +1864,14 @@ function DayPicker(props) {
|
|
|
1661
1864
|
props.labels,
|
|
1662
1865
|
props.classNames
|
|
1663
1866
|
]);
|
|
1664
|
-
const { captionLayout, mode, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles: styles2 } = props;
|
|
1867
|
+
const { captionLayout, mode, navLayout, numberOfMonths = 1, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles: styles2 } = props;
|
|
1665
1868
|
const { formatCaption: formatCaption2, formatDay: formatDay2, formatMonthDropdown: formatMonthDropdown2, formatWeekNumber: formatWeekNumber2, formatWeekNumberHeader: formatWeekNumberHeader2, formatWeekdayName: formatWeekdayName2, formatYearDropdown: formatYearDropdown2 } = formatters;
|
|
1666
1869
|
const calendar = useCalendar(props, dateLib);
|
|
1667
1870
|
const { days, months, navStart, navEnd, previousMonth, nextMonth, goToMonth } = calendar;
|
|
1668
|
-
const getModifiers =
|
|
1871
|
+
const getModifiers = createGetModifiers(days, props, navStart, navEnd, dateLib);
|
|
1669
1872
|
const { isSelected, select, selected: selectedValue } = useSelection(props, dateLib) ?? {};
|
|
1670
1873
|
const { blur, focused, isFocusTarget, moveFocus, setFocused } = useFocus(props, calendar, getModifiers, isSelected ?? (() => false), dateLib);
|
|
1671
|
-
const { labelDayButton: labelDayButton2, labelGridcell: labelGridcell2, labelGrid: labelGrid2, labelMonthDropdown: labelMonthDropdown2, labelNav: labelNav2, labelWeekday: labelWeekday2, labelWeekNumber: labelWeekNumber2, labelWeekNumberHeader: labelWeekNumberHeader2, labelYearDropdown: labelYearDropdown2 } = labels;
|
|
1874
|
+
const { labelDayButton: labelDayButton2, labelGridcell: labelGridcell2, labelGrid: labelGrid2, labelMonthDropdown: labelMonthDropdown2, labelNav: labelNav2, labelPrevious: labelPrevious2, labelNext: labelNext2, labelWeekday: labelWeekday2, labelWeekNumber: labelWeekNumber2, labelWeekNumberHeader: labelWeekNumberHeader2, labelYearDropdown: labelYearDropdown2 } = labels;
|
|
1672
1875
|
const weekdays = useMemo(() => getWeekdays(dateLib, props.ISOWeek), [dateLib, props.ISOWeek]);
|
|
1673
1876
|
const isInteractive = mode !== void 0 || onDayClick !== void 0;
|
|
1674
1877
|
const handlePreviousClick = useCallback(() => {
|
|
@@ -1700,10 +1903,16 @@ function DayPicker(props) {
|
|
|
1700
1903
|
}, [blur, onDayBlur]);
|
|
1701
1904
|
const handleDayKeyDown = useCallback((day, modifiers) => (e) => {
|
|
1702
1905
|
const keyMap = {
|
|
1703
|
-
ArrowLeft: [
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1906
|
+
ArrowLeft: [
|
|
1907
|
+
e.shiftKey ? "month" : "day",
|
|
1908
|
+
props.dir === "rtl" ? "after" : "before"
|
|
1909
|
+
],
|
|
1910
|
+
ArrowRight: [
|
|
1911
|
+
e.shiftKey ? "month" : "day",
|
|
1912
|
+
props.dir === "rtl" ? "before" : "after"
|
|
1913
|
+
],
|
|
1914
|
+
ArrowDown: [e.shiftKey ? "year" : "week", "after"],
|
|
1915
|
+
ArrowUp: [e.shiftKey ? "year" : "week", "before"],
|
|
1707
1916
|
PageUp: [e.shiftKey ? "year" : "month", "before"],
|
|
1708
1917
|
PageDown: [e.shiftKey ? "year" : "month", "after"],
|
|
1709
1918
|
Home: ["startOfWeek", "before"],
|
|
@@ -1738,6 +1947,13 @@ function DayPicker(props) {
|
|
|
1738
1947
|
style: { ...styles2 == null ? void 0 : styles2[UI.Root], ...props.style }
|
|
1739
1948
|
}), [classNames2, props.className, props.style, styles2]);
|
|
1740
1949
|
const dataAttributes = getDataAttributes(props);
|
|
1950
|
+
const rootElRef = useRef(null);
|
|
1951
|
+
useAnimation(rootElRef, Boolean(props.animate), {
|
|
1952
|
+
classNames: classNames2,
|
|
1953
|
+
months,
|
|
1954
|
+
focused,
|
|
1955
|
+
dateLib
|
|
1956
|
+
});
|
|
1741
1957
|
const contextValue = {
|
|
1742
1958
|
dayPickerProps: props,
|
|
1743
1959
|
selected: selectedValue,
|
|
@@ -1759,44 +1975,77 @@ function DayPicker(props) {
|
|
|
1759
1975
|
{ value: contextValue },
|
|
1760
1976
|
React.createElement(
|
|
1761
1977
|
components2.Root,
|
|
1762
|
-
{ className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], ...dataAttributes },
|
|
1978
|
+
{ rootRef: props.animate ? rootElRef : void 0, className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], ...dataAttributes },
|
|
1763
1979
|
React.createElement(
|
|
1764
1980
|
components2.Months,
|
|
1765
1981
|
{ className: classNames2[UI.Months], style: styles2 == null ? void 0 : styles2[UI.Months] },
|
|
1766
|
-
!props.hideNavigation && React.createElement(components2.Nav, { className: classNames2[UI.Nav], style: styles2 == null ? void 0 : styles2[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
|
|
1982
|
+
!props.hideNavigation && !navLayout && React.createElement(components2.Nav, { "data-animated-nav": props.animate ? "true" : void 0, className: classNames2[UI.Nav], style: styles2 == null ? void 0 : styles2[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
|
|
1767
1983
|
months.map((calendarMonth, displayIndex) => {
|
|
1768
|
-
const dropdownMonths = getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib);
|
|
1769
|
-
const dropdownYears = getYearOptions(navStart, navEnd, formatters, dateLib);
|
|
1770
1984
|
return React.createElement(
|
|
1771
1985
|
components2.Month,
|
|
1772
|
-
{
|
|
1773
|
-
|
|
1986
|
+
{
|
|
1987
|
+
"data-animated-month": props.animate ? "true" : void 0,
|
|
1988
|
+
className: classNames2[UI.Month],
|
|
1989
|
+
style: styles2 == null ? void 0 : styles2[UI.Month],
|
|
1990
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: breaks animation
|
|
1991
|
+
key: displayIndex,
|
|
1992
|
+
displayIndex,
|
|
1993
|
+
calendarMonth
|
|
1994
|
+
},
|
|
1995
|
+
navLayout === "around" && !props.hideNavigation && displayIndex === 0 && React.createElement(
|
|
1996
|
+
components2.PreviousMonthButton,
|
|
1997
|
+
{ type: "button", className: classNames2[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, "aria-disabled": previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick: handlePreviousClick, "data-animated-button": props.animate ? "true" : void 0 },
|
|
1998
|
+
React.createElement(components2.Chevron, { disabled: previousMonth ? void 0 : true, className: classNames2[UI.Chevron], orientation: props.dir === "rtl" ? "right" : "left" })
|
|
1999
|
+
),
|
|
2000
|
+
React.createElement(components2.MonthCaption, { "data-animated-caption": props.animate ? "true" : void 0, className: classNames2[UI.MonthCaption], style: styles2 == null ? void 0 : styles2[UI.MonthCaption], calendarMonth, displayIndex }, (captionLayout == null ? void 0 : captionLayout.startsWith("dropdown")) ? React.createElement(
|
|
1774
2001
|
components2.DropdownNav,
|
|
1775
2002
|
{ className: classNames2[UI.Dropdowns], style: styles2 == null ? void 0 : styles2[UI.Dropdowns] },
|
|
1776
|
-
captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { className: classNames2[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options:
|
|
1777
|
-
captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { className: classNames2[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options:
|
|
1778
|
-
|
|
2003
|
+
captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { className: classNames2[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options: getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getMonth(calendarMonth.date) }) : React.createElement("span", null, formatMonthDropdown2(calendarMonth.date, dateLib)),
|
|
2004
|
+
captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { className: classNames2[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options: getYearOptions(navStart, navEnd, formatters, dateLib, Boolean(props.reverseYears)), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getYear(calendarMonth.date) }) : React.createElement("span", null, formatYearDropdown2(calendarMonth.date, dateLib)),
|
|
2005
|
+
React.createElement("span", { role: "status", "aria-live": "polite", style: {
|
|
2006
|
+
border: 0,
|
|
2007
|
+
clip: "rect(0 0 0 0)",
|
|
2008
|
+
height: "1px",
|
|
2009
|
+
margin: "-1px",
|
|
2010
|
+
overflow: "hidden",
|
|
2011
|
+
padding: 0,
|
|
2012
|
+
position: "absolute",
|
|
2013
|
+
width: "1px",
|
|
2014
|
+
whiteSpace: "nowrap",
|
|
2015
|
+
wordWrap: "normal"
|
|
2016
|
+
} }, formatCaption2(calendarMonth.date, dateLib.options, dateLib))
|
|
2017
|
+
) : (
|
|
2018
|
+
// biome-ignore lint/a11y/useSemanticElements: breaking change
|
|
2019
|
+
React.createElement(components2.CaptionLabel, { className: classNames2[UI.CaptionLabel], role: "status", "aria-live": "polite" }, formatCaption2(calendarMonth.date, dateLib.options, dateLib))
|
|
2020
|
+
)),
|
|
2021
|
+
navLayout === "around" && !props.hideNavigation && displayIndex === numberOfMonths - 1 && React.createElement(
|
|
2022
|
+
components2.NextMonthButton,
|
|
2023
|
+
{ type: "button", className: classNames2[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, "aria-disabled": nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick: handleNextClick, "data-animated-button": props.animate ? "true" : void 0 },
|
|
2024
|
+
React.createElement(components2.Chevron, { disabled: nextMonth ? void 0 : true, className: classNames2[UI.Chevron], orientation: props.dir === "rtl" ? "left" : "right" })
|
|
2025
|
+
),
|
|
2026
|
+
displayIndex === numberOfMonths - 1 && navLayout === "after" && !props.hideNavigation && React.createElement(components2.Nav, { "data-animated-nav": props.animate ? "true" : void 0, className: classNames2[UI.Nav], style: styles2 == null ? void 0 : styles2[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
|
|
1779
2027
|
React.createElement(
|
|
1780
2028
|
components2.MonthGrid,
|
|
1781
2029
|
{ role: "grid", "aria-multiselectable": mode === "multiple" || mode === "range", "aria-label": labelGrid2(calendarMonth.date, dateLib.options, dateLib) || void 0, className: classNames2[UI.MonthGrid], style: styles2 == null ? void 0 : styles2[UI.MonthGrid] },
|
|
1782
2030
|
!props.hideWeekdays && React.createElement(
|
|
1783
2031
|
components2.Weekdays,
|
|
1784
|
-
{ className: classNames2[UI.Weekdays], style: styles2 == null ? void 0 : styles2[UI.Weekdays] },
|
|
2032
|
+
{ "data-animated-weekdays": props.animate ? "true" : void 0, className: classNames2[UI.Weekdays], style: styles2 == null ? void 0 : styles2[UI.Weekdays] },
|
|
1785
2033
|
showWeekNumber && React.createElement(components2.WeekNumberHeader, { "aria-label": labelWeekNumberHeader2(dateLib.options), className: classNames2[UI.WeekNumberHeader], style: styles2 == null ? void 0 : styles2[UI.WeekNumberHeader], scope: "col" }, formatWeekNumberHeader2()),
|
|
1786
|
-
weekdays.map((weekday
|
|
2034
|
+
weekdays.map((weekday) => React.createElement(components2.Weekday, { "aria-label": labelWeekday2(weekday, dateLib.options, dateLib), className: classNames2[UI.Weekday], key: String(weekday), style: styles2 == null ? void 0 : styles2[UI.Weekday], scope: "col" }, formatWeekdayName2(weekday, dateLib.options, dateLib)))
|
|
1787
2035
|
),
|
|
1788
|
-
React.createElement(components2.Weeks, { className: classNames2[UI.Weeks], style: styles2 == null ? void 0 : styles2[UI.Weeks] }, calendarMonth.weeks.map((week
|
|
2036
|
+
React.createElement(components2.Weeks, { "data-animated-weeks": props.animate ? "true" : void 0, className: classNames2[UI.Weeks], style: styles2 == null ? void 0 : styles2[UI.Weeks] }, calendarMonth.weeks.map((week) => {
|
|
1789
2037
|
return React.createElement(
|
|
1790
2038
|
components2.Week,
|
|
1791
2039
|
{ className: classNames2[UI.Week], key: week.weekNumber, style: styles2 == null ? void 0 : styles2[UI.Week], week },
|
|
1792
|
-
showWeekNumber &&
|
|
2040
|
+
showWeekNumber && // biome-ignore lint/a11y/useSemanticElements: react component
|
|
2041
|
+
React.createElement(components2.WeekNumber, { week, style: styles2 == null ? void 0 : styles2[UI.WeekNumber], "aria-label": labelWeekNumber2(week.weekNumber, {
|
|
1793
2042
|
locale
|
|
1794
|
-
}), className: classNames2[UI.WeekNumber], scope: "row", role: "rowheader" }, formatWeekNumber2(week.weekNumber)),
|
|
2043
|
+
}), className: classNames2[UI.WeekNumber], scope: "row", role: "rowheader" }, formatWeekNumber2(week.weekNumber, dateLib)),
|
|
1795
2044
|
week.days.map((day) => {
|
|
1796
2045
|
const { date } = day;
|
|
1797
2046
|
const modifiers = getModifiers(day);
|
|
1798
2047
|
modifiers[DayFlag.focused] = !modifiers.hidden && Boolean(focused == null ? void 0 : focused.isEqualTo(day));
|
|
1799
|
-
modifiers[SelectionState.selected] =
|
|
2048
|
+
modifiers[SelectionState.selected] = (isSelected == null ? void 0 : isSelected(date)) || modifiers.selected;
|
|
1800
2049
|
if (isDateRange(selectedValue)) {
|
|
1801
2050
|
const { from, to } = selectedValue;
|
|
1802
2051
|
modifiers[SelectionState.range_start] = Boolean(from && to && dateLib.isSameDay(date, from));
|
|
@@ -1806,7 +2055,10 @@ function DayPicker(props) {
|
|
|
1806
2055
|
const style2 = getStyleForModifiers(modifiers, styles2, props.modifiersStyles);
|
|
1807
2056
|
const className2 = getClassNamesForModifiers(modifiers, classNames2, props.modifiersClassNames);
|
|
1808
2057
|
const ariaLabel = !isInteractive && !modifiers.hidden ? labelGridcell2(date, modifiers, dateLib.options, dateLib) : void 0;
|
|
1809
|
-
return
|
|
2058
|
+
return (
|
|
2059
|
+
// biome-ignore lint/a11y/useSemanticElements: react component
|
|
2060
|
+
React.createElement(components2.Day, { key: `${dateLib.format(date, "yyyy-MM-dd")}_${dateLib.format(day.displayMonth, "yyyy-MM")}`, day, modifiers, className: className2.join(" "), style: style2, role: "gridcell", "aria-selected": modifiers.selected || void 0, "aria-label": ariaLabel, "data-day": dateLib.format(date, "yyyy-MM-dd"), "data-month": day.outside ? dateLib.format(date, "yyyy-MM") : void 0, "data-selected": modifiers.selected || void 0, "data-disabled": modifiers.disabled || void 0, "data-hidden": modifiers.hidden || void 0, "data-outside": day.outside || void 0, "data-focused": modifiers.focused || void 0, "data-today": modifiers.today || void 0 }, !modifiers.hidden && isInteractive ? React.createElement(components2.DayButton, { className: classNames2[UI.DayButton], style: styles2 == null ? void 0 : styles2[UI.DayButton], type: "button", day, modifiers, disabled: modifiers.disabled || void 0, tabIndex: isFocusTarget(day) ? 0 : -1, "aria-label": labelDayButton2(date, modifiers, dateLib.options, dateLib), onClick: handleDayClick(day, modifiers), onBlur: handleDayBlur(day, modifiers), onFocus: handleDayFocus(day, modifiers), onKeyDown: handleDayKeyDown(day, modifiers), onMouseEnter: handleDayMouseEnter(day, modifiers), onMouseLeave: handleDayMouseLeave(day, modifiers) }, formatDay2(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay2(day.date, dateLib.options, dateLib))
|
|
2061
|
+
);
|
|
1810
2062
|
})
|
|
1811
2063
|
);
|
|
1812
2064
|
}))
|
|
@@ -1814,7 +2066,8 @@ function DayPicker(props) {
|
|
|
1814
2066
|
);
|
|
1815
2067
|
})
|
|
1816
2068
|
),
|
|
1817
|
-
props.footer &&
|
|
2069
|
+
props.footer && // biome-ignore lint/a11y/useSemanticElements: react component
|
|
2070
|
+
React.createElement(components2.Footer, { className: classNames2[UI.Footer], style: styles2 == null ? void 0 : styles2[UI.Footer], role: "status", "aria-live": "polite" }, props.footer)
|
|
1818
2071
|
)
|
|
1819
2072
|
);
|
|
1820
2073
|
}
|
|
@@ -2101,7 +2354,7 @@ const DatePicker = React.forwardRef((props, ref) => {
|
|
|
2101
2354
|
}
|
|
2102
2355
|
}, [returnInputFocus]);
|
|
2103
2356
|
const handleEscapeKeyDown = () => {
|
|
2104
|
-
(refObject == null ? void 0 : refObject.current)
|
|
2357
|
+
if (refObject == null ? void 0 : refObject.current) refObject.current.focus();
|
|
2105
2358
|
setDatePickerOpen(false);
|
|
2106
2359
|
};
|
|
2107
2360
|
useKeyboardEvent(datepickerWrapperRef, handleEscapeKeyDown, [KeyboardEventKey.Escape]);
|
|
@@ -2115,7 +2368,7 @@ const DatePicker = React.forwardRef((props, ref) => {
|
|
|
2115
2368
|
} else {
|
|
2116
2369
|
setDateState(void 0);
|
|
2117
2370
|
}
|
|
2118
|
-
onChange
|
|
2371
|
+
if (onChange) onChange(event, event.currentTarget.value);
|
|
2119
2372
|
};
|
|
2120
2373
|
const handleInputFocus = () => {
|
|
2121
2374
|
if (!returnInputFocus) {
|
|
@@ -2135,9 +2388,9 @@ const DatePicker = React.forwardRef((props, ref) => {
|
|
|
2135
2388
|
setInputValue(format(date, dateFormat));
|
|
2136
2389
|
setDatePickerOpen(false);
|
|
2137
2390
|
}
|
|
2138
|
-
onChange
|
|
2391
|
+
if (onChange) onChange(e, date);
|
|
2139
2392
|
triggerSyntheticInputEvents(refObject, format(date, dateFormat), date);
|
|
2140
|
-
onDatePopupClosed
|
|
2393
|
+
if (onDatePopupClosed) onDatePopupClosed(date);
|
|
2141
2394
|
};
|
|
2142
2395
|
const triggerSyntheticInputEvents = (inputRef, value, date, _onChange) => {
|
|
2143
2396
|
if (inputRef.current) {
|
|
@@ -2163,7 +2416,7 @@ const DatePicker = React.forwardRef((props, ref) => {
|
|
|
2163
2416
|
};
|
|
2164
2417
|
const handleInputBlur = (e) => {
|
|
2165
2418
|
if (!datePickerOpen && (typeof onDatePopupClosed === "undefined" || isTyping.current)) {
|
|
2166
|
-
onBlur
|
|
2419
|
+
if (onBlur) onBlur(e);
|
|
2167
2420
|
}
|
|
2168
2421
|
isTyping.current = false;
|
|
2169
2422
|
};
|
|
@@ -2191,7 +2444,7 @@ const DatePicker = React.forwardRef((props, ref) => {
|
|
|
2191
2444
|
const handleMobileInputChange = (e) => {
|
|
2192
2445
|
handleInputChange(e, "yyyy-MM-dd");
|
|
2193
2446
|
if (!isTyping.current) {
|
|
2194
|
-
onDatePopupClosed
|
|
2447
|
+
if (onDatePopupClosed) onDatePopupClosed(dateState);
|
|
2195
2448
|
}
|
|
2196
2449
|
};
|
|
2197
2450
|
const renderMobile = /* @__PURE__ */ jsx(
|
|
@@ -2311,14 +2564,14 @@ const DateTime = React.forwardRef((props, ref) => {
|
|
|
2311
2564
|
const value2 = event.target.value;
|
|
2312
2565
|
if (isNumericString(value2)) {
|
|
2313
2566
|
setInputValue(value2);
|
|
2314
|
-
onChange
|
|
2567
|
+
if (onChange) onChange(event);
|
|
2315
2568
|
}
|
|
2316
2569
|
};
|
|
2317
2570
|
const handleInputBlur = (event) => {
|
|
2318
2571
|
const formattedValue = formatAsTwoDigits(event.target.value);
|
|
2319
2572
|
setInputValue(formattedValue);
|
|
2320
|
-
onChange
|
|
2321
|
-
onBlur
|
|
2573
|
+
if (onChange) onChange(event);
|
|
2574
|
+
if (onBlur) onBlur(event);
|
|
2322
2575
|
};
|
|
2323
2576
|
const handleInputOnKeyDown = (event) => {
|
|
2324
2577
|
const validChars = /[0-9]/;
|