@oslokommune/punkt-react 18.6.0 → 18.7.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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * card.ts
3
+ *
4
+ * Type definitions for pkt-card.
5
+ * Used by React, Elements, and typed component specs.
6
+ */
7
+ import type { THeadingLevel } from './heading';
8
+ import type { TLayout } from './layout';
9
+ import type { TTagSkin } from './skin';
10
+ /** Card skin variants — shared runtime source for types, specs, and Preview. */
11
+ export declare const CARD_SKINS: readonly ['outlined', 'outlined-beige', 'gray', 'blue', 'beige', 'green'];
12
+ export type TCardSkin = (typeof CARD_SKINS)[number];
13
+ /** Card padding variants — shared runtime source for types, specs, and Preview. */
14
+ export declare const CARD_PADDINGS: readonly ['none', 'default'];
15
+ export type TCardPadding = (typeof CARD_PADDINGS)[number];
16
+ /** Card image shape variants — shared runtime source for types, specs, and Preview. */
17
+ export declare const CARD_IMAGE_SHAPES: readonly ['square', 'round'];
18
+ export type TCardImageShape = (typeof CARD_IMAGE_SHAPES)[number];
19
+ /** Card image aspect-ratio overrides — shared runtime source for types, specs, and Preview. */
20
+ export declare const CARD_IMAGE_ASPECTS: readonly ['auto', '1-1', '4-3', '3-2', '16-9', '19-10'];
21
+ export type TCardImageAspect = (typeof CARD_IMAGE_ASPECTS)[number];
22
+ /** Card tag-row placement — shared runtime source for types, specs, and Preview. */
23
+ export declare const CARD_TAG_POSITIONS: readonly ['top', 'bottom'];
24
+ export type TCardTagPosition = (typeof CARD_TAG_POSITIONS)[number];
25
+ /**
26
+ * Curated tag skins offered for Card's `tags` prop in Preview/docs.
27
+ * `ICardTag.skin` itself stays the full `TTagSkin` union — this is a
28
+ * documented/recommended subset, not a type restriction.
29
+ */
30
+ export declare const CARD_TAG_SKIN_OPTIONS: readonly ['blue', 'green', 'red', 'yellow'];
31
+ /** One tag rendered in Card's tag row. */
32
+ export interface ICardTag {
33
+ skin?: TTagSkin;
34
+ iconName?: string;
35
+ ariaLabel?: string;
36
+ text: string;
37
+ }
38
+ /** Card's `image` prop. */
39
+ export interface ICardImage {
40
+ src: string;
41
+ alt?: string;
42
+ }
43
+ /** Card props shared by React and Elements. */
44
+ export interface IPktCardBase {
45
+ ariaLabel?: string;
46
+ metaLead?: string | null;
47
+ metaTrail?: string | null;
48
+ layout?: TLayout;
49
+ heading?: string;
50
+ headingLevel?: THeadingLevel;
51
+ image?: ICardImage;
52
+ imageShape?: TCardImageShape;
53
+ imageAspect?: TCardImageAspect;
54
+ restrictImageHeight?: boolean;
55
+ clickCardLink?: string | null;
56
+ openLinkInNewTab?: boolean;
57
+ borderOnHover?: boolean;
58
+ zoom?: boolean;
59
+ padding?: TCardPadding;
60
+ skin?: TCardSkin;
61
+ subheading?: string;
62
+ tagPosition?: TCardTagPosition;
63
+ tags?: ICardTag[];
64
+ }
65
+ /**
66
+ * Documented Card props (subset of `IPktCardBase`).
67
+ * Used for typed component specs in documentation. Every Card prop is
68
+ * shared between React and Elements — there are no reactOnly/elementsOnly
69
+ * props or events on this component.
70
+ */
71
+ export type ICardSpecProps = Pick<IPktCardBase, 'ariaLabel' | 'metaLead' | 'metaTrail' | 'layout' | 'heading' | 'headingLevel' | 'image' | 'imageShape' | 'imageAspect' | 'restrictImageHeight' | 'clickCardLink' | 'openLinkInNewTab' | 'borderOnHover' | 'zoom' | 'padding' | 'skin' | 'subheading' | 'tagPosition' | 'tags'>;
72
+ /**
73
+ * Default values for pkt-card. Single source of truth for both frameworks
74
+ */
75
+ export declare const CARD_DEFAULTS: {
76
+ readonly headingLevel: 3;
77
+ readonly layout: 'vertical';
78
+ readonly skin: 'outlined';
79
+ readonly padding: 'default';
80
+ readonly tagPosition: 'top';
81
+ readonly openLinkInNewTab: false;
82
+ readonly borderOnHover: true;
83
+ readonly zoom: false;
84
+ readonly imageShape: 'square';
85
+ readonly restrictImageHeight: false;
86
+ };
@@ -9,6 +9,9 @@ export { HEADER_MENU_LOCALES, DEFAULT_HEADER_FOOTER_URL, DEFAULT_HEADER_LOGO_LIN
9
9
  export type { THeaderMenuLocale, IHeaderMenuLink, IHeaderMenuIconLink, IHeaderMenuButton, IHeaderMenuServices, IHeaderMenuSection, IMegaMenu, IHeaderFooter, IHeaderFooterLocaleData, THeaderFooterApi, IPktHeaderMenu, IPktHeaderGlobal, } from './header-footer';
10
10
  export type { IPktFooterLink, IPktFooterColumn, IPktFooterSocialLink, IPktFooterBase, IPktFooterProps, IPktFooterSimpleProps, IFooterSimpleSpecProps, IFooterSpecProps, } from './footer';
11
11
  export { DEFAULT_FOOTER_PERSONVERN_URL, DEFAULT_FOOTER_TILGJENGELIGHET_URL } from './footer';
12
+ export { CARD_SKINS, CARD_PADDINGS, CARD_IMAGE_SHAPES, CARD_IMAGE_ASPECTS, CARD_TAG_POSITIONS, CARD_TAG_SKIN_OPTIONS, CARD_DEFAULTS } from './card';
13
+ export type { TCardSkin, TCardPadding, TCardImageShape, TCardImageAspect, TCardTagPosition, ICardTag, ICardImage, IPktCardBase, ICardSpecProps, } from './card';
14
+ export { LAYOUT_DIRECTIONS } from './layout';
12
15
  export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
13
16
  export type { THTMLButtonType, TSelectionMode } from './form';
14
17
  export type { TPktInputSize, TSize3, TSize5, TSize7 } from './size';
@@ -24,7 +27,7 @@ export type { TBreadcrumbsNavigationType, IBreadcrumb, IBreadcrumbItem, IBreadcr
24
27
  export type { IRenderLink, TRenderLink } from './render-link';
25
28
  export type { IPktStringsProps } from '../shared-strings';
26
29
  export type { IHelptextProps, ITagOptionalRequiredProps, IFormFieldLabelProps, IFormFieldErrorProps, IFormFieldCommonProps, TFormFieldCommonSpecKeys, } from './form-field';
27
- export type { TMessageboxSkin, TCardSkin, TTagSkin } from './skin';
30
+ export type { TMessageboxSkin, TTagSkin } from './skin';
28
31
  export { CALENDAR_DEFAULTS } from './calendar';
29
32
  export type { IPktCalendarBase, ICalendarSpecProps, IDateConstraints, ICalendarGridDimensions, IGridCellPosition, TDateRangeMap, ISelectionState, ISelectionOptions, } from './calendar';
30
33
  export type { IDatepickerStrings } from './datepicker';
@@ -7,7 +7,8 @@
7
7
  /**
8
8
  * Layout direction - vertical or horizontal orientation
9
9
  */
10
- export type TLayout = 'vertical' | 'horizontal';
10
+ export declare const LAYOUT_DIRECTIONS: readonly ['vertical', 'horizontal'];
11
+ export type TLayout = (typeof LAYOUT_DIRECTIONS)[number];
11
12
  /**
12
13
  * Generic positioning type for top/bottom placement
13
14
  */
@@ -7,14 +7,11 @@
7
7
  */
8
8
  export { ALERT_SKINS, type TAlertSkin } from './alert';
9
9
  export { ACCORDION_SKINS, type TAccordionSkin } from './accordion';
10
+ export { CARD_SKINS, type TCardSkin } from './card';
10
11
  /**
11
12
  * Messagebox component skin variants
12
13
  */
13
14
  export type TMessageboxSkin = 'beige' | 'blue' | 'red' | 'green';
14
- /**
15
- * Card component skin variants
16
- */
17
- export type TCardSkin = 'outlined' | 'outlined-beige' | 'gray' | 'beige' | 'green' | 'blue';
18
15
  /**
19
16
  * Tag component skin variants
20
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "18.6.0",
3
+ "version": "18.7.0",
4
4
  "description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo Origo",
@@ -102,5 +102,5 @@
102
102
  "url": "https://github.com/oslokommune/punkt/issues"
103
103
  },
104
104
  "license": "MIT",
105
- "gitHead": "054139e3e0fadc58e7404bef71a5ed2f74d5ca8b"
105
+ "gitHead": "4c21f73f787855c7ecdcb53fdbe2d2494af949b0"
106
106
  }
@@ -2,45 +2,14 @@
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
5
- import type { TCardSkin, TLayout, TTagSkin } from 'shared-types'
5
+ import { CARD_DEFAULTS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
6
6
 
7
7
  import { PktHeading } from '../heading/Heading'
8
8
  import { PktTag } from '../tag/Tag'
9
9
 
10
10
  export type { TCardSkin, TLayout }
11
- type TCardPadding = 'none' | 'default'
12
- type TCardImageShape = 'square' | 'round'
13
- type TCardImageAspect = 'auto' | '1-1' | '4-3' | '3-2' | '16-9' | '19-10'
14
- type TCardTagPosition = 'top' | 'bottom'
15
- type THeadingLevel = 1 | 2 | 3 | 4 | 5 | 6
16
11
 
17
- interface ICardTag {
18
- skin?: TTagSkin
19
- iconName?: string
20
- ariaLabel?: string
21
- text: string
22
- }
23
-
24
- export interface IPktCard extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
25
- ariaLabel?: string
26
- metaLead?: string | null
27
- borderOnHover?: boolean
28
- zoom?: boolean
29
- metaTrail?: string | null
30
- layout?: TLayout
31
- heading?: string
32
- headingLevel?: THeadingLevel
33
- image?: { src: string; alt: string }
34
- imageShape?: TCardImageShape
35
- imageAspect?: TCardImageAspect
36
- restrictImageHeight?: boolean
37
- clickCardLink?: string | null
38
- padding?: TCardPadding
39
- openLinkInNewTab?: boolean
40
- skin?: TCardSkin
41
- subheading?: string
42
- tagPosition?: TCardTagPosition
43
- tags?: ICardTag[]
12
+ export interface IPktCard extends IPktCardBase, Omit<HTMLAttributes<HTMLElement>, 'title'> {
44
13
  children?: ReactNode
45
14
  ref?: Ref<HTMLElement>
46
15
  }
@@ -52,22 +21,22 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
52
21
  className,
53
22
  ariaLabel,
54
23
  metaLead,
55
- borderOnHover = true,
24
+ borderOnHover = CARD_DEFAULTS.borderOnHover,
56
25
  metaTrail,
57
- layout = 'vertical',
26
+ layout = CARD_DEFAULTS.layout,
58
27
  heading = '',
59
- headingLevel = 3,
28
+ headingLevel = CARD_DEFAULTS.headingLevel,
60
29
  image,
61
- imageShape = 'square',
30
+ imageShape = CARD_DEFAULTS.imageShape,
62
31
  imageAspect,
63
- restrictImageHeight = false,
32
+ restrictImageHeight = CARD_DEFAULTS.restrictImageHeight,
64
33
  clickCardLink,
65
- padding = 'default',
66
- openLinkInNewTab = false,
67
- skin = 'outlined',
34
+ padding = CARD_DEFAULTS.padding,
35
+ openLinkInNewTab = CARD_DEFAULTS.openLinkInNewTab,
36
+ skin = CARD_DEFAULTS.skin,
68
37
  subheading = '',
69
- tagPosition = 'top',
70
- zoom = false,
38
+ tagPosition = CARD_DEFAULTS.tagPosition,
39
+ zoom = CARD_DEFAULTS.zoom,
71
40
  tags = [],
72
41
  ...props
73
42
  },
@@ -153,7 +153,7 @@ describe('PktDatepicker', () => {
153
153
 
154
154
  const button = container.querySelector('button[type="button"]')
155
155
  expect(button).toBeInTheDocument()
156
- expect(button).toHaveAttribute('aria-label', 'Åpne kalender')
156
+ expect(button).toHaveAccessibleName('Åpne kalender')
157
157
  })
158
158
 
159
159
  test('input has aria-describedby when helptext is present', () => {
@@ -162,7 +162,9 @@ describe('PktDatepicker', () => {
162
162
  })
163
163
 
164
164
  const input = container.querySelector('input[type="date"]') as HTMLInputElement
165
- expect(input).toHaveAttribute('aria-describedby', `${datePickerId}-helptext`)
165
+ const describedby = input.getAttribute('aria-describedby')
166
+ expect(describedby).toBe(`${datePickerId}-input-helptext`)
167
+ expect(container.querySelector(`#${describedby}`)).not.toBeNull()
166
168
  })
167
169
 
168
170
  test('input does not have aria-describedby when no helptext', () => {
@@ -189,7 +191,9 @@ describe('PktDatepicker', () => {
189
191
  })
190
192
 
191
193
  const input = container.querySelector('input[type="date"]') as HTMLInputElement
192
- expect(input).toHaveAttribute('aria-errormessage', `${datePickerId}-error`)
194
+ const errormessage = input.getAttribute('aria-errormessage')
195
+ expect(errormessage).toBe(`${datePickerId}-input-error`)
196
+ expect(container.querySelector(`#${errormessage}`)).not.toBeNull()
193
197
  })
194
198
 
195
199
  test('input does not have aria-invalid when no error', () => {
@@ -261,7 +265,7 @@ describe('PktDatepicker', () => {
261
265
  })
262
266
 
263
267
  const button = container.querySelector('button[type="button"]')
264
- expect(button).toHaveAttribute('aria-label', 'Open calendar')
268
+ expect(button).toHaveAccessibleName('Open calendar')
265
269
  })
266
270
 
267
271
  test('uses custom strings for range labels', () => {
@@ -285,7 +289,7 @@ describe('PktDatepicker', () => {
285
289
  })
286
290
 
287
291
  const button = container.querySelector('button[type="button"]')
288
- expect(button).toHaveAttribute('aria-label', 'Åpne kalender')
292
+ expect(button).toHaveAccessibleName('Åpne kalender')
289
293
 
290
294
  const prefix = container.querySelector('.pkt-input-prefix')
291
295
  expect(prefix).toHaveTextContent('Fra')
@@ -72,7 +72,7 @@ describe('PktDatepicker', () => {
72
72
 
73
73
  const button = container.querySelector('button[type="button"]')
74
74
  expect(button).toBeInTheDocument()
75
- expect(button).toHaveAttribute('aria-label', 'Åpne kalender')
75
+ expect(button).toHaveAccessibleName('Åpne kalender')
76
76
  })
77
77
  })
78
78
 
@@ -147,6 +147,29 @@ describe('PktDatepicker', () => {
147
147
  })
148
148
 
149
149
  describe('Range selection', () => {
150
+ test('fires change on a complete range and on clearing, not on the first date', () => {
151
+ const fired: string[] = []
152
+ const { container } = createDatepickerTest({
153
+ range: true,
154
+ calendarOpen: true,
155
+ currentmonth: '2026-01',
156
+ onChange: (e: ChangeEvent<HTMLInputElement>) => fired.push(e.target.value),
157
+ })
158
+
159
+ const days = Array.from(container.querySelectorAll('button')).filter((b) =>
160
+ /^\d+$/.test((b.textContent ?? '').trim()),
161
+ )
162
+
163
+ fireEvent.click(days[14])
164
+ expect(fired).toEqual([])
165
+
166
+ fireEvent.click(days[19])
167
+ expect(fired).toEqual(['2026-01-15,2026-01-20'])
168
+
169
+ fireEvent.click(days[14])
170
+ expect(fired).toEqual(['2026-01-15,2026-01-20', ''])
171
+ })
172
+
150
173
  test('renders two inputs for range mode', () => {
151
174
  const { container } = createDatepickerTest({
152
175
  range: true,
@@ -64,7 +64,6 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
64
64
  type="button"
65
65
  onClick={toggleCalendar}
66
66
  disabled={disabled}
67
- aria-label={strings.datepicker.openPicker}
68
67
  >
69
68
  <PktIcon name="calendar" />
70
69
  <span className="pkt-btn__text">{strings.datepicker.openPicker}</span>
@@ -93,9 +92,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
93
92
  placeholder={placeholder}
94
93
  readOnly={readOnly || (isIOSDevice && !readOnly)}
95
94
  disabled={isInputDisabled}
96
- aria-describedby={helptext ? `${id}-helptext` : undefined}
95
+ aria-describedby={helptext ? `${inputId}-helptext` : undefined}
97
96
  aria-invalid={hasError}
98
- aria-errormessage={hasError ? `${id}-error` : undefined}
97
+ aria-errormessage={hasError ? `${inputId}-error` : undefined}
99
98
  onClick={handleInputClick}
100
99
  onTouchEnd={handleInputTouchEnd}
101
100
  onKeyDown={handleMultipleKeydown}
@@ -129,9 +128,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
129
128
  disabled={disabled}
130
129
  required={required}
131
130
  aria-label={`${label} ${strings.generic.from}`}
132
- aria-describedby={helptext ? `${id}-helptext` : undefined}
131
+ aria-describedby={helptext ? `${inputId}-helptext` : undefined}
133
132
  aria-invalid={hasError}
134
- aria-errormessage={hasError ? `${id}-error` : undefined}
133
+ aria-errormessage={hasError ? `${inputId}-error` : undefined}
135
134
  onClick={handleInputClick}
136
135
  onTouchEnd={handleInputTouchEnd}
137
136
  onKeyDown={handleRangeFromKeydown}
@@ -187,9 +186,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
187
186
  readOnly={readOnly || (isIOSDevice && !readOnly)}
188
187
  disabled={disabled}
189
188
  required={required}
190
- aria-describedby={helptext ? `${id}-helptext` : undefined}
189
+ aria-describedby={helptext ? `${inputId}-helptext` : undefined}
191
190
  aria-invalid={hasError}
192
- aria-errormessage={hasError ? `${id}-error` : undefined}
191
+ aria-errormessage={hasError ? `${inputId}-error` : undefined}
193
192
  onClick={handleInputClick}
194
193
  onTouchEnd={handleInputTouchEnd}
195
194
  onKeyDown={handleSingleKeydown}
@@ -188,12 +188,14 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
188
188
 
189
189
  const dispatchChange = useCallback(
190
190
  (newValues: string[]) => {
191
+ // Én dato er ingen fullført periode. Tom er en fullført endring.
192
+ if (range && newValues.length === 1) return
191
193
  const input = changeInputRef.current
192
194
  if (!input || !nativeInputValueSetter) return
193
195
  nativeInputValueSetter.call(input, newValues.join(','))
194
196
  input.dispatchEvent(new Event('input', { bubbles: true }))
195
197
  },
196
- [nativeInputValueSetter],
198
+ [nativeInputValueSetter, range],
197
199
  )
198
200
 
199
201
  // Calendar toggle