@helsenorge/datepicker 12.5.0 → 12.7.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/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ ## [12.7.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.6.4&targetVersion=GTv12.7.0) (2025-10-17)
2
+
3
+ ### Features
4
+
5
+ - **formgroup:** endre prop for FormFieldTag til å være lik som i label
6
+ ([850b4e0](https://github.com/helsenorge/designsystem/commit/850b4e0cdc5888dbe29ba894c23e460dfe9d4930)), closes
7
+ [#362503](https://github.com/helsenorge/designsystem/issues/362503)
8
+
9
+ ## [12.6.4](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.6.3&targetVersion=GTv12.6.4) (2025-10-16)
10
+
11
+ ### Reverts
12
+
13
+ - Revert "v12.6.3" ([973e6b8](https://github.com/helsenorge/designsystem/commit/973e6b8893fc765892a993adf83d93f4d5bfd5dd))
14
+
15
+ ## [12.6.3](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.6.2&targetVersion=GTv12.6.3) (2025-10-16)
16
+
17
+ ## [12.6.2](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.6.1&targetVersion=GTv12.6.2) (2025-10-16)
18
+
19
+ ## [12.6.1](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.6.0&targetVersion=GTv12.6.1) (2025-10-16)
20
+
21
+ ## [12.6.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.5.0&targetVersion=GTv12.6.0) (2025-10-16)
22
+
23
+ ### Features
24
+
25
+ - **formfieldtag:** ny komponent for å markere obligatoriske felter
26
+ ([43186e8](https://github.com/helsenorge/designsystem/commit/43186e85e06d6b3e34124c3afd372180ecff9af9)), closes
27
+ [#361861](https://github.com/helsenorge/designsystem/issues/361861)
28
+ - **stickynote:** justeringer etter ny figma komponent
29
+ ([b3afb5a](https://github.com/helsenorge/designsystem/commit/b3afb5a41f1400bef0afce40b244deafcac7b505)), closes
30
+ [#361520](https://github.com/helsenorge/designsystem/issues/361520)
31
+
32
+ ### Bug Fixes
33
+
34
+ - **formfieldtag:** fiks display for at den holder seg i riktig størrelse
35
+ ([1e53dc1](https://github.com/helsenorge/designsystem/commit/1e53dc1cf52215a3476a1d6d86c36f8108b0fbc1)), closes
36
+ [#361861](https://github.com/helsenorge/designsystem/issues/361861)
37
+ - **label:** bruk formfieldtag som komponent slik at man får satt id
38
+ ([006e152](https://github.com/helsenorge/designsystem/commit/006e1520cc16b66f637c11c193902510ebd72b76)), closes
39
+ [#361861](https://github.com/helsenorge/designsystem/issues/361861)
40
+
1
41
  ## [12.5.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv12.4.0&targetVersion=GTv12.5.0) (2025-10-08)
2
42
 
3
43
  ### Features
@@ -1,6 +1,6 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import React, { createContext, useContext, useCallback, useRef, useLayoutEffect, useState, useEffect, useMemo } from "react";
3
- import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getYear, getWeek, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, isValid, parse, isWithinInterval } from "date-fns";
3
+ import { addDays, addMonths, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarMonths, eachMonthOfInterval, eachYearOfInterval, endOfISOWeek, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, getMonth, getYear, getWeek, isAfter, isBefore, isDate, isSameDay, isSameMonth, isSameYear, max, min, setMonth, setYear, startOfDay, startOfISOWeek, startOfMonth, startOfWeek, startOfYear, isValid, parse, isWithinInterval } from "date-fns";
4
4
  import { nb } from "date-fns/locale";
5
5
  import Button$1 from "@helsenorge/designsystem-react/components/Button";
6
6
  import Icon from "@helsenorge/designsystem-react/components/Icon";
@@ -325,6 +325,19 @@ class DateLib {
325
325
  var _a;
326
326
  return ((_a = this.overrides) == null ? void 0 : _a.eachMonthOfInterval) ? this.overrides.eachMonthOfInterval(interval) : eachMonthOfInterval(interval);
327
327
  };
328
+ this.eachYearOfInterval = (interval) => {
329
+ var _a;
330
+ const years = ((_a = this.overrides) == null ? void 0 : _a.eachYearOfInterval) ? this.overrides.eachYearOfInterval(interval) : eachYearOfInterval(interval);
331
+ const uniqueYears = new Set(years.map((d) => this.getYear(d)));
332
+ if (uniqueYears.size === years.length) {
333
+ return years;
334
+ }
335
+ const yearsArray = [];
336
+ uniqueYears.forEach((y) => {
337
+ yearsArray.push(new Date(y, 0, 1));
338
+ });
339
+ return yearsArray;
340
+ };
328
341
  this.endOfBroadcastWeek = (date) => {
329
342
  var _a;
330
343
  return ((_a = this.overrides) == null ? void 0 : _a.endOfBroadcastWeek) ? this.overrides.endOfBroadcastWeek(date) : endOfBroadcastWeek(date, this);
@@ -475,7 +488,62 @@ class DateLib {
475
488
  formatNumber(value) {
476
489
  return this.replaceDigits(value.toString());
477
490
  }
478
- }
491
+ /**
492
+ * Returns the preferred ordering for month and year labels for the current
493
+ * locale.
494
+ */
495
+ getMonthYearOrder() {
496
+ var _a;
497
+ const code = (_a = this.options.locale) == null ? void 0 : _a.code;
498
+ if (!code) {
499
+ return "month-first";
500
+ }
501
+ return DateLib.yearFirstLocales.has(code) ? "year-first" : "month-first";
502
+ }
503
+ /**
504
+ * Formats the month/year pair respecting locale conventions.
505
+ *
506
+ * @since 9.11.0
507
+ */
508
+ formatMonthYear(date) {
509
+ const { locale, timeZone, numerals } = this.options;
510
+ const localeCode = locale == null ? void 0 : locale.code;
511
+ if (localeCode && DateLib.yearFirstLocales.has(localeCode)) {
512
+ try {
513
+ const intl = new Intl.DateTimeFormat(localeCode, {
514
+ month: "long",
515
+ year: "numeric",
516
+ timeZone,
517
+ numberingSystem: numerals
518
+ });
519
+ const formatted = intl.format(date);
520
+ return formatted;
521
+ } catch {
522
+ }
523
+ }
524
+ const pattern = this.getMonthYearOrder() === "year-first" ? "y LLLL" : "LLLL y";
525
+ return this.format(date, pattern);
526
+ }
527
+ }
528
+ DateLib.yearFirstLocales = /* @__PURE__ */ new Set([
529
+ "eu",
530
+ "hu",
531
+ "ja",
532
+ "ja-Hira",
533
+ "ja-JP",
534
+ "ko",
535
+ "ko-KR",
536
+ "lt",
537
+ "lt-LT",
538
+ "lv",
539
+ "lv-LV",
540
+ "mn",
541
+ "mn-MN",
542
+ "zh",
543
+ "zh-CN",
544
+ "zh-HK",
545
+ "zh-TW"
546
+ ]);
479
547
  const defaultDateLib = new DateLib();
480
548
  class CalendarDay {
481
549
  constructor(date, displayMonth, dateLib = defaultDateLib) {
@@ -947,7 +1015,8 @@ function getDefaultClassNames() {
947
1015
  return classNames2;
948
1016
  }
949
1017
  function formatCaption(month, options, dateLib) {
950
- return (dateLib ?? new DateLib(options)).format(month, "LLLL y");
1018
+ const lib = dateLib ?? new DateLib(options);
1019
+ return lib.formatMonthYear(month);
951
1020
  }
952
1021
  const formatMonthCaption = formatCaption;
953
1022
  function formatDay(date, options, dateLib) {
@@ -1035,21 +1104,16 @@ function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false)
1035
1104
  return void 0;
1036
1105
  if (!navEnd)
1037
1106
  return void 0;
1038
- const { startOfYear: startOfYear2, endOfYear: endOfYear2, addYears: addYears2, getYear: getYear2, isBefore: isBefore2, isSameYear: isSameYear2 } = dateLib;
1107
+ const { startOfYear: startOfYear2, endOfYear: endOfYear2, eachYearOfInterval: eachYearOfInterval2, getYear: getYear2 } = dateLib;
1039
1108
  const firstNavYear = startOfYear2(navStart);
1040
1109
  const lastNavYear = endOfYear2(navEnd);
1041
- const years = [];
1042
- let year = firstNavYear;
1043
- while (isBefore2(year, lastNavYear) || isSameYear2(year, lastNavYear)) {
1044
- years.push(year);
1045
- year = addYears2(year, 1);
1046
- }
1110
+ const years = eachYearOfInterval2({ start: firstNavYear, end: lastNavYear });
1047
1111
  if (reverse)
1048
1112
  years.reverse();
1049
- return years.map((year2) => {
1050
- const label = formatters.formatYearDropdown(year2, dateLib);
1113
+ return years.map((year) => {
1114
+ const label = formatters.formatYearDropdown(year, dateLib);
1051
1115
  return {
1052
- value: getYear2(year2),
1116
+ value: getYear2(year),
1053
1117
  label,
1054
1118
  disabled: false
1055
1119
  };
@@ -1065,7 +1129,8 @@ function labelDayButton(date, modifiers, options, dateLib) {
1065
1129
  }
1066
1130
  const labelDay = labelDayButton;
1067
1131
  function labelGrid(date, options, dateLib) {
1068
- return (dateLib ?? new DateLib(options)).format(date, "LLLL y");
1132
+ const lib = dateLib ?? new DateLib(options);
1133
+ return lib.formatMonthYear(date);
1069
1134
  }
1070
1135
  const labelCaption = labelGrid;
1071
1136
  function labelGridcell(date, modifiers, options, dateLib) {
@@ -1557,6 +1622,12 @@ function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
1557
1622
  const nextFocus = getNextFocus(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
1558
1623
  if (!nextFocus)
1559
1624
  return;
1625
+ if (props.disableNavigation) {
1626
+ const isNextInCalendar = calendar.days.some((day) => day.isEqualTo(nextFocus));
1627
+ if (!isNextInCalendar) {
1628
+ return;
1629
+ }
1630
+ }
1560
1631
  calendar.goToDay(nextFocus);
1561
1632
  setFocused(nextFocus);
1562
1633
  };
@@ -1977,7 +2048,7 @@ function DayPicker(initialProps) {
1977
2048
  { value: contextValue },
1978
2049
  React.createElement(
1979
2050
  components2.Root,
1980
- { rootRef: props.animate ? rootElRef : void 0, className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], ...dataAttributes },
2051
+ { rootRef: props.animate ? rootElRef : void 0, className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], ...dataAttributes },
1981
2052
  React.createElement(
1982
2053
  components2.Months,
1983
2054
  { className: classNames2[UI.Months], style: styles2 == null ? void 0 : styles2[UI.Months] },
@@ -2002,8 +2073,12 @@ function DayPicker(initialProps) {
2002
2073
  React.createElement(components2.MonthCaption, { "data-animated-caption": props.animate ? "true" : void 0, className: classNames2[UI.MonthCaption], style: styles2 == null ? void 0 : styles2[UI.MonthCaption], calendarMonth, displayIndex }, (captionLayout == null ? void 0 : captionLayout.startsWith("dropdown")) ? React.createElement(
2003
2074
  components2.DropdownNav,
2004
2075
  { className: classNames2[UI.Dropdowns], style: styles2 == null ? void 0 : styles2[UI.Dropdowns] },
2005
- captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { className: classNames2[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options: getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getMonth(calendarMonth.date) }) : React.createElement("span", null, formatMonthDropdown2(calendarMonth.date, dateLib)),
2006
- captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { className: classNames2[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options: getYearOptions(navStart, navEnd, formatters, dateLib, Boolean(props.reverseYears)), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getYear(calendarMonth.date) }) : React.createElement("span", null, formatYearDropdown2(calendarMonth.date, dateLib)),
2076
+ (() => {
2077
+ const monthControl = captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { key: "month", className: classNames2[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options: getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getMonth(calendarMonth.date) }) : React.createElement("span", { key: "month" }, formatMonthDropdown2(calendarMonth.date, dateLib));
2078
+ const yearControl = captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { key: "year", className: classNames2[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames: classNames2, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options: getYearOptions(navStart, navEnd, formatters, dateLib, Boolean(props.reverseYears)), style: styles2 == null ? void 0 : styles2[UI.Dropdown], value: dateLib.getYear(calendarMonth.date) }) : React.createElement("span", { key: "year" }, formatYearDropdown2(calendarMonth.date, dateLib));
2079
+ const controls = dateLib.getMonthYearOrder() === "year-first" ? [yearControl, monthControl] : [monthControl, yearControl];
2080
+ return controls;
2081
+ })(),
2007
2082
  React.createElement("span", { role: "status", "aria-live": "polite", style: {
2008
2083
  border: 0,
2009
2084
  clip: "rect(0 0 0 0)",