@oslokommune/punkt-react 20.2.0 → 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.
- package/CHANGELOG.md +21 -0
- package/dist/components/header/HeaderGlobal.js +148 -146
- package/dist/components/header/HeaderService.js +2 -2
- package/dist/components/header/types.d.ts +26 -93
- package/dist/components/header-menu/HeaderMenu.js +108 -106
- package/dist/components/interfaces.d.ts +3 -2
- package/dist/components/tabs/TabItem.d.ts +2 -10
- package/dist/components/tabs/TabItem.js +62 -60
- package/dist/components/tabs/Tabs.d.ts +4 -23
- package/dist/components/tabs/Tabs.js +38 -43
- package/dist/punkt-react.cjs +1 -1
- package/dist/shared-strings/index.d.ts +1 -1
- package/dist/shared-strings/nb.d.ts +1 -0
- package/dist/shared-strings/nb.js +2 -1
- package/dist/shared-strings/resolve.d.ts +9 -0
- package/dist/shared-strings/resolve.js +9 -1
- package/dist/shared-types/header-footer.d.ts +0 -44
- package/dist/shared-types/header.d.ts +214 -10
- package/dist/shared-types/header.js +26 -0
- package/dist/shared-types/index.d.ts +5 -3
- package/dist/shared-types/index.js +24 -22
- package/dist/shared-types/tabs.d.ts +66 -0
- package/dist/shared-types/tabs.js +12 -0
- package/package.json +2 -2
- package/src/components/header/HeaderGlobal.test.tsx +82 -0
- package/src/components/header/HeaderGlobal.tsx +35 -16
- package/src/components/header/HeaderService.tsx +12 -12
- package/src/components/header/types.ts +37 -97
- package/src/components/header-menu/HeaderMenu.test.tsx +14 -0
- package/src/components/header-menu/HeaderMenu.tsx +7 -2
- package/src/components/interfaces.ts +3 -2
- package/src/components/tabs/TabItem.tsx +18 -12
- package/src/components/tabs/Tabs.test.tsx +22 -0
- package/src/components/tabs/Tabs.tsx +10 -43
|
@@ -1,41 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { TABS_DEFAULTS as e } from "../../shared-types/tabs.js";
|
|
3
|
+
import "../../shared-types/index.js";
|
|
4
|
+
import { tabIndexForKey as t } from "../../shared-utils/tabs/keyboard.js";
|
|
5
|
+
import { PktIcon as n } from "../icon/Icon.js";
|
|
6
|
+
import { PktTabItem as r } from "./TabItem.js";
|
|
7
|
+
import { withStableKeys as i } from "../../utils/stableKeys.js";
|
|
8
|
+
import { Children as a, createContext as o, forwardRef as s, useCallback as c, useContext as l, useRef as u, useState as d } from "react";
|
|
7
9
|
import { jsx as f } from "react/jsx-runtime";
|
|
8
10
|
// src/components/tabs/Tabs.tsx
|
|
9
|
-
var p =
|
|
10
|
-
let e =
|
|
11
|
+
var p = o(null), m = () => {
|
|
12
|
+
let e = l(p);
|
|
11
13
|
if (!e) throw Error("TabItem must be used within a Tabs component");
|
|
12
14
|
return e;
|
|
13
|
-
}, h =
|
|
14
|
-
let S = u([]), C
|
|
15
|
-
|
|
15
|
+
}, h = s(({ arrowNav: o = e.arrowNav, disableArrowNav: s = e.disableArrowNav, separatorIconName: l, separatorIconPath: m, togglePanels: h = e.togglePanels, ariaLabel: g, ariaLabelledBy: _, tabs: v, onTabSelected: y, children: b }, x) => {
|
|
16
|
+
let S = u([]), [C, w] = d(null), [T, E] = d(null), D = c((e, t) => {
|
|
17
|
+
E((n) => {
|
|
16
18
|
let r = n?.[e];
|
|
17
19
|
if (t ? r?.active === t.active && r?.disabled === t.disabled : !r) return n;
|
|
18
20
|
let i = { ...n };
|
|
19
21
|
return t ? i[e] = t : delete i[e], i;
|
|
20
22
|
});
|
|
21
|
-
}, []),
|
|
22
|
-
|
|
23
|
-
S.current = S.current.slice(0, N), Object.keys(C.current).forEach((e) => {
|
|
24
|
-
let t = Number(e);
|
|
25
|
-
t >= N && delete C.current[t];
|
|
26
|
-
});
|
|
27
|
-
}, [N]);
|
|
28
|
-
let F = (e) => v ? !!v[e]?.disabled : !!C.current[e], I = (e) => {
|
|
29
|
-
if (F(e)) return;
|
|
23
|
+
}, []), O = T && !Object.values(T).some((e) => e.active) ? Object.keys(T).map(Number).filter((e) => !T[e].disabled).sort((e, t) => e - t)[0] ?? null : null, k = o && !s, A = a.toArray(b), j = A.length > 0, M = T ? Math.max(0, ...Object.keys(T).map((e) => Number(e) + 1)) : 0, N = !!(l || m), P = (e) => !T?.[e] || T[e].disabled, F = (e) => {
|
|
24
|
+
if (P(e)) return;
|
|
30
25
|
let t = v?.[e];
|
|
31
|
-
t?.action && t.action(e), y && y(e), h &&
|
|
32
|
-
},
|
|
33
|
-
if (!
|
|
34
|
-
let r =
|
|
35
|
-
r === null ? (n.key === "Enter" || n.key === " " || n.key === "Spacebar" || n.key === "ArrowDown") && (n.preventDefault(),
|
|
36
|
-
},
|
|
37
|
-
S.current[e] = t
|
|
38
|
-
},
|
|
26
|
+
t?.action && t.action(e), y && y(e), h && w(e);
|
|
27
|
+
}, I = (e, n) => {
|
|
28
|
+
if (!k) return;
|
|
29
|
+
let r = t(n.key, e, M, P);
|
|
30
|
+
r === null ? (n.key === "Enter" || n.key === " " || n.key === "Spacebar" || n.key === "ArrowDown") && (n.preventDefault(), P(e) || F(e)) : (n.preventDefault(), S.current[r]?.focus(), h && r !== e && F(r));
|
|
31
|
+
}, L = (e, t) => {
|
|
32
|
+
S.current[e] = t;
|
|
33
|
+
}, R = (e) => /* @__PURE__ */ f("span", {
|
|
39
34
|
className: "pkt-tabs__separator",
|
|
40
35
|
"aria-hidden": "true",
|
|
41
36
|
role: "presentation",
|
|
@@ -43,11 +38,11 @@ var p = a(null), m = () => {
|
|
|
43
38
|
src: m,
|
|
44
39
|
alt: "",
|
|
45
40
|
"aria-hidden": "true"
|
|
46
|
-
}) :
|
|
47
|
-
name:
|
|
41
|
+
}) : l ? /* @__PURE__ */ f(n, {
|
|
42
|
+
name: l,
|
|
48
43
|
className: "pkt-tabs__separator-icon"
|
|
49
44
|
}) : null
|
|
50
|
-
}, e),
|
|
45
|
+
}, e), z = (e) => !N || e.length <= 1 ? e : e.flatMap((t, n) => n < e.length - 1 ? [t, R(`separator-${n}`)] : [t]), B = i(v ?? [], (e) => `${e.href ?? ""}|${e.text}`).map(({ item: e, key: t }, n) => /* @__PURE__ */ f(r, {
|
|
51
46
|
active: !e.disabled && e.active,
|
|
52
47
|
disabled: e.disabled,
|
|
53
48
|
href: e.href,
|
|
@@ -55,30 +50,30 @@ var p = a(null), m = () => {
|
|
|
55
50
|
controls: e.controls,
|
|
56
51
|
tag: e.tag?.text,
|
|
57
52
|
tagSkin: e.tag?.skin,
|
|
58
|
-
index:
|
|
53
|
+
index: n,
|
|
59
54
|
children: e.text
|
|
60
|
-
}, t)),
|
|
55
|
+
}, t)), V = ["pkt-tabs", N && "pkt-tabs--with-separator"].filter(Boolean).join(" "), H = z(j ? A : B || []);
|
|
61
56
|
return /* @__PURE__ */ f(p.Provider, {
|
|
62
57
|
value: {
|
|
63
|
-
arrowNav:
|
|
58
|
+
arrowNav: k,
|
|
64
59
|
togglePanels: h,
|
|
65
|
-
selectedIndex:
|
|
66
|
-
setSelectedIndex:
|
|
67
|
-
fallbackFocusIndex:
|
|
68
|
-
reportTab:
|
|
69
|
-
registerTabRef:
|
|
70
|
-
handleKeyPress:
|
|
71
|
-
selectTab:
|
|
60
|
+
selectedIndex: C,
|
|
61
|
+
setSelectedIndex: w,
|
|
62
|
+
fallbackFocusIndex: O,
|
|
63
|
+
reportTab: D,
|
|
64
|
+
registerTabRef: L,
|
|
65
|
+
handleKeyPress: I,
|
|
66
|
+
selectTab: F
|
|
72
67
|
},
|
|
73
68
|
children: /* @__PURE__ */ f("div", {
|
|
74
|
-
className:
|
|
69
|
+
className: V,
|
|
75
70
|
ref: x,
|
|
76
71
|
children: /* @__PURE__ */ f("div", {
|
|
77
72
|
className: "pkt-tabs__list",
|
|
78
|
-
role:
|
|
73
|
+
role: k ? "tablist" : "navigation",
|
|
79
74
|
"aria-label": g || void 0,
|
|
80
75
|
"aria-labelledby": _ || void 0,
|
|
81
|
-
children:
|
|
76
|
+
children: H
|
|
82
77
|
})
|
|
83
78
|
})
|
|
84
79
|
});
|