@entur/datepicker 11.7.0 → 12.0.0-next.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.
@@ -1,14 +1,14 @@
1
- import { useRandomId, ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from "@entur/utils";
1
+ import { ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from "@entur/utils";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import React, { useRef, useEffect, useState } from "react";
3
+ import React, { useRef, useEffect, useId, useState } from "react";
4
4
  import { useDateFieldState, useDatePickerState, useTimeFieldState } from "@react-stately/datepicker";
5
5
  import { useDateSegment, useDateField, useDatePicker, useTimeField } from "@react-aria/datepicker";
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, getWeeksInMonth, isSameDay, parseTime } from "@internationalized/date";
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 { useCalendarCell, useCalendarGrid, useCalendar, useRangeCalendar } from "@react-aria/calendar";
11
+ import { useCalendarGrid, useCalendarCell, useCalendar, useRangeCalendar } from "@react-aria/calendar";
12
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";
@@ -258,7 +258,7 @@ const DateField = ({
258
258
  const dateFieldRef = useRef(null);
259
259
  const { labelProps, fieldProps } = useDateField(_props, state, dateFieldRef);
260
260
  useEffect(() => onValidate?.(!state.isInvalid), [state.isInvalid]);
261
- const id = useRandomId("datefield");
261
+ const id = `datefield${useId()}`;
262
262
  return /* @__PURE__ */ jsx(
263
263
  ConditionalWrapper,
264
264
  {
@@ -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 = `eds-calendar${useId()}`;
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(CalendarBase, { ...props }) });
554
+ return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_Calendar, { ...props }) });
480
555
  };
481
- const CalendarBase = ({
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,36 @@ const CalendarBase = ({
522
599
  () => rest.onValidate?.(!state.isValueInvalid),
523
600
  [state.isValueInvalid]
524
601
  );
525
- return /* @__PURE__ */ jsxs(
526
- "div",
602
+ return /* @__PURE__ */ jsx(
603
+ CalendarBase,
527
604
  {
528
- ...calendarProps,
529
- ref: calendarRef,
530
- className: classNames("eds-datepicker__calendar", className),
605
+ state,
606
+ calendarProps,
607
+ prevButtonProps,
608
+ nextButtonProps,
609
+ title,
610
+ calendarRef,
531
611
  style,
532
- children: [
533
- /* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__header", children: [
534
- /* @__PURE__ */ jsx(
535
- CalendarButton,
536
- {
537
- ...prevButtonProps,
538
- "aria-label": ariaLabelIfNorwegian(
539
- "Forrige måned",
540
- locale,
541
- prevButtonProps
542
- ),
543
- children: /* @__PURE__ */ jsx(LeftArrowIcon, { size: 20 })
544
- }
545
- ),
546
- /* @__PURE__ */ jsx("h2", { children: title }),
547
- /* @__PURE__ */ jsx(
548
- CalendarButton,
549
- {
550
- ...nextButtonProps,
551
- "aria-label": ariaLabelIfNorwegian(
552
- "Neste måned",
553
- locale,
554
- nextButtonProps
555
- ),
556
- children: /* @__PURE__ */ jsx(RightArrowIcon, { size: 20 })
557
- }
558
- )
559
- ] }),
560
- /* @__PURE__ */ jsx(
561
- CalendarGrid,
562
- {
563
- ...rest,
564
- state,
565
- navigationDescription,
566
- onSelectedCellClick,
567
- onCellClick,
568
- classNameForDate,
569
- ariaLabelForDate,
570
- showWeekNumbers,
571
- weekNumberHeader,
572
- showOutsideMonth
573
- }
574
- )
575
- ]
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
+ )
576
632
  }
577
633
  );
578
634
  };
@@ -650,101 +706,15 @@ const RangeCalendarCell = ({
650
706
  }
651
707
  ) });
652
708
  };
653
- const RangeCalendarGrid = ({
654
- state,
655
- startDate,
656
- navigationDescription,
657
- showWeekNumbers,
658
- weekNumberHeader,
659
- showOutsideMonth = false,
660
- classNameForDate,
661
- ariaLabelForDate,
662
- ...rest
663
- }) => {
664
- const calendarGridId = useRandomId("eds-calendar");
665
- const { locale } = useLocale();
666
- const gridStartDate = startDate ?? state.visibleRange.start;
667
- const { gridProps, headerProps, weekDays } = useCalendarGrid(
668
- { ...rest, startDate: gridStartDate },
669
- state
670
- );
671
- const weeksInMonth = getWeeksInMonth(gridStartDate, locale);
672
- const weeksArray = Array.from(Array(weeksInMonth).keys());
673
- const weekDaysMapped = () => {
674
- if (locale.toLowerCase().includes("no"))
675
- return ["ma", "ti", "on", "to", "fr", "lø", "sø"];
676
- if (locale.toLowerCase().includes("en")) {
677
- if (weekDays[0] === "M")
678
- return ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
679
- if (weekDays[0] === "S")
680
- return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
681
- }
682
- return weekDays.map((day) => day.toLowerCase());
683
- };
684
- const getNavigationDescription = () => {
685
- if (navigationDescription) return navigationDescription;
686
- if (locale.toLowerCase().includes("en"))
687
- return "Use the arrow keys to navigate between dates";
688
- return "Bruk piltastene til å navigere mellom datoer";
689
- };
690
- return /* @__PURE__ */ jsxs(Fragment, { children: [
691
- /* @__PURE__ */ jsxs(
692
- "table",
693
- {
694
- ...gridProps,
695
- cellSpacing: "0",
696
- className: "eds-datepicker__calendar__grid",
697
- children: [
698
- /* @__PURE__ */ jsx("thead", { ...headerProps, children: /* @__PURE__ */ jsxs("tr", { children: [
699
- showWeekNumbers && /* @__PURE__ */ jsx("th", { className: "eds-datepicker__calendar__grid__weeknumber-header", children: weekNumberHeader }),
700
- weekDaysMapped().map((day) => /* @__PURE__ */ jsx("th", { children: day }, day))
701
- ] }) }),
702
- /* @__PURE__ */ jsx("tbody", { children: weeksArray.map((weekIndex) => {
703
- const weekNumber = getWeekNumberForDate(
704
- state.getDatesInWeek(weekIndex, gridStartDate)[0]
705
- );
706
- return /* @__PURE__ */ jsxs("tr", { children: [
707
- showWeekNumbers && /* @__PURE__ */ jsx(
708
- "th",
709
- {
710
- "aria-label": `${weekNumberHeader} ${weekNumber}`,
711
- className: "eds-datepicker__calendar__grid__weeknumber",
712
- children: weekNumber
713
- }
714
- ),
715
- state.getDatesInWeek(weekIndex, gridStartDate).map(
716
- (date, i) => date ? /* @__PURE__ */ jsx(
717
- RangeCalendarCell,
718
- {
719
- state,
720
- date,
721
- currentMonth: gridStartDate,
722
- "aria-describedby": calendarGridId + "description",
723
- weekNumberString: showWeekNumbers ? `, ${weekNumberHeader} ${weekNumber},` : "",
724
- classNameForDate,
725
- ariaLabelForDate,
726
- showOutsideMonth
727
- },
728
- `${date.month}.${date.day}`
729
- ) : /* @__PURE__ */ jsx("td", {}, i)
730
- )
731
- ] }, weekIndex);
732
- }) })
733
- ]
734
- }
735
- ),
736
- /* @__PURE__ */ jsx(VisuallyHidden, { id: calendarGridId + "description", children: getNavigationDescription() })
737
- ] });
738
- };
739
709
  const RangeCalendar = ({
740
710
  locale: localOverride,
741
711
  ...rest
742
712
  }) => {
743
713
  const props = { isDisabled: rest.disabled, ...rest };
744
714
  const { locale } = useLocale();
745
- return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(RangeCalendarBase, { ...props }) });
715
+ return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(_RangeCalendar, { ...props }) });
746
716
  };
747
- const RangeCalendarBase = ({
717
+ const _RangeCalendar = ({
748
718
  value,
749
719
  onChange,
750
720
  minDate,
@@ -780,63 +750,34 @@ const RangeCalendarBase = ({
780
750
  () => rest.onValidate?.(!state.isValueInvalid),
781
751
  [state.isValueInvalid]
782
752
  );
783
- const monthCount = state.visibleRange.end.month - state.visibleRange.start.month + 1 + (state.visibleRange.end.year - state.visibleRange.start.year) * 12;
784
- const getMonthTitle = (startDate) => new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(
785
- new Date(startDate.year, startDate.month - 1)
786
- );
787
753
  return /* @__PURE__ */ jsx(
788
- "div",
754
+ CalendarBase,
789
755
  {
790
- ...calendarProps,
791
- ref,
792
- className: classNames("eds-datepicker__calendar", className),
756
+ state,
757
+ calendarProps,
758
+ prevButtonProps,
759
+ nextButtonProps,
760
+ title,
761
+ calendarRef: ref,
793
762
  style,
794
- children: /* @__PURE__ */ jsx("div", { className: "eds-datepicker__calendar__grids", children: Array.from({ length: monthCount }, (_, i) => {
795
- const startDate = state.visibleRange.start.add({ months: i });
796
- return /* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__month", children: [
797
- /* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__header", children: [
798
- i === 0 && /* @__PURE__ */ jsx(
799
- CalendarButton,
800
- {
801
- ...prevButtonProps,
802
- "aria-label": ariaLabelIfNorwegian(
803
- "Forrige måned",
804
- locale,
805
- prevButtonProps
806
- ),
807
- children: /* @__PURE__ */ jsx(LeftArrowIcon, { size: 20 })
808
- }
809
- ),
810
- /* @__PURE__ */ jsx("h2", { children: monthCount > 1 ? getMonthTitle(startDate) : title }),
811
- i === monthCount - 1 && /* @__PURE__ */ jsx(
812
- CalendarButton,
813
- {
814
- ...nextButtonProps,
815
- "aria-label": ariaLabelIfNorwegian(
816
- "Neste måned",
817
- locale,
818
- nextButtonProps
819
- ),
820
- children: /* @__PURE__ */ jsx(RightArrowIcon, { size: 20 })
821
- }
822
- )
823
- ] }),
824
- /* @__PURE__ */ jsx(
825
- RangeCalendarGrid,
826
- {
827
- ...rest,
828
- state,
829
- startDate,
830
- navigationDescription,
831
- classNameForDate,
832
- ariaLabelForDate,
833
- showWeekNumbers,
834
- weekNumberHeader,
835
- showOutsideMonth
836
- }
837
- )
838
- ] }, i);
839
- }) })
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
+ )
840
781
  }
841
782
  );
842
783
  };
@@ -1016,7 +957,7 @@ const NativeDatePicker = React.forwardRef(
1016
957
  prepend = /* @__PURE__ */ jsx(DateIcon, { inline: true }),
1017
958
  ...rest
1018
959
  }, ref) => {
1019
- const nativedatepickerId = useRandomId("eds-nativetimepicker");
960
+ const nativedatepickerId = `eds-nativetimepicker${useId()}`;
1020
961
  return /* @__PURE__ */ jsx(
1021
962
  BaseFormControl,
1022
963
  {
@@ -1133,7 +1074,7 @@ const TimePicker = ({
1133
1074
  }) => {
1134
1075
  let { locale } = useLocale();
1135
1076
  if (customLocale) locale = customLocale;
1136
- const timePickerId = useRandomId("eds-timepicker");
1077
+ const timePickerId = `eds-timepicker${useId()}`;
1137
1078
  const timeZone = forcedTimeZone ?? (selectedTime !== null && "timeZone" in selectedTime ? selectedTime.timeZone : "Europe/Oslo");
1138
1079
  const handleOnChange2 = (value) => {
1139
1080
  if (forcedReturnType !== void 0 || !selectedTime) {
@@ -1164,7 +1105,7 @@ const TimePicker = ({
1164
1105
  state,
1165
1106
  timeFieldRef
1166
1107
  );
1167
- const id = useRandomId("timepicker");
1108
+ const id = `timepicker${useId()}`;
1168
1109
  const getCurrentTime = () => {
1169
1110
  const getCurrentTimeWithCorrectType = convertValueToType({
1170
1111
  value: now(timeZone),
@@ -1264,7 +1205,7 @@ const TimePicker = ({
1264
1205
  };
1265
1206
  const NativeTimePicker = React.forwardRef(
1266
1207
  ({ className, style, onChange, label, feedback, variant, prepend, ...rest }, ref) => {
1267
- const nativetimepickerId = useRandomId("eds-native-timepicker");
1208
+ const nativetimepickerId = `eds-native-timepicker${useId()}`;
1268
1209
  return /* @__PURE__ */ jsx(
1269
1210
  BaseFormControl,
1270
1211
  {