@oslokommune/punkt-react 20.2.1 → 20.2.2

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,197 +1,199 @@
1
1
  "use client";
2
2
  import "../../shared-types/index.js";
3
3
  import { DEFAULT_HEADER_FOOTER_URL as e } from "../../shared-types/header-footer.js";
4
- import { deriveSocialIcon as t, mapOdsIcon as n } from "../../shared-utils/header-footer/icon-map.js";
5
- import { fetchHeaderFooterData as r } from "../../shared-utils/header-footer/fetch-header-footer-data.js";
6
- import { selectLocaleData as i } from "../../shared-utils/header-footer/select-megamenu.js";
7
- import { useElementWidth as a } from "../../hooks/useElementWidth.js";
8
- import { usePktStrings as o } from "../../hooks/usePktStrings.js";
9
- import { PktAccordion as s } from "../accordion/Accordion.js";
10
- import { PktAccordionItem as c } from "../accordion/AccordionItem.js";
11
- import { PktIcon as l } from "../icon/Icon.js";
12
- import { useCallback as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
13
- import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
4
+ import { resolveOverride as t } from "../../shared-strings/resolve.js";
5
+ import { deriveSocialIcon as n, mapOdsIcon as r } from "../../shared-utils/header-footer/icon-map.js";
6
+ import { fetchHeaderFooterData as i } from "../../shared-utils/header-footer/fetch-header-footer-data.js";
7
+ import { selectLocaleData as a } from "../../shared-utils/header-footer/select-megamenu.js";
8
+ import { useElementWidth as o } from "../../hooks/useElementWidth.js";
9
+ import { usePktStrings as s } from "../../hooks/usePktStrings.js";
10
+ import { PktAccordion as c } from "../accordion/Accordion.js";
11
+ import { PktAccordionItem as l } from "../accordion/AccordionItem.js";
12
+ import { PktIcon as u } from "../icon/Icon.js";
13
+ import { PktStringsContext as d } from "../strings/PktStringsProvider.js";
14
+ import { useCallback as f, useContext as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
15
+ import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
14
16
  // src/components/header-menu/HeaderMenu.tsx
15
- var v = ({ dataUrl: t = e, data: n, locale: s = "nb-NO", open: c = !1, mobileBreakpoint: l = 768, className: v, onDataLoaded: y, onDataError: w, ref: E, strings: D, ...O }) => {
16
- let k = o(["header"], D).header, [A, j] = m("loading"), [M, N] = m(void 0), P = n ? "ready" : A, F = p(y), I = p(w);
17
- d(() => {
18
- F.current = y;
19
- }, [y]), d(() => {
20
- I.current = w;
21
- }, [w]);
22
- let L = p(null), R = u((e) => {
23
- L.current = e, typeof E == "function" ? E(e) : E && (E.current = e);
24
- }, [E]), z = a(L) < l;
25
- d(() => {
26
- n && F.current?.(n);
27
- }, [n]), d(() => {
28
- if (n) return;
17
+ var x = ({ dataUrl: n = e, data: r, locale: c = "nb-NO", open: l = !1, mobileBreakpoint: u = 768, className: x, onDataLoaded: S, onDataError: D, ref: k, strings: A, ...j }) => {
18
+ let M = s(["header"], A).header, N = p(d), [P, F] = _("loading"), [I, L] = _(void 0), R = r ? "ready" : P, z = g(S), B = g(D);
19
+ m(() => {
20
+ z.current = S;
21
+ }, [S]), m(() => {
22
+ B.current = D;
23
+ }, [D]);
24
+ let V = g(null), H = f((e) => {
25
+ V.current = e, typeof k == "function" ? k(e) : k && (k.current = e);
26
+ }, [k]), U = o(V) < u;
27
+ m(() => {
28
+ r && z.current?.(r);
29
+ }, [r]), m(() => {
30
+ if (r) return;
29
31
  let e = new AbortController();
30
- return r(t, e.signal).then((t) => {
31
- e.signal.aborted || (N(t), j("ready"), F.current?.(t));
32
+ return i(n, e.signal).then((t) => {
33
+ e.signal.aborted || (L(t), F("ready"), z.current?.(t));
32
34
  }).catch((e) => {
33
- e.name !== "AbortError" && (j("error"), I.current?.(e));
35
+ e.name !== "AbortError" && (F("error"), B.current?.(e));
34
36
  }), () => e.abort();
35
- }, [n, t]);
36
- let B = n ?? M, V = f(() => i(B, s), [B, s]), H = [
37
+ }, [r, n]);
38
+ let W = r ?? I, G = h(() => a(W, c), [W, c]), K = [
37
39
  "pkt-header-menu",
38
- c && "pkt-header-menu--open",
39
- v
40
+ l && "pkt-header-menu--open",
41
+ x
40
42
  ].filter(Boolean).join(" ");
41
- if (P === "loading") return /* @__PURE__ */ g("nav", {
42
- ...O,
43
- ref: R,
44
- className: H,
43
+ if (R === "loading") return /* @__PURE__ */ y("nav", {
44
+ ...j,
45
+ ref: H,
46
+ className: K,
45
47
  "aria-busy": "true",
46
- children: /* @__PURE__ */ g("p", {
48
+ children: /* @__PURE__ */ y("p", {
47
49
  className: "pkt-header-menu__loading",
48
- children: k.menuLoading
50
+ children: M.menuLoading
49
51
  })
50
52
  });
51
- if (P === "error" || !V) return /* @__PURE__ */ g("nav", {
52
- ...O,
53
- ref: R,
54
- className: H,
55
- "aria-hidden": !c,
56
- children: /* @__PURE__ */ g("p", {
53
+ if (R === "error" || !G) return /* @__PURE__ */ y("nav", {
54
+ ...j,
55
+ ref: H,
56
+ className: K,
57
+ "aria-hidden": !l,
58
+ children: /* @__PURE__ */ y("p", {
57
59
  className: "pkt-header-menu__error",
58
- children: k.menuLoadError
60
+ children: M.menuLoadError
59
61
  })
60
62
  });
61
- let { megamenu: U, i18n: W } = V, G = W?.navAriaLabel || "Hovedmeny";
62
- return /* @__PURE__ */ _("nav", {
63
- ...O,
64
- ref: R,
65
- className: H,
66
- "aria-label": G,
63
+ let { megamenu: q, i18n: J } = G, Y = t("header", "navAriaLabel", N, A) ?? (J?.navAriaLabel || M.navAriaLabel);
64
+ return /* @__PURE__ */ b("nav", {
65
+ ...j,
66
+ ref: H,
67
+ className: K,
68
+ "aria-label": Y,
67
69
  children: [
68
- z ? /* @__PURE__ */ g(b, {
69
- services: U.services,
70
- sections: U.sections
71
- }) : /* @__PURE__ */ _(h, { children: [
72
- /* @__PURE__ */ g(x, { services: U.services }),
73
- /* @__PURE__ */ g(S, {
74
- buttons: U.buttons,
70
+ U ? /* @__PURE__ */ y(C, {
71
+ services: q.services,
72
+ sections: q.sections
73
+ }) : /* @__PURE__ */ b(v, { children: [
74
+ /* @__PURE__ */ y(w, { services: q.services }),
75
+ /* @__PURE__ */ y(T, {
76
+ buttons: q.buttons,
75
77
  mobile: !1
76
78
  }),
77
- /* @__PURE__ */ g(C, { sections: U.sections })
79
+ /* @__PURE__ */ y(E, { sections: q.sections })
78
80
  ] }),
79
- /* @__PURE__ */ g(S, {
80
- buttons: U.buttons,
81
+ /* @__PURE__ */ y(T, {
82
+ buttons: q.buttons,
81
83
  mobile: !0
82
84
  }),
83
- /* @__PURE__ */ g(T, {
84
- links: U.links,
85
- some: U.some
85
+ /* @__PURE__ */ y(O, {
86
+ links: q.links,
87
+ some: q.some
86
88
  })
87
89
  ]
88
90
  });
89
- }, y = ({ services: e }) => /* @__PURE__ */ g("ul", {
91
+ }, S = ({ services: e }) => /* @__PURE__ */ y("ul", {
90
92
  className: "pkt-header-menu__services-list",
91
- children: e.links.map((e) => /* @__PURE__ */ g("li", {
93
+ children: e.links.map((e) => /* @__PURE__ */ y("li", {
92
94
  className: "pkt-header-menu__service",
93
- children: /* @__PURE__ */ _("a", {
95
+ children: /* @__PURE__ */ b("a", {
94
96
  className: "pkt-header-menu__service-link",
95
97
  href: e.url,
96
- children: [/* @__PURE__ */ g(l, {
98
+ children: [/* @__PURE__ */ y(u, {
97
99
  className: "pkt-header-menu__service-icon",
98
- name: n(e.icon),
100
+ name: r(e.icon),
99
101
  "aria-hidden": "true"
100
- }), /* @__PURE__ */ g("span", {
102
+ }), /* @__PURE__ */ y("span", {
101
103
  className: "pkt-header-menu__service-text",
102
104
  children: e.text
103
105
  })]
104
106
  })
105
107
  }, e.url))
106
- }), b = ({ services: e, sections: t }) => /* @__PURE__ */ g("div", {
108
+ }), C = ({ services: e, sections: t }) => /* @__PURE__ */ y("div", {
107
109
  className: "pkt-header-menu__sections",
108
- children: /* @__PURE__ */ _(s, {
110
+ children: /* @__PURE__ */ b(c, {
109
111
  className: "pkt-header-menu__sections-inner",
110
112
  skin: "plus-minus",
111
113
  name: "header-menu-accordion",
112
- children: [/* @__PURE__ */ g(c, {
114
+ children: [/* @__PURE__ */ y(l, {
113
115
  className: "pkt-header-menu__section",
114
116
  skin: "plus-minus",
115
117
  id: "pkt-header-menu-services",
116
118
  title: e.title,
117
- children: /* @__PURE__ */ g(y, { services: e })
118
- }), t.map((e, t) => /* @__PURE__ */ g(c, {
119
+ children: /* @__PURE__ */ y(S, { services: e })
120
+ }), t.map((e, t) => /* @__PURE__ */ y(l, {
119
121
  className: "pkt-header-menu__section",
120
122
  skin: "plus-minus",
121
123
  id: `pkt-header-menu-section-${t}`,
122
124
  title: e.title,
123
- children: /* @__PURE__ */ g(w, { links: e.links })
125
+ children: /* @__PURE__ */ y(D, { links: e.links })
124
126
  }, e.title))]
125
127
  })
126
- }), x = ({ services: e }) => /* @__PURE__ */ _("div", {
128
+ }), w = ({ services: e }) => /* @__PURE__ */ b("div", {
127
129
  className: "pkt-header-menu__services",
128
- children: [/* @__PURE__ */ g("h2", {
130
+ children: [/* @__PURE__ */ y("h2", {
129
131
  className: "pkt-header-menu__services-title",
130
132
  children: e.title
131
- }), /* @__PURE__ */ g(y, { services: e })]
132
- }), S = ({ buttons: e, mobile: t }) => {
133
+ }), /* @__PURE__ */ y(S, { services: e })]
134
+ }), T = ({ buttons: e, mobile: t }) => {
133
135
  if (!e || e.length === 0) return null;
134
- let r = ["pkt-header-menu__buttons", t && "pkt-header-menu__buttons--mobile"].filter(Boolean).join(" ");
135
- return /* @__PURE__ */ g("div", {
136
- className: r,
137
- children: e.map((e) => /* @__PURE__ */ _("a", {
136
+ let n = ["pkt-header-menu__buttons", t && "pkt-header-menu__buttons--mobile"].filter(Boolean).join(" ");
137
+ return /* @__PURE__ */ y("div", {
138
+ className: n,
139
+ children: e.map((e) => /* @__PURE__ */ b("a", {
138
140
  className: "pkt-btn pkt-btn--secondary pkt-btn--icon-right pkt-btn--small",
139
141
  href: e.url,
140
- children: [/* @__PURE__ */ g(l, {
142
+ children: [/* @__PURE__ */ y(u, {
141
143
  className: "pkt-btn__icon",
142
- name: e.iconName ? n(e.iconName) : "user",
144
+ name: e.iconName ? r(e.iconName) : "user",
143
145
  "aria-hidden": "true"
144
- }), /* @__PURE__ */ g("span", {
146
+ }), /* @__PURE__ */ y("span", {
145
147
  className: "pkt-btn__text",
146
148
  children: e.text
147
149
  })]
148
150
  }, e.url))
149
151
  });
150
- }, C = ({ sections: e }) => !e || e.length === 0 ? null : /* @__PURE__ */ g("div", {
152
+ }, E = ({ sections: e }) => !e || e.length === 0 ? null : /* @__PURE__ */ y("div", {
151
153
  className: "pkt-header-menu__sections",
152
- children: /* @__PURE__ */ g("div", {
154
+ children: /* @__PURE__ */ y("div", {
153
155
  className: "pkt-header-menu__sections-inner",
154
- children: e.map((e) => /* @__PURE__ */ _("div", {
156
+ children: e.map((e) => /* @__PURE__ */ b("div", {
155
157
  className: "pkt-header-menu__section",
156
- children: [/* @__PURE__ */ g("h2", {
158
+ children: [/* @__PURE__ */ y("h2", {
157
159
  className: "pkt-header-menu__section-title",
158
160
  children: e.title
159
- }), /* @__PURE__ */ g(w, { links: e.links })]
161
+ }), /* @__PURE__ */ y(D, { links: e.links })]
160
162
  }, e.title))
161
163
  })
162
- }), w = ({ links: e }) => /* @__PURE__ */ g("ul", {
164
+ }), D = ({ links: e }) => /* @__PURE__ */ y("ul", {
163
165
  className: "pkt-header-menu__section-list",
164
- children: e.map((e) => /* @__PURE__ */ g("li", { children: /* @__PURE__ */ g("a", {
166
+ children: e.map((e) => /* @__PURE__ */ y("li", { children: /* @__PURE__ */ y("a", {
165
167
  className: "pkt-header-menu__section-link",
166
168
  href: e.url,
167
169
  children: e.text
168
170
  }) }, e.url))
169
- }), T = ({ links: e, some: t }) => {
171
+ }), O = ({ links: e, some: t }) => {
170
172
  let n = e && e.length > 0, r = t && t.length > 0;
171
- return !n && !r ? null : /* @__PURE__ */ _("div", {
173
+ return !n && !r ? null : /* @__PURE__ */ b("div", {
172
174
  className: "pkt-header-menu__footer",
173
- children: [n && /* @__PURE__ */ g("ul", {
175
+ children: [n && /* @__PURE__ */ y("ul", {
174
176
  className: "pkt-header-menu__footer-list",
175
- children: e.map((e) => /* @__PURE__ */ g("li", { children: /* @__PURE__ */ g("a", {
177
+ children: e.map((e) => /* @__PURE__ */ y("li", { children: /* @__PURE__ */ y("a", {
176
178
  className: "pkt-header-menu__footer-link",
177
179
  href: e.url,
178
180
  children: e.text
179
181
  }) }, e.url))
180
- }), r && /* @__PURE__ */ g("ul", {
182
+ }), r && /* @__PURE__ */ y("ul", {
181
183
  className: "pkt-header-menu__footer-list pkt-header-menu__footer-list--social",
182
- children: t.map((e) => /* @__PURE__ */ g(E, { entry: e }, e.url))
184
+ children: t.map((e) => /* @__PURE__ */ y(k, { entry: e }, e.url))
183
185
  })]
184
186
  });
185
- }, E = ({ entry: e }) => {
186
- let n = t(e.url, e.text);
187
- return /* @__PURE__ */ g("li", { children: /* @__PURE__ */ g("a", {
187
+ }, k = ({ entry: e }) => {
188
+ let t = n(e.url, e.text);
189
+ return /* @__PURE__ */ y("li", { children: /* @__PURE__ */ y("a", {
188
190
  className: "pkt-header-menu__social-link",
189
191
  href: e.url,
190
192
  "aria-label": e.text,
191
- children: n ? /* @__PURE__ */ g(l, {
192
- name: n,
193
+ children: t ? /* @__PURE__ */ y(u, {
194
+ name: t,
193
195
  "aria-hidden": "true"
194
- }) : /* @__PURE__ */ g("span", { children: e.text })
196
+ }) : /* @__PURE__ */ y("span", { children: e.text })
195
197
  }) });
196
198
  };
197
- export { v as PktHeaderMenu };
199
+ export { x as PktHeaderMenu };
@@ -12,7 +12,7 @@ export type { IPktDatepicker } from './datepicker/Datepicker';
12
12
  export type { IPktFileUpload } from './fileupload/FileUpload';
13
13
  export type { IPktFooter } from './footer/Footer';
14
14
  export type { IPktFooterSimple } from './footerSimple/FooterSimple';
15
- export type { IPktHeader } from './header/Header';
15
+ export type { IPktHeader, IPktHeaderGlobal, IPktHeaderProps } from './header/Header';
16
16
  export type { IPktHeaderMenu } from './header-menu/HeaderMenu';
17
17
  export type { IPktHeaderService } from './header/HeaderService';
18
18
  export type { IPktInputWrapper } from './inputwrapper/InputWrapper';