@oslokommune/punkt-react 20.2.0 → 20.2.1

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
@@ -5,6 +5,22 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
5
5
 
6
6
  ---
7
7
 
8
+ ## [20.2.1](https://github.com/oslokommune/punkt/compare/20.2.0...20.2.1) (2026-11-17)
9
+
10
+ ### Bug Fixes
11
+ * Typesikre tabs-spec + piltastene finner alle faner (#3831). - Tabs og TabItem har spesifikasjon i TypeScript, med felles typer og
12
+ defaultverdier
13
+ - Piltastene kødder seg ikke lenger til når en fane fjernes eller
14
+ skjules
15
+ - arrow-nav, disable-arrow-nav og toggle-panels bruker booleanish
16
+
17
+ Har nå brukt `useDefault` sammen med `reflect` i Elements slik at
18
+ attributtene blir reflektert på elementet _kun_ når verdien ikke er
19
+ default.
20
+
21
+ ---
22
+
23
+
8
24
  ## [20.2.0](https://github.com/oslokommune/punkt/compare/20.1.7...20.2.0) (2026-11-17)
9
25
 
10
26
  ### Features
@@ -25,7 +25,8 @@ export type { IPktRadioButton } from './radio/RadioButton';
25
25
  export type { IPktRadioGroup } from './radiogroup/RadioGroup';
26
26
  export type { IPktStep } from './stepper/Step';
27
27
  export type { IPktStepper } from './stepper/Stepper';
28
- export type { IPktTab } from './tabs/Tabs';
28
+ export type { IPktTab, IPktTabs } from './tabs/Tabs';
29
+ export type { IPktTabItem } from './tabs/TabItem';
29
30
  export type { IPktTag } from './tag/Tag';
30
31
  export type { IPktTextarea } from './textarea/Textarea';
31
32
  export type { IPktTextinput } from './textinput/Textinput';
@@ -1,15 +1,7 @@
1
1
  import { MouseEvent, ReactNode } from 'react';
2
- import { TTagSkin } from '../../shared-types';
3
- export interface IPktTabItem {
2
+ import { IPktTabItemBase } from '../../shared-types';
3
+ export interface IPktTabItem extends IPktTabItemBase {
4
4
  children: ReactNode;
5
- active?: boolean;
6
- disabled?: boolean;
7
- href?: string;
8
5
  onClick?: (event: MouseEvent) => void;
9
- icon?: string;
10
- controls?: string;
11
- tag?: string;
12
- tagSkin?: TTagSkin;
13
- index?: number;
14
6
  }
15
7
  export declare const PktTabItem: import('react').ForwardRefExoticComponent<IPktTabItem & import('react').RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
@@ -1,79 +1,81 @@
1
1
  "use client";
2
- import { PktIcon as e } from "../icon/Icon.js";
3
- import { syncTabPanel as t, tabIdFor as n } from "../../shared-utils/tabs/panels.js";
4
- import { PktTag as r } from "../tag/Tag.js";
5
- import { useTabsContext as i } from "./Tabs.js";
6
- import { forwardRef as a, useEffect as o, useRef as s } from "react";
7
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
2
+ import { TAB_ITEM_DEFAULTS as e } from "../../shared-types/tabs.js";
3
+ import { PktIcon as t } from "../icon/Icon.js";
4
+ import "../../shared-types/index.js";
5
+ import { syncTabPanel as n, tabIdFor as r } from "../../shared-utils/tabs/panels.js";
6
+ import { PktTag as i } from "../tag/Tag.js";
7
+ import { useTabsContext as a } from "./Tabs.js";
8
+ import { forwardRef as o, useEffect as s, useRef as c } from "react";
9
+ import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
8
10
  // src/components/tabs/TabItem.tsx
9
- var d = a(({ children: a, active: d, disabled: f = !1, href: p, onClick: m, icon: h, controls: g, tag: _, tagSkin: v = "blue", index: y = 0 }, b) => {
10
- let { arrowNav: x, togglePanels: S, selectedIndex: C, setSelectedIndex: w, fallbackFocusIndex: T, reportTab: E, registerTabRef: D, handleKeyPress: O, selectTab: k } = i(), A = !f && (S && C !== null ? C === y : !!d), j = A || T === y, M = S && g ? n(g) : void 0, N = !x && A ? p ? "page" : "true" : void 0, P = s(null);
11
- o(() => {
12
- S && d && !f && w(y);
11
+ var f = o(({ children: o, active: f = e.active, disabled: p = e.disabled, href: m, onClick: h, icon: g, controls: _, tag: v, tagSkin: y = e.tagSkin, index: b = e.index }, x) => {
12
+ let { arrowNav: S, togglePanels: C, selectedIndex: w, setSelectedIndex: T, fallbackFocusIndex: E, reportTab: D, registerTabRef: O, handleKeyPress: k, selectTab: A } = a(), j = !p && (C && w !== null ? w === b : !!f), M = j || E === b, N = C && _ ? r(_) : void 0, P = !S && j ? m ? "page" : "true" : void 0, F = c(null);
13
+ s(() => {
14
+ C && f && !p && T(b);
13
15
  }, [
14
- S,
15
- d,
16
+ C,
16
17
  f,
17
- y,
18
- w
19
- ]), o(() => (E(y, {
20
- active: A,
21
- disabled: f
22
- }), () => E(y, null)), [
23
- y,
24
- A,
25
- f,
26
- E
27
- ]), o(() => {
28
- S && g && P.current && t(P.current, g, A, x);
18
+ p,
19
+ b,
20
+ T
21
+ ]), s(() => (D(b, {
22
+ active: j,
23
+ disabled: p
24
+ }), () => D(b, null)), [
25
+ b,
26
+ j,
27
+ p,
28
+ D
29
+ ]), s(() => {
30
+ C && _ && F.current && n(F.current, _, j, S);
29
31
  }, [
30
- S,
31
- g,
32
- A,
33
- x
32
+ C,
33
+ _,
34
+ j,
35
+ S
34
36
  ]);
35
- let F = {
36
- id: M,
37
- "aria-selected": x ? A : void 0,
38
- "aria-current": N,
39
- "aria-controls": g,
40
- role: x ? "tab" : void 0,
37
+ let I = {
38
+ id: N,
39
+ "aria-selected": S ? j : void 0,
40
+ "aria-current": P,
41
+ "aria-controls": _,
42
+ role: S ? "tab" : void 0,
41
43
  onKeyDown: (e) => {
42
- f && (e.key === "Enter" || e.key === " " || e.key === "Spacebar") ? (e.preventDefault(), e.stopPropagation()) : O(y, e);
44
+ p && (e.key === "Enter" || e.key === " " || e.key === "Spacebar") ? (e.preventDefault(), e.stopPropagation()) : k(b, e);
43
45
  },
44
46
  onClick: (e) => {
45
- f ? (e.preventDefault(), e.stopPropagation()) : (k(y), m?.(e));
47
+ p ? (e.preventDefault(), e.stopPropagation()) : (A(b), h?.(e));
46
48
  },
47
- tabIndex: f ? -1 : j || !x ? void 0 : -1,
49
+ tabIndex: p ? -1 : M || !S ? void 0 : -1,
48
50
  ref: (e) => {
49
- P.current = e, D(y, e, f), typeof b == "function" ? b(e) : b && (b.current = e);
51
+ F.current = e, O(b, e), typeof x == "function" ? x(e) : x && (x.current = e);
50
52
  }
51
- }, I = /* @__PURE__ */ u(c, { children: [
52
- h && /* @__PURE__ */ l(e, {
53
- name: h,
54
- className: `pkt-icon--small ${h === "check" ? "pkt-tabs__status-icon" : ""}`
53
+ }, L = /* @__PURE__ */ d(l, { children: [
54
+ g && /* @__PURE__ */ u(t, {
55
+ name: g,
56
+ className: `pkt-icon--small ${g === "check" ? "pkt-tabs__status-icon" : ""}`
55
57
  }),
56
- a,
57
- _ && /* @__PURE__ */ l(r, {
58
- skin: v,
58
+ o,
59
+ v && /* @__PURE__ */ u(i, {
60
+ skin: y,
59
61
  size: "small",
60
- children: _
62
+ children: v
61
63
  })
62
64
  ] });
63
- return p ? /* @__PURE__ */ l("a", {
64
- ...F,
65
- href: f ? void 0 : p,
66
- "aria-disabled": f || void 0,
67
- className: `pkt-tabs__link ${A ? "active" : ""} ${f ? "pkt-tabs__item--disabled" : ""}`,
68
- children: I
69
- }) : /* @__PURE__ */ l("button", {
70
- ...F,
65
+ return m ? /* @__PURE__ */ u("a", {
66
+ ...I,
67
+ href: p ? void 0 : m,
68
+ "aria-disabled": p || void 0,
69
+ className: `pkt-tabs__link ${j ? "active" : ""} ${p ? "pkt-tabs__item--disabled" : ""}`,
70
+ children: L
71
+ }) : /* @__PURE__ */ u("button", {
72
+ ...I,
71
73
  type: "button",
72
- disabled: f,
73
- "aria-disabled": f || void 0,
74
- className: `pkt-tabs__button pkt-link-button ${A ? "active" : ""} ${f ? "pkt-tabs__item--disabled" : ""}`,
75
- children: I
74
+ disabled: p,
75
+ "aria-disabled": p || void 0,
76
+ className: `pkt-tabs__button pkt-link-button ${j ? "active" : ""} ${p ? "pkt-tabs__item--disabled" : ""}`,
77
+ children: L
76
78
  });
77
79
  });
78
- d.displayName = "PktTabItem";
79
- export { d as PktTabItem };
80
+ f.displayName = "PktTabItem";
81
+ export { f as PktTabItem };
@@ -1,5 +1,5 @@
1
1
  import { KeyboardEvent, ReactNode } from 'react';
2
- import { TTagSkin } from '../../shared-types';
2
+ import { IPktTab, IPktTabsBase } from '../../shared-types';
3
3
  type TTabState = {
4
4
  active: boolean;
5
5
  disabled: boolean;
@@ -11,32 +11,13 @@ interface ITabsContext {
11
11
  setSelectedIndex: (index: number) => void;
12
12
  fallbackFocusIndex: number | null;
13
13
  reportTab: (index: number, state: TTabState | null) => void;
14
- registerTabRef: (index: number, el: HTMLAnchorElement | HTMLButtonElement | null, disabled?: boolean) => void;
14
+ registerTabRef: (index: number, el: HTMLAnchorElement | HTMLButtonElement | null) => void;
15
15
  handleKeyPress: (index: number, event: KeyboardEvent<HTMLAnchorElement | HTMLButtonElement>) => void;
16
16
  selectTab: (index: number) => void;
17
17
  }
18
18
  export declare const useTabsContext: () => ITabsContext;
19
- export interface IPktTab {
20
- text: string;
21
- href?: string;
22
- action?: (index: number) => void;
23
- disabled?: boolean;
24
- icon?: string;
25
- controls?: string;
26
- tag?: {
27
- text: string;
28
- skin: TTagSkin | undefined;
29
- };
30
- active?: boolean;
31
- }
32
- export interface IPktTabs {
33
- arrowNav?: boolean;
34
- disableArrowNav?: boolean;
35
- separatorIconName?: string;
36
- separatorIconPath?: string;
37
- togglePanels?: boolean;
38
- ariaLabel?: string;
39
- ariaLabelledBy?: string;
19
+ export type { IPktTab };
20
+ export interface IPktTabs extends IPktTabsBase {
40
21
  tabs?: IPktTab[];
41
22
  onTabSelected?: (index: number) => void;
42
23
  children?: ReactNode;
@@ -1,41 +1,36 @@
1
1
  "use client";
2
- import { tabIndexForKey as e } from "../../shared-utils/tabs/keyboard.js";
3
- import { PktIcon as t } from "../icon/Icon.js";
4
- import { PktTabItem as n } from "./TabItem.js";
5
- import { withStableKeys as r } from "../../utils/stableKeys.js";
6
- import { Children as i, createContext as a, forwardRef as o, useCallback as s, useContext as c, useEffect as l, useRef as u, useState as d } from "react";
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 = a(null), m = () => {
10
- let e = c(p);
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 = o(({ arrowNav: a = !0, disableArrowNav: o = !1, separatorIconName: c, separatorIconPath: m, togglePanels: h = !1, ariaLabel: g, ariaLabelledBy: _, tabs: v, onTabSelected: y, children: b }, x) => {
14
- let S = u([]), C = u({}), [w, T] = d(null), [E, D] = d(null), O = s((e, t) => {
15
- D((n) => {
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
- }, []), k = E && !Object.values(E).some((e) => e.active) ? Object.keys(E).map(Number).filter((e) => !E[e].disabled).sort((e, t) => e - t)[0] ?? null : null, A = a && !o, j = i.toArray(b), M = j.length > 0, N = M ? j.length : v?.length || 0, P = !!(c || m);
22
- l(() => {
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 && T(e);
32
- }, L = (t, n) => {
33
- if (!A) return;
34
- let r = e(n.key, t, N, F);
35
- r === null ? (n.key === "Enter" || n.key === " " || n.key === "Spacebar" || n.key === "ArrowDown") && (n.preventDefault(), F(t) || I(t)) : (n.preventDefault(), S.current[r]?.focus(), h && r !== t && I(r));
36
- }, R = (e, t, n = !1) => {
37
- S.current[e] = t, C.current[e] = n;
38
- }, z = (e) => /* @__PURE__ */ f("span", {
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
- }) : c ? /* @__PURE__ */ f(t, {
47
- name: c,
41
+ }) : l ? /* @__PURE__ */ f(n, {
42
+ name: l,
48
43
  className: "pkt-tabs__separator-icon"
49
44
  }) : null
50
- }, e), B = (e) => !P || e.length <= 1 ? e : e.flatMap((t, n) => n < e.length - 1 ? [t, z(`separator-${n}`)] : [t]), V = r(v ?? [], (e) => `${e.href ?? ""}|${e.text}`).map(({ item: e, key: t }, r) => /* @__PURE__ */ f(n, {
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: r,
53
+ index: n,
59
54
  children: e.text
60
- }, t)), H = ["pkt-tabs", P && "pkt-tabs--with-separator"].filter(Boolean).join(" "), U = B(M ? j : V || []);
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: A,
58
+ arrowNav: k,
64
59
  togglePanels: h,
65
- selectedIndex: w,
66
- setSelectedIndex: T,
67
- fallbackFocusIndex: k,
68
- reportTab: O,
69
- registerTabRef: R,
70
- handleKeyPress: L,
71
- selectTab: I
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: H,
69
+ className: V,
75
70
  ref: x,
76
71
  children: /* @__PURE__ */ f("div", {
77
72
  className: "pkt-tabs__list",
78
- role: A ? "tablist" : "navigation",
73
+ role: k ? "tablist" : "navigation",
79
74
  "aria-label": g || void 0,
80
75
  "aria-labelledby": _ || void 0,
81
- children: U
76
+ children: H
82
77
  })
83
78
  })
84
79
  });