@helsenorge/datepicker 13.4.0 → 13.6.0

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.
Files changed (33) hide show
  1. package/lib/CHANGELOG.md +40 -0
  2. package/lib/DayPicker.js +2188 -0
  3. package/lib/DayPicker.js.map +1 -0
  4. package/lib/components/DatePicker/DatePicker.d.ts +1 -1
  5. package/lib/components/DatePicker/index.js +5 -1976
  6. package/lib/components/DatePicker/index.js.map +1 -1
  7. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.d.ts +31 -0
  8. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.module.scss +446 -0
  9. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.module.scss.d.ts +31 -0
  10. package/lib/components/Unsafe_DatePicker/BaseDayPicker/CustomComponents.d.ts +6 -0
  11. package/lib/components/Unsafe_DatePicker/BaseDayPicker/utils.d.ts +1 -0
  12. package/lib/components/Unsafe_DatePicker/DateInputInternal.d.ts +28 -0
  13. package/lib/components/Unsafe_DatePicker/DatePicker.module.scss +277 -0
  14. package/lib/components/Unsafe_DatePicker/DatePicker.module.scss.d.ts +24 -0
  15. package/lib/components/Unsafe_DatePicker/RangeDatePickers.module.scss +9 -0
  16. package/lib/components/Unsafe_DatePicker/RangeDatePickers.module.scss.d.ts +9 -0
  17. package/lib/components/Unsafe_DatePicker/TimeInput/TimeInputInternal.d.ts +23 -0
  18. package/lib/components/Unsafe_DatePicker/TimeInput/Unsafe_TimeInput.d.ts +25 -0
  19. package/lib/components/Unsafe_DatePicker/Unsafe_DateAndTime.d.ts +16 -0
  20. package/lib/components/Unsafe_DatePicker/Unsafe_DateAndTime.module.scss +18 -0
  21. package/lib/components/Unsafe_DatePicker/Unsafe_DateAndTime.module.scss.d.ts +10 -0
  22. package/lib/components/Unsafe_DatePicker/Unsafe_DatePicker.d.ts +26 -0
  23. package/lib/components/Unsafe_DatePicker/Unsafe_ISODatePicker.d.ts +9 -0
  24. package/lib/components/Unsafe_DatePicker/Unsafe_RangeDatePickers.d.ts +12 -0
  25. package/lib/components/Unsafe_DatePicker/index.d.ts +11 -0
  26. package/lib/components/Unsafe_DatePicker/index.js +3702 -0
  27. package/lib/components/Unsafe_DatePicker/index.js.map +1 -0
  28. package/lib/components/Unsafe_DatePicker/resourceHelper.d.ts +3 -0
  29. package/lib/components/Unsafe_DatePicker/validate.d.ts +1 -0
  30. package/lib/resources/HN.Designsystem.DatePicker.en-GB.json.d.ts +1 -4
  31. package/lib/resources/HN.Designsystem.DatePicker.nb-NO.json.d.ts +1 -6
  32. package/lib/resources/HN.Designsystem.Unsafe_DatePicker.nb-NO.json.d.ts +32 -0
  33. package/package.json +2 -1
@@ -1,5 +1,6 @@
1
- import React, { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
2
- import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, eachYearOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getWeek, getYear, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, isValid, isWithinInterval, max, min, parse, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear } from "date-fns";
1
+ import { t as DayPicker } from "../../DayPicker.js";
2
+ import React, { useEffect, useId, useRef, useState } from "react";
3
+ import { format, isAfter, isBefore, isSameDay, isValid, isWithinInterval, parse } from "date-fns";
3
4
  import { nb } from "date-fns/locale";
4
5
  import Button from "@helsenorge/designsystem-react/components/Button";
5
6
  import Icon from "@helsenorge/designsystem-react/components/Icon";
@@ -14,7 +15,6 @@ import { useLanguage } from "@helsenorge/designsystem-react/utils/language";
14
15
  import { isMobileUA } from "@helsenorge/designsystem-react/utils/mobile";
15
16
  import { isMutableRefObject, mergeRefs } from "@helsenorge/designsystem-react/utils/refs";
16
17
  import classNames from "classnames";
17
- import { enUS, enUS as defaultLocale } from "date-fns/locale/en-US";
18
18
  import reactdaypickerstyles from "react-day-picker/dist/style.module.css";
19
19
  import { useInterval } from "@helsenorge/designsystem-react/hooks/useInterval";
20
20
  import { useIsVisible } from "@helsenorge/designsystem-react/hooks/useIsVisible";
@@ -26,1969 +26,6 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
26
26
  import { LanguageLocales as LanguageLocales$1 } from "@helsenorge/designsystem-react";
27
27
  import ErrorWrapper from "@helsenorge/designsystem-react/components/ErrorWrapper";
28
28
  import { isComponent } from "@helsenorge/designsystem-react/utils/component";
29
- var __defProp = Object.defineProperty;
30
- var __export = (all, symbols) => {
31
- let target = {};
32
- for (var name in all) __defProp(target, name, {
33
- get: all[name],
34
- enumerable: true
35
- });
36
- if (symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
37
- return target;
38
- };
39
- function tzName(timeZone, date, format$1 = "long") {
40
- return new Intl.DateTimeFormat("en-US", {
41
- hour: "numeric",
42
- timeZone,
43
- timeZoneName: format$1
44
- }).format(date).split(/\s/g).slice(2).join(" ");
45
- }
46
- var offsetFormatCache = {};
47
- var offsetCache = {};
48
- function tzOffset(timeZone, date) {
49
- try {
50
- const offsetStr = (offsetFormatCache[timeZone] ||= new Intl.DateTimeFormat("en-US", {
51
- timeZone,
52
- timeZoneName: "longOffset"
53
- }).format)(date).split("GMT")[1];
54
- if (offsetStr in offsetCache) return offsetCache[offsetStr];
55
- return calcOffset(offsetStr, offsetStr.split(":"));
56
- } catch {
57
- if (timeZone in offsetCache) return offsetCache[timeZone];
58
- const captures = timeZone?.match(offsetRe);
59
- if (captures) return calcOffset(timeZone, captures.slice(1));
60
- return NaN;
61
- }
62
- }
63
- var offsetRe = /([+-]\d\d):?(\d\d)?/;
64
- function calcOffset(cacheStr, values) {
65
- const hours = +(values[0] || 0);
66
- const minutes = +(values[1] || 0);
67
- const seconds = +(values[2] || 0) / 60;
68
- return offsetCache[cacheStr] = hours * 60 + minutes > 0 ? hours * 60 + minutes + seconds : hours * 60 - minutes - seconds;
69
- }
70
- var TZDateMini = class TZDateMini extends Date {
71
- constructor(...args) {
72
- super();
73
- if (args.length > 1 && typeof args[args.length - 1] === "string") this.timeZone = args.pop();
74
- this.internal = /* @__PURE__ */ new Date();
75
- if (isNaN(tzOffset(this.timeZone, this))) this.setTime(NaN);
76
- else if (!args.length) this.setTime(Date.now());
77
- else if (typeof args[0] === "number" && (args.length === 1 || args.length === 2 && typeof args[1] !== "number")) this.setTime(args[0]);
78
- else if (typeof args[0] === "string") this.setTime(+new Date(args[0]));
79
- else if (args[0] instanceof Date) this.setTime(+args[0]);
80
- else {
81
- this.setTime(+new Date(...args));
82
- adjustToSystemTZ(this, NaN);
83
- syncToInternal(this);
84
- }
85
- }
86
- static tz(tz, ...args) {
87
- return args.length ? new TZDateMini(...args, tz) : new TZDateMini(Date.now(), tz);
88
- }
89
- withTimeZone(timeZone) {
90
- return new TZDateMini(+this, timeZone);
91
- }
92
- getTimezoneOffset() {
93
- const offset = -tzOffset(this.timeZone, this);
94
- return offset > 0 ? Math.floor(offset) : Math.ceil(offset);
95
- }
96
- setTime(time) {
97
- Date.prototype.setTime.apply(this, arguments);
98
- syncToInternal(this);
99
- return +this;
100
- }
101
- [Symbol.for("constructDateFrom")](date) {
102
- return new TZDateMini(+new Date(date), this.timeZone);
103
- }
104
- };
105
- var re = /^(get|set)(?!UTC)/;
106
- Object.getOwnPropertyNames(Date.prototype).forEach((method) => {
107
- if (!re.test(method)) return;
108
- const utcMethod = method.replace(re, "$1UTC");
109
- if (!TZDateMini.prototype[utcMethod]) return;
110
- if (method.startsWith("get")) TZDateMini.prototype[method] = function() {
111
- return this.internal[utcMethod]();
112
- };
113
- else {
114
- TZDateMini.prototype[method] = function() {
115
- Date.prototype[utcMethod].apply(this.internal, arguments);
116
- syncFromInternal(this);
117
- return +this;
118
- };
119
- TZDateMini.prototype[utcMethod] = function() {
120
- Date.prototype[utcMethod].apply(this, arguments);
121
- syncToInternal(this);
122
- return +this;
123
- };
124
- }
125
- });
126
- function syncToInternal(date) {
127
- date.internal.setTime(+date);
128
- date.internal.setUTCSeconds(date.internal.getUTCSeconds() - Math.round(-tzOffset(date.timeZone, date) * 60));
129
- }
130
- function syncFromInternal(date) {
131
- Date.prototype.setFullYear.call(date, date.internal.getUTCFullYear(), date.internal.getUTCMonth(), date.internal.getUTCDate());
132
- Date.prototype.setHours.call(date, date.internal.getUTCHours(), date.internal.getUTCMinutes(), date.internal.getUTCSeconds(), date.internal.getUTCMilliseconds());
133
- adjustToSystemTZ(date);
134
- }
135
- function adjustToSystemTZ(date) {
136
- const baseOffset = tzOffset(date.timeZone, date);
137
- const offset = baseOffset > 0 ? Math.floor(baseOffset) : Math.ceil(baseOffset);
138
- const prevHour = /* @__PURE__ */ new Date(+date);
139
- prevHour.setUTCHours(prevHour.getUTCHours() - 1);
140
- const systemOffset = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset();
141
- const systemDSTChange = systemOffset - -(/* @__PURE__ */ new Date(+prevHour)).getTimezoneOffset();
142
- const dstShift = Date.prototype.getHours.apply(date) !== date.internal.getUTCHours();
143
- if (systemDSTChange && dstShift) date.internal.setUTCMinutes(date.internal.getUTCMinutes() + systemDSTChange);
144
- const offsetDiff = systemOffset - offset;
145
- if (offsetDiff) Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetDiff);
146
- const systemDate = /* @__PURE__ */ new Date(+date);
147
- systemDate.setUTCSeconds(0);
148
- const systemSecondsOffset = systemOffset > 0 ? systemDate.getSeconds() : (systemDate.getSeconds() - 60) % 60;
149
- const secondsOffset = Math.round(-(tzOffset(date.timeZone, date) * 60)) % 60;
150
- if (secondsOffset || systemSecondsOffset) {
151
- date.internal.setUTCSeconds(date.internal.getUTCSeconds() + secondsOffset);
152
- Date.prototype.setUTCSeconds.call(date, Date.prototype.getUTCSeconds.call(date) + secondsOffset + systemSecondsOffset);
153
- }
154
- const postBaseOffset = tzOffset(date.timeZone, date);
155
- const postOffset = postBaseOffset > 0 ? Math.floor(postBaseOffset) : Math.ceil(postBaseOffset);
156
- const postOffsetDiff = -(/* @__PURE__ */ new Date(+date)).getTimezoneOffset() - postOffset;
157
- const offsetChanged = postOffset !== offset;
158
- const postDiff = postOffsetDiff - offsetDiff;
159
- if (offsetChanged && postDiff) {
160
- Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + postDiff);
161
- const newBaseOffset = tzOffset(date.timeZone, date);
162
- const offsetChange = postOffset - (newBaseOffset > 0 ? Math.floor(newBaseOffset) : Math.ceil(newBaseOffset));
163
- if (offsetChange) {
164
- date.internal.setUTCMinutes(date.internal.getUTCMinutes() + offsetChange);
165
- Date.prototype.setUTCMinutes.call(date, Date.prototype.getUTCMinutes.call(date) + offsetChange);
166
- }
167
- }
168
- }
169
- var TZDate = class TZDate extends TZDateMini {
170
- static tz(tz, ...args) {
171
- return args.length ? new TZDate(...args, tz) : new TZDate(Date.now(), tz);
172
- }
173
- toISOString() {
174
- const [sign, hours, minutes] = this.tzComponents();
175
- const tz = `${sign}${hours}:${minutes}`;
176
- return this.internal.toISOString().slice(0, -1) + tz;
177
- }
178
- toString() {
179
- return `${this.toDateString()} ${this.toTimeString()}`;
180
- }
181
- toDateString() {
182
- const [day, date, month, year] = this.internal.toUTCString().split(" ");
183
- return `${day?.slice(0, -1)} ${month} ${date} ${year}`;
184
- }
185
- toTimeString() {
186
- const time = this.internal.toUTCString().split(" ")[4];
187
- const [sign, hours, minutes] = this.tzComponents();
188
- return `${time} GMT${sign}${hours}${minutes} (${tzName(this.timeZone, this)})`;
189
- }
190
- toLocaleString(locales, options) {
191
- return Date.prototype.toLocaleString.call(this, locales, {
192
- ...options,
193
- timeZone: options?.timeZone || this.timeZone
194
- });
195
- }
196
- toLocaleDateString(locales, options) {
197
- return Date.prototype.toLocaleDateString.call(this, locales, {
198
- ...options,
199
- timeZone: options?.timeZone || this.timeZone
200
- });
201
- }
202
- toLocaleTimeString(locales, options) {
203
- return Date.prototype.toLocaleTimeString.call(this, locales, {
204
- ...options,
205
- timeZone: options?.timeZone || this.timeZone
206
- });
207
- }
208
- tzComponents() {
209
- const offset = this.getTimezoneOffset();
210
- return [
211
- offset > 0 ? "-" : "+",
212
- String(Math.floor(Math.abs(offset) / 60)).padStart(2, "0"),
213
- String(Math.abs(offset) % 60).padStart(2, "0")
214
- ];
215
- }
216
- withTimeZone(timeZone) {
217
- return new TZDate(+this, timeZone);
218
- }
219
- [Symbol.for("constructDateFrom")](date) {
220
- return new TZDate(+new Date(date), this.timeZone);
221
- }
222
- };
223
- var FIVE_WEEKS = 5;
224
- var FOUR_WEEKS = 4;
225
- function getBroadcastWeeksInMonth(month, dateLib) {
226
- const firstDayOfMonth = dateLib.startOfMonth(month);
227
- const firstDayOfWeek = firstDayOfMonth.getDay() > 0 ? firstDayOfMonth.getDay() : 7;
228
- const broadcastStartDate = dateLib.addDays(month, -firstDayOfWeek + 1);
229
- const lastDateOfLastWeek = dateLib.addDays(broadcastStartDate, FIVE_WEEKS * 7 - 1);
230
- return dateLib.getMonth(month) === dateLib.getMonth(lastDateOfLastWeek) ? FIVE_WEEKS : FOUR_WEEKS;
231
- }
232
- function startOfBroadcastWeek(date, dateLib) {
233
- const firstOfMonth = dateLib.startOfMonth(date);
234
- const dayOfWeek = firstOfMonth.getDay();
235
- if (dayOfWeek === 1) return firstOfMonth;
236
- else if (dayOfWeek === 0) return dateLib.addDays(firstOfMonth, -6);
237
- else return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
238
- }
239
- function endOfBroadcastWeek(date, dateLib) {
240
- const startDate = startOfBroadcastWeek(date, dateLib);
241
- const numberOfWeeks = getBroadcastWeeksInMonth(date, dateLib);
242
- return dateLib.addDays(startDate, numberOfWeeks * 7 - 1);
243
- }
244
- var DateLib = class DateLib {
245
- constructor(options, overrides) {
246
- this.Date = Date;
247
- this.today = () => {
248
- if (this.overrides?.today) return this.overrides.today();
249
- if (this.options.timeZone) return TZDate.tz(this.options.timeZone);
250
- return new this.Date();
251
- };
252
- this.newDate = (year, monthIndex, date) => {
253
- if (this.overrides?.newDate) return this.overrides.newDate(year, monthIndex, date);
254
- if (this.options.timeZone) return new TZDate(year, monthIndex, date, this.options.timeZone);
255
- return new Date(year, monthIndex, date);
256
- };
257
- this.addDays = (date, amount) => {
258
- return this.overrides?.addDays ? this.overrides.addDays(date, amount) : addDays(date, amount);
259
- };
260
- this.addMonths = (date, amount) => {
261
- return this.overrides?.addMonths ? this.overrides.addMonths(date, amount) : addMonths(date, amount);
262
- };
263
- this.addWeeks = (date, amount) => {
264
- return this.overrides?.addWeeks ? this.overrides.addWeeks(date, amount) : addWeeks(date, amount);
265
- };
266
- this.addYears = (date, amount) => {
267
- return this.overrides?.addYears ? this.overrides.addYears(date, amount) : addYears(date, amount);
268
- };
269
- this.differenceInCalendarDays = (dateLeft, dateRight) => {
270
- return this.overrides?.differenceInCalendarDays ? this.overrides.differenceInCalendarDays(dateLeft, dateRight) : differenceInCalendarDays(dateLeft, dateRight);
271
- };
272
- this.differenceInCalendarMonths = (dateLeft, dateRight) => {
273
- return this.overrides?.differenceInCalendarMonths ? this.overrides.differenceInCalendarMonths(dateLeft, dateRight) : differenceInCalendarMonths(dateLeft, dateRight);
274
- };
275
- this.eachMonthOfInterval = (interval) => {
276
- return this.overrides?.eachMonthOfInterval ? this.overrides.eachMonthOfInterval(interval) : eachMonthOfInterval(interval);
277
- };
278
- this.eachYearOfInterval = (interval) => {
279
- const years = this.overrides?.eachYearOfInterval ? this.overrides.eachYearOfInterval(interval) : eachYearOfInterval(interval);
280
- const uniqueYears = new Set(years.map((d) => this.getYear(d)));
281
- if (uniqueYears.size === years.length) return years;
282
- const yearsArray = [];
283
- uniqueYears.forEach((y) => {
284
- yearsArray.push(new Date(y, 0, 1));
285
- });
286
- return yearsArray;
287
- };
288
- this.endOfBroadcastWeek = (date) => {
289
- return this.overrides?.endOfBroadcastWeek ? this.overrides.endOfBroadcastWeek(date) : endOfBroadcastWeek(date, this);
290
- };
291
- this.endOfISOWeek = (date) => {
292
- return this.overrides?.endOfISOWeek ? this.overrides.endOfISOWeek(date) : endOfISOWeek(date);
293
- };
294
- this.endOfMonth = (date) => {
295
- return this.overrides?.endOfMonth ? this.overrides.endOfMonth(date) : endOfMonth(date);
296
- };
297
- this.endOfWeek = (date, options$1) => {
298
- return this.overrides?.endOfWeek ? this.overrides.endOfWeek(date, options$1) : endOfWeek(date, this.options);
299
- };
300
- this.endOfYear = (date) => {
301
- return this.overrides?.endOfYear ? this.overrides.endOfYear(date) : endOfYear(date);
302
- };
303
- this.format = (date, formatStr, _options) => {
304
- const formatted = this.overrides?.format ? this.overrides.format(date, formatStr, this.options) : format(date, formatStr, this.options);
305
- if (this.options.numerals && this.options.numerals !== "latn") return this.replaceDigits(formatted);
306
- return formatted;
307
- };
308
- this.getISOWeek = (date) => {
309
- return this.overrides?.getISOWeek ? this.overrides.getISOWeek(date) : getISOWeek(date);
310
- };
311
- this.getMonth = (date, _options) => {
312
- return this.overrides?.getMonth ? this.overrides.getMonth(date, this.options) : getMonth(date, this.options);
313
- };
314
- this.getYear = (date, _options) => {
315
- return this.overrides?.getYear ? this.overrides.getYear(date, this.options) : getYear(date, this.options);
316
- };
317
- this.getWeek = (date, _options) => {
318
- return this.overrides?.getWeek ? this.overrides.getWeek(date, this.options) : getWeek(date, this.options);
319
- };
320
- this.isAfter = (date, dateToCompare) => {
321
- return this.overrides?.isAfter ? this.overrides.isAfter(date, dateToCompare) : isAfter(date, dateToCompare);
322
- };
323
- this.isBefore = (date, dateToCompare) => {
324
- return this.overrides?.isBefore ? this.overrides.isBefore(date, dateToCompare) : isBefore(date, dateToCompare);
325
- };
326
- this.isDate = (value) => {
327
- return this.overrides?.isDate ? this.overrides.isDate(value) : isDate(value);
328
- };
329
- this.isSameDay = (dateLeft, dateRight) => {
330
- return this.overrides?.isSameDay ? this.overrides.isSameDay(dateLeft, dateRight) : isSameDay(dateLeft, dateRight);
331
- };
332
- this.isSameMonth = (dateLeft, dateRight) => {
333
- return this.overrides?.isSameMonth ? this.overrides.isSameMonth(dateLeft, dateRight) : isSameMonth(dateLeft, dateRight);
334
- };
335
- this.isSameYear = (dateLeft, dateRight) => {
336
- return this.overrides?.isSameYear ? this.overrides.isSameYear(dateLeft, dateRight) : isSameYear(dateLeft, dateRight);
337
- };
338
- this.max = (dates) => {
339
- return this.overrides?.max ? this.overrides.max(dates) : max(dates);
340
- };
341
- this.min = (dates) => {
342
- return this.overrides?.min ? this.overrides.min(dates) : min(dates);
343
- };
344
- this.setMonth = (date, month) => {
345
- return this.overrides?.setMonth ? this.overrides.setMonth(date, month) : setMonth(date, month);
346
- };
347
- this.setYear = (date, year) => {
348
- return this.overrides?.setYear ? this.overrides.setYear(date, year) : setYear(date, year);
349
- };
350
- this.startOfBroadcastWeek = (date, _dateLib) => {
351
- return this.overrides?.startOfBroadcastWeek ? this.overrides.startOfBroadcastWeek(date, this) : startOfBroadcastWeek(date, this);
352
- };
353
- this.startOfDay = (date) => {
354
- return this.overrides?.startOfDay ? this.overrides.startOfDay(date) : startOfDay(date);
355
- };
356
- this.startOfISOWeek = (date) => {
357
- return this.overrides?.startOfISOWeek ? this.overrides.startOfISOWeek(date) : startOfISOWeek(date);
358
- };
359
- this.startOfMonth = (date) => {
360
- return this.overrides?.startOfMonth ? this.overrides.startOfMonth(date) : startOfMonth(date);
361
- };
362
- this.startOfWeek = (date, _options) => {
363
- return this.overrides?.startOfWeek ? this.overrides.startOfWeek(date, this.options) : startOfWeek(date, this.options);
364
- };
365
- this.startOfYear = (date) => {
366
- return this.overrides?.startOfYear ? this.overrides.startOfYear(date) : startOfYear(date);
367
- };
368
- this.options = {
369
- locale: enUS,
370
- ...options
371
- };
372
- this.overrides = overrides;
373
- }
374
- getDigitMap() {
375
- const { numerals = "latn" } = this.options;
376
- const formatter = new Intl.NumberFormat("en-US", { numberingSystem: numerals });
377
- const digitMap = {};
378
- for (let i = 0; i < 10; i++) digitMap[i.toString()] = formatter.format(i);
379
- return digitMap;
380
- }
381
- replaceDigits(input) {
382
- const digitMap = this.getDigitMap();
383
- return input.replace(/\d/g, (digit) => digitMap[digit] || digit);
384
- }
385
- formatNumber(value) {
386
- return this.replaceDigits(value.toString());
387
- }
388
- getMonthYearOrder() {
389
- const code = this.options.locale?.code;
390
- if (!code) return "month-first";
391
- return DateLib.yearFirstLocales.has(code) ? "year-first" : "month-first";
392
- }
393
- formatMonthYear(date) {
394
- const { locale, timeZone, numerals } = this.options;
395
- const localeCode = locale?.code;
396
- if (localeCode && DateLib.yearFirstLocales.has(localeCode)) try {
397
- return new Intl.DateTimeFormat(localeCode, {
398
- month: "long",
399
- year: "numeric",
400
- timeZone,
401
- numberingSystem: numerals
402
- }).format(date);
403
- } catch {}
404
- const pattern = this.getMonthYearOrder() === "year-first" ? "y LLLL" : "LLLL y";
405
- return this.format(date, pattern);
406
- }
407
- };
408
- DateLib.yearFirstLocales = new Set([
409
- "eu",
410
- "hu",
411
- "ja",
412
- "ja-Hira",
413
- "ja-JP",
414
- "ko",
415
- "ko-KR",
416
- "lt",
417
- "lt-LT",
418
- "lv",
419
- "lv-LV",
420
- "mn",
421
- "mn-MN",
422
- "zh",
423
- "zh-CN",
424
- "zh-HK",
425
- "zh-TW"
426
- ]);
427
- const defaultDateLib = new DateLib();
428
- var CalendarDay = class {
429
- constructor(date, displayMonth, dateLib = defaultDateLib) {
430
- this.date = date;
431
- this.displayMonth = displayMonth;
432
- this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
433
- this.dateLib = dateLib;
434
- this.isoDate = dateLib.format(date, "yyyy-MM-dd");
435
- this.displayMonthId = dateLib.format(displayMonth, "yyyy-MM");
436
- this.dateMonthId = dateLib.format(date, "yyyy-MM");
437
- }
438
- isEqualTo(day) {
439
- return this.dateLib.isSameDay(day.date, this.date) && this.dateLib.isSameMonth(day.displayMonth, this.displayMonth);
440
- }
441
- };
442
- var CalendarMonth = class {
443
- constructor(month, weeks) {
444
- this.date = month;
445
- this.weeks = weeks;
446
- }
447
- };
448
- var CalendarWeek = class {
449
- constructor(weekNumber, days) {
450
- this.days = days;
451
- this.weekNumber = weekNumber;
452
- }
453
- };
454
- function Button$1(props) {
455
- return React.createElement("button", { ...props });
456
- }
457
- function CaptionLabel(props) {
458
- return React.createElement("span", { ...props });
459
- }
460
- function Chevron(props) {
461
- const { size = 24, orientation = "left", className } = props;
462
- return React.createElement("svg", {
463
- className,
464
- width: size,
465
- height: size,
466
- viewBox: "0 0 24 24"
467
- }, 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" }), 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" }), orientation === "left" && React.createElement("polygon", { points: "16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" }), orientation === "right" && React.createElement("polygon", { points: "8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20" }));
468
- }
469
- function Day(props) {
470
- const { day, modifiers, ...tdProps } = props;
471
- return React.createElement("td", { ...tdProps });
472
- }
473
- function DayButton(props) {
474
- const { day, modifiers, ...buttonProps } = props;
475
- const ref = React.useRef(null);
476
- React.useEffect(() => {
477
- if (modifiers.focused) ref.current?.focus();
478
- }, [modifiers.focused]);
479
- return React.createElement("button", {
480
- ref,
481
- ...buttonProps
482
- });
483
- }
484
- var UI;
485
- (function(UI$1) {
486
- UI$1["Root"] = "root";
487
- UI$1["Chevron"] = "chevron";
488
- UI$1["Day"] = "day";
489
- UI$1["DayButton"] = "day_button";
490
- UI$1["CaptionLabel"] = "caption_label";
491
- UI$1["Dropdowns"] = "dropdowns";
492
- UI$1["Dropdown"] = "dropdown";
493
- UI$1["DropdownRoot"] = "dropdown_root";
494
- UI$1["Footer"] = "footer";
495
- UI$1["MonthGrid"] = "month_grid";
496
- UI$1["MonthCaption"] = "month_caption";
497
- UI$1["MonthsDropdown"] = "months_dropdown";
498
- UI$1["Month"] = "month";
499
- UI$1["Months"] = "months";
500
- UI$1["Nav"] = "nav";
501
- UI$1["NextMonthButton"] = "button_next";
502
- UI$1["PreviousMonthButton"] = "button_previous";
503
- UI$1["Week"] = "week";
504
- UI$1["Weeks"] = "weeks";
505
- UI$1["Weekday"] = "weekday";
506
- UI$1["Weekdays"] = "weekdays";
507
- UI$1["WeekNumber"] = "week_number";
508
- UI$1["WeekNumberHeader"] = "week_number_header";
509
- UI$1["YearsDropdown"] = "years_dropdown";
510
- })(UI || (UI = {}));
511
- var DayFlag;
512
- (function(DayFlag$1) {
513
- DayFlag$1["disabled"] = "disabled";
514
- DayFlag$1["hidden"] = "hidden";
515
- DayFlag$1["outside"] = "outside";
516
- DayFlag$1["focused"] = "focused";
517
- DayFlag$1["today"] = "today";
518
- })(DayFlag || (DayFlag = {}));
519
- var SelectionState;
520
- (function(SelectionState$1) {
521
- SelectionState$1["range_end"] = "range_end";
522
- SelectionState$1["range_middle"] = "range_middle";
523
- SelectionState$1["range_start"] = "range_start";
524
- SelectionState$1["selected"] = "selected";
525
- })(SelectionState || (SelectionState = {}));
526
- var Animation;
527
- (function(Animation$1) {
528
- Animation$1["weeks_before_enter"] = "weeks_before_enter";
529
- Animation$1["weeks_before_exit"] = "weeks_before_exit";
530
- Animation$1["weeks_after_enter"] = "weeks_after_enter";
531
- Animation$1["weeks_after_exit"] = "weeks_after_exit";
532
- Animation$1["caption_after_enter"] = "caption_after_enter";
533
- Animation$1["caption_after_exit"] = "caption_after_exit";
534
- Animation$1["caption_before_enter"] = "caption_before_enter";
535
- Animation$1["caption_before_exit"] = "caption_before_exit";
536
- })(Animation || (Animation = {}));
537
- function Dropdown(props) {
538
- const { options, className, components, classNames: classNames$1, ...selectProps } = props;
539
- const cssClassSelect = [classNames$1[UI.Dropdown], className].join(" ");
540
- const selectedOption = options?.find(({ value }) => value === selectProps.value);
541
- return React.createElement("span", {
542
- "data-disabled": selectProps.disabled,
543
- className: classNames$1[UI.DropdownRoot]
544
- }, React.createElement(components.Select, {
545
- className: cssClassSelect,
546
- ...selectProps
547
- }, options?.map(({ value, label, disabled }) => React.createElement(components.Option, {
548
- key: value,
549
- value,
550
- disabled
551
- }, label))), React.createElement("span", {
552
- className: classNames$1[UI.CaptionLabel],
553
- "aria-hidden": true
554
- }, selectedOption?.label, React.createElement(components.Chevron, {
555
- orientation: "down",
556
- size: 18,
557
- className: classNames$1[UI.Chevron]
558
- })));
559
- }
560
- function DropdownNav(props) {
561
- return React.createElement("div", { ...props });
562
- }
563
- function Footer(props) {
564
- return React.createElement("div", { ...props });
565
- }
566
- function Month(props) {
567
- const { calendarMonth, displayIndex, ...divProps } = props;
568
- return React.createElement("div", { ...divProps }, props.children);
569
- }
570
- function MonthCaption(props) {
571
- const { calendarMonth, displayIndex, ...divProps } = props;
572
- return React.createElement("div", { ...divProps });
573
- }
574
- function MonthGrid(props) {
575
- return React.createElement("table", { ...props });
576
- }
577
- function Months(props) {
578
- return React.createElement("div", { ...props });
579
- }
580
- const dayPickerContext = createContext(void 0);
581
- function useDayPicker() {
582
- const context = useContext(dayPickerContext);
583
- if (context === void 0) throw new Error("useDayPicker() must be used within a custom component.");
584
- return context;
585
- }
586
- function MonthsDropdown(props) {
587
- const { components } = useDayPicker();
588
- return React.createElement(components.Dropdown, { ...props });
589
- }
590
- function Nav(props) {
591
- const { onPreviousClick, onNextClick, previousMonth: previousMonth$2, nextMonth: nextMonth$2, ...navProps } = props;
592
- const { components, classNames: classNames$1, labels: { labelPrevious: labelPrevious$1, labelNext: labelNext$1 } } = useDayPicker();
593
- const handleNextClick = useCallback((e) => {
594
- if (nextMonth$2) onNextClick?.(e);
595
- }, [nextMonth$2, onNextClick]);
596
- const handlePreviousClick = useCallback((e) => {
597
- if (previousMonth$2) onPreviousClick?.(e);
598
- }, [previousMonth$2, onPreviousClick]);
599
- return React.createElement("nav", { ...navProps }, React.createElement(components.PreviousMonthButton, {
600
- type: "button",
601
- className: classNames$1[UI.PreviousMonthButton],
602
- tabIndex: previousMonth$2 ? void 0 : -1,
603
- "aria-disabled": previousMonth$2 ? void 0 : true,
604
- "aria-label": labelPrevious$1(previousMonth$2),
605
- onClick: handlePreviousClick
606
- }, React.createElement(components.Chevron, {
607
- disabled: previousMonth$2 ? void 0 : true,
608
- className: classNames$1[UI.Chevron],
609
- orientation: "left"
610
- })), React.createElement(components.NextMonthButton, {
611
- type: "button",
612
- className: classNames$1[UI.NextMonthButton],
613
- tabIndex: nextMonth$2 ? void 0 : -1,
614
- "aria-disabled": nextMonth$2 ? void 0 : true,
615
- "aria-label": labelNext$1(nextMonth$2),
616
- onClick: handleNextClick
617
- }, React.createElement(components.Chevron, {
618
- disabled: nextMonth$2 ? void 0 : true,
619
- orientation: "right",
620
- className: classNames$1[UI.Chevron]
621
- })));
622
- }
623
- function NextMonthButton(props) {
624
- const { components } = useDayPicker();
625
- return React.createElement(components.Button, { ...props });
626
- }
627
- function Option(props) {
628
- return React.createElement("option", { ...props });
629
- }
630
- function PreviousMonthButton(props) {
631
- const { components } = useDayPicker();
632
- return React.createElement(components.Button, { ...props });
633
- }
634
- function Root(props) {
635
- const { rootRef, ...rest } = props;
636
- return React.createElement("div", {
637
- ...rest,
638
- ref: rootRef
639
- });
640
- }
641
- function Select(props) {
642
- return React.createElement("select", { ...props });
643
- }
644
- function Week(props) {
645
- const { week, ...trProps } = props;
646
- return React.createElement("tr", { ...trProps });
647
- }
648
- function Weekday(props) {
649
- return React.createElement("th", { ...props });
650
- }
651
- function Weekdays(props) {
652
- return React.createElement("thead", { "aria-hidden": true }, React.createElement("tr", { ...props }));
653
- }
654
- function WeekNumber(props) {
655
- const { week, ...thProps } = props;
656
- return React.createElement("th", { ...thProps });
657
- }
658
- function WeekNumberHeader(props) {
659
- return React.createElement("th", { ...props });
660
- }
661
- function Weeks(props) {
662
- return React.createElement("tbody", { ...props });
663
- }
664
- function YearsDropdown(props) {
665
- const { components } = useDayPicker();
666
- return React.createElement(components.Dropdown, { ...props });
667
- }
668
- var custom_components_exports = /* @__PURE__ */ __export({
669
- Button: () => Button$1,
670
- CaptionLabel: () => CaptionLabel,
671
- Chevron: () => Chevron,
672
- Day: () => Day,
673
- DayButton: () => DayButton,
674
- Dropdown: () => Dropdown,
675
- DropdownNav: () => DropdownNav,
676
- Footer: () => Footer,
677
- Month: () => Month,
678
- MonthCaption: () => MonthCaption,
679
- MonthGrid: () => MonthGrid,
680
- Months: () => Months,
681
- MonthsDropdown: () => MonthsDropdown,
682
- Nav: () => Nav,
683
- NextMonthButton: () => NextMonthButton,
684
- Option: () => Option,
685
- PreviousMonthButton: () => PreviousMonthButton,
686
- Root: () => Root,
687
- Select: () => Select,
688
- Week: () => Week,
689
- WeekNumber: () => WeekNumber,
690
- WeekNumberHeader: () => WeekNumberHeader,
691
- Weekday: () => Weekday,
692
- Weekdays: () => Weekdays,
693
- Weeks: () => Weeks,
694
- YearsDropdown: () => YearsDropdown
695
- });
696
- function rangeIncludesDate(range, date, excludeEnds = false, dateLib = defaultDateLib) {
697
- let { from, to } = range;
698
- const { differenceInCalendarDays: differenceInCalendarDays$1, isSameDay: isSameDay$1 } = dateLib;
699
- if (from && to) {
700
- if (differenceInCalendarDays$1(to, from) < 0) [from, to] = [to, from];
701
- return differenceInCalendarDays$1(date, from) >= (excludeEnds ? 1 : 0) && differenceInCalendarDays$1(to, date) >= (excludeEnds ? 1 : 0);
702
- }
703
- if (!excludeEnds && to) return isSameDay$1(to, date);
704
- if (!excludeEnds && from) return isSameDay$1(from, date);
705
- return false;
706
- }
707
- function isDateInterval(matcher) {
708
- return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
709
- }
710
- function isDateRange(value) {
711
- return Boolean(value && typeof value === "object" && "from" in value);
712
- }
713
- function isDateAfterType(value) {
714
- return Boolean(value && typeof value === "object" && "after" in value);
715
- }
716
- function isDateBeforeType(value) {
717
- return Boolean(value && typeof value === "object" && "before" in value);
718
- }
719
- function isDayOfWeekType(value) {
720
- return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
721
- }
722
- function isDatesArray(value, dateLib) {
723
- return Array.isArray(value) && value.every(dateLib.isDate);
724
- }
725
- function dateMatchModifiers(date, matchers, dateLib = defaultDateLib) {
726
- const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
727
- const { isSameDay: isSameDay$1, differenceInCalendarDays: differenceInCalendarDays$1, isAfter: isAfter$1 } = dateLib;
728
- return matchersArr.some((matcher) => {
729
- if (typeof matcher === "boolean") return matcher;
730
- if (dateLib.isDate(matcher)) return isSameDay$1(date, matcher);
731
- if (isDatesArray(matcher, dateLib)) return matcher.includes(date);
732
- if (isDateRange(matcher)) return rangeIncludesDate(matcher, date, false, dateLib);
733
- if (isDayOfWeekType(matcher)) {
734
- if (!Array.isArray(matcher.dayOfWeek)) return matcher.dayOfWeek === date.getDay();
735
- return matcher.dayOfWeek.includes(date.getDay());
736
- }
737
- if (isDateInterval(matcher)) {
738
- const diffBefore = differenceInCalendarDays$1(matcher.before, date);
739
- const diffAfter = differenceInCalendarDays$1(matcher.after, date);
740
- const isDayBefore = diffBefore > 0;
741
- const isDayAfter = diffAfter < 0;
742
- if (isAfter$1(matcher.before, matcher.after)) return isDayAfter && isDayBefore;
743
- else return isDayBefore || isDayAfter;
744
- }
745
- if (isDateAfterType(matcher)) return differenceInCalendarDays$1(date, matcher.after) > 0;
746
- if (isDateBeforeType(matcher)) return differenceInCalendarDays$1(matcher.before, date) > 0;
747
- if (typeof matcher === "function") return matcher(date);
748
- return false;
749
- });
750
- }
751
- function createGetModifiers(days, props, navStart, navEnd, dateLib) {
752
- const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today = dateLib.today() } = props;
753
- const { isSameDay: isSameDay$1, isSameMonth: isSameMonth$1, startOfMonth: startOfMonth$1, isBefore: isBefore$1, endOfMonth: endOfMonth$1, isAfter: isAfter$1 } = dateLib;
754
- const computedNavStart = navStart && startOfMonth$1(navStart);
755
- const computedNavEnd = navEnd && endOfMonth$1(navEnd);
756
- const internalModifiersMap = {
757
- [DayFlag.focused]: [],
758
- [DayFlag.outside]: [],
759
- [DayFlag.disabled]: [],
760
- [DayFlag.hidden]: [],
761
- [DayFlag.today]: []
762
- };
763
- const customModifiersMap = {};
764
- for (const day of days) {
765
- const { date, displayMonth } = day;
766
- const isOutside = Boolean(displayMonth && !isSameMonth$1(date, displayMonth));
767
- const isBeforeNavStart = Boolean(computedNavStart && isBefore$1(date, computedNavStart));
768
- const isAfterNavEnd = Boolean(computedNavEnd && isAfter$1(date, computedNavEnd));
769
- const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
770
- const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeNavStart || isAfterNavEnd || !broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
771
- const isToday = isSameDay$1(date, today);
772
- if (isOutside) internalModifiersMap.outside.push(day);
773
- if (isDisabled) internalModifiersMap.disabled.push(day);
774
- if (isHidden) internalModifiersMap.hidden.push(day);
775
- if (isToday) internalModifiersMap.today.push(day);
776
- if (modifiers) Object.keys(modifiers).forEach((name) => {
777
- const modifierValue = modifiers?.[name];
778
- if (!(modifierValue ? dateMatchModifiers(date, modifierValue, dateLib) : false)) return;
779
- if (customModifiersMap[name]) customModifiersMap[name].push(day);
780
- else customModifiersMap[name] = [day];
781
- });
782
- }
783
- return (day) => {
784
- const dayFlags = {
785
- [DayFlag.focused]: false,
786
- [DayFlag.disabled]: false,
787
- [DayFlag.hidden]: false,
788
- [DayFlag.outside]: false,
789
- [DayFlag.today]: false
790
- };
791
- const customModifiers = {};
792
- for (const name in internalModifiersMap) dayFlags[name] = internalModifiersMap[name].some((d) => d === day);
793
- for (const name in customModifiersMap) customModifiers[name] = customModifiersMap[name].some((d) => d === day);
794
- return {
795
- ...dayFlags,
796
- ...customModifiers
797
- };
798
- };
799
- }
800
- function getClassNamesForModifiers(modifiers, classNames$1, modifiersClassNames = {}) {
801
- return Object.entries(modifiers).filter(([, active]) => active === true).reduce((previousValue, [key]) => {
802
- if (modifiersClassNames[key]) previousValue.push(modifiersClassNames[key]);
803
- else if (classNames$1[DayFlag[key]]) previousValue.push(classNames$1[DayFlag[key]]);
804
- else if (classNames$1[SelectionState[key]]) previousValue.push(classNames$1[SelectionState[key]]);
805
- return previousValue;
806
- }, [classNames$1[UI.Day]]);
807
- }
808
- function getComponents(customComponents) {
809
- return {
810
- ...custom_components_exports,
811
- ...customComponents
812
- };
813
- }
814
- function getDataAttributes(props) {
815
- const dataAttributes = {
816
- "data-mode": props.mode ?? void 0,
817
- "data-required": "required" in props ? props.required : void 0,
818
- "data-multiple-months": props.numberOfMonths && props.numberOfMonths > 1 || void 0,
819
- "data-week-numbers": props.showWeekNumber || void 0,
820
- "data-broadcast-calendar": props.broadcastCalendar || void 0,
821
- "data-nav-layout": props.navLayout || void 0
822
- };
823
- Object.entries(props).forEach(([key, val]) => {
824
- if (key.startsWith("data-")) dataAttributes[key] = val;
825
- });
826
- return dataAttributes;
827
- }
828
- function getDefaultClassNames() {
829
- const classNames$1 = {};
830
- for (const key in UI) classNames$1[UI[key]] = `rdp-${UI[key]}`;
831
- for (const key in DayFlag) classNames$1[DayFlag[key]] = `rdp-${DayFlag[key]}`;
832
- for (const key in SelectionState) classNames$1[SelectionState[key]] = `rdp-${SelectionState[key]}`;
833
- for (const key in Animation) classNames$1[Animation[key]] = `rdp-${Animation[key]}`;
834
- return classNames$1;
835
- }
836
- function formatCaption(month, options, dateLib) {
837
- return (dateLib ?? new DateLib(options)).formatMonthYear(month);
838
- }
839
- const formatMonthCaption = formatCaption;
840
- function formatDay(date, options, dateLib) {
841
- return (dateLib ?? new DateLib(options)).format(date, "d");
842
- }
843
- function formatMonthDropdown(month, dateLib = defaultDateLib) {
844
- return dateLib.format(month, "LLLL");
845
- }
846
- function formatWeekdayName(weekday, options, dateLib) {
847
- return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
848
- }
849
- function formatWeekNumber(weekNumber, dateLib = defaultDateLib) {
850
- if (weekNumber < 10) return dateLib.formatNumber(`0${weekNumber.toLocaleString()}`);
851
- return dateLib.formatNumber(`${weekNumber.toLocaleString()}`);
852
- }
853
- function formatWeekNumberHeader() {
854
- return ``;
855
- }
856
- function formatYearDropdown(year, dateLib = defaultDateLib) {
857
- return dateLib.format(year, "yyyy");
858
- }
859
- const formatYearCaption = formatYearDropdown;
860
- var formatters_exports = /* @__PURE__ */ __export({
861
- formatCaption: () => formatCaption,
862
- formatDay: () => formatDay,
863
- formatMonthCaption: () => formatMonthCaption,
864
- formatMonthDropdown: () => formatMonthDropdown,
865
- formatWeekNumber: () => formatWeekNumber,
866
- formatWeekNumberHeader: () => formatWeekNumberHeader,
867
- formatWeekdayName: () => formatWeekdayName,
868
- formatYearCaption: () => formatYearCaption,
869
- formatYearDropdown: () => formatYearDropdown
870
- });
871
- function getFormatters(customFormatters) {
872
- if (customFormatters?.formatMonthCaption && !customFormatters.formatCaption) customFormatters.formatCaption = customFormatters.formatMonthCaption;
873
- if (customFormatters?.formatYearCaption && !customFormatters.formatYearDropdown) customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
874
- return {
875
- ...formatters_exports,
876
- ...customFormatters
877
- };
878
- }
879
- function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
880
- const { startOfMonth: startOfMonth$1, startOfYear: startOfYear$1, endOfYear: endOfYear$1, eachMonthOfInterval: eachMonthOfInterval$1, getMonth: getMonth$1 } = dateLib;
881
- return eachMonthOfInterval$1({
882
- start: startOfYear$1(displayMonth),
883
- end: endOfYear$1(displayMonth)
884
- }).map((month) => {
885
- const label = formatters.formatMonthDropdown(month, dateLib);
886
- return {
887
- value: getMonth$1(month),
888
- label,
889
- disabled: navStart && month < startOfMonth$1(navStart) || navEnd && month > startOfMonth$1(navEnd) || false
890
- };
891
- });
892
- }
893
- function getStyleForModifiers(dayModifiers, styles$1 = {}, modifiersStyles = {}) {
894
- let style = { ...styles$1?.[UI.Day] };
895
- Object.entries(dayModifiers).filter(([, active]) => active === true).forEach(([modifier]) => {
896
- style = {
897
- ...style,
898
- ...modifiersStyles?.[modifier]
899
- };
900
- });
901
- return style;
902
- }
903
- function getWeekdays(dateLib, ISOWeek, broadcastCalendar, today) {
904
- const referenceToday = today ?? dateLib.today();
905
- const start = broadcastCalendar ? dateLib.startOfBroadcastWeek(referenceToday, dateLib) : ISOWeek ? dateLib.startOfISOWeek(referenceToday) : dateLib.startOfWeek(referenceToday);
906
- const days = [];
907
- for (let i = 0; i < 7; i++) {
908
- const day = dateLib.addDays(start, i);
909
- days.push(day);
910
- }
911
- return days;
912
- }
913
- function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
914
- if (!navStart) return void 0;
915
- if (!navEnd) return void 0;
916
- const { startOfYear: startOfYear$1, endOfYear: endOfYear$1, eachYearOfInterval: eachYearOfInterval$1, getYear: getYear$1 } = dateLib;
917
- const years = eachYearOfInterval$1({
918
- start: startOfYear$1(navStart),
919
- end: endOfYear$1(navEnd)
920
- });
921
- if (reverse) years.reverse();
922
- return years.map((year) => {
923
- const label = formatters.formatYearDropdown(year, dateLib);
924
- return {
925
- value: getYear$1(year),
926
- label,
927
- disabled: false
928
- };
929
- });
930
- }
931
- function labelDayButton(date, modifiers, options, dateLib) {
932
- let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
933
- if (modifiers.today) label = `Today, ${label}`;
934
- if (modifiers.selected) label = `${label}, selected`;
935
- return label;
936
- }
937
- const labelDay = labelDayButton;
938
- function labelGrid(date, options, dateLib) {
939
- return (dateLib ?? new DateLib(options)).formatMonthYear(date);
940
- }
941
- const labelCaption = labelGrid;
942
- function labelGridcell(date, modifiers, options, dateLib) {
943
- let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
944
- if (modifiers?.today) label = `Today, ${label}`;
945
- return label;
946
- }
947
- function labelMonthDropdown(_options) {
948
- return "Choose the Month";
949
- }
950
- function labelNav() {
951
- return "";
952
- }
953
- function labelNext(_month) {
954
- return "Go to the Next Month";
955
- }
956
- function labelPrevious(_month) {
957
- return "Go to the Previous Month";
958
- }
959
- function labelWeekday(date, options, dateLib) {
960
- return (dateLib ?? new DateLib(options)).format(date, "cccc");
961
- }
962
- function labelWeekNumber(weekNumber, _options) {
963
- return `Week ${weekNumber}`;
964
- }
965
- function labelWeekNumberHeader(_options) {
966
- return "Week Number";
967
- }
968
- function labelYearDropdown(_options) {
969
- return "Choose the Year";
970
- }
971
- var labels_exports = /* @__PURE__ */ __export({
972
- labelCaption: () => labelCaption,
973
- labelDay: () => labelDay,
974
- labelDayButton: () => labelDayButton,
975
- labelGrid: () => labelGrid,
976
- labelGridcell: () => labelGridcell,
977
- labelMonthDropdown: () => labelMonthDropdown,
978
- labelNav: () => labelNav,
979
- labelNext: () => labelNext,
980
- labelPrevious: () => labelPrevious,
981
- labelWeekNumber: () => labelWeekNumber,
982
- labelWeekNumberHeader: () => labelWeekNumberHeader,
983
- labelWeekday: () => labelWeekday,
984
- labelYearDropdown: () => labelYearDropdown
985
- });
986
- var asHtmlElement = (element) => {
987
- if (element instanceof HTMLElement) return element;
988
- return null;
989
- };
990
- var queryMonthEls = (element) => [...element.querySelectorAll("[data-animated-month]") ?? []];
991
- var queryMonthEl = (element) => asHtmlElement(element.querySelector("[data-animated-month]"));
992
- var queryCaptionEl = (element) => asHtmlElement(element.querySelector("[data-animated-caption]"));
993
- var queryWeeksEl = (element) => asHtmlElement(element.querySelector("[data-animated-weeks]"));
994
- var queryNavEl = (element) => asHtmlElement(element.querySelector("[data-animated-nav]"));
995
- var queryWeekdaysEl = (element) => asHtmlElement(element.querySelector("[data-animated-weekdays]"));
996
- function useAnimation(rootElRef, enabled, { classNames: classNames$1, months, focused, dateLib }) {
997
- const previousRootElSnapshotRef = useRef(null);
998
- const previousMonthsRef = useRef(months);
999
- const animatingRef = useRef(false);
1000
- useLayoutEffect(() => {
1001
- const previousMonths = previousMonthsRef.current;
1002
- previousMonthsRef.current = months;
1003
- if (!enabled || !rootElRef.current || !(rootElRef.current instanceof HTMLElement) || months.length === 0 || previousMonths.length === 0 || months.length !== previousMonths.length) return;
1004
- const isSameMonth$1 = dateLib.isSameMonth(months[0].date, previousMonths[0].date);
1005
- const isAfterPreviousMonth = dateLib.isAfter(months[0].date, previousMonths[0].date);
1006
- const captionAnimationClass = isAfterPreviousMonth ? classNames$1[Animation.caption_after_enter] : classNames$1[Animation.caption_before_enter];
1007
- const weeksAnimationClass = isAfterPreviousMonth ? classNames$1[Animation.weeks_after_enter] : classNames$1[Animation.weeks_before_enter];
1008
- const previousRootElSnapshot = previousRootElSnapshotRef.current;
1009
- const rootElSnapshot = rootElRef.current.cloneNode(true);
1010
- if (rootElSnapshot instanceof HTMLElement) {
1011
- queryMonthEls(rootElSnapshot).forEach((currentMonthElSnapshot) => {
1012
- if (!(currentMonthElSnapshot instanceof HTMLElement)) return;
1013
- const previousMonthElSnapshot = queryMonthEl(currentMonthElSnapshot);
1014
- if (previousMonthElSnapshot && currentMonthElSnapshot.contains(previousMonthElSnapshot)) currentMonthElSnapshot.removeChild(previousMonthElSnapshot);
1015
- const captionEl = queryCaptionEl(currentMonthElSnapshot);
1016
- if (captionEl) captionEl.classList.remove(captionAnimationClass);
1017
- const weeksEl = queryWeeksEl(currentMonthElSnapshot);
1018
- if (weeksEl) weeksEl.classList.remove(weeksAnimationClass);
1019
- });
1020
- previousRootElSnapshotRef.current = rootElSnapshot;
1021
- } else previousRootElSnapshotRef.current = null;
1022
- if (animatingRef.current || isSameMonth$1 || focused) return;
1023
- const previousMonthEls = previousRootElSnapshot instanceof HTMLElement ? queryMonthEls(previousRootElSnapshot) : [];
1024
- const currentMonthEls = queryMonthEls(rootElRef.current);
1025
- if (currentMonthEls?.every((el) => el instanceof HTMLElement) && previousMonthEls && previousMonthEls.every((el) => el instanceof HTMLElement)) {
1026
- animatingRef.current = true;
1027
- const cleanUpFunctions = [];
1028
- rootElRef.current.style.isolation = "isolate";
1029
- const navEl = queryNavEl(rootElRef.current);
1030
- if (navEl) navEl.style.zIndex = "1";
1031
- currentMonthEls.forEach((currentMonthEl, index) => {
1032
- const previousMonthEl = previousMonthEls[index];
1033
- if (!previousMonthEl) return;
1034
- currentMonthEl.style.position = "relative";
1035
- currentMonthEl.style.overflow = "hidden";
1036
- const captionEl = queryCaptionEl(currentMonthEl);
1037
- if (captionEl) captionEl.classList.add(captionAnimationClass);
1038
- const weeksEl = queryWeeksEl(currentMonthEl);
1039
- if (weeksEl) weeksEl.classList.add(weeksAnimationClass);
1040
- const cleanUp = () => {
1041
- animatingRef.current = false;
1042
- if (rootElRef.current) rootElRef.current.style.isolation = "";
1043
- if (navEl) navEl.style.zIndex = "";
1044
- if (captionEl) captionEl.classList.remove(captionAnimationClass);
1045
- if (weeksEl) weeksEl.classList.remove(weeksAnimationClass);
1046
- currentMonthEl.style.position = "";
1047
- currentMonthEl.style.overflow = "";
1048
- if (currentMonthEl.contains(previousMonthEl)) currentMonthEl.removeChild(previousMonthEl);
1049
- };
1050
- cleanUpFunctions.push(cleanUp);
1051
- previousMonthEl.style.pointerEvents = "none";
1052
- previousMonthEl.style.position = "absolute";
1053
- previousMonthEl.style.overflow = "hidden";
1054
- previousMonthEl.setAttribute("aria-hidden", "true");
1055
- const previousWeekdaysEl = queryWeekdaysEl(previousMonthEl);
1056
- if (previousWeekdaysEl) previousWeekdaysEl.style.opacity = "0";
1057
- const previousCaptionEl = queryCaptionEl(previousMonthEl);
1058
- if (previousCaptionEl) {
1059
- previousCaptionEl.classList.add(isAfterPreviousMonth ? classNames$1[Animation.caption_before_exit] : classNames$1[Animation.caption_after_exit]);
1060
- previousCaptionEl.addEventListener("animationend", cleanUp);
1061
- }
1062
- const previousWeeksEl = queryWeeksEl(previousMonthEl);
1063
- if (previousWeeksEl) previousWeeksEl.classList.add(isAfterPreviousMonth ? classNames$1[Animation.weeks_before_exit] : classNames$1[Animation.weeks_after_exit]);
1064
- currentMonthEl.insertBefore(previousMonthEl, currentMonthEl.firstChild);
1065
- });
1066
- }
1067
- });
1068
- }
1069
- function getDates(displayMonths, maxDate, props, dateLib) {
1070
- const firstMonth = displayMonths[0];
1071
- const lastMonth = displayMonths[displayMonths.length - 1];
1072
- const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
1073
- const { addDays: addDays$1, differenceInCalendarDays: differenceInCalendarDays$1, differenceInCalendarMonths: differenceInCalendarMonths$1, endOfBroadcastWeek: endOfBroadcastWeek$1, endOfISOWeek: endOfISOWeek$1, endOfMonth: endOfMonth$1, endOfWeek: endOfWeek$1, isAfter: isAfter$1, startOfBroadcastWeek: startOfBroadcastWeek$1, startOfISOWeek: startOfISOWeek$1, startOfWeek: startOfWeek$1 } = dateLib;
1074
- const startWeekFirstDate = broadcastCalendar ? startOfBroadcastWeek$1(firstMonth, dateLib) : ISOWeek ? startOfISOWeek$1(firstMonth) : startOfWeek$1(firstMonth);
1075
- const nOfDays = differenceInCalendarDays$1(broadcastCalendar ? endOfBroadcastWeek$1(lastMonth) : ISOWeek ? endOfISOWeek$1(endOfMonth$1(lastMonth)) : endOfWeek$1(endOfMonth$1(lastMonth)), startWeekFirstDate);
1076
- const nOfMonths = differenceInCalendarMonths$1(lastMonth, firstMonth) + 1;
1077
- const dates = [];
1078
- for (let i = 0; i <= nOfDays; i++) {
1079
- const date = addDays$1(startWeekFirstDate, i);
1080
- if (maxDate && isAfter$1(date, maxDate)) break;
1081
- dates.push(date);
1082
- }
1083
- const extraDates = (broadcastCalendar ? 35 : 42) * nOfMonths;
1084
- if (fixedWeeks && dates.length < extraDates) {
1085
- const daysToAdd = extraDates - dates.length;
1086
- for (let i = 0; i < daysToAdd; i++) {
1087
- const date = addDays$1(dates[dates.length - 1], 1);
1088
- dates.push(date);
1089
- }
1090
- }
1091
- return dates;
1092
- }
1093
- function getDays(calendarMonths) {
1094
- const initialDays = [];
1095
- return calendarMonths.reduce((days, month) => {
1096
- const weekDays = month.weeks.reduce((weekDays$1, week) => {
1097
- return weekDays$1.concat(week.days.slice());
1098
- }, initialDays.slice());
1099
- return days.concat(weekDays.slice());
1100
- }, initialDays.slice());
1101
- }
1102
- function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib) {
1103
- const { numberOfMonths = 1 } = props;
1104
- const months = [];
1105
- for (let i = 0; i < numberOfMonths; i++) {
1106
- const month = dateLib.addMonths(firstDisplayedMonth, i);
1107
- if (calendarEndMonth && month > calendarEndMonth) break;
1108
- months.push(month);
1109
- }
1110
- return months;
1111
- }
1112
- function getInitialMonth(props, navStart, navEnd, dateLib) {
1113
- const { month, defaultMonth, today = dateLib.today(), numberOfMonths = 1 } = props;
1114
- let initialMonth = month || defaultMonth || today;
1115
- const { differenceInCalendarMonths: differenceInCalendarMonths$1, addMonths: addMonths$1, startOfMonth: startOfMonth$1 } = dateLib;
1116
- if (navEnd && differenceInCalendarMonths$1(navEnd, initialMonth) < numberOfMonths - 1) initialMonth = addMonths$1(navEnd, -1 * (numberOfMonths - 1));
1117
- if (navStart && differenceInCalendarMonths$1(initialMonth, navStart) < 0) initialMonth = navStart;
1118
- return startOfMonth$1(initialMonth);
1119
- }
1120
- function getMonths(displayMonths, dates, props, dateLib) {
1121
- const { addDays: addDays$1, endOfBroadcastWeek: endOfBroadcastWeek$1, endOfISOWeek: endOfISOWeek$1, endOfMonth: endOfMonth$1, endOfWeek: endOfWeek$1, getISOWeek: getISOWeek$1, getWeek: getWeek$1, startOfBroadcastWeek: startOfBroadcastWeek$1, startOfISOWeek: startOfISOWeek$1, startOfWeek: startOfWeek$1 } = dateLib;
1122
- const dayPickerMonths = displayMonths.reduce((months, month) => {
1123
- const firstDateOfFirstWeek = props.broadcastCalendar ? startOfBroadcastWeek$1(month, dateLib) : props.ISOWeek ? startOfISOWeek$1(month) : startOfWeek$1(month);
1124
- const lastDateOfLastWeek = props.broadcastCalendar ? endOfBroadcastWeek$1(month) : props.ISOWeek ? endOfISOWeek$1(endOfMonth$1(month)) : endOfWeek$1(endOfMonth$1(month));
1125
- const monthDates = dates.filter((date) => {
1126
- return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
1127
- });
1128
- const nrOfDaysWithFixedWeeks = props.broadcastCalendar ? 35 : 42;
1129
- if (props.fixedWeeks && monthDates.length < nrOfDaysWithFixedWeeks) {
1130
- const extraDates = dates.filter((date) => {
1131
- const daysToAdd = nrOfDaysWithFixedWeeks - monthDates.length;
1132
- return date > lastDateOfLastWeek && date <= addDays$1(lastDateOfLastWeek, daysToAdd);
1133
- });
1134
- monthDates.push(...extraDates);
1135
- }
1136
- const dayPickerMonth = new CalendarMonth(month, monthDates.reduce((weeks, date) => {
1137
- const weekNumber = props.ISOWeek ? getISOWeek$1(date) : getWeek$1(date);
1138
- const week = weeks.find((week$1) => week$1.weekNumber === weekNumber);
1139
- const day = new CalendarDay(date, month, dateLib);
1140
- if (!week) weeks.push(new CalendarWeek(weekNumber, [day]));
1141
- else week.days.push(day);
1142
- return weeks;
1143
- }, []));
1144
- months.push(dayPickerMonth);
1145
- return months;
1146
- }, []);
1147
- if (!props.reverseMonths) return dayPickerMonths;
1148
- else return dayPickerMonths.reverse();
1149
- }
1150
- function getNavMonths(props, dateLib) {
1151
- let { startMonth, endMonth } = props;
1152
- const { startOfYear: startOfYear$1, startOfDay: startOfDay$1, startOfMonth: startOfMonth$1, endOfMonth: endOfMonth$1, addYears: addYears$1, endOfYear: endOfYear$1, newDate, today } = dateLib;
1153
- const { fromYear, toYear, fromMonth, toMonth } = props;
1154
- if (!startMonth && fromMonth) startMonth = fromMonth;
1155
- if (!startMonth && fromYear) startMonth = dateLib.newDate(fromYear, 0, 1);
1156
- if (!endMonth && toMonth) endMonth = toMonth;
1157
- if (!endMonth && toYear) endMonth = newDate(toYear, 11, 31);
1158
- const hasYearDropdown = props.captionLayout === "dropdown" || props.captionLayout === "dropdown-years";
1159
- if (startMonth) startMonth = startOfMonth$1(startMonth);
1160
- else if (fromYear) startMonth = newDate(fromYear, 0, 1);
1161
- else if (!startMonth && hasYearDropdown) startMonth = startOfYear$1(addYears$1(props.today ?? today(), -100));
1162
- if (endMonth) endMonth = endOfMonth$1(endMonth);
1163
- else if (toYear) endMonth = newDate(toYear, 11, 31);
1164
- else if (!endMonth && hasYearDropdown) endMonth = endOfYear$1(props.today ?? today());
1165
- return [startMonth ? startOfDay$1(startMonth) : startMonth, endMonth ? startOfDay$1(endMonth) : endMonth];
1166
- }
1167
- function getNextMonth(firstDisplayedMonth, calendarEndMonth, options, dateLib) {
1168
- if (options.disableNavigation) return;
1169
- const { pagedNavigation, numberOfMonths = 1 } = options;
1170
- const { startOfMonth: startOfMonth$1, addMonths: addMonths$1, differenceInCalendarMonths: differenceInCalendarMonths$1 } = dateLib;
1171
- const offset = pagedNavigation ? numberOfMonths : 1;
1172
- const month = startOfMonth$1(firstDisplayedMonth);
1173
- if (!calendarEndMonth) return addMonths$1(month, offset);
1174
- if (differenceInCalendarMonths$1(calendarEndMonth, firstDisplayedMonth) < numberOfMonths) return;
1175
- return addMonths$1(month, offset);
1176
- }
1177
- function getPreviousMonth(firstDisplayedMonth, calendarStartMonth, options, dateLib) {
1178
- if (options.disableNavigation) return;
1179
- const { pagedNavigation, numberOfMonths } = options;
1180
- const { startOfMonth: startOfMonth$1, addMonths: addMonths$1, differenceInCalendarMonths: differenceInCalendarMonths$1 } = dateLib;
1181
- const offset = pagedNavigation ? numberOfMonths ?? 1 : 1;
1182
- const month = startOfMonth$1(firstDisplayedMonth);
1183
- if (!calendarStartMonth) return addMonths$1(month, -offset);
1184
- if (differenceInCalendarMonths$1(month, calendarStartMonth) <= 0) return;
1185
- return addMonths$1(month, -offset);
1186
- }
1187
- function getWeeks(months) {
1188
- return months.reduce((weeks, month) => {
1189
- return weeks.concat(month.weeks.slice());
1190
- }, [].slice());
1191
- }
1192
- function useControlledValue(defaultValue, controlledValue) {
1193
- const [uncontrolledValue, setValue] = useState(defaultValue);
1194
- return [controlledValue === void 0 ? uncontrolledValue : controlledValue, setValue];
1195
- }
1196
- function useCalendar(props, dateLib) {
1197
- const [navStart, navEnd] = getNavMonths(props, dateLib);
1198
- const { startOfMonth: startOfMonth$1, endOfMonth: endOfMonth$1 } = dateLib;
1199
- const initialMonth = getInitialMonth(props, navStart, navEnd, dateLib);
1200
- const [firstMonth, setFirstMonth] = useControlledValue(initialMonth, props.month ? initialMonth : void 0);
1201
- useEffect(() => {
1202
- setFirstMonth(getInitialMonth(props, navStart, navEnd, dateLib));
1203
- }, [props.timeZone]);
1204
- const { months, weeks, days, previousMonth: previousMonth$2, nextMonth: nextMonth$2 } = useMemo(() => {
1205
- const displayMonths = getDisplayMonths(firstMonth, navEnd, { numberOfMonths: props.numberOfMonths }, dateLib);
1206
- const months$1 = getMonths(displayMonths, getDates(displayMonths, props.endMonth ? endOfMonth$1(props.endMonth) : void 0, {
1207
- ISOWeek: props.ISOWeek,
1208
- fixedWeeks: props.fixedWeeks,
1209
- broadcastCalendar: props.broadcastCalendar
1210
- }, dateLib), {
1211
- broadcastCalendar: props.broadcastCalendar,
1212
- fixedWeeks: props.fixedWeeks,
1213
- ISOWeek: props.ISOWeek,
1214
- reverseMonths: props.reverseMonths
1215
- }, dateLib);
1216
- return {
1217
- months: months$1,
1218
- weeks: getWeeks(months$1),
1219
- days: getDays(months$1),
1220
- previousMonth: getPreviousMonth(firstMonth, navStart, props, dateLib),
1221
- nextMonth: getNextMonth(firstMonth, navEnd, props, dateLib)
1222
- };
1223
- }, [
1224
- dateLib,
1225
- firstMonth.getTime(),
1226
- navEnd?.getTime(),
1227
- navStart?.getTime(),
1228
- props.disableNavigation,
1229
- props.broadcastCalendar,
1230
- props.endMonth?.getTime(),
1231
- props.fixedWeeks,
1232
- props.ISOWeek,
1233
- props.numberOfMonths,
1234
- props.pagedNavigation,
1235
- props.reverseMonths
1236
- ]);
1237
- const { disableNavigation, onMonthChange } = props;
1238
- const isDayInCalendar = (day) => weeks.some((week) => week.days.some((d) => d.isEqualTo(day)));
1239
- const goToMonth = (date) => {
1240
- if (disableNavigation) return;
1241
- let newMonth = startOfMonth$1(date);
1242
- if (navStart && newMonth < startOfMonth$1(navStart)) newMonth = startOfMonth$1(navStart);
1243
- if (navEnd && newMonth > startOfMonth$1(navEnd)) newMonth = startOfMonth$1(navEnd);
1244
- setFirstMonth(newMonth);
1245
- onMonthChange?.(newMonth);
1246
- };
1247
- const goToDay = (day) => {
1248
- if (isDayInCalendar(day)) return;
1249
- goToMonth(day.date);
1250
- };
1251
- return {
1252
- months,
1253
- weeks,
1254
- days,
1255
- navStart,
1256
- navEnd,
1257
- previousMonth: previousMonth$2,
1258
- nextMonth: nextMonth$2,
1259
- goToMonth,
1260
- goToDay
1261
- };
1262
- }
1263
- var FocusTargetPriority;
1264
- (function(FocusTargetPriority$1) {
1265
- FocusTargetPriority$1[FocusTargetPriority$1["Today"] = 0] = "Today";
1266
- FocusTargetPriority$1[FocusTargetPriority$1["Selected"] = 1] = "Selected";
1267
- FocusTargetPriority$1[FocusTargetPriority$1["LastFocused"] = 2] = "LastFocused";
1268
- FocusTargetPriority$1[FocusTargetPriority$1["FocusedModifier"] = 3] = "FocusedModifier";
1269
- })(FocusTargetPriority || (FocusTargetPriority = {}));
1270
- function isFocusableDay(modifiers) {
1271
- return !modifiers[DayFlag.disabled] && !modifiers[DayFlag.hidden] && !modifiers[DayFlag.outside];
1272
- }
1273
- function calculateFocusTarget(days, getModifiers, isSelected, lastFocused) {
1274
- let focusTarget;
1275
- let foundFocusTargetPriority = -1;
1276
- for (const day of days) {
1277
- const modifiers = getModifiers(day);
1278
- if (isFocusableDay(modifiers)) {
1279
- if (modifiers[DayFlag.focused] && foundFocusTargetPriority < FocusTargetPriority.FocusedModifier) {
1280
- focusTarget = day;
1281
- foundFocusTargetPriority = FocusTargetPriority.FocusedModifier;
1282
- } else if (lastFocused?.isEqualTo(day) && foundFocusTargetPriority < FocusTargetPriority.LastFocused) {
1283
- focusTarget = day;
1284
- foundFocusTargetPriority = FocusTargetPriority.LastFocused;
1285
- } else if (isSelected(day.date) && foundFocusTargetPriority < FocusTargetPriority.Selected) {
1286
- focusTarget = day;
1287
- foundFocusTargetPriority = FocusTargetPriority.Selected;
1288
- } else if (modifiers[DayFlag.today] && foundFocusTargetPriority < FocusTargetPriority.Today) {
1289
- focusTarget = day;
1290
- foundFocusTargetPriority = FocusTargetPriority.Today;
1291
- }
1292
- }
1293
- }
1294
- if (!focusTarget) focusTarget = days.find((day) => isFocusableDay(getModifiers(day)));
1295
- return focusTarget;
1296
- }
1297
- function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dateLib) {
1298
- const { ISOWeek, broadcastCalendar } = props;
1299
- const { addDays: addDays$1, addMonths: addMonths$1, addWeeks: addWeeks$1, addYears: addYears$1, endOfBroadcastWeek: endOfBroadcastWeek$1, endOfISOWeek: endOfISOWeek$1, endOfWeek: endOfWeek$1, max: max$1, min: min$1, startOfBroadcastWeek: startOfBroadcastWeek$1, startOfISOWeek: startOfISOWeek$1, startOfWeek: startOfWeek$1 } = dateLib;
1300
- let focusableDate = {
1301
- day: addDays$1,
1302
- week: addWeeks$1,
1303
- month: addMonths$1,
1304
- year: addYears$1,
1305
- startOfWeek: (date) => broadcastCalendar ? startOfBroadcastWeek$1(date, dateLib) : ISOWeek ? startOfISOWeek$1(date) : startOfWeek$1(date),
1306
- endOfWeek: (date) => broadcastCalendar ? endOfBroadcastWeek$1(date) : ISOWeek ? endOfISOWeek$1(date) : endOfWeek$1(date)
1307
- }[moveBy](refDate, moveDir === "after" ? 1 : -1);
1308
- if (moveDir === "before" && navStart) focusableDate = max$1([navStart, focusableDate]);
1309
- else if (moveDir === "after" && navEnd) focusableDate = min$1([navEnd, focusableDate]);
1310
- return focusableDate;
1311
- }
1312
- function getNextFocus(moveBy, moveDir, refDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt = 0) {
1313
- if (attempt > 365) return;
1314
- const focusableDate = getFocusableDate(moveBy, moveDir, refDay.date, calendarStartMonth, calendarEndMonth, props, dateLib);
1315
- const isDisabled = Boolean(props.disabled && dateMatchModifiers(focusableDate, props.disabled, dateLib));
1316
- const isHidden = Boolean(props.hidden && dateMatchModifiers(focusableDate, props.hidden, dateLib));
1317
- const focusDay = new CalendarDay(focusableDate, focusableDate, dateLib);
1318
- if (!isDisabled && !isHidden) return focusDay;
1319
- return getNextFocus(moveBy, moveDir, focusDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt + 1);
1320
- }
1321
- function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
1322
- const { autoFocus } = props;
1323
- const [lastFocused, setLastFocused] = useState();
1324
- const focusTarget = calculateFocusTarget(calendar.days, getModifiers, isSelected || (() => false), lastFocused);
1325
- const [focusedDay, setFocused] = useState(autoFocus ? focusTarget : void 0);
1326
- const blur = () => {
1327
- setLastFocused(focusedDay);
1328
- setFocused(void 0);
1329
- };
1330
- const moveFocus = (moveBy, moveDir) => {
1331
- if (!focusedDay) return;
1332
- const nextFocus = getNextFocus(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
1333
- if (!nextFocus) return;
1334
- if (props.disableNavigation) {
1335
- if (!calendar.days.some((day) => day.isEqualTo(nextFocus))) return;
1336
- }
1337
- calendar.goToDay(nextFocus);
1338
- setFocused(nextFocus);
1339
- };
1340
- const isFocusTarget = (day) => {
1341
- return Boolean(focusTarget?.isEqualTo(day));
1342
- };
1343
- return {
1344
- isFocusTarget,
1345
- setFocused,
1346
- focused: focusedDay,
1347
- blur,
1348
- moveFocus
1349
- };
1350
- }
1351
- function useMulti(props, dateLib) {
1352
- const { selected: initiallySelected, required, onSelect } = props;
1353
- const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1354
- const selected = !onSelect ? internallySelected : initiallySelected;
1355
- const { isSameDay: isSameDay$1 } = dateLib;
1356
- const isSelected = (date) => {
1357
- return selected?.some((d) => isSameDay$1(d, date)) ?? false;
1358
- };
1359
- const { min: min$1, max: max$1 } = props;
1360
- const select = (triggerDate, modifiers, e) => {
1361
- let newDates = [...selected ?? []];
1362
- if (isSelected(triggerDate)) {
1363
- if (selected?.length === min$1) return;
1364
- if (required && selected?.length === 1) return;
1365
- newDates = selected?.filter((d) => !isSameDay$1(d, triggerDate));
1366
- } else if (selected?.length === max$1) newDates = [triggerDate];
1367
- else newDates = [...newDates, triggerDate];
1368
- if (!onSelect) setSelected(newDates);
1369
- onSelect?.(newDates, triggerDate, modifiers, e);
1370
- return newDates;
1371
- };
1372
- return {
1373
- selected,
1374
- select,
1375
- isSelected
1376
- };
1377
- }
1378
- function addToRange(date, initialRange, min$1 = 0, max$1 = 0, required = false, dateLib = defaultDateLib) {
1379
- const { from, to } = initialRange || {};
1380
- const { isSameDay: isSameDay$1, isAfter: isAfter$1, isBefore: isBefore$1 } = dateLib;
1381
- let range;
1382
- if (!from && !to) range = {
1383
- from: date,
1384
- to: min$1 > 0 ? void 0 : date
1385
- };
1386
- else if (from && !to) if (isSameDay$1(from, date)) if (min$1 === 0) range = {
1387
- from,
1388
- to: date
1389
- };
1390
- else if (required) range = {
1391
- from,
1392
- to: void 0
1393
- };
1394
- else range = void 0;
1395
- else if (isBefore$1(date, from)) range = {
1396
- from: date,
1397
- to: from
1398
- };
1399
- else range = {
1400
- from,
1401
- to: date
1402
- };
1403
- else if (from && to) if (isSameDay$1(from, date) && isSameDay$1(to, date)) if (required) range = {
1404
- from,
1405
- to
1406
- };
1407
- else range = void 0;
1408
- else if (isSameDay$1(from, date)) range = {
1409
- from,
1410
- to: min$1 > 0 ? void 0 : date
1411
- };
1412
- else if (isSameDay$1(to, date)) range = {
1413
- from: date,
1414
- to: min$1 > 0 ? void 0 : date
1415
- };
1416
- else if (isBefore$1(date, from)) range = {
1417
- from: date,
1418
- to
1419
- };
1420
- else if (isAfter$1(date, from)) range = {
1421
- from,
1422
- to: date
1423
- };
1424
- else if (isAfter$1(date, to)) range = {
1425
- from,
1426
- to: date
1427
- };
1428
- else throw new Error("Invalid range");
1429
- if (range?.from && range?.to) {
1430
- const diff = dateLib.differenceInCalendarDays(range.to, range.from);
1431
- if (max$1 > 0 && diff > max$1) range = {
1432
- from: date,
1433
- to: void 0
1434
- };
1435
- else if (min$1 > 1 && diff < min$1) range = {
1436
- from: date,
1437
- to: void 0
1438
- };
1439
- }
1440
- return range;
1441
- }
1442
- function rangeContainsDayOfWeek(range, dayOfWeek, dateLib = defaultDateLib) {
1443
- const dayOfWeekArr = !Array.isArray(dayOfWeek) ? [dayOfWeek] : dayOfWeek;
1444
- let date = range.from;
1445
- const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
1446
- const totalDaysLimit = Math.min(totalDays, 6);
1447
- for (let i = 0; i <= totalDaysLimit; i++) {
1448
- if (dayOfWeekArr.includes(date.getDay())) return true;
1449
- date = dateLib.addDays(date, 1);
1450
- }
1451
- return false;
1452
- }
1453
- function rangeOverlaps(rangeLeft, rangeRight, dateLib = defaultDateLib) {
1454
- return rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) || rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib);
1455
- }
1456
- function rangeContainsModifiers(range, modifiers, dateLib = defaultDateLib) {
1457
- const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
1458
- if (matchers.filter((matcher) => typeof matcher !== "function").some((matcher) => {
1459
- if (typeof matcher === "boolean") return matcher;
1460
- if (dateLib.isDate(matcher)) return rangeIncludesDate(range, matcher, false, dateLib);
1461
- if (isDatesArray(matcher, dateLib)) return matcher.some((date) => rangeIncludesDate(range, date, false, dateLib));
1462
- if (isDateRange(matcher)) {
1463
- if (matcher.from && matcher.to) return rangeOverlaps(range, {
1464
- from: matcher.from,
1465
- to: matcher.to
1466
- }, dateLib);
1467
- return false;
1468
- }
1469
- if (isDayOfWeekType(matcher)) return rangeContainsDayOfWeek(range, matcher.dayOfWeek, dateLib);
1470
- if (isDateInterval(matcher)) {
1471
- if (dateLib.isAfter(matcher.before, matcher.after)) return rangeOverlaps(range, {
1472
- from: dateLib.addDays(matcher.after, 1),
1473
- to: dateLib.addDays(matcher.before, -1)
1474
- }, dateLib);
1475
- return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
1476
- }
1477
- if (isDateAfterType(matcher) || isDateBeforeType(matcher)) return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
1478
- return false;
1479
- })) return true;
1480
- const functionMatchers = matchers.filter((matcher) => typeof matcher === "function");
1481
- if (functionMatchers.length) {
1482
- let date = range.from;
1483
- const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
1484
- for (let i = 0; i <= totalDays; i++) {
1485
- if (functionMatchers.some((matcher) => matcher(date))) return true;
1486
- date = dateLib.addDays(date, 1);
1487
- }
1488
- }
1489
- return false;
1490
- }
1491
- function useRange(props, dateLib) {
1492
- const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect } = props;
1493
- const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1494
- const selected = !onSelect ? internallySelected : initiallySelected;
1495
- const isSelected = (date) => selected && rangeIncludesDate(selected, date, false, dateLib);
1496
- const select = (triggerDate, modifiers, e) => {
1497
- const { min: min$1, max: max$1 } = props;
1498
- const newRange = triggerDate ? addToRange(triggerDate, selected, min$1, max$1, required, dateLib) : void 0;
1499
- if (excludeDisabled && disabled && newRange?.from && newRange.to) {
1500
- if (rangeContainsModifiers({
1501
- from: newRange.from,
1502
- to: newRange.to
1503
- }, disabled, dateLib)) {
1504
- newRange.from = triggerDate;
1505
- newRange.to = void 0;
1506
- }
1507
- }
1508
- if (!onSelect) setSelected(newRange);
1509
- onSelect?.(newRange, triggerDate, modifiers, e);
1510
- return newRange;
1511
- };
1512
- return {
1513
- selected,
1514
- select,
1515
- isSelected
1516
- };
1517
- }
1518
- function useSingle(props, dateLib) {
1519
- const { selected: initiallySelected, required, onSelect } = props;
1520
- const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
1521
- const selected = !onSelect ? internallySelected : initiallySelected;
1522
- const { isSameDay: isSameDay$1 } = dateLib;
1523
- const isSelected = (compareDate) => {
1524
- return selected ? isSameDay$1(selected, compareDate) : false;
1525
- };
1526
- const select = (triggerDate, modifiers, e) => {
1527
- let newDate = triggerDate;
1528
- if (!required && selected && selected && isSameDay$1(triggerDate, selected)) newDate = void 0;
1529
- if (!onSelect) setSelected(newDate);
1530
- if (required) onSelect?.(newDate, triggerDate, modifiers, e);
1531
- else onSelect?.(newDate, triggerDate, modifiers, e);
1532
- return newDate;
1533
- };
1534
- return {
1535
- selected,
1536
- select,
1537
- isSelected
1538
- };
1539
- }
1540
- function useSelection(props, dateLib) {
1541
- const single = useSingle(props, dateLib);
1542
- const multi = useMulti(props, dateLib);
1543
- const range = useRange(props, dateLib);
1544
- switch (props.mode) {
1545
- case "single": return single;
1546
- case "multiple": return multi;
1547
- case "range": return range;
1548
- default: return;
1549
- }
1550
- }
1551
- function toTimeZone(date, timeZone) {
1552
- if (date instanceof TZDate && date.timeZone === timeZone) return date;
1553
- return new TZDate(date, timeZone);
1554
- }
1555
- function convertMatcher(matcher, timeZone) {
1556
- if (typeof matcher === "boolean" || typeof matcher === "function") return matcher;
1557
- if (matcher instanceof Date) return toTimeZone(matcher, timeZone);
1558
- if (Array.isArray(matcher)) return matcher.map((value) => value instanceof Date ? toTimeZone(value, timeZone) : value);
1559
- if (isDateRange(matcher)) return {
1560
- ...matcher,
1561
- from: matcher.from ? toTimeZone(matcher.from, timeZone) : matcher.from,
1562
- to: matcher.to ? toTimeZone(matcher.to, timeZone) : matcher.to
1563
- };
1564
- if (isDateInterval(matcher)) return {
1565
- before: toTimeZone(matcher.before, timeZone),
1566
- after: toTimeZone(matcher.after, timeZone)
1567
- };
1568
- if (isDateAfterType(matcher)) return { after: toTimeZone(matcher.after, timeZone) };
1569
- if (isDateBeforeType(matcher)) return { before: toTimeZone(matcher.before, timeZone) };
1570
- return matcher;
1571
- }
1572
- function convertMatchersToTimeZone(matchers, timeZone) {
1573
- if (!matchers) return matchers;
1574
- if (Array.isArray(matchers)) return matchers.map((matcher) => convertMatcher(matcher, timeZone));
1575
- return convertMatcher(matchers, timeZone);
1576
- }
1577
- function DayPicker(initialProps) {
1578
- let props = initialProps;
1579
- const timeZone = props.timeZone;
1580
- if (timeZone) {
1581
- props = {
1582
- ...initialProps,
1583
- timeZone
1584
- };
1585
- if (props.today) props.today = toTimeZone(props.today, timeZone);
1586
- if (props.month) props.month = toTimeZone(props.month, timeZone);
1587
- if (props.defaultMonth) props.defaultMonth = toTimeZone(props.defaultMonth, timeZone);
1588
- if (props.startMonth) props.startMonth = toTimeZone(props.startMonth, timeZone);
1589
- if (props.endMonth) props.endMonth = toTimeZone(props.endMonth, timeZone);
1590
- if (props.mode === "single" && props.selected) props.selected = toTimeZone(props.selected, timeZone);
1591
- else if (props.mode === "multiple" && props.selected) props.selected = props.selected?.map((date) => toTimeZone(date, timeZone));
1592
- else if (props.mode === "range" && props.selected) props.selected = {
1593
- from: props.selected.from ? toTimeZone(props.selected.from, timeZone) : props.selected.from,
1594
- to: props.selected.to ? toTimeZone(props.selected.to, timeZone) : props.selected.to
1595
- };
1596
- if (props.disabled !== void 0) props.disabled = convertMatchersToTimeZone(props.disabled, timeZone);
1597
- if (props.hidden !== void 0) props.hidden = convertMatchersToTimeZone(props.hidden, timeZone);
1598
- if (props.modifiers) {
1599
- const nextModifiers = {};
1600
- Object.keys(props.modifiers).forEach((key) => {
1601
- nextModifiers[key] = convertMatchersToTimeZone(props.modifiers?.[key], timeZone);
1602
- });
1603
- props.modifiers = nextModifiers;
1604
- }
1605
- }
1606
- const { components, formatters, labels, dateLib, locale, classNames: classNames$1 } = useMemo(() => {
1607
- const locale$1 = {
1608
- ...defaultLocale,
1609
- ...props.locale
1610
- };
1611
- return {
1612
- dateLib: new DateLib({
1613
- locale: locale$1,
1614
- weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn,
1615
- firstWeekContainsDate: props.firstWeekContainsDate,
1616
- useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
1617
- useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens,
1618
- timeZone: props.timeZone,
1619
- numerals: props.numerals
1620
- }, props.dateLib),
1621
- components: getComponents(props.components),
1622
- formatters: getFormatters(props.formatters),
1623
- labels: {
1624
- ...labels_exports,
1625
- ...props.labels
1626
- },
1627
- locale: locale$1,
1628
- classNames: {
1629
- ...getDefaultClassNames(),
1630
- ...props.classNames
1631
- }
1632
- };
1633
- }, [
1634
- props.locale,
1635
- props.broadcastCalendar,
1636
- props.weekStartsOn,
1637
- props.firstWeekContainsDate,
1638
- props.useAdditionalWeekYearTokens,
1639
- props.useAdditionalDayOfYearTokens,
1640
- props.timeZone,
1641
- props.numerals,
1642
- props.dateLib,
1643
- props.components,
1644
- props.formatters,
1645
- props.labels,
1646
- props.classNames
1647
- ]);
1648
- if (!props.today) props = {
1649
- ...props,
1650
- today: dateLib.today()
1651
- };
1652
- const { captionLayout, mode, navLayout, numberOfMonths = 1, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles: styles$1 } = props;
1653
- const { formatCaption: formatCaption$1, formatDay: formatDay$1, formatMonthDropdown: formatMonthDropdown$1, formatWeekNumber: formatWeekNumber$1, formatWeekNumberHeader: formatWeekNumberHeader$1, formatWeekdayName: formatWeekdayName$1, formatYearDropdown: formatYearDropdown$1 } = formatters;
1654
- const calendar = useCalendar(props, dateLib);
1655
- const { days, months, navStart, navEnd, previousMonth: previousMonth$2, nextMonth: nextMonth$2, goToMonth } = calendar;
1656
- const getModifiers = createGetModifiers(days, props, navStart, navEnd, dateLib);
1657
- const { isSelected, select, selected: selectedValue } = useSelection(props, dateLib) ?? {};
1658
- const { blur, focused, isFocusTarget, moveFocus, setFocused } = useFocus(props, calendar, getModifiers, isSelected ?? (() => false), dateLib);
1659
- const { labelDayButton: labelDayButton$1, labelGridcell: labelGridcell$1, labelGrid: labelGrid$1, labelMonthDropdown: labelMonthDropdown$1, labelNav: labelNav$1, labelPrevious: labelPrevious$1, labelNext: labelNext$1, labelWeekday: labelWeekday$1, labelWeekNumber: labelWeekNumber$1, labelWeekNumberHeader: labelWeekNumberHeader$1, labelYearDropdown: labelYearDropdown$1 } = labels;
1660
- const weekdays = useMemo(() => getWeekdays(dateLib, props.ISOWeek, props.broadcastCalendar, props.today), [
1661
- dateLib,
1662
- props.ISOWeek,
1663
- props.broadcastCalendar,
1664
- props.today
1665
- ]);
1666
- const isInteractive = mode !== void 0 || onDayClick !== void 0;
1667
- const handlePreviousClick = useCallback(() => {
1668
- if (!previousMonth$2) return;
1669
- goToMonth(previousMonth$2);
1670
- onPrevClick?.(previousMonth$2);
1671
- }, [
1672
- previousMonth$2,
1673
- goToMonth,
1674
- onPrevClick
1675
- ]);
1676
- const handleNextClick = useCallback(() => {
1677
- if (!nextMonth$2) return;
1678
- goToMonth(nextMonth$2);
1679
- onNextClick?.(nextMonth$2);
1680
- }, [
1681
- goToMonth,
1682
- nextMonth$2,
1683
- onNextClick
1684
- ]);
1685
- const handleDayClick = useCallback((day, m) => (e) => {
1686
- e.preventDefault();
1687
- e.stopPropagation();
1688
- setFocused(day);
1689
- select?.(day.date, m, e);
1690
- onDayClick?.(day.date, m, e);
1691
- }, [
1692
- select,
1693
- onDayClick,
1694
- setFocused
1695
- ]);
1696
- const handleDayFocus = useCallback((day, m) => (e) => {
1697
- setFocused(day);
1698
- onDayFocus?.(day.date, m, e);
1699
- }, [onDayFocus, setFocused]);
1700
- const handleDayBlur = useCallback((day, m) => (e) => {
1701
- blur();
1702
- onDayBlur?.(day.date, m, e);
1703
- }, [blur, onDayBlur]);
1704
- const handleDayKeyDown = useCallback((day, modifiers) => (e) => {
1705
- const keyMap = {
1706
- ArrowLeft: [e.shiftKey ? "month" : "day", props.dir === "rtl" ? "after" : "before"],
1707
- ArrowRight: [e.shiftKey ? "month" : "day", props.dir === "rtl" ? "before" : "after"],
1708
- ArrowDown: [e.shiftKey ? "year" : "week", "after"],
1709
- ArrowUp: [e.shiftKey ? "year" : "week", "before"],
1710
- PageUp: [e.shiftKey ? "year" : "month", "before"],
1711
- PageDown: [e.shiftKey ? "year" : "month", "after"],
1712
- Home: ["startOfWeek", "before"],
1713
- End: ["endOfWeek", "after"]
1714
- };
1715
- if (keyMap[e.key]) {
1716
- e.preventDefault();
1717
- e.stopPropagation();
1718
- const [moveBy, moveDir] = keyMap[e.key];
1719
- moveFocus(moveBy, moveDir);
1720
- }
1721
- onDayKeyDown?.(day.date, modifiers, e);
1722
- }, [
1723
- moveFocus,
1724
- onDayKeyDown,
1725
- props.dir
1726
- ]);
1727
- const handleDayMouseEnter = useCallback((day, modifiers) => (e) => {
1728
- onDayMouseEnter?.(day.date, modifiers, e);
1729
- }, [onDayMouseEnter]);
1730
- const handleDayMouseLeave = useCallback((day, modifiers) => (e) => {
1731
- onDayMouseLeave?.(day.date, modifiers, e);
1732
- }, [onDayMouseLeave]);
1733
- const handleMonthChange = useCallback((date) => (e) => {
1734
- const selectedMonth = Number(e.target.value);
1735
- goToMonth(dateLib.setMonth(dateLib.startOfMonth(date), selectedMonth));
1736
- }, [dateLib, goToMonth]);
1737
- const handleYearChange = useCallback((date) => (e) => {
1738
- const selectedYear = Number(e.target.value);
1739
- goToMonth(dateLib.setYear(dateLib.startOfMonth(date), selectedYear));
1740
- }, [dateLib, goToMonth]);
1741
- const { className, style } = useMemo(() => ({
1742
- className: [classNames$1[UI.Root], props.className].filter(Boolean).join(" "),
1743
- style: {
1744
- ...styles$1?.[UI.Root],
1745
- ...props.style
1746
- }
1747
- }), [
1748
- classNames$1,
1749
- props.className,
1750
- props.style,
1751
- styles$1
1752
- ]);
1753
- const dataAttributes = getDataAttributes(props);
1754
- const rootElRef = useRef(null);
1755
- useAnimation(rootElRef, Boolean(props.animate), {
1756
- classNames: classNames$1,
1757
- months,
1758
- focused,
1759
- dateLib
1760
- });
1761
- const contextValue = {
1762
- dayPickerProps: props,
1763
- selected: selectedValue,
1764
- select,
1765
- isSelected,
1766
- months,
1767
- nextMonth: nextMonth$2,
1768
- previousMonth: previousMonth$2,
1769
- goToMonth,
1770
- getModifiers,
1771
- components,
1772
- classNames: classNames$1,
1773
- styles: styles$1,
1774
- labels,
1775
- formatters
1776
- };
1777
- return React.createElement(dayPickerContext.Provider, { value: contextValue }, React.createElement(components.Root, {
1778
- rootRef: props.animate ? rootElRef : void 0,
1779
- className,
1780
- style,
1781
- dir: props.dir,
1782
- id: props.id,
1783
- lang: props.lang,
1784
- nonce: props.nonce,
1785
- title: props.title,
1786
- role: props.role,
1787
- "aria-label": props["aria-label"],
1788
- "aria-labelledby": props["aria-labelledby"],
1789
- ...dataAttributes
1790
- }, React.createElement(components.Months, {
1791
- className: classNames$1[UI.Months],
1792
- style: styles$1?.[UI.Months]
1793
- }, !props.hideNavigation && !navLayout && React.createElement(components.Nav, {
1794
- "data-animated-nav": props.animate ? "true" : void 0,
1795
- className: classNames$1[UI.Nav],
1796
- style: styles$1?.[UI.Nav],
1797
- "aria-label": labelNav$1(),
1798
- onPreviousClick: handlePreviousClick,
1799
- onNextClick: handleNextClick,
1800
- previousMonth: previousMonth$2,
1801
- nextMonth: nextMonth$2
1802
- }), months.map((calendarMonth, displayIndex) => {
1803
- return React.createElement(components.Month, {
1804
- "data-animated-month": props.animate ? "true" : void 0,
1805
- className: classNames$1[UI.Month],
1806
- style: styles$1?.[UI.Month],
1807
- key: displayIndex,
1808
- displayIndex,
1809
- calendarMonth
1810
- }, navLayout === "around" && !props.hideNavigation && displayIndex === 0 && React.createElement(components.PreviousMonthButton, {
1811
- type: "button",
1812
- className: classNames$1[UI.PreviousMonthButton],
1813
- tabIndex: previousMonth$2 ? void 0 : -1,
1814
- "aria-disabled": previousMonth$2 ? void 0 : true,
1815
- "aria-label": labelPrevious$1(previousMonth$2),
1816
- onClick: handlePreviousClick,
1817
- "data-animated-button": props.animate ? "true" : void 0
1818
- }, React.createElement(components.Chevron, {
1819
- disabled: previousMonth$2 ? void 0 : true,
1820
- className: classNames$1[UI.Chevron],
1821
- orientation: props.dir === "rtl" ? "right" : "left"
1822
- })), React.createElement(components.MonthCaption, {
1823
- "data-animated-caption": props.animate ? "true" : void 0,
1824
- className: classNames$1[UI.MonthCaption],
1825
- style: styles$1?.[UI.MonthCaption],
1826
- calendarMonth,
1827
- displayIndex
1828
- }, captionLayout?.startsWith("dropdown") ? React.createElement(components.DropdownNav, {
1829
- className: classNames$1[UI.Dropdowns],
1830
- style: styles$1?.[UI.Dropdowns]
1831
- }, (() => {
1832
- const monthControl = captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components.MonthsDropdown, {
1833
- key: "month",
1834
- className: classNames$1[UI.MonthsDropdown],
1835
- "aria-label": labelMonthDropdown$1(),
1836
- classNames: classNames$1,
1837
- components,
1838
- disabled: Boolean(props.disableNavigation),
1839
- onChange: handleMonthChange(calendarMonth.date),
1840
- options: getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib),
1841
- style: styles$1?.[UI.Dropdown],
1842
- value: dateLib.getMonth(calendarMonth.date)
1843
- }) : React.createElement("span", { key: "month" }, formatMonthDropdown$1(calendarMonth.date, dateLib));
1844
- const yearControl = captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components.YearsDropdown, {
1845
- key: "year",
1846
- className: classNames$1[UI.YearsDropdown],
1847
- "aria-label": labelYearDropdown$1(dateLib.options),
1848
- classNames: classNames$1,
1849
- components,
1850
- disabled: Boolean(props.disableNavigation),
1851
- onChange: handleYearChange(calendarMonth.date),
1852
- options: getYearOptions(navStart, navEnd, formatters, dateLib, Boolean(props.reverseYears)),
1853
- style: styles$1?.[UI.Dropdown],
1854
- value: dateLib.getYear(calendarMonth.date)
1855
- }) : React.createElement("span", { key: "year" }, formatYearDropdown$1(calendarMonth.date, dateLib));
1856
- return dateLib.getMonthYearOrder() === "year-first" ? [yearControl, monthControl] : [monthControl, yearControl];
1857
- })(), React.createElement("span", {
1858
- role: "status",
1859
- "aria-live": "polite",
1860
- style: {
1861
- border: 0,
1862
- clip: "rect(0 0 0 0)",
1863
- height: "1px",
1864
- margin: "-1px",
1865
- overflow: "hidden",
1866
- padding: 0,
1867
- position: "absolute",
1868
- width: "1px",
1869
- whiteSpace: "nowrap",
1870
- wordWrap: "normal"
1871
- }
1872
- }, formatCaption$1(calendarMonth.date, dateLib.options, dateLib))) : React.createElement(components.CaptionLabel, {
1873
- className: classNames$1[UI.CaptionLabel],
1874
- role: "status",
1875
- "aria-live": "polite"
1876
- }, formatCaption$1(calendarMonth.date, dateLib.options, dateLib))), navLayout === "around" && !props.hideNavigation && displayIndex === numberOfMonths - 1 && React.createElement(components.NextMonthButton, {
1877
- type: "button",
1878
- className: classNames$1[UI.NextMonthButton],
1879
- tabIndex: nextMonth$2 ? void 0 : -1,
1880
- "aria-disabled": nextMonth$2 ? void 0 : true,
1881
- "aria-label": labelNext$1(nextMonth$2),
1882
- onClick: handleNextClick,
1883
- "data-animated-button": props.animate ? "true" : void 0
1884
- }, React.createElement(components.Chevron, {
1885
- disabled: nextMonth$2 ? void 0 : true,
1886
- className: classNames$1[UI.Chevron],
1887
- orientation: props.dir === "rtl" ? "left" : "right"
1888
- })), displayIndex === numberOfMonths - 1 && navLayout === "after" && !props.hideNavigation && React.createElement(components.Nav, {
1889
- "data-animated-nav": props.animate ? "true" : void 0,
1890
- className: classNames$1[UI.Nav],
1891
- style: styles$1?.[UI.Nav],
1892
- "aria-label": labelNav$1(),
1893
- onPreviousClick: handlePreviousClick,
1894
- onNextClick: handleNextClick,
1895
- previousMonth: previousMonth$2,
1896
- nextMonth: nextMonth$2
1897
- }), React.createElement(components.MonthGrid, {
1898
- role: "grid",
1899
- "aria-multiselectable": mode === "multiple" || mode === "range",
1900
- "aria-label": labelGrid$1(calendarMonth.date, dateLib.options, dateLib) || void 0,
1901
- className: classNames$1[UI.MonthGrid],
1902
- style: styles$1?.[UI.MonthGrid]
1903
- }, !props.hideWeekdays && React.createElement(components.Weekdays, {
1904
- "data-animated-weekdays": props.animate ? "true" : void 0,
1905
- className: classNames$1[UI.Weekdays],
1906
- style: styles$1?.[UI.Weekdays]
1907
- }, showWeekNumber && React.createElement(components.WeekNumberHeader, {
1908
- "aria-label": labelWeekNumberHeader$1(dateLib.options),
1909
- className: classNames$1[UI.WeekNumberHeader],
1910
- style: styles$1?.[UI.WeekNumberHeader],
1911
- scope: "col"
1912
- }, formatWeekNumberHeader$1()), weekdays.map((weekday) => React.createElement(components.Weekday, {
1913
- "aria-label": labelWeekday$1(weekday, dateLib.options, dateLib),
1914
- className: classNames$1[UI.Weekday],
1915
- key: String(weekday),
1916
- style: styles$1?.[UI.Weekday],
1917
- scope: "col"
1918
- }, formatWeekdayName$1(weekday, dateLib.options, dateLib)))), React.createElement(components.Weeks, {
1919
- "data-animated-weeks": props.animate ? "true" : void 0,
1920
- className: classNames$1[UI.Weeks],
1921
- style: styles$1?.[UI.Weeks]
1922
- }, calendarMonth.weeks.map((week) => {
1923
- return React.createElement(components.Week, {
1924
- className: classNames$1[UI.Week],
1925
- key: week.weekNumber,
1926
- style: styles$1?.[UI.Week],
1927
- week
1928
- }, showWeekNumber && React.createElement(components.WeekNumber, {
1929
- week,
1930
- style: styles$1?.[UI.WeekNumber],
1931
- "aria-label": labelWeekNumber$1(week.weekNumber, { locale }),
1932
- className: classNames$1[UI.WeekNumber],
1933
- scope: "row",
1934
- role: "rowheader"
1935
- }, formatWeekNumber$1(week.weekNumber, dateLib)), week.days.map((day) => {
1936
- const { date } = day;
1937
- const modifiers = getModifiers(day);
1938
- modifiers[DayFlag.focused] = !modifiers.hidden && Boolean(focused?.isEqualTo(day));
1939
- modifiers[SelectionState.selected] = isSelected?.(date) || modifiers.selected;
1940
- if (isDateRange(selectedValue)) {
1941
- const { from, to } = selectedValue;
1942
- modifiers[SelectionState.range_start] = Boolean(from && to && dateLib.isSameDay(date, from));
1943
- modifiers[SelectionState.range_end] = Boolean(from && to && dateLib.isSameDay(date, to));
1944
- modifiers[SelectionState.range_middle] = rangeIncludesDate(selectedValue, date, true, dateLib);
1945
- }
1946
- const style$1 = getStyleForModifiers(modifiers, styles$1, props.modifiersStyles);
1947
- const className$1 = getClassNamesForModifiers(modifiers, classNames$1, props.modifiersClassNames);
1948
- const ariaLabel = !isInteractive && !modifiers.hidden ? labelGridcell$1(date, modifiers, dateLib.options, dateLib) : void 0;
1949
- return React.createElement(components.Day, {
1950
- key: `${day.isoDate}_${day.displayMonthId}`,
1951
- day,
1952
- modifiers,
1953
- className: className$1.join(" "),
1954
- style: style$1,
1955
- role: "gridcell",
1956
- "aria-selected": modifiers.selected || void 0,
1957
- "aria-label": ariaLabel,
1958
- "data-day": day.isoDate,
1959
- "data-month": day.outside ? day.dateMonthId : void 0,
1960
- "data-selected": modifiers.selected || void 0,
1961
- "data-disabled": modifiers.disabled || void 0,
1962
- "data-hidden": modifiers.hidden || void 0,
1963
- "data-outside": day.outside || void 0,
1964
- "data-focused": modifiers.focused || void 0,
1965
- "data-today": modifiers.today || void 0
1966
- }, !modifiers.hidden && isInteractive ? React.createElement(components.DayButton, {
1967
- className: classNames$1[UI.DayButton],
1968
- style: styles$1?.[UI.DayButton],
1969
- type: "button",
1970
- day,
1971
- modifiers,
1972
- disabled: !modifiers.focused && modifiers.disabled || void 0,
1973
- "aria-disabled": modifiers.focused && modifiers.disabled || void 0,
1974
- tabIndex: isFocusTarget(day) ? 0 : -1,
1975
- "aria-label": labelDayButton$1(date, modifiers, dateLib.options, dateLib),
1976
- onClick: handleDayClick(day, modifiers),
1977
- onBlur: handleDayBlur(day, modifiers),
1978
- onFocus: handleDayFocus(day, modifiers),
1979
- onKeyDown: handleDayKeyDown(day, modifiers),
1980
- onMouseEnter: handleDayMouseEnter(day, modifiers),
1981
- onMouseLeave: handleDayMouseLeave(day, modifiers)
1982
- }, formatDay$1(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay$1(day.date, dateLib.options, dateLib));
1983
- }));
1984
- }))));
1985
- })), props.footer && React.createElement(components.Footer, {
1986
- className: classNames$1[UI.Footer],
1987
- style: styles$1?.[UI.Footer],
1988
- role: "status",
1989
- "aria-live": "polite"
1990
- }, props.footer)));
1991
- }
1992
29
  var BUBBLE_WIDTH_PX = 329;
1993
30
  var WINDOW_MARGIN_PX = 12;
1994
31
  var BUBBLE_VERTICAL_OFFSET_PX = 26;
@@ -2202,10 +239,7 @@ var HN_Designsystem_DatePicker_en_GB_default = {
2202
239
  nextMonth: "Next month",
2203
240
  previousMonth: "Previous month",
2204
241
  monthDropdown: "Select month",
2205
- yearDropdown: "Select year",
2206
- dayFormatPlaceholder: "dd",
2207
- monthFormatPlaceholder: "mm",
2208
- yearFormatPlaceholder: "yyyy"
242
+ yearDropdown: "Select year"
2209
243
  };
2210
244
  var HN_Designsystem_DatePicker_nb_NO_default = {
2211
245
  dateButtonAriaLabel: "Åpne datovelger",
@@ -2215,12 +249,7 @@ var HN_Designsystem_DatePicker_nb_NO_default = {
2215
249
  nextMonth: "Neste måned",
2216
250
  previousMonth: "Forrige måned",
2217
251
  monthDropdown: "Velg måned",
2218
- yearDropdown: "Velg år",
2219
- goToToday: "Gå til i dag",
2220
- loadingText: "Henter info. Vennligst vent.",
2221
- dayFormatPlaceholder: "dd",
2222
- monthFormatPlaceholder: "mm",
2223
- yearFormatPlaceholder: "åååå"
252
+ yearDropdown: "Velg år"
2224
253
  };
2225
254
  const getResources = (language) => {
2226
255
  switch (language) {