@telia/teddy 0.1.10 → 0.1.12
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/dist/components/date-picker/date-picker-props.d.ts +2 -1
- package/dist/components/date-picker/date-picker.cjs +36 -14
- package/dist/components/date-picker/date-picker.js +37 -15
- package/dist/components/navigation-menu/global-navigation/utils.cjs +5 -0
- package/dist/components/navigation-menu/global-navigation/utils.d.ts +8 -0
- package/dist/components/navigation-menu/global-navigation/utils.js +5 -0
- package/package.json +1 -1
|
@@ -14,10 +14,11 @@ export default interface DatePickerProps {
|
|
|
14
14
|
min?: string;
|
|
15
15
|
max?: string;
|
|
16
16
|
modalOpen?: boolean;
|
|
17
|
-
isDateDisabled
|
|
17
|
+
isDateDisabled?: (date: Date | undefined | null) => boolean;
|
|
18
18
|
invalidErrorMessage?: string;
|
|
19
19
|
invalidMinErrorMessage?: string;
|
|
20
20
|
invalidMaxErrorMessage?: string;
|
|
21
21
|
requiredErrorMessage?: string;
|
|
22
22
|
formId?: string;
|
|
23
|
+
onSelectedDate?: (date: Date) => void;
|
|
23
24
|
}
|
|
@@ -37,6 +37,7 @@ const DatePicker = ({
|
|
|
37
37
|
invalidMaxErrorMessage = "Dato er for ny",
|
|
38
38
|
requiredErrorMessage = "Feltet er påkrevd",
|
|
39
39
|
isDateDisabled = () => false,
|
|
40
|
+
onSelectedDate = null,
|
|
40
41
|
formId = void 0
|
|
41
42
|
}) => {
|
|
42
43
|
const inputId = components_datePicker_datePickerUniqueId.uniqueId("input");
|
|
@@ -99,11 +100,18 @@ const DatePicker = ({
|
|
|
99
100
|
};
|
|
100
101
|
});
|
|
101
102
|
const show = () => {
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
if (!open) {
|
|
104
|
+
setOpen(true);
|
|
105
|
+
}
|
|
106
|
+
const d = components_datePicker_dateUtils.parseDate(currentValue) || /* @__PURE__ */ new Date();
|
|
107
|
+
if (focusedDay != d) {
|
|
108
|
+
setFocusedDay(d);
|
|
109
|
+
}
|
|
104
110
|
};
|
|
105
111
|
const hide = (moveFocusToButton = true) => {
|
|
106
|
-
|
|
112
|
+
if (open) {
|
|
113
|
+
setOpen(false);
|
|
114
|
+
}
|
|
107
115
|
clearTimeout(focusTimeoutId);
|
|
108
116
|
const TRANSITION_MS = 300;
|
|
109
117
|
if (moveFocusToButton) {
|
|
@@ -133,7 +141,9 @@ const DatePicker = ({
|
|
|
133
141
|
setValue(parsed);
|
|
134
142
|
hide();
|
|
135
143
|
} else {
|
|
136
|
-
|
|
144
|
+
if (currentValue != target.value) {
|
|
145
|
+
setCurrentValue(target.value);
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
};
|
|
@@ -241,8 +251,12 @@ const DatePicker = ({
|
|
|
241
251
|
setValue(day);
|
|
242
252
|
setErrorMessage("");
|
|
243
253
|
hide();
|
|
254
|
+
if (onSelectedDate) {
|
|
255
|
+
onSelectedDate(day);
|
|
256
|
+
}
|
|
244
257
|
} else {
|
|
245
|
-
|
|
258
|
+
if (focusedDay !== day)
|
|
259
|
+
setFocusedDay(day);
|
|
246
260
|
}
|
|
247
261
|
};
|
|
248
262
|
const handleBlur = (event) => {
|
|
@@ -276,7 +290,9 @@ const DatePicker = ({
|
|
|
276
290
|
const min2 = components_datePicker_dateUtils.setMonth(components_datePicker_dateUtils.startOfMonth(focusedDay), month);
|
|
277
291
|
const max2 = components_datePicker_dateUtils.endOfMonth(min2);
|
|
278
292
|
const date = components_datePicker_dateUtils.setMonth(focusedDay, month);
|
|
279
|
-
|
|
293
|
+
const clamped = components_datePicker_dateUtils.clamp(date, min2, max2);
|
|
294
|
+
if (focusedDay !== clamped)
|
|
295
|
+
setFocusedDay(clamped);
|
|
280
296
|
};
|
|
281
297
|
const updateYear = (year) => {
|
|
282
298
|
const minY = components_datePicker_dateUtils.setYear(components_datePicker_dateUtils.startOfMonth(focusedDay), year);
|
|
@@ -288,7 +304,12 @@ const DatePicker = ({
|
|
|
288
304
|
components_datePicker_dateUtils.parseDate(min),
|
|
289
305
|
components_datePicker_dateUtils.parseDate(max)
|
|
290
306
|
);
|
|
291
|
-
|
|
307
|
+
const years = components_datePicker_dateUtils.getViewOfYears(minYear, maxYear);
|
|
308
|
+
const y = res.getFullYear();
|
|
309
|
+
if (years.includes(y)) {
|
|
310
|
+
if (focusedDay !== res)
|
|
311
|
+
setFocusedDay(res);
|
|
312
|
+
}
|
|
292
313
|
};
|
|
293
314
|
const addMonths = (months) => {
|
|
294
315
|
updateFocusedDay(focusedDay.getMonth() + months);
|
|
@@ -349,7 +370,8 @@ const DatePicker = ({
|
|
|
349
370
|
components_datePicker_dateUtils.parseDate(min),
|
|
350
371
|
components_datePicker_dateUtils.parseDate(max)
|
|
351
372
|
);
|
|
352
|
-
|
|
373
|
+
if (focusedDay !== clamped)
|
|
374
|
+
setFocusedDay(clamped);
|
|
353
375
|
};
|
|
354
376
|
const handleKeyboardNavigation = (event) => {
|
|
355
377
|
let handled = true;
|
|
@@ -409,23 +431,23 @@ const DatePicker = ({
|
|
|
409
431
|
updateYear(year - 1);
|
|
410
432
|
break;
|
|
411
433
|
case components_datePicker_datePickerNavigationKey.DOWN:
|
|
412
|
-
updateYear(year
|
|
434
|
+
updateYear(year + 4);
|
|
413
435
|
break;
|
|
414
436
|
case components_datePicker_datePickerNavigationKey.UP:
|
|
415
|
-
updateYear(year
|
|
437
|
+
updateYear(year - 4);
|
|
416
438
|
break;
|
|
417
439
|
case components_datePicker_datePickerNavigationKey.PAGE_UP:
|
|
418
440
|
if (event.shiftKey) {
|
|
419
|
-
updateYear(year + 4);
|
|
420
|
-
} else {
|
|
421
441
|
updateYear(year - 4);
|
|
442
|
+
} else {
|
|
443
|
+
updateYear(year + 4);
|
|
422
444
|
}
|
|
423
445
|
break;
|
|
424
446
|
case components_datePicker_datePickerNavigationKey.PAGE_DOWN:
|
|
425
447
|
if (event.shiftKey) {
|
|
426
|
-
updateYear(year - 4);
|
|
427
|
-
} else {
|
|
428
448
|
updateYear(year + 4);
|
|
449
|
+
} else {
|
|
450
|
+
updateYear(year - 4);
|
|
429
451
|
}
|
|
430
452
|
break;
|
|
431
453
|
case components_datePicker_datePickerNavigationKey.HOME:
|
|
@@ -10,7 +10,7 @@ import DatePickerInput from "./date-picker-input.js";
|
|
|
10
10
|
import DatePickerMonth from "./date-picker-month.js";
|
|
11
11
|
import DatePickerYear from "./date-picker-year.js";
|
|
12
12
|
import { css } from "./css.js";
|
|
13
|
-
import { parseDate, printDate, DaysOfWeek, inRange, setYear, startOfMonth, endOfMonth, clamp, printISODate, addDays, setMonth } from "./date-utils.js";
|
|
13
|
+
import { parseDate, printDate, DaysOfWeek, inRange, setYear, startOfMonth, endOfMonth, clamp, getViewOfYears, printISODate, addDays, setMonth } from "./date-utils.js";
|
|
14
14
|
const DateDisabledPredicate = () => false;
|
|
15
15
|
const cn = (classes) => {
|
|
16
16
|
return Object.keys(classes).filter((key) => classes[key]).join(" ");
|
|
@@ -35,6 +35,7 @@ const DatePicker = ({
|
|
|
35
35
|
invalidMaxErrorMessage = "Dato er for ny",
|
|
36
36
|
requiredErrorMessage = "Feltet er påkrevd",
|
|
37
37
|
isDateDisabled = () => false,
|
|
38
|
+
onSelectedDate = null,
|
|
38
39
|
formId = void 0
|
|
39
40
|
}) => {
|
|
40
41
|
const inputId = uniqueId("input");
|
|
@@ -97,11 +98,18 @@ const DatePicker = ({
|
|
|
97
98
|
};
|
|
98
99
|
});
|
|
99
100
|
const show = () => {
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
if (!open) {
|
|
102
|
+
setOpen(true);
|
|
103
|
+
}
|
|
104
|
+
const d = parseDate(currentValue) || /* @__PURE__ */ new Date();
|
|
105
|
+
if (focusedDay != d) {
|
|
106
|
+
setFocusedDay(d);
|
|
107
|
+
}
|
|
102
108
|
};
|
|
103
109
|
const hide = (moveFocusToButton = true) => {
|
|
104
|
-
|
|
110
|
+
if (open) {
|
|
111
|
+
setOpen(false);
|
|
112
|
+
}
|
|
105
113
|
clearTimeout(focusTimeoutId);
|
|
106
114
|
const TRANSITION_MS = 300;
|
|
107
115
|
if (moveFocusToButton) {
|
|
@@ -131,7 +139,9 @@ const DatePicker = ({
|
|
|
131
139
|
setValue(parsed);
|
|
132
140
|
hide();
|
|
133
141
|
} else {
|
|
134
|
-
|
|
142
|
+
if (currentValue != target.value) {
|
|
143
|
+
setCurrentValue(target.value);
|
|
144
|
+
}
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
};
|
|
@@ -239,8 +249,12 @@ const DatePicker = ({
|
|
|
239
249
|
setValue(day);
|
|
240
250
|
setErrorMessage("");
|
|
241
251
|
hide();
|
|
252
|
+
if (onSelectedDate) {
|
|
253
|
+
onSelectedDate(day);
|
|
254
|
+
}
|
|
242
255
|
} else {
|
|
243
|
-
|
|
256
|
+
if (focusedDay !== day)
|
|
257
|
+
setFocusedDay(day);
|
|
244
258
|
}
|
|
245
259
|
};
|
|
246
260
|
const handleBlur = (event) => {
|
|
@@ -274,7 +288,9 @@ const DatePicker = ({
|
|
|
274
288
|
const min2 = setMonth(startOfMonth(focusedDay), month);
|
|
275
289
|
const max2 = endOfMonth(min2);
|
|
276
290
|
const date = setMonth(focusedDay, month);
|
|
277
|
-
|
|
291
|
+
const clamped = clamp(date, min2, max2);
|
|
292
|
+
if (focusedDay !== clamped)
|
|
293
|
+
setFocusedDay(clamped);
|
|
278
294
|
};
|
|
279
295
|
const updateYear = (year) => {
|
|
280
296
|
const minY = setYear(startOfMonth(focusedDay), year);
|
|
@@ -286,7 +302,12 @@ const DatePicker = ({
|
|
|
286
302
|
parseDate(min),
|
|
287
303
|
parseDate(max)
|
|
288
304
|
);
|
|
289
|
-
|
|
305
|
+
const years = getViewOfYears(minYear, maxYear);
|
|
306
|
+
const y = res.getFullYear();
|
|
307
|
+
if (years.includes(y)) {
|
|
308
|
+
if (focusedDay !== res)
|
|
309
|
+
setFocusedDay(res);
|
|
310
|
+
}
|
|
290
311
|
};
|
|
291
312
|
const addMonths = (months) => {
|
|
292
313
|
updateFocusedDay(focusedDay.getMonth() + months);
|
|
@@ -347,7 +368,8 @@ const DatePicker = ({
|
|
|
347
368
|
parseDate(min),
|
|
348
369
|
parseDate(max)
|
|
349
370
|
);
|
|
350
|
-
|
|
371
|
+
if (focusedDay !== clamped)
|
|
372
|
+
setFocusedDay(clamped);
|
|
351
373
|
};
|
|
352
374
|
const handleKeyboardNavigation = (event) => {
|
|
353
375
|
let handled = true;
|
|
@@ -407,23 +429,23 @@ const DatePicker = ({
|
|
|
407
429
|
updateYear(year - 1);
|
|
408
430
|
break;
|
|
409
431
|
case navigationKey.DOWN:
|
|
410
|
-
updateYear(year
|
|
432
|
+
updateYear(year + 4);
|
|
411
433
|
break;
|
|
412
434
|
case navigationKey.UP:
|
|
413
|
-
updateYear(year
|
|
435
|
+
updateYear(year - 4);
|
|
414
436
|
break;
|
|
415
437
|
case navigationKey.PAGE_UP:
|
|
416
438
|
if (event.shiftKey) {
|
|
417
|
-
updateYear(year + 4);
|
|
418
|
-
} else {
|
|
419
439
|
updateYear(year - 4);
|
|
440
|
+
} else {
|
|
441
|
+
updateYear(year + 4);
|
|
420
442
|
}
|
|
421
443
|
break;
|
|
422
444
|
case navigationKey.PAGE_DOWN:
|
|
423
445
|
if (event.shiftKey) {
|
|
424
|
-
updateYear(year - 4);
|
|
425
|
-
} else {
|
|
426
446
|
updateYear(year + 4);
|
|
447
|
+
} else {
|
|
448
|
+
updateYear(year - 4);
|
|
427
449
|
}
|
|
428
450
|
break;
|
|
429
451
|
case navigationKey.HOME:
|
|
@@ -108,6 +108,11 @@ const PRIVATE_LINKS = {
|
|
|
108
108
|
link: "/mobil/tilbehor/",
|
|
109
109
|
appKey: APP_KEYS["web-shop"]
|
|
110
110
|
},
|
|
111
|
+
{
|
|
112
|
+
name: "Pakketilbud",
|
|
113
|
+
link: "/mobil/mobilabonnement/pakketilbud/",
|
|
114
|
+
appKey: APP_KEYS["web-shop"]
|
|
115
|
+
},
|
|
111
116
|
{
|
|
112
117
|
name: "Påfyll kontantkort",
|
|
113
118
|
link: "/mobil/mobilabonnement/kontantkort/lade/",
|
|
@@ -160,6 +160,10 @@ export declare const PRIVATE_LINKS: {
|
|
|
160
160
|
readonly name: "Tilbehør";
|
|
161
161
|
readonly link: "/mobil/tilbehor/";
|
|
162
162
|
readonly appKey: "web-shop";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "Pakketilbud";
|
|
165
|
+
readonly link: "/mobil/mobilabonnement/pakketilbud/";
|
|
166
|
+
readonly appKey: "web-shop";
|
|
163
167
|
}, {
|
|
164
168
|
readonly name: "Påfyll kontantkort";
|
|
165
169
|
readonly link: "/mobil/mobilabonnement/kontantkort/lade/";
|
|
@@ -399,6 +403,10 @@ export declare const LINKS: [{
|
|
|
399
403
|
readonly name: "Tilbehør";
|
|
400
404
|
readonly link: "/mobil/tilbehor/";
|
|
401
405
|
readonly appKey: "web-shop";
|
|
406
|
+
}, {
|
|
407
|
+
readonly name: "Pakketilbud";
|
|
408
|
+
readonly link: "/mobil/mobilabonnement/pakketilbud/";
|
|
409
|
+
readonly appKey: "web-shop";
|
|
402
410
|
}, {
|
|
403
411
|
readonly name: "Påfyll kontantkort";
|
|
404
412
|
readonly link: "/mobil/mobilabonnement/kontantkort/lade/";
|
|
@@ -106,6 +106,11 @@ const PRIVATE_LINKS = {
|
|
|
106
106
|
link: "/mobil/tilbehor/",
|
|
107
107
|
appKey: APP_KEYS["web-shop"]
|
|
108
108
|
},
|
|
109
|
+
{
|
|
110
|
+
name: "Pakketilbud",
|
|
111
|
+
link: "/mobil/mobilabonnement/pakketilbud/",
|
|
112
|
+
appKey: APP_KEYS["web-shop"]
|
|
113
|
+
},
|
|
109
114
|
{
|
|
110
115
|
name: "Påfyll kontantkort",
|
|
111
116
|
link: "/mobil/mobilabonnement/kontantkort/lade/",
|