@entur/datepicker 11.6.2 → 11.8.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.
- package/dist/DatePicker/Calendar.d.ts +6 -1
- package/dist/DatePicker/CalendarBase.d.ts +20 -0
- package/dist/DatePicker/CalendarCell.d.ts +2 -1
- package/dist/DatePicker/CalendarGrid.d.ts +5 -8
- package/dist/DatePicker/RangeCalendar.d.ts +69 -0
- package/dist/DatePicker/RangeCalendarCell.d.ts +14 -0
- package/dist/DatePicker/index.d.ts +1 -0
- package/dist/datepicker.cjs.js +348 -142
- package/dist/datepicker.cjs.js.map +1 -1
- package/dist/datepicker.esm.js +351 -145
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/styles.css +130 -8
- package/package.json +10 -10
package/dist/datepicker.esm.js
CHANGED
|
@@ -6,10 +6,10 @@ import { useDateSegment, useDateField, useDatePicker, useTimeField } from "@reac
|
|
|
6
6
|
import { useLocale, I18nProvider } from "@react-aria/i18n";
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import { BaseFormControl, useVariant, useInputGroupContext, isFilled, TextField } from "@entur/form";
|
|
9
|
-
import { toTime, now, toZoned, toCalendarDateTime, today, toCalendarDate, GregorianCalendar, startOfWeek, startOfYear, CalendarDate, Time, getLocalTimeZone, ZonedDateTime, parseAbsolute, CalendarDateTime, isEqualDay,
|
|
9
|
+
import { toTime, now, toZoned, toCalendarDateTime, today, toCalendarDate, GregorianCalendar, startOfWeek, startOfYear, CalendarDate, Time, getLocalTimeZone, ZonedDateTime, parseAbsolute, CalendarDateTime, getWeeksInMonth, isEqualDay, isSameDay, parseTime } from "@internationalized/date";
|
|
10
10
|
import { CalendarDate as CalendarDate2, CalendarDateTime as CalendarDateTime2, Time as Time2, ZonedDateTime as ZonedDateTime2 } from "@internationalized/date";
|
|
11
|
-
import {
|
|
12
|
-
import { useCalendarState } from "@react-stately/calendar";
|
|
11
|
+
import { useCalendarGrid, useCalendarCell, useCalendar, useRangeCalendar } from "@react-aria/calendar";
|
|
12
|
+
import { useCalendarState, useRangeCalendarState } from "@react-stately/calendar";
|
|
13
13
|
import { LeftArrowIcon, RightArrowIcon, CalendarIcon, DateIcon, ClockIcon } from "@entur/icons";
|
|
14
14
|
import { useButton } from "@react-aria/button";
|
|
15
15
|
import { IconButton } from "@entur/button";
|
|
@@ -303,9 +303,158 @@ const CalendarButton = ({
|
|
|
303
303
|
const { buttonProps } = useButton(props, ref);
|
|
304
304
|
return /* @__PURE__ */ jsx(IconButton, { ...buttonProps, ref, className, style, children });
|
|
305
305
|
};
|
|
306
|
+
const CalendarGrid = ({
|
|
307
|
+
state,
|
|
308
|
+
startDate,
|
|
309
|
+
navigationDescription,
|
|
310
|
+
showWeekNumbers,
|
|
311
|
+
weekNumberHeader,
|
|
312
|
+
renderCell
|
|
313
|
+
}) => {
|
|
314
|
+
const calendarGridId = useRandomId("eds-calendar");
|
|
315
|
+
const { locale } = useLocale();
|
|
316
|
+
const gridStartDate = startDate ?? state.visibleRange.start;
|
|
317
|
+
const { gridProps, headerProps, weekDays } = useCalendarGrid(
|
|
318
|
+
{ startDate: gridStartDate },
|
|
319
|
+
state
|
|
320
|
+
);
|
|
321
|
+
const weeksInMonth = getWeeksInMonth(gridStartDate, locale);
|
|
322
|
+
const weeksArray = Array.from(Array(weeksInMonth).keys());
|
|
323
|
+
const weekDaysMapped = () => {
|
|
324
|
+
if (locale.toLowerCase().includes("no"))
|
|
325
|
+
return ["ma", "ti", "on", "to", "fr", "lø", "sø"];
|
|
326
|
+
if (locale.toLowerCase().includes("en")) {
|
|
327
|
+
if (weekDays[0] === "M")
|
|
328
|
+
return ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
329
|
+
if (weekDays[0] === "S")
|
|
330
|
+
return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
331
|
+
}
|
|
332
|
+
return weekDays.map((day) => day.toLowerCase());
|
|
333
|
+
};
|
|
334
|
+
const getNavigationDescription = () => {
|
|
335
|
+
if (navigationDescription) return navigationDescription;
|
|
336
|
+
if (locale.toLowerCase().includes("en"))
|
|
337
|
+
return "Use the arrow keys to navigate between dates";
|
|
338
|
+
return "Bruk piltastene til å navigere mellom datoer";
|
|
339
|
+
};
|
|
340
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
341
|
+
/* @__PURE__ */ jsxs(
|
|
342
|
+
"table",
|
|
343
|
+
{
|
|
344
|
+
...gridProps,
|
|
345
|
+
cellSpacing: "0",
|
|
346
|
+
className: "eds-datepicker__calendar__grid",
|
|
347
|
+
children: [
|
|
348
|
+
/* @__PURE__ */ jsx("thead", { ...headerProps, children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
349
|
+
showWeekNumbers && /* @__PURE__ */ jsx("th", { className: "eds-datepicker__calendar__grid__weeknumber-header", children: weekNumberHeader }),
|
|
350
|
+
weekDaysMapped().map((day) => /* @__PURE__ */ jsx("th", { children: day }, day))
|
|
351
|
+
] }) }),
|
|
352
|
+
/* @__PURE__ */ jsx("tbody", { children: weeksArray.map((weekIndex) => {
|
|
353
|
+
const weekNumber = getWeekNumberForDate(
|
|
354
|
+
state.getDatesInWeek(weekIndex, gridStartDate)[0]
|
|
355
|
+
);
|
|
356
|
+
const weekNumberString = showWeekNumbers ? `, ${weekNumberHeader} ${weekNumber},` : "";
|
|
357
|
+
return /* @__PURE__ */ jsxs("tr", { children: [
|
|
358
|
+
showWeekNumbers && /* @__PURE__ */ jsx(
|
|
359
|
+
"th",
|
|
360
|
+
{
|
|
361
|
+
"aria-label": `${weekNumberHeader} ${weekNumber}`,
|
|
362
|
+
className: "eds-datepicker__calendar__grid__weeknumber",
|
|
363
|
+
children: weekNumber
|
|
364
|
+
}
|
|
365
|
+
),
|
|
366
|
+
state.getDatesInWeek(weekIndex, gridStartDate).map(
|
|
367
|
+
(date, i) => date ? renderCell(
|
|
368
|
+
date,
|
|
369
|
+
gridStartDate,
|
|
370
|
+
weekNumberString,
|
|
371
|
+
calendarGridId + "description"
|
|
372
|
+
) : /* @__PURE__ */ jsx("td", {}, i)
|
|
373
|
+
)
|
|
374
|
+
] }, weekIndex);
|
|
375
|
+
}) })
|
|
376
|
+
]
|
|
377
|
+
}
|
|
378
|
+
),
|
|
379
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { id: calendarGridId + "description", children: getNavigationDescription() })
|
|
380
|
+
] });
|
|
381
|
+
};
|
|
382
|
+
const CalendarBase = ({
|
|
383
|
+
state,
|
|
384
|
+
calendarProps,
|
|
385
|
+
prevButtonProps,
|
|
386
|
+
nextButtonProps,
|
|
387
|
+
title,
|
|
388
|
+
calendarRef,
|
|
389
|
+
style,
|
|
390
|
+
className,
|
|
391
|
+
navigationDescription,
|
|
392
|
+
showWeekNumbers,
|
|
393
|
+
weekNumberHeader,
|
|
394
|
+
renderCell
|
|
395
|
+
}) => {
|
|
396
|
+
const { locale } = useLocale();
|
|
397
|
+
const monthCount = state.visibleRange.end.month - state.visibleRange.start.month + 1 + (state.visibleRange.end.year - state.visibleRange.start.year) * 12;
|
|
398
|
+
const getMonthTitle = (startDate) => new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(
|
|
399
|
+
new Date(startDate.year, startDate.month - 1)
|
|
400
|
+
);
|
|
401
|
+
return /* @__PURE__ */ jsx(
|
|
402
|
+
"div",
|
|
403
|
+
{
|
|
404
|
+
...calendarProps,
|
|
405
|
+
ref: calendarRef,
|
|
406
|
+
className: classNames("eds-datepicker__calendar", className),
|
|
407
|
+
style,
|
|
408
|
+
children: /* @__PURE__ */ jsx("div", { className: "eds-datepicker__calendar__grids", children: Array.from({ length: monthCount }, (_, i) => {
|
|
409
|
+
const startDate = state.visibleRange.start.add({ months: i });
|
|
410
|
+
return /* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__month", children: [
|
|
411
|
+
/* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__header", children: [
|
|
412
|
+
i === 0 && /* @__PURE__ */ jsx(
|
|
413
|
+
CalendarButton,
|
|
414
|
+
{
|
|
415
|
+
...prevButtonProps,
|
|
416
|
+
"aria-label": ariaLabelIfNorwegian(
|
|
417
|
+
"Forrige måned",
|
|
418
|
+
locale,
|
|
419
|
+
prevButtonProps
|
|
420
|
+
),
|
|
421
|
+
children: /* @__PURE__ */ jsx(LeftArrowIcon, { size: 20 })
|
|
422
|
+
}
|
|
423
|
+
),
|
|
424
|
+
/* @__PURE__ */ jsx("h2", { children: monthCount > 1 ? getMonthTitle(startDate) : title }),
|
|
425
|
+
i === monthCount - 1 && /* @__PURE__ */ jsx(
|
|
426
|
+
CalendarButton,
|
|
427
|
+
{
|
|
428
|
+
...nextButtonProps,
|
|
429
|
+
"aria-label": ariaLabelIfNorwegian(
|
|
430
|
+
"Neste måned",
|
|
431
|
+
locale,
|
|
432
|
+
nextButtonProps
|
|
433
|
+
),
|
|
434
|
+
children: /* @__PURE__ */ jsx(RightArrowIcon, { size: 20 })
|
|
435
|
+
}
|
|
436
|
+
)
|
|
437
|
+
] }),
|
|
438
|
+
/* @__PURE__ */ jsx(
|
|
439
|
+
CalendarGrid,
|
|
440
|
+
{
|
|
441
|
+
state,
|
|
442
|
+
startDate,
|
|
443
|
+
navigationDescription,
|
|
444
|
+
showWeekNumbers,
|
|
445
|
+
weekNumberHeader,
|
|
446
|
+
renderCell
|
|
447
|
+
}
|
|
448
|
+
)
|
|
449
|
+
] }, i);
|
|
450
|
+
}) })
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
};
|
|
306
454
|
const CalendarCell = ({
|
|
307
455
|
state,
|
|
308
456
|
date,
|
|
457
|
+
currentMonth,
|
|
309
458
|
showOutsideMonth = false,
|
|
310
459
|
onSelectedCellClick = () => {
|
|
311
460
|
return;
|
|
@@ -329,6 +478,8 @@ const CalendarCell = ({
|
|
|
329
478
|
formattedDate
|
|
330
479
|
} = useCalendarCell({ date }, state, cellRef);
|
|
331
480
|
const ariaLabel = `${buttonProps["aria-label"]}${weekNumberString} ${ariaLabelForDate?.(date) ?? ""}`;
|
|
481
|
+
const isOverflowDate = date.month !== currentMonth.month || date.year !== currentMonth.year;
|
|
482
|
+
const isBetweenVisibleMonths = isOverflowDate && !isOutsideVisibleRange;
|
|
332
483
|
const cellCanBeSelected = showOutsideMonth ? !(isDisabled || isUnavailable) : !(isOutsideVisibleRange || isDisabled || isUnavailable);
|
|
333
484
|
const shouldHideDate = !showOutsideMonth && isOutsideVisibleRange;
|
|
334
485
|
const extendedButtonProps = {
|
|
@@ -344,21 +495,31 @@ const CalendarCell = ({
|
|
|
344
495
|
onCellClick();
|
|
345
496
|
}
|
|
346
497
|
}
|
|
498
|
+
},
|
|
499
|
+
...isBetweenVisibleMonths && {
|
|
500
|
+
tabIndex: -1,
|
|
501
|
+
role: "presentation",
|
|
502
|
+
onClick: void 0,
|
|
503
|
+
onKeyDown: void 0,
|
|
504
|
+
onKeyUp: void 0,
|
|
505
|
+
onPointerDown: void 0,
|
|
506
|
+
onFocus: void 0
|
|
347
507
|
}
|
|
348
508
|
};
|
|
349
509
|
return /* @__PURE__ */ jsx("td", { ...cellProps, className: "eds-datepicker__calendar__grid__cell__td", children: /* @__PURE__ */ jsx(
|
|
350
510
|
"div",
|
|
351
511
|
{
|
|
352
512
|
...extendedButtonProps,
|
|
353
|
-
"aria-label": ariaLabel,
|
|
354
|
-
"aria-hidden": shouldHideDate,
|
|
513
|
+
"aria-label": isBetweenVisibleMonths ? void 0 : ariaLabel,
|
|
514
|
+
"aria-hidden": shouldHideDate || isBetweenVisibleMonths,
|
|
355
515
|
ref: cellRef,
|
|
356
516
|
hidden: shouldHideDate,
|
|
357
517
|
className: classNames("eds-datepicker__calendar__grid__cell", {
|
|
358
518
|
[classNameForDate?.(date) ?? ""]: !shouldHideDate,
|
|
359
|
-
"eds-datepicker__calendar__grid__cell--selected": isSelected,
|
|
519
|
+
"eds-datepicker__calendar__grid__cell--selected": isSelected && !isOverflowDate,
|
|
360
520
|
"eds-datepicker__calendar__grid__cell--disabled": isDisabled || isUnavailable,
|
|
361
521
|
"eds-datepicker__calendar__grid__cell--outside-month": isOutsideVisibleRange && !showOutsideMonth,
|
|
522
|
+
"eds-datepicker__calendar__grid__cell--between-months": isBetweenVisibleMonths,
|
|
362
523
|
"eds-datepicker__calendar__grid__cell--outside-month--visible": isOutsideVisibleRange && showOutsideMonth,
|
|
363
524
|
"eds-datepicker__calendar__grid__cell--today": isEqualDay(
|
|
364
525
|
date,
|
|
@@ -367,11 +528,13 @@ const CalendarCell = ({
|
|
|
367
528
|
}),
|
|
368
529
|
...rest,
|
|
369
530
|
onClick: (e) => {
|
|
531
|
+
if (isBetweenVisibleMonths) return;
|
|
370
532
|
extendedButtonProps?.onClick?.(e);
|
|
371
533
|
isSelected && onSelectedCellClick();
|
|
372
534
|
cellCanBeSelected && onCellClick();
|
|
373
535
|
},
|
|
374
536
|
onKeyUp: (e) => {
|
|
537
|
+
if (isBetweenVisibleMonths) return;
|
|
375
538
|
extendedButtonProps?.onKeyUp?.(e);
|
|
376
539
|
if (e.key === "Enter") {
|
|
377
540
|
isSelected && onSelectedCellClick();
|
|
@@ -382,103 +545,15 @@ const CalendarCell = ({
|
|
|
382
545
|
}
|
|
383
546
|
) });
|
|
384
547
|
};
|
|
385
|
-
const CalendarGrid = ({
|
|
386
|
-
state,
|
|
387
|
-
navigationDescription,
|
|
388
|
-
onSelectedCellClick = () => {
|
|
389
|
-
return;
|
|
390
|
-
},
|
|
391
|
-
onCellClick = () => {
|
|
392
|
-
return;
|
|
393
|
-
},
|
|
394
|
-
showWeekNumbers,
|
|
395
|
-
weekNumberHeader,
|
|
396
|
-
showOutsideMonth = false,
|
|
397
|
-
classNameForDate,
|
|
398
|
-
ariaLabelForDate,
|
|
399
|
-
...rest
|
|
400
|
-
}) => {
|
|
401
|
-
const calendarGridId = useRandomId("eds-calendar");
|
|
402
|
-
const { locale } = useLocale();
|
|
403
|
-
const { gridProps, headerProps, weekDays } = useCalendarGrid(rest, state);
|
|
404
|
-
const weeksInMonth = getWeeksInMonth(state.visibleRange.start, locale);
|
|
405
|
-
const weeksArray = Array.from(Array(weeksInMonth).keys());
|
|
406
|
-
const weekDaysMapped = () => {
|
|
407
|
-
if (locale.toLowerCase().includes("no"))
|
|
408
|
-
return ["ma", "ti", "on", "to", "fr", "lø", "sø"];
|
|
409
|
-
if (locale.toLowerCase().includes("en")) {
|
|
410
|
-
if (weekDays[0] === "M")
|
|
411
|
-
return ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
412
|
-
if (weekDays[0] === "S")
|
|
413
|
-
return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
414
|
-
}
|
|
415
|
-
return weekDays.map((day) => day.toLowerCase());
|
|
416
|
-
};
|
|
417
|
-
const getNavigationDescription = () => {
|
|
418
|
-
if (navigationDescription) return navigationDescription;
|
|
419
|
-
if (locale.toLowerCase().includes("en"))
|
|
420
|
-
return "Use the arrow keys to navigate between dates";
|
|
421
|
-
return "Bruk piltastene til å navigere mellom datoer";
|
|
422
|
-
};
|
|
423
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
424
|
-
/* @__PURE__ */ jsxs(
|
|
425
|
-
"table",
|
|
426
|
-
{
|
|
427
|
-
...gridProps,
|
|
428
|
-
cellSpacing: "0",
|
|
429
|
-
className: "eds-datepicker__calendar__grid",
|
|
430
|
-
children: [
|
|
431
|
-
/* @__PURE__ */ jsx("thead", { ...headerProps, children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
432
|
-
showWeekNumbers && /* @__PURE__ */ jsx("th", { className: "eds-datepicker__calendar__grid__weeknumber-header", children: weekNumberHeader }),
|
|
433
|
-
weekDaysMapped().map((day) => /* @__PURE__ */ jsx("th", { children: day }, day))
|
|
434
|
-
] }) }),
|
|
435
|
-
/* @__PURE__ */ jsx("tbody", { children: weeksArray.map((weekIndex) => {
|
|
436
|
-
const weekNumber = getWeekNumberForDate(
|
|
437
|
-
state.getDatesInWeek(weekIndex)[0]
|
|
438
|
-
);
|
|
439
|
-
return /* @__PURE__ */ jsxs("tr", { children: [
|
|
440
|
-
showWeekNumbers && /* @__PURE__ */ jsx(
|
|
441
|
-
"th",
|
|
442
|
-
{
|
|
443
|
-
"aria-label": `${weekNumberHeader} ${weekNumber}`,
|
|
444
|
-
className: "eds-datepicker__calendar__grid__weeknumber",
|
|
445
|
-
children: weekNumber
|
|
446
|
-
}
|
|
447
|
-
),
|
|
448
|
-
state.getDatesInWeek(weekIndex).map(
|
|
449
|
-
(date, i) => date ? /* @__PURE__ */ jsx(
|
|
450
|
-
CalendarCell,
|
|
451
|
-
{
|
|
452
|
-
state,
|
|
453
|
-
date,
|
|
454
|
-
"aria-describedby": calendarGridId + "description",
|
|
455
|
-
weekNumberString: showWeekNumbers ? `, ${weekNumberHeader} ${weekNumber},` : "",
|
|
456
|
-
onSelectedCellClick,
|
|
457
|
-
onCellClick,
|
|
458
|
-
classNameForDate,
|
|
459
|
-
ariaLabelForDate,
|
|
460
|
-
showOutsideMonth
|
|
461
|
-
},
|
|
462
|
-
`${date.month}.${date.day}`
|
|
463
|
-
) : /* @__PURE__ */ jsx("td", {}, i)
|
|
464
|
-
)
|
|
465
|
-
] }, weekIndex);
|
|
466
|
-
}) })
|
|
467
|
-
]
|
|
468
|
-
}
|
|
469
|
-
),
|
|
470
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { id: calendarGridId + "description", children: getNavigationDescription() })
|
|
471
|
-
] });
|
|
472
|
-
};
|
|
473
548
|
const Calendar = ({
|
|
474
549
|
locale: localOverride,
|
|
475
550
|
...rest
|
|
476
551
|
}) => {
|
|
477
552
|
const props = { isDisabled: rest.disabled, ...rest };
|
|
478
553
|
const { locale } = useLocale();
|
|
479
|
-
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(
|
|
554
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_Calendar, { ...props }) });
|
|
480
555
|
};
|
|
481
|
-
const
|
|
556
|
+
const _Calendar = ({
|
|
482
557
|
selectedDate,
|
|
483
558
|
onChange,
|
|
484
559
|
minDate,
|
|
@@ -486,6 +561,7 @@ const CalendarBase = ({
|
|
|
486
561
|
showWeekNumbers = false,
|
|
487
562
|
weekNumberHeader = "uke",
|
|
488
563
|
showOutsideMonth = false,
|
|
564
|
+
visibleDuration,
|
|
489
565
|
forcedReturnType,
|
|
490
566
|
style,
|
|
491
567
|
className,
|
|
@@ -514,7 +590,8 @@ const CalendarBase = ({
|
|
|
514
590
|
locale,
|
|
515
591
|
createCalendar,
|
|
516
592
|
minValue: minDate,
|
|
517
|
-
maxValue: getAdjustedMaxDate(maxDate)
|
|
593
|
+
maxValue: getAdjustedMaxDate(maxDate),
|
|
594
|
+
visibleDuration
|
|
518
595
|
};
|
|
519
596
|
const state = useCalendarState(_props);
|
|
520
597
|
const { calendarProps, prevButtonProps, nextButtonProps, title } = useCalendar(_props, state);
|
|
@@ -522,57 +599,185 @@ const CalendarBase = ({
|
|
|
522
599
|
() => rest.onValidate?.(!state.isValueInvalid),
|
|
523
600
|
[state.isValueInvalid]
|
|
524
601
|
);
|
|
525
|
-
return /* @__PURE__ */
|
|
526
|
-
|
|
602
|
+
return /* @__PURE__ */ jsx(
|
|
603
|
+
CalendarBase,
|
|
527
604
|
{
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
605
|
+
state,
|
|
606
|
+
calendarProps,
|
|
607
|
+
prevButtonProps,
|
|
608
|
+
nextButtonProps,
|
|
609
|
+
title,
|
|
610
|
+
calendarRef,
|
|
531
611
|
style,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
612
|
+
className,
|
|
613
|
+
navigationDescription,
|
|
614
|
+
showWeekNumbers,
|
|
615
|
+
weekNumberHeader,
|
|
616
|
+
renderCell: (date, currentMonth, weekNumberString, ariaDescribedBy) => /* @__PURE__ */ jsx(
|
|
617
|
+
CalendarCell,
|
|
618
|
+
{
|
|
619
|
+
state,
|
|
620
|
+
date,
|
|
621
|
+
currentMonth,
|
|
622
|
+
"aria-describedby": ariaDescribedBy,
|
|
623
|
+
weekNumberString,
|
|
624
|
+
onSelectedCellClick,
|
|
625
|
+
onCellClick,
|
|
626
|
+
classNameForDate,
|
|
627
|
+
ariaLabelForDate,
|
|
628
|
+
showOutsideMonth
|
|
629
|
+
},
|
|
630
|
+
`${date.month}.${date.day}`
|
|
631
|
+
)
|
|
632
|
+
}
|
|
633
|
+
);
|
|
634
|
+
};
|
|
635
|
+
const RangeCalendarCell = ({
|
|
636
|
+
state,
|
|
637
|
+
date,
|
|
638
|
+
currentMonth,
|
|
639
|
+
showOutsideMonth = false,
|
|
640
|
+
weekNumberString,
|
|
641
|
+
classNameForDate,
|
|
642
|
+
ariaLabelForDate,
|
|
643
|
+
...rest
|
|
644
|
+
}) => {
|
|
645
|
+
const cellRef = useRef(null);
|
|
646
|
+
const {
|
|
647
|
+
cellProps,
|
|
648
|
+
buttonProps,
|
|
649
|
+
isSelected,
|
|
650
|
+
isOutsideVisibleRange,
|
|
651
|
+
isDisabled,
|
|
652
|
+
isUnavailable,
|
|
653
|
+
formattedDate
|
|
654
|
+
} = useCalendarCell({ date }, state, cellRef);
|
|
655
|
+
const ariaLabel = `${buttonProps["aria-label"]}${weekNumberString} ${ariaLabelForDate?.(date) ?? ""}`;
|
|
656
|
+
const highlightedRange = state.highlightedRange;
|
|
657
|
+
const isSelectionStart = isSelected && highlightedRange ? isSameDay(date, highlightedRange.start) : isSelected;
|
|
658
|
+
const isSelectionEnd = isSelected && highlightedRange ? isSameDay(date, highlightedRange.end) : isSelected;
|
|
659
|
+
const isInRange = isSelected && !isSelectionStart && !isSelectionEnd;
|
|
660
|
+
const isOverflowDate = date.month !== currentMonth.month || date.year !== currentMonth.year;
|
|
661
|
+
const isBetweenVisibleMonths = isOverflowDate && !isOutsideVisibleRange;
|
|
662
|
+
const shouldHideDate = !showOutsideMonth && isOutsideVisibleRange;
|
|
663
|
+
const extendedButtonProps = {
|
|
664
|
+
...buttonProps,
|
|
665
|
+
...showOutsideMonth && isOutsideVisibleRange && {
|
|
666
|
+
onClick: () => state.selectDate(date),
|
|
667
|
+
onKeyUp: (e) => {
|
|
668
|
+
if (e.key === "Enter") state.selectDate(date);
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
...isBetweenVisibleMonths && {
|
|
672
|
+
tabIndex: -1,
|
|
673
|
+
role: "presentation",
|
|
674
|
+
onClick: void 0,
|
|
675
|
+
onKeyDown: void 0,
|
|
676
|
+
onKeyUp: void 0,
|
|
677
|
+
onPointerDown: void 0,
|
|
678
|
+
onFocus: void 0
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
return /* @__PURE__ */ jsx("td", { ...cellProps, className: "eds-datepicker__calendar__grid__cell__td", children: /* @__PURE__ */ jsx(
|
|
682
|
+
"div",
|
|
683
|
+
{
|
|
684
|
+
...extendedButtonProps,
|
|
685
|
+
"aria-label": isBetweenVisibleMonths ? void 0 : ariaLabel,
|
|
686
|
+
"aria-hidden": shouldHideDate || isBetweenVisibleMonths,
|
|
687
|
+
ref: cellRef,
|
|
688
|
+
hidden: shouldHideDate,
|
|
689
|
+
className: classNames("eds-datepicker__calendar__grid__cell", {
|
|
690
|
+
[classNameForDate?.(date) ?? ""]: !shouldHideDate,
|
|
691
|
+
"eds-datepicker__calendar__grid__cell--selected": isSelected && !isOverflowDate,
|
|
692
|
+
"eds-datepicker__calendar__grid__cell--selection-start": isSelectionStart && !isOverflowDate,
|
|
693
|
+
"eds-datepicker__calendar__grid__cell--selection-end": isSelectionEnd && !isOverflowDate,
|
|
694
|
+
"eds-datepicker__calendar__grid__cell--in-range": isInRange && !isOverflowDate,
|
|
695
|
+
"eds-datepicker__calendar__grid__cell--disabled": isDisabled || isUnavailable,
|
|
696
|
+
"eds-datepicker__calendar__grid__cell--outside-month": isOutsideVisibleRange && !showOutsideMonth,
|
|
697
|
+
"eds-datepicker__calendar__grid__cell--between-months": isBetweenVisibleMonths,
|
|
698
|
+
"eds-datepicker__calendar__grid__cell--outside-month--visible": isOutsideVisibleRange && showOutsideMonth,
|
|
699
|
+
"eds-datepicker__calendar__grid__cell--today": isEqualDay(
|
|
700
|
+
date,
|
|
701
|
+
now(state.timeZone ?? getLocalTimeZone())
|
|
574
702
|
)
|
|
575
|
-
|
|
703
|
+
}),
|
|
704
|
+
...rest,
|
|
705
|
+
children: formattedDate
|
|
706
|
+
}
|
|
707
|
+
) });
|
|
708
|
+
};
|
|
709
|
+
const RangeCalendar = ({
|
|
710
|
+
locale: localOverride,
|
|
711
|
+
...rest
|
|
712
|
+
}) => {
|
|
713
|
+
const props = { isDisabled: rest.disabled, ...rest };
|
|
714
|
+
const { locale } = useLocale();
|
|
715
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_RangeCalendar, { ...props }) });
|
|
716
|
+
};
|
|
717
|
+
const _RangeCalendar = ({
|
|
718
|
+
value,
|
|
719
|
+
onChange,
|
|
720
|
+
minDate,
|
|
721
|
+
maxDate,
|
|
722
|
+
showWeekNumbers = false,
|
|
723
|
+
weekNumberHeader = "uke",
|
|
724
|
+
showOutsideMonth = false,
|
|
725
|
+
visibleDuration,
|
|
726
|
+
style,
|
|
727
|
+
className,
|
|
728
|
+
navigationDescription,
|
|
729
|
+
classNameForDate,
|
|
730
|
+
ariaLabelForDate,
|
|
731
|
+
calendarRef,
|
|
732
|
+
...rest
|
|
733
|
+
}) => {
|
|
734
|
+
const { locale } = useLocale();
|
|
735
|
+
const internalRef = useRef(null);
|
|
736
|
+
const ref = calendarRef ?? internalRef;
|
|
737
|
+
const _props = {
|
|
738
|
+
...rest,
|
|
739
|
+
value,
|
|
740
|
+
onChange,
|
|
741
|
+
locale,
|
|
742
|
+
createCalendar,
|
|
743
|
+
minValue: minDate,
|
|
744
|
+
maxValue: getAdjustedMaxDate(maxDate),
|
|
745
|
+
visibleDuration
|
|
746
|
+
};
|
|
747
|
+
const state = useRangeCalendarState(_props);
|
|
748
|
+
const { calendarProps, prevButtonProps, nextButtonProps, title } = useRangeCalendar(_props, state, ref);
|
|
749
|
+
useEffect(
|
|
750
|
+
() => rest.onValidate?.(!state.isValueInvalid),
|
|
751
|
+
[state.isValueInvalid]
|
|
752
|
+
);
|
|
753
|
+
return /* @__PURE__ */ jsx(
|
|
754
|
+
CalendarBase,
|
|
755
|
+
{
|
|
756
|
+
state,
|
|
757
|
+
calendarProps,
|
|
758
|
+
prevButtonProps,
|
|
759
|
+
nextButtonProps,
|
|
760
|
+
title,
|
|
761
|
+
calendarRef: ref,
|
|
762
|
+
style,
|
|
763
|
+
className,
|
|
764
|
+
navigationDescription,
|
|
765
|
+
showWeekNumbers,
|
|
766
|
+
weekNumberHeader,
|
|
767
|
+
renderCell: (date, currentMonth, weekNumberString, ariaDescribedBy) => /* @__PURE__ */ jsx(
|
|
768
|
+
RangeCalendarCell,
|
|
769
|
+
{
|
|
770
|
+
state,
|
|
771
|
+
date,
|
|
772
|
+
currentMonth,
|
|
773
|
+
"aria-describedby": ariaDescribedBy,
|
|
774
|
+
weekNumberString,
|
|
775
|
+
classNameForDate,
|
|
776
|
+
ariaLabelForDate,
|
|
777
|
+
showOutsideMonth
|
|
778
|
+
},
|
|
779
|
+
`${date.month}.${date.day}`
|
|
780
|
+
)
|
|
576
781
|
}
|
|
577
782
|
);
|
|
578
783
|
};
|
|
@@ -1253,6 +1458,7 @@ export {
|
|
|
1253
1458
|
DatePicker,
|
|
1254
1459
|
NativeDatePicker,
|
|
1255
1460
|
NativeTimePicker,
|
|
1461
|
+
RangeCalendar,
|
|
1256
1462
|
SimpleTimePicker,
|
|
1257
1463
|
Time2 as Time,
|
|
1258
1464
|
TimePicker,
|