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