@fremtind/jokul 5.2.3 → 6.0.0-next.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/README.md +1 -1
- package/build/build-stats.html +37 -36
- package/build/cjs/components/autosuggest/BaseAutosuggest.cjs +1 -1
- package/build/cjs/components/autosuggest/BaseAutosuggest.cjs.map +1 -1
- package/build/cjs/components/date-input/DateInput.cjs +2 -0
- package/build/cjs/components/date-input/DateInput.cjs.map +1 -0
- package/build/cjs/components/date-input/DateInput.d.cts +7 -0
- package/build/cjs/components/date-input/calendar/Calendar.cjs +2 -0
- package/build/cjs/components/date-input/calendar/Calendar.cjs.map +1 -0
- package/build/cjs/components/date-input/calendar/Calendar.d.cts +6 -0
- package/build/cjs/components/date-input/calendar/CalendarDay.cjs +2 -0
- package/build/cjs/components/date-input/calendar/CalendarDay.cjs.map +1 -0
- package/build/cjs/components/date-input/calendar/CalendarDay.d.cts +16 -0
- package/build/cjs/components/date-input/calendar/CalendarWeek.cjs +2 -0
- package/build/cjs/components/date-input/calendar/CalendarWeek.cjs.map +1 -0
- package/build/cjs/components/date-input/calendar/CalendarWeek.d.cts +8 -0
- package/build/cjs/components/date-input/calendar/types.d.cts +6 -0
- package/build/cjs/components/date-input/calendar/utils.cjs +2 -0
- package/build/cjs/components/date-input/calendar/utils.cjs.map +1 -0
- package/build/cjs/components/date-input/calendar/utils.d.cts +19 -0
- package/build/cjs/components/date-input/index.cjs +2 -0
- package/build/cjs/components/date-input/index.d.cts +3 -0
- package/build/cjs/components/date-input/types.d.cts +35 -0
- package/build/cjs/components/date-input/utils.cjs +2 -0
- package/build/cjs/components/date-input/utils.cjs.map +1 -0
- package/build/cjs/components/date-input/utils.d.cts +34 -0
- package/build/cjs/components/file/File.cjs +1 -1
- package/build/cjs/components/file/File.cjs.map +1 -1
- package/build/cjs/components/file/types.d.cts +10 -1
- package/build/cjs/components/search/Search.cjs +1 -1
- package/build/cjs/components/search/Search.cjs.map +1 -1
- package/build/cjs/components/select/Option.cjs +2 -0
- package/build/cjs/components/select/Option.cjs.map +1 -0
- package/build/cjs/components/select/Option.d.cts +12 -0
- package/build/cjs/components/select/Select.cjs +1 -1
- package/build/cjs/components/select/Select.cjs.map +1 -1
- package/build/cjs/components/select/Select.d.cts +18 -3
- package/build/cjs/components/select/index.cjs +1 -1
- package/build/cjs/components/select/index.d.cts +1 -5
- package/build/cjs/components/select/utils.cjs +2 -0
- package/build/cjs/components/select/utils.cjs.map +1 -0
- package/build/cjs/components/select/utils.d.cts +5 -0
- package/build/cjs/components/table/TablePagination.cjs +1 -1
- package/build/cjs/components/table/TablePagination.cjs.map +1 -1
- package/build/cjs/components/tabs/Tabs.cjs.map +1 -1
- package/build/cjs/hooks/index.cjs +1 -1
- package/build/cjs/hooks/index.d.cts +0 -1
- package/build/cjs/hooks/useListNavigation/useListNavigation.cjs +1 -1
- package/build/cjs/hooks/useListNavigation/useListNavigation.cjs.map +1 -1
- package/build/cjs/hooks/useListNavigation/useListNavigation.d.cts +4 -2
- package/build/cjs/utilities/formatters/index.cjs +1 -1
- package/build/cjs/utilities/formatters/index.d.cts +1 -1
- package/build/cjs/utilities/formatters/util/registerWithMask.cjs +1 -1
- package/build/cjs/utilities/formatters/util/registerWithMask.cjs.map +1 -1
- package/build/cjs/utilities/formatters/util/registerWithMask.d.cts +0 -8
- package/build/cjs/utilities/index.cjs +1 -1
- package/build/cjs/utilities/validators/index.cjs +1 -1
- package/build/cjs/utilities/validators/index.d.cts +0 -1
- package/build/cjs/utilities/valuePair.cjs.map +1 -1
- package/build/cjs/utilities/valuePair.d.cts +2 -0
- package/build/es/components/autosuggest/BaseAutosuggest.js +1 -1
- package/build/es/components/autosuggest/BaseAutosuggest.js.map +1 -1
- package/build/es/components/date-input/DateInput.d.ts +7 -0
- package/build/es/components/date-input/DateInput.js +2 -0
- package/build/es/components/date-input/DateInput.js.map +1 -0
- package/build/es/components/date-input/calendar/Calendar.d.ts +6 -0
- package/build/es/components/date-input/calendar/Calendar.js +2 -0
- package/build/es/components/date-input/calendar/Calendar.js.map +1 -0
- package/build/es/components/date-input/calendar/CalendarDay.d.ts +16 -0
- package/build/es/components/date-input/calendar/CalendarDay.js +2 -0
- package/build/es/components/date-input/calendar/CalendarDay.js.map +1 -0
- package/build/es/components/date-input/calendar/CalendarWeek.d.ts +8 -0
- package/build/es/components/date-input/calendar/CalendarWeek.js +2 -0
- package/build/es/components/date-input/calendar/CalendarWeek.js.map +1 -0
- package/build/es/components/date-input/calendar/types.d.ts +6 -0
- package/build/es/components/date-input/calendar/utils.d.ts +19 -0
- package/build/es/components/date-input/calendar/utils.js +2 -0
- package/build/es/components/date-input/calendar/utils.js.map +1 -0
- package/build/es/components/date-input/index.d.ts +3 -0
- package/build/es/components/date-input/index.js +2 -0
- package/build/es/components/date-input/types.d.ts +35 -0
- package/build/es/components/date-input/utils.d.ts +34 -0
- package/build/es/components/date-input/utils.js +2 -0
- package/build/es/components/date-input/utils.js.map +1 -0
- package/build/es/components/file/File.js +1 -1
- package/build/es/components/file/File.js.map +1 -1
- package/build/es/components/file/types.d.ts +10 -1
- package/build/es/components/search/Search.js +1 -1
- package/build/es/components/search/Search.js.map +1 -1
- package/build/es/components/select/Option.d.ts +12 -0
- package/build/es/components/select/Option.js +2 -0
- package/build/es/components/select/Option.js.map +1 -0
- package/build/es/components/select/Select.d.ts +18 -3
- package/build/es/components/select/Select.js +1 -1
- package/build/es/components/select/Select.js.map +1 -1
- package/build/es/components/select/index.d.ts +1 -5
- package/build/es/components/select/index.js +1 -1
- package/build/es/components/select/utils.d.ts +5 -0
- package/build/es/components/select/utils.js +2 -0
- package/build/es/components/select/utils.js.map +1 -0
- package/build/es/components/table/TablePagination.js +1 -1
- package/build/es/components/table/TablePagination.js.map +1 -1
- package/build/es/components/tabs/Tabs.js.map +1 -1
- package/build/es/hooks/index.d.ts +0 -1
- package/build/es/hooks/index.js +1 -1
- package/build/es/hooks/useListNavigation/useListNavigation.d.ts +4 -2
- package/build/es/hooks/useListNavigation/useListNavigation.js +1 -1
- package/build/es/hooks/useListNavigation/useListNavigation.js.map +1 -1
- package/build/es/utilities/formatters/index.d.ts +1 -1
- package/build/es/utilities/formatters/index.js +1 -1
- package/build/es/utilities/formatters/util/registerWithMask.d.ts +0 -8
- package/build/es/utilities/formatters/util/registerWithMask.js +1 -1
- package/build/es/utilities/formatters/util/registerWithMask.js.map +1 -1
- package/build/es/utilities/index.js +1 -1
- package/build/es/utilities/validators/index.d.ts +0 -1
- package/build/es/utilities/validators/index.js +1 -1
- package/build/es/utilities/valuePair.d.ts +2 -0
- package/build/es/utilities/valuePair.js.map +1 -1
- package/codemods/CODEMODS.md +55 -0
- package/codemods/__tests__/import-paths.test.mjs +155 -0
- package/codemods/import-paths.mjs +10 -2
- package/codemods/transforms/date-input.mjs +225 -0
- package/codemods/transforms/import-specifiers.mjs +26 -0
- package/codemods/transforms/register-with-mask.mjs +267 -0
- package/package.json +14 -13
- package/src/fonts/Jokul-Icons.woff2 +0 -0
- package/src/fonts/brands/fremtind/Jokul-Icons.woff2 +0 -0
- package/styles/base.css +8 -1
- package/styles/base.min.css +1 -1
- package/styles/components/autosuggest/autosuggest.min.css +1 -1
- package/styles/components/beta/description-list/description-list.min.css +1 -1
- package/styles/components/beta/nav-link/navlink.min.css +1 -1
- package/styles/components/breadcrumb/breadcrumb.min.css +1 -1
- package/styles/components/button/button.min.css +1 -1
- package/styles/components/card/card.min.css +1 -1
- package/styles/components/checkbox/checkbox.min.css +1 -1
- package/styles/components/checkbox-panel/checkbox-panel.min.css +1 -1
- package/styles/components/checkbox-panel/development/styles.min.css +1 -1
- package/styles/components/chip/chip.min.css +1 -1
- package/styles/components/combobox/combobox.min.css +1 -1
- package/styles/components/cookie-consent/cookie-consent.min.css +1 -1
- package/styles/components/countdown/countdown.css +2 -2
- package/styles/components/countdown/countdown.min.css +1 -1
- package/styles/components/date-input/_index.scss +8 -0
- package/styles/components/date-input/calendar/_index.scss +8 -0
- package/styles/components/date-input/calendar/calendar.css +60 -0
- package/styles/components/date-input/calendar/calendar.min.css +1 -0
- package/styles/components/date-input/calendar/calendar.scss +79 -0
- package/styles/components/date-input/date-input.css +187 -0
- package/styles/components/date-input/date-input.min.css +1 -0
- package/styles/components/date-input/date-input.scss +67 -0
- package/styles/components/description-list/description-list.min.css +1 -1
- package/styles/components/expander/accordion.min.css +1 -1
- package/styles/components/expander/expandable.min.css +1 -1
- package/styles/components/feedback/feedback.css +2 -2
- package/styles/components/feedback/feedback.min.css +1 -1
- package/styles/components/file/file.css +50 -61
- package/styles/components/file/file.min.css +1 -1
- package/styles/components/file/file.scss +66 -79
- package/styles/components/file-input/file-input.css +59 -70
- package/styles/components/file-input/file-input.min.css +1 -1
- package/styles/components/flex/flex.min.css +1 -1
- package/styles/components/help/help.min.css +1 -1
- package/styles/components/icon/icon.css +1 -1
- package/styles/components/icon/icon.min.css +1 -1
- package/styles/components/icon/icon.scss +1 -0
- package/styles/components/icon-button/icon-button.min.css +1 -1
- package/styles/components/image/development/style.min.css +1 -1
- package/styles/components/image/image.min.css +1 -1
- package/styles/components/input-group/input-group.css +2 -2
- package/styles/components/input-group/input-group.min.css +1 -1
- package/styles/components/input-panel/input-panel.min.css +1 -1
- package/styles/components/link/link.min.css +1 -1
- package/styles/components/link-list/link-list.min.css +1 -1
- package/styles/components/list/list.min.css +1 -1
- package/styles/components/loader/loader.css +6 -6
- package/styles/components/loader/loader.min.css +1 -1
- package/styles/components/loader/skeleton-loader.css +3 -3
- package/styles/components/loader/skeleton-loader.min.css +1 -1
- package/styles/components/logo/development/styles.min.css +1 -1
- package/styles/components/logo/logo.min.css +1 -1
- package/styles/components/menu/menu.min.css +1 -1
- package/styles/components/message/message.css +2 -2
- package/styles/components/message/message.min.css +1 -1
- package/styles/components/modal/modal.min.css +1 -1
- package/styles/components/nav-link/nav-link.min.css +1 -1
- package/styles/components/number-input/number-input.min.css +1 -1
- package/styles/components/pagination/development/styles.min.css +1 -1
- package/styles/components/pagination/pagination.min.css +1 -1
- package/styles/components/popover/popover.min.css +1 -1
- package/styles/components/progress-bar/progress-bar.css +1 -1
- package/styles/components/progress-bar/progress-bar.min.css +1 -1
- package/styles/components/radio-button/radio-button.min.css +1 -1
- package/styles/components/radio-panel/development/styles.min.css +1 -1
- package/styles/components/radio-panel/radio-panel.min.css +1 -1
- package/styles/components/search/search-with-submit-button.min.css +1 -1
- package/styles/components/search/search.min.css +1 -1
- package/styles/components/segmented-control/segmented-control.css +3 -3
- package/styles/components/segmented-control/segmented-control.min.css +1 -1
- package/styles/components/select/_index.scss +5 -0
- package/styles/components/select/option.css +73 -0
- package/styles/components/select/option.min.css +1 -0
- package/styles/components/select/option.scss +74 -0
- package/styles/components/select/select.css +84 -264
- package/styles/components/select/select.min.css +1 -1
- package/styles/components/select/select.scss +79 -328
- package/styles/components/summary-table/summary-table.min.css +1 -1
- package/styles/components/system-message/system-message.css +2 -2
- package/styles/components/system-message/system-message.min.css +1 -1
- package/styles/components/table/table.min.css +3 -1
- package/styles/components/table-of-contents/table-of-contents.min.css +1 -1
- package/styles/components/tabs/tabs.min.css +1 -1
- package/styles/components/tag/tag.min.css +1 -1
- package/styles/components/text-area/text-area.min.css +1 -1
- package/styles/components/text-input/text-input.min.css +1 -1
- package/styles/components/toast/toast.css +4 -4
- package/styles/components/toast/toast.min.css +1 -1
- package/styles/components/toggle-switch/toggle-switch.min.css +1 -1
- package/styles/components/tooltip/tooltip.min.css +1 -1
- package/styles/components/typography/title.min.css +1 -1
- package/styles/components.css +4391 -4612
- package/styles/components.min.css +3 -1
- package/styles/components.scss +2 -3
- package/styles/jkl/_shadows.scss +0 -12
- package/styles/theme/_fonts.scss +1 -1
- package/styles/utility/_index.scss +2 -1
- package/styles/utility/_lists.scss +7 -0
- package/build/_commonjsHelpers-C37NGDzP.cjs +0 -2
- package/build/_commonjsHelpers-C37NGDzP.cjs.map +0 -1
- package/build/_commonjsHelpers-CXUWDbkB.js +0 -2
- package/build/_commonjsHelpers-CXUWDbkB.js.map +0 -1
- package/build/cjs/components/beta/select/Select.cjs +0 -2
- package/build/cjs/components/beta/select/Select.cjs.map +0 -1
- package/build/cjs/components/beta/select/Select.d.cts +0 -3
- package/build/cjs/components/beta/select/index.cjs +0 -2
- package/build/cjs/components/beta/select/index.d.cts +0 -2
- package/build/cjs/components/beta/select/types.d.cts +0 -10
- package/build/cjs/components/datepicker/DatePicker.cjs +0 -2
- package/build/cjs/components/datepicker/DatePicker.cjs.map +0 -1
- package/build/cjs/components/datepicker/DatePicker.d.cts +0 -3
- package/build/cjs/components/datepicker/index.cjs +0 -2
- package/build/cjs/components/datepicker/index.cjs.map +0 -1
- package/build/cjs/components/datepicker/index.d.cts +0 -4
- package/build/cjs/components/datepicker/internal/Calendar.cjs +0 -2
- package/build/cjs/components/datepicker/internal/Calendar.cjs.map +0 -1
- package/build/cjs/components/datepicker/internal/Calendar.d.cts +0 -15
- package/build/cjs/components/datepicker/internal/calendarReducer.cjs +0 -2
- package/build/cjs/components/datepicker/internal/calendarReducer.cjs.map +0 -1
- package/build/cjs/components/datepicker/internal/calendarReducer.d.cts +0 -18
- package/build/cjs/components/datepicker/internal/useCalendar.cjs +0 -2
- package/build/cjs/components/datepicker/internal/useCalendar.cjs.map +0 -1
- package/build/cjs/components/datepicker/internal/useCalendar.d.cts +0 -59
- package/build/cjs/components/datepicker/internal/utils.cjs +0 -2
- package/build/cjs/components/datepicker/internal/utils.cjs.map +0 -1
- package/build/cjs/components/datepicker/internal/utils.d.cts +0 -167
- package/build/cjs/components/datepicker/types.d.cts +0 -280
- package/build/cjs/components/datepicker/utils.cjs +0 -2
- package/build/cjs/components/datepicker/utils.cjs.map +0 -1
- package/build/cjs/components/datepicker/utils.d.cts +0 -22
- package/build/cjs/components/datepicker/validation.cjs +0 -2
- package/build/cjs/components/datepicker/validation.cjs.map +0 -1
- package/build/cjs/components/datepicker/validation.d.cts +0 -4
- package/build/cjs/components/select/NativeSelect.cjs +0 -2
- package/build/cjs/components/select/NativeSelect.cjs.map +0 -1
- package/build/cjs/components/select/NativeSelect.d.cts +0 -3
- package/build/cjs/components/select/select-utils.cjs +0 -2
- package/build/cjs/components/select/select-utils.cjs.map +0 -1
- package/build/cjs/components/select/select-utils.d.cts +0 -2
- package/build/cjs/components/select/types.cjs +0 -2
- package/build/cjs/components/select/types.cjs.map +0 -1
- package/build/cjs/components/select/types.d.cts +0 -66
- package/build/cjs/hooks/useAnimatedDetails/index.cjs +0 -2
- package/build/cjs/hooks/useAnimatedDetails/index.cjs.map +0 -1
- package/build/cjs/hooks/useAnimatedDetails/index.d.cts +0 -1
- package/build/cjs/hooks/useAnimatedDetails/useAnimatedDetails.cjs +0 -2
- package/build/cjs/hooks/useAnimatedDetails/useAnimatedDetails.cjs.map +0 -1
- package/build/cjs/hooks/useAnimatedDetails/useAnimatedDetails.d.cts +0 -21
- package/build/cjs/utilities/validators/isValidDogId/isValidDogId.cjs +0 -2
- package/build/cjs/utilities/validators/isValidDogId/isValidDogId.cjs.map +0 -1
- package/build/cjs/utilities/validators/isValidDogId/isValidDogId.d.cts +0 -7
- package/build/es/components/beta/select/Select.d.ts +0 -3
- package/build/es/components/beta/select/Select.js +0 -2
- package/build/es/components/beta/select/Select.js.map +0 -1
- package/build/es/components/beta/select/index.d.ts +0 -2
- package/build/es/components/beta/select/index.js +0 -2
- package/build/es/components/beta/select/types.d.ts +0 -10
- package/build/es/components/datepicker/DatePicker.d.ts +0 -3
- package/build/es/components/datepicker/DatePicker.js +0 -2
- package/build/es/components/datepicker/DatePicker.js.map +0 -1
- package/build/es/components/datepicker/index.d.ts +0 -4
- package/build/es/components/datepicker/index.js +0 -2
- package/build/es/components/datepicker/index.js.map +0 -1
- package/build/es/components/datepicker/internal/Calendar.d.ts +0 -15
- package/build/es/components/datepicker/internal/Calendar.js +0 -2
- package/build/es/components/datepicker/internal/Calendar.js.map +0 -1
- package/build/es/components/datepicker/internal/calendarReducer.d.ts +0 -18
- package/build/es/components/datepicker/internal/calendarReducer.js +0 -2
- package/build/es/components/datepicker/internal/calendarReducer.js.map +0 -1
- package/build/es/components/datepicker/internal/useCalendar.d.ts +0 -59
- package/build/es/components/datepicker/internal/useCalendar.js +0 -2
- package/build/es/components/datepicker/internal/useCalendar.js.map +0 -1
- package/build/es/components/datepicker/internal/utils.d.ts +0 -167
- package/build/es/components/datepicker/internal/utils.js +0 -2
- package/build/es/components/datepicker/internal/utils.js.map +0 -1
- package/build/es/components/datepicker/types.d.ts +0 -280
- package/build/es/components/datepicker/utils.d.ts +0 -22
- package/build/es/components/datepicker/utils.js +0 -2
- package/build/es/components/datepicker/utils.js.map +0 -1
- package/build/es/components/datepicker/validation.d.ts +0 -4
- package/build/es/components/datepicker/validation.js +0 -2
- package/build/es/components/datepicker/validation.js.map +0 -1
- package/build/es/components/select/NativeSelect.d.ts +0 -3
- package/build/es/components/select/NativeSelect.js +0 -2
- package/build/es/components/select/NativeSelect.js.map +0 -1
- package/build/es/components/select/select-utils.d.ts +0 -2
- package/build/es/components/select/select-utils.js +0 -2
- package/build/es/components/select/select-utils.js.map +0 -1
- package/build/es/components/select/types.d.ts +0 -66
- package/build/es/components/select/types.js +0 -2
- package/build/es/components/select/types.js.map +0 -1
- package/build/es/hooks/useAnimatedDetails/index.d.ts +0 -1
- package/build/es/hooks/useAnimatedDetails/index.js +0 -2
- package/build/es/hooks/useAnimatedDetails/index.js.map +0 -1
- package/build/es/hooks/useAnimatedDetails/useAnimatedDetails.d.ts +0 -21
- package/build/es/hooks/useAnimatedDetails/useAnimatedDetails.js +0 -2
- package/build/es/hooks/useAnimatedDetails/useAnimatedDetails.js.map +0 -1
- package/build/es/utilities/validators/isValidDogId/isValidDogId.d.ts +0 -7
- package/build/es/utilities/validators/isValidDogId/isValidDogId.js +0 -2
- package/build/es/utilities/validators/isValidDogId/isValidDogId.js.map +0 -1
- package/build/utils-C5AH4j8B.js +0 -2
- package/build/utils-C5AH4j8B.js.map +0 -1
- package/build/utils-CD_aHC6R.cjs +0 -2
- package/build/utils-CD_aHC6R.cjs.map +0 -1
- package/src/fonts/Fremtind-Material-Symbols.woff2 +0 -0
- package/src/fonts/brands/fremtind/Fremtind-Material-Symbols.woff2 +0 -0
- package/styles/components/beta/select/_index.scss +0 -3
- package/styles/components/beta/select/select.css +0 -101
- package/styles/components/beta/select/select.min.css +0 -1
- package/styles/components/beta/select/select.scss +0 -99
- package/styles/components/datepicker/_calendar-date-button.scss +0 -72
- package/styles/components/datepicker/_calendar-navigation-dropdown.scss +0 -55
- package/styles/components/datepicker/_calendar-navigation.scss +0 -14
- package/styles/components/datepicker/_calendar-table.scss +0 -29
- package/styles/components/datepicker/_calendar.scss +0 -28
- package/styles/components/datepicker/_index.scss +0 -6
- package/styles/components/datepicker/datepicker.css +0 -246
- package/styles/components/datepicker/datepicker.min.css +0 -1
- package/styles/components/datepicker/datepicker.scss +0 -49
- /package/build/cjs/components/{beta/select → date-input/calendar}/types.cjs +0 -0
- /package/build/cjs/components/{beta/select → date-input/calendar}/types.cjs.map +0 -0
- /package/build/cjs/components/{beta/select → date-input}/index.cjs.map +0 -0
- /package/build/cjs/components/{datepicker → date-input}/types.cjs +0 -0
- /package/build/cjs/components/{datepicker → date-input}/types.cjs.map +0 -0
- /package/build/es/components/{beta/select → date-input/calendar}/types.js +0 -0
- /package/build/es/components/{beta/select → date-input/calendar}/types.js.map +0 -0
- /package/build/es/components/{beta/select → date-input}/index.js.map +0 -0
- /package/build/es/components/{datepicker → date-input}/types.js +0 -0
- /package/build/es/components/{datepicker → date-input}/types.js.map +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAnimatedDetails.cjs","sources":["../../../../src/hooks/useAnimatedDetails/useAnimatedDetails.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\n/**\n * Lar deg animere et HTML details element med en summary trigger og noe innhold.\n * HTML strukturen din bør se ut som omtrent\n * <details ref={detailsRef}>\n * <summary ref={summaryRef} onClick={onSummaryClick}>Trigger for å åpne</summary>\n * <div ref={contentRef}>Ekspanderbart innhold</div>\n * </details>\n *\n * @param onOpenChange Callback med informasjon om når elementet åpner/lukker seg.\n * @param isExpanded Styr åpning/lukking utenfra.\n * @deprecated Bruk heller `useAnimatedHeightBetween` eller lignende på selve innholdet\n */\nexport const useAnimatedDetails = ({\n onOpenChange,\n isExpanded,\n}: {\n onOpenChange: (open: boolean, e: React.MouseEvent<HTMLElement>) => void;\n isExpanded: boolean;\n}): {\n detailsRef: React.RefObject<HTMLDetailsElement>;\n summaryRef: React.RefObject<HTMLButtonElement>;\n contentRef: React.RefObject<HTMLDivElement>;\n onSummaryClick: React.MouseEventHandler<HTMLElement>;\n} => {\n const detailsRef = useRef<HTMLDetailsElement>(null);\n const summaryRef = useRef<HTMLButtonElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const animation = useRef<Animation | null>(null);\n\n const [isClosing, setIsClosing] = useState(false);\n const [isExpanding, setIsExpanding] = useState(false);\n\n useEffect(() => {\n onAnimationFinish(isExpanded);\n }, [isExpanded]);\n\n const onAnimationFinish = (open: boolean) => {\n if (detailsRef.current && summaryRef.current) {\n detailsRef.current.open = open;\n animation.current = null;\n setIsClosing(false);\n setIsExpanding(false);\n detailsRef.current.style.overflow = \"\";\n detailsRef.current.style.height = \"\";\n }\n };\n\n const open = (e: React.MouseEvent<HTMLElement>) => {\n if (detailsRef.current && summaryRef.current) {\n detailsRef.current.style.height = `${detailsRef.current.offsetHeight}px`;\n detailsRef.current.open = true;\n requestAnimationFrame(() => {\n if (\n detailsRef.current &&\n summaryRef.current &&\n contentRef.current\n ) {\n setIsExpanding(true);\n onOpenChange(true, e);\n const startHeight = detailsRef.current.offsetHeight;\n const endHeight =\n summaryRef.current.offsetHeight +\n contentRef.current.offsetHeight;\n\n if (animation.current) {\n animation.current.cancel();\n }\n\n if (detailsRef.current.animate) {\n animation.current = detailsRef.current.animate(\n {\n height: [`${startHeight}px`, `${endHeight}px`],\n },\n {\n duration: 150,\n easing: \"ease\",\n },\n );\n animation.current.onfinish = () =>\n onAnimationFinish(true);\n animation.current.oncancel = () =>\n setIsExpanding(false);\n }\n }\n });\n }\n };\n\n const close = (e: React.MouseEvent<HTMLElement>) => {\n if (detailsRef.current && summaryRef.current) {\n setIsClosing(true);\n onOpenChange(false, e);\n const startHeight = detailsRef.current.offsetHeight;\n const endHeight = summaryRef.current.offsetHeight;\n if (animation.current) {\n animation.current.cancel();\n }\n\n if (detailsRef.current.animate) {\n animation.current = detailsRef.current.animate(\n {\n height: [`${startHeight}px`, `${endHeight}px`],\n },\n {\n duration: 150,\n easing: \"ease\",\n },\n );\n animation.current.onfinish = () => onAnimationFinish(false);\n animation.current.oncancel = () => setIsClosing(false);\n }\n }\n };\n\n const onSummaryClick = (e: React.MouseEvent<HTMLElement>) => {\n e.preventDefault();\n if (detailsRef.current && summaryRef.current) {\n detailsRef.current.style.overflow = \"hidden\";\n if (isClosing || !detailsRef.current.open) {\n open(e);\n } else if (isExpanding || detailsRef.current.open) {\n close(e);\n }\n }\n };\n\n return { detailsRef, summaryRef, contentRef, onSummaryClick };\n};\n"],"names":["onOpenChange","isExpanded","detailsRef","useRef","summaryRef","contentRef","animation","isClosing","setIsClosing","useState","isExpanding","setIsExpanding","useEffect","onAnimationFinish","open","current","style","overflow","height","onSummaryClick","e","preventDefault","offsetHeight","requestAnimationFrame","startHeight","endHeight","cancel","animate","duration","easing","onfinish","oncancel","close"],"mappings":"oIAckC,EAC9BA,aAAAA,EACAC,WAAAA,MAUA,MAAMC,EAAaC,EAAAA,OAA2B,MACxCC,EAAaD,EAAAA,OAA0B,MACvCE,EAAaF,EAAAA,OAAuB,MACpCG,EAAYH,EAAAA,OAAyB,OAEpCI,EAAWC,GAAgBC,EAAAA,UAAS,IACpCC,EAAaC,GAAkBF,EAAAA,UAAS,GAE/CG,EAAAA,UAAU,KACNC,EAAkBZ,IACnB,CAACA,IAEJ,MAAMY,EAAqBC,IACnBZ,EAAWa,SAAWX,EAAWW,UACjCb,EAAWa,QAAQD,KAAOA,EAC1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U,IACVC,OAAQ,SAGhBvB,EAAUS,QAAQe,SAAW,IAAMjB,GAAkB,GACrDP,EAAUS,QAAQgB,SAAW,IAAMvB,GAAa,GAExD,GAUQwB,CAAMZ"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lar deg animere et HTML details element med en summary trigger og noe innhold.
|
|
3
|
-
* HTML strukturen din bør se ut som omtrent
|
|
4
|
-
* <details ref={detailsRef}>
|
|
5
|
-
* <summary ref={summaryRef} onClick={onSummaryClick}>Trigger for å åpne</summary>
|
|
6
|
-
* <div ref={contentRef}>Ekspanderbart innhold</div>
|
|
7
|
-
* </details>
|
|
8
|
-
*
|
|
9
|
-
* @param onOpenChange Callback med informasjon om når elementet åpner/lukker seg.
|
|
10
|
-
* @param isExpanded Styr åpning/lukking utenfra.
|
|
11
|
-
* @deprecated Bruk heller `useAnimatedHeightBetween` eller lignende på selve innholdet
|
|
12
|
-
*/
|
|
13
|
-
export declare const useAnimatedDetails: ({ onOpenChange, isExpanded, }: {
|
|
14
|
-
onOpenChange: (open: boolean, e: React.MouseEvent<HTMLElement>) => void;
|
|
15
|
-
isExpanded: boolean;
|
|
16
|
-
}) => {
|
|
17
|
-
detailsRef: React.RefObject<HTMLDetailsElement>;
|
|
18
|
-
summaryRef: React.RefObject<HTMLButtonElement>;
|
|
19
|
-
contentRef: React.RefObject<HTMLDivElement>;
|
|
20
|
-
onSummaryClick: React.MouseEventHandler<HTMLElement>;
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isValidDogId.cjs","sources":["../../../../../src/utilities/validators/isValidDogId/isValidDogId.ts"],"sourcesContent":["export const DOGID_REGEX = /^5780[0-9]{11}$/;\n\n/**\n * Validerer at verdien er et gyldig norsk ID-nummer for hund.\n * @deprecated This only validates norwegian id-tags, that is probably more restrictive than you want\n * expect this function to change, use carefully\n */\nexport const isValidDogId = (value: string): boolean => DOGID_REGEX.test(value);\n"],"names":["DOGID_REGEX","value","test"],"mappings":"gFAAO,MAAMA,EAAc,6DAOEC,GAA2BD,EAAYE,KAAKD"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const DOGID_REGEX: RegExp;
|
|
2
|
-
/**
|
|
3
|
-
* Validerer at verdien er et gyldig norsk ID-nummer for hund.
|
|
4
|
-
* @deprecated This only validates norwegian id-tags, that is probably more restrictive than you want
|
|
5
|
-
* expect this function to change, use carefully
|
|
6
|
-
*/
|
|
7
|
-
export declare const isValidDogId: (value: string) => boolean;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as o,jsxs as n}from"react/jsx-runtime";import{c as i}from"../../../../clsx-BeLtu-UY.js";import{forwardRef as c}from"react";import"../../icon/Icon.js";import"../../icon/icons/animated/ArrowVerticalAnimated.js";import"../../icon/icons/animated/ArrowHorizontalAnimated.js";import"../../icon/icons/animated/PlusRemoveAnimated.js";import{ArrowDownIcon as s}from"../../icon/icons/ArrowDownIcon.js";import"../../icon/icons/ArrowLeftIcon.js";import"../../icon/icons/ArrowNorthEastIcon.js";import"../../icon/icons/ArrowRightIcon.js";import"../../icon/icons/ArrowUpIcon.js";import"../../icon/icons/CalendarIcon.js";import"../../icon/icons/CheckIcon.js";import"../../icon/icons/ChevronDownIcon.js";import"../../icon/icons/ChevronLeftIcon.js";import"../../icon/icons/ChevronRightIcon.js";import"../../icon/icons/ChevronUpIcon.js";import"../../icon/icons/CloseIcon.js";import"../../icon/icons/CopyIcon.js";import"../../icon/icons/DotsIcon.js";import"../../icon/icons/DragIcon.js";import"../../icon/icons/ErrorIcon.js";import"../../icon/icons/GreenCheckIcon.js";import"../../icon/icons/HamburgerIcon.js";import"../../icon/icons/InfoIcon.js";import"../../icon/icons/LinkIcon.js";import"../../icon/icons/MinusIcon.js";import"../../icon/icons/OpenInNewIcon.js";import"../../icon/icons/PenIcon.js";import"../../icon/icons/PlusIcon.js";import"../../icon/icons/QuestionIcon.js";import"../../icon/icons/RedCrossIcon.js";import"../../icon/icons/SearchIcon.js";import"../../icon/icons/SuccessIcon.js";import"../../icon/icons/ThumbDownIcon.js";import"../../icon/icons/ThumbUpIcon.js";import"../../icon/icons/TrashCanIcon.js";import"../../icon/icons/WarningIcon.js";import{InputGroup as r}from"../../input-group/InputGroup.js";const e=c((c,e)=>{const{label:t,className:p,errorLabel:a,helpLabel:m,labelProps:l,placeholder:j="Velg",supportLabelProps:I,tooltip:d,value:u,description:h,...b}=c;return o(r,{label:t,errorLabel:a,helpLabel:m,labelProps:l,supportLabelProps:I,tooltip:d,description:h,"data-testid":"jkl-select--beta",className:i("jkl-select--beta",p),render:i=>n("div",{className:"jkl-select--beta-wrapper",children:[n("select",{ref:e,defaultValue:u?void 0:"",value:u,...i,...b,children:[j&&o("option",{disabled:!0,selected:!0,value:"",children:j}),c.children]}),o(s,{})]})})});export{e as Select};
|
|
2
|
-
//# sourceMappingURL=Select.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../../../src/components/beta/select/Select.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef } from \"react\";\nimport { ArrowDownIcon } from \"../../icon/index.js\";\nimport { InputGroup } from \"../../input-group/InputGroup.jsx\";\nimport type { SelectProps } from \"./types.js\";\n\nexport const Select = forwardRef<HTMLSelectElement, SelectProps>(\n (props, ref) => {\n const {\n label,\n className,\n errorLabel,\n helpLabel,\n labelProps,\n placeholder = \"Velg\",\n supportLabelProps,\n tooltip,\n value,\n description,\n ...rest\n } = props;\n\n const inputGroupProps = {\n label,\n errorLabel,\n helpLabel,\n labelProps,\n supportLabelProps,\n tooltip,\n description,\n };\n\n return (\n <InputGroup\n {...inputGroupProps}\n data-testid=\"jkl-select--beta\"\n className={clsx(\"jkl-select--beta\", className)}\n render={(inputProps) => (\n <div className=\"jkl-select--beta-wrapper\">\n <select\n ref={ref}\n defaultValue={value ? undefined : \"\"}\n value={value}\n {...inputProps}\n {...rest}\n >\n {placeholder && (\n <option disabled selected value=\"\">\n {placeholder}\n </option>\n )}\n {props.children}\n </select>\n <ArrowDownIcon />\n </div>\n )}\n />\n );\n },\n);\n"],"names":["Select","forwardRef","props","ref","label","className","errorLabel","helpLabel","labelProps","placeholder","supportLabelProps","tooltip","value","description","rest","jsx","InputGroup","clsx","render","inputProps","jsxs","children","defaultValue","disabled","selected","ArrowDownIcon"],"mappings":"irDAMO,MAAMA,EAASC,EAClB,CAACC,EAAOC,KACJ,MACIC,MAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAC,YAAAA,EAAc,OACdC,kBAAAA,EACAC,QAAAA,EACAC,MAAAA,EACAC,YAAAA,KACGC,GACHZ,EAYJ,OACIa,EAACC,EAAA,CAVDZ,MAAAA,EACAE,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAE,kBAAAA,EACAC,QAAAA,EACAE,YAAAA,EAMI,cAAY,mBACZR,UAAWY,EAAK,mBAAoBZ,GACpCa,OAASC,GACLC,EAAC,MAAA,CAAIf,UAAU,2BACXgB,SAAA,CAAAD,EAAC,SAAA,CACGjB,IAAAA,EACAmB,aAAcV,OAAQ,EAAY,GAClCA,MAAAA,KACIO,KACAL,EAEHO,SAAA,CAAAZ,GACGM,EAAC,UAAOQ,UAAQ,EAACC,UAAQ,EAACZ,MAAM,GAC3BS,SAAAZ,IAGRP,EAAMmB,cAEVI,EAAA,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode, SelectHTMLAttributes } from 'react';
|
|
2
|
-
import { InputGroupProps } from '../../input-group/types.js';
|
|
3
|
-
export interface SelectProps extends Omit<InputGroupProps, "children" | "inline">, SelectHTMLAttributes<HTMLSelectElement> {
|
|
4
|
-
/**
|
|
5
|
-
* Setter inn et placeholderelement som vises når ingenting er valgt i nedtrekkslisten.
|
|
6
|
-
* @default "Velg"
|
|
7
|
-
*/
|
|
8
|
-
placeholder?: string;
|
|
9
|
-
children: ReactNode | ReactNode[];
|
|
10
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as r}from"../../../clsx-BeLtu-UY.js";import{d as a,g as o}from"../../../utils-C5AH4j8B.js";import{forwardRef as n,useState as l,useRef as s,useCallback as i}from"react";import{flushSync as u}from"react-dom";import{formatDateString as c}from"../../utilities/formatters/date/formatDate.js";import{IconButton as d}from"../icon-button/IconButton.js";import{CalendarIcon as p}from"../icon/icons/CalendarIcon.js";import{InputGroup as m}from"../input-group/InputGroup.js";import{Popover as f}from"../popover/Popover.js";import{BaseTextInput as v}from"../text-input/BaseTextInput.js";import{Calendar as D}from"./internal/Calendar.js";import{parseDateString as h,formatInput as b}from"./utils.js";import{isWithinLowerBound as g,isWithinUpperBound as k}from"./validation.js";const j=n((n,j)=>{const{"data-testautoid":y,id:L,className:w="",label:x="Velg dato",labelProps:C,defaultValue:I,defaultShow:O=!1,value:P,disableBeforeDate:T,disableAfterDate:B,yearsToShow:E,name:_,helpLabel:S,errorLabel:N,invalid:R,days:U,months:V,monthLabel:F,yearLabel:K,placeholder:W="dd.mm.åååå",width:A="11.25rem",onChange:G,onBlur:H,onFocus:M,onKeyDown:q,action:$,showCalendarLabel:z="Åpne kalender",hideCalendarLabel:J="Lukk kalender",supportLabelProps:Q,tooltip:X,textInputProps:Y,description:Z,...ee}=n;"production"!==process.env.NODE_ENV&&P&&I&&console.warn("DatePicker må enten være controlled eller uncontrolled. Hvis du bruker defaultValue og value sammen vil defaultValue bli ignorert.");const te=h(T),re=te?a(te).startOf("day").toDate():void 0,ae=h(B),oe=ae?a(ae).startOf("day").toDate():void 0,[ne,le]=l(o(P,I,re,oe)),[se,ie]=l(null),[ue,ce]=l(O),de=s(null),pe=s(null),me=s(null),fe=s(null),ve=s(!1),De=i(e=>{fe.current=e,j&&("function"==typeof j?j(e):j.current=e)},[j]),he=i(e=>{M&&pe.current&&(pe.current.contains(e.relatedTarget)||M(e,ne,{error:se,value:e.target.value}))},[M,ne,se]),be=i(e=>{H&&H(e,ne,{error:se,value:e.target.value})},[H,ne,se]),ge=i(e=>{"Escape"===e.key&&(ce(!1),e.preventDefault(),e.stopPropagation()),$?.onKeyDown&&$.onKeyDown(e)},[$]),ke=i(e=>{const t=e.currentTarget.value,r=((e,t)=>{const r=e.replace(/\D/g,""),a=c(r,{partial:!0}),o=e.replace(/\D+$/,""),n=8===r.length?c(r):e,l=h(n)?n:null,s=t&&e!==r&&o===a&&void 0===h(e)&&null===l;return l??(s?r:e)})(t,ve.current);r!==t&&((e,t)=>{const r=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set;r?r.call(e,t):e.value=t})(e.currentTarget,r);const a=t.replace(/\D/g,"");ve.current=t===a&&r===c(a)&&r!==t&&void 0!==h(r);const{date:o,error:n}=(({value:e,minDate:t,maxDate:r})=>{if(!e)return{date:null,error:null};const a=h(e);return a?t&&!g(a,t)?{date:a,error:"OUTSIDE_LOWER_BOUND"}:r&&!k(a,r)?{date:a,error:"OUTSIDE_UPPER_BOUND"}:{date:a,error:null}:{date:null,error:"WRONG_FORMAT"}})({value:r,minDate:re,maxDate:oe});o&&!n&&ce(!1),ie(n),le(o),G&&G(e,o,{error:n,value:r})},[G,re,oe]),je=i(e=>{u(()=>{ce(!ue)});const t=de.current,r=t&&t.querySelector('[aria-pressed="true"]');window.requestAnimationFrame(()=>r?.focus()),$?.onClick&&$.onClick(e)},[ue,$]),ye=i(({date:e})=>{if(ce(!1),le(e),fe.current){const t=fe.current;ve.current=!1,t.value=b(e);const r=document.createEvent("HTMLEvents");r.initEvent("input",!0,!1),t.dispatchEvent(r),t.focus(),G&&G(r,e,{error:null,value:t.value})}},[G]),Le=i(e=>{e.preventDefault(),ce(!1),me.current?.focus()},[]);return e(m,{id:L,className:r("jkl-datepicker",w),...ee,ref:pe,label:x,labelProps:C,helpLabel:S,errorLabel:N,supportLabelProps:Q,tooltip:X,description:Z,render:r=>e(v,{"data-focused":ue?"true":void 0,ref:De,"data-testid":"jkl-datepicker__input","data-testautoid":y,className:"jkl-datepicker__input",name:_,defaultValue:I,value:P,type:"text",placeholder:W,width:A,onFocus:he,onBlur:be,onChange:ke,actionButton:t(f,{positionReference:fe,open:ue,onOpenChange:()=>ce(!ue),offset:8,children:[e(f.Trigger,{...$,"data-testid":"jkl-datepicker__trigger",className:"jkl-text-input-action-button",title:ue?J:z,tabIndex:0,onClick:je,onKeyDown:ge,asChild:!0,children:e(d,{children:e(p,{})})}),e(f.Content,{initialFocus:-1,padding:24,children:e(D,{ref:de,date:ne,minDate:re,maxDate:oe,days:U,months:V,monthLabel:F,yearLabel:K,yearsToShow:E,onDateSelected:ye,onTabOutside:Le})})]}),...Y,...r,"aria-invalid":R||!!N})})});j.displayName="DatePicker";export{j as DatePicker};
|
|
2
|
-
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sources":["../../../../src/components/datepicker/DatePicker.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport dayjs from \"dayjs\";\nimport React, {\n type ChangeEvent,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n forwardRef,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { formatDateString } from \"../../utilities/formatters/date/formatDate.js\";\nimport { IconButton } from \"../icon-button/IconButton.js\";\nimport { CalendarIcon } from \"../icon/icons/CalendarIcon.js\";\nimport { InputGroup } from \"../input-group/InputGroup.js\";\nimport Popover from \"../popover/Popover.js\";\nimport { BaseTextInput } from \"../text-input/BaseTextInput.js\";\nimport { Calendar } from \"./internal/Calendar.js\";\nimport { type DateInfo, getInitialDate } from \"./internal/utils.js\";\nimport type { DatePickerProps, DateValidationError } from \"./types.js\";\nimport { formatInput, parseDateString } from \"./utils.js\";\nimport { isWithinLowerBound, isWithinUpperBound } from \"./validation.js\";\n\nconst setInputValue = (input: HTMLInputElement, value: string) => {\n const nativeSetter = Object.getOwnPropertyDescriptor(\n HTMLInputElement.prototype,\n \"value\",\n )?.set;\n\n if (nativeSetter) {\n nativeSetter.call(input, value);\n } else {\n input.value = value;\n }\n};\n\nconst normalizeInputValue = (\n rawValue: string,\n shouldStripAutoFormatting: boolean,\n) => {\n const digits = rawValue.replace(/\\D/g, \"\");\n const partialCompactDate = formatDateString(digits, {\n partial: true,\n });\n const rawValueWithoutTrailingPunctuation = rawValue.replace(/\\D+$/, \"\");\n const compactDateCandidate =\n digits.length === 8 ? formatDateString(digits) : rawValue;\n const validCompactDate = parseDateString(compactDateCandidate)\n ? compactDateCandidate\n : null;\n const shouldRemoveFormatting =\n shouldStripAutoFormatting &&\n rawValue !== digits &&\n rawValueWithoutTrailingPunctuation === partialCompactDate &&\n parseDateString(rawValue) === undefined &&\n validCompactDate === null;\n\n return validCompactDate ?? (shouldRemoveFormatting ? digits : rawValue);\n};\n\nconst getInputValidationState = ({\n value,\n minDate,\n maxDate,\n}: {\n value: string;\n minDate?: Date;\n maxDate?: Date;\n}): { date: Date | null; error: DateValidationError | null } => {\n if (!value) {\n return { date: null, error: null };\n }\n\n const parsedDate = parseDateString(value);\n\n if (!parsedDate) {\n return { date: null, error: \"WRONG_FORMAT\" };\n }\n\n if (minDate && !isWithinLowerBound(parsedDate, minDate)) {\n return { date: parsedDate, error: \"OUTSIDE_LOWER_BOUND\" };\n }\n\n if (maxDate && !isWithinUpperBound(parsedDate, maxDate)) {\n return { date: parsedDate, error: \"OUTSIDE_UPPER_BOUND\" };\n }\n\n return { date: parsedDate, error: null };\n};\n\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(\n (props, forwardedInputRef) => {\n const {\n \"data-testautoid\": testAutoId,\n id,\n className = \"\",\n label = \"Velg dato\",\n labelProps,\n defaultValue,\n defaultShow = false,\n value,\n disableBeforeDate: disableBefore,\n disableAfterDate: disableAfter,\n yearsToShow,\n name,\n helpLabel,\n errorLabel,\n invalid,\n days,\n months,\n monthLabel,\n yearLabel,\n placeholder = \"dd.mm.åååå\",\n width = \"11.25rem\",\n onChange,\n onBlur,\n onFocus,\n onKeyDown,\n action,\n showCalendarLabel = \"Åpne kalender\",\n hideCalendarLabel = \"Lukk kalender\",\n supportLabelProps,\n tooltip,\n textInputProps,\n description,\n ...rest\n } = props;\n\n if (process.env.NODE_ENV !== \"production\" && value && defaultValue) {\n console.warn(\n \"DatePicker må enten være controlled eller uncontrolled. Hvis du bruker defaultValue og value sammen vil defaultValue bli ignorert.\",\n );\n }\n /// Input state\n\n const disableBeforeDate = parseDateString(disableBefore);\n const minDate = disableBeforeDate\n ? dayjs(disableBeforeDate).startOf(\"day\").toDate()\n : undefined;\n const disableAfterDate = parseDateString(disableAfter);\n const maxDate = disableAfterDate\n ? dayjs(disableAfterDate).startOf(\"day\").toDate()\n : undefined;\n\n const [date, setDate] = useState(\n getInitialDate(value, defaultValue, minDate, maxDate),\n );\n const [error, setError] = useState<DateValidationError | null>(null);\n\n /// Calendar state\n\n const [showCalendar, setShowCalendar] = useState(defaultShow);\n\n const calendarRef = useRef<HTMLDivElement>(null);\n const datepickerRef = useRef<HTMLDivElement>(null);\n\n /// Input events\n\n const iconButtonRef = useRef<HTMLButtonElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const didAutoFormatCompactInputRef = useRef(false);\n\n // Hjelper for å gjøre det enklere å både forwarde refen men også bruke den selv internt\n const unifiedInputRef = useCallback(\n (instance: HTMLInputElement | null) => {\n inputRef.current = instance;\n if (forwardedInputRef) {\n if (typeof forwardedInputRef === \"function\") {\n forwardedInputRef(instance);\n } else {\n forwardedInputRef.current = instance;\n }\n }\n },\n [forwardedInputRef],\n );\n\n const handleFocus = useCallback(\n (e: FocusEvent<HTMLInputElement>) => {\n if (!onFocus || !datepickerRef.current) {\n return;\n }\n\n const nextFocusIsInside = datepickerRef.current.contains(\n e.relatedTarget as Node,\n );\n if (!nextFocusIsInside) {\n onFocus(e, date, { error, value: e.target.value });\n }\n },\n [onFocus, date, error],\n );\n\n const handleBlur = useCallback(\n (e: FocusEvent<HTMLInputElement>) => {\n if (onBlur) {\n onBlur(e, date, { error, value: e.target.value });\n }\n },\n [onBlur, date, error],\n );\n\n const handleKeyDownAction = useCallback(\n (e: React.KeyboardEvent<HTMLButtonElement>) => {\n if (e.key === \"Escape\") {\n setShowCalendar(false);\n e.preventDefault();\n e.stopPropagation();\n }\n\n if (action?.onKeyDown) {\n action.onKeyDown(e);\n }\n },\n [action],\n );\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n const rawValue = e.currentTarget.value;\n const formattedValue = normalizeInputValue(\n rawValue,\n didAutoFormatCompactInputRef.current,\n );\n\n if (formattedValue !== rawValue) {\n setInputValue(e.currentTarget, formattedValue);\n }\n\n const digits = rawValue.replace(/\\D/g, \"\");\n didAutoFormatCompactInputRef.current =\n rawValue === digits &&\n formattedValue === formatDateString(digits) &&\n formattedValue !== rawValue &&\n parseDateString(formattedValue) !== undefined;\n\n const { date: nextDate, error: nextError } =\n getInputValidationState({\n value: formattedValue,\n minDate,\n maxDate,\n });\n\n if (nextDate && !nextError) {\n setShowCalendar(false);\n }\n\n setError(nextError);\n setDate(nextDate);\n\n if (onChange) {\n onChange(e, nextDate, {\n error: nextError,\n value: formattedValue,\n });\n }\n },\n [onChange, minDate, maxDate],\n );\n\n /// Calendar events\n\n const clickCalendar = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n flushSync(() => {\n setShowCalendar(!showCalendar);\n });\n\n const calendarEl = calendarRef.current;\n const button =\n calendarEl &&\n (calendarEl.querySelector(\n '[aria-pressed=\"true\"]',\n ) as HTMLButtonElement);\n // Make sure the popover-modal is correctly positioned before focusing a button\n // so we avoid accidentally scrolling to the top of the page\n window.requestAnimationFrame(() => button?.focus());\n\n if (action?.onClick) {\n action.onClick(e);\n }\n },\n [showCalendar, action],\n );\n\n const handleClickCalendarDay = useCallback(\n ({ date }: DateInfo) => {\n setShowCalendar(false);\n setDate(date);\n\n if (inputRef.current) {\n const node = inputRef.current;\n\n didAutoFormatCompactInputRef.current = false;\n node.value = formatInput(date);\n\n // Simulér et change-event så APIet blir så likt som mulig en endring av inputfeltet\n const event = document.createEvent(\"HTMLEvents\");\n event.initEvent(\"input\", true, false);\n node.dispatchEvent(event);\n\n node.focus();\n\n if (onChange) {\n // Det er ikke helt sant at dette er et React.SyntheticEvent, men it's fine – probably?\n // Den har tingene man kan forvente, men hvis du gjør serdeles fancy ting med events\n // så kan det hende du må utvide denne for å dekke behovet ditt.\n onChange(\n event as unknown as ChangeEvent<HTMLInputElement>,\n date,\n {\n error: null,\n value: node.value,\n },\n );\n }\n }\n },\n [onChange],\n );\n\n const handleTabOutsideCalendar = useCallback((e: KeyboardEvent) => {\n e.preventDefault();\n setShowCalendar(false);\n iconButtonRef.current?.focus();\n }, []);\n\n return (\n <InputGroup\n id={id}\n className={clsx(\"jkl-datepicker\", className)}\n {...rest}\n ref={datepickerRef}\n label={label}\n labelProps={labelProps}\n helpLabel={helpLabel}\n errorLabel={errorLabel}\n supportLabelProps={supportLabelProps}\n tooltip={tooltip}\n description={description}\n render={(inputProps) => (\n <BaseTextInput\n data-focused={showCalendar ? \"true\" : undefined}\n ref={unifiedInputRef}\n data-testid=\"jkl-datepicker__input\"\n data-testautoid={testAutoId}\n className=\"jkl-datepicker__input\"\n name={name}\n defaultValue={defaultValue}\n value={value}\n type=\"text\"\n placeholder={placeholder}\n width={width}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onChange={handleChange}\n actionButton={\n <Popover\n positionReference={inputRef}\n open={showCalendar}\n onOpenChange={() =>\n setShowCalendar(!showCalendar)\n }\n offset={8}\n >\n <Popover.Trigger\n {...action}\n data-testid=\"jkl-datepicker__trigger\"\n className=\"jkl-text-input-action-button\"\n title={\n showCalendar\n ? hideCalendarLabel\n : showCalendarLabel\n }\n tabIndex={0}\n onClick={clickCalendar}\n onKeyDown={handleKeyDownAction}\n asChild\n >\n <IconButton>\n <CalendarIcon />\n </IconButton>\n </Popover.Trigger>\n <Popover.Content initialFocus={-1} padding={24}>\n <Calendar\n ref={calendarRef}\n date={date}\n minDate={minDate}\n maxDate={maxDate}\n days={days}\n months={months}\n monthLabel={monthLabel}\n yearLabel={yearLabel}\n yearsToShow={yearsToShow}\n onDateSelected={handleClickCalendarDay}\n onTabOutside={handleTabOutsideCalendar}\n />\n </Popover.Content>\n </Popover>\n }\n {...textInputProps}\n {...inputProps}\n aria-invalid={invalid || !!errorLabel}\n />\n )}\n />\n );\n },\n);\n\nDatePicker.displayName = \"DatePicker\";\n"],"names":["DatePicker","forwardRef","props","forwardedInputRef","testAutoId","id","className","label","labelProps","defaultValue","defaultShow","value","disableBeforeDate","disableBefore","disableAfterDate","disableAfter","yearsToShow","name","helpLabel","errorLabel","invalid","days","months","monthLabel","yearLabel","placeholder","width","onChange","onBlur","onFocus","onKeyDown","action","showCalendarLabel","hideCalendarLabel","supportLabelProps","tooltip","textInputProps","description","rest","process","env","NODE_ENV","console","warn","parseDateString","minDate","dayjs","startOf","toDate","maxDate","date","setDate","useState","getInitialDate","error","setError","showCalendar","setShowCalendar","calendarRef","useRef","datepickerRef","iconButtonRef","inputRef","didAutoFormatCompactInputRef","unifiedInputRef","useCallback","instance","current","handleFocus","e","contains","relatedTarget","target","handleBlur","handleKeyDownAction","key","preventDefault","stopPropagation","handleChange","rawValue","currentTarget","formattedValue","shouldStripAutoFormatting","digits","replace","partialCompactDate","formatDateString","partial","rawValueWithoutTrailingPunctuation","compactDateCandidate","length","validCompactDate","shouldRemoveFormatting","normalizeInputValue","input","nativeSetter","Object","getOwnPropertyDescriptor","HTMLInputElement","prototype","set","call","setInputValue","nextDate","nextError","parsedDate","isWithinLowerBound","isWithinUpperBound","getInputValidationState","clickCalendar","flushSync","calendarEl","button","querySelector","window","requestAnimationFrame","focus","onClick","handleClickCalendarDay","node","formatInput","event","document","createEvent","initEvent","dispatchEvent","handleTabOutsideCalendar","jsx","InputGroup","clsx","ref","render","inputProps","BaseTextInput","type","actionButton","jsxs","Popover","positionReference","open","onOpenChange","offset","children","Trigger","title","tabIndex","asChild","IconButton","CalendarIcon","Content","initialFocus","padding","Calendar","onDateSelected","onTabOutside","displayName"],"mappings":"wzBAyBA,MAmEaA,EAAaC,EACtB,CAACC,EAAOC,KACJ,MACI,kBAAmBC,EACnBC,GAAAA,EACAC,UAAAA,EAAY,GACZC,MAAAA,EAAQ,YACRC,WAAAA,EACAC,aAAAA,EACAC,YAAAA,GAAc,EACdC,MAAAA,EACAC,kBAAmBC,EACnBC,iBAAkBC,EAClBC,YAAAA,EACAC,KAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAC,QAAAA,EACAC,KAAAA,EACAC,OAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,YAAAA,EAAc,aACdC,MAAAA,EAAQ,WACRC,SAAAA,EACAC,OAAAA,EACAC,QAAAA,EACAC,UAAAA,EACAC,OAAAA,EACAC,kBAAAA,EAAoB,gBACpBC,kBAAAA,EAAoB,gBACpBC,kBAAAA,EACAC,QAAAA,EACAC,eAAAA,EACAC,YAAAA,KACGC,IACHpC,EAEyB,eAAzBqC,QAAQC,IAAIC,UAA6B9B,GAASF,GAClDiC,QAAQC,KACJ,sIAKR,MAAM/B,GAAoBgC,EAAgB/B,GACpCgC,GAAUjC,GACVkC,EAAMlC,IAAmBmC,QAAQ,OAAOC,cACxC,EACAlC,GAAmB8B,EAAgB7B,GACnCkC,GAAUnC,GACVgC,EAAMhC,IAAkBiC,QAAQ,OAAOC,cACvC,GAECE,GAAMC,IAAWC,EACpBC,EAAe1C,EAAOF,EAAcoC,GAASI,MAE1CK,GAAOC,IAAYH,EAAqC,OAIxDI,GAAcC,IAAmBL,EAAS1C,GAE3CgD,GAAcC,EAAuB,MACrCC,GAAgBD,EAAuB,MAIvCE,GAAgBF,EAAiC,MACjDG,GAAWH,EAAgC,MAC3CI,GAA+BJ,GAAO,GAGtCK,GAAkBC,EACnBC,IACGJ,GAASK,QAAUD,EACf/D,IACiC,mBA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@@
|
|
|
1
|
-
export { DatePicker } from './DatePicker.js';
|
|
2
|
-
export { isCorrectFormat, isWithinLowerBound, isWithinUpperBound, } from './validation.js';
|
|
3
|
-
export { formatInput, parseDateString, isBlurTargetOutside } from './utils.js';
|
|
4
|
-
export type { DatePickerProps, YearsToShow, DatePickerChangeEventHandler, DatePickerFocusEventHandler, DatePickerBlurEventHandler, DatePickerKeyDownEventHandler, DatePickerAction, ComparisonOptions, DatePickerMetadata, } from './types.js';
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{DatePicker as r}from"./DatePicker.js";import{isCorrectFormat as s,isWithinLowerBound as a,isWithinUpperBound as i}from"./validation.js";import{formatInput as t,isBlurTargetOutside as e,parseDateString as o}from"./utils.js";export{r as DatePicker,t as formatInput,e as isBlurTargetOutside,s as isCorrectFormat,a as isWithinLowerBound,i as isWithinUpperBound,o as parseDateString};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { YearsToShow } from '../types.js';
|
|
3
|
-
import { UseCalendarProps } from './useCalendar.js';
|
|
4
|
-
interface CalendarProps extends Omit<UseCalendarProps, "date" | "onOffsetChanged" | "offset" | "firstDayOfWeek" | "selected"> {
|
|
5
|
-
date: Date | null;
|
|
6
|
-
defaultSelected?: Date;
|
|
7
|
-
days?: string[];
|
|
8
|
-
months?: string[];
|
|
9
|
-
monthLabel?: string;
|
|
10
|
-
yearLabel?: string;
|
|
11
|
-
yearsToShow?: YearsToShow;
|
|
12
|
-
onTabOutside: React.KeyboardEventHandler;
|
|
13
|
-
}
|
|
14
|
-
export declare const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{forwardRef as a,useReducer as n,useEffect as r,useCallback as l,useRef as o}from"react";import{flushSync as s}from"react-dom";import{useId as d}from"../../../hooks/useId/useId.js";import{Button as c}from"../../button/Button.js";import{ArrowLeftIcon as i}from"../../icon/icons/ArrowLeftIcon.js";import{ArrowRightIcon as u}from"../../icon/icons/ArrowRightIcon.js";import{ChevronDownIcon as h}from"../../icon/icons/ChevronDownIcon.js";import{calendarReducer as m,calendarInitializer as f}from"./calendarReducer.js";import{useCalendar as g}from"./useCalendar.js";import{D as b,a as p,i as v,s as k,b as j,c as D,e as w,f as y}from"../../../../utils-C5AH4j8B.js";const M=["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"],F=["man","tir","ons","tor","fre","lør","søn"],S=a((a,S)=>{const{date:A,defaultSelected:N,minDate:_,maxDate:$,days:x=F,months:C=M,monthLabel:E="Velg måned",yearLabel:Y="Velg år",yearsToShow:I=b,onTabOutside:O,...T}=a,R=d("jkl-calendar"),[{offset:L,selectedDate:q,shownDate:K},B]=n(m,p(A,N,_,$),f),J=K.getMonth(),P=K.getFullYear();r(()=>{B({type:"SET_SELECTED_DATE",newDate:p(A,N,_,$)})},[A,N,_,$]);const V=l(e=>{B({type:"SET_OFFSET",newOffset:e})},[]),{calendars:z,getBackProps:U,getDateProps:W,getForwardProps:G,handleOffsetChanged:H}=g({date:q,selected:q,minDate:_,maxDate:$,offset:L,onOffsetChanged:V,firstDayOfWeek:1,...T}),Q=o(null),X=l(e=>{if(!Q.current)return;const t=document.activeElement,a=Q.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]'),n=async e=>{t?.setAttribute("tabindex","-1"),e.setAttribute("tabindex","0"),e.focus()};a.forEach((r,l)=>{const o=l+e;if(r===t)if(o<=a.length-1&&o>=0)n(a[o]);else if(e<0){if(v({calendars:z,minDate:_})||(s(()=>{H(L-k({calendars:z,offset:1,minDate:_}))}),!Q.current))return;const e=Q.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]');e[e.length+o]&&(e[0].setAttribute("tabindex","-1"),n(e[e.length+o]))}else{if(j({calendars:z,maxDate:$})||(s(()=>{H(L+D({calendars:z,offset:1,maxDate:$}))}),!Q.current))return;const e=Q.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]');e[o-a.length]&&(e[0].setAttribute("tabindex","-1"),n(e[o-a.length]))}})},[H,L,z,$,_]),Z=l(e=>{switch(e.key){case"ArrowUp":X(-7),e.preventDefault();break;case"ArrowRight":X(1),e.preventDefault();break;case"ArrowDown":X(7),e.preventDefault();break;case"ArrowLeft":X(-1),e.preventDefault()}},[X]),ee=l(e=>{if("Tab"!==e.key)return;const t=Q.current?.querySelectorAll('button:not([disabled]):not([tabindex="-1"]), select');if(!t)return;const a=t[0],n=t[t.length-1];e.shiftKey||document.activeElement!==n?e.shiftKey&&document.activeElement===a&&(n.focus(),e.preventDefault()):(a.focus(),e.preventDefault())},[]),te=l(e=>{const{date:t,selected:a,selectable:n,prevMonth:r,nextMonth:l}=e;return!!n&&!(!a&&t.toString()!==_?.toString()&&(r||l||K.getFullYear()!==t.getFullYear()||q.getMonth()===t.getMonth()||1!==t.getDate()))},[K,_,q]),ae=l(()=>{_&&K.getFullYear()-_.getFullYear()===0&&K.getMonth()-_.getMonth()===1?document.querySelector(`[data-testid="${R}-forward-button"]`)?.focus():$&&$.getFullYear()-K.getFullYear()===0&&$.getMonth()-K.getMonth()===1&&document.querySelector(`[data-testid="${R}-back-button"]`)?.focus()},[_,$,K,R]),ne=l(e=>{if(4!==e.target.value.length)return;const t=Number.parseInt(e.target.value);if(Number.isNaN(t))return;let a=12*(t-K.getFullYear());const n=new Date(K.getFullYear(),K.getMonth()+a,K.getDate());$&&$.getFullYear()===n.getFullYear()&&$.getMonth()<n.getMonth()?a-=n.getMonth()-$.getMonth():_&&_.getFullYear()===n.getFullYear()&&_.getMonth()>n.getMonth()&&(a+=_.getMonth()-n.getMonth()),B({type:"ADD_OFFSET",addedOffset:a})},[K,_,$]),re=l(e=>{if(!q&&!A)return;const t=K.getFullYear()-(q||new Date).getFullYear(),a=Number.parseInt(e.target.value)-(q||new Date).getMonth();B({type:"SET_OFFSET",newOffset:12*t+a})},[q,A,K]),le=w(P,_,$,I),oe=y(P,C,_,$);return e("div",{ref:S,id:R,className:"jkl-calendar","data-testid":"jkl-calendar",children:t("div",{className:"jkl-calendar__padding",ref:Q,onKeyDown:ee,children:[t("fieldset",{className:"jkl-calendar-navigation",children:[t("div",{children:[e(c,{...U({calendars:z,onClick:ae}),"data-testid":`${R}-back-button`,variant:"ghost",icon:e(i,{variant:"medium",bold:!0})}),e(c,{...G({calendars:z,onClick:ae}),variant:"ghost","data-testid":`${R}-forward-button`,icon:e(u,{variant:"medium",bold:!0})})]}),t("div",{children:[t("div",{className:"jkl-calendar-navigation-dropdown",children:[e("select",{onChange:re,className:"jkl-calendar-navigation-dropdown__select","aria-label":E,value:J.toString(),children:oe.map(({label:t,value:a})=>e("option",{value:a,children:t},a))}),e(h,{bold:!0,className:"jkl-calendar-navigation-dropdown__chevron"})]}),t("div",{className:"jkl-calendar-navigation-dropdown",children:[e("select",{onChange:ne,className:"jkl-calendar-navigation-dropdown__select","aria-label":Y,value:P.toString(),children:le.map(t=>e("option",{value:t,children:t},t))}),e(h,{bold:!0,className:"jkl-calendar-navigation-dropdown__chevron"})]})]})]}),z.map(a=>t("table",{className:"jkl-calendar-table","data-testid":"jkl-datepicker-calendar",children:[t("caption",{className:"jkl-sr-only",children:[C[a.month],", ",a.year]}),e("thead",{children:e("tr",{children:x.map(t=>e("th",{children:t},`${a.month}${a.year}${t}`))})}),e("tbody",{"data-testid":"jkl-datepicker-dates",children:a.weeks.map((t,n)=>e("tr",{children:t.map((t,r)=>{const l=`${a.month}${a.year}${n}${r}`;if("string"==typeof t)return e("td",{className:"jkl-calendar__date jkl-calendar__date--empty",children:t},l);const{date:o,selectable:s,today:d,prevMonth:c,nextMonth:i}=t;return e("td",{children:e("button",{...W({dateObj:t}),type:"button",className:"jkl-calendar-date-button",tabIndex:te(t)?0:-1,"aria-label":`${o.getDate()}. ${C[o.getMonth()].toLowerCase()}`,"aria-current":d?"date":void 0,"data-adjacent":c||i?"true":void 0,disabled:!s,onKeyDown:Z,children:e("span",{"aria-hidden":"true",children:o.getDate()})})},l)})},`${a.month}${a.year}${n}`))})]},`${a.month}${a.year}`))]})})});S.displayName="Calendar";export{S as Calendar};
|
|
2
|
-
//# sourceMappingURL=Calendar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.js","sources":["../../../../../src/components/datepicker/internal/Calendar.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useReducer,\n useRef,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useId } from \"../../../hooks/useId/useId.js\";\nimport { Button } from \"../../button/Button.js\";\nimport { ArrowLeftIcon } from \"../../icon/icons/ArrowLeftIcon.js\";\nimport { ArrowRightIcon } from \"../../icon/icons/ArrowRightIcon.js\";\nimport { ChevronDownIcon } from \"../../icon/icons/ChevronDownIcon.js\";\nimport type { YearsToShow } from \"../types.js\";\nimport { calendarInitializer, calendarReducer } from \"./calendarReducer.js\";\nimport { type UseCalendarProps, useCalendar } from \"./useCalendar.js\";\nimport {\n DEFAULT_YEARS_TO_SHOW,\n type DateInfo,\n addMonth,\n getInitialDateShown,\n getMonthSelectOptions,\n getYearSelectOptions,\n isBackDisabled,\n isForwardDisabled,\n subtractMonth,\n} from \"./utils.js\";\n\ninterface CalendarProps\n extends Omit<\n UseCalendarProps,\n \"date\" | \"onOffsetChanged\" | \"offset\" | \"firstDayOfWeek\" | \"selected\"\n > {\n date: Date | null;\n defaultSelected?: Date;\n days?: string[];\n months?: string[];\n monthLabel?: string;\n yearLabel?: string;\n yearsToShow?: YearsToShow;\n onTabOutside: React.KeyboardEventHandler;\n}\n\nconst defaultMonths = [\n \"Januar\",\n \"Februar\",\n \"Mars\",\n \"April\",\n \"Mai\",\n \"Juni\",\n \"Juli\",\n \"August\",\n \"September\",\n \"Oktober\",\n \"November\",\n \"Desember\",\n];\n\nconst defaultDays = [\"man\", \"tir\", \"ons\", \"tor\", \"fre\", \"lør\", \"søn\"];\n\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(\n (props, ref) => {\n const {\n date,\n defaultSelected,\n minDate,\n maxDate,\n days = defaultDays,\n months = defaultMonths,\n monthLabel = \"Velg måned\",\n yearLabel = \"Velg år\",\n yearsToShow = DEFAULT_YEARS_TO_SHOW,\n onTabOutside,\n ...rest\n } = props;\n\n const id = useId(\"jkl-calendar\");\n\n const [{ offset, selectedDate, shownDate }, dispatch] = useReducer(\n calendarReducer,\n getInitialDateShown(date, defaultSelected, minDate, maxDate),\n calendarInitializer,\n );\n\n const shownMonth = shownDate.getMonth();\n const shownYear = shownDate.getFullYear();\n\n useEffect(() => {\n dispatch({\n type: \"SET_SELECTED_DATE\",\n newDate: getInitialDateShown(\n date,\n defaultSelected,\n minDate,\n maxDate,\n ),\n });\n }, [date, defaultSelected, minDate, maxDate]);\n\n const onOffsetChanged = useCallback((newOffset: number) => {\n dispatch({\n type: \"SET_OFFSET\",\n newOffset,\n });\n }, []);\n\n const {\n calendars,\n getBackProps,\n getDateProps,\n getForwardProps,\n handleOffsetChanged,\n } = useCalendar({\n date: selectedDate,\n selected: selectedDate,\n minDate,\n maxDate,\n offset,\n onOffsetChanged,\n firstDayOfWeek: 1,\n ...rest,\n });\n\n /// Calendar keyboard navigation\n\n const calendarPaddingRef = useRef<HTMLDivElement>(null);\n const doFocusChange = useCallback(\n (offsetDiff: number) => {\n if (!calendarPaddingRef.current) {\n return;\n }\n\n const e = document.activeElement;\n const buttons =\n calendarPaddingRef.current.querySelectorAll<HTMLButtonElement>(\n 'button.jkl-calendar-date-button:not([data-adjacent=\"true\"]',\n );\n\n const changeFocusTo = async (nextButton: HTMLButtonElement) => {\n e?.setAttribute(\"tabindex\", \"-1\");\n nextButton.setAttribute(\"tabindex\", \"0\");\n nextButton.focus();\n };\n\n buttons.forEach((el, i) => {\n const newNodeKey = i + offsetDiff;\n\n if (el === e) {\n if (\n newNodeKey <= buttons.length - 1 &&\n newNodeKey >= 0\n ) {\n changeFocusTo(buttons[newNodeKey]);\n } else if (offsetDiff < 0) {\n if (isBackDisabled({ calendars, minDate })) {\n return;\n }\n\n // Hvis newNodeKey er utenfor samlingen med knapper så har vi prøvd å gå til\n // en dag utenfor måneden. Er offsetDiff negativ så har vi gått tilbake en\n // måned.\n flushSync(() => {\n handleOffsetChanged(\n offset -\n subtractMonth({\n calendars,\n offset: 1,\n minDate,\n }),\n );\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons =\n calendarPaddingRef.current.querySelectorAll<HTMLButtonElement>(\n 'button.jkl-calendar-date-button:not([data-adjacent=\"true\"]',\n );\n // + - = -\n if (newButtons[newButtons.length + newNodeKey]) {\n // Sørg for at ikke både 1. i måneden og valgt dag er fokuserbare\n newButtons[0].setAttribute(\"tabindex\", \"-1\");\n changeFocusTo(\n newButtons[newButtons.length + newNodeKey],\n );\n }\n } else {\n if (isForwardDisabled({ calendars, maxDate })) {\n return;\n }\n\n // Hvis newNodeKey er utenfor samlingen med knapper så har vi prøvd å gå til\n // en dag utenfor måneden. Er offsetDiff positiv så har vi gått frem en\n // måned.\n flushSync(() => {\n handleOffsetChanged(\n offset +\n addMonth({\n calendars,\n offset: 1,\n maxDate,\n }),\n );\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons =\n calendarPaddingRef.current.querySelectorAll<HTMLButtonElement>(\n 'button.jkl-calendar-date-button:not([data-adjacent=\"true\"]',\n );\n // NewNodeKey er basert på forrige måneds liste med knapper. For at verdien skal bli\n // riktig i vår nye måned må vi trekke fra anntal dager fra forrige måned.\n if (newButtons[newNodeKey - buttons.length]) {\n // Sørg for at ikke både 1. i måneden og valgt dag er fokuserbare\n newButtons[0].setAttribute(\"tabindex\", \"-1\");\n changeFocusTo(\n newButtons[newNodeKey - buttons.length],\n );\n }\n }\n }\n });\n },\n [handleOffsetChanged, offset, calendars, maxDate, minDate],\n );\n\n const handleArrowNavigation = useCallback(\n (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"ArrowUp\":\n doFocusChange(-7);\n event.preventDefault();\n break;\n case \"ArrowRight\":\n doFocusChange(1);\n event.preventDefault();\n break;\n case \"ArrowDown\":\n doFocusChange(7);\n event.preventDefault();\n break;\n case \"ArrowLeft\":\n doFocusChange(-1);\n event.preventDefault();\n break;\n default:\n break;\n }\n },\n [doFocusChange],\n );\n\n const handleTabInside: React.KeyboardEventHandler = useCallback(\n (event) => {\n if (event.key !== \"Tab\") return;\n\n const focusableElements =\n calendarPaddingRef.current?.querySelectorAll<HTMLElement>(\n 'button:not([disabled]):not([tabindex=\"-1\"]), select',\n );\n\n if (!focusableElements) return;\n\n const firstElement = focusableElements[0];\n const lastElement =\n focusableElements[focusableElements.length - 1];\n\n if (!event.shiftKey && document.activeElement === lastElement) {\n firstElement.focus();\n event.preventDefault();\n } else if (\n event.shiftKey &&\n document.activeElement === firstElement\n ) {\n lastElement.focus();\n event.preventDefault();\n }\n },\n [],\n );\n\n const isFocusableDate = useCallback(\n (dateInfo: DateInfo) => {\n const { date, selected, selectable, prevMonth, nextMonth } =\n dateInfo;\n\n // Datoen kan ikke velges\n if (!selectable) {\n return false;\n }\n // Datoen er valgt dato\n if (selected) {\n return true;\n }\n // Datoen er første valgbare dato\n if (date.toString() === minDate?.toString()) {\n return true;\n }\n\n // Datoen er første i måneden som vises\n if (\n !prevMonth &&\n !nextMonth &&\n shownDate.getFullYear() === date.getFullYear() &&\n selectedDate.getMonth() !== date.getMonth() &&\n date.getDate() === 1\n ) {\n return true;\n }\n\n return false;\n },\n [shownDate, minDate, selectedDate],\n );\n\n const handleGotoEdgeMonth = useCallback(() => {\n if (\n // Vi er i ferd med å gå til første måned\n minDate &&\n shownDate.getFullYear() - minDate.getFullYear() === 0 &&\n shownDate.getMonth() - minDate.getMonth() === 1\n ) {\n // Fokuser på \"neste månded\"-knappen\n document\n .querySelector<HTMLButtonElement>(\n `[data-testid=\"${id}-forward-button\"]`,\n )\n ?.focus();\n } else if (\n // Vi er i ferd med å gå til siste måned\n maxDate &&\n maxDate.getFullYear() - shownDate.getFullYear() === 0 &&\n maxDate.getMonth() - shownDate.getMonth() === 1\n ) {\n // Fokuser på \"forrige månded\"-knappen\n document\n .querySelector<HTMLButtonElement>(\n `[data-testid=\"${id}-back-button\"]`,\n )\n ?.focus();\n }\n }, [minDate, maxDate, shownDate, id]);\n\n /// Extended variant events\n\n const handleYearChange = useCallback<\n React.ChangeEventHandler<HTMLSelectElement>\n >(\n (event) => {\n if (event.target.value.length !== 4) {\n return;\n }\n\n const year: number = Number.parseInt(event.target.value);\n if (Number.isNaN(year)) {\n return;\n }\n\n let offset = (year - shownDate.getFullYear()) * 12;\n const expectedDate = new Date(\n shownDate.getFullYear(),\n shownDate.getMonth() + offset,\n shownDate.getDate(),\n );\n\n // Pass på at vi ikke hopper forbi maks. eller min. dato\n if (\n maxDate &&\n maxDate.getFullYear() === expectedDate.getFullYear() &&\n maxDate.getMonth() < expectedDate.getMonth()\n ) {\n offset -= expectedDate.getMonth() - maxDate.getMonth();\n } else if (\n minDate &&\n minDate.getFullYear() === expectedDate.getFullYear() &&\n minDate.getMonth() > expectedDate.getMonth()\n ) {\n offset += minDate.getMonth() - expectedDate.getMonth();\n }\n\n dispatch({\n type: \"ADD_OFFSET\",\n addedOffset: offset,\n });\n\n return;\n },\n [shownDate, minDate, maxDate],\n );\n\n const handleMonthChange = useCallback<\n React.ChangeEventHandler<HTMLSelectElement>\n >(\n (event) => {\n if (!selectedDate && !date) {\n return;\n }\n\n const yearDiff =\n shownDate.getFullYear() -\n (selectedDate || new Date()).getFullYear();\n const monthDiff =\n Number.parseInt(event.target.value) -\n (selectedDate || new Date()).getMonth();\n\n dispatch({\n type: \"SET_OFFSET\",\n newOffset: yearDiff * 12 + monthDiff,\n });\n\n return;\n },\n [selectedDate, date, shownDate],\n );\n\n const yearSelectOptions = getYearSelectOptions(\n shownYear,\n minDate,\n maxDate,\n yearsToShow,\n );\n const monthSelectOptions = getMonthSelectOptions(\n shownYear,\n months,\n minDate,\n maxDate,\n );\n\n return (\n <div\n ref={ref}\n id={id}\n className=\"jkl-calendar\"\n data-testid=\"jkl-calendar\"\n >\n {/* Vi lytter på på trykk på Tab inne i kalenderen for å håndtere fokus */}\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}\n <div\n className=\"jkl-calendar__padding\"\n ref={calendarPaddingRef}\n onKeyDown={handleTabInside}\n >\n <fieldset className=\"jkl-calendar-navigation\">\n <div>\n <Button\n {...getBackProps({\n calendars,\n onClick: handleGotoEdgeMonth,\n })}\n data-testid={`${id}-back-button`}\n variant=\"ghost\"\n icon={<ArrowLeftIcon variant=\"medium\" bold />}\n />\n <Button\n {...getForwardProps({\n calendars,\n onClick: handleGotoEdgeMonth,\n })}\n variant=\"ghost\"\n data-testid={`${id}-forward-button`}\n icon={<ArrowRightIcon variant=\"medium\" bold />}\n />\n </div>\n <div>\n <div className=\"jkl-calendar-navigation-dropdown\">\n <select\n onChange={handleMonthChange}\n className=\"jkl-calendar-navigation-dropdown__select\"\n aria-label={monthLabel}\n value={shownMonth.toString()}\n >\n {monthSelectOptions.map(\n ({ label, value }) => (\n <option key={value} value={value}>\n {label}\n </option>\n ),\n )}\n </select>\n <ChevronDownIcon\n bold\n className=\"jkl-calendar-navigation-dropdown__chevron\"\n />\n </div>\n <div className=\"jkl-calendar-navigation-dropdown\">\n <select\n onChange={handleYearChange}\n className=\"jkl-calendar-navigation-dropdown__select\"\n aria-label={yearLabel}\n value={shownYear.toString()}\n >\n {yearSelectOptions.map((year) => (\n <option key={year} value={year}>\n {year}\n </option>\n ))}\n </select>\n <ChevronDownIcon\n bold\n className=\"jkl-calendar-navigation-dropdown__chevron\"\n />\n </div>\n </div>\n </fieldset>\n {calendars.map((calendar) => (\n <table\n className=\"jkl-calendar-table\"\n key={`${calendar.month}${calendar.year}`}\n data-testid=\"jkl-datepicker-calendar\"\n >\n <caption className=\"jkl-sr-only\">\n {months[calendar.month]}, {calendar.year}\n </caption>\n <thead>\n <tr>\n {days.map((weekday) => (\n <th\n key={`${calendar.month}${calendar.year}${weekday}`}\n >\n {weekday}\n </th>\n ))}\n </tr>\n </thead>\n <tbody data-testid=\"jkl-datepicker-dates\">\n {calendar.weeks.map((week, weekIndex) => (\n <tr\n key={`${calendar.month}${calendar.year}${weekIndex}`}\n >\n {week.map((dateInfo, index) => {\n const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;\n if (typeof dateInfo === \"string\") {\n return (\n <td\n className=\"jkl-calendar__date jkl-calendar__date--empty\"\n key={key}\n >\n {dateInfo}\n </td>\n );\n }\n const {\n date,\n selectable,\n today,\n prevMonth,\n nextMonth,\n } = dateInfo;\n\n return (\n <td key={key}>\n <button\n {...getDateProps({\n dateObj: dateInfo,\n })}\n type=\"button\"\n className=\"jkl-calendar-date-button\"\n tabIndex={\n isFocusableDate(\n dateInfo,\n )\n ? 0\n : -1\n }\n aria-label={`${date.getDate()}. ${months[\n date.getMonth()\n ].toLowerCase()}`}\n aria-current={\n today\n ? \"date\"\n : undefined\n }\n data-adjacent={\n prevMonth ||\n nextMonth\n ? \"true\"\n : undefined\n }\n disabled={!selectable}\n onKeyDown={\n handleArrowNavigation\n }\n >\n <span aria-hidden=\"true\">\n {date.getDate()}\n </span>\n </button>\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n ))}\n </div>\n </div>\n );\n },\n);\n\nCalendar.displayName = \"Calendar\";\n"],"names":["defaultMonths","defaultDays","Calendar","forwardRef","props","ref","date","defaultSelected","minDate","maxDate","days","months","monthLabel","yearLabel","yearsToShow","DEFAULT_YEARS_TO_SHOW","onTabOutside","rest","id","useId","offset","selectedDate","shownDate","dispatch","useReducer","calendarReducer","getInitialDateShown","calendarInitializer","shownMonth","getMonth","shownYear","getFullYear","useEffect","type","newDate","onOffsetChanged","useCallback","newOffset","calendars","getBackProps","getDateProps","getForwardProps","handleOffsetChanged","useCalendar","selected","firstDayOfWeek","calendarPaddingRef","useRef","doFocusChange","offsetDiff","current","e","document","activeElement","buttons","querySelectorAll","changeFocusTo","async","nextButton","setAttribute","focus","forEach","el","i","newNodeKey","length","isBackDisabled","flushSync","subtractMonth","newButtons","isForwardDisabled","addMonth","handleArrowNavigation","event","key","preventDefault","handleTabInside","focusableElements","firstElement","lastElement","shiftKey","isFocusableDate","dateInfo","selectable","prevMonth","nextMonth","toString","getDate","handleGotoEdgeMonth","querySelector","handleYearChange","target","value","year","Number","parseInt","isNaN","expectedDate","Date","addedOffset","handleMonthChange","yearDiff","monthDiff","yearSelectOptions","getYearSelectOptions","monthSelectOptions","getMonthSelectOptions","jsx","className","children","jsxs","onKeyDown","Button","onClick","variant","icon","ArrowLeftIcon","bold","ArrowRightIcon","onChange","map","label","ChevronDownIcon","calendar","month","weekday","weeks","week","weekIndex","index","today","dateObj","tabIndex","toLowerCase","disabled","displayName"],"mappings":"2sBA2CA,MAAMA,EAAgB,CAClB,SACA,UACA,OACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,YAGEC,EAAc,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,OAElDC,EAAWC,EACpB,CAACC,EAAOC,KACJ,MACIC,KAAAA,EACAC,gBAAAA,EACAC,QAAAA,EACAC,QAAAA,EACAC,KAAAA,EAAOT,EACPU,OAAAA,EAASX,EACTY,WAAAA,EAAa,aACbC,UAAAA,EAAY,UACZC,YAAAA,EAAcC,EACdC,aAAAA,KACGC,GACHb,EAEEc,EAAKC,EAAM,kBAERC,OAAAA,EAAQC,aAAAA,EAAcC,UAAAA,GAAaC,GAAYC,EACpDC,EACAC,EAAoBpB,EAAMC,EAAiBC,EAASC,GACpDkB,GAGEC,EAAaN,EAAUO,WACvBC,EAAYR,EAAUS,cAE5BC,EAAU,KACNT,EAAS,CACLU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,EAAK8G,IAAKK,GACPlB,EAAC,KAAA,CAGIE,SAAAgB,GAFI,GAAGF,EAASC,QAAQD,EAAS9B,OAAOgC,UAOzDlB,EAAC,SAAM,cAAY,uBACdE,WAASiB,MAAMN,IAAI,CAACO,EAAMC,IACvBrB,EAAC,KAAA,CAGIE,SAAAkB,EAAKP,IAAI,CAACtC,EAAU+C,KACjB,MAAMvD,EAAM,GAAGiD,EAASC,QAAQD,EAAS9B,OAAOmC,IAAYC,IAC5D,GAAwB,iBAAb/C,EACP,OACIyB,EAAC,KAAA,CACGC,UAAU,+CAGTC,SAAA3B,GAFIR,GAMjB,MACIpE,KAAAA,EACA6E,WAAAA,EACA+C,MAAAA,EACA9C,UAAAA,EACAC,UAAAA,GACAH,EAEJ,SACK,KAAA,CACG2B,SAAAF,EAAC,SAAA,IACOnE,EAAa,CACb2F,QAASjD,IAEbjD,KAAK,SACL2E,UAAU,2BACVwB,SACInD,GACIC,GAEE,GACA,EAEV,aAAY,GAAG5E,EAAKiF,cAAc5E,EAC9BL,EAAKuB,YACPwG,gBACF,eACIH,EACM,YACA,EAEV,gBACI9C,GACAC,EACM,YACA,EAEViD,UAAWnD,EACX4B,UACIvC,EAGJqC,WAAC,OAAA,CAAK,cAAY,OACbA,SAAAvG,EAAKiF,eAlCTb,MAvBZ,GAAGiD,EAASC,QAAQD,EAAS9B,OAAOmC,UApBhD,GAAGL,EAASC,QAAQD,EAAS9B,gBA8F9D3F,EAASqI,YAAc"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Reducer } from 'react';
|
|
2
|
-
export type CalendarAction = {
|
|
3
|
-
type: "SET_SELECTED_DATE";
|
|
4
|
-
newDate: Date;
|
|
5
|
-
} | {
|
|
6
|
-
type: "SET_OFFSET";
|
|
7
|
-
newOffset: number;
|
|
8
|
-
} | {
|
|
9
|
-
type: "ADD_OFFSET";
|
|
10
|
-
addedOffset: number;
|
|
11
|
-
};
|
|
12
|
-
export type CalendarState = {
|
|
13
|
-
selectedDate: Date;
|
|
14
|
-
offset: number;
|
|
15
|
-
shownDate: Date;
|
|
16
|
-
};
|
|
17
|
-
export declare const calendarReducer: Reducer<CalendarState, CalendarAction>;
|
|
18
|
-
export declare const calendarInitializer: (initialDate: Date) => CalendarState;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=(e,s)=>{let a;switch(s.type){case"SET_OFFSET":return a=new Date(e.selectedDate),a.setMonth(e.selectedDate.getMonth()+s.newOffset),{...e,offset:s.newOffset,shownDate:a};case"ADD_OFFSET":return a=new Date(e.selectedDate),a.setMonth(e.selectedDate.getMonth()+e.offset+s.addedOffset),{...e,offset:e.offset+s.addedOffset,shownDate:a};case"SET_SELECTED_DATE":return t(s.newDate);default:return e}},t=e=>({selectedDate:e,offset:0,shownDate:e});export{t as calendarInitializer,e as calendarReducer};
|
|
2
|
-
//# sourceMappingURL=calendarReducer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calendarReducer.js","sources":["../../../../../src/components/datepicker/internal/calendarReducer.ts"],"sourcesContent":["import type { Reducer } from \"react\";\n\nexport type CalendarAction =\n | {\n type: \"SET_SELECTED_DATE\";\n newDate: Date;\n }\n | {\n type: \"SET_OFFSET\";\n newOffset: number;\n }\n | {\n type: \"ADD_OFFSET\";\n addedOffset: number;\n };\n\nexport type CalendarState = {\n selectedDate: Date;\n offset: number;\n shownDate: Date;\n};\n\nexport const calendarReducer: Reducer<CalendarState, CalendarAction> = (\n currentState,\n action,\n) => {\n let shownDate: Date;\n\n switch (action.type) {\n case \"SET_OFFSET\":\n shownDate = new Date(currentState.selectedDate);\n shownDate.setMonth(\n currentState.selectedDate.getMonth() + action.newOffset,\n );\n\n return {\n ...currentState,\n offset: action.newOffset,\n shownDate,\n };\n\n case \"ADD_OFFSET\":\n shownDate = new Date(currentState.selectedDate);\n shownDate.setMonth(\n currentState.selectedDate.getMonth() +\n currentState.offset +\n action.addedOffset,\n );\n\n return {\n ...currentState,\n offset: currentState.offset + action.addedOffset,\n shownDate,\n };\n\n case \"SET_SELECTED_DATE\":\n return calendarInitializer(action.newDate);\n\n default:\n return currentState;\n }\n};\n\nexport const calendarInitializer = (initialDate: Date): CalendarState => ({\n selectedDate: initialDate,\n offset: 0,\n shownDate: initialDate,\n});\n"],"names":["calendarReducer","currentState","action","shownDate","type","Date","selectedDate","setMonth","getMonth","newOffset","offset","addedOffset","calendarInitializer","newDate","initialDate"],"mappings":"AAsBO,MAAMA,EAA0D,CACnEC,EACAC,KAEA,IAAIC,EAEJ,OAAQD,EAAOE,MACX,IAAK,aACD,OAAAD,EAAY,IAAIE,KAAKJ,EAAaK,cAClCH,EAAUI,SACNN,EAAaK,aAAaE,WAAaN,EAAOO,WAG3C,IACAR,EACHS,OAAQR,EAAOO,UACfN,UAAAA,GAGR,IAAK,aACD,OAAAA,EAAY,IAAIE,KAAKJ,EAAaK,cAClCH,EAAUI,SACNN,EAAaK,aAAaE,WACtBP,EAAaS,OACbR,EAAOS,aAGR,IACAV,EACHS,OAAQT,EAAaS,OAASR,EAAOS,YACrCR,UAAAA,GAGR,IAAK,oBACD,OAAOS,EAAoBV,EAAOW,SAEtC,QACI,OAAOZ,IAINW,EAAuBE,IAAAA,CAChCR,aAAcQ,EACdJ,OAAQ,EACRP,UAAWW"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { CalendarMonth, DateInfo } from './utils.js';
|
|
3
|
-
type GetDateProps = {
|
|
4
|
-
onClick?: React.MouseEventHandler;
|
|
5
|
-
dateObj: DateInfo;
|
|
6
|
-
};
|
|
7
|
-
type GetDatePropsResult = {
|
|
8
|
-
onClick: React.MouseEventHandler;
|
|
9
|
-
disabled: boolean;
|
|
10
|
-
"aria-pressed": boolean;
|
|
11
|
-
role: "button";
|
|
12
|
-
};
|
|
13
|
-
type GetBackProps = {
|
|
14
|
-
onClick?: React.MouseEventHandler;
|
|
15
|
-
offset?: number;
|
|
16
|
-
calendars: CalendarMonth[];
|
|
17
|
-
};
|
|
18
|
-
type GetBackPropsResult = {
|
|
19
|
-
onClick: React.MouseEventHandler;
|
|
20
|
-
disabled: boolean;
|
|
21
|
-
"aria-label": string;
|
|
22
|
-
title: string;
|
|
23
|
-
};
|
|
24
|
-
type GetForwardProps = {
|
|
25
|
-
onClick?: React.MouseEventHandler;
|
|
26
|
-
offset?: number;
|
|
27
|
-
calendars: CalendarMonth[];
|
|
28
|
-
};
|
|
29
|
-
type GetForwardPropsResult = {
|
|
30
|
-
onClick: React.MouseEventHandler;
|
|
31
|
-
disabled: boolean;
|
|
32
|
-
"aria-label": string;
|
|
33
|
-
title: string;
|
|
34
|
-
};
|
|
35
|
-
export interface UseCalendarProps {
|
|
36
|
-
date?: Date;
|
|
37
|
-
maxDate?: Date;
|
|
38
|
-
minDate?: Date;
|
|
39
|
-
monthsToDisplay?: number;
|
|
40
|
-
firstDayOfWeek?: number;
|
|
41
|
-
showOutsideDays?: boolean;
|
|
42
|
-
offset: number;
|
|
43
|
-
onDateSelected: (dateObj: DateInfo, event: React.MouseEvent) => void;
|
|
44
|
-
onOffsetChanged: (newOffset: number) => void;
|
|
45
|
-
selected?: Date | Date[];
|
|
46
|
-
}
|
|
47
|
-
export type GetDatePropsFunc = (props: GetDateProps) => GetDatePropsResult;
|
|
48
|
-
export type GetBackPropsFunc = (props: GetBackProps) => GetBackPropsResult;
|
|
49
|
-
export type GetForwardPropsFunc = (props: GetForwardProps) => GetForwardPropsResult;
|
|
50
|
-
export type HandleOffsetFunc = (newOffset: number) => void;
|
|
51
|
-
export type UseCalendarResult = {
|
|
52
|
-
calendars: CalendarMonth[];
|
|
53
|
-
getDateProps: GetDatePropsFunc;
|
|
54
|
-
getBackProps: GetBackPropsFunc;
|
|
55
|
-
getForwardProps: GetForwardPropsFunc;
|
|
56
|
-
handleOffsetChanged: HandleOffsetFunc;
|
|
57
|
-
};
|
|
58
|
-
export declare function useCalendar({ date, maxDate, minDate, monthsToDisplay, firstDayOfWeek, showOutsideDays, offset, onDateSelected, onOffsetChanged, selected, }: UseCalendarProps): UseCalendarResult;
|
|
59
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{h as e,d as a,b as t,j as n,i as s,s as o,c as f}from"../../../../utils-C5AH4j8B.js";import{useState as l}from"react";function d(e){return void 0!==e}function i(e,{onClick:a,dateObj:t}){return{onClick:n(a,a=>{e(t,a)}),disabled:!t.selectable,"aria-pressed":t.selected,role:"button"}}function r({minDate:e,offsetMonth:a,handleOffsetChanged:t},{onClick:f,offset:l=1,calendars:d}){const i=`Gå tilbake ${l} måned${1===l?"":"er"}`;return{onClick:n(f,()=>{t(a-o({calendars:d,offset:l,minDate:e}))}),disabled:s({calendars:d,minDate:e}),"aria-label":i,title:i}}function c({maxDate:e,offsetMonth:a,handleOffsetChanged:s},{onClick:o,offset:l=1,calendars:d}){const i=`Gå frem ${l} måned${1===l?"":"er"}`;return{onClick:n(o,()=>{s(a+f({calendars:d,offset:l,maxDate:e}))}),disabled:t({calendars:d,maxDate:e}),"aria-label":i,title:i}}function u({date:t=a().startOf("day").toDate(),maxDate:n,minDate:s,monthsToDisplay:o=1,firstDayOfWeek:f=0,showOutsideDays:u=!0,offset:m,onDateSelected:D,onOffsetChanged:h,selected:b}){const[C,O]=l(0),k=function(e,a){return d(e)?e:a}(m,C);function g(e){d(m)||O(e),h(e)}return{calendars:e({date:t,selected:b,monthsToDisplay:o,minDate:s,maxDate:n,offset:k,firstDayOfWeek:f,showOutsideDays:u}),getDateProps:i.bind(null,D),getBackProps:r.bind(null,{minDate:s,offsetMonth:k,handleOffsetChanged:g}),getForwardProps:c.bind(null,{maxDate:n,offsetMonth:k,handleOffsetChanged:g}),handleOffsetChanged:g}}export{u as useCalendar};
|
|
2
|
-
//# sourceMappingURL=useCalendar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCalendar.js","sources":["../../../../../src/components/datepicker/internal/useCalendar.ts"],"sourcesContent":["import dayjs from \"dayjs\";\n/***\n * MIT License\n *\n * Copyright (c) 2017 Deseret Digital Media. 2022 Fremtind Forsikring AS.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport React, { useState } from \"react\";\nimport {\n type CalendarMonth,\n type DateInfo,\n addMonth,\n composeEventHandlers,\n getCalendars,\n isBackDisabled,\n isForwardDisabled,\n subtractMonth,\n} from \"./utils.js\";\n\nfunction isOffsetControlled(propOffset: number | undefined): boolean {\n return propOffset !== undefined;\n}\n\nfunction getOffset(prop: number, state: number): number {\n return isOffsetControlled(prop) ? prop : state;\n}\n\ntype BoundGetDateProps = (dateInfo: DateInfo, event: React.MouseEvent) => void;\n\ntype GetDateProps = {\n onClick?: React.MouseEventHandler;\n dateObj: DateInfo;\n};\n\ntype GetDatePropsResult = {\n onClick: React.MouseEventHandler;\n disabled: boolean;\n \"aria-pressed\": boolean;\n role: \"button\";\n};\n\nfunction getDateProps(\n onDateSelected: BoundGetDateProps,\n { onClick, dateObj }: GetDateProps,\n): GetDatePropsResult {\n return {\n onClick: composeEventHandlers(onClick, (event) => {\n onDateSelected(dateObj, event);\n }),\n disabled: !dateObj.selectable,\n \"aria-pressed\": dateObj.selected,\n role: \"button\",\n };\n}\n\ntype BoundGetBackProps = {\n handleOffsetChanged: (newOffset: number) => void;\n offsetMonth: number;\n minDate?: Date;\n};\n\ntype GetBackProps = {\n onClick?: React.MouseEventHandler;\n offset?: number;\n calendars: CalendarMonth[];\n};\n\ntype GetBackPropsResult = {\n onClick: React.MouseEventHandler;\n disabled: boolean;\n \"aria-label\": string;\n title: string;\n};\n\nfunction getBackProps(\n { minDate, offsetMonth, handleOffsetChanged }: BoundGetBackProps,\n { onClick, offset = 1, calendars }: GetBackProps,\n): GetBackPropsResult {\n const label = `Gå tilbake ${offset} måned${offset === 1 ? \"\" : \"er\"}`;\n return {\n onClick: composeEventHandlers(onClick, () => {\n handleOffsetChanged(\n offsetMonth - subtractMonth({ calendars, offset, minDate }),\n );\n }),\n disabled: isBackDisabled({ calendars, minDate }),\n \"aria-label\": label,\n title: label,\n };\n}\n\ntype BoundGetForwardProps = {\n handleOffsetChanged: (newOffset: number) => void;\n offsetMonth: number;\n maxDate?: Date;\n};\n\ntype GetForwardProps = {\n onClick?: React.MouseEventHandler;\n offset?: number;\n calendars: CalendarMonth[];\n};\n\ntype GetForwardPropsResult = {\n onClick: React.MouseEventHandler;\n disabled: boolean;\n \"aria-label\": string;\n title: string;\n};\n\nfunction getForwardProps(\n { maxDate, offsetMonth, handleOffsetChanged }: BoundGetForwardProps,\n { onClick, offset = 1, calendars }: GetForwardProps,\n): GetForwardPropsResult {\n const label = `Gå frem ${offset} måned${offset === 1 ? \"\" : \"er\"}`;\n return {\n onClick: composeEventHandlers(onClick, () => {\n handleOffsetChanged(\n offsetMonth + addMonth({ calendars, offset, maxDate }),\n );\n }),\n disabled: isForwardDisabled({ calendars, maxDate }),\n \"aria-label\": label,\n title: label,\n };\n}\n\nexport interface UseCalendarProps {\n date?: Date;\n maxDate?: Date;\n minDate?: Date;\n monthsToDisplay?: number;\n firstDayOfWeek?: number;\n showOutsideDays?: boolean;\n offset: number;\n onDateSelected: (dateObj: DateInfo, event: React.MouseEvent) => void;\n onOffsetChanged: (newOffset: number) => void;\n selected?: Date | Date[];\n}\n\nexport type GetDatePropsFunc = (props: GetDateProps) => GetDatePropsResult;\nexport type GetBackPropsFunc = (props: GetBackProps) => GetBackPropsResult;\nexport type GetForwardPropsFunc = (\n props: GetForwardProps,\n) => GetForwardPropsResult;\nexport type HandleOffsetFunc = (newOffset: number) => void;\n\nexport type UseCalendarResult = {\n calendars: CalendarMonth[];\n getDateProps: GetDatePropsFunc;\n getBackProps: GetBackPropsFunc;\n getForwardProps: GetForwardPropsFunc;\n handleOffsetChanged: HandleOffsetFunc;\n};\n\nexport function useCalendar({\n date = dayjs().startOf(\"day\").toDate(),\n maxDate,\n minDate,\n monthsToDisplay = 1,\n firstDayOfWeek = 0,\n showOutsideDays = true,\n offset,\n onDateSelected,\n onOffsetChanged,\n selected,\n}: UseCalendarProps): UseCalendarResult {\n const [stateOffset, setStateOffset] = useState(0);\n const offsetMonth = getOffset(offset, stateOffset);\n\n function handleOffsetChanged(newOffset: number) {\n if (!isOffsetControlled(offset)) {\n setStateOffset(newOffset);\n }\n onOffsetChanged(newOffset);\n }\n\n const calendars = getCalendars({\n date,\n selected,\n monthsToDisplay,\n minDate,\n maxDate,\n offset: offsetMonth,\n firstDayOfWeek,\n showOutsideDays,\n });\n return {\n calendars,\n getDateProps: getDateProps.bind(null, onDateSelected),\n getBackProps: getBackProps.bind(null, {\n minDate,\n offsetMonth,\n handleOffsetChanged,\n }),\n getForwardProps: getForwardProps.bind(null, {\n maxDate,\n offsetMonth,\n handleOffsetChanged,\n }),\n handleOffsetChanged,\n };\n}\n"],"names":["isOffsetControlled","propOffset","getDateProps","onDateSelected","onClick","dateObj","composeEventHandlers","event","disabled","selectable","selected","role","getBackProps","minDate","offsetMonth","handleOffsetChanged","offset","calendars","label","subtractMonth","isBackDisabled","title","getForwardProps","maxDate","addMonth","isForwardDisabled","useCalendar","date","dayjs","startOf","toDate","monthsToDisplay","firstDayOfWeek","showOutsideDays","onOffsetChanged","stateOffset","setStateOffset","useState","prop","state","getOffset","newOffset","getCalendars","bind"],"mappings":"6HAoCA,SAASA,EAAmBC,GACxB,YAAsB,IAAfA,CACX,CAoBA,SAASC,EACLC,GACEC,QAAAA,EAASC,QAAAA,IAEX,MAAO,CACHD,QAASE,EAAqBF,EAAUG,IACpCJ,EAAeE,EAASE,KAE5BC,UAAWH,EAAQI,WACnB,eAAgBJ,EAAQK,SACxBC,KAAM,SAEd,CAqBA,SAASC,GACHC,QAAAA,EAASC,YAAAA,EAAaC,oBAAAA,IACtBX,QAAAA,EAASY,OAAAA,EAAS,EAAGC,UAAAA,IAEvB,MAAMC,EAAQ,cAAcF,UAA0B,IAAXA,EAAe,GAAK,OAC/D,MAAO,CACHZ,QAASE,EAAqBF,EAAS,KACnCW,EACID,EAAcK,EAAc,CAAEF,UAAAA,EAAWD,OAAAA,EAAQH,QAAAA,OAGzDL,SAAUY,EAAe,CAAEH,UAAAA,EAAWJ,QAAAA,IACtC,aAAcK,EACdG,MAAOH,EAEf,CAqBA,SAASI,GACHC,QAAAA,EAAST,YAAAA,EAAaC,oBAAAA,IACtBX,QAAAA,EAASY,OAAAA,EAAS,EAAGC,UAAAA,IAEvB,MAAMC,EAAQ,WAAWF,UAA0B,IAAXA,EAAe,GAAK,OAC5D,MAAO,CACHZ,QAASE,EAAqBF,EAAS,KACnCW,EACID,EAAcU,EAAS,CAAEP,UAAAA,EAAWD,OAAAA,EAAQO,QAAAA,OAGpDf,SAAUiB,EAAkB,CAAER,UAAAA,EAAWM,QAAAA,IACzC,aAAcL,EACdG,MAAOH,EAEf,CA8BO,SAASQ,GACZC,KAAAA,EAAOC,IAAQC,QAAQ,OAAOC,SAC9BP,QAAAA,EACAV,QAAAA,EACAkB,gBAAAA,EAAkB,EAClBC,eAAAA,EAAiB,EACjBC,gBAAAA,GAAkB,EAClBjB,OAAAA,EACAb,eAAAA,EACA+B,gBAAAA,EACAxB,SAAAA,IAEA,MAAOyB,EAAaC,GAAkBC,EAAS,GACzCvB,EAjJV,SAAmBwB,EAAcC,GAC7B,OAAOvC,EAAmBsC,GAAQA,EAAOC,CAC7C,CA+IwBC,CAAUxB,EAAQmB,GAEtC,SAASpB,EAAoB0B,GACpBzC,EAAmBgB,IACpBoB,EAAeK,GAEnBP,EAAgBO,EACpB,CAYA,MAAO,CACHxB,UAXcyB,EAAa,CAC3Bf,KAAAA,EACAjB,SAAAA,EACAqB,gBAAAA,EACAlB,QAAAA,EACAU,QAAAA,EACAP,OAAQF,EACRkB,eAAAA,EACAC,gBAAAA,IAIA/B,aAAcA,EAAayC,KAAK,KAAMxC,GACtCS,aAAcA,EAAa+B,KAAK,KAAM,CAClC9B,QAAAA,EACAC,YAAAA,EACAC,oBAAAA,IAEJO,gBAAiBA,EAAgBqB,KAAK,KAAM,CACxCpB,QAAAA,EACAT,YAAAA,EACAC,oBAAAA,IAEJA,oBAAAA,EAER"}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { ValuePair } from '../../../utilities/valuePair.js';
|
|
3
|
-
import { YearsToShow } from '../types.js';
|
|
4
|
-
export declare function composeEventHandlers(...fns: Array<React.MouseEventHandler | undefined>): (event: React.MouseEvent) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Takes a calendars array and figures out the number of months to subtract
|
|
7
|
-
* based on the current offset and the minDate allowed.
|
|
8
|
-
* @param {Object} param The param object
|
|
9
|
-
* @param {Array} param.calendars The calendars array created by the getCalendars function
|
|
10
|
-
* @param {Number} param.offset The num of months to be subtracted
|
|
11
|
-
* @param {Date} param.minDate The earliest date we are allow to subtract back to
|
|
12
|
-
* @returns {Number} The number of months to subtract
|
|
13
|
-
*/
|
|
14
|
-
export declare function subtractMonth({ calendars, offset, minDate, }: {
|
|
15
|
-
calendars: CalendarMonth[];
|
|
16
|
-
offset: number;
|
|
17
|
-
minDate?: Date;
|
|
18
|
-
}): number;
|
|
19
|
-
export declare const DEFAULT_YEARS_TO_SHOW = 3;
|
|
20
|
-
/**
|
|
21
|
-
* Generates an array of year strings for a year selector component, with min and max dates taken into account.
|
|
22
|
-
*
|
|
23
|
-
* @param {number} currentYear - The current year to center the list around
|
|
24
|
-
* @param {Date | undefined} [minDate] - The minimum date to include in the list of years
|
|
25
|
-
* @param {Date | undefined} [maxDate] - The maximum date to include in the list of years
|
|
26
|
-
*
|
|
27
|
-
* @returns {string[]} - An array of year strings, starting from the earliest year specified by minDate or currentYear - 3, and ending at the latest year specified by maxDate or currentYear + 3
|
|
28
|
-
*/
|
|
29
|
-
export declare function getYearSelectOptions(currentYear: number, minDate: Date | undefined, maxDate: Date | undefined, yearsToShow: YearsToShow): string[];
|
|
30
|
-
/**
|
|
31
|
-
* Returns an array of months that are allowed for selection in the current year based on the minimum and maximum dates.
|
|
32
|
-
* @param {number} currentYear The current year
|
|
33
|
-
* @param {string[]} monthNames An array of strings representing the month names
|
|
34
|
-
* @param {Date | undefined} minDate The minimum date that is allowed for selection
|
|
35
|
-
* @param {Date | undefined} maxDate The maximum date that is allowed for selection
|
|
36
|
-
* @returns {ValuePair[]} An array of ValuePairs representing the months that are allowed for selection in the current year
|
|
37
|
-
*/
|
|
38
|
-
export declare function getMonthSelectOptions(currentYear: number, monthNames: string[], minDate: Date | undefined, maxDate: Date | undefined): ValuePair[];
|
|
39
|
-
/**s
|
|
40
|
-
* Takes a calendars array and figures out the number of months to add
|
|
41
|
-
* based on the current offset and the maxDate allowed.
|
|
42
|
-
* @param {Object} param The param object
|
|
43
|
-
* @param {Array} param.calendars The calendars array created by the getCalendars function
|
|
44
|
-
* @param {Number} param.offset The num of months to be added
|
|
45
|
-
* @param {Date} param.maxDate The furthest date we are allow to add forward to
|
|
46
|
-
* @returns {Number} The number of months to add
|
|
47
|
-
*/
|
|
48
|
-
export declare function addMonth({ calendars, offset, maxDate, }: {
|
|
49
|
-
calendars: CalendarMonth[];
|
|
50
|
-
offset: number;
|
|
51
|
-
maxDate?: Date;
|
|
52
|
-
}): number;
|
|
53
|
-
/**
|
|
54
|
-
* Takes a calendars array and figures out if the back button should be
|
|
55
|
-
* disabled based on the minDate allowed.
|
|
56
|
-
* @param {Object} param The param object
|
|
57
|
-
* @param {Array} param.calendars The calendars array created by the getCalendars function
|
|
58
|
-
* @param {Date} param.minDate The earliest date available
|
|
59
|
-
* @returns {Boolean} Whether the back button should be disabled.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isBackDisabled({ calendars, minDate, }: {
|
|
62
|
-
calendars: CalendarMonth[];
|
|
63
|
-
minDate?: Date;
|
|
64
|
-
}): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Takes a calendars array and figures out if the forward button should be
|
|
67
|
-
* disabled based on the maxDate allowed.
|
|
68
|
-
* @param {Object} param The param object
|
|
69
|
-
* @param {Array} param.calendars The calendars array created by the getCalendars function
|
|
70
|
-
* @param {Date} param.maxDate The furthest date available
|
|
71
|
-
* @returns {Boolean} Whether the forward button should be disabled.
|
|
72
|
-
*/
|
|
73
|
-
export declare function isForwardDisabled({ calendars, maxDate, }: {
|
|
74
|
-
calendars: CalendarMonth[];
|
|
75
|
-
maxDate?: Date;
|
|
76
|
-
}): boolean;
|
|
77
|
-
type GetCalendarProps = {
|
|
78
|
-
/** The date to start the calendar at */
|
|
79
|
-
date: Date;
|
|
80
|
-
/** Date or dates currently selected. */
|
|
81
|
-
selected?: Date | Date[];
|
|
82
|
-
/** The earliest date available */
|
|
83
|
-
minDate?: Date;
|
|
84
|
-
/** The earliest date available */
|
|
85
|
-
maxDate?: Date;
|
|
86
|
-
/** The number of months to return in the calendar view */
|
|
87
|
-
monthsToDisplay: number;
|
|
88
|
-
/** The number of months to offset based off the param.date given */
|
|
89
|
-
offset: number;
|
|
90
|
-
/** First day of week, 0-6 (Sunday to Saturday) */
|
|
91
|
-
firstDayOfWeek: number;
|
|
92
|
-
/** Flag to fill front and back weeks with dates from adjacent months */
|
|
93
|
-
showOutsideDays: boolean;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Figures out the months data needed based off the number of monthsToDisplay
|
|
97
|
-
* and other options provided.
|
|
98
|
-
* @param {Object} param The param object
|
|
99
|
-
* @param {Date} param.date The date to start the calendar at
|
|
100
|
-
* @param {Array.<Date>} param.selected An array of dates currently selected
|
|
101
|
-
* @param {Number} param.monthsToDisplay The number of months to return in the calendar view
|
|
102
|
-
* @param {Number} param.offset The number of months to offset based off the param.date given
|
|
103
|
-
* @param {Date} param.minDate The earliest date available
|
|
104
|
-
* @param {Date} param.maxDate The furthest date available
|
|
105
|
-
* @param {Number} param.firstDayOfWeek First day of week, 0-6 (Sunday to Saturday)
|
|
106
|
-
* @param {Bool} param.showOutsideDays Flag to fill front and back weeks with dates from adjacent months
|
|
107
|
-
* @returns {Array.<Object>} An array of objects with month data
|
|
108
|
-
*/
|
|
109
|
-
export declare function getCalendars({ date, selected, monthsToDisplay, offset, minDate, maxDate, firstDayOfWeek, showOutsideDays, }: GetCalendarProps): CalendarMonth[];
|
|
110
|
-
export type CalendarMonth = {
|
|
111
|
-
firstDayOfMonth: Date;
|
|
112
|
-
lastDayOfMonth: Date;
|
|
113
|
-
month: number;
|
|
114
|
-
year: number;
|
|
115
|
-
weeks: CalendarWeek[];
|
|
116
|
-
};
|
|
117
|
-
export type CalendarWeek = CalendarDay[];
|
|
118
|
-
export type CalendarDay = DateInfo | string;
|
|
119
|
-
export type DateInfo = {
|
|
120
|
-
date: Date;
|
|
121
|
-
selected: boolean;
|
|
122
|
-
selectable: boolean;
|
|
123
|
-
today: boolean;
|
|
124
|
-
prevMonth: boolean;
|
|
125
|
-
nextMonth: boolean;
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Check if two Date objects represent the same day
|
|
129
|
-
*
|
|
130
|
-
* @param date1 first Date to compare
|
|
131
|
-
* @param date2 second Date to compare
|
|
132
|
-
*/
|
|
133
|
-
export declare function isSameDay(date1: Date, date2: Date): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* Check if the date has changed from the previous date
|
|
136
|
-
*
|
|
137
|
-
* @param date First date to compare
|
|
138
|
-
* @param newDate Second date to compare
|
|
139
|
-
*/
|
|
140
|
-
export declare function dateHasChanged(date: Date | undefined, newDate: Date): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Check if a given date is outside a given range
|
|
143
|
-
*
|
|
144
|
-
* @param date Input date
|
|
145
|
-
* @param rangeStart Dates before this date should be disabled
|
|
146
|
-
* @param rangeEnd Dates after this date should be disabled
|
|
147
|
-
*/
|
|
148
|
-
export declare function dateIsOutsideRange(date: Date, rangeStart: Date | undefined, rangeEnd: Date | undefined): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Get the correct initial date for initiating the datepicker reducer store
|
|
151
|
-
*
|
|
152
|
-
* @param value Value from props
|
|
153
|
-
* @param initialDate Initial date from porps
|
|
154
|
-
* @param disableDate Function for checking whether the date should be disabled
|
|
155
|
-
*/
|
|
156
|
-
export declare function getInitialDate(value: string | undefined, defaultValue: string | undefined, minDate: Date | undefined, maxDate: Date | undefined): Date | null;
|
|
157
|
-
/**
|
|
158
|
-
* Get the initial date to show in the calendar
|
|
159
|
-
*
|
|
160
|
-
* @param date The date set in the DatePicker (from props)
|
|
161
|
-
* @param defaultSelected The defaultSelected prop from DatePicker
|
|
162
|
-
* @param minDate The earliest selectable date, from props
|
|
163
|
-
* @param maxDate The latest selectable date, from props
|
|
164
|
-
* @returns The date to show in the calendar
|
|
165
|
-
*/
|
|
166
|
-
export declare function getInitialDateShown(date: Date | null, defaultSelected: Date | undefined, minDate: Date | undefined, maxDate: Date | undefined): Date;
|
|
167
|
-
export {};
|