@oslokommune/punkt-react 19.19.1 → 20.0.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +3 -2
  3. package/dist/components/card/Card.js +77 -70
  4. package/dist/components/checkbox/Checkbox.js +1 -1
  5. package/dist/components/inputwrapper/InputWrapper.js +1 -1
  6. package/dist/components/link/Link.d.ts +0 -1
  7. package/dist/components/link/Link.js +10 -12
  8. package/dist/components/linkcard/LinkCard.d.ts +1 -1
  9. package/dist/components/linkcard/LinkCard.js +23 -20
  10. package/dist/components/messagebox/Messagebox.js +29 -28
  11. package/dist/components/progressbar/Progressbar.d.ts +2 -16
  12. package/dist/components/progressbar/Progressbar.js +49 -42
  13. package/dist/components/radio/RadioButton.js +1 -1
  14. package/dist/components/tag/Tag.d.ts +2 -1
  15. package/dist/components/tag/Tag.js +37 -35
  16. package/dist/punkt-react.cjs +1 -1
  17. package/dist/shared-strings/nb.d.ts +3 -0
  18. package/dist/shared-strings/nb.js +1 -0
  19. package/dist/shared-types/card.d.ts +5 -17
  20. package/dist/shared-types/card.js +9 -8
  21. package/dist/shared-types/combobox.d.ts +3 -3
  22. package/dist/shared-types/icon.d.ts +2 -2
  23. package/dist/shared-types/icon.js +1 -1
  24. package/dist/shared-types/index.d.ts +11 -9
  25. package/dist/shared-types/index.js +17 -15
  26. package/dist/shared-types/linkcard.d.ts +7 -4
  27. package/dist/shared-types/linkcard.js +9 -0
  28. package/dist/shared-types/messagebox.d.ts +4 -2
  29. package/dist/shared-types/messagebox.js +8 -3
  30. package/dist/shared-types/progressbar.d.ts +82 -5
  31. package/dist/shared-types/progressbar.js +14 -0
  32. package/dist/shared-types/skin.d.ts +8 -2
  33. package/package.json +4 -4
  34. package/src/components/button/Button.test.tsx +1 -1
  35. package/src/components/card/Card.test.tsx +78 -43
  36. package/src/components/card/Card.tsx +17 -24
  37. package/src/components/checkbox/Checkbox.tsx +1 -1
  38. package/src/components/inputwrapper/InputWrapper.tsx +1 -1
  39. package/src/components/link/Link.test.tsx +9 -21
  40. package/src/components/link/Link.tsx +0 -4
  41. package/src/components/linkcard/LinkCard.test.tsx +20 -9
  42. package/src/components/linkcard/LinkCard.tsx +5 -11
  43. package/src/components/messagebox/Messagebox.test.tsx +10 -1
  44. package/src/components/messagebox/Messagebox.tsx +11 -2
  45. package/src/components/progressbar/Progressbar.test.tsx +25 -0
  46. package/src/components/progressbar/Progressbar.tsx +30 -40
  47. package/src/components/radio/RadioButton.tsx +1 -1
  48. package/src/components/tag/Tag.test.tsx +21 -0
  49. package/src/components/tag/Tag.tsx +6 -2
@@ -19,7 +19,11 @@ describe('PktCard', () => {
19
19
  })
20
20
 
21
21
  test('renders content in children', () => {
22
- const { container } = render(<PktCard><p>Test content here</p></PktCard>)
22
+ const { container } = render(
23
+ <PktCard>
24
+ <p>Test content here</p>
25
+ </PktCard>,
26
+ )
23
27
  const content = container.querySelector('.pkt-card__content')
24
28
  expect(content).toBeInTheDocument()
25
29
  expect(content?.textContent).toContain('Test content here')
@@ -39,7 +43,11 @@ describe('PktCard', () => {
39
43
 
40
44
  test('forwards ref correctly', () => {
41
45
  const ref = createRef<HTMLDivElement>()
42
- const { unmount } = render(<PktCard ref={ref} heading="Test">innhold</PktCard>)
46
+ const { unmount } = render(
47
+ <PktCard ref={ref} heading="Test">
48
+ innhold
49
+ </PktCard>,
50
+ )
43
51
  expect(ref.current).toBeInstanceOf(HTMLElement)
44
52
  unmount()
45
53
  expect(ref.current).toBeNull()
@@ -50,14 +58,14 @@ describe('PktCard', () => {
50
58
  test('applies default properties correctly', () => {
51
59
  const { container } = render(<PktCard>innhold</PktCard>)
52
60
  const article = container.querySelector('article')
53
- expect(article).toHaveClass('pkt-card--outlined')
61
+ expect(article).toHaveClass('pkt-card--gray')
54
62
  expect(article).toHaveClass('pkt-card--vertical')
55
- expect(article).toHaveClass('pkt-card--padding-default')
56
- expect(article).toHaveClass('pkt-card--border-on-hover')
63
+ expect(article).not.toHaveClass('pkt-card--clickable')
64
+ expect(article).not.toHaveAttribute('data-mode')
57
65
  })
58
66
 
59
67
  test('applies different skin properties correctly', () => {
60
- const skins = ['outlined', 'outlined-beige', 'gray', 'beige', 'green', 'blue'] as const
68
+ const skins = ['gray', 'outlined', 'transparent', 'white', 'blue', 'green', 'beige'] as const
61
69
  for (const skin of skins) {
62
70
  const { container, unmount } = render(<PktCard skin={skin}>innhold</PktCard>)
63
71
  const article = container.querySelector('article')
@@ -76,20 +84,18 @@ describe('PktCard', () => {
76
84
  }
77
85
  })
78
86
 
79
- test('applies different padding properties correctly', () => {
80
- const paddingOptions = ['none', 'default'] as const
81
- for (const padding of paddingOptions) {
82
- const { container, unmount } = render(<PktCard padding={padding}>innhold</PktCard>)
83
- const article = container.querySelector('article')
84
- expect(article).toHaveClass(`pkt-card--padding-${padding}`)
87
+ test('keeps light-only skins in light mode', () => {
88
+ for (const skin of ['white', 'blue', 'green', 'beige'] as const) {
89
+ const { container, unmount } = render(<PktCard skin={skin}>innhold</PktCard>)
90
+ expect(container.querySelector('article')).toHaveAttribute('data-mode', 'light')
85
91
  unmount()
86
92
  }
87
- })
88
93
 
89
- test('handles borderOnHover property correctly', () => {
90
- const { container } = render(<PktCard borderOnHover={false}>innhold</PktCard>)
91
- const article = container.querySelector('article')
92
- expect(article).not.toHaveClass('pkt-card--border-on-hover')
94
+ for (const skin of ['gray', 'outlined', 'transparent'] as const) {
95
+ const { container, unmount } = render(<PktCard skin={skin}>innhold</PktCard>)
96
+ expect(container.querySelector('article')).not.toHaveAttribute('data-mode')
97
+ unmount()
98
+ }
93
99
  })
94
100
 
95
101
  test('supports custom className', () => {
@@ -117,7 +123,9 @@ describe('PktCard', () => {
117
123
 
118
124
  test('applies correct heading level', () => {
119
125
  const { container } = render(
120
- <PktCard heading="Test" headingLevel={2}>innhold</PktCard>,
126
+ <PktCard heading="Test" headingLevel={2}>
127
+ innhold
128
+ </PktCard>,
121
129
  )
122
130
  const heading = container.querySelector('h2.pkt-card__heading')
123
131
  expect(heading).toBeInTheDocument()
@@ -148,7 +156,9 @@ describe('PktCard', () => {
148
156
 
149
157
  test('renders as link card when clickCardLink provided', () => {
150
158
  const { container } = render(
151
- <PktCard heading="Test Title" clickCardLink="/test-url">innhold</PktCard>,
159
+ <PktCard heading="Test Title" clickCardLink="/test-url">
160
+ innhold
161
+ </PktCard>,
152
162
  )
153
163
  const linkHeading = container.querySelector('.pkt-card__link-heading')
154
164
  const link = container.querySelector('.pkt-card__link')
@@ -159,11 +169,26 @@ describe('PktCard', () => {
159
169
 
160
170
  const article = container.querySelector('article')
161
171
  expect(article?.getAttribute('aria-label')).toBe('Test Title lenkekort')
172
+ expect(article).toHaveClass('pkt-card--clickable')
173
+ })
174
+
175
+ test('renders an arrow after the link in the heading', () => {
176
+ const { container } = render(
177
+ <PktCard heading="Test Title" clickCardLink="/test-url">
178
+ innhold
179
+ </PktCard>,
180
+ )
181
+ const icon = container.querySelector('.pkt-card__link-heading > .pkt-card__link-icon')
182
+ expect(icon).toBeInTheDocument()
183
+ expect(icon?.getAttribute('name')).toBe('arrow-link')
184
+ expect(icon?.previousElementSibling).toHaveClass('pkt-card__link')
162
185
  })
163
186
 
164
187
  test('does not render plain heading when clickCardLink is set', () => {
165
188
  const { container } = render(
166
- <PktCard heading="Test" clickCardLink="/test">innhold</PktCard>,
189
+ <PktCard heading="Test" clickCardLink="/test">
190
+ innhold
191
+ </PktCard>,
167
192
  )
168
193
  const headings = container.querySelectorAll('.pkt-card__heading')
169
194
  // Should only have the link heading, not both
@@ -173,7 +198,9 @@ describe('PktCard', () => {
173
198
 
174
199
  test('handles openLinkInNewTab correctly', () => {
175
200
  const { container } = render(
176
- <PktCard heading="Test" clickCardLink="/test" openLinkInNewTab>innhold</PktCard>,
201
+ <PktCard heading="Test" clickCardLink="/test" openLinkInNewTab>
202
+ innhold
203
+ </PktCard>,
177
204
  )
178
205
  const link = container.querySelector('.pkt-card__link')
179
206
  expect(link?.getAttribute('target')).toBe('_blank')
@@ -182,7 +209,9 @@ describe('PktCard', () => {
182
209
 
183
210
  test('applies correct aria-label for link cards with custom ariaLabel', () => {
184
211
  const { container } = render(
185
- <PktCard clickCardLink="/test" ariaLabel="Custom aria label">innhold</PktCard>,
212
+ <PktCard clickCardLink="/test" ariaLabel="Custom aria label">
213
+ innhold
214
+ </PktCard>,
186
215
  )
187
216
  const article = container.querySelector('article')
188
217
  expect(article?.getAttribute('aria-label')).toBe('Custom aria label')
@@ -191,9 +220,7 @@ describe('PktCard', () => {
191
220
 
192
221
  describe('Image functionality', () => {
193
222
  test('renders image when provided', () => {
194
- const { container } = render(
195
- <PktCard image={{ src: '/test-image.jpg', alt: 'Test image' }}>innhold</PktCard>,
196
- )
223
+ const { container } = render(<PktCard image={{ src: '/test-image.jpg', alt: 'Test image' }}>innhold</PktCard>)
197
224
  const imageDiv = container.querySelector('.pkt-card__image')
198
225
  const img = imageDiv?.querySelector('img')
199
226
  expect(imageDiv).toBeInTheDocument()
@@ -208,16 +235,16 @@ describe('PktCard', () => {
208
235
  expect(imageDiv).not.toBeInTheDocument()
209
236
  })
210
237
 
211
- test('applies correct image shape classes', () => {
212
- const shapes = ['square', 'round'] as const
213
- for (const shape of shapes) {
214
- const { container, unmount } = render(
215
- <PktCard image={{ src: '/test.jpg', alt: 'Test' }} imageShape={shape}>innhold</PktCard>,
216
- )
217
- const imageDiv = container.querySelector('.pkt-card__image')
218
- expect(imageDiv).toHaveClass(`pkt-card__image-${shape}`)
219
- unmount()
220
- }
238
+ test('applies image aspect class only when imageAspect is set', () => {
239
+ const { container, rerender } = render(<PktCard image={{ src: '/test.jpg', alt: 'Test' }}>innhold</PktCard>)
240
+ expect(Array.from(container.querySelector('.pkt-card__image')?.classList ?? [])).toEqual(['pkt-card__image'])
241
+
242
+ rerender(
243
+ <PktCard image={{ src: '/test.jpg', alt: 'Test' }} imageAspect="16-9">
244
+ innhold
245
+ </PktCard>,
246
+ )
247
+ expect(container.querySelector('.pkt-card__image')).toHaveClass('pkt-card__image-aspect-16-9')
221
248
  })
222
249
  })
223
250
 
@@ -245,7 +272,9 @@ describe('PktCard', () => {
245
272
  for (const position of positions) {
246
273
  const tags = [{ text: 'Test Tag' }]
247
274
  const { container, unmount } = render(
248
- <PktCard tags={tags} tagPosition={position}>innhold</PktCard>,
275
+ <PktCard tags={tags} tagPosition={position}>
276
+ innhold
277
+ </PktCard>,
249
278
  )
250
279
  const tagsContainer = container.querySelector('.pkt-card__tags')
251
280
  expect(tagsContainer).toHaveClass(`pkt-card__tags-${position}`)
@@ -263,7 +292,9 @@ describe('PktCard', () => {
263
292
  describe('Metadata functionality', () => {
264
293
  test('renders metadata when provided', () => {
265
294
  const { container } = render(
266
- <PktCard metaLead="Author Name" metaTrail="2023-12-01">innhold</PktCard>,
295
+ <PktCard metaLead="Author Name" metaTrail="2023-12-01">
296
+ innhold
297
+ </PktCard>,
267
298
  )
268
299
  const metadata = container.querySelector('.pkt-card__metadata')
269
300
  const metaLead = metadata?.querySelector('.pkt-card__metadata-lead')
@@ -313,7 +344,9 @@ describe('PktCard', () => {
313
344
  </PktCard>,
314
345
  )
315
346
  const article = container.querySelector('article')
316
- const children = Array.from(article?.children || [])
347
+ expect(article?.children).toHaveLength(1)
348
+ expect(article?.firstElementChild).toHaveClass('pkt-card__container')
349
+ const children = Array.from(article?.firstElementChild?.children || [])
317
350
 
318
351
  // Image first, then wrapper
319
352
  expect(children[0]).toHaveClass('pkt-card__image')
@@ -331,11 +364,11 @@ describe('PktCard', () => {
331
364
  test('places tags at bottom when tagPosition is bottom', () => {
332
365
  const tags = [{ text: 'Test Tag' }]
333
366
  const { container } = render(
334
- <PktCard heading="Test Title" tags={tags} tagPosition="bottom">innhold</PktCard>,
335
- )
336
- const wrapperChildren = Array.from(
337
- container.querySelector('.pkt-card__wrapper')?.children || [],
367
+ <PktCard heading="Test Title" tags={tags} tagPosition="bottom">
368
+ innhold
369
+ </PktCard>,
338
370
  )
371
+ const wrapperChildren = Array.from(container.querySelector('.pkt-card__wrapper')?.children || [])
339
372
 
340
373
  // Order: header, content, tags (bottom)
341
374
  expect(wrapperChildren[0]).toHaveClass('pkt-card__header')
@@ -353,7 +386,9 @@ describe('PktCard', () => {
353
386
 
354
387
  test('applies custom aria-label', () => {
355
388
  const { container } = render(
356
- <PktCard heading="Test" ariaLabel="Custom accessible label">innhold</PktCard>,
389
+ <PktCard heading="Test" ariaLabel="Custom accessible label">
390
+ innhold
391
+ </PktCard>,
357
392
  )
358
393
  const article = container.querySelector('article')
359
394
  expect(article?.getAttribute('aria-label')).toBe('Custom accessible label')
@@ -3,9 +3,10 @@
3
3
  import classNames from 'classnames'
4
4
  import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
5
5
  import { plural, type IPktStringsProps } from 'shared-strings'
6
- import { CARD_DEFAULTS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
6
+ import { CARD_DEFAULTS, CARD_LIGHT_ONLY_SKINS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
7
7
 
8
8
  import { PktHeading } from '../heading/Heading'
9
+ import { PktIcon } from '../icon/Icon'
9
10
  import { PktTag } from '../tag/Tag'
10
11
  import { usePktStrings } from '../../hooks/usePktStrings'
11
12
  import { withStableKeys } from '../../utils/stableKeys'
@@ -24,17 +25,13 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
24
25
  className,
25
26
  ariaLabel,
26
27
  metaLead,
27
- borderOnHover = CARD_DEFAULTS.borderOnHover,
28
28
  metaTrail,
29
29
  layout = CARD_DEFAULTS.layout,
30
30
  heading = '',
31
31
  headingLevel = CARD_DEFAULTS.headingLevel,
32
32
  image,
33
- imageShape = CARD_DEFAULTS.imageShape,
34
33
  imageAspect,
35
- restrictImageHeight = CARD_DEFAULTS.restrictImageHeight,
36
34
  clickCardLink,
37
- padding = CARD_DEFAULTS.padding,
38
35
  openLinkInNewTab = CARD_DEFAULTS.openLinkInNewTab,
39
36
  skin = CARD_DEFAULTS.skin,
40
37
  subheading = '',
@@ -51,8 +48,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
51
48
  'pkt-card': true,
52
49
  [`pkt-card--${skin}`]: skin,
53
50
  [`pkt-card--${layout}`]: layout,
54
- [`pkt-card--padding-${padding}`]: padding,
55
- 'pkt-card--border-on-hover': borderOnHover,
51
+ 'pkt-card--clickable': !!clickCardLink,
56
52
  'pkt-card--zoom': zoom,
57
53
  })
58
54
 
@@ -62,14 +58,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
62
58
  const renderImage = () => {
63
59
  if (!image?.src) return null
64
60
  return (
65
- <div
66
- className={classNames(
67
- 'pkt-card__image',
68
- `pkt-card__image-${imageShape}`,
69
- imageAspect && `pkt-card__image-aspect-${imageAspect}`,
70
- restrictImageHeight && 'pkt-card__image-restricted',
71
- )}
72
- >
61
+ <div className={classNames('pkt-card__image', imageAspect && `pkt-card__image-aspect-${imageAspect}`)}>
73
62
  <img src={image.src} alt={image.alt || ''} />
74
63
  </div>
75
64
  )
@@ -102,7 +91,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
102
91
  const renderHeading = () => {
103
92
  if (!heading || clickCardLink) return null
104
93
  return (
105
- <PktHeading className="pkt-card__heading" level={headingLevel} size="medium" weight="regular">
94
+ <PktHeading className="pkt-card__heading" level={headingLevel} size="medium" weight="medium">
106
95
  {heading}
107
96
  </PktHeading>
108
97
  )
@@ -115,7 +104,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
115
104
  className="pkt-card__link-heading pkt-card__heading"
116
105
  level={headingLevel}
117
106
  size="medium"
118
- weight="regular"
107
+ weight="medium"
119
108
  >
120
109
  <a
121
110
  className="pkt-card__link"
@@ -125,6 +114,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
125
114
  >
126
115
  {heading}
127
116
  </a>
117
+ <PktIcon className="pkt-card__link-icon" name="arrow-link" />
128
118
  </PktHeading>
129
119
  )
130
120
  }
@@ -161,14 +151,17 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
161
151
  ref={ref}
162
152
  className={classNames(classes, className)}
163
153
  aria-label={clickCardLink ? ariaLabelLenke : ariaLabelVanlig}
154
+ data-mode={CARD_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
164
155
  >
165
- {renderImage()}
166
- <div className="pkt-card__wrapper">
167
- {tagPosition === 'top' && renderTags()}
168
- {renderHeader()}
169
- <section className="pkt-card__content">{children}</section>
170
- {tagPosition === 'bottom' && renderTags()}
171
- {renderMetadata()}
156
+ <div className="pkt-card__container">
157
+ {renderImage()}
158
+ <div className="pkt-card__wrapper">
159
+ {tagPosition === 'top' && renderTags()}
160
+ {renderHeader()}
161
+ <section className="pkt-card__content">{children}</section>
162
+ {tagPosition === 'bottom' && renderTags()}
163
+ {renderMetadata()}
164
+ </div>
172
165
  </div>
173
166
  </article>
174
167
  )
@@ -125,7 +125,7 @@ export const PktCheckbox = forwardRef(
125
125
  <>
126
126
  {tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
127
127
  {optionalTag && (
128
- <span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
128
+ <span className={tagClasses + ` pkt-tag--blue-pale`}>{optionalText ?? s.forms.optional}</span>
129
129
  )}
130
130
  {requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
131
131
  </>
@@ -116,7 +116,7 @@ export const PktInputWrapper = forwardRef(
116
116
  <>
117
117
  {tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
118
118
  {optionalTag && (
119
- <span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
119
+ <span className={tagClasses + ` pkt-tag--blue-pale`}>{optionalText ?? s.forms.optional}</span>
120
120
  )}
121
121
  {requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
122
122
  </>
@@ -58,36 +58,24 @@ describe('PktLink', () => {
58
58
  })
59
59
  const icon = document.querySelector('.pkt-link__icon')
60
60
  if (iconName) {
61
- expect(icon).toBeInTheDocument();
61
+ expect(icon).toBeInTheDocument()
62
62
  } else {
63
- expect(icon).not.toBeInTheDocument();
63
+ expect(icon).not.toBeInTheDocument()
64
64
  }
65
65
  })
66
66
 
67
- it.each`
68
- description | external | hasExternalClass | relAttribute
69
- ${'external class and rel when external is true'} | ${true} | ${true} | ${'noopener noreferrer'}
70
- ${'no external class or rel when external is false'} | ${false} | ${false} | ${null}
71
- ${'no external class or rel when external is undefined'} | ${undefined} | ${false} | ${null}
72
- `('should apply $description', ({ external, hasExternalClass, relAttribute }) => {
67
+ it('passes rel through to the anchor', () => {
73
68
  render(
74
- <PktLink href="/test" external={external}>
69
+ <PktLink href="/test" rel="noopener noreferrer">
75
70
  Test Link
76
71
  </PktLink>,
77
72
  )
78
- const link = screen.getByText('Test Link')
79
-
80
- if (hasExternalClass) {
81
- expect(link).toHaveClass('pkt-link--external')
82
- } else {
83
- expect(link).not.toHaveClass('pkt-link--external')
84
- }
73
+ expect(screen.getByText('Test Link')).toHaveAttribute('rel', 'noopener noreferrer')
74
+ })
85
75
 
86
- if (relAttribute) {
87
- expect(link).toHaveAttribute('rel', relAttribute)
88
- } else {
89
- expect(link).not.toHaveAttribute('rel')
90
- }
76
+ it('has no rel by default', () => {
77
+ render(<PktLink href="/test">Test Link</PktLink>)
78
+ expect(screen.getByText('Test Link')).not.toHaveAttribute('rel')
91
79
  })
92
80
 
93
81
  it('should apply target attribute', () => {
@@ -9,7 +9,6 @@ interface IPktLink extends LinkHTMLAttributes<HTMLAnchorElement> {
9
9
  iconName?: string | undefined
10
10
  className?: string | undefined
11
11
  iconPosition?: string | undefined
12
- external?: boolean
13
12
  target?: string | undefined
14
13
  renderLink?: TRenderLink<ReactNode, AnchorHTMLAttributes<HTMLAnchorElement>>
15
14
  }
@@ -19,7 +18,6 @@ export const PktLink: FC<IPktLink> = ({
19
18
  iconName,
20
19
  className,
21
20
  iconPosition,
22
- external,
23
21
  target,
24
22
  renderLink,
25
23
  children,
@@ -29,7 +27,6 @@ export const PktLink: FC<IPktLink> = ({
29
27
  'pkt-link': true,
30
28
  'pkt-link--icon-left': (!!iconName && iconPosition === 'left') || !!(iconName && !iconPosition),
31
29
  'pkt-link--icon-right': !!iconName && iconPosition === 'right',
32
- 'pkt-link--external': external,
33
30
  }
34
31
 
35
32
  const linkChildren = (
@@ -54,7 +51,6 @@ export const PktLink: FC<IPktLink> = ({
54
51
  props: {
55
52
  ...props,
56
53
  target,
57
- rel: external ? 'noopener noreferrer' : undefined,
58
54
  },
59
55
  })
60
56
  }
@@ -84,16 +84,17 @@ describe('PktLinkCard', () => {
84
84
  expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--green')
85
85
  })
86
86
 
87
- it('renders with beige-outline skin', async () => {
87
+ it('renders with outlined skin', async () => {
88
88
  const { container } = render(
89
89
  <div>
90
- <PktLinkCard title="Beige outline" skin="beige-outline" />
90
+ <PktLinkCard title="Outlined" skin="outlined" />
91
91
  </div>,
92
92
  )
93
93
  const linkElement = container.querySelector('.pkt-linkcard')
94
- expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--beige-outline')
94
+ expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--outlined')
95
95
  })
96
- it('renders with gray-outline skin', async () => {
96
+
97
+ it('keeps the deprecated gray-outline class', async () => {
97
98
  const { container } = render(
98
99
  <div>
99
100
  <PktLinkCard title="Gray outline" skin="gray-outline" />
@@ -102,6 +103,20 @@ describe('PktLinkCard', () => {
102
103
  const linkElement = container.querySelector('.pkt-linkcard')
103
104
  expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--gray-outline')
104
105
  })
106
+
107
+ it('keeps light-only skins in light mode', async () => {
108
+ for (const skin of ['white', 'blue', 'green', 'beige'] as const) {
109
+ const { container, unmount } = render(<PktLinkCard title="Lys" skin={skin} />)
110
+ expect(container.querySelector('.pkt-linkcard')).toHaveAttribute('data-mode', 'light')
111
+ unmount()
112
+ }
113
+
114
+ for (const skin of ['gray', 'outlined', 'transparent', 'normal', 'gray-outline'] as const) {
115
+ const { container, unmount } = render(<PktLinkCard title="Følger modus" skin={skin} />)
116
+ expect(container.querySelector('.pkt-linkcard')).not.toHaveAttribute('data-mode')
117
+ unmount()
118
+ }
119
+ })
105
120
  })
106
121
 
107
122
  describe('openInNewTab strings', () => {
@@ -123,11 +138,7 @@ describe('PktLinkCard', () => {
123
138
 
124
139
  it('uses a custom override from the strings prop', () => {
125
140
  const { getByText, queryByText } = render(
126
- <PktLinkCard
127
- title="Normal"
128
- openInNewTab
129
- strings={{ linkcard: { openInNewTab: 'Opens in a new tab' } }}
130
- >
141
+ <PktLinkCard title="Normal" openInNewTab strings={{ linkcard: { openInNewTab: 'Opens in a new tab' } }}>
131
142
  Content
132
143
  </PktLinkCard>,
133
144
  )
@@ -2,16 +2,14 @@
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import { HTMLAttributes, ReactNode } from 'react'
5
- import type { IPktLinkCardBase, TLinkCardSkin } from 'shared-types'
5
+ import { LINKCARD_LIGHT_ONLY_SKINS, type IPktLinkCardBase, type TLinkCardSkin } from 'shared-types'
6
6
 
7
7
  import { PktIcon } from '../icon/Icon'
8
8
  import { usePktStrings } from '../../hooks/usePktStrings'
9
9
 
10
10
  export type { TLinkCardSkin }
11
11
 
12
- export interface IPktLinkCard
13
- extends IPktLinkCardBase,
14
- Omit<HTMLAttributes<HTMLAnchorElement>, 'title'> {
12
+ export interface IPktLinkCard extends IPktLinkCardBase, Omit<HTMLAttributes<HTMLAnchorElement>, 'title'> {
15
13
  children?: ReactNode
16
14
  }
17
15
 
@@ -22,7 +20,6 @@ export const PktLinkCard = ({
22
20
  href,
23
21
  iconName,
24
22
  openInNewTab,
25
- external,
26
23
  className,
27
24
  strings,
28
25
  ...props
@@ -30,21 +27,18 @@ export const PktLinkCard = ({
30
27
  const s = usePktStrings(['linkcard'], strings)
31
28
  const classes = ['pkt-linkcard', skin && `pkt-linkcard--${skin}`].filter(Boolean).join(' ')
32
29
 
33
- const titleClasses = ['pkt-linkcard__title', external && 'pkt-link pkt-link--external'].filter(Boolean).join(' ')
34
-
35
30
  return (
36
31
  <a
37
32
  {...props}
38
33
  href={href}
39
34
  className={classNames(classes, className)}
35
+ data-mode={skin && LINKCARD_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
40
36
  target={openInNewTab ? '_blank' : '_self'}
41
37
  rel={openInNewTab ? 'noopener noreferrer' : undefined}
42
38
  >
43
39
  {iconName && <PktIcon className="pkt-link__icon" name={iconName} />}
44
- {title && <div className={classNames(titleClasses)}>{title}</div>}
45
- {openInNewTab && s.linkcard.openInNewTab ? (
46
- <span className="pkt-sr-only">{s.linkcard.openInNewTab}</span>
47
- ) : null}
40
+ {title && <div className="pkt-linkcard__title">{title}</div>}
41
+ {openInNewTab && s.linkcard.openInNewTab ? <span className="pkt-sr-only">{s.linkcard.openInNewTab}</span> : null}
48
42
  <div className="pkt-linkcard__text">{children}</div>
49
43
  </a>
50
44
  )
@@ -13,7 +13,8 @@ describe('Messagebox', () => {
13
13
  it('render with defaults', async () => {
14
14
  const { messageBox } = render(<PktMessagebox />)
15
15
 
16
- expect(messageBox.className).toEqual('pkt-messagebox pkt-messagebox--beige')
16
+ expect(messageBox.className).toEqual('pkt-messagebox pkt-messagebox--gray')
17
+ expect(messageBox).not.toHaveAttribute('data-mode')
17
18
  })
18
19
 
19
20
  it('render with skin', async () => {
@@ -22,6 +23,14 @@ describe('Messagebox', () => {
22
23
  expect(messageBox.classList).toContain('pkt-messagebox--green')
23
24
  })
24
25
 
26
+ it('keeps light-only skins in light mode', async () => {
27
+ for (const skin of ['beige', 'blue', 'red', 'green'] as const) {
28
+ const { messageBox, unmount } = render(<PktMessagebox skin={skin} />)
29
+ expect(messageBox).toHaveAttribute('data-mode', 'light')
30
+ unmount()
31
+ }
32
+ })
33
+
25
34
  it('render compact', async () => {
26
35
  const { messageBox } = render(<PktMessagebox compact />)
27
36
 
@@ -3,7 +3,12 @@
3
3
  import classNames from 'classnames'
4
4
  import { FC, HTMLAttributes, ReactNode, useCallback, useState } from 'react'
5
5
  import type { IPktStringsProps } from 'shared-strings'
6
- import { MESSAGEBOX_DEFAULTS, type IPktMessageboxBase, type TMessageboxSkin } from 'shared-types'
6
+ import {
7
+ MESSAGEBOX_DEFAULTS,
8
+ MESSAGEBOX_LIGHT_ONLY_SKINS,
9
+ type IPktMessageboxBase,
10
+ type TMessageboxSkin,
11
+ } from 'shared-types'
7
12
 
8
13
  import { usePktStrings } from '../../hooks/usePktStrings'
9
14
  import { PktIcon } from '../icon/Icon'
@@ -49,7 +54,11 @@ export const PktMessagebox: FC<IPktMessagebox> = ({
49
54
  }, [setClosed, onClose])
50
55
 
51
56
  return (
52
- <div {...props} className={classNames(classes, className)}>
57
+ <div
58
+ {...props}
59
+ className={classNames(classes, className)}
60
+ data-mode={skin && MESSAGEBOX_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
61
+ >
53
62
  {closable && (
54
63
  <div className={'pkt-messagebox__close'}>
55
64
  <button
@@ -69,6 +69,31 @@ describe('PktProgressbar', () => {
69
69
  expect(status).toHaveTextContent('50 av 200')
70
70
  })
71
71
 
72
+ test('renders fraction relative to valueMin', () => {
73
+ const { container } = render(
74
+ <PktProgressbar id="progress-min" valueCurrent={25} valueMin={20} valueMax={30} statusType="fraction" />,
75
+ )
76
+ const bar = container.querySelector('.pkt-progressbar')
77
+ const barContainer = container.querySelector<HTMLElement>('.pkt-progressbar__container')
78
+ expect(container.querySelector('.pkt-progressbar__status')).toHaveTextContent('5 av 10')
79
+ expect(bar).toHaveAttribute('aria-valuetext', '5 av 10')
80
+ expect(barContainer?.style.getPropertyValue('--pkt-progress-width')).toBe('50%')
81
+ })
82
+
83
+ test('uses the same bar width for fraction and percentage', () => {
84
+ const props = { valueCurrent: 10, valueMin: 1, valueMax: 10 }
85
+ const { container } = render(
86
+ <>
87
+ <PktProgressbar id="progress-fraction" statusType="fraction" {...props} />
88
+ <PktProgressbar id="progress-percentage" statusType="percentage" {...props} />
89
+ </>,
90
+ )
91
+ const widths = Array.from(container.querySelectorAll<HTMLElement>('.pkt-progressbar__container'), (el) =>
92
+ el.style.getPropertyValue('--pkt-progress-width'),
93
+ )
94
+ expect(widths).toEqual(['100%', '100%'])
95
+ })
96
+
72
97
  test('renders status with center placement', () => {
73
98
  const { container } = render(
74
99
  <PktProgressbar id="progress7" valueCurrent={50} statusType="percentage" statusPlacement="center" />,