@oslokommune/punkt-react 16.10.0 → 16.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "16.10.0",
3
+ "version": "16.11.1",
4
4
  "description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo Origo",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@lit-labs/ssr-dom-shim": "^1.2.1",
41
41
  "@lit/react": "^1.0.7",
42
- "@oslokommune/punkt-elements": "^16.10.0",
42
+ "@oslokommune/punkt-elements": "^16.11.0",
43
43
  "classnames": "^2.5.1",
44
44
  "prettier": "^3.3.3",
45
45
  "react-hook-form": "^7.53.0"
@@ -50,7 +50,7 @@
50
50
  "@eslint/eslintrc": "^3.3.3",
51
51
  "@eslint/js": "^9.37.0",
52
52
  "@oslokommune/punkt-assets": "^16.0.0",
53
- "@oslokommune/punkt-css": "^16.10.0",
53
+ "@oslokommune/punkt-css": "^16.11.1",
54
54
  "@testing-library/jest-dom": "^6.5.0",
55
55
  "@testing-library/react": "^16.0.1",
56
56
  "@testing-library/user-event": "^14.5.2",
@@ -109,5 +109,5 @@
109
109
  "url": "https://github.com/oslokommune/punkt/issues"
110
110
  },
111
111
  "license": "MIT",
112
- "gitHead": "7d339c3bc11d0da4291536496aebb6761dd519cb"
112
+ "gitHead": "c0da9ee95130ddfec70981101500f84217b031d6"
113
113
  }
@@ -65,7 +65,7 @@ export const PktTabItem = forwardRef<HTMLAnchorElement | HTMLButtonElement, IPkt
65
65
 
66
66
  const content = (
67
67
  <>
68
- {icon && <PktIcon name={icon} className="pkt-icon--small" />}
68
+ {icon && <PktIcon name={icon} className={`pkt-icon--small ${icon === 'check' ? 'pkt-tabs__status-icon' : ''}`} />}
69
69
  {children}
70
70
  {tag && (
71
71
  <PktTag skin={tagSkin} size="small">
@@ -56,6 +56,45 @@ describe('Tabs component', () => {
56
56
  expect(results).toHaveNoViolations()
57
57
  })
58
58
  })
59
+
60
+ describe('separators', () => {
61
+ it('applies separator class on tabs root when separator icon is provided', () => {
62
+ const { container } = render(<PktTabs tabs={tabs} separatorIconName="arrow-right" />)
63
+ expect(container.querySelector('.pkt-tabs')).toHaveClass('pkt-tabs--with-separator')
64
+ })
65
+
66
+ it('keeps tab semantics when separators are enabled', () => {
67
+ const { getByText, container } = render(<PktTabs tabs={tabs} separatorIconName="arrow-right" />)
68
+ const tabList = container.querySelector('.pkt-tabs__list')
69
+
70
+ expect(tabList).toHaveAttribute('role', 'tablist')
71
+ expect(getByText('Tab 1')).toHaveAttribute('role', 'tab')
72
+ expect(getByText('Tab 2')).toHaveAttribute('role', 'tab')
73
+ })
74
+
75
+ it('renders decorative separators in DOM', () => {
76
+ const { container } = render(
77
+ <PktTabs separatorIconName="arrow-right">
78
+ <PktTabItem index={0}>First</PktTabItem>
79
+ <PktTabItem index={1} disabled>
80
+ Second
81
+ </PktTabItem>
82
+ <PktTabItem index={2}>Third</PktTabItem>
83
+ </PktTabs>,
84
+ )
85
+
86
+ expect(container.querySelectorAll('.pkt-tabs__separator')).toHaveLength(2)
87
+ expect(container.querySelectorAll('.pkt-tabs__button, .pkt-tabs__link')).toHaveLength(3)
88
+ })
89
+
90
+ it('prefers separatorIconPath over separatorIconName', () => {
91
+ const { container } = render(
92
+ <PktTabs tabs={tabs} separatorIconName="arrow-right" separatorIconPath="/custom.svg" />,
93
+ )
94
+ const separatorImage = container.querySelector('.pkt-tabs__separator img')
95
+ expect(separatorImage).toHaveAttribute('src', '/custom.svg')
96
+ })
97
+ })
59
98
  })
60
99
 
61
100
  describe('PktTabItem children format', () => {
@@ -12,6 +12,7 @@ import {
12
12
  useRef,
13
13
  } from 'react'
14
14
 
15
+ import { PktIcon } from '../icon/Icon'
15
16
  import { PktTabItem } from './TabItem'
16
17
 
17
18
  export type TSkin = 'blue' | 'green' | 'red' | 'beige' | 'yellow' | 'grey' | 'gray' | 'blue-light'
@@ -55,6 +56,8 @@ export interface IPktTab {
55
56
  export interface IPktTabs {
56
57
  arrowNav?: boolean
57
58
  disableArrowNav?: boolean
59
+ separatorIconName?: string
60
+ separatorIconPath?: string
58
61
  tabs?: IPktTab[]
59
62
  onTabSelected?: (index: number) => void
60
63
  children?: ReactNode
@@ -62,7 +65,15 @@ export interface IPktTabs {
62
65
 
63
66
  export const PktTabs = forwardRef(
64
67
  (
65
- { arrowNav = true, disableArrowNav = false, tabs, onTabSelected, children }: IPktTabs,
68
+ {
69
+ arrowNav = true,
70
+ disableArrowNav = false,
71
+ separatorIconName,
72
+ separatorIconPath,
73
+ tabs,
74
+ onTabSelected,
75
+ children,
76
+ }: IPktTabs,
66
77
  ref: Ref<HTMLDivElement>,
67
78
  ): JSX.Element => {
68
79
  const tabRefs = useRef<Array<HTMLAnchorElement | HTMLButtonElement | null>>([])
@@ -71,8 +82,10 @@ export const PktTabs = forwardRef(
71
82
  const useArrowNav = arrowNav && !disableArrowNav
72
83
 
73
84
  // Determine if we're using children or tabs array
74
- const hasChildren = children && Children.count(children) > 0
75
- const tabCount = hasChildren ? Children.count(children) : tabs?.length || 0
85
+ const childItems = Children.toArray(children)
86
+ const hasChildren = childItems.length > 0
87
+ const tabCount = hasChildren ? childItems.length : tabs?.length || 0
88
+ const hasSeparator = !!(separatorIconName || separatorIconPath)
76
89
 
77
90
  useEffect(() => {
78
91
  tabRefs.current = tabRefs.current.slice(0, tabCount)
@@ -139,7 +152,23 @@ export const PktTabs = forwardRef(
139
152
  disabledMap.current[index] = disabled
140
153
  }
141
154
 
142
- // If tabs as prop instead of children
155
+ const renderSeparator = (key: string) => (
156
+ <span className="pkt-tabs__separator" aria-hidden="true" role="presentation" key={key}>
157
+ {separatorIconPath ? (
158
+ <img src={separatorIconPath} alt="" aria-hidden="true" />
159
+ ) : separatorIconName ? (
160
+ <PktIcon name={separatorIconName} className="pkt-tabs__separator-icon" />
161
+ ) : null}
162
+ </span>
163
+ )
164
+
165
+ const withSeparators = (items: ReactNode[]) => {
166
+ if (!hasSeparator || items.length <= 1) return items
167
+ return items.flatMap((item, index) =>
168
+ index < items.length - 1 ? [item, renderSeparator(`separator-${index}`)] : [item],
169
+ )
170
+ }
171
+
143
172
  const tabItems = tabs?.map((tab, index) => (
144
173
  <PktTabItem
145
174
  key={index}
@@ -156,11 +185,14 @@ export const PktTabs = forwardRef(
156
185
  </PktTabItem>
157
186
  ))
158
187
 
188
+ const tabsClasses = ['pkt-tabs', hasSeparator && 'pkt-tabs--with-separator'].filter(Boolean).join(' ')
189
+ const renderedTabs = withSeparators((hasChildren ? childItems : tabItems || []) as ReactNode[])
190
+
159
191
  return (
160
192
  <TabsContext.Provider value={{ arrowNav: useArrowNav, registerTabRef, handleKeyPress, selectTab }}>
161
- <div className="pkt-tabs" ref={ref}>
193
+ <div className={tabsClasses} ref={ref}>
162
194
  <div className="pkt-tabs__list" role={useArrowNav ? 'tablist' : 'navigation'}>
163
- {children || tabItems}
195
+ {renderedTabs}
164
196
  </div>
165
197
  </div>
166
198
  </TabsContext.Provider>