@oslokommune/punkt-react 18.5.0 → 18.6.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.
@@ -5,6 +5,73 @@
5
5
  * Used by both Elements and React calendar implementations
6
6
  * and by the shared calendar helper functions.
7
7
  */
8
+ import type { IPktStringsProps } from '../shared-strings';
9
+ /** Calendar props shared by React and Elements. */
10
+ export interface IPktCalendarBase extends IPktStringsProps<'dates' | 'calendar'> {
11
+ id?: string;
12
+ currentmonth?: Date | string | null;
13
+ selected?: string[];
14
+ excludeweekdays?: string[];
15
+ excludedates?: Date[] | string[];
16
+ earliest?: string | null;
17
+ latest?: string | null;
18
+ weeknumbers?: boolean;
19
+ withcontrols?: boolean;
20
+ multiple?: boolean;
21
+ maxMultiple?: number;
22
+ range?: boolean;
23
+ today?: string | null;
24
+ }
25
+ export declare const CALENDAR_DEFAULTS: {
26
+ readonly multiple: false;
27
+ readonly maxMultiple: 0;
28
+ readonly range: false;
29
+ readonly earliest: any;
30
+ readonly latest: any;
31
+ readonly weeknumbers: false;
32
+ readonly withcontrols: false;
33
+ };
34
+ /**
35
+ * Documented Calendar props (subset of `IPktCalendarBase`), plus the
36
+ * React-only selection/close callbacks and the Elements-only deprecated
37
+ * per-string props that `strings` / `setPktStrings()` have superseded.
38
+ */
39
+ export type ICalendarSpecProps = Pick<IPktCalendarBase, 'id' | 'currentmonth' | 'selected' | 'excludeweekdays' | 'excludedates' | 'earliest' | 'latest' | 'weeknumbers' | 'withcontrols' | 'multiple' | 'maxMultiple' | 'range' | 'today'> & {
40
+ /**
41
+ * React-only callback fired with the updated selection (ISO date strings).
42
+ * @remarks Elements-paritet: `date-selected`-eventet.
43
+ */
44
+ onDateSelected?: (selected: string[]) => void;
45
+ /**
46
+ * React-only callback fired when the calendar requests to close (Escape or focus-out).
47
+ * @remarks Elements-paritet: `close`-eventet.
48
+ */
49
+ onClose?: () => void;
50
+ /**
51
+ * @deprecated Elements-only. Bruk `strings={{ dates: { daysShort: [...] } }}` eller `setPktStrings()`.
52
+ */
53
+ dayStrings?: string[];
54
+ /**
55
+ * @deprecated Elements-only. Bruk `strings={{ dates: { days: [...] } }}` eller `setPktStrings()`.
56
+ */
57
+ dayStringsLong?: string[];
58
+ /**
59
+ * @deprecated Elements-only. Bruk `strings={{ dates: { months: [...] } }}` eller `setPktStrings()`.
60
+ */
61
+ monthStrings?: string[];
62
+ /**
63
+ * @deprecated Elements-only. Bruk `strings={{ dates: { week: '...' } }}` eller `setPktStrings()`.
64
+ */
65
+ weekString?: string;
66
+ /**
67
+ * @deprecated Elements-only. Bruk `strings={{ calendar: { prevMonth: '...' } }}` eller `setPktStrings()`.
68
+ */
69
+ prevMonthString?: string;
70
+ /**
71
+ * @deprecated Elements-only. Bruk `strings={{ calendar: { nextMonth: '...' } }}` eller `setPktStrings()`.
72
+ */
73
+ nextMonthString?: string;
74
+ };
8
75
  export interface IDateConstraints {
9
76
  earliest: string | null;
10
77
  latest: string | null;
@@ -25,7 +25,8 @@ export type { IRenderLink, TRenderLink } from './render-link';
25
25
  export type { IPktStringsProps } from '../shared-strings';
26
26
  export type { IHelptextProps, ITagOptionalRequiredProps, IFormFieldLabelProps, IFormFieldErrorProps, IFormFieldCommonProps, TFormFieldCommonSpecKeys, } from './form-field';
27
27
  export type { TMessageboxSkin, TCardSkin, TTagSkin } from './skin';
28
- export type { IDateConstraints, ICalendarGridDimensions, IGridCellPosition, TDateRangeMap, ISelectionState, ISelectionOptions, } from './calendar';
28
+ export { CALENDAR_DEFAULTS } from './calendar';
29
+ export type { IPktCalendarBase, ICalendarSpecProps, IDateConstraints, ICalendarGridDimensions, IGridCellPosition, TDateRangeMap, ISelectionState, ISelectionOptions, } from './calendar';
29
30
  export type { IDatepickerStrings } from './datepicker';
30
31
  export { defaultSingleStrings, defaultRangeStrings } from './datepicker';
31
32
  export type { ITimepickerStrings } from './timepicker';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "18.5.0",
3
+ "version": "18.6.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",
@@ -44,8 +44,8 @@
44
44
  "@eslint/compat": "^2.1.0",
45
45
  "@eslint/eslintrc": "^3.3.5",
46
46
  "@eslint/js": "^10.0.1",
47
- "@oslokommune/punkt-assets": "^18.0.0",
48
- "@oslokommune/punkt-css": "^18.5.0",
47
+ "@oslokommune/punkt-assets": "^18.5.1",
48
+ "@oslokommune/punkt-css": "^18.5.1",
49
49
  "@testing-library/jest-dom": "^6.9.1",
50
50
  "@testing-library/react": "^16.3.2",
51
51
  "@testing-library/user-event": "^14.6.1",
@@ -102,5 +102,5 @@
102
102
  "url": "https://github.com/oslokommune/punkt/issues"
103
103
  },
104
104
  "license": "MIT",
105
- "gitHead": "dd8d7102f860aab26f29b63534788f27a8d52cf6"
105
+ "gitHead": "054139e3e0fadc58e7404bef71a5ed2f74d5ca8b"
106
106
  }
@@ -1,6 +1,4 @@
1
- import type { IDateConstraints, TDateRangeMap } from 'shared-types/calendar'
2
-
3
- import type { IPktStringsProps } from 'shared-strings'
1
+ import type { IDateConstraints, IPktCalendarBase, TDateRangeMap } from 'shared-types/calendar'
4
2
 
5
3
  /** Datonavn og navigasjonstekster slik kalender-underkomponentene forventer dem. */
6
4
  export interface IPktCalendarStrings {
@@ -23,31 +21,12 @@ export interface PktCalendarHandle {
23
21
  close: () => void
24
22
  }
25
23
 
26
- export interface IPktCalendar extends IPktStringsProps<'dates' | 'calendar'> {
27
- // Selection
28
- selected?: string[]
29
- multiple?: boolean
30
- maxMultiple?: number
31
- range?: boolean
32
-
33
- // Constraints
34
- earliest?: string | null
35
- latest?: string | null
36
- excludedates?: Date[] | string[]
37
- excludeweekdays?: string[]
38
-
39
- // Display
40
- weeknumbers?: boolean
41
- withcontrols?: boolean
42
- currentmonth?: Date | string | null
43
- today?: string
44
-
24
+ export interface IPktCalendar extends IPktCalendarBase {
45
25
  // Callbacks
46
26
  onDateSelected?: (selected: string[]) => void
47
27
  onClose?: () => void
48
28
 
49
29
  // React standard
50
- id?: string
51
30
  className?: string
52
31
  }
53
32
 
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
2
2
  import { formatISODate, newDate, parseISODateString, newDateFromDate, todayInTz } from 'shared-utils/date-utils'
3
- import type { IDateConstraints, TDateRangeMap } from 'shared-types/calendar'
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'
5
5
  import {
6
6
  convertSelectedToDates,
@@ -23,15 +23,15 @@ import { usePktStrings } from '../../hooks/usePktStrings'
23
23
  export function useCalendarState(props: IPktCalendar): ICalendarState {
24
24
  const {
25
25
  selected: selectedProp,
26
- multiple = false,
27
- maxMultiple = 0,
28
- range = false,
29
- earliest = null,
30
- latest = null,
26
+ multiple = CALENDAR_DEFAULTS.multiple,
27
+ maxMultiple = CALENDAR_DEFAULTS.maxMultiple,
28
+ range = CALENDAR_DEFAULTS.range,
29
+ earliest = CALENDAR_DEFAULTS.earliest,
30
+ latest = CALENDAR_DEFAULTS.latest,
31
31
  excludedates: excludedatesProp,
32
32
  excludeweekdays = [],
33
- weeknumbers = false,
34
- withcontrols = false,
33
+ weeknumbers = CALENDAR_DEFAULTS.weeknumbers,
34
+ withcontrols = CALENDAR_DEFAULTS.withcontrols,
35
35
  currentmonth: currentmonthProp,
36
36
  today: todayProp,
37
37
  strings: stringsProp,