@oslokommune/punkt-react 19.15.2 → 19.15.4

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.
@@ -84,7 +84,6 @@ export interface ICalendarGridDimensions {
84
84
  startingDay: number;
85
85
  numDays: number;
86
86
  numRows: number;
87
- numDaysPrevMonth: number;
88
87
  initialWeek: number;
89
88
  }
90
89
  export interface IGridCellPosition {
@@ -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';
@@ -10,7 +10,3 @@ export declare function calculateCalendarDimensions(year: number, month: number)
10
10
  * Determine what type of cell to render at a given position
11
11
  */
12
12
  export declare function getCellType(rowIndex: number, colIndex: number, dayCounter: number, gridDimensions: ICalendarGridDimensions): 'prev-month' | 'current-month' | 'next-month';
13
- /**
14
- * Get the day number to display for a given cell
15
- */
16
- export declare function getDayNumber(cellType: 'prev-month' | 'current-month' | 'next-month', colIndex: number, dayCounter: number, gridDimensions: ICalendarGridDimensions): number;
@@ -5,6 +5,6 @@
5
5
  * to provide a single import point for calendar-related utilities.
6
6
  */
7
7
  export { isDateExcluded, isDayDisabled, isPrevMonthAllowed, isNextMonthAllowed, type IDateConstraints, } from './date-validation';
8
- export { DAYS_PER_WEEK, MONDAY_OFFSET, calculateCalendarDimensions, getCellType, getDayNumber, type ICalendarGridDimensions, type IGridCellPosition, } from './calendar-grid';
8
+ export { DAYS_PER_WEEK, MONDAY_OFFSET, calculateCalendarDimensions, getCellType, type ICalendarGridDimensions, type IGridCellPosition, } from './calendar-grid';
9
9
  export { convertSelectedToDates, updateRangeMap, isRangeAllowed, addToSelection, removeFromSelection, toggleSelection, handleRangeSelection, type TDateRangeMap, type ISelectionState, type ISelectionOptions, } from './selection-manager';
10
10
  export { KEY_DIRECTION_MAP, shouldIgnoreKeyboardEvent, findNextSelectableDate, getKeyDirection, } from './keyboard-navigation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.15.2",
3
+ "version": "19.15.4",
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",
@@ -41,7 +41,7 @@
41
41
  "@eslint/eslintrc": "^3.3.5",
42
42
  "@eslint/js": "^10.0.1",
43
43
  "@oslokommune/punkt-assets": "^19.14.2",
44
- "@oslokommune/punkt-css": "^19.15.2",
44
+ "@oslokommune/punkt-css": "^19.15.3",
45
45
  "@testing-library/jest-dom": "^6.9.1",
46
46
  "@testing-library/react": "^16.3.2",
47
47
  "@testing-library/user-event": "^14.6.1",
@@ -101,5 +101,5 @@
101
101
  "url": "https://github.com/oslokommune/punkt/issues"
102
102
  },
103
103
  "license": "MIT",
104
- "gitHead": "111568431950f1c24b7954647294c30971558e8e"
104
+ "gitHead": "dee1f862952b4a13c654f3b82d28a68922fad014"
105
105
  }
@@ -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>,
@@ -29,6 +29,15 @@ describe('PktCalendar', () => {
29
29
  expect(monthNav).toBeInTheDocument()
30
30
  })
31
31
 
32
+ test('renders days outside the current month as empty cells', () => {
33
+ const { container } = createCalendar({ currentmonth: '2024-10-01' })
34
+
35
+ const otherCells = container.querySelectorAll('.pkt-cal-other')
36
+ expect(otherCells).toHaveLength(4)
37
+ otherCells.forEach((cell) => expect(cell).toBeEmptyDOMElement())
38
+ expect(container.querySelectorAll('.pkt-calendar__date')).toHaveLength(31)
39
+ })
40
+
32
41
  test('renders month picker when withcontrols is true', () => {
33
42
  const { container } = createCalendar({ withcontrols: true })
34
43
 
@@ -1,9 +1,4 @@
1
- import {
2
- DAYS_PER_WEEK,
3
- calculateCalendarDimensions,
4
- getCellType,
5
- getDayNumber,
6
- } from 'shared-utils/calendar/calendar-grid'
1
+ import { DAYS_PER_WEEK, calculateCalendarDimensions, getCellType } from 'shared-utils/calendar/calendar-grid'
7
2
  import {
8
3
  getDayViewData,
9
4
  getDayCellClasses,
@@ -122,13 +117,7 @@ export const CalendarGrid = ({ state }: { state: ICalendarState }) => {
122
117
  )
123
118
  }
124
119
 
125
- const renderEmptyDayCell = (day: number, key: string) => (
126
- <td key={key} className="pkt-cal-other">
127
- <div className="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only" data-disabled="disabled">
128
- <span className="pkt-btn__text pkt-txt-14-light">{day}</span>
129
- </div>
130
- </td>
131
- )
120
+ const renderEmptyDayCell = (key: string) => <td key={key} className="pkt-cal-other"></td>
132
121
 
133
122
  const renderCalendarBody = () => {
134
123
  const today = todayDate
@@ -161,8 +150,7 @@ export const CalendarGrid = ({ state }: { state: ICalendarState }) => {
161
150
  cells.push(renderDayView(dayCounter, today))
162
151
  dayCounter++
163
152
  } else {
164
- const dayNumber = getDayNumber(cellType, j, dayCounter, dimensions)
165
- cells.push(renderEmptyDayCell(dayNumber, `${cellType}-${i}-${j}`))
153
+ cells.push(renderEmptyDayCell(`${cellType}-${i}-${j}`))
166
154
  if (cellType === 'next-month') {
167
155
  dayCounter++
168
156
  }
@@ -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(() => {