@oslokommune/punkt-react 18.5.1 → 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.
- package/CHANGELOG.md +17 -0
- package/dist/components/calendar/types.d.ts +2 -16
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +593 -585
- package/dist/shared-types/calendar.d.ts +67 -0
- package/dist/shared-types/index.d.ts +2 -1
- package/package.json +2 -2
- package/src/components/calendar/types.ts +2 -23
- package/src/components/calendar/useCalendarState.ts +8 -8
|
@@ -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
|
|
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.
|
|
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",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
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
|
|
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
|
|
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 =
|
|
27
|
-
maxMultiple =
|
|
28
|
-
range =
|
|
29
|
-
earliest =
|
|
30
|
-
latest =
|
|
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 =
|
|
34
|
-
withcontrols =
|
|
33
|
+
weeknumbers = CALENDAR_DEFAULTS.weeknumbers,
|
|
34
|
+
withcontrols = CALENDAR_DEFAULTS.withcontrols,
|
|
35
35
|
currentmonth: currentmonthProp,
|
|
36
36
|
today: todayProp,
|
|
37
37
|
strings: stringsProp,
|