@oslokommune/punkt-react 19.15.3 → 19.15.5

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.
@@ -7,6 +7,8 @@
7
7
  import type { Booleanish } from './booleanish';
8
8
  /** Default CDN path for icons. Overridden globally by `window.pktIconPath`. */
9
9
  export declare const ICON_DEFAULT_PATH = "https://punkt-cdn.oslo.kommune.no/latest/icons/";
10
+ /** Default CDN path for loading animations. Overridden globally by `window.pktAnimationPath`. */
11
+ export declare const ANIMATION_DEFAULT_PATH = "https://punkt-cdn.oslo.kommune.no/latest/animations/";
10
12
  /** Icon size modifier classes — shared runtime source for types, specs, and Preview. */
11
13
  export declare const ICON_SIZE_CLASSES: readonly ['pkt-icon--small', 'pkt-icon--medium', 'pkt-icon--large'];
12
14
  export type TIconSizeClass = (typeof ICON_SIZE_CLASSES)[number];
@@ -19,7 +19,7 @@ export { OPTION_GROUP_DEFAULTS } from './option-group';
19
19
  export type { IPktOptionGroupBase, IPktRadioGroupBase, IPktCheckboxGroupBase, IRadioGroupSpecProps, ICheckboxGroupSpecProps, } from './option-group';
20
20
  export { CONSENT_TRIGGER_TYPES, CONSENT_TRIGGER_TYPE_OPTIONS, CONSENT_DEFAULTS } from './consent';
21
21
  export type { TPktConsentTriggerType, IConsentItem, IConsentValue, ICookieConsentEvent, TConsentDetailsMap, TCookieEventHandler, ICookieEvents, ICookieBannerApi, IPktConsentBase, IConsentSpecProps, } from './consent';
22
- export { ICON_DEFAULT_PATH, ICON_SIZE_CLASSES, ICON_DEFAULTS } from './icon';
22
+ export { ANIMATION_DEFAULT_PATH, ICON_DEFAULT_PATH, ICON_SIZE_CLASSES, ICON_DEFAULTS } from './icon';
23
23
  export type { TIconSizeClass, IPktIconBase, IIconSpecProps } from './icon';
24
24
  export { LAYOUT_DIRECTIONS } from './layout';
25
25
  export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.15.3",
3
+ "version": "19.15.5",
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",
@@ -101,5 +101,5 @@
101
101
  "url": "https://github.com/oslokommune/punkt/issues"
102
102
  },
103
103
  "license": "MIT",
104
- "gitHead": "e4314e8b6bd5119bb74094fa2809fc5d389bcd2e"
104
+ "gitHead": "0baab53f4a1bd33c07a73d24eacbd66087c98738"
105
105
  }
@@ -56,6 +56,20 @@ describe('PktBreadcrumbs Component', () => {
56
56
  expect(getAllByText('Item')).toBeTruthy()
57
57
  })
58
58
 
59
+ it('renders a single crumb without a back link', () => {
60
+ const { container, getByText } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs.slice(0, 1)} />)
61
+
62
+ expect(getByText('Home').closest('[aria-current="true"]')).toBeInTheDocument()
63
+ expect(container.querySelector('.pkt-breadcrumbs--mobile')).not.toBeInTheDocument()
64
+ })
65
+
66
+ it('renders an empty trail without a back link', () => {
67
+ const { container } = render(<PktBreadcrumbs breadcrumbs={[]} />)
68
+
69
+ expect(container.querySelector('.pkt-breadcrumbs__item')).not.toBeInTheDocument()
70
+ expect(container.querySelector('.pkt-breadcrumbs--mobile')).not.toBeInTheDocument()
71
+ })
72
+
59
73
  it('renders with no wcag errors with axe', async () => {
60
74
  const { container } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />)
61
75
  const results = await axe(container)
@@ -78,21 +78,22 @@ export const PktBreadcrumbs = forwardRef(
78
78
  ))}
79
79
  </ol>
80
80
 
81
- {linkRenderer({
82
- href: backLink.href,
83
- className: 'pkt-link pkt-link--icon-left pkt-breadcrumbs--mobile',
84
- children: (
85
- <>
86
- <PktIcon
87
- className="pkt-back-link__icon pkt-icon pkt-link__icon"
88
- name="chevron-thin-left"
89
- aria-hidden="true"
90
- />
91
- <span className="pkt-breadcrumbs__text">{backLink.text}</span>
92
- </>
93
- ),
94
- props,
95
- })}
81
+ {backLink &&
82
+ linkRenderer({
83
+ href: backLink.href,
84
+ className: 'pkt-link pkt-link--icon-left pkt-breadcrumbs--mobile',
85
+ children: (
86
+ <>
87
+ <PktIcon
88
+ className="pkt-back-link__icon pkt-icon pkt-link__icon"
89
+ name="chevron-thin-left"
90
+ aria-hidden="true"
91
+ />
92
+ <span className="pkt-breadcrumbs__text">{backLink.text}</span>
93
+ </>
94
+ ),
95
+ props,
96
+ })}
96
97
  </nav>
97
98
  )
98
99
  },
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
  import { type ButtonHTMLAttributes, ForwardedRef, forwardRef } from 'react'
3
- import type { IPktButtonBase } from 'shared-types'
3
+ import { ANIMATION_DEFAULT_PATH, type IPktButtonBase } from 'shared-types'
4
4
 
5
5
  import { PktIcon } from '../icon/Icon'
6
6
  declare global {
@@ -10,14 +10,11 @@ declare global {
10
10
  }
11
11
 
12
12
  if (typeof window !== 'undefined') {
13
- window.pktAnimationPath =
14
- window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
13
+ window.pktAnimationPath = window.pktAnimationPath || ANIMATION_DEFAULT_PATH
15
14
  }
16
15
 
17
-
18
16
  export interface IPktButton
19
- extends IPktButtonBase,
20
- Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'disabled' | 'color'> {
17
+ extends IPktButtonBase, Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'disabled' | 'color'> {
21
18
  loadingAnimationPath?: string
22
19
  }
23
20
 
@@ -40,7 +37,7 @@ export const PktButton = forwardRef(
40
37
  color,
41
38
  isLoading = undefined,
42
39
  disabled = undefined,
43
- loadingAnimationPath = window.pktAnimationPath,
40
+ loadingAnimationPath = typeof window !== 'undefined' ? window.pktAnimationPath : ANIMATION_DEFAULT_PATH,
44
41
  ...props
45
42
  }: IPktButton,
46
43
  ref: ForwardedRef<HTMLButtonElement>,
@@ -35,6 +35,7 @@ import type { IPktCombobox, IComboboxState } from './types'
35
35
  import { formatString } from 'shared-strings'
36
36
  import { usePktStrings } from '../../hooks/usePktStrings'
37
37
  import { useOwnerForm } from '../../hooks/useOwnerForm'
38
+ import { setNativeInputValue } from '../../utils/nativeInputValue'
38
39
 
39
40
  // Options sync helper (React-specific: immutable, returns new array)
40
41
  function syncOptionsWithValues(options: IPktComboboxOption[], values: string[]): IPktComboboxOption[] {
@@ -228,20 +229,15 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
228
229
  }, [options, searchValue, typeahead])
229
230
 
230
231
  // Hidden input — dispatch native events for React synthetic event compat
231
- const nativeInputValueSetter = useMemo(
232
- () => Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set,
233
- [],
234
- )
235
-
236
232
  const dispatchChange = useCallback(
237
233
  (newValues: string[]) => {
238
234
  const input = changeInputRef.current
239
- if (!input || !nativeInputValueSetter) return
235
+ if (!input) return
240
236
  const stringVal = multiple ? newValues.join(',') : newValues[0] || ''
241
- nativeInputValueSetter.call(input, stringVal)
237
+ setNativeInputValue(input, stringVal)
242
238
  input.dispatchEvent(new Event('input', { bubbles: true }))
243
239
  },
244
- [nativeInputValueSetter, multiple],
240
+ [multiple],
245
241
  )
246
242
 
247
243
  // Sync hidden input value
@@ -15,6 +15,7 @@ import {
15
15
 
16
16
  import type { IPktDatepicker, IDatepickerState } from './types'
17
17
  import { usePktStrings } from '../../hooks/usePktStrings'
18
+ import { setNativeInputValue } from '../../utils/nativeInputValue'
18
19
 
19
20
  export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRef<HTMLDivElement>): IDatepickerState {
20
21
  const {
@@ -181,21 +182,16 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
181
182
  [isControlled, onValueChange],
182
183
  )
183
184
 
184
- const nativeInputValueSetter = useMemo(
185
- () => Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set,
186
- [],
187
- )
188
-
189
185
  const dispatchChange = useCallback(
190
186
  (newValues: string[]) => {
191
187
  // Én dato er ingen fullført periode. Tom er en fullført endring.
192
188
  if (range && newValues.length === 1) return
193
189
  const input = changeInputRef.current
194
- if (!input || !nativeInputValueSetter) return
195
- nativeInputValueSetter.call(input, newValues.join(','))
190
+ if (!input) return
191
+ setNativeInputValue(input, newValues.join(','))
196
192
  input.dispatchEvent(new Event('input', { bubbles: true }))
197
193
  },
198
- [nativeInputValueSetter, range],
194
+ [range],
199
195
  )
200
196
 
201
197
  // Calendar toggle
@@ -2,6 +2,7 @@
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import { forwardRef, HTMLAttributes, ReactNode, useEffect, useState } from 'react'
5
+ import { ANIMATION_DEFAULT_PATH } from 'shared-types'
5
6
 
6
7
  import { PktIcon } from '../icon/Icon'
7
8
 
@@ -12,7 +13,7 @@ declare global {
12
13
  }
13
14
 
14
15
  if (typeof window !== 'undefined') {
15
- window.pktAnimationPath = window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
16
+ window.pktAnimationPath = window.pktAnimationPath || ANIMATION_DEFAULT_PATH
16
17
  }
17
18
 
18
19
  export type TPktLoaderVariant = 'blue' | 'rainbow' | 'shapes'
@@ -70,7 +71,7 @@ export const PktLoader = forwardRef<HTMLDivElement, IPktLoader>(function PktLoad
70
71
  message = null,
71
72
  size = 'medium',
72
73
  variant = 'rainbow',
73
- loadingAnimationPath = typeof window !== 'undefined' ? window.pktAnimationPath : undefined,
74
+ loadingAnimationPath = typeof window !== 'undefined' ? window.pktAnimationPath : ANIMATION_DEFAULT_PATH,
74
75
  className,
75
76
  children,
76
77
  ...rest
@@ -0,0 +1,46 @@
1
+ // @vitest-environment node
2
+ import { type ElementType, Fragment } from 'react'
3
+ import { renderToString } from 'react-dom/server'
4
+ import { MemoryRouter } from 'react-router-dom'
5
+
6
+ import * as components from './index'
7
+
8
+ const requiredProps: Record<string, Record<string, unknown>> = {
9
+ PktBreadcrumbs: {
10
+ breadcrumbs: [
11
+ { text: 'Start', href: '/' },
12
+ { text: 'Side', href: '/side' },
13
+ ],
14
+ },
15
+ PktTabItem: { index: 0 },
16
+ }
17
+
18
+ const parents: Record<string, ElementType> = {
19
+ PktTabItem: components.PktTabs,
20
+ }
21
+
22
+ const isComponent = (value: unknown) =>
23
+ typeof value === 'function' || (typeof value === 'object' && value !== null && '$$typeof' in value)
24
+
25
+ const entries = Object.entries(components as Record<string, unknown>)
26
+ .filter(([name, value]) => name.startsWith('Pkt') && isComponent(value))
27
+ .map(([name, value]) => [name, value as ElementType] as [string, ElementType])
28
+
29
+ describe('server rendering', () => {
30
+ test('runs without window', () => {
31
+ expect(typeof window).toBe('undefined')
32
+ })
33
+
34
+ test.each(entries)('%s renders without throwing', (name, Component) => {
35
+ const Parent = parents[name] ?? Fragment
36
+ expect(() =>
37
+ renderToString(
38
+ <MemoryRouter>
39
+ <Parent>
40
+ <Component {...requiredProps[name]} />
41
+ </Parent>
42
+ </MemoryRouter>,
43
+ ),
44
+ ).not.toThrow()
45
+ })
46
+ })
@@ -16,6 +16,7 @@ import type { IPktTimepicker } from './types'
16
16
  import { TPktInputSize } from 'shared-types/size'
17
17
  import { usePktStrings } from '../../hooks/usePktStrings'
18
18
  import { useOwnerForm } from '../../hooks/useOwnerForm'
19
+ import { setNativeInputValue } from '../../utils/nativeInputValue'
19
20
  import { formatString, type TPktStrings } from 'shared-strings'
20
21
 
21
22
  /**
@@ -203,11 +204,6 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
203
204
  const minutesFirstDigitRef = useRef(-1)
204
205
  const [touched, setTouched] = useState(false)
205
206
 
206
- const nativeInputValueSetter = useMemo(
207
- () => Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set,
208
- [],
209
- )
210
-
211
207
  const minuteStep = useMemo(() => getMinuteStep(step), [step])
212
208
  const hourOptions = useMemo(() => getHourOptions(min, max), [min, max])
213
209
  const minuteOptions = useMemo(() => getMinuteOptions(step), [step])
@@ -235,12 +231,12 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
235
231
  setInternalValue(newValue)
236
232
  }
237
233
  const input = changeInputRef.current
238
- if (!input || !nativeInputValueSetter) return
239
- nativeInputValueSetter.call(input, newValue)
234
+ if (!input) return
235
+ setNativeInputValue(input, newValue)
240
236
  input.dispatchEvent(new Event('input', { bubbles: true }))
241
237
  onValueChange?.(newValue)
242
238
  },
243
- [isControlled, nativeInputValueSetter, onValueChange],
239
+ [isControlled, onValueChange],
244
240
  )
245
241
 
246
242
  const syncValueFromDisplay = useCallback(() => {