@telia/teddy 0.0.37 → 0.0.38
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/card/card-button.cjs +42 -0
- package/dist/components/card/card-button.d.ts +35 -0
- package/dist/components/card/card-button.js +42 -0
- package/dist/components/card/card-content.cjs +15 -0
- package/dist/components/card/card-content.d.ts +6 -0
- package/dist/components/card/card-content.js +15 -0
- package/dist/components/card/card-footer.cjs +15 -0
- package/dist/components/card/card-footer.d.ts +6 -0
- package/dist/components/card/card-footer.js +15 -0
- package/dist/components/card/card-heading.cjs +25 -0
- package/dist/components/card/card-heading.d.ts +6 -0
- package/dist/components/card/card-heading.js +25 -0
- package/dist/components/card/card-illustration.cjs +22 -0
- package/dist/components/card/card-illustration.d.ts +15 -0
- package/dist/components/card/card-illustration.js +22 -0
- package/dist/components/card/card-line.cjs +13 -0
- package/dist/components/card/card-line.d.ts +5 -0
- package/dist/components/card/card-line.js +13 -0
- package/dist/components/card/card-link.cjs +18 -0
- package/dist/components/card/card-link.d.ts +11 -0
- package/dist/components/card/card-link.js +18 -0
- package/dist/components/card/card-slot.cjs +36 -0
- package/dist/components/card/card-slot.d.ts +8 -0
- package/dist/components/card/card-slot.js +36 -0
- package/dist/components/card/card.cjs +38 -171
- package/dist/components/card/card.d.ts +15 -99
- package/dist/components/card/card.js +39 -172
- package/dist/components/card/index.cjs +28 -1
- package/dist/components/card/index.d.ts +64 -2
- package/dist/components/card/index.js +28 -1
- package/dist/components/card/utils.cjs +4 -0
- package/dist/components/card/utils.d.ts +2 -0
- package/dist/components/card/utils.js +4 -0
- package/dist/components/date-picker/css.cjs +59 -0
- package/dist/components/date-picker/css.d.ts +1 -0
- package/dist/components/date-picker/css.js +59 -0
- package/dist/components/date-picker/date-picker-day.cjs +67 -0
- package/dist/components/date-picker/date-picker-day.d.ts +13 -0
- package/dist/components/date-picker/date-picker-day.js +67 -0
- package/dist/components/date-picker/date-picker-input.cjs +89 -0
- package/dist/components/date-picker/date-picker-input.d.ts +27 -0
- package/dist/components/date-picker/date-picker-input.js +90 -0
- package/dist/components/date-picker/date-picker-localization.cjs +31 -0
- package/dist/components/date-picker/date-picker-localization.d.ts +20 -0
- package/dist/components/date-picker/date-picker-localization.js +32 -0
- package/dist/components/date-picker/date-picker-month.cjs +42 -0
- package/dist/components/date-picker/date-picker-month.d.ts +20 -0
- package/dist/components/date-picker/date-picker-month.js +43 -0
- package/dist/components/date-picker/date-picker-navigation-key.cjs +15 -0
- package/dist/components/date-picker/date-picker-navigation-key.d.ts +14 -0
- package/dist/components/date-picker/date-picker-navigation-key.js +16 -0
- package/dist/components/date-picker/date-picker-props.cjs +1 -0
- package/dist/components/date-picker/date-picker-props.d.ts +23 -0
- package/dist/components/date-picker/date-picker-props.js +1 -0
- package/dist/components/date-picker/date-picker-unique-id.cjs +4 -0
- package/dist/components/date-picker/date-picker-unique-id.d.ts +1 -0
- package/dist/components/date-picker/date-picker-unique-id.js +4 -0
- package/dist/components/date-picker/date-picker-year-print.cjs +61 -0
- package/dist/components/date-picker/date-picker-year-print.d.ts +12 -0
- package/dist/components/date-picker/date-picker-year-print.js +61 -0
- package/dist/components/date-picker/date-picker-year.cjs +36 -0
- package/dist/components/date-picker/date-picker-year.d.ts +16 -0
- package/dist/components/date-picker/date-picker-year.js +37 -0
- package/dist/components/date-picker/date-picker.cjs +597 -0
- package/dist/components/date-picker/date-picker.d.ts +5 -0
- package/dist/components/date-picker/date-picker.js +597 -0
- package/dist/components/date-picker/date-utils.cjs +340 -0
- package/dist/components/date-picker/date-utils.d.ts +29 -0
- package/dist/components/date-picker/date-utils.js +340 -0
- package/dist/components/date-picker/date-year-range.cjs +1 -0
- package/dist/components/date-picker/date-year-range.d.ts +4 -0
- package/dist/components/date-picker/date-year-range.js +1 -0
- package/dist/components/date-picker/dialog-utils.cjs +36 -0
- package/dist/components/date-picker/dialog-utils.d.ts +3 -0
- package/dist/components/date-picker/dialog-utils.js +36 -0
- package/dist/components/date-picker/index.cjs +4 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +4 -0
- package/dist/components/expandable-card/expandable-card-root.cjs +15 -15
- package/dist/components/expandable-card/expandable-card-root.js +15 -15
- package/dist/components/image/image.cjs +1 -1
- package/dist/components/image/image.js +1 -1
- package/dist/components/index.cjs +4 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +3 -1
- package/dist/components/modal/modal.cjs +4 -4
- package/dist/components/modal/modal.js +4 -4
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.cjs +5 -5
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.js +5 -5
- package/dist/components/navigation-menu/global-navigation/utils.cjs +127 -126
- package/dist/components/navigation-menu/global-navigation/utils.d.ts +227 -219
- package/dist/components/navigation-menu/global-navigation/utils.js +127 -126
- package/dist/components/notification/notification.cjs +2 -2
- package/dist/components/notification/notification.d.ts +7 -7
- package/dist/components/notification/notification.js +1 -1
- package/dist/main.cjs +4 -2
- package/dist/main.js +3 -1
- package/dist/style.css +623 -179
- package/package.json +1 -1
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import "../../assets/sprite.269ba410-teddy.svg";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { uniqueId } from "./date-picker-unique-id.js";
|
|
6
|
+
import { cleanValue } from "./dialog-utils.js";
|
|
7
|
+
import navigationKey from "./date-picker-navigation-key.js";
|
|
8
|
+
import localization from "./date-picker-localization.js";
|
|
9
|
+
import DatePickerInput from "./date-picker-input.js";
|
|
10
|
+
import DatePickerMonth from "./date-picker-month.js";
|
|
11
|
+
import DatePickerYear from "./date-picker-year.js";
|
|
12
|
+
import { css } from "./css.js";
|
|
13
|
+
import { parseDate, printDate, DaysOfWeek, inRange, setYear, startOfMonth, endOfMonth, clamp, printISODate, addDays, setMonth } from "./date-utils.js";
|
|
14
|
+
const DateDisabledPredicate = () => false;
|
|
15
|
+
const cn = (classes) => {
|
|
16
|
+
return Object.keys(classes).filter((key) => classes[key]).join(" ");
|
|
17
|
+
};
|
|
18
|
+
const DISALLOWED_CHARACTERS = /[^0-9\s.-]+/g;
|
|
19
|
+
const DatePicker = ({
|
|
20
|
+
name = "date",
|
|
21
|
+
label,
|
|
22
|
+
additional,
|
|
23
|
+
range = { past: 23, future: 1 },
|
|
24
|
+
disabled = false,
|
|
25
|
+
role,
|
|
26
|
+
buttonLabel,
|
|
27
|
+
readonly = false,
|
|
28
|
+
required = false,
|
|
29
|
+
value = "",
|
|
30
|
+
min = "",
|
|
31
|
+
max = "",
|
|
32
|
+
modalOpen = false,
|
|
33
|
+
invalidErrorMessage = "Ugyldig dato format",
|
|
34
|
+
invalidMinErrorMessage = "Dato er for tidlig",
|
|
35
|
+
invalidMaxErrorMessage = "Dato er for ny",
|
|
36
|
+
requiredErrorMessage = "Feltet er påkrevd",
|
|
37
|
+
isDateDisabled = () => false,
|
|
38
|
+
formId = void 0
|
|
39
|
+
}) => {
|
|
40
|
+
const inputId = uniqueId("input");
|
|
41
|
+
const labelId = uniqueId("dateLabel");
|
|
42
|
+
const labelYearId = uniqueId("dateYearLabel");
|
|
43
|
+
const errorId = uniqueId("error");
|
|
44
|
+
const additionalId = uniqueId("additional");
|
|
45
|
+
let datePickerButton;
|
|
46
|
+
let datePickerInput;
|
|
47
|
+
let focusTimeoutId;
|
|
48
|
+
const setToggleRef = (element) => {
|
|
49
|
+
datePickerButton = element;
|
|
50
|
+
};
|
|
51
|
+
const setTextInputRef = (element) => {
|
|
52
|
+
datePickerInput = element;
|
|
53
|
+
};
|
|
54
|
+
let initialTouchX;
|
|
55
|
+
let initialTouchY;
|
|
56
|
+
const [currentValue, setCurrentValue] = useState(value ?? "");
|
|
57
|
+
const [focusedDay, setFocusedDay] = useState(/* @__PURE__ */ new Date());
|
|
58
|
+
const [errorMessage, setErrorMessage] = useState("");
|
|
59
|
+
const [touched, setTouched] = useState(false);
|
|
60
|
+
const [open, setOpen] = useState(modalOpen);
|
|
61
|
+
const [showYearDialog, setShowYearDialog] = useState(false);
|
|
62
|
+
const [wrapperRef, setWrapperRef] = useState();
|
|
63
|
+
const openRef = useRef(open);
|
|
64
|
+
const wrapperRefRef = useRef(wrapperRef);
|
|
65
|
+
const dateFormatShort = new Intl.DateTimeFormat(localization.locale, {
|
|
66
|
+
day: "numeric",
|
|
67
|
+
month: "long"
|
|
68
|
+
});
|
|
69
|
+
const dateFormatLong = new Intl.DateTimeFormat(localization.locale, {
|
|
70
|
+
day: "numeric",
|
|
71
|
+
month: "long",
|
|
72
|
+
year: "numeric"
|
|
73
|
+
});
|
|
74
|
+
const handleDocumentClick = (e) => {
|
|
75
|
+
if (!openRef.current) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const isClickOutside = e.composedPath().every(
|
|
79
|
+
(node) => node !== wrapperRefRef.current
|
|
80
|
+
);
|
|
81
|
+
if (isClickOutside) {
|
|
82
|
+
hide(false);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
openRef.current = open;
|
|
87
|
+
}, [open]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
wrapperRefRef.current = wrapperRef;
|
|
90
|
+
}, [wrapperRef]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (typeof document !== "undefined" && document) {
|
|
93
|
+
document.addEventListener("click", handleDocumentClick);
|
|
94
|
+
}
|
|
95
|
+
return () => {
|
|
96
|
+
document.removeEventListener("click", handleDocumentClick);
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const show = () => {
|
|
100
|
+
setOpen(true);
|
|
101
|
+
setFocusedDay(parseDate(currentValue) || /* @__PURE__ */ new Date());
|
|
102
|
+
};
|
|
103
|
+
const hide = (moveFocusToButton = true) => {
|
|
104
|
+
setOpen(false);
|
|
105
|
+
clearTimeout(focusTimeoutId);
|
|
106
|
+
const TRANSITION_MS = 300;
|
|
107
|
+
if (moveFocusToButton) {
|
|
108
|
+
setTimeout(
|
|
109
|
+
() => {
|
|
110
|
+
var _a;
|
|
111
|
+
return (_a = datePickerButton == null ? void 0 : datePickerButton.querySelector("button")) == null ? void 0 : _a.focus();
|
|
112
|
+
},
|
|
113
|
+
TRANSITION_MS + 150
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const setValue = (date) => {
|
|
118
|
+
const newDate = printISODate(date);
|
|
119
|
+
if (newDate != currentValue) {
|
|
120
|
+
setCurrentValue(newDate);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handleInputChange = () => {
|
|
124
|
+
const target = datePickerInput;
|
|
125
|
+
cleanValue(target, DISALLOWED_CHARACTERS);
|
|
126
|
+
if (target.value.length < currentValue.length) {
|
|
127
|
+
setCurrentValue(target.value);
|
|
128
|
+
} else {
|
|
129
|
+
const parsed = parseDate(target.value);
|
|
130
|
+
if (parsed || target.value === "") {
|
|
131
|
+
setValue(parsed);
|
|
132
|
+
hide();
|
|
133
|
+
} else {
|
|
134
|
+
setCurrentValue(target.value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const updateErrorMessage = (message) => {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
if (errorMessage !== message) {
|
|
141
|
+
if (message) {
|
|
142
|
+
(_a = datePickerInput == null ? void 0 : datePickerInput.setCustomValidity) == null ? void 0 : _a.call(datePickerInput, message);
|
|
143
|
+
} else {
|
|
144
|
+
(_b = datePickerInput == null ? void 0 : datePickerInput.setCustomValidity) == null ? void 0 : _b.call(datePickerInput, "");
|
|
145
|
+
}
|
|
146
|
+
setErrorMessage(message);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const isValueLessThanMinDate = () => {
|
|
150
|
+
const inputValue = datePickerInput.value;
|
|
151
|
+
const parsedDate = parseDate(inputValue);
|
|
152
|
+
if (parsedDate === void 0)
|
|
153
|
+
return false;
|
|
154
|
+
const minDate2 = parseDate(min);
|
|
155
|
+
if (!minDate2)
|
|
156
|
+
return false;
|
|
157
|
+
return parsedDate < minDate2;
|
|
158
|
+
};
|
|
159
|
+
const isValueLargerThanMaxDate = () => {
|
|
160
|
+
const inputValue = datePickerInput.value;
|
|
161
|
+
const parsedDate = parseDate(inputValue);
|
|
162
|
+
if (parsedDate === void 0)
|
|
163
|
+
return false;
|
|
164
|
+
const maxDate2 = parseDate(min);
|
|
165
|
+
if (!maxDate2)
|
|
166
|
+
return false;
|
|
167
|
+
return parsedDate > maxDate2;
|
|
168
|
+
};
|
|
169
|
+
const isValueValid = () => {
|
|
170
|
+
const inputValue = datePickerInput.value;
|
|
171
|
+
const parsedDate = parseDate(inputValue);
|
|
172
|
+
if (parsedDate === void 0)
|
|
173
|
+
return false;
|
|
174
|
+
const isInRange = inRange(
|
|
175
|
+
parsedDate,
|
|
176
|
+
parseDate(min),
|
|
177
|
+
parseDate(max)
|
|
178
|
+
);
|
|
179
|
+
if (!isInRange)
|
|
180
|
+
return false;
|
|
181
|
+
const isDisabled = isDateDisabled(parsedDate);
|
|
182
|
+
return !isDisabled;
|
|
183
|
+
};
|
|
184
|
+
const makeTouched = () => {
|
|
185
|
+
if (touched !== true) {
|
|
186
|
+
setTouched(true);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const updateErrorState = () => {
|
|
190
|
+
var _a;
|
|
191
|
+
const requiredError = !!(requiredErrorMessage == null ? void 0 : requiredErrorMessage.length);
|
|
192
|
+
const invalidError = !!(invalidErrorMessage == null ? void 0 : invalidErrorMessage.length);
|
|
193
|
+
const invalidMinError = !!(invalidMinErrorMessage == null ? void 0 : invalidMinErrorMessage.length);
|
|
194
|
+
const invalidMaxError = !!(invalidMaxErrorMessage == null ? void 0 : invalidMaxErrorMessage.length);
|
|
195
|
+
const length = ((_a = datePickerInput == null ? void 0 : datePickerInput.value) == null ? void 0 : _a.length) ?? 0;
|
|
196
|
+
let error = null;
|
|
197
|
+
let isTouched = touched;
|
|
198
|
+
if (length > 0) {
|
|
199
|
+
if (invalidError) {
|
|
200
|
+
if (!isValueValid()) {
|
|
201
|
+
if (invalidMinError && isValueLessThanMinDate()) {
|
|
202
|
+
error = invalidMinErrorMessage;
|
|
203
|
+
} else if (invalidMaxError && isValueLargerThanMaxDate()) {
|
|
204
|
+
error = invalidMaxErrorMessage;
|
|
205
|
+
} else {
|
|
206
|
+
error = invalidErrorMessage;
|
|
207
|
+
}
|
|
208
|
+
isTouched = true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (length === 0) {
|
|
213
|
+
if (required) {
|
|
214
|
+
if (requiredError) {
|
|
215
|
+
error = requiredErrorMessage;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (isTouched) {
|
|
220
|
+
makeTouched();
|
|
221
|
+
}
|
|
222
|
+
updateErrorMessage(error);
|
|
223
|
+
};
|
|
224
|
+
const onHandleYearSelected = (_event, year) => {
|
|
225
|
+
if (showYearDialog) {
|
|
226
|
+
_event.stopPropagation();
|
|
227
|
+
updateYear(parseInt(year.toString(), 10));
|
|
228
|
+
setShowYearDialog(false);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const handleDaySelect = (_event, day) => {
|
|
232
|
+
const isInRange = inRange(
|
|
233
|
+
day,
|
|
234
|
+
parseDate(min),
|
|
235
|
+
parseDate(max)
|
|
236
|
+
);
|
|
237
|
+
const isAllowed = !isDateDisabled(day);
|
|
238
|
+
if (isInRange && isAllowed) {
|
|
239
|
+
setValue(day);
|
|
240
|
+
setErrorMessage("");
|
|
241
|
+
hide();
|
|
242
|
+
} else {
|
|
243
|
+
setFocusedDay(day);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const handleBlur = (event) => {
|
|
247
|
+
event.stopPropagation();
|
|
248
|
+
updateErrorState();
|
|
249
|
+
};
|
|
250
|
+
const handleFocus = (event) => {
|
|
251
|
+
event.stopPropagation();
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
open ? hide(false) : show();
|
|
254
|
+
};
|
|
255
|
+
const showAdditional = !!additional;
|
|
256
|
+
const showError = !!(errorMessage == null ? void 0 : errorMessage.length);
|
|
257
|
+
const describedBy = cn({
|
|
258
|
+
[additionalId]: showAdditional,
|
|
259
|
+
[errorId]: showError
|
|
260
|
+
});
|
|
261
|
+
const valueAsDate = parseDate(currentValue);
|
|
262
|
+
const focusedMonth = focusedDay.getMonth();
|
|
263
|
+
const focusedYear = focusedDay.getFullYear();
|
|
264
|
+
const minDate = parseDate(min);
|
|
265
|
+
const maxDate = parseDate(max);
|
|
266
|
+
const prevMonthDisabled = minDate !== void 0 && minDate.getMonth() === focusedMonth && minDate.getFullYear() === focusedYear;
|
|
267
|
+
const nextMonthDisabled = maxDate !== void 0 && maxDate.getMonth() === focusedMonth && maxDate.getFullYear() === focusedYear;
|
|
268
|
+
const nextYearDisabled = maxDate !== void 0 && maxDate.getFullYear() === focusedYear;
|
|
269
|
+
const past = range.past;
|
|
270
|
+
const future = range.future;
|
|
271
|
+
const minYear = minDate !== void 0 ? minDate.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear() - past;
|
|
272
|
+
const maxYear = maxDate !== void 0 ? maxDate.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear() + future;
|
|
273
|
+
const updateFocusedDay = (month) => {
|
|
274
|
+
const min2 = setMonth(startOfMonth(focusedDay), month);
|
|
275
|
+
const max2 = endOfMonth(min2);
|
|
276
|
+
const date = setMonth(focusedDay, month);
|
|
277
|
+
setFocusedDay(clamp(date, min2, max2));
|
|
278
|
+
};
|
|
279
|
+
const updateYear = (year) => {
|
|
280
|
+
const minY = setYear(startOfMonth(focusedDay), year);
|
|
281
|
+
const maxM = endOfMonth(minY);
|
|
282
|
+
const date = setYear(focusedDay, year);
|
|
283
|
+
const day = clamp(date, minY, maxM);
|
|
284
|
+
const res = clamp(
|
|
285
|
+
day,
|
|
286
|
+
parseDate(min),
|
|
287
|
+
parseDate(max)
|
|
288
|
+
);
|
|
289
|
+
setFocusedDay(res);
|
|
290
|
+
};
|
|
291
|
+
const addMonths = (months) => {
|
|
292
|
+
updateFocusedDay(focusedDay.getMonth() + months);
|
|
293
|
+
};
|
|
294
|
+
const handleTouchStart = (event) => {
|
|
295
|
+
const touch = event.changedTouches[0];
|
|
296
|
+
initialTouchX = touch.pageX;
|
|
297
|
+
initialTouchY = touch.pageY;
|
|
298
|
+
};
|
|
299
|
+
const handleTouchEnd = (event) => {
|
|
300
|
+
const touch = event.changedTouches[0];
|
|
301
|
+
const distX = touch.pageX - initialTouchX;
|
|
302
|
+
const distY = touch.pageY - initialTouchY;
|
|
303
|
+
const threshold = 70;
|
|
304
|
+
const isHorizontalSwipe = Math.abs(distX) >= threshold && Math.abs(distY) <= threshold;
|
|
305
|
+
const isDownwardsSwipe = Math.abs(distY) >= threshold && Math.abs(distX) <= threshold && distY > 0;
|
|
306
|
+
if (isHorizontalSwipe) {
|
|
307
|
+
addMonths(distX < 0 ? 1 : -1);
|
|
308
|
+
} else if (isDownwardsSwipe) {
|
|
309
|
+
hide(false);
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
}
|
|
312
|
+
initialTouchY = 0;
|
|
313
|
+
initialTouchX = 0;
|
|
314
|
+
};
|
|
315
|
+
const handleEscKey = (event) => {
|
|
316
|
+
var _a;
|
|
317
|
+
if (event.keyCode === navigationKey.ESC) {
|
|
318
|
+
(_a = document.getElementById(inputId)) == null ? void 0 : _a.blur();
|
|
319
|
+
hide();
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const setDialogWrapperRef = (element) => {
|
|
323
|
+
setWrapperRef(element);
|
|
324
|
+
};
|
|
325
|
+
const handlePreviousMonthClick = (event) => {
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
addMonths(-1);
|
|
328
|
+
};
|
|
329
|
+
const handleNextMonthClick = (event) => {
|
|
330
|
+
event.preventDefault();
|
|
331
|
+
addMonths(1);
|
|
332
|
+
};
|
|
333
|
+
const handleOnYearDialogOpenClick = () => {
|
|
334
|
+
if (!showYearDialog) {
|
|
335
|
+
setShowYearDialog(true);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
const handleOnYearDialogCloseClick = () => {
|
|
339
|
+
if (showYearDialog) {
|
|
340
|
+
setShowYearDialog(false);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const updateDays = (days) => {
|
|
344
|
+
const d = addDays(focusedDay, days);
|
|
345
|
+
const clamped = clamp(
|
|
346
|
+
d,
|
|
347
|
+
parseDate(min),
|
|
348
|
+
parseDate(max)
|
|
349
|
+
);
|
|
350
|
+
setFocusedDay(clamped);
|
|
351
|
+
};
|
|
352
|
+
const handleKeyboardNavigation = (event) => {
|
|
353
|
+
let handled = true;
|
|
354
|
+
switch (event.keyCode) {
|
|
355
|
+
case navigationKey.TAB:
|
|
356
|
+
updateDays(event.shiftKey ? -1 : 1);
|
|
357
|
+
break;
|
|
358
|
+
case navigationKey.RIGHT:
|
|
359
|
+
updateDays(1);
|
|
360
|
+
break;
|
|
361
|
+
case navigationKey.LEFT:
|
|
362
|
+
updateDays(-1);
|
|
363
|
+
break;
|
|
364
|
+
case navigationKey.DOWN:
|
|
365
|
+
updateDays(7);
|
|
366
|
+
break;
|
|
367
|
+
case navigationKey.UP:
|
|
368
|
+
updateDays(-7);
|
|
369
|
+
break;
|
|
370
|
+
case navigationKey.PAGE_UP:
|
|
371
|
+
if (event.shiftKey) {
|
|
372
|
+
updateYear(-1);
|
|
373
|
+
} else {
|
|
374
|
+
addMonths(-1);
|
|
375
|
+
}
|
|
376
|
+
break;
|
|
377
|
+
case navigationKey.PAGE_DOWN:
|
|
378
|
+
if (event.shiftKey) {
|
|
379
|
+
updateYear(1);
|
|
380
|
+
} else {
|
|
381
|
+
addMonths(1);
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
case navigationKey.HOME:
|
|
385
|
+
break;
|
|
386
|
+
case navigationKey.END:
|
|
387
|
+
break;
|
|
388
|
+
default: {
|
|
389
|
+
handled = false;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (handled) {
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const handleKeyboardNavigationYear = (event) => {
|
|
397
|
+
let handled = true;
|
|
398
|
+
const year = focusedDay.getFullYear();
|
|
399
|
+
switch (event.keyCode) {
|
|
400
|
+
case navigationKey.TAB:
|
|
401
|
+
updateYear(event.shiftKey ? year - 1 : year + 1);
|
|
402
|
+
break;
|
|
403
|
+
case navigationKey.RIGHT:
|
|
404
|
+
updateYear(year + 1);
|
|
405
|
+
break;
|
|
406
|
+
case navigationKey.LEFT:
|
|
407
|
+
updateYear(year - 1);
|
|
408
|
+
break;
|
|
409
|
+
case navigationKey.DOWN:
|
|
410
|
+
updateYear(year - 4);
|
|
411
|
+
break;
|
|
412
|
+
case navigationKey.UP:
|
|
413
|
+
updateYear(year + 4);
|
|
414
|
+
break;
|
|
415
|
+
case navigationKey.PAGE_UP:
|
|
416
|
+
if (event.shiftKey) {
|
|
417
|
+
updateYear(year + 4);
|
|
418
|
+
} else {
|
|
419
|
+
updateYear(year - 4);
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
case navigationKey.PAGE_DOWN:
|
|
423
|
+
if (event.shiftKey) {
|
|
424
|
+
updateYear(year - 4);
|
|
425
|
+
} else {
|
|
426
|
+
updateYear(year + 4);
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
case navigationKey.HOME:
|
|
430
|
+
break;
|
|
431
|
+
case navigationKey.END:
|
|
432
|
+
break;
|
|
433
|
+
default: {
|
|
434
|
+
handled = false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (handled) {
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
const displayDate = printDate(currentValue);
|
|
442
|
+
const containerCss = css("__container");
|
|
443
|
+
return /* @__PURE__ */ jsx("div", { className: containerCss, ref: setDialogWrapperRef, children: /* @__PURE__ */ jsxs("div", { className: css(""), onKeyDown: handleEscKey, children: [
|
|
444
|
+
/* @__PURE__ */ jsx("label", { htmlFor: inputId, children: (required ? "* " : "") + (label ?? "Velg dato") }),
|
|
445
|
+
/* @__PURE__ */ jsx(
|
|
446
|
+
DatePickerInput,
|
|
447
|
+
{
|
|
448
|
+
describedBy: buttonLabel + " " + describedBy,
|
|
449
|
+
value: currentValue,
|
|
450
|
+
dateFormatter: dateFormatLong,
|
|
451
|
+
valueAsDate,
|
|
452
|
+
formattedValue: displayDate,
|
|
453
|
+
onInput: handleInputChange,
|
|
454
|
+
onBlur: handleBlur,
|
|
455
|
+
onFocus: handleFocus,
|
|
456
|
+
name,
|
|
457
|
+
disabled,
|
|
458
|
+
readonly,
|
|
459
|
+
role,
|
|
460
|
+
required,
|
|
461
|
+
identifier: inputId,
|
|
462
|
+
localization,
|
|
463
|
+
buttonLabel,
|
|
464
|
+
buttonRef: setToggleRef,
|
|
465
|
+
inputRef: setTextInputRef,
|
|
466
|
+
touched,
|
|
467
|
+
makeTouched,
|
|
468
|
+
formId
|
|
469
|
+
}
|
|
470
|
+
),
|
|
471
|
+
/* @__PURE__ */ jsx("div", { className: css("__dialog-container"), children: /* @__PURE__ */ jsx(
|
|
472
|
+
"div",
|
|
473
|
+
{
|
|
474
|
+
className: css("__dialog") + " " + (open ? css("is-active") : ""),
|
|
475
|
+
role: "dialog",
|
|
476
|
+
"aria-modal": "true",
|
|
477
|
+
"aria-hidden": open ? "false" : "true",
|
|
478
|
+
"aria-labelledby": labelId,
|
|
479
|
+
onTouchStart: handleTouchStart,
|
|
480
|
+
onTouchEnd: handleTouchEnd,
|
|
481
|
+
children: /* @__PURE__ */ jsxs("div", { className: css("__dialog-content"), children: [
|
|
482
|
+
/* @__PURE__ */ jsxs("div", { className: css("__header"), children: [
|
|
483
|
+
/* @__PURE__ */ jsxs(
|
|
484
|
+
"h2",
|
|
485
|
+
{
|
|
486
|
+
id: labelId,
|
|
487
|
+
className: css("__vhidden"),
|
|
488
|
+
"aria-live": "polite",
|
|
489
|
+
"aria-atomic": "true",
|
|
490
|
+
children: [
|
|
491
|
+
localization.monthNames[focusedMonth],
|
|
492
|
+
" ",
|
|
493
|
+
focusedDay.getFullYear()
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
),
|
|
497
|
+
/* @__PURE__ */ jsxs("div", { className: css("__nav"), children: [
|
|
498
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
499
|
+
"button",
|
|
500
|
+
{
|
|
501
|
+
className: css("__year-button"),
|
|
502
|
+
onClick: handleOnYearDialogOpenClick,
|
|
503
|
+
disabled: nextYearDisabled,
|
|
504
|
+
type: "button",
|
|
505
|
+
"aria-label": localization.nextMonthLabel,
|
|
506
|
+
children: [
|
|
507
|
+
/* @__PURE__ */ jsx("span", { children: focusedYear }),
|
|
508
|
+
/* @__PURE__ */ jsx(Icon, { name: "chevron-down", className: css("__year-chevron") })
|
|
509
|
+
]
|
|
510
|
+
}
|
|
511
|
+
) }),
|
|
512
|
+
!showYearDialog && /* @__PURE__ */ jsxs("div", { className: css("__nav-month"), children: [
|
|
513
|
+
/* @__PURE__ */ jsx(
|
|
514
|
+
"button",
|
|
515
|
+
{
|
|
516
|
+
className: css("__prev"),
|
|
517
|
+
onClick: handlePreviousMonthClick,
|
|
518
|
+
disabled: prevMonthDisabled,
|
|
519
|
+
type: "button",
|
|
520
|
+
"aria-label": localization.prevMonthLabel,
|
|
521
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left" })
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
/* @__PURE__ */ jsx("div", { className: css("__select-label"), children: /* @__PURE__ */ jsx("span", { children: localization.monthNames[focusedMonth] }) }),
|
|
525
|
+
/* @__PURE__ */ jsx(
|
|
526
|
+
"button",
|
|
527
|
+
{
|
|
528
|
+
className: css("__next"),
|
|
529
|
+
onClick: handleNextMonthClick,
|
|
530
|
+
disabled: nextMonthDisabled,
|
|
531
|
+
type: "button",
|
|
532
|
+
"aria-label": localization.nextMonthLabel,
|
|
533
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "chevron-right" })
|
|
534
|
+
}
|
|
535
|
+
)
|
|
536
|
+
] }),
|
|
537
|
+
showYearDialog && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
538
|
+
"button",
|
|
539
|
+
{
|
|
540
|
+
className: css("__close_year"),
|
|
541
|
+
onClick: handleOnYearDialogCloseClick,
|
|
542
|
+
type: "button",
|
|
543
|
+
"aria-label": "Lukk",
|
|
544
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "close" })
|
|
545
|
+
}
|
|
546
|
+
) })
|
|
547
|
+
] })
|
|
548
|
+
] }),
|
|
549
|
+
showYearDialog && /* @__PURE__ */ jsx(
|
|
550
|
+
DatePickerYear,
|
|
551
|
+
{
|
|
552
|
+
selectedYear: valueAsDate ? valueAsDate.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear(),
|
|
553
|
+
focusedYear,
|
|
554
|
+
onYearSelect: onHandleYearSelected,
|
|
555
|
+
labelledById: labelYearId,
|
|
556
|
+
localization,
|
|
557
|
+
onKeyboardNavigation: handleKeyboardNavigationYear,
|
|
558
|
+
min: minYear,
|
|
559
|
+
max: maxYear
|
|
560
|
+
}
|
|
561
|
+
),
|
|
562
|
+
!showYearDialog && /* @__PURE__ */ jsx(
|
|
563
|
+
DatePickerMonth,
|
|
564
|
+
{
|
|
565
|
+
dateFormatter: dateFormatShort,
|
|
566
|
+
selectedDate: valueAsDate,
|
|
567
|
+
focusedDate: focusedDay,
|
|
568
|
+
onDateSelect: handleDaySelect,
|
|
569
|
+
labelledById: labelId,
|
|
570
|
+
localization,
|
|
571
|
+
firstDayOfWeek: DaysOfWeek.Monday,
|
|
572
|
+
onKeyboardNavigation: handleKeyboardNavigation,
|
|
573
|
+
min: minDate,
|
|
574
|
+
max: maxDate,
|
|
575
|
+
isDateDisabled
|
|
576
|
+
}
|
|
577
|
+
)
|
|
578
|
+
] })
|
|
579
|
+
}
|
|
580
|
+
) }),
|
|
581
|
+
showError && /* @__PURE__ */ jsxs(
|
|
582
|
+
"label",
|
|
583
|
+
{
|
|
584
|
+
className: css("__error"),
|
|
585
|
+
id: errorId,
|
|
586
|
+
children: [
|
|
587
|
+
/* @__PURE__ */ jsx(Icon, { name: "error" }),
|
|
588
|
+
errorMessage
|
|
589
|
+
]
|
|
590
|
+
}
|
|
591
|
+
)
|
|
592
|
+
] }) });
|
|
593
|
+
};
|
|
594
|
+
export {
|
|
595
|
+
DateDisabledPredicate,
|
|
596
|
+
DatePicker
|
|
597
|
+
};
|