@helsenorge/datepicker 13.4.0 → 13.5.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.
Files changed (27) hide show
  1. package/lib/CHANGELOG.md +18 -1
  2. package/lib/DayPicker.js +1969 -0
  3. package/lib/DayPicker.js.map +1 -0
  4. package/lib/components/DatePicker/index.js +5 -1976
  5. package/lib/components/DatePicker/index.js.map +1 -1
  6. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.d.ts +31 -0
  7. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.module.scss +446 -0
  8. package/lib/components/Unsafe_DatePicker/BaseDayPicker/BaseDayPicker.module.scss.d.ts +31 -0
  9. package/lib/components/Unsafe_DatePicker/BaseDayPicker/CustomComponents.d.ts +6 -0
  10. package/lib/components/Unsafe_DatePicker/BaseDayPicker/utils.d.ts +1 -0
  11. package/lib/components/Unsafe_DatePicker/DateInputInternal.d.ts +28 -0
  12. package/lib/components/Unsafe_DatePicker/DatePicker.module.scss +261 -0
  13. package/lib/components/Unsafe_DatePicker/DatePicker.module.scss.d.ts +22 -0
  14. package/lib/components/Unsafe_DatePicker/RangeDatePickers.module.scss +9 -0
  15. package/lib/components/Unsafe_DatePicker/RangeDatePickers.module.scss.d.ts +9 -0
  16. package/lib/components/Unsafe_DatePicker/Unsafe_DatePicker.d.ts +26 -0
  17. package/lib/components/Unsafe_DatePicker/Unsafe_ISODatePicker.d.ts +9 -0
  18. package/lib/components/Unsafe_DatePicker/Unsafe_RangeDatePickers.d.ts +12 -0
  19. package/lib/components/Unsafe_DatePicker/index.d.ts +9 -0
  20. package/lib/components/Unsafe_DatePicker/index.js +3409 -0
  21. package/lib/components/Unsafe_DatePicker/index.js.map +1 -0
  22. package/lib/components/Unsafe_DatePicker/resourceHelper.d.ts +3 -0
  23. package/lib/components/Unsafe_DatePicker/validate.d.ts +1 -0
  24. package/lib/resources/HN.Designsystem.DatePicker.en-GB.json.d.ts +1 -4
  25. package/lib/resources/HN.Designsystem.DatePicker.nb-NO.json.d.ts +1 -6
  26. package/lib/resources/HN.Designsystem.Unsafe_DatePicker.nb-NO.json.d.ts +30 -0
  27. package/package.json +2 -1
@@ -0,0 +1,31 @@
1
+ import { default as React } from 'react';
2
+ import { Locale } from 'date-fns';
3
+ import { DayPickerProps, Labels, Matcher } from 'react-day-picker';
4
+ import { HNDesignsystemUnsafe_DatePicker } from '../../../resources/Resources';
5
+ export type DatePickerModifiers = {
6
+ emphasized?: Date[] | Matcher[];
7
+ partiallyBooked?: Date[] | Matcher[];
8
+ fullyBooked?: Date[] | Matcher[];
9
+ disabled?: Date[] | Matcher[];
10
+ [key: string]: Date[] | Matcher[] | undefined;
11
+ };
12
+ export interface BaseDayPickerProps extends Pick<DayPickerProps, 'startMonth' | 'endMonth' | 'captionLayout' | 'footer' | 'fixedWeeks' | 'animate'> {
13
+ /** The currenlty selected date in the calendar */
14
+ selectedDate?: Date;
15
+ /** Callback for change in selected date */
16
+ onDateChange?: (date: Date | undefined) => void;
17
+ /** Show loading state */
18
+ isLoading?: boolean;
19
+ /** Modifiers for days. Extended from react-day-picker default modifiers */
20
+ modifiers?: DatePickerModifiers;
21
+ /** If a button sohuld be shown in the footer that switches view to current month */
22
+ showGoToTodayButton?: boolean;
23
+ /** Locale used in the calendar texts. Default is nb, norwegian bokmål */
24
+ localeForCalendar?: Locale;
25
+ /** Functions used in ReactDayPicker to customize aria labels on different elements */
26
+ labelsForCalendar?: Partial<Labels>;
27
+ /** Resources for component */
28
+ resources?: Partial<HNDesignsystemUnsafe_DatePicker>;
29
+ }
30
+ declare const BaseDayPicker: (props: BaseDayPickerProps) => React.ReactNode;
31
+ export default BaseDayPicker;
@@ -0,0 +1,446 @@
1
+ /* stylelint-disable custom-property-pattern */
2
+ @use 'sass:map';
3
+ @use '@helsenorge/designsystem-react/scss/font-mixins' as fonts;
4
+ @use '@helsenorge/designsystem-react/scss/breakpoints' as breakpoints;
5
+ @import '@helsenorge/designsystem-react/scss/supernova/styles/colors';
6
+
7
+ // todo: active states når tokens er brukt i figma
8
+
9
+ .root_override {
10
+ --rdp-day_button-border-radius: 0;
11
+ --rdp-day_button-height: 2.375rem;
12
+ --rdp-day_button-width: 2.375rem;
13
+ --rdp-day-width: calc(2.375rem + 0.375rem); // day width + gap 3px
14
+ --rdp-day-height: calc(2.375rem + 0.375rem); // day width + gap 3px
15
+ --rdp-nav_button-width: 2.75rem;
16
+ --rdp-nav_button-height: 2.75rem;
17
+ --rdp-dropdown-gap: 0;
18
+
19
+ width: fit-content;
20
+ border: 1px solid var(--color-action-border-onlight);
21
+ padding: 0.5rem;
22
+ background-color: var(--color-base-background-white);
23
+
24
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
25
+ --rdp-day_button-height: 2.75rem;
26
+ --rdp-day_button-width: 2.75rem;
27
+ --rdp-day-width: calc(2.75rem + 0.375rem); // day width + gap 6px
28
+ --rdp-day-height: calc(2.75rem + 0.375rem); // day width + gap 6px
29
+
30
+ padding: 0.875rem;
31
+ }
32
+
33
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
34
+ --rdp-day_button-height: 2.875rem;
35
+ --rdp-day_button-width: 2.875rem;
36
+ --rdp-day-width: calc(2.875rem + 0.375rem); // day width + gap 6px
37
+ --rdp-day-height: calc(2.875rem + 0.375rem); // day width + gap 6px
38
+ --rdp-nav_button-width: 3rem;
39
+ --rdp-nav_button-height: 3rem;
40
+
41
+ padding: 1rem;
42
+ }
43
+ }
44
+
45
+ @mixin strikethrough-line {
46
+ text-decoration: line-through;
47
+ text-decoration-color: var(--color-disabled-border);
48
+ }
49
+
50
+ @mixin no-strikethrough-line {
51
+ text-decoration: unset;
52
+ }
53
+
54
+ @mixin focus-border {
55
+ outline: 4px solid var(--color-action-border-onlight-focus);
56
+ }
57
+
58
+ @mixin day-indicator($color) {
59
+ &::after {
60
+ content: '';
61
+ position: absolute;
62
+ background-color: if($color == 'blue', var(--color-action-graphics-onlight), var(--color-action-graphics-ondark));
63
+ border-radius: 100%;
64
+ width: 6px;
65
+ height: 6px;
66
+ transform: translateY(calc(0.1875em + 0.5rem));
67
+ }
68
+ }
69
+
70
+ /* by design */
71
+ /* stylelint-disable no-descending-specificity */
72
+ .date {
73
+ &--default {
74
+ .custom_day_button {
75
+ @include fonts.label;
76
+
77
+ color: var(--color-action-graphics-onlight);
78
+
79
+ &:hover:not(:disabled) {
80
+ background: var(--color-action-background-transparent-onlight-hover);
81
+ }
82
+
83
+ &:focus-visible {
84
+ @include focus-border;
85
+ }
86
+ }
87
+ }
88
+
89
+ &--emphasized {
90
+ .custom_day_button {
91
+ color: var(--color-action-graphics-emphasized-onlight);
92
+ border: 1px solid var(--color-action-border-onlight);
93
+ background: var(--color-action-background-transparent-onlight-hover);
94
+
95
+ &:hover:not(:disabled) {
96
+ background: var(--color-action-background-transparent-onlight-active);
97
+ }
98
+
99
+ &:focus-visible {
100
+ @include focus-border;
101
+ }
102
+ }
103
+ }
104
+
105
+ &--today {
106
+ .custom_day_button {
107
+ @include day-indicator('blue');
108
+ }
109
+ }
110
+
111
+ &--disabled {
112
+ .custom_day_button {
113
+ @include strikethrough-line;
114
+ @include fonts.label-subdued;
115
+
116
+ color: var(--color-disabled-text);
117
+ }
118
+ }
119
+
120
+ &--partial {
121
+ .custom_day_button {
122
+ @include strikethrough-line;
123
+
124
+ color: var(--color-action-graphics-emphasized-onlight);
125
+ border: 1px solid var(--color-action-border-onlight);
126
+ background: linear-gradient(180deg, transparent 50%, var(--color-action-background-transparent-onlight-hover) 50%);
127
+
128
+ &:hover:not(:disabled) {
129
+ background: linear-gradient(180deg, transparent 50%, var(--color-action-background-transparent-onlight-active) 50%);
130
+ }
131
+
132
+ &:focus-visible {
133
+ @include focus-border;
134
+ }
135
+ }
136
+ }
137
+
138
+ &--fully {
139
+ .custom_day_button {
140
+ @include strikethrough-line;
141
+ @include fonts.label-subdued;
142
+
143
+ border: 1px dashed var(--color-disabled-border);
144
+ color: var(--color-disabled-text);
145
+ background-color: unset;
146
+
147
+ &:focus-visible {
148
+ @include focus-border;
149
+ }
150
+
151
+ &:hover:not(:disabled) {
152
+ background: var(--core-color-neutral-100);
153
+ }
154
+ }
155
+ }
156
+
157
+ &--selected {
158
+ .custom_day_button {
159
+ --rdp-day_button-border-radius: 100%;
160
+
161
+ @include no-strikethrough-line;
162
+
163
+ background: var(--color-action-graphics-onlight);
164
+ color: var(--color-base-text-ondark);
165
+
166
+ &:hover:not(:disabled) {
167
+ background: var(--color-action-graphics-onlight-hover);
168
+ }
169
+
170
+ &:focus-visible {
171
+ @include focus-border;
172
+
173
+ border: 1px solid var(--color-action-border-ondark-focus);
174
+ }
175
+
176
+ &:active {
177
+ background-color: var(--color-action-background-onlight-active);
178
+ }
179
+ }
180
+ }
181
+
182
+ &--selected.date--today {
183
+ .custom_day_button {
184
+ @include day-indicator('white');
185
+ }
186
+ }
187
+ }
188
+
189
+ .custom_month_caption {
190
+ text-transform: capitalize;
191
+ }
192
+
193
+ .custom_chevron {
194
+ fill: var(--color-action-graphics-onlight);
195
+ }
196
+
197
+ .custom_nav_button {
198
+ border: none;
199
+
200
+ &:focus {
201
+ outline: none;
202
+ }
203
+
204
+ &__circle {
205
+ border: 1px solid var(--color-action-border-onlight);
206
+ border-radius: 100%;
207
+ width: 2rem;
208
+ height: 2rem;
209
+
210
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
211
+ width: 2.375rem;
212
+ height: 2.375rem;
213
+ }
214
+
215
+ :focus-visible > & {
216
+ outline: 2px solid var(--color-action-border-onlight-focus);
217
+ }
218
+
219
+ // todo: fix aria-disabled
220
+ :hover:not([aria-disabled='true']) > & {
221
+ background: var(--core-color-neutral-50);
222
+ }
223
+
224
+ :active:not([aria-disabled='true']) > & {
225
+ background: var(--core-color-neutral-100);
226
+ }
227
+
228
+ svg {
229
+ // sentrer ikonet vertikalt i sirkelen
230
+ // 24px is IconSize.XXSmall
231
+ margin-top: calc((2rem - 24px - 1px) / 2);
232
+ margin-left: -1px;
233
+
234
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
235
+ margin-top: -1px;
236
+ }
237
+ }
238
+ }
239
+ }
240
+
241
+ .loading-overlay {
242
+ position: absolute;
243
+ inset: 2.75rem 0 0;
244
+ background-color: var(--color-action-graphics-ondark);
245
+ display: flex;
246
+ flex-direction: column;
247
+ align-items: center;
248
+ justify-content: center;
249
+ text-align: center;
250
+ }
251
+
252
+ .datepicker-footer {
253
+ max-width: 19.75rem;
254
+ margin-top: 0.25rem;
255
+
256
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
257
+ max-width: 22.375rem;
258
+ }
259
+
260
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
261
+ max-width: 24.25rem;
262
+ }
263
+
264
+ &--with-today-button {
265
+ display: flex;
266
+ flex-flow: row wrap;
267
+ gap: 0 0.25rem;
268
+
269
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
270
+ gap: 0 0.5rem;
271
+ }
272
+ }
273
+ }
274
+
275
+ .custom_caption-label {
276
+ @include fonts.body;
277
+
278
+ font-weight: 400;
279
+ align-items: center;
280
+ }
281
+
282
+ .dropdown_container {
283
+ display: flex;
284
+ align-items: center;
285
+ gap: 0.25rem;
286
+ padding: 0.1875rem 0.25rem 0.1875rem 1rem;
287
+ background-color: var(--core-color-white);
288
+ border: none;
289
+ font-size: 1.125rem;
290
+ line-height: 150%;
291
+ font-weight: 400;
292
+ margin: 2px; // gir plass til fokusstrek
293
+
294
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
295
+ font-size: 1.25rem;
296
+ line-height: 140%;
297
+ padding: 0.3125rem 0.25rem 0.3125rem 1rem;
298
+ }
299
+
300
+ &:hover {
301
+ background: var(--core-color-neutral-100);
302
+ }
303
+
304
+ &:active {
305
+ background: var(--color-action-background-transparent-onlight-active);
306
+ }
307
+ }
308
+
309
+ .dropdown_root_custom {
310
+ &:focus-within {
311
+ .dropdown_container {
312
+ outline: 4px solid var(--color-action-border-onlight-focus);
313
+ }
314
+ }
315
+
316
+ &:hover {
317
+ .dropdown_container {
318
+ background: var(--core-color-neutral-100);
319
+ }
320
+ }
321
+ }
322
+
323
+ .dropdown_label {
324
+ @include fonts.input-text;
325
+
326
+ font-weight: 600;
327
+ }
328
+
329
+ .dropdown_chevron {
330
+ fill: var(--color-action-graphics-onlight);
331
+ }
332
+
333
+ .clear-button {
334
+ --button-size: calc(2.75rem);
335
+
336
+ // position inside input field and 2px for centering adjusted for border
337
+ translate: -3rem 2px;
338
+ position: absolute;
339
+ width: var(--button-size);
340
+ height: var(--button-size);
341
+ border: none;
342
+ background: transparent;
343
+ display: flex;
344
+ align-items: center;
345
+ justify-content: center;
346
+
347
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
348
+ --button-size: calc(3rem);
349
+
350
+ // position inside input field and 2px for centering adjusted for border
351
+ translate: -3.25rem 2px;
352
+ }
353
+
354
+ &:hover {
355
+ &::after {
356
+ content: '';
357
+ position: absolute;
358
+ border-radius: 100%;
359
+ background: var(--core-color-neutral-50);
360
+ width: 2rem;
361
+ height: 2rem;
362
+ z-index: 1;
363
+ }
364
+
365
+ svg {
366
+ fill: var(--color-action-graphics-onlight-hover);
367
+ }
368
+ }
369
+
370
+ &:active {
371
+ &::after {
372
+ content: '';
373
+ position: absolute;
374
+ border-radius: 100%;
375
+ background: var(--core-color-neutral-100);
376
+ width: 2rem;
377
+ height: 2rem;
378
+ z-index: 1;
379
+ }
380
+ }
381
+
382
+ &:focus-visible {
383
+ @include focus-border;
384
+ }
385
+
386
+ svg {
387
+ fill: var(--color-action-graphics-onlight);
388
+ z-index: 2;
389
+ }
390
+ }
391
+
392
+ .calendar-button {
393
+ // Same as Input component
394
+ --button-size: calc(2.75rem + 0.25rem); // 44px height + 4px border
395
+
396
+ width: var(--button-size);
397
+ height: var(--button-size);
398
+ background: transparent;
399
+ display: flex;
400
+ align-items: center;
401
+ justify-content: center;
402
+ border: 2px solid var(--color-base-border-onlight-emphasized);
403
+ border-left: none;
404
+
405
+ @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
406
+ // Same as Input component
407
+ --button-size: calc(3rem + 0.25rem); // 48px height + 4px border
408
+ }
409
+
410
+ &:disabled {
411
+ border: 2px dashed var(--color-disabled-border);
412
+ border-left: none;
413
+
414
+ svg {
415
+ fill: var(--color-disabled-graphics);
416
+ }
417
+ }
418
+
419
+ &:hover:not(:disabled) {
420
+ background: var(--core-color-neutral-50);
421
+
422
+ svg {
423
+ fill: var(--color-action-graphics-onlight-hover);
424
+ }
425
+ }
426
+
427
+ &:active:not(:disabled) {
428
+ background: var(--core-color-neutral-100);
429
+
430
+ svg {
431
+ fill: var(--color-action-graphics-emphasized-onlight);
432
+ }
433
+ }
434
+
435
+ &:focus-visible:not(:disabled) {
436
+ outline: 2px solid var(--color-action-border-onlight-focus);
437
+ border-color: var(--color-action-border-onlight-focus);
438
+
439
+ // hack to make focus border on left without moving icon
440
+ box-shadow: -2px 0 0 2px var(--color-action-border-onlight-focus);
441
+ }
442
+
443
+ svg {
444
+ fill: var(--color-action-graphics-onlight);
445
+ }
446
+ }
@@ -0,0 +1,31 @@
1
+ export type Styles = {
2
+ 'calendar-button': string;
3
+ 'clear-button': string;
4
+ 'custom_caption-label': string;
5
+ custom_chevron: string;
6
+ custom_day_button: string;
7
+ custom_month_caption: string;
8
+ custom_nav_button: string;
9
+ custom_nav_button__circle: string;
10
+ 'date--default': string;
11
+ 'date--disabled': string;
12
+ 'date--emphasized': string;
13
+ 'date--fully': string;
14
+ 'date--partial': string;
15
+ 'date--selected': string;
16
+ 'date--today': string;
17
+ 'datepicker-footer': string;
18
+ 'datepicker-footer--with-today-button': string;
19
+ dropdown_chevron: string;
20
+ dropdown_container: string;
21
+ dropdown_label: string;
22
+ dropdown_root_custom: string;
23
+ 'loading-overlay': string;
24
+ root_override: string;
25
+ };
26
+
27
+ export type ClassNames = keyof Styles;
28
+
29
+ declare const styles: Styles;
30
+
31
+ export default styles;
@@ -0,0 +1,6 @@
1
+ import { default as React, ButtonHTMLAttributes } from 'react';
2
+ import { CaptionLabelProps, DropdownProps } from 'react-day-picker';
3
+ export declare const CustomPreviousButton: (props: ButtonHTMLAttributes<HTMLButtonElement>) => React.JSX.Element;
4
+ export declare const CustomNextButton: (props: ButtonHTMLAttributes<HTMLButtonElement>) => React.JSX.Element;
5
+ export declare const CustomDropdown: (props: DropdownProps) => React.JSX.Element;
6
+ export declare const CustomCaptionLabel: (props: CaptionLabelProps) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function matchesDayObjectMatcher(date: Date, matcher: Record<string, any>): boolean;
@@ -0,0 +1,28 @@
1
+ import { HNDesignsystemUnsafe_DatePicker } from '../../resources/Resources';
2
+ export interface DateInputInternalProps {
3
+ /** Currently given date, in norwegian format dd.mm.yyyy */
4
+ value?: string;
5
+ /** Callback for change in date */
6
+ onChange?: (value: string) => void;
7
+ /** Callback for blur on input field */
8
+ onBlur?: (value: string) => void;
9
+ /** Id for legend, for connecting legend to input */
10
+ legendId: string;
11
+ /** Callback for setting error text when validating */
12
+ setErrorText?: (text: string) => void;
13
+ /** Wether or not to shw a clear button when there is content in the input */
14
+ withClearButton?: boolean;
15
+ /** Resources for component */
16
+ resources?: Partial<HNDesignsystemUnsafe_DatePicker>;
17
+ /** Sets aria-describedby on the input, for connecting labels */
18
+ ['aria-describedby']?: string;
19
+ /** Sets aria-labelledby on the input, for connecting labels */
20
+ ['aria-labelledby']?: string;
21
+ /** Id for input, for connecting labels */
22
+ inputId?: string;
23
+ }
24
+ declare const DateInputInternal: {
25
+ ({ value, onChange, onBlur, inputId, legendId, setErrorText, resources, withClearButton, ["aria-describedby"]: ariaDescribedBy, ["aria-labelledby"]: ariaLabelledBy, }: DateInputInternalProps): import("react/jsx-runtime").JSX.Element;
26
+ displayName: string;
27
+ };
28
+ export default DateInputInternal;