@oslokommune/punkt-react 18.9.5 → 18.9.7

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.
@@ -80,6 +80,16 @@ export declare const nb: {
80
80
  menu: string;
81
81
  openMenu: string;
82
82
  openSearch: string;
83
+ logoLabel: string;
84
+ logoAlt: string;
85
+ logOut: string;
86
+ userMenuButton: string;
87
+ userMenuLabel: string;
88
+ loggedInAs: string;
89
+ lastLoggedIn: string;
90
+ representing: string;
91
+ orgNumber: string;
92
+ changeRepresentation: string;
83
93
  };
84
94
  listbox: {
85
95
  searchLabel: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "18.9.5",
3
+ "version": "18.9.7",
4
4
  "description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo kommune",
@@ -40,7 +40,7 @@
40
40
  "@eslint/eslintrc": "^3.3.5",
41
41
  "@eslint/js": "^10.0.1",
42
42
  "@oslokommune/punkt-assets": "^18.9.1",
43
- "@oslokommune/punkt-css": "^18.9.4",
43
+ "@oslokommune/punkt-css": "^18.9.6",
44
44
  "@testing-library/jest-dom": "^6.9.1",
45
45
  "@testing-library/react": "^16.3.2",
46
46
  "@testing-library/user-event": "^14.6.1",
@@ -100,5 +100,5 @@
100
100
  "url": "https://github.com/oslokommune/punkt/issues"
101
101
  },
102
102
  "license": "MIT",
103
- "gitHead": "a8572816da5d735db6c6759d812458853f8717bc"
103
+ "gitHead": "0e5e542f79f46e2d0419e8918ffb0aff8a9c9ba6"
104
104
  }
@@ -203,10 +203,18 @@ describe('PktHeaderGlobal', () => {
203
203
 
204
204
  test('logo lenker til www.oslo.kommune.no når logoLink er satt', () => {
205
205
  renderGlobal({ logoLink: 'https://www.oslo.kommune.no' })
206
- const logoLink = screen.getByRole('link', { name: 'Til hovedsiden' })
206
+ const logoLink = screen.getByRole('link', { name: 'Til Oslo kommunes hovednettsted' })
207
207
  expect(logoLink).toHaveAttribute('href', 'https://www.oslo.kommune.no')
208
208
  })
209
209
 
210
+ test('rendrer logoen uten lenke når logoLink er tom', () => {
211
+ const { container } = renderGlobal({ logoLink: '' })
212
+ const logo = container.querySelector('.pkt-header-global__logo')
213
+ expect(logo?.querySelector('a')).not.toBeInTheDocument()
214
+ expect(logo).toHaveAttribute('role', 'img')
215
+ expect(logo).toHaveAttribute('aria-label', 'Oslo kommune')
216
+ })
217
+
210
218
  test('skjuler kontaktlenken når bruker er innlogget', () => {
211
219
  const { container } = renderGlobal({ ...DESKTOP, user: { name: 'Aksel Web Opdahl' } })
212
220
  expect(container.querySelector('.pkt-header-global__contact')).not.toBeInTheDocument()
@@ -282,11 +282,17 @@ export const PktHeaderGlobal = forwardRef(
282
282
  ref={setHeaderRef}
283
283
  >
284
284
  <div className="pkt-header-global__logo-area">
285
- <span className="pkt-header-global__logo">
286
- <a href={logoLink} aria-label="Til hovedsiden" onClick={logoClick}>
285
+ {logoLink ? (
286
+ <span className="pkt-header-global__logo">
287
+ <a href={logoLink} aria-label={headerStrings.logoLabel} onClick={logoClick}>
288
+ <PktIcon name="oslologo" aria-hidden="true" path={logoPath} />
289
+ </a>
290
+ </span>
291
+ ) : (
292
+ <span className="pkt-header-global__logo" role="img" aria-label={headerStrings.logoAlt}>
287
293
  <PktIcon name="oslologo" aria-hidden="true" path={logoPath} />
288
- </a>
289
- </span>
294
+ </span>
295
+ )}
290
296
  </div>
291
297
 
292
298
  <div className="pkt-header-global__content">
@@ -371,12 +377,13 @@ export const PktHeaderGlobal = forwardRef(
371
377
  secondIconName={isUserOpen ? 'chevron-thin-up' : 'chevron-thin-down'}
372
378
  onClick={() => handleMenuToggle('user')}
373
379
  >
374
- <span className="pkt-sr-only">Brukermeny: </span>
380
+ <span className="pkt-sr-only">{headerStrings.userMenuButton} </span>
375
381
  <span translate="no">{representing?.name || user.name}</span>
376
382
  </PktButton>
377
383
  {isUserOpen && (
378
384
  <div className="pkt-header-global__user-menu is-open">
379
385
  <PktHeaderUserMenu
386
+ strings={strings}
380
387
  user={user}
381
388
  formattedLastLoggedIn={formattedLastLoggedIn}
382
389
  representing={representing}
@@ -1,6 +1,7 @@
1
1
  import '@testing-library/jest-dom'
2
2
 
3
3
  import { fireEvent, render, screen } from '@testing-library/react'
4
+ import { resetPktStrings, setPktStrings } from 'shared-strings'
4
5
  import { vi } from 'vitest'
5
6
 
6
7
  //mock element width to control mobile/desktop behavior
@@ -121,6 +122,47 @@ describe('PktHeaderService', () => {
121
122
  const logoLink = container.querySelector('.pkt-header-service__logo a')
122
123
  expect(logoLink).toHaveAttribute('href', 'https://www.oslo.kommune.no')
123
124
  })
125
+
126
+ it('renders logo without a link when logoLink is an empty string', () => {
127
+ const { container } = render(<PktHeaderService serviceName="Svc" logoLink="" />)
128
+ const logo = container.querySelector('.pkt-header-service__logo')
129
+ expect(logo).toBeTruthy()
130
+ expect(logo?.querySelector('a')).toBeNull()
131
+ expect(logo).toHaveAttribute('role', 'img')
132
+ expect(logo).toHaveAttribute('aria-label', 'Oslo kommune')
133
+ })
134
+ })
135
+
136
+ describe('strings', () => {
137
+ afterEach(() => resetPktStrings())
138
+
139
+ it('labels the logo link from the string catalogue', () => {
140
+ const { container } = render(<PktHeaderService serviceName="Svc" />)
141
+ const logoLink = container.querySelector('.pkt-header-service__logo a')
142
+ expect(logoLink).toHaveAttribute('aria-label', 'Til Oslo kommunes hovednettsted')
143
+ })
144
+
145
+ it('uses the overridden logo label', () => {
146
+ setPktStrings({ header: { logoLabel: 'To the front page', logoAlt: 'City of Oslo' } })
147
+
148
+ const { container } = render(<PktHeaderService serviceName="Svc" />)
149
+ expect(container.querySelector('.pkt-header-service__logo a')).toHaveAttribute('aria-label', 'To the front page')
150
+
151
+ const { container: withoutLink } = render(<PktHeaderService serviceName="Svc" logoLink="" />)
152
+ expect(withoutLink.querySelector('.pkt-header-service__logo')).toHaveAttribute('aria-label', 'City of Oslo')
153
+ })
154
+
155
+ it('passes the strings prop on to the user menu', () => {
156
+ render(
157
+ <PktHeaderService
158
+ serviceName="Svc"
159
+ user={{ name: 'Aksel' }}
160
+ openedMenu="user"
161
+ strings={{ header: { loggedInAs: 'Innlogget som' } }}
162
+ />,
163
+ )
164
+ expect(screen.getByText('Innlogget som')).toBeInTheDocument()
165
+ })
124
166
  })
125
167
 
126
168
  // New tests for position and scrollBehavior props
@@ -77,7 +77,7 @@ export const PktHeaderService = forwardRef(
77
77
  position = 'fixed',
78
78
  scrollBehavior = 'hide',
79
79
  slotMenuVariant = 'icon-only',
80
- slotMenuText = 'Meny',
80
+ slotMenuText,
81
81
  strings,
82
82
  }: IPktHeaderService,
83
83
  ref: ForwardedRef<HTMLDivElement>,
@@ -303,13 +303,18 @@ export const PktHeaderService = forwardRef(
303
303
  (!serviceName || serviceName === '') && 'pkt-header-service__logo-area--without-service',
304
304
  )}
305
305
  >
306
- {!hideLogo && (
307
- <span className="pkt-header-service__logo">
308
- <a href={logoLink} aria-label="Tilbake til forside" onClick={logoClick}>
306
+ {!hideLogo &&
307
+ (logoLink ? (
308
+ <span className="pkt-header-service__logo">
309
+ <a href={logoLink} aria-label={headerStrings.logoLabel} onClick={logoClick}>
310
+ <PktIcon name="oslologo" aria-hidden="true" path={logoPath}></PktIcon>
311
+ </a>
312
+ </span>
313
+ ) : (
314
+ <span className="pkt-header-service__logo" role="img" aria-label={headerStrings.logoAlt}>
309
315
  <PktIcon name="oslologo" aria-hidden="true" path={logoPath}></PktIcon>
310
- </a>
311
- </span>
312
- )}
316
+ </span>
317
+ ))}
313
318
  {serviceName && (
314
319
  <span className="pkt-header-service__service-name" translate="no">
315
320
  {serviceLink ? (
@@ -348,14 +353,14 @@ export const PktHeaderService = forwardRef(
348
353
  aria-controls="mobile-slot-menu"
349
354
  aria-label={headerStrings.openMenu}
350
355
  >
351
- {slotMenuText}
356
+ {slotMenuText ?? headerStrings.menu}
352
357
  </PktButton>
353
358
  )}
354
359
  <div
355
360
  className={classNames('pkt-header-service__slot-content', alignSlotRight && 'align-right')}
356
361
  id="mobile-slot-menu"
357
362
  role={isTablet ? 'group' : undefined}
358
- aria-label={isTablet ? 'Meny' : undefined}
363
+ aria-label={isTablet ? headerStrings.menu : undefined}
359
364
  ref={slotContentRef}
360
365
  onClick={handleSlotContentClick}
361
366
  >
@@ -382,7 +387,7 @@ export const PktHeaderService = forwardRef(
382
387
  aria-controls="mobile-search-menu"
383
388
  aria-label={headerStrings.openSearch}
384
389
  >
385
- Søk
390
+ {headerStrings.search}
386
391
  </PktButton>
387
392
  <div
388
393
  className={classNames(
@@ -441,7 +446,7 @@ export const PktHeaderService = forwardRef(
441
446
  iconName="exit"
442
447
  onClick={logOut}
443
448
  >
444
- Logg ut
449
+ {headerStrings.logOut}
445
450
  </PktButton>
446
451
  )}
447
452
  </div>
@@ -469,7 +474,7 @@ export const PktHeaderService = forwardRef(
469
474
  secondIconName={openMenu === 'user' ? 'chevron-thin-up' : 'chevron-thin-down'}
470
475
  onClick={() => handleMenuToggle('user')}
471
476
  >
472
- <span className="pkt-sr-only">Brukermeny: </span>
477
+ <span className="pkt-sr-only">{headerStrings.userMenuButton} </span>
473
478
  <span translate="no">{representing?.name || user.name}</span>
474
479
  </PktButton>
475
480
  {openMenu === 'user' && user && (
@@ -480,6 +485,7 @@ export const PktHeaderService = forwardRef(
480
485
  )}
481
486
  >
482
487
  <PktHeaderUserMenu
488
+ strings={strings}
483
489
  user={user}
484
490
  formattedLastLoggedIn={formattedLastLoggedIn}
485
491
  representing={representing}
@@ -496,7 +502,7 @@ export const PktHeaderService = forwardRef(
496
502
  )}
497
503
  {!isMobile && logOut && (logOutButtonPlacement === 'header' || logOutButtonPlacement === 'both') && (
498
504
  <PktButton skin="tertiary" size="medium" variant="icon-right" iconName="exit" onClick={logOut}>
499
- Logg ut
505
+ {headerStrings.logOut}
500
506
  </PktButton>
501
507
  )}
502
508
  </div>
@@ -61,7 +61,7 @@ export interface IPktHeader extends IPktStringsProps<'header'> {
61
61
  'data-mode'?: 'dark'
62
62
  /** Hide the Oslo logo. Default: false (logo is shown) */
63
63
  hideLogo?: boolean
64
- /** Link URL for the logo */
64
+ /** Link URL for the logo. Pass an empty string to render the logo without a link */
65
65
  logoLink?: string
66
66
  /** Override CDN path for the logo */
67
67
  logoPath?: string
@@ -3,6 +3,9 @@
3
3
  import classNames from 'classnames'
4
4
  import { ForwardedRef, forwardRef } from 'react'
5
5
 
6
+ import { formatString, type TPktStringsOverride } from 'shared-strings'
7
+
8
+ import { usePktStrings } from '../../hooks/usePktStrings'
6
9
  import { Representing, User, UserMenuItem } from '../header/types'
7
10
  import { PktIcon } from '../icon/Icon'
8
11
  import { PktLink } from '../link/Link'
@@ -32,6 +35,7 @@ const convertUserMenuItem = (item: UserMenuItem): TInternalMenuItem => {
32
35
  }
33
36
 
34
37
  export interface IPktHeaderUserMenu {
38
+ strings?: TPktStringsOverride<'header'>
35
39
  user: User
36
40
  formattedLastLoggedIn?: string
37
41
  representing?: Representing
@@ -84,6 +88,7 @@ const LinkSection = ({ links }: { links: TInternalMenuItem[] }) => {
84
88
  export const PktHeaderUserMenu = forwardRef(
85
89
  (
86
90
  {
91
+ strings,
87
92
  user,
88
93
  formattedLastLoggedIn,
89
94
  representing,
@@ -94,22 +99,24 @@ export const PktHeaderUserMenu = forwardRef(
94
99
  }: IPktHeaderUserMenu,
95
100
  ref: ForwardedRef<HTMLDivElement>,
96
101
  ) => {
102
+ const s = usePktStrings(['header'], strings).header
103
+
97
104
  // Convert userMenu items to internal format
98
105
  const internalMenuItems = userMenu?.map(convertUserMenuItem)
99
106
 
100
107
  return (
101
- <nav className="pkt-user-menu" ref={ref} aria-label="Meny for innlogget bruker">
108
+ <nav className="pkt-user-menu" ref={ref} aria-label={s.userMenuLabel}>
102
109
  <ul className="pkt-user-menu__list">
103
110
  {/* User section */}
104
111
  {user && (
105
112
  <li className="pkt-user-menu__item">
106
- <div className="pkt-user-menu__label">Pålogget som</div>
113
+ <div className="pkt-user-menu__label">{s.loggedInAs}</div>
107
114
  <div className="pkt-user-menu__name" translate="no">
108
115
  {user.name}
109
116
  </div>
110
117
  {formattedLastLoggedIn && (
111
118
  <div className="pkt-user-menu__last-logged-in">
112
- Sist pålogget: <time>{formattedLastLoggedIn}</time>
119
+ {s.lastLoggedIn} <time>{formattedLastLoggedIn}</time>
113
120
  </div>
114
121
  )}
115
122
  </li>
@@ -125,18 +132,20 @@ export const PktHeaderUserMenu = forwardRef(
125
132
  {/* Representing section */}
126
133
  {representing && (
127
134
  <li className="pkt-user-menu__item">
128
- <div className="pkt-user-menu__label">Representerer</div>
135
+ <div className="pkt-user-menu__label">{s.representing}</div>
129
136
  <div className="pkt-user-menu__name" translate="no">
130
137
  {representing.name}
131
138
  </div>
132
139
  {representing.orgNumber && (
133
- <div className="pkt-user-menu__org-number">Org.nr. {representing.orgNumber}</div>
140
+ <div className="pkt-user-menu__org-number">
141
+ {formatString(s.orgNumber, { number: representing.orgNumber })}
142
+ </div>
134
143
  )}
135
144
  {canChangeRepresentation && changeRepresentation && (
136
145
  <ul className="pkt-user-menu__sublist mt-size-16">
137
146
  <li className="pkt-user-menu__subitem">
138
147
  <LinkOrButtonComponent
139
- item={{ title: 'Endre organisasjon', iconName: 'cogwheel', onClick: changeRepresentation }}
148
+ item={{ title: s.changeRepresentation, iconName: 'cogwheel', onClick: changeRepresentation }}
140
149
  />
141
150
  </li>
142
151
  </ul>
@@ -150,7 +159,7 @@ export const PktHeaderUserMenu = forwardRef(
150
159
  <ul className="pkt-user-menu__sublist">
151
160
  <li className="pkt-user-menu__subitem">
152
161
  <LinkOrButtonComponent
153
- item={{ title: 'Endre organisasjon', iconName: 'cogwheel', onClick: changeRepresentation }}
162
+ item={{ title: s.changeRepresentation, iconName: 'cogwheel', onClick: changeRepresentation }}
154
163
  />
155
164
  </li>
156
165
  </ul>
@@ -160,7 +169,7 @@ export const PktHeaderUserMenu = forwardRef(
160
169
  {/* Logout */}
161
170
  {logoutOnClick && (
162
171
  <li className="pkt-user-menu__item">
163
- <LinkOrButtonComponent item={{ title: 'Logg ut', iconName: 'exit', onClick: logoutOnClick }} />
172
+ <LinkOrButtonComponent item={{ title: s.logOut, iconName: 'exit', onClick: logoutOnClick }} />
164
173
  </li>
165
174
  )}
166
175
  </ul>