@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
|
@@ -10,12 +10,11 @@ import {
|
|
|
10
10
|
Ref,
|
|
11
11
|
useCallback,
|
|
12
12
|
useContext,
|
|
13
|
-
useEffect,
|
|
14
13
|
useRef,
|
|
15
14
|
useState,
|
|
16
15
|
} from 'react'
|
|
17
16
|
|
|
18
|
-
import type
|
|
17
|
+
import { TABS_DEFAULTS, type IPktTab, type IPktTabsBase } from 'shared-types'
|
|
19
18
|
import { tabIndexForKey } from 'shared-utils/tabs/keyboard'
|
|
20
19
|
|
|
21
20
|
import { PktIcon } from '../icon/Icon'
|
|
@@ -32,7 +31,7 @@ interface ITabsContext {
|
|
|
32
31
|
setSelectedIndex: (index: number) => void
|
|
33
32
|
fallbackFocusIndex: number | null
|
|
34
33
|
reportTab: (index: number, state: TTabState | null) => void
|
|
35
|
-
registerTabRef: (index: number, el: HTMLAnchorElement | HTMLButtonElement | null
|
|
34
|
+
registerTabRef: (index: number, el: HTMLAnchorElement | HTMLButtonElement | null) => void
|
|
36
35
|
handleKeyPress: (index: number, event: KeyboardEvent<HTMLAnchorElement | HTMLButtonElement>) => void
|
|
37
36
|
selectTab: (index: number) => void
|
|
38
37
|
}
|
|
@@ -47,28 +46,9 @@ export const useTabsContext = () => {
|
|
|
47
46
|
return context
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
export
|
|
51
|
-
text: string
|
|
52
|
-
href?: string
|
|
53
|
-
action?: (index: number) => void
|
|
54
|
-
disabled?: boolean
|
|
55
|
-
icon?: string
|
|
56
|
-
controls?: string
|
|
57
|
-
tag?: {
|
|
58
|
-
text: string
|
|
59
|
-
skin: TTagSkin | undefined
|
|
60
|
-
}
|
|
61
|
-
active?: boolean
|
|
62
|
-
}
|
|
49
|
+
export type { IPktTab }
|
|
63
50
|
|
|
64
|
-
export interface IPktTabs {
|
|
65
|
-
arrowNav?: boolean
|
|
66
|
-
disableArrowNav?: boolean
|
|
67
|
-
separatorIconName?: string
|
|
68
|
-
separatorIconPath?: string
|
|
69
|
-
togglePanels?: boolean
|
|
70
|
-
ariaLabel?: string
|
|
71
|
-
ariaLabelledBy?: string
|
|
51
|
+
export interface IPktTabs extends IPktTabsBase {
|
|
72
52
|
tabs?: IPktTab[]
|
|
73
53
|
onTabSelected?: (index: number) => void
|
|
74
54
|
children?: ReactNode
|
|
@@ -77,11 +57,11 @@ export interface IPktTabs {
|
|
|
77
57
|
export const PktTabs = forwardRef(
|
|
78
58
|
(
|
|
79
59
|
{
|
|
80
|
-
arrowNav =
|
|
81
|
-
disableArrowNav =
|
|
60
|
+
arrowNav = TABS_DEFAULTS.arrowNav,
|
|
61
|
+
disableArrowNav = TABS_DEFAULTS.disableArrowNav,
|
|
82
62
|
separatorIconName,
|
|
83
63
|
separatorIconPath,
|
|
84
|
-
togglePanels =
|
|
64
|
+
togglePanels = TABS_DEFAULTS.togglePanels,
|
|
85
65
|
ariaLabel,
|
|
86
66
|
ariaLabelledBy,
|
|
87
67
|
tabs,
|
|
@@ -91,7 +71,6 @@ export const PktTabs = forwardRef(
|
|
|
91
71
|
ref: Ref<HTMLDivElement>,
|
|
92
72
|
): JSX.Element => {
|
|
93
73
|
const tabElementsRef = useRef<Array<HTMLAnchorElement | HTMLButtonElement | null>>([])
|
|
94
|
-
const disabledMapRef = useRef<Record<number, boolean>>({})
|
|
95
74
|
const [selectedIndex, setSelectedIndex] = useState<number | null>(null)
|
|
96
75
|
const [tabStates, setTabStates] = useState<Record<number, TTabState> | null>(null)
|
|
97
76
|
|
|
@@ -121,21 +100,10 @@ export const PktTabs = forwardRef(
|
|
|
121
100
|
// eslint-disable-next-line @eslint-react/no-children-to-array
|
|
122
101
|
const childItems = Children.toArray(children)
|
|
123
102
|
const hasChildren = childItems.length > 0
|
|
124
|
-
const tabCount =
|
|
103
|
+
const tabCount = tabStates ? Math.max(0, ...Object.keys(tabStates).map((key) => Number(key) + 1)) : 0
|
|
125
104
|
const hasSeparator = !!(separatorIconName || separatorIconPath)
|
|
126
105
|
|
|
127
|
-
|
|
128
|
-
tabElementsRef.current = tabElementsRef.current.slice(0, tabCount)
|
|
129
|
-
Object.keys(disabledMapRef.current).forEach((key) => {
|
|
130
|
-
const index = Number(key)
|
|
131
|
-
if (index >= tabCount) delete disabledMapRef.current[index]
|
|
132
|
-
})
|
|
133
|
-
}, [tabCount])
|
|
134
|
-
|
|
135
|
-
const isTabDisabled = (index: number): boolean => {
|
|
136
|
-
if (tabs) return !!tabs[index]?.disabled
|
|
137
|
-
return !!disabledMapRef.current[index]
|
|
138
|
-
}
|
|
106
|
+
const isTabDisabled = (index: number): boolean => !tabStates?.[index] || tabStates[index].disabled
|
|
139
107
|
|
|
140
108
|
const selectTab = (index: number): void => {
|
|
141
109
|
if (isTabDisabled(index)) return
|
|
@@ -166,9 +134,8 @@ export const PktTabs = forwardRef(
|
|
|
166
134
|
}
|
|
167
135
|
}
|
|
168
136
|
|
|
169
|
-
const registerTabRef = (index: number, el: HTMLAnchorElement | HTMLButtonElement | null
|
|
137
|
+
const registerTabRef = (index: number, el: HTMLAnchorElement | HTMLButtonElement | null) => {
|
|
170
138
|
tabElementsRef.current[index] = el
|
|
171
|
-
disabledMapRef.current[index] = disabled
|
|
172
139
|
}
|
|
173
140
|
|
|
174
141
|
const renderSeparator = (key: string) => (
|