@oslokommune/punkt-react 19.2.0 → 19.3.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/card/Card.d.ts +2 -1
  3. package/dist/components/checkbox/Checkbox.d.ts +2 -20
  4. package/dist/components/datepicker/types.d.ts +1 -1
  5. package/dist/components/fileupload/extensions/Comments.d.ts +2 -1
  6. package/dist/components/fileupload/extensions/Remove.d.ts +2 -1
  7. package/dist/components/fileupload/extensions/Rename.d.ts +2 -1
  8. package/dist/components/fileupload/hooks/index.d.ts +1 -0
  9. package/dist/components/fileupload/hooks/useImageObjectUrl.d.ts +1 -0
  10. package/dist/components/fileupload/hooks.d.ts +1 -0
  11. package/dist/components/fileupload/types.d.ts +2 -0
  12. package/dist/components/header-menu/HeaderMenu.d.ts +3 -2
  13. package/dist/components/messagebox/Messagebox.d.ts +2 -1
  14. package/dist/components/modal/Modal.d.ts +2 -1
  15. package/dist/punkt-react.cjs +1 -1
  16. package/dist/punkt-react.js +1991 -1953
  17. package/dist/shared-strings/nb.d.ts +34 -0
  18. package/dist/shared-types/checkbox.d.ts +52 -0
  19. package/dist/shared-types/index.d.ts +2 -0
  20. package/package.json +2 -2
  21. package/src/components/alert/Alert.test.tsx +5 -5
  22. package/src/components/alert/Alert.tsx +2 -4
  23. package/src/components/breadcrumbs/Breadcrumbs.tsx +15 -12
  24. package/src/components/calendar/Calendar.core.test.tsx +22 -16
  25. package/src/components/calendar/CalendarNav.tsx +11 -6
  26. package/src/components/calendar/useCalendarState.ts +42 -55
  27. package/src/components/card/Card.tsx +17 -5
  28. package/src/components/checkbox/Checkbox.tsx +11 -26
  29. package/src/components/combobox/ComboboxTags.tsx +3 -3
  30. package/src/components/combobox/Listbox.tsx +7 -5
  31. package/src/components/combobox/useComboboxState.ts +22 -18
  32. package/src/components/consent/Consent.tsx +4 -1
  33. package/src/components/datepicker/DatepickerInputs.tsx +3 -9
  34. package/src/components/datepicker/types.ts +1 -1
  35. package/src/components/datepicker/useDatepickerState.ts +22 -17
  36. package/src/components/fileupload/DropZone.tsx +10 -10
  37. package/src/components/fileupload/FileUpload.tsx +9 -14
  38. package/src/components/fileupload/Subcomponents.tsx +78 -84
  39. package/src/components/fileupload/extensions/Comments.tsx +56 -50
  40. package/src/components/fileupload/extensions/Remove.tsx +8 -3
  41. package/src/components/fileupload/extensions/Rename.tsx +12 -8
  42. package/src/components/fileupload/hooks/index.ts +1 -0
  43. package/src/components/fileupload/hooks/useImageObjectUrl.ts +15 -0
  44. package/src/components/fileupload/hooks/useOperationState.ts +9 -16
  45. package/src/components/fileupload/hooks.ts +1 -0
  46. package/src/components/fileupload/types.ts +7 -1
  47. package/src/components/formAttribute.test.tsx +1 -0
  48. package/src/components/header/HeaderGlobal.tsx +8 -2
  49. package/src/components/header/HeaderService.test.tsx +5 -2
  50. package/src/components/header/HeaderService.tsx +5 -5
  51. package/src/components/header-menu/HeaderMenu.tsx +8 -3
  52. package/src/components/headerUserMenu/UserMenu.tsx +3 -2
  53. package/src/components/inputwrapper/InputWrapper.tsx +20 -27
  54. package/src/components/loader/Loader.tsx +12 -9
  55. package/src/components/messagebox/Messagebox.tsx +6 -2
  56. package/src/components/modal/Modal.tsx +13 -9
  57. package/src/components/searchinput/SearchInput.tsx +10 -6
  58. package/src/components/tabs/Tabs.test.tsx +1 -1
  59. package/src/components/tabs/Tabs.tsx +30 -35
  60. package/src/components/tag/Tag.tsx +7 -6
  61. package/src/components/textarea/Textarea.test.tsx +9 -0
  62. package/src/components/textarea/Textarea.tsx +6 -10
  63. package/src/components/textinput/Textinput.tsx +3 -9
  64. package/src/components/timepicker/useTimepickerState.ts +25 -21
@@ -72,6 +72,10 @@ export declare const nb: {
72
72
  alert: {
73
73
  lastUpdated: string;
74
74
  };
75
+ card: {
76
+ tagsLabelOne: string;
77
+ tagsLabelOther: string;
78
+ };
75
79
  tag: {
76
80
  remove: string;
77
81
  };
@@ -90,10 +94,15 @@ export declare const nb: {
90
94
  representing: string;
91
95
  orgNumber: string;
92
96
  changeRepresentation: string;
97
+ menuLoading: string;
98
+ menuLoadError: string;
93
99
  };
94
100
  listbox: {
95
101
  searchLabel: string;
96
102
  searchPlaceholder: string;
103
+ empty: string;
104
+ addValue: string;
105
+ maxReached: string;
97
106
  };
98
107
  combobox: {
99
108
  noResults: string;
@@ -117,6 +126,8 @@ export declare const nb: {
117
126
  dropZoneOpenFileDialogSingle: string;
118
127
  dropZoneOpenFileDialogMultipleThumbnail: string;
119
128
  dropZoneOpenFileDialogSingleThumbnail: string;
129
+ openFileDialogLabelMultiple: string;
130
+ openFileDialogLabelSingle: string;
120
131
  supportedFormatsPrefix: string;
121
132
  invalidFormat: string;
122
133
  sizeTooLarge: string;
@@ -131,5 +142,28 @@ export declare const nb: {
131
142
  srFilesAdded: string;
132
143
  srFilesUploadedOfTotal: string;
133
144
  srFilesFailedOfTotal: string;
145
+ filename: string;
146
+ uploading: string;
147
+ uploadingFile: string;
148
+ save: string;
149
+ cancel: string;
150
+ cancelUpload: string;
151
+ removeFailed: string;
152
+ removeFailedFile: string;
153
+ remove: string;
154
+ removeFile: string;
155
+ rename: string;
156
+ renameFile: string;
157
+ renameInputLabel: string;
158
+ addComment: string;
159
+ editComment: string;
160
+ saveComment: string;
161
+ deleteComment: string;
162
+ commentPlaceholder: string;
163
+ commentText: string;
164
+ commentTimestamp: string;
165
+ previewPrevious: string;
166
+ previewNext: string;
167
+ previewImageAlt: string;
134
168
  };
135
169
  };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * checkbox.ts
3
+ *
4
+ * Type definitions for pkt-checkbox.
5
+ * Used by React, Elements, and typed component specs.
6
+ */
7
+ import type { IPktStringsProps } from '../shared-strings';
8
+ import type { IFormFieldErrorProps, IFormFieldLabelProps, ITagOptionalRequiredProps } from './form-field';
9
+ /** Checkbox label placement — shared runtime source for types, specs, and Preview. */
10
+ export declare const CHECKBOX_LABEL_POSITIONS: readonly ['right', 'left'];
11
+ export type TCheckboxLabelPosition = (typeof CHECKBOX_LABEL_POSITIONS)[number];
12
+ /**
13
+ * Checkbox props shared by React and Elements.
14
+ *
15
+ * @remarks React requires `id` and widens `checkHelptext` to `ReactNode`.
16
+ * Elements accepts booleanish strings for `checked`/`indeterminate`.
17
+ */
18
+ export interface IPktCheckboxBase extends IFormFieldLabelProps, Pick<IFormFieldErrorProps, 'disabled' | 'hasError'>, ITagOptionalRequiredProps, IPktStringsProps<'forms'> {
19
+ id?: string;
20
+ name?: string;
21
+ form?: string;
22
+ value?: string;
23
+ checkHelptext?: string;
24
+ defaultChecked?: boolean;
25
+ checked?: boolean;
26
+ indeterminate?: boolean;
27
+ hasTile?: boolean;
28
+ isSwitch?: boolean;
29
+ hideLabel?: boolean;
30
+ labelPosition?: TCheckboxLabelPosition;
31
+ }
32
+ /**
33
+ * Documented Checkbox props (subset of `IPktCheckboxBase`).
34
+ * Used for typed component specs in documentation.
35
+ */
36
+ export type ICheckboxSpecProps = Pick<IPktCheckboxBase, 'label' | 'checkHelptext' | 'name' | 'form' | 'value' | 'id' | 'defaultChecked' | 'checked' | 'indeterminate' | 'hasTile' | 'disabled' | 'hasError' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText'>;
37
+ /**
38
+ * Default values for pkt-checkbox. Single source of truth for both frameworks.
39
+ * `checked` is intentionally absent — React must keep it `undefined` to stay uncontrolled.
40
+ */
41
+ export declare const CHECKBOX_DEFAULTS: {
42
+ readonly defaultChecked: false;
43
+ readonly indeterminate: false;
44
+ readonly hasTile: false;
45
+ readonly disabled: false;
46
+ readonly hasError: false;
47
+ readonly isSwitch: false;
48
+ readonly hideLabel: false;
49
+ readonly labelPosition: 'right';
50
+ readonly requiredTag: false;
51
+ readonly optionalTag: false;
52
+ };
@@ -11,6 +11,8 @@ export type { IPktFooterLink, IPktFooterColumn, IPktFooterSocialLink, IPktFooter
11
11
  export { DEFAULT_FOOTER_PERSONVERN_URL, DEFAULT_FOOTER_TILGJENGELIGHET_URL } from './footer';
12
12
  export { CARD_SKINS, CARD_PADDINGS, CARD_IMAGE_SHAPES, CARD_IMAGE_ASPECTS, CARD_TAG_POSITIONS, CARD_TAG_SKIN_OPTIONS, CARD_DEFAULTS } from './card';
13
13
  export type { TCardSkin, TCardPadding, TCardImageShape, TCardImageAspect, TCardTagPosition, ICardTag, ICardImage, IPktCardBase, ICardSpecProps, } from './card';
14
+ export { CHECKBOX_LABEL_POSITIONS, CHECKBOX_DEFAULTS } from './checkbox';
15
+ export type { TCheckboxLabelPosition, IPktCheckboxBase, ICheckboxSpecProps } from './checkbox';
14
16
  export { LAYOUT_DIRECTIONS } from './layout';
15
17
  export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
16
18
  export type { THTMLButtonType, TSelectionMode } from './form';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.2.0",
3
+ "version": "19.3.1",
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": "9ffef14fdbc5993d24cba60a16324095834103f5"
104
+ "gitHead": "40680531212b05400461eaf3ce7eddc3f14edd85"
105
105
  }
@@ -18,7 +18,7 @@ describe('PktAlert', () => {
18
18
  Hello World
19
19
  </PktAlert>,
20
20
  )
21
- fireEvent.click(getByLabelText('close'))
21
+ fireEvent.click(getByLabelText('Lukk'))
22
22
  await waitFor(() => {
23
23
  expect(onClose).toHaveBeenCalledTimes(1)
24
24
  })
@@ -64,10 +64,10 @@ describe('PktAlert', () => {
64
64
  ${''} | ${undefined}
65
65
  ${null} | ${undefined}
66
66
  ${(
67
- <span>
68
- Complex <strong>title</strong>
69
- </span>
70
- )} | ${'<span>Complex <strong>title</strong></span>'}
67
+ <span>
68
+ Complex <strong>title</strong>
69
+ </span>
70
+ )} | ${'<span>Complex <strong>title</strong></span>'}
71
71
  `('support complex title %$', async ({ title, expected }) => {
72
72
  const { container } = render(<PktAlert title={title}>Alert text</PktAlert>)
73
73
  const titleElement = container.querySelector('.pkt-alert__title')
@@ -84,7 +84,7 @@ export const PktAlert: FC<IPktAlert> = ({
84
84
  <div className="pkt-alert__close">
85
85
  <PktButton
86
86
  tabIndex={0}
87
- aria-label="close"
87
+ aria-label={s.generic.close}
88
88
  size={size}
89
89
  type="button"
90
90
  skin="tertiary"
@@ -100,9 +100,7 @@ export const PktAlert: FC<IPktAlert> = ({
100
100
 
101
101
  <div className="pkt-alert__text">{children}</div>
102
102
 
103
- {date && (
104
- <div className="pkt-alert__date">{formatString(s.alert.lastUpdated, { date })}</div>
105
- )}
103
+ {date && <div className="pkt-alert__date">{formatString(s.alert.lastUpdated, { date })}</div>}
106
104
  </div>
107
105
  </div>
108
106
  )
@@ -2,15 +2,11 @@
2
2
 
3
3
  import { ForwardedRef, forwardRef, type AnchorHTMLAttributes, type ReactNode } from 'react'
4
4
  import { Link } from 'react-router-dom'
5
- import type {
6
- IBreadcrumb,
7
- IPktBreadcrumbsBase,
8
- TBreadcrumbsNavigationType,
9
- TRenderLink,
10
- } from 'shared-types'
5
+ import type { IBreadcrumb, IPktBreadcrumbsBase, TBreadcrumbsNavigationType, TRenderLink } from 'shared-types'
11
6
 
12
7
  import { PktIcon } from '../icon/Icon'
13
8
  import { usePktStrings } from '../../hooks/usePktStrings'
9
+ import { withStableKeys } from '../../utils/stableKeys'
14
10
 
15
11
  export type { IBreadcrumb }
16
12
 
@@ -18,8 +14,7 @@ export type { IBreadcrumb }
18
14
  export type IBreadcrumbs = IBreadcrumb
19
15
 
20
16
  export interface IPktBreadcrumbs
21
- extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'children'>,
22
- IPktBreadcrumbsBase {
17
+ extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'children'>, IPktBreadcrumbsBase {
23
18
  navigationType?: TBreadcrumbsNavigationType
24
19
  renderLink?: TRenderLink<ReactNode, AnchorHTMLAttributes<HTMLAnchorElement>>
25
20
  }
@@ -56,8 +51,8 @@ export const PktBreadcrumbs = forwardRef(
56
51
  return (
57
52
  <nav ref={ref} aria-label={s.breadcrumbs.ariaLabel} className={classes}>
58
53
  <ol className="pkt-breadcrumbs__list pkt-breadcrumbs--desktop">
59
- {slicedBreadcrumbs.map((item, index) => (
60
- <li key={`breadcrumb-${index}`} className="pkt-breadcrumbs__item">
54
+ {withStableKeys(slicedBreadcrumbs, (item) => `${item.href}|${item.text}`).map(({ item, key }, index) => (
55
+ <li key={key} className="pkt-breadcrumbs__item">
61
56
  {index === slicedBreadcrumbs.length - 1 ? (
62
57
  <span className="pkt-breadcrumbs__label" aria-current="true">
63
58
  <span className="pkt-breadcrumbs__text">{item.text}</span>
@@ -68,7 +63,11 @@ export const PktBreadcrumbs = forwardRef(
68
63
  className: 'pkt-link pkt-link--icon-right pkt-breadcrumbs__label pkt-breadcrumbs__link',
69
64
  children: (
70
65
  <>
71
- <PktIcon className="pkt-icon pkt-breadcrumbs__icon pkt-link__icon" name="chevron-thin-right" aria-hidden="true" />
66
+ <PktIcon
67
+ className="pkt-icon pkt-breadcrumbs__icon pkt-link__icon"
68
+ name="chevron-thin-right"
69
+ aria-hidden="true"
70
+ />
72
71
  <span className="pkt-breadcrumbs__text">{item.text}</span>
73
72
  </>
74
73
  ),
@@ -84,7 +83,11 @@ export const PktBreadcrumbs = forwardRef(
84
83
  className: 'pkt-link pkt-link--icon-left pkt-breadcrumbs--mobile',
85
84
  children: (
86
85
  <>
87
- <PktIcon className="pkt-back-link__icon pkt-icon pkt-link__icon" name="chevron-thin-left" aria-hidden="true" />
86
+ <PktIcon
87
+ className="pkt-back-link__icon pkt-icon pkt-link__icon"
88
+ name="chevron-thin-left"
89
+ aria-hidden="true"
90
+ />
88
91
  <span className="pkt-breadcrumbs__text">{backLink.text}</span>
89
92
  </>
90
93
  ),
@@ -119,9 +119,7 @@ describe('PktCalendar', () => {
119
119
  expect(grid).toHaveAttribute('aria-multiselectable', 'true')
120
120
 
121
121
  // Select 3 dates - all should work
122
- const availableDates = container.querySelectorAll(
123
- '.pkt-calendar__date:not(.pkt-calendar__date--disabled)',
124
- )
122
+ const availableDates = container.querySelectorAll('.pkt-calendar__date:not(.pkt-calendar__date--disabled)')
125
123
  expect(availableDates.length).toBeGreaterThan(3)
126
124
 
127
125
  fireEvent.click(availableDates[0])
@@ -139,6 +137,23 @@ describe('PktCalendar', () => {
139
137
  expect(monthTitle?.textContent).toContain('Mars')
140
138
  expect(monthTitle?.textContent).toContain('2024')
141
139
  })
140
+
141
+ test('selected date takes precedence over currentmonth', () => {
142
+ const { container } = createCalendar({ currentmonth: '2024-03-15', selected: ['2024-08-10'] })
143
+
144
+ const monthTitle = container.querySelector('.pkt-calendar__month-title')
145
+ expect(monthTitle?.textContent).toContain('August')
146
+ expect(monthTitle?.textContent).toContain('2024')
147
+ })
148
+
149
+ test('follows selected date when it changes', () => {
150
+ const { container, rerender } = render(<PktCalendar selected={['2024-08-10']} />)
151
+ rerender(<PktCalendar selected={['2025-01-05']} />)
152
+
153
+ const monthTitle = container.querySelector('.pkt-calendar__month-title')
154
+ expect(monthTitle?.textContent).toContain('Januar')
155
+ expect(monthTitle?.textContent).toContain('2025')
156
+ })
142
157
  })
143
158
 
144
159
  describe('Month navigation', () => {
@@ -172,9 +187,7 @@ describe('PktCalendar', () => {
172
187
  const nextButton = container.querySelector('.pkt-calendar__next-month')
173
188
  expect(nextButton).toBeInTheDocument()
174
189
 
175
- const monthSelect = container.querySelector(
176
- '.pkt-cal-month-picker select',
177
- ) as HTMLSelectElement
190
+ const monthSelect = container.querySelector('.pkt-cal-month-picker select') as HTMLSelectElement
178
191
  const initialMonth = monthSelect?.value
179
192
 
180
193
  fireEvent.click(nextButton!)
@@ -186,16 +199,12 @@ describe('PktCalendar', () => {
186
199
  test('month navigation updates visible dates', () => {
187
200
  const { container } = createCalendar({ withcontrols: true, currentmonth: '2024-06-15' })
188
201
 
189
- const initialDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map(
190
- (el) => el.textContent,
191
- )
202
+ const initialDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map((el) => el.textContent)
192
203
 
193
204
  const nextButton = container.querySelector('.pkt-calendar__next-month')
194
205
  fireEvent.click(nextButton!)
195
206
 
196
- const newDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map(
197
- (el) => el.textContent,
198
- )
207
+ const newDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map((el) => el.textContent)
199
208
  expect(newDates).not.toEqual(initialDates)
200
209
  })
201
210
  })
@@ -236,10 +245,7 @@ describe('PktCalendar', () => {
236
245
  withcontrols: true,
237
246
  strings: {
238
247
  dates: {
239
- months: [
240
- 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
241
- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
242
- ],
248
+ months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
243
249
  },
244
250
  },
245
251
  })
@@ -19,9 +19,7 @@ export const CalendarNav = ({
19
19
  }: ICalendarNavProps) => {
20
20
  const renderMonthNavButton = (direction: 'prev' | 'next') => {
21
21
  const isPrev = direction === 'prev'
22
- const isAllowed = isPrev
23
- ? checkPrevMonthAllowed(year, month, earliest)
24
- : checkNextMonthAllowed(year, month, latest)
22
+ const isAllowed = isPrev ? checkPrevMonthAllowed(year, month, earliest) : checkNextMonthAllowed(year, month, latest)
25
23
  const label = isPrev ? strings.prevMonth : strings.nextMonth
26
24
  const iconName = isPrev ? 'chevron-thin-left' : 'chevron-thin-right'
27
25
  const btnClassName = isPrev ? 'pkt-calendar__prev-month' : 'pkt-calendar__next-month'
@@ -43,7 +41,9 @@ export const CalendarNav = ({
43
41
  'pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only',
44
42
  btnClassName,
45
43
  !isAllowed && 'pkt-invisible',
46
- ].filter(Boolean).join(' ')}
44
+ ]
45
+ .filter(Boolean)
46
+ .join(' ')}
47
47
  data-disabled={!isAllowed ? 'disabled' : undefined}
48
48
  aria-disabled={!isAllowed || undefined}
49
49
  tabIndex={isAllowed ? 0 : -1}
@@ -59,7 +59,9 @@ export const CalendarNav = ({
59
59
  if (withcontrols) {
60
60
  return (
61
61
  <div className="pkt-cal-month-picker">
62
- <label htmlFor={`${componentId}-monthnav`} className="pkt-hide">{strings.month}</label>
62
+ <label htmlFor={`${componentId}-monthnav`} className="pkt-hide">
63
+ {strings.month}
64
+ </label>
63
65
  <select
64
66
  aria-label={strings.month}
65
67
  className="pkt-input pkt-input-compact"
@@ -71,12 +73,15 @@ export const CalendarNav = ({
71
73
  }}
72
74
  >
73
75
  {strings.months.map((monthName, index) => (
76
+ // eslint-disable-next-line @eslint-react/no-array-index-key
74
77
  <option key={index} value={index}>
75
78
  {monthName}
76
79
  </option>
77
80
  ))}
78
81
  </select>
79
- <label htmlFor={`${componentId}-yearnav`} className="pkt-hide">{strings.year}</label>
82
+ <label htmlFor={`${componentId}-yearnav`} className="pkt-hide">
83
+ {strings.year}
84
+ </label>
80
85
  <input
81
86
  aria-label={strings.year}
82
87
  className="pkt-input pkt-cal-input-year pkt-input-compact"
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
1
+ import { useCallback, useId, useMemo, useRef, useState } from 'react'
2
2
  import { formatISODate, newDate, parseISODateString, newDateFromDate, todayInTz } from 'shared-utils/date-utils'
3
3
  import { CALENDAR_DEFAULTS, type IDateConstraints, type TDateRangeMap } from 'shared-types/calendar'
4
4
  import { isDateExcluded, isDayDisabled as checkDayDisabled } from 'shared-utils/calendar/date-validation'
@@ -59,10 +59,7 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
59
59
  [catalog],
60
60
  )
61
61
 
62
- const todayDate = useMemo(
63
- () => (todayProp ? parseISODateString(todayProp) : todayInTz()),
64
- [todayProp],
65
- )
62
+ const todayDate = useMemo(() => (todayProp ? parseISODateString(todayProp) : todayInTz()), [todayProp])
66
63
 
67
64
  const excludedates = useMemo<Date[]>(() => {
68
65
  if (!excludedatesProp) return []
@@ -75,45 +72,19 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
75
72
 
76
73
  const _selected = useMemo(() => convertSelectedToDates(activeSelected), [activeSelected])
77
74
 
78
- const [year, setYear] = useState<number>(0)
79
- const [month, setMonth] = useState<number>(0)
80
-
81
- const [inRange, setInRange] = useState<TDateRangeMap>({})
82
- const [rangeHovered, setRangeHovered] = useState<Date | null>(null)
83
-
84
- const [focusedDate, setFocusedDate] = useState<string | null>(null)
85
-
86
- const calendarRef = useRef<HTMLDivElement>(null)
87
- const selectableDatesRef = useRef<{ currentDateISO: string; isDisabled: boolean; tabindex: string }[]>([])
88
- const tabIndexSetRef = useRef<number>(0)
89
- const currentmonthtouchedRef = useRef<boolean>(false)
90
- const initializedRef = useRef<boolean>(false)
91
-
92
- const dateConstraints = useMemo<IDateConstraints>(
93
- () => ({ earliest, latest, excludedates, excludeweekdays }),
94
- [earliest, latest, excludedates, excludeweekdays],
95
- )
75
+ const resolveInitialMonth = (): Date => {
76
+ const lastSelected =
77
+ activeSelected.length > 0 && activeSelected[0] !== ''
78
+ ? parseISODateString(activeSelected[activeSelected.length - 1])
79
+ : null
80
+ if (lastSelected && !isNaN(lastSelected.getTime())) return lastSelected
96
81
 
97
- useEffect(() => {
98
82
  let effectiveMonth: Date | null = null
99
-
100
- if (currentmonthProp != null) {
101
- if (currentmonthProp instanceof Date) {
102
- effectiveMonth = newDateFromDate(currentmonthProp)
103
- } else if (typeof currentmonthProp === 'string') {
104
- effectiveMonth = parseISODateString(currentmonthProp)
105
- }
106
- }
107
-
108
- if (!effectiveMonth || isNaN(effectiveMonth.getTime())) {
109
- if (activeSelected.length > 0 && activeSelected[0] !== '') {
110
- const d = parseISODateString(activeSelected[activeSelected.length - 1])
111
- effectiveMonth = isNaN(d.getTime()) ? newDateFromDate(todayDate) : d
112
- } else {
113
- effectiveMonth = newDateFromDate(todayDate)
114
- }
83
+ if (currentmonthProp instanceof Date) {
84
+ effectiveMonth = newDateFromDate(currentmonthProp)
85
+ } else if (typeof currentmonthProp === 'string') {
86
+ effectiveMonth = parseISODateString(currentmonthProp)
115
87
  }
116
-
117
88
  if (!effectiveMonth || isNaN(effectiveMonth.getTime())) {
118
89
  effectiveMonth = newDateFromDate(todayDate)
119
90
  }
@@ -131,34 +102,50 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
131
102
  effectiveMonth = earliestDate
132
103
  }
133
104
  }
105
+ return effectiveMonth
106
+ }
134
107
 
135
- setYear(effectiveMonth.getFullYear())
136
- setMonth(effectiveMonth.getMonth())
137
- initializedRef.current = true
138
- }, [])
108
+ const [year, setYear] = useState<number>(() => resolveInitialMonth().getFullYear())
109
+ const [month, setMonth] = useState<number>(() => resolveInitialMonth().getMonth())
110
+
111
+ const [inRange, setInRange] = useState<TDateRangeMap>(() =>
112
+ range && _selected.length === 2 ? calculateRangeMap(_selected[0], _selected[1]) : {},
113
+ )
114
+ const [rangeHovered, setRangeHovered] = useState<Date | null>(null)
139
115
 
140
- // Sync when selected changes externally (controlled mode)
141
- useEffect(() => {
142
- if (!initializedRef.current) return
143
- if (currentmonthtouchedRef.current) return
116
+ const [focusedDate, setFocusedDate] = useState<string | null>(null)
117
+
118
+ const calendarRef = useRef<HTMLDivElement>(null)
119
+ const selectableDatesRef = useRef<{ currentDateISO: string; isDisabled: boolean; tabindex: string }[]>([])
120
+ const tabIndexSetRef = useRef<number>(0)
121
+ const [currentmonthTouched, setCurrentmonthTouched] = useState(false)
144
122
 
145
- if (activeSelected.length > 0 && activeSelected[0] !== '') {
123
+ const [prevActiveSelected, setPrevActiveSelected] = useState(activeSelected)
124
+ if (activeSelected !== prevActiveSelected) {
125
+ setPrevActiveSelected(activeSelected)
126
+ if (!currentmonthTouched && activeSelected.length > 0 && activeSelected[0] !== '') {
146
127
  const d = parseISODateString(activeSelected[activeSelected.length - 1])
147
128
  if (!isNaN(d.getTime())) {
148
129
  setYear(d.getFullYear())
149
130
  setMonth(d.getMonth())
150
131
  }
151
132
  }
152
- }, [activeSelected])
133
+ }
153
134
 
154
- // Sync range map when selected changes
155
- useEffect(() => {
135
+ const [prevRangeInput, setPrevRangeInput] = useState({ range, _selected })
136
+ if (range !== prevRangeInput.range || _selected !== prevRangeInput._selected) {
137
+ setPrevRangeInput({ range, _selected })
156
138
  if (range && _selected.length === 2) {
157
139
  setInRange(calculateRangeMap(_selected[0], _selected[1]))
158
140
  } else if (!range || _selected.length < 2) {
159
141
  setInRange({})
160
142
  }
161
- }, [range, _selected])
143
+ }
144
+
145
+ const dateConstraints = useMemo<IDateConstraints>(
146
+ () => ({ earliest, latest, excludedates, excludeweekdays }),
147
+ [earliest, latest, excludedates, excludeweekdays],
148
+ )
162
149
 
163
150
  const updateSelected = useCallback(
164
151
  (newSelected: string[]) => {
@@ -180,7 +167,7 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
180
167
  tabIndexSetRef.current = 0
181
168
  setFocusedDate(null)
182
169
  selectableDatesRef.current = []
183
- currentmonthtouchedRef.current = true
170
+ setCurrentmonthTouched(true)
184
171
  }, [])
185
172
 
186
173
  const prevMonth = useCallback(() => {
@@ -2,14 +2,17 @@
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
5
+ import { plural, type IPktStringsProps } from 'shared-strings'
5
6
  import { CARD_DEFAULTS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
6
7
 
7
8
  import { PktHeading } from '../heading/Heading'
8
9
  import { PktTag } from '../tag/Tag'
10
+ import { usePktStrings } from '../../hooks/usePktStrings'
11
+ import { withStableKeys } from '../../utils/stableKeys'
9
12
 
10
13
  export type { TCardSkin, TLayout }
11
14
 
12
- export interface IPktCard extends IPktCardBase, Omit<HTMLAttributes<HTMLElement>, 'title'> {
15
+ export interface IPktCard extends IPktCardBase, Omit<HTMLAttributes<HTMLElement>, 'title'>, IPktStringsProps<'card'> {
13
16
  children?: ReactNode
14
17
  ref?: Ref<HTMLElement>
15
18
  }
@@ -38,10 +41,12 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
38
41
  tagPosition = CARD_DEFAULTS.tagPosition,
39
42
  zoom = CARD_DEFAULTS.zoom,
40
43
  tags = [],
44
+ strings,
41
45
  ...props
42
46
  },
43
47
  ref,
44
48
  ) => {
49
+ const s = usePktStrings(['card'], strings)
45
50
  const classes = classNames({
46
51
  'pkt-card': true,
47
52
  [`pkt-card--${skin}`]: skin,
@@ -57,7 +62,14 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
57
62
  const renderImage = () => {
58
63
  if (!image?.src) return null
59
64
  return (
60
- <div className={classNames('pkt-card__image', `pkt-card__image-${imageShape}`, imageAspect && `pkt-card__image-aspect-${imageAspect}`, restrictImageHeight && 'pkt-card__image-restricted')}>
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
73
  <img src={image.src} alt={image.alt || ''} />
62
74
  </div>
63
75
  )
@@ -69,11 +81,11 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
69
81
  <div
70
82
  className={classNames('pkt-card__tags', `pkt-card__tags-${tagPosition}`)}
71
83
  role="list"
72
- aria-label={tags.length > 1 ? 'merkelapper' : 'merkelapp'}
84
+ aria-label={plural(tags.length, s.card.tagsLabelOne, s.card.tagsLabelOther)}
73
85
  >
74
- {tags.map((tag, index) => (
86
+ {withStableKeys(tags, (tag) => tag.text).map(({ item: tag, key }) => (
75
87
  <PktTag
76
- key={index}
88
+ key={key}
77
89
  role="listitem"
78
90
  textStyle="normal-text"
79
91
  size="medium"
@@ -10,29 +10,14 @@ import {
10
10
  } from 'react'
11
11
  import { usePktStrings } from '../../hooks/usePktStrings'
12
12
  import { useGeneratedId } from '../../hooks/useGeneratedId'
13
- import type { IPktStringsProps } from 'shared-strings'
13
+ import { CHECKBOX_DEFAULTS, type IPktCheckboxBase } from 'shared-types'
14
14
 
15
- export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
15
+ export interface IPktCheckbox
16
+ extends
17
+ Omit<IPktCheckboxBase, 'id' | 'checkHelptext'>,
18
+ Omit<InputHTMLAttributes<HTMLInputElement>, keyof IPktCheckboxBase> {
16
19
  id: string
17
- hasTile?: boolean
18
- disabled?: boolean
19
- label?: string
20
20
  checkHelptext?: ReactNode | ReactNode[] | string
21
- hasError?: boolean
22
- defaultChecked?: boolean
23
- checked?: boolean
24
- indeterminate?: boolean
25
- value?: string
26
- isSwitch?: boolean
27
- hideLabel?: boolean
28
- labelPosition?: 'right' | 'left'
29
- optionalTag?: boolean
30
- /** @deprecated Bruk `strings={{ forms: { optional: '…' } }}` eller `setPktStrings()`. */
31
- optionalText?: string
32
- requiredTag?: boolean
33
- /** @deprecated Bruk `strings={{ forms: { required: '…' } }}` eller `setPktStrings()`. */
34
- requiredText?: string
35
- tagText?: string | null
36
21
  onChange?: ChangeEventHandler<HTMLInputElement>
37
22
  }
38
23
 
@@ -40,15 +25,15 @@ export const PktCheckbox = forwardRef(
40
25
  (
41
26
  {
42
27
  id: idProp,
43
- hasTile = false,
44
- disabled = false,
28
+ hasTile = CHECKBOX_DEFAULTS.hasTile,
29
+ disabled = CHECKBOX_DEFAULTS.disabled,
45
30
  label,
46
31
  checkHelptext,
47
- hasError = false,
32
+ hasError = CHECKBOX_DEFAULTS.hasError,
48
33
  className,
49
- isSwitch = false,
50
- hideLabel = false,
51
- labelPosition = 'right',
34
+ isSwitch = CHECKBOX_DEFAULTS.isSwitch,
35
+ hideLabel = CHECKBOX_DEFAULTS.hideLabel,
36
+ labelPosition = CHECKBOX_DEFAULTS.labelPosition,
52
37
  defaultChecked,
53
38
  checked,
54
39
  indeterminate,