@oslokommune/punkt-react 19.15.6 → 19.16.1
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 +30 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/accordion/Accordion.js +28 -0
- package/dist/components/accordion/AccordionItem.js +60 -0
- package/dist/components/alert/Alert.js +76 -0
- package/dist/components/backlink/BackLink.js +35 -0
- package/dist/components/breadcrumbs/Breadcrumbs.js +67 -0
- package/dist/components/button/Button.js +54 -0
- package/dist/components/calendar/Calendar.js +49 -0
- package/dist/components/calendar/CalendarGrid.js +99 -0
- package/dist/components/calendar/CalendarNav.js +89 -0
- package/dist/components/calendar/calendar-utils.js +44 -0
- package/dist/components/calendar/useCalendarState.js +214 -0
- package/dist/components/card/Card.js +99 -0
- package/dist/components/checkbox/Checkbox.js +101 -0
- package/dist/components/checkboxgroup/CheckboxGroup.js +88 -0
- package/dist/components/checkboxgroup/CheckboxGroupContext.js +5 -0
- package/dist/components/combobox/Combobox.js +65 -0
- package/dist/components/combobox/ComboboxInput.js +87 -0
- package/dist/components/combobox/ComboboxTags.js +82 -0
- package/dist/components/combobox/Listbox.js +136 -0
- package/dist/components/combobox/useComboboxState.js +577 -0
- package/dist/components/consent/Consent.js +110 -0
- package/dist/components/datepicker/DateTags.js +28 -0
- package/dist/components/datepicker/Datepicker.js +79 -0
- package/dist/components/datepicker/DatepickerInputs.js +149 -0
- package/dist/components/datepicker/DatepickerPopup.js +41 -0
- package/dist/components/datepicker/useDatepickerState.js +243 -0
- package/dist/components/fileupload/DropZone.js +131 -0
- package/dist/components/fileupload/FileUpload.js +223 -0
- package/dist/components/fileupload/FileUploadContext.d.ts +2 -0
- package/dist/components/fileupload/FileUploadContext.js +6 -0
- package/dist/components/fileupload/QueueDisplay.js +67 -0
- package/dist/components/fileupload/QueueItemContent.js +88 -0
- package/dist/components/fileupload/Subcomponents.js +265 -0
- package/dist/components/fileupload/Truncate.js +22 -0
- package/dist/components/fileupload/extensions/Comments.js +128 -0
- package/dist/components/fileupload/extensions/Remove.js +9 -0
- package/dist/components/fileupload/extensions/Rename.js +66 -0
- package/dist/components/fileupload/hooks/useFileAttributes.js +25 -0
- package/dist/components/fileupload/hooks/useImageObjectUrl.js +15 -0
- package/dist/components/fileupload/hooks/useImagePreview.js +24 -0
- package/dist/components/fileupload/hooks/useOperationState.js +31 -0
- package/dist/components/fileupload/hooks/useRequiredFormValidation.js +23 -0
- package/dist/components/fileupload/types.d.ts +0 -1
- package/dist/components/fileupload/types.js +12 -0
- package/dist/components/footer/Footer.js +134 -0
- package/dist/components/footer/FooterGlobal.js +105 -0
- package/dist/components/footerSimple/FooterSimple.js +87 -0
- package/dist/components/header/Header.js +15 -0
- package/dist/components/header/HeaderGlobal.js +286 -0
- package/dist/components/header/HeaderService.js +281 -0
- package/dist/components/header-menu/HeaderMenu.js +197 -0
- package/dist/components/headerUserMenu/UserMenu.js +134 -0
- package/dist/components/heading/Heading.js +37 -0
- package/dist/components/helptext/Helptext.js +50 -0
- package/dist/components/icon/Icon.d.ts +6 -0
- package/dist/components/icon/Icon.js +69 -0
- package/dist/components/input/Input.js +23 -0
- package/dist/components/inputwrapper/InputWrapper.js +128 -0
- package/dist/components/link/Link.js +34 -0
- package/dist/components/linkcard/LinkCard.js +38 -0
- package/dist/components/loader/Loader.js +47 -0
- package/dist/components/messagebox/Messagebox.js +50 -0
- package/dist/components/modal/Modal.js +89 -0
- package/dist/components/progressbar/Progressbar.js +62 -0
- package/dist/components/radio/RadioButton.js +85 -0
- package/dist/components/radiogroup/RadioGroup.js +70 -0
- package/dist/components/radiogroup/RadioGroupContext.js +5 -0
- package/dist/components/searchinput/SearchInput.js +102 -0
- package/dist/components/select/Select.js +56 -0
- package/dist/components/stepper/Step.js +78 -0
- package/dist/components/stepper/Stepper.js +21 -0
- package/dist/components/strings/PktStringsProvider.js +21 -0
- package/dist/components/table/Table.js +19 -0
- package/dist/components/table/TableBody.js +13 -0
- package/dist/components/table/TableDataCell.js +14 -0
- package/dist/components/table/TableHeader.js +12 -0
- package/dist/components/table/TableHeaderCell.js +12 -0
- package/dist/components/table/TableRow.js +12 -0
- package/dist/components/tabs/TabItem.js +60 -0
- package/dist/components/tabs/Tabs.js +90 -0
- package/dist/components/tag/Tag.js +76 -0
- package/dist/components/textarea/Textarea.js +74 -0
- package/dist/components/textinput/Textinput.js +106 -0
- package/dist/components/timepicker/Timepicker.js +224 -0
- package/dist/components/timepicker/useTimepickerState.js +483 -0
- package/dist/hooks/useElementWidth.js +23 -0
- package/dist/hooks/useFocusModality.js +28 -0
- package/dist/hooks/useGeneratedId.js +8 -0
- package/dist/hooks/useHeaderChrome.js +36 -0
- package/dist/hooks/useOptionGroupField.js +70 -0
- package/dist/hooks/useOwnerForm.js +15 -0
- package/dist/hooks/usePktStrings.js +16 -0
- package/dist/hooks/useScrollLock.js +12 -0
- package/dist/node_modules/@date-fns/tz/date/index.js +57 -0
- package/dist/node_modules/@date-fns/tz/date/mini.js +75 -0
- package/dist/node_modules/@date-fns/tz/index.js +6 -0
- package/dist/node_modules/@date-fns/tz/tz/index.js +1 -0
- package/dist/node_modules/@date-fns/tz/tzName/index.js +10 -0
- package/dist/node_modules/@date-fns/tz/tzOffset/index.js +22 -0
- package/dist/node_modules/classnames/index.js +32 -0
- package/dist/node_modules/date-fns/_lib/addLeadingZeros.js +6 -0
- package/dist/node_modules/date-fns/_lib/defaultOptions.js +7 -0
- package/dist/node_modules/date-fns/_lib/format/formatters.js +389 -0
- package/dist/node_modules/date-fns/_lib/format/lightFormatters.js +43 -0
- package/dist/node_modules/date-fns/_lib/format/longFormatters.js +38 -0
- package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +8 -0
- package/dist/node_modules/date-fns/_lib/normalizeDates.js +8 -0
- package/dist/node_modules/date-fns/_lib/normalizeInterval.js +11 -0
- package/dist/node_modules/date-fns/_lib/protectedTokens.js +23 -0
- package/dist/node_modules/date-fns/addDays.js +9 -0
- package/dist/node_modules/date-fns/constants.js +10 -0
- package/dist/node_modules/date-fns/constructFrom.js +7 -0
- package/dist/node_modules/date-fns/differenceInCalendarDays.js +11 -0
- package/dist/node_modules/date-fns/eachDayOfInterval.js +15 -0
- package/dist/node_modules/date-fns/endOfDay.js +8 -0
- package/dist/node_modules/date-fns/format.js +59 -0
- package/dist/node_modules/date-fns/getDayOfYear.js +10 -0
- package/dist/node_modules/date-fns/getISODay.js +8 -0
- package/dist/node_modules/date-fns/getISOWeek.js +11 -0
- package/dist/node_modules/date-fns/getISOWeekYear.js +14 -0
- package/dist/node_modules/date-fns/getWeek.js +11 -0
- package/dist/node_modules/date-fns/getWeekYear.js +15 -0
- package/dist/node_modules/date-fns/isDate.js +6 -0
- package/dist/node_modules/date-fns/isValid.js +8 -0
- package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +9 -0
- package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +17 -0
- package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.js +22 -0
- package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +18 -0
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +69 -0
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.js +32 -0
- package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +11 -0
- package/dist/node_modules/date-fns/locale/en-US/_lib/localize.js +202 -0
- package/dist/node_modules/date-fns/locale/en-US/_lib/match.js +124 -0
- package/dist/node_modules/date-fns/locale/en-US.js +20 -0
- package/dist/node_modules/date-fns/startOfDay.js +8 -0
- package/dist/node_modules/date-fns/startOfISOWeek.js +10 -0
- package/dist/node_modules/date-fns/startOfISOWeekYear.js +10 -0
- package/dist/node_modules/date-fns/startOfWeek.js +9 -0
- package/dist/node_modules/date-fns/startOfWeekYear.js +11 -0
- package/dist/node_modules/date-fns/startOfYear.js +8 -0
- package/dist/node_modules/date-fns/toDate.js +7 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +55 -9388
- package/dist/shared-strings/consent.js +113 -0
- package/dist/shared-strings/format.js +18 -0
- package/dist/shared-strings/nb.js +201 -0
- package/dist/shared-strings/resolve.js +40 -0
- package/dist/shared-strings/store.js +35 -0
- package/dist/shared-types/accordion.js +4 -0
- package/dist/shared-types/calendar.js +12 -0
- package/dist/shared-types/card.js +15 -0
- package/dist/shared-types/checkbox.js +15 -0
- package/dist/shared-types/combobox.js +19 -0
- package/dist/shared-types/consent.js +8 -0
- package/dist/shared-types/footer.js +4 -0
- package/dist/shared-types/header-footer.js +4 -0
- package/dist/shared-types/icon.js +7 -0
- package/dist/shared-types/messagebox.js +8 -0
- package/dist/shared-types/option-group.js +14 -0
- package/dist/shared-types/radiobutton.js +11 -0
- package/dist/shared-types/select.js +14 -0
- package/dist/shared-types/table.js +8 -0
- package/dist/shared-utils/calendar/calendar-grid.js +19 -0
- package/dist/shared-utils/calendar/date-validation.js +19 -0
- package/dist/shared-utils/calendar/keyboard-navigation.js +26 -0
- package/dist/shared-utils/calendar/selection-manager.js +52 -0
- package/dist/shared-utils/combobox/input-utils.js +39 -0
- package/dist/shared-utils/combobox/keyboard-navigation.js +41 -0
- package/dist/shared-utils/combobox/option-utils.js +48 -0
- package/dist/shared-utils/date-utils.js +71 -0
- package/dist/shared-utils/datepicker-utils.js +32 -0
- package/dist/shared-utils/device-utils.js +7 -0
- package/dist/shared-utils/fileupload/announcements.js +21 -0
- package/dist/shared-utils/fileupload/filename.js +8 -0
- package/dist/shared-utils/fileupload/focus-trap.js +2 -0
- package/dist/shared-utils/fileupload/formats.js +29 -0
- package/dist/shared-utils/fileupload/index.js +11 -0
- package/dist/shared-utils/fileupload/navigation.js +6 -0
- package/dist/shared-utils/fileupload/size.js +25 -0
- package/dist/shared-utils/fileupload/transfers.js +23 -0
- package/dist/shared-utils/fileupload/truncate.js +9 -0
- package/dist/shared-utils/fileupload/validation.js +32 -0
- package/dist/shared-utils/focus-trap/index.js +60 -0
- package/dist/shared-utils/forms/described-by.js +7 -0
- package/dist/shared-utils/header-footer/external-domain.js +30 -0
- package/dist/shared-utils/header-footer/fetch-header-footer-data.js +29 -0
- package/dist/shared-utils/header-footer/icon-map.js +55 -0
- package/dist/shared-utils/header-footer/select-megamenu.js +7 -0
- package/dist/shared-utils/scroll-lock/index.js +21 -0
- package/dist/shared-utils/timepicker/options.js +10 -0
- package/dist/shared-utils/timepicker/stepper.js +10 -0
- package/dist/shared-utils/timepicker/time-utils.js +7 -0
- package/dist/shared-utils/value-utils.js +12 -0
- package/dist/utils/nativeInputValue.js +6 -0
- package/dist/utils/stableKeys.js +13 -0
- package/dist/utils/stringutils.js +7 -0
- package/package.json +3 -2
- package/src/components/checkbox/Checkbox.tsx +2 -0
- package/src/components/combobox/types.ts +0 -2
- package/src/components/fileupload/FileUpload.tsx +3 -1
- package/src/components/fileupload/FileUploadContext.ts +7 -0
- package/src/components/fileupload/QueueDisplay.tsx +3 -3
- package/src/components/fileupload/Subcomponents.tsx +2 -7
- package/src/components/fileupload/extensions/Comments.tsx +2 -1
- package/src/components/fileupload/extensions/Rename.tsx +2 -1
- package/src/components/fileupload/types.ts +1 -2
- package/src/components/header/Header.test.tsx +0 -7
- package/src/components/header/Header.tsx +0 -2
- package/src/components/heading/Heading.tsx +0 -2
- package/src/components/hydration.test.tsx +61 -15
- package/src/components/icon/Icon.test.tsx +0 -7
- package/src/components/icon/Icon.tsx +7 -0
- package/src/components/input/Input.tsx +0 -2
- package/src/components/link/Link.tsx +0 -2
- package/src/components/radio/RadioButton.tsx +2 -0
- package/src/components/server-components.test.ts +69 -0
- package/src/components/stepper/Step.tsx +0 -2
- package/src/components/stepper/Stepper.tsx +0 -2
- package/src/components/strings/PktStringsProvider.tsx +2 -0
- package/src/components/table/Table.tsx +0 -2
- package/src/components/table/TableBody.tsx +1 -3
- package/src/components/table/TableDataCell.tsx +0 -2
- package/src/components/table/TableHeader.tsx +0 -2
- package/src/components/table/TableHeaderCell.tsx +0 -2
- package/src/components/table/TableRow.tsx +0 -2
- package/dist/components/accordion/Accordion.test.d.ts +0 -0
- package/dist/components/alert/Alert.test.d.ts +0 -0
- package/dist/components/backlink/BackLink.test.d.ts +0 -0
- package/dist/components/breadcrumbs/Breadcrumbs.test.d.ts +0 -1
- package/dist/components/button/Button.test.d.ts +0 -0
- package/dist/components/calendar/Calendar.accessibility.test.d.ts +0 -0
- package/dist/components/calendar/Calendar.constraints.test.d.ts +0 -0
- package/dist/components/calendar/Calendar.core.test.d.ts +0 -0
- package/dist/components/calendar/Calendar.interaction.test.d.ts +0 -0
- package/dist/components/calendar/Calendar.selection.test.d.ts +0 -0
- package/dist/components/card/Card.test.d.ts +0 -0
- package/dist/components/checkbox/Checkbox.test.d.ts +0 -0
- package/dist/components/checkboxgroup/CheckboxGroup.forms.test.d.ts +0 -0
- package/dist/components/checkboxgroup/CheckboxGroup.test.d.ts +0 -0
- package/dist/components/combobox/Combobox.accessibility.test.d.ts +0 -0
- package/dist/components/combobox/Combobox.core.test.d.ts +0 -0
- package/dist/components/combobox/Combobox.interaction.test.d.ts +0 -0
- package/dist/components/combobox/Combobox.preselection.test.d.ts +0 -0
- package/dist/components/combobox/Combobox.selection.test.d.ts +0 -0
- package/dist/components/consent/Consent.test.d.ts +0 -0
- package/dist/components/datepicker/Datepicker.accessibility.test.d.ts +0 -0
- package/dist/components/datepicker/Datepicker.core.test.d.ts +0 -0
- package/dist/components/datepicker/Datepicker.input.test.d.ts +0 -0
- package/dist/components/datepicker/Datepicker.selection.test.d.ts +0 -0
- package/dist/components/datepicker/Datepicker.validation.test.d.ts +0 -0
- package/dist/components/fileupload/FileUpload.test.d.ts +0 -0
- package/dist/components/fileupload/QueueDisplay.test.d.ts +0 -0
- package/dist/components/fileupload/Truncate.test.d.ts +0 -0
- package/dist/components/footer/Footer.accessibility.test.d.ts +0 -0
- package/dist/components/footer/Footer.test.d.ts +0 -1
- package/dist/components/footerSimple/FooterSimple.test.d.ts +0 -1
- package/dist/components/formAttribute.test.d.ts +0 -1
- package/dist/components/header/Header.test.d.ts +0 -0
- package/dist/components/header/HeaderGlobal.accessibility.test.d.ts +0 -0
- package/dist/components/header/HeaderGlobal.test.d.ts +0 -0
- package/dist/components/header/HeaderService.accessibility.test.d.ts +0 -0
- package/dist/components/header/HeaderService.test.d.ts +0 -0
- package/dist/components/header-menu/HeaderMenu.test.d.ts +0 -0
- package/dist/components/headerUserMenu/UserMenu.test.d.ts +0 -0
- package/dist/components/heading/Heading.test.d.ts +0 -0
- package/dist/components/helptext/Helptext.test.d.ts +0 -0
- package/dist/components/helptext/helptextAssociation.test.d.ts +0 -1
- package/dist/components/hydration.test.d.ts +0 -1
- package/dist/components/icon/Icon.test.d.ts +0 -9
- package/dist/components/inputwrapper/InputWrapper.test.d.ts +0 -0
- package/dist/components/link/Link.test.d.ts +0 -1
- package/dist/components/linkcard/LinkCard.test.d.ts +0 -0
- package/dist/components/loader/Loader.test.d.ts +0 -0
- package/dist/components/messagebox/Messagebox.test.d.ts +0 -1
- package/dist/components/modal/Modal.test.d.ts +0 -0
- package/dist/components/progressbar/Progressbar.test.d.ts +0 -0
- package/dist/components/radio/RadioButton.test.d.ts +0 -0
- package/dist/components/radiogroup/RadioGroup.forms.test.d.ts +0 -0
- package/dist/components/radiogroup/RadioGroup.test.d.ts +0 -0
- package/dist/components/searchinput/SearchInput.test.d.ts +0 -0
- package/dist/components/select/Select.test.d.ts +0 -0
- package/dist/components/ssr.test.d.ts +0 -1
- package/dist/components/stepper/Stepper.test.d.ts +0 -0
- package/dist/components/strings/strings-override.test.d.ts +0 -1
- package/dist/components/table/Table.test.d.ts +0 -0
- package/dist/components/tabs/Tabs.test.d.ts +0 -0
- package/dist/components/tag/Tag.test.d.ts +0 -0
- package/dist/components/textarea/Textarea.test.d.ts +0 -0
- package/dist/components/textinput/Textinput.test.d.ts +0 -0
- package/dist/components/timepicker/Timepicker.test.d.ts +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { PktIcon as e } from "../icon/Icon.js";
|
|
3
|
+
import { describedByIds as t } from "../../shared-utils/forms/described-by.js";
|
|
4
|
+
import { PktInputWrapper as n } from "../inputwrapper/InputWrapper.js";
|
|
5
|
+
import { useTimepickerState as r } from "./useTimepickerState.js";
|
|
6
|
+
import { forwardRef as i } from "react";
|
|
7
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
8
|
+
//#region src/components/timepicker/Timepicker.tsx
|
|
9
|
+
var s = i((i, s) => {
|
|
10
|
+
let { onChange: c, inputSize: l = "medium" } = i, u = r(i, s), d = u.strings.hours, f = u.strings.minutes, p = u.label ? `${d}, ${u.label}` : d, m = u.label ? `${f}, ${u.label}` : f, h = t({
|
|
11
|
+
id: u.hoursId,
|
|
12
|
+
hasHelptext: !!u.helptext,
|
|
13
|
+
ariaDescribedby: u.ariaDescribedby
|
|
14
|
+
}), g = (e, t) => {
|
|
15
|
+
let n = String(e).padStart(2, "0"), r = e === (t === "hour" ? u.hours === "" ? NaN : parseInt(u.hours, 10) : u.minutes === "" ? NaN : parseInt(u.minutes, 10));
|
|
16
|
+
return /* @__PURE__ */ a("button", {
|
|
17
|
+
type: "button",
|
|
18
|
+
className: [
|
|
19
|
+
"pkt-btn",
|
|
20
|
+
"pkt-btn--tertiary",
|
|
21
|
+
"pkt-btn--small",
|
|
22
|
+
"pkt-btn--label-only",
|
|
23
|
+
"pkt-timepicker-popup__option",
|
|
24
|
+
r ? "pkt-timepicker-popup__option--selected" : ""
|
|
25
|
+
].filter(Boolean).join(" "),
|
|
26
|
+
role: "option",
|
|
27
|
+
"aria-selected": r ? "true" : "false",
|
|
28
|
+
tabIndex: r ? 0 : -1,
|
|
29
|
+
"data-type": t,
|
|
30
|
+
"data-value": e,
|
|
31
|
+
onClick: (n) => {
|
|
32
|
+
n.stopPropagation(), u.handleOptionClick(e, t);
|
|
33
|
+
},
|
|
34
|
+
children: /* @__PURE__ */ a("span", {
|
|
35
|
+
className: "pkt-btn__text pkt-txt-14-light",
|
|
36
|
+
children: n
|
|
37
|
+
})
|
|
38
|
+
}, `${t}-${e}`);
|
|
39
|
+
}, _ = () => /* @__PURE__ */ o("div", {
|
|
40
|
+
ref: u.popupRef,
|
|
41
|
+
className: "pkt-timepicker-popup",
|
|
42
|
+
id: u.popupId,
|
|
43
|
+
hidden: !u.isOpen,
|
|
44
|
+
role: "group",
|
|
45
|
+
"aria-label": u.strings.selectTime,
|
|
46
|
+
onKeyDown: u.handlePopupKeydown,
|
|
47
|
+
onBlur: u.handlePopupFocusOut,
|
|
48
|
+
children: [/* @__PURE__ */ a("div", {
|
|
49
|
+
className: "pkt-timepicker-popup__col",
|
|
50
|
+
role: "listbox",
|
|
51
|
+
"aria-label": d,
|
|
52
|
+
"aria-orientation": "vertical",
|
|
53
|
+
children: u.hourOptions.map((e) => g(e, "hour"))
|
|
54
|
+
}), /* @__PURE__ */ a("div", {
|
|
55
|
+
className: "pkt-timepicker-popup__col",
|
|
56
|
+
role: "listbox",
|
|
57
|
+
"aria-label": f,
|
|
58
|
+
"aria-orientation": "vertical",
|
|
59
|
+
children: u.minuteOptions.map((e) => g(e, "minute"))
|
|
60
|
+
})]
|
|
61
|
+
}), v = () => /* @__PURE__ */ o("div", {
|
|
62
|
+
className: `pkt-input__container pkt-input__container--${l}`,
|
|
63
|
+
onClick: (e) => {
|
|
64
|
+
e.target.closest("button, input") || u.hoursInputRef.current?.focus();
|
|
65
|
+
},
|
|
66
|
+
children: [
|
|
67
|
+
u.stepArrows && /* @__PURE__ */ o("button", {
|
|
68
|
+
type: "button",
|
|
69
|
+
className: `pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${l} pkt-timepicker__button pkt-timepicker__button--prev`,
|
|
70
|
+
"aria-label": u.strings.prevTime,
|
|
71
|
+
disabled: u.disabled,
|
|
72
|
+
onClick: () => u.stepTimeDelta(-1),
|
|
73
|
+
children: [/* @__PURE__ */ a(e, { name: "chevron-thin-left" }), /* @__PURE__ */ a("span", {
|
|
74
|
+
className: "pkt-btn__text",
|
|
75
|
+
children: u.strings.prevTime
|
|
76
|
+
})]
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ a("input", {
|
|
79
|
+
ref: u.hoursInputRef,
|
|
80
|
+
type: "text",
|
|
81
|
+
inputMode: "numeric",
|
|
82
|
+
maxLength: 2,
|
|
83
|
+
size: 2,
|
|
84
|
+
className: `pkt-input pkt-input--${l} pkt-timepicker__input`,
|
|
85
|
+
id: u.hoursId,
|
|
86
|
+
"data-min": "0",
|
|
87
|
+
"data-max": "23",
|
|
88
|
+
value: u.hours,
|
|
89
|
+
placeholder: "––",
|
|
90
|
+
"aria-label": p,
|
|
91
|
+
role: "spinbutton",
|
|
92
|
+
"aria-invalid": u.hasError || u.isInvalid || void 0,
|
|
93
|
+
"aria-errormessage": u.hasError ? `${u.hoursId}-error` : void 0,
|
|
94
|
+
"aria-describedby": h,
|
|
95
|
+
"aria-valuemin": 0,
|
|
96
|
+
"aria-valuemax": 23,
|
|
97
|
+
"aria-valuenow": u.hours === "" ? void 0 : parseInt(u.hours, 10),
|
|
98
|
+
"aria-valuetext": u.hours === "" ? void 0 : `${u.hours} ${d.toLowerCase()}`,
|
|
99
|
+
autoComplete: "off",
|
|
100
|
+
disabled: u.disabled,
|
|
101
|
+
onKeyDown: u.handleHoursKeydown,
|
|
102
|
+
onBlur: u.handleHoursBlur,
|
|
103
|
+
onFocus: (e) => {
|
|
104
|
+
e.currentTarget.select();
|
|
105
|
+
},
|
|
106
|
+
onChange: () => {},
|
|
107
|
+
onPaste: (e) => e.preventDefault()
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ a("span", {
|
|
110
|
+
className: "pkt-timepicker__separator",
|
|
111
|
+
children: ":"
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ a("input", {
|
|
114
|
+
ref: u.minutesInputRef,
|
|
115
|
+
type: "text",
|
|
116
|
+
inputMode: "numeric",
|
|
117
|
+
maxLength: 2,
|
|
118
|
+
size: 2,
|
|
119
|
+
className: `pkt-input pkt-input--${l} pkt-timepicker__input`,
|
|
120
|
+
id: u.minutesId,
|
|
121
|
+
"data-min": "0",
|
|
122
|
+
"data-max": "59",
|
|
123
|
+
value: u.minutes,
|
|
124
|
+
placeholder: "––",
|
|
125
|
+
"aria-label": m,
|
|
126
|
+
role: "spinbutton",
|
|
127
|
+
"aria-invalid": u.hasError || u.isInvalid || void 0,
|
|
128
|
+
"aria-errormessage": u.hasError ? `${u.hoursId}-error` : void 0,
|
|
129
|
+
"aria-describedby": h,
|
|
130
|
+
"aria-valuemin": 0,
|
|
131
|
+
"aria-valuemax": 59,
|
|
132
|
+
"aria-valuenow": u.minutes === "" ? void 0 : parseInt(u.minutes, 10),
|
|
133
|
+
"aria-valuetext": u.minutes === "" ? void 0 : `${u.minutes} ${f.toLowerCase()}`,
|
|
134
|
+
autoComplete: "off",
|
|
135
|
+
disabled: u.disabled,
|
|
136
|
+
onKeyDown: u.handleMinutesKeydown,
|
|
137
|
+
onBlur: u.handleMinutesBlur,
|
|
138
|
+
onFocus: (e) => {
|
|
139
|
+
e.currentTarget.select();
|
|
140
|
+
},
|
|
141
|
+
onChange: () => {},
|
|
142
|
+
onPaste: (e) => e.preventDefault()
|
|
143
|
+
}),
|
|
144
|
+
u.hidePicker && !u.stepArrows && /* @__PURE__ */ a(e, {
|
|
145
|
+
className: "pkt-input-icon pkt-timepicker__icon",
|
|
146
|
+
name: "clock",
|
|
147
|
+
"aria-hidden": !0
|
|
148
|
+
}),
|
|
149
|
+
!u.hidePicker && !u.stepArrows && /* @__PURE__ */ o("button", {
|
|
150
|
+
ref: u.buttonRef,
|
|
151
|
+
type: "button",
|
|
152
|
+
className: `pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${l} pkt-timepicker__button`,
|
|
153
|
+
"aria-label": u.strings.openPicker,
|
|
154
|
+
"aria-haspopup": "listbox",
|
|
155
|
+
"aria-expanded": u.isOpen,
|
|
156
|
+
"aria-controls": u.popupId,
|
|
157
|
+
disabled: u.disabled,
|
|
158
|
+
onClick: u.handleClockButtonClick,
|
|
159
|
+
children: [/* @__PURE__ */ a(e, { name: "clock" }), /* @__PURE__ */ a("span", {
|
|
160
|
+
className: "pkt-btn__text",
|
|
161
|
+
children: u.strings.openPicker
|
|
162
|
+
})]
|
|
163
|
+
}),
|
|
164
|
+
u.stepArrows && /* @__PURE__ */ o("button", {
|
|
165
|
+
type: "button",
|
|
166
|
+
className: `pkt-input-icon pkt-btn pkt-btn--icon-only pkt-btn--tertiary pkt-btn--${l} pkt-timepicker__button pkt-timepicker__button--next`,
|
|
167
|
+
"aria-label": u.strings.nextTime,
|
|
168
|
+
disabled: u.disabled,
|
|
169
|
+
onClick: () => u.stepTimeDelta(1),
|
|
170
|
+
children: [/* @__PURE__ */ a(e, { name: "chevron-thin-right" }), /* @__PURE__ */ a("span", {
|
|
171
|
+
className: "pkt-btn__text",
|
|
172
|
+
children: u.strings.nextTime
|
|
173
|
+
})]
|
|
174
|
+
}),
|
|
175
|
+
/* @__PURE__ */ a("input", {
|
|
176
|
+
ref: u.changeInputRef,
|
|
177
|
+
type: "time",
|
|
178
|
+
hidden: !0,
|
|
179
|
+
name: u.name,
|
|
180
|
+
form: u.form,
|
|
181
|
+
id: u.hiddenInputId,
|
|
182
|
+
disabled: u.disabled,
|
|
183
|
+
tabIndex: -1,
|
|
184
|
+
"aria-hidden": !0,
|
|
185
|
+
onChange: c
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
return /* @__PURE__ */ a("div", {
|
|
190
|
+
ref: u.containerRef,
|
|
191
|
+
className: u.outerClasses,
|
|
192
|
+
id: u.id || void 0,
|
|
193
|
+
onFocus: u.handleFocusIn,
|
|
194
|
+
onBlur: u.handleFocusOut,
|
|
195
|
+
children: /* @__PURE__ */ a(n, {
|
|
196
|
+
strings: u.stringsOverride,
|
|
197
|
+
forId: u.hoursId,
|
|
198
|
+
label: u.label,
|
|
199
|
+
disabled: u.disabled,
|
|
200
|
+
hasError: u.hasError,
|
|
201
|
+
hasFieldset: i.hasFieldset ?? !1,
|
|
202
|
+
inline: u.inline,
|
|
203
|
+
optionalTag: u.optionalTag,
|
|
204
|
+
optionalText: u.optionalText,
|
|
205
|
+
requiredTag: u.requiredTag,
|
|
206
|
+
requiredText: u.requiredText,
|
|
207
|
+
useWrapper: u.useWrapper,
|
|
208
|
+
ariaDescribedby: u.ariaDescribedby,
|
|
209
|
+
errorMessage: u.errorMessage,
|
|
210
|
+
helptext: u.helptext,
|
|
211
|
+
helptextDropdown: u.helptextDropdown,
|
|
212
|
+
helptextDropdownButton: u.helptextDropdownButton,
|
|
213
|
+
tagText: u.tagText,
|
|
214
|
+
size: l,
|
|
215
|
+
children: !u.hidePicker && !u.stepArrows ? /* @__PURE__ */ o("div", {
|
|
216
|
+
className: "pkt-timepicker__anchor",
|
|
217
|
+
children: [v(), _()]
|
|
218
|
+
}) : v()
|
|
219
|
+
})
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
s.displayName = "PktTimepicker";
|
|
223
|
+
//#endregion
|
|
224
|
+
export { s as PktTimepicker };
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { formatString as e } from "../../shared-strings/format.js";
|
|
2
|
+
import { usePktStrings as t } from "../../hooks/usePktStrings.js";
|
|
3
|
+
import { useOwnerForm as n } from "../../hooks/useOwnerForm.js";
|
|
4
|
+
import { setNativeInputValue as r } from "../../utils/nativeInputValue.js";
|
|
5
|
+
import { getHourOptions as i, getMinuteOptions as a, getMinuteStep as ee } from "../../shared-utils/timepicker/options.js";
|
|
6
|
+
import { stepTime as o } from "../../shared-utils/timepicker/stepper.js";
|
|
7
|
+
import { isValidTimeString as s, timeToMinutes as c } from "../../shared-utils/timepicker/time-utils.js";
|
|
8
|
+
import { useCallback as l, useEffect as u, useImperativeHandle as d, useLayoutEffect as te, useMemo as f, useRef as p, useState as m } from "react";
|
|
9
|
+
//#region src/components/timepicker/useTimepickerState.ts
|
|
10
|
+
function h(e) {
|
|
11
|
+
if (e && s(e)) {
|
|
12
|
+
let [t, n] = e.split(":");
|
|
13
|
+
return [t, n];
|
|
14
|
+
}
|
|
15
|
+
return ["", ""];
|
|
16
|
+
}
|
|
17
|
+
function ne(e, t) {
|
|
18
|
+
return `${String(parseInt(e, 10)).padStart(2, "0")}:${String(parseInt(t, 10)).padStart(2, "0")}`;
|
|
19
|
+
}
|
|
20
|
+
function re(t, n, r) {
|
|
21
|
+
let { required: i, min: a, max: o, step: l } = n;
|
|
22
|
+
if (i && !t) return {
|
|
23
|
+
valid: !1,
|
|
24
|
+
message: r.valueMissing
|
|
25
|
+
};
|
|
26
|
+
if (!t) return { valid: !0 };
|
|
27
|
+
if (!s(t)) return {
|
|
28
|
+
valid: !1,
|
|
29
|
+
message: r.typeMismatch
|
|
30
|
+
};
|
|
31
|
+
let u = c(t), d = ee(l);
|
|
32
|
+
return a && u < c(String(a)) ? {
|
|
33
|
+
valid: !1,
|
|
34
|
+
message: e(r.rangeUnderflowMin, { min: String(a) })
|
|
35
|
+
} : o && u > c(String(o)) ? {
|
|
36
|
+
valid: !1,
|
|
37
|
+
message: e(r.rangeOverflowMax, { max: String(o) })
|
|
38
|
+
} : l && u % d !== 0 ? {
|
|
39
|
+
valid: !1,
|
|
40
|
+
message: d === 60 ? r.timeStepMismatchHour : d === 30 ? r.timeStepMismatchHalfHour : e(r.timeStepMismatch, { step: `${d}, ${d * 2}, ${d * 3}` })
|
|
41
|
+
} : { valid: !0 };
|
|
42
|
+
}
|
|
43
|
+
function ie(e) {
|
|
44
|
+
return e === 3600 || e < 3600 && 3600 % e == 0 && e % 60 == 0;
|
|
45
|
+
}
|
|
46
|
+
function ae(e, s) {
|
|
47
|
+
let { id: c, label: ae, value: g, defaultValue: _, min: v, max: y, step: b = 60, hidePicker: oe = !1, stepArrows: se = !1, fullwidth: ce = !1, name: le, form: ue, disabled: x = !1, required: S = !1, helptext: de, helptextDropdown: fe, helptextDropdownButton: pe, hasError: me = !1, errorMessage: he, optionalTag: ge = !1, optionalText: _e, requiredTag: ve = !1, requiredText: ye, tagText: be, inline: xe = !1, useWrapper: Se = !0, ariaDescribedby: Ce, strings: we, className: Te, inputSize: Ee = "medium", onValueChange: C, onFocus: De, onBlur: Oe } = e, w = t(["timepicker", "validation"], we), ke = w.timepicker, Ae = we, T = g !== void 0, je = g === void 0 ? _ ?? "" : g ?? "", Me = p(je), [Ne, E] = m(() => je), D = T ? g ?? "" : Ne, [Pe, Fe] = m(() => h(g === void 0 ? _ : g)[0]), [Ie, Le] = m(() => h(g === void 0 ? _ : g)[1]), O = p(Pe), k = p(Ie), A = l((e) => {
|
|
48
|
+
O.current = e, Fe(e);
|
|
49
|
+
}, []), j = l((e) => {
|
|
50
|
+
k.current = e, Le(e);
|
|
51
|
+
}, []), [M, N] = m(!1), [Re, ze] = m(g);
|
|
52
|
+
if (T && g !== Re) {
|
|
53
|
+
ze(g);
|
|
54
|
+
let [e, t] = h(g);
|
|
55
|
+
A(e), j(t);
|
|
56
|
+
}
|
|
57
|
+
u(() => {
|
|
58
|
+
b != null && !ie(b) && console.warn(`PktTimepicker: step="${b}" er ikke en gyldig verdi. Step må være et multiplum av 60 (hele minutter) eller nøyaktig 3600 (hel time).`);
|
|
59
|
+
}, [b]);
|
|
60
|
+
let P = p(null), F = p(null), I = p(null), L = p(null), R = p(null), z = p(null), B = n(R, ue), V = p(0), H = p(-1), U = p(0), W = p(-1), [Be, G] = m(!1), K = f(() => ee(b), [b]), Ve = f(() => i(v, y), [v, y]), He = f(() => a(b), [b]), Ue = `${c}-hours`, We = `${c}-minutes`, Ge = `${c}-popup`, Ke = `${c}-input`, q = f(() => re(D, {
|
|
61
|
+
required: S,
|
|
62
|
+
min: v,
|
|
63
|
+
max: y,
|
|
64
|
+
step: b
|
|
65
|
+
}, w.validation), [
|
|
66
|
+
D,
|
|
67
|
+
S,
|
|
68
|
+
v,
|
|
69
|
+
y,
|
|
70
|
+
b,
|
|
71
|
+
w.validation
|
|
72
|
+
]), qe = Be && !q.valid;
|
|
73
|
+
u(() => {
|
|
74
|
+
P.current?.setCustomValidity(q.valid ? "" : q.message ?? "");
|
|
75
|
+
}, [q]);
|
|
76
|
+
let J = l((e) => {
|
|
77
|
+
T || E(e);
|
|
78
|
+
let t = z.current;
|
|
79
|
+
t && (r(t, e), t.dispatchEvent(new Event("input", { bubbles: !0 })), C?.(e));
|
|
80
|
+
}, [T, C]), Y = l(() => {
|
|
81
|
+
let e = O.current, t = k.current;
|
|
82
|
+
if (e !== "" && t !== "") {
|
|
83
|
+
let n = ne(e, t);
|
|
84
|
+
n !== D && J(n);
|
|
85
|
+
} else D !== "" && J("");
|
|
86
|
+
}, [D, J]), X = l(() => {
|
|
87
|
+
let e = O.current, t = k.current;
|
|
88
|
+
if (e !== "" && t !== "") {
|
|
89
|
+
let n = ne(e, t);
|
|
90
|
+
n === D ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J(n);
|
|
91
|
+
} else D === "" ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J("");
|
|
92
|
+
}, [D, J]), Z = l(() => {
|
|
93
|
+
G(!0), Y();
|
|
94
|
+
let e = P.current, t = z.current;
|
|
95
|
+
if (!e) return;
|
|
96
|
+
let n = re(t?.value ?? "", {
|
|
97
|
+
required: S,
|
|
98
|
+
min: v,
|
|
99
|
+
max: y,
|
|
100
|
+
step: b
|
|
101
|
+
}, w.validation);
|
|
102
|
+
e.setCustomValidity(n.valid ? "" : n.message ?? "");
|
|
103
|
+
}, [
|
|
104
|
+
Y,
|
|
105
|
+
S,
|
|
106
|
+
v,
|
|
107
|
+
y,
|
|
108
|
+
b,
|
|
109
|
+
w.validation
|
|
110
|
+
]);
|
|
111
|
+
u(() => {
|
|
112
|
+
if (!B) return;
|
|
113
|
+
let e = (e) => {
|
|
114
|
+
let t = e;
|
|
115
|
+
if (!t || !B.contains(t)) return !1;
|
|
116
|
+
let n = t.closest("button, input[type=\"submit\"], input[type=\"image\"]");
|
|
117
|
+
return !n || !B.contains(n) ? !1 : n instanceof HTMLButtonElement ? n.type !== "button" && n.type !== "reset" : n instanceof HTMLInputElement;
|
|
118
|
+
}, t = (t) => {
|
|
119
|
+
e(t.target) && Z();
|
|
120
|
+
};
|
|
121
|
+
return B.addEventListener("pointerdown", t, !0), () => B.removeEventListener("pointerdown", t, !0);
|
|
122
|
+
}, [Z, B]), u(() => {
|
|
123
|
+
z.current && (z.current.value = D);
|
|
124
|
+
}, [D]);
|
|
125
|
+
let Q = l(() => {
|
|
126
|
+
N(!1), Y();
|
|
127
|
+
}, [Y]);
|
|
128
|
+
te(() => {
|
|
129
|
+
if (!M) return;
|
|
130
|
+
let e = L.current;
|
|
131
|
+
if (!e) return;
|
|
132
|
+
e.querySelectorAll(".pkt-timepicker-popup__col").forEach((e) => {
|
|
133
|
+
let t = e.querySelector(".pkt-timepicker-popup__option--selected");
|
|
134
|
+
t && t.scrollIntoView({ block: "center" });
|
|
135
|
+
});
|
|
136
|
+
let t = e.querySelectorAll(".pkt-timepicker-popup__col")[0];
|
|
137
|
+
if (!t) return;
|
|
138
|
+
let n = t.querySelector(".pkt-timepicker-popup__option--selected"), r = t.querySelector(".pkt-timepicker-popup__option");
|
|
139
|
+
(n || r)?.focus();
|
|
140
|
+
}, [M]), u(() => {
|
|
141
|
+
if (!M) return;
|
|
142
|
+
let e = (e) => {
|
|
143
|
+
let t = e.target;
|
|
144
|
+
R.current && !R.current.contains(t) && Q();
|
|
145
|
+
};
|
|
146
|
+
return document.addEventListener("click", e, !0), () => document.removeEventListener("click", e, !0);
|
|
147
|
+
}, [M, Q]);
|
|
148
|
+
let $ = l((e) => {
|
|
149
|
+
let t = L.current;
|
|
150
|
+
if (!t) return;
|
|
151
|
+
let n = t.querySelectorAll(".pkt-timepicker-popup__col"), r = e === "hour" ? n[0] : n[1];
|
|
152
|
+
if (!r) return;
|
|
153
|
+
let i = r.querySelector(".pkt-timepicker-popup__option--selected"), a = r.querySelector(".pkt-timepicker-popup__option");
|
|
154
|
+
(i || a)?.focus();
|
|
155
|
+
}, []), Je = l((e, t) => {
|
|
156
|
+
let n = String(e).padStart(2, "0");
|
|
157
|
+
if (t === "hour") A(n), requestAnimationFrame(() => $("minute"));
|
|
158
|
+
else {
|
|
159
|
+
j(n), N(!1);
|
|
160
|
+
let e = O.current;
|
|
161
|
+
e !== "" && J(`${e}:${n}`), requestAnimationFrame(() => I.current?.focus());
|
|
162
|
+
}
|
|
163
|
+
}, [
|
|
164
|
+
J,
|
|
165
|
+
$,
|
|
166
|
+
A,
|
|
167
|
+
j
|
|
168
|
+
]), Ye = l((e) => {
|
|
169
|
+
let t = o(O.current, k.current, e, K);
|
|
170
|
+
A(t.hours), j(t.minutes), `${t.hours}:${t.minutes}` !== D && J(`${t.hours}:${t.minutes}`);
|
|
171
|
+
}, [
|
|
172
|
+
K,
|
|
173
|
+
D,
|
|
174
|
+
J,
|
|
175
|
+
A,
|
|
176
|
+
j
|
|
177
|
+
]), Xe = l((e) => {
|
|
178
|
+
P.current?.setCustomValidity("");
|
|
179
|
+
let t = e.currentTarget, n = k.current;
|
|
180
|
+
switch (e.key) {
|
|
181
|
+
case "ArrowUp": {
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
let t = O.current === "" ? 0 : parseInt(O.current, 10), r = String((t + 1) % 24).padStart(2, "0");
|
|
184
|
+
if (A(r), n !== "") {
|
|
185
|
+
let e = `${r}:${n}`;
|
|
186
|
+
e === D ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J(e);
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "ArrowDown": {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
let t = O.current === "" ? 0 : parseInt(O.current, 10), r = String((t - 1 + 24) % 24).padStart(2, "0");
|
|
193
|
+
if (A(r), n !== "") {
|
|
194
|
+
let e = `${r}:${n}`;
|
|
195
|
+
e === D ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J(e);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "ArrowRight":
|
|
200
|
+
e.preventDefault(), F.current?.focus();
|
|
201
|
+
break;
|
|
202
|
+
case "Backspace":
|
|
203
|
+
case "Delete": {
|
|
204
|
+
e.preventDefault(), V.current = 0, H.current = -1;
|
|
205
|
+
let t = O.current;
|
|
206
|
+
t.length > 0 && A(t.slice(0, -1)), X();
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case "Tab": break;
|
|
210
|
+
case "Enter": {
|
|
211
|
+
e.preventDefault(), Z();
|
|
212
|
+
let n = t.form;
|
|
213
|
+
n ? n.requestSubmit() : t.blur();
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
default: if (/^\d$/.test(e.key)) {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
let t = parseInt(e.key, 10);
|
|
219
|
+
if (V.current === 0) {
|
|
220
|
+
H.current = t;
|
|
221
|
+
let e = String(t).padStart(2, "0");
|
|
222
|
+
A(e), V.current = 1, z.current?.dispatchEvent(new Event("input", { bubbles: !0 })), t >= 3 && (H.current = -1, V.current = 0, X(), F.current?.focus());
|
|
223
|
+
} else {
|
|
224
|
+
let e = H.current * 10 + t, n = e <= 23 ? String(e).padStart(2, "0") : String(t).padStart(2, "0");
|
|
225
|
+
A(n), H.current = -1, V.current = 0, X(), F.current?.focus();
|
|
226
|
+
}
|
|
227
|
+
} else e.preventDefault();
|
|
228
|
+
}
|
|
229
|
+
}, [
|
|
230
|
+
D,
|
|
231
|
+
J,
|
|
232
|
+
A,
|
|
233
|
+
X,
|
|
234
|
+
Z
|
|
235
|
+
]), Ze = l(() => {
|
|
236
|
+
if (G(!0), O.current !== "") {
|
|
237
|
+
let e = String(parseInt(O.current, 10)).padStart(2, "0");
|
|
238
|
+
A(e);
|
|
239
|
+
}
|
|
240
|
+
V.current = 0, H.current = -1, Y();
|
|
241
|
+
}, [A, Y]), Qe = l((e) => {
|
|
242
|
+
P.current?.setCustomValidity("");
|
|
243
|
+
let t = e.currentTarget, n = O.current;
|
|
244
|
+
switch (e.key) {
|
|
245
|
+
case "ArrowUp": {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
let t = k.current === "" ? 0 : parseInt(k.current, 10), r = String((t + K) % 60).padStart(2, "0");
|
|
248
|
+
if (j(r), n !== "") {
|
|
249
|
+
let e = `${n}:${r}`;
|
|
250
|
+
e === D ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J(e);
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "ArrowDown": {
|
|
255
|
+
e.preventDefault();
|
|
256
|
+
let t = k.current === "" ? 0 : parseInt(k.current, 10), r = String((t - K + 60) % 60).padStart(2, "0");
|
|
257
|
+
if (j(r), n !== "") {
|
|
258
|
+
let e = `${n}:${r}`;
|
|
259
|
+
e === D ? z.current?.dispatchEvent(new Event("input", { bubbles: !0 })) : J(e);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case "ArrowLeft":
|
|
264
|
+
e.preventDefault(), P.current?.focus();
|
|
265
|
+
break;
|
|
266
|
+
case "Backspace":
|
|
267
|
+
case "Delete": {
|
|
268
|
+
e.preventDefault(), U.current = 0, W.current = -1;
|
|
269
|
+
let t = k.current;
|
|
270
|
+
t.length > 0 && j(t.slice(0, -1)), X();
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case "Tab": break;
|
|
274
|
+
case "Enter": {
|
|
275
|
+
e.preventDefault(), Z();
|
|
276
|
+
let n = t.form;
|
|
277
|
+
n ? n.requestSubmit() : t.blur();
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
default: if (/^\d$/.test(e.key)) {
|
|
281
|
+
e.preventDefault();
|
|
282
|
+
let t = parseInt(e.key, 10);
|
|
283
|
+
if (U.current === 0) {
|
|
284
|
+
W.current = t;
|
|
285
|
+
let e = String(t).padStart(2, "0");
|
|
286
|
+
j(e), U.current = 1, z.current?.dispatchEvent(new Event("input", { bubbles: !0 })), t >= 6 && (W.current = -1, U.current = 0, X());
|
|
287
|
+
} else {
|
|
288
|
+
let e = W.current * 10 + t, n = e <= 59 ? String(e).padStart(2, "0") : String(t).padStart(2, "0");
|
|
289
|
+
j(n), W.current = -1, U.current = 0, X();
|
|
290
|
+
}
|
|
291
|
+
} else e.preventDefault();
|
|
292
|
+
}
|
|
293
|
+
}, [
|
|
294
|
+
K,
|
|
295
|
+
D,
|
|
296
|
+
J,
|
|
297
|
+
j,
|
|
298
|
+
X,
|
|
299
|
+
Z
|
|
300
|
+
]), $e = l(() => {
|
|
301
|
+
if (G(!0), k.current !== "") {
|
|
302
|
+
let e = String(parseInt(k.current, 10)).padStart(2, "0");
|
|
303
|
+
j(e);
|
|
304
|
+
}
|
|
305
|
+
U.current = 0, W.current = -1, Y();
|
|
306
|
+
}, [j, Y]), et = l((e) => {
|
|
307
|
+
let t = document.activeElement, n = t.closest(".pkt-timepicker-popup__col");
|
|
308
|
+
if (!n) return;
|
|
309
|
+
let r = Array.from(n.querySelectorAll(".pkt-timepicker-popup__option")), i = r.indexOf(t), a = (e) => {
|
|
310
|
+
if (!e) return;
|
|
311
|
+
let n = parseInt(e.dataset.value ?? "0", 10), r = String(n).padStart(2, "0");
|
|
312
|
+
t.dataset.type === "hour" ? A(r) : j(r), e.focus();
|
|
313
|
+
};
|
|
314
|
+
switch (e.key) {
|
|
315
|
+
case "ArrowDown":
|
|
316
|
+
e.preventDefault(), a(r[Math.min(i + 1, r.length - 1)]);
|
|
317
|
+
break;
|
|
318
|
+
case "ArrowUp":
|
|
319
|
+
e.preventDefault(), a(r[Math.max(i - 1, 0)]);
|
|
320
|
+
break;
|
|
321
|
+
case "Home":
|
|
322
|
+
e.preventDefault(), a(r[0]);
|
|
323
|
+
break;
|
|
324
|
+
case "End":
|
|
325
|
+
e.preventDefault(), a(r[r.length - 1]);
|
|
326
|
+
break;
|
|
327
|
+
case "ArrowRight":
|
|
328
|
+
if (e.preventDefault(), t.dataset.type === "hour") {
|
|
329
|
+
let e = parseInt(t.dataset.value ?? "0", 10);
|
|
330
|
+
A(String(e).padStart(2, "0")), requestAnimationFrame(() => {
|
|
331
|
+
L.current?.querySelectorAll(".pkt-timepicker-popup__col").forEach((e) => {
|
|
332
|
+
e.querySelector(".pkt-timepicker-popup__option--selected")?.scrollIntoView({ block: "center" });
|
|
333
|
+
}), $("minute");
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
case "ArrowLeft":
|
|
338
|
+
if (e.preventDefault(), t.dataset.type === "minute") {
|
|
339
|
+
let e = parseInt(t.dataset.value ?? "0", 10);
|
|
340
|
+
j(String(e).padStart(2, "0")), requestAnimationFrame(() => {
|
|
341
|
+
L.current?.querySelectorAll(".pkt-timepicker-popup__col").forEach((e) => {
|
|
342
|
+
e.querySelector(".pkt-timepicker-popup__option--selected")?.scrollIntoView({ block: "center" });
|
|
343
|
+
}), $("hour");
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
break;
|
|
347
|
+
case "Enter":
|
|
348
|
+
case " ":
|
|
349
|
+
e.preventDefault(), t.click();
|
|
350
|
+
break;
|
|
351
|
+
case "Escape": e.preventDefault(), Q(), I.current?.focus();
|
|
352
|
+
}
|
|
353
|
+
}, [
|
|
354
|
+
Q,
|
|
355
|
+
$,
|
|
356
|
+
A,
|
|
357
|
+
j
|
|
358
|
+
]), tt = l((e) => {
|
|
359
|
+
let t = L.current;
|
|
360
|
+
if (!t) return;
|
|
361
|
+
let n = e.relatedTarget;
|
|
362
|
+
(!n || !t.contains(n)) && Q();
|
|
363
|
+
}, [Q]), nt = l((e) => {
|
|
364
|
+
let t = R.current;
|
|
365
|
+
if (!t) return;
|
|
366
|
+
let n = e.relatedTarget;
|
|
367
|
+
n && t.contains(n) || De?.(e);
|
|
368
|
+
}, [De]), rt = l((e) => {
|
|
369
|
+
let t = R.current;
|
|
370
|
+
if (!t) return;
|
|
371
|
+
let n = e.relatedTarget;
|
|
372
|
+
n && t.contains(n) || Oe?.(e);
|
|
373
|
+
}, [Oe]), it = l(() => {
|
|
374
|
+
x || (M ? Q() : N(!0));
|
|
375
|
+
}, [
|
|
376
|
+
x,
|
|
377
|
+
M,
|
|
378
|
+
Q
|
|
379
|
+
]);
|
|
380
|
+
return d(s, () => ({
|
|
381
|
+
get value() {
|
|
382
|
+
return z.current?.value ?? "";
|
|
383
|
+
},
|
|
384
|
+
set value(e) {
|
|
385
|
+
let t = e ?? "";
|
|
386
|
+
T || E(t);
|
|
387
|
+
let [n, r] = h(t);
|
|
388
|
+
A(n), j(r), z.current && (z.current.value = t);
|
|
389
|
+
},
|
|
390
|
+
focus() {
|
|
391
|
+
P.current?.focus();
|
|
392
|
+
},
|
|
393
|
+
blur() {
|
|
394
|
+
P.current?.blur();
|
|
395
|
+
}
|
|
396
|
+
}), [
|
|
397
|
+
T,
|
|
398
|
+
A,
|
|
399
|
+
j
|
|
400
|
+
]), u(() => {
|
|
401
|
+
if (!B) return;
|
|
402
|
+
let e, t = () => {
|
|
403
|
+
window.clearTimeout(e), e = window.setTimeout(() => {
|
|
404
|
+
let e = Me.current, [t, n] = h(e);
|
|
405
|
+
A(t), j(n), T || E(e), z.current && (z.current.value = e), N(!1), G(!1);
|
|
406
|
+
}, 0);
|
|
407
|
+
};
|
|
408
|
+
return B.addEventListener("reset", t), () => {
|
|
409
|
+
B.removeEventListener("reset", t), window.clearTimeout(e);
|
|
410
|
+
};
|
|
411
|
+
}, [
|
|
412
|
+
T,
|
|
413
|
+
A,
|
|
414
|
+
j,
|
|
415
|
+
B
|
|
416
|
+
]), {
|
|
417
|
+
id: c,
|
|
418
|
+
containerRef: R,
|
|
419
|
+
outerClasses: [
|
|
420
|
+
"pkt-timepicker",
|
|
421
|
+
`pkt-timepicker--${Ee}`,
|
|
422
|
+
ce ? "pkt-timepicker--fullwidth" : "",
|
|
423
|
+
se ? "pkt-timepicker--stepper" : "",
|
|
424
|
+
Te ?? ""
|
|
425
|
+
].filter(Boolean).join(" "),
|
|
426
|
+
inputSize: Ee,
|
|
427
|
+
strings: ke,
|
|
428
|
+
stringsOverride: Ae,
|
|
429
|
+
label: ae,
|
|
430
|
+
disabled: x,
|
|
431
|
+
required: S,
|
|
432
|
+
helptext: de,
|
|
433
|
+
helptextDropdown: fe,
|
|
434
|
+
helptextDropdownButton: pe,
|
|
435
|
+
hasError: me,
|
|
436
|
+
isInvalid: qe,
|
|
437
|
+
errorMessage: he,
|
|
438
|
+
optionalTag: ge,
|
|
439
|
+
optionalText: _e,
|
|
440
|
+
requiredTag: ve,
|
|
441
|
+
requiredText: ye,
|
|
442
|
+
tagText: be,
|
|
443
|
+
inline: xe,
|
|
444
|
+
useWrapper: Se,
|
|
445
|
+
ariaDescribedby: Ce,
|
|
446
|
+
hidePicker: oe,
|
|
447
|
+
stepArrows: se,
|
|
448
|
+
min: v,
|
|
449
|
+
max: y,
|
|
450
|
+
step: b,
|
|
451
|
+
hours: Pe,
|
|
452
|
+
minutes: Ie,
|
|
453
|
+
hoursId: Ue,
|
|
454
|
+
minutesId: We,
|
|
455
|
+
popupId: Ge,
|
|
456
|
+
hiddenInputId: Ke,
|
|
457
|
+
name: le ?? c,
|
|
458
|
+
form: ue,
|
|
459
|
+
isOpen: M,
|
|
460
|
+
hourOptions: Ve,
|
|
461
|
+
minuteOptions: He,
|
|
462
|
+
hoursInputRef: P,
|
|
463
|
+
minutesInputRef: F,
|
|
464
|
+
buttonRef: I,
|
|
465
|
+
popupRef: L,
|
|
466
|
+
changeInputRef: z,
|
|
467
|
+
handleHoursKeydown: Xe,
|
|
468
|
+
handleHoursBlur: Ze,
|
|
469
|
+
handleMinutesKeydown: Qe,
|
|
470
|
+
handleMinutesBlur: $e,
|
|
471
|
+
handlePopupKeydown: et,
|
|
472
|
+
handlePopupFocusOut: tt,
|
|
473
|
+
handleFocusIn: nt,
|
|
474
|
+
handleFocusOut: rt,
|
|
475
|
+
handleOptionClick: Je,
|
|
476
|
+
handleClockButtonClick: it,
|
|
477
|
+
closePopup: Q,
|
|
478
|
+
stepTimeDelta: Ye,
|
|
479
|
+
effectiveValue: D
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
export { ae as useTimepickerState };
|