@fremtind/jokul 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/build/NativeSelect-CNcZmpDZ.cjs +2 -0
- package/build/{NativeSelect-DSmX3GZo.cjs.map → NativeSelect-CNcZmpDZ.cjs.map} +1 -1
- package/build/NativeSelect-CfNZEQF0.js +2 -0
- package/build/{NativeSelect-EidDABsT.js.map → NativeSelect-CfNZEQF0.js.map} +1 -1
- package/build/build-stats.html +1 -1
- package/build/cjs/components/datepicker/DatePicker.js +1 -1
- package/build/cjs/components/datepicker/DatePicker.js.map +1 -1
- package/build/cjs/components/datepicker/internal/Calendar.js +1 -1
- package/build/cjs/components/datepicker/internal/Calendar.js.map +1 -1
- package/build/cjs/components/feedback/Feedback.js +2 -0
- package/build/cjs/components/feedback/Feedback.js.map +1 -0
- package/build/cjs/components/feedback/FeedbackSuccess.js +2 -0
- package/build/cjs/components/feedback/FeedbackSuccess.js.map +1 -0
- package/build/cjs/components/feedback/FeedbackValues.js +2 -0
- package/build/cjs/components/feedback/FeedbackValues.js.map +1 -0
- package/build/cjs/components/feedback/feedbackContext.js +2 -0
- package/build/cjs/components/feedback/feedbackContext.js.map +1 -0
- package/build/cjs/components/feedback/followup/Followup.js +2 -0
- package/build/cjs/components/feedback/followup/Followup.js.map +1 -0
- package/build/cjs/components/feedback/followup/followupContext.js +2 -0
- package/build/cjs/components/feedback/followup/followupContext.js.map +1 -0
- package/build/cjs/components/feedback/followup/useFollowup.js +2 -0
- package/build/cjs/components/feedback/followup/useFollowup.js.map +1 -0
- package/build/cjs/components/feedback/index.js +2 -0
- package/build/cjs/components/feedback/index.js.map +1 -0
- package/build/cjs/components/feedback/main-question/MainQuestion.js +2 -0
- package/build/cjs/components/feedback/main-question/MainQuestion.js.map +1 -0
- package/build/cjs/components/feedback/main-question/mainQuestionContext.js +2 -0
- package/build/cjs/components/feedback/main-question/mainQuestionContext.js.map +1 -0
- package/build/cjs/components/feedback/main-question/useMainQuestion.js +2 -0
- package/build/cjs/components/feedback/main-question/useMainQuestion.js.map +1 -0
- package/build/cjs/components/feedback/presets.js +2 -0
- package/build/cjs/components/feedback/presets.js.map +1 -0
- package/build/cjs/components/feedback/questions/AddonQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/AddonQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/CheckboxQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/CheckboxQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/ContactQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/ContactQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/RadioQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/RadioQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/SmileyQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/SmileyQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/TextQuestion.js +2 -0
- package/build/cjs/components/feedback/questions/TextQuestion.js.map +1 -0
- package/build/cjs/components/feedback/questions/index.js +2 -0
- package/build/cjs/components/feedback/questions/index.js.map +1 -0
- package/build/cjs/components/feedback/questions/smileyUtils.js +2 -0
- package/build/cjs/components/feedback/questions/smileyUtils.js.map +1 -0
- package/build/cjs/components/feedback/types.js +2 -0
- package/build/cjs/components/feedback/types.js.map +1 -0
- package/build/cjs/components/feedback/utils.js +2 -0
- package/build/cjs/components/feedback/utils.js.map +1 -0
- package/build/cjs/components/index.js +1 -1
- package/build/cjs/components/message/DismissButton.js +2 -0
- package/build/cjs/components/message/DismissButton.js.map +1 -0
- package/build/cjs/components/message/FormErrorMessage.js +2 -0
- package/build/cjs/components/message/FormErrorMessage.js.map +1 -0
- package/build/cjs/components/message/Message.js +2 -0
- package/build/cjs/components/message/Message.js.map +1 -0
- package/build/cjs/components/message/index.js +2 -0
- package/build/cjs/components/message/index.js.map +1 -0
- package/build/cjs/components/popover/Popover.js +2 -0
- package/build/cjs/components/popover/Popover.js.map +1 -0
- package/build/cjs/components/popover/index.js +2 -0
- package/build/cjs/components/popover/index.js.map +1 -0
- package/build/cjs/components/popover/utils.js +2 -0
- package/build/cjs/components/popover/utils.js.map +1 -0
- package/build/cjs/components/select/NativeSelect.js +1 -1
- package/build/cjs/components/select/Select.js +1 -1
- package/build/cjs/components/select/index.js +1 -1
- package/build/cjs/components/text-input/BaseTextInput.js +1 -1
- package/build/cjs/components/text-input/BaseTextInput.js.map +1 -1
- package/build/cjs/components/text-input/TextArea.js +1 -1
- package/build/cjs/components/text-input/TextArea.js.map +1 -1
- package/build/cjs/components/text-input/TextInput.js +1 -1
- package/build/cjs/components/text-input/TextInput.js.map +1 -1
- package/build/cjs/components/tooltip/TooltipContent.js +1 -1
- package/build/cjs/components/tooltip/TooltipContent.js.map +1 -1
- package/build/cjs/index.js +1 -1
- package/build/cjs/utilities/index.js +1 -1
- package/build/cjs/utilities/validators/hasMinimumWords/hasMinimumWords.js +2 -0
- package/build/cjs/utilities/validators/hasMinimumWords/hasMinimumWords.js.map +1 -0
- package/build/cjs/utilities/validators/hasNoIllegalCharacters/hasNoIllegalCharacters.js +2 -0
- package/build/cjs/utilities/validators/hasNoIllegalCharacters/hasNoIllegalCharacters.js.map +1 -0
- package/build/cjs/utilities/validators/index.js +2 -0
- package/build/cjs/utilities/validators/index.js.map +1 -0
- package/build/cjs/utilities/validators/isExactLength/isExactLength.js +2 -0
- package/build/cjs/utilities/validators/isExactLength/isExactLength.js.map +1 -0
- package/build/cjs/utilities/validators/isInteger/isInteger.js +2 -0
- package/build/cjs/utilities/validators/isInteger/isInteger.js.map +1 -0
- package/build/cjs/utilities/validators/isValidChassisnummer/isValidChassisnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidChassisnummer/isValidChassisnummer.js.map +1 -0
- package/build/cjs/utilities/validators/isValidDogId/isValidDogId.js +2 -0
- package/build/cjs/utilities/validators/isValidDogId/isValidDogId.js.map +1 -0
- package/build/cjs/utilities/validators/isValidEpost/isValidEpost.js +2 -0
- package/build/cjs/utilities/validators/isValidEpost/isValidEpost.js.map +1 -0
- package/build/cjs/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.js.map +1 -0
- package/build/cjs/utilities/validators/isValidKortnummer/isValidKortnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidKortnummer/isValidKortnummer.js.map +1 -0
- package/build/cjs/utilities/validators/isValidName/isValidName.js +2 -0
- package/build/cjs/utilities/validators/isValidName/isValidName.js.map +1 -0
- package/build/cjs/utilities/validators/isValidOrganisasjonsnummer/isValidOrganisasjonsnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidOrganisasjonsnummer/isValidOrganisasjonsnummer.js.map +1 -0
- package/build/cjs/utilities/validators/isValidRegistreringsnummer/isValidRegistreringsnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidRegistreringsnummer/isValidRegistreringsnummer.js.map +1 -0
- package/build/cjs/utilities/validators/isValidTelefonnummer/isValidTelefonnummer.js +2 -0
- package/build/cjs/utilities/validators/isValidTelefonnummer/isValidTelefonnummer.js.map +1 -0
- package/build/components/feedback/Feedback.d.ts +42 -0
- package/build/components/feedback/FeedbackSuccess.d.ts +3 -0
- package/build/components/feedback/FeedbackValues.d.ts +6 -0
- package/build/components/feedback/feedbackContext.d.ts +19 -0
- package/build/components/feedback/followup/Followup.d.ts +14 -0
- package/build/components/feedback/followup/followupContext.d.ts +9 -0
- package/build/components/feedback/followup/useFollowup.d.ts +19 -0
- package/build/components/feedback/index.d.ts +3 -0
- package/build/components/feedback/main-question/MainQuestion.d.ts +16 -0
- package/build/components/feedback/main-question/mainQuestionContext.d.ts +9 -0
- package/build/components/feedback/main-question/useMainQuestion.d.ts +13 -0
- package/build/components/feedback/presets.d.ts +6 -0
- package/build/components/feedback/questions/AddonQuestion.d.ts +7 -0
- package/build/components/feedback/questions/CheckboxQuestion.d.ts +3 -0
- package/build/components/feedback/questions/ContactQuestion.d.ts +28 -0
- package/build/components/feedback/questions/RadioQuestion.d.ts +3 -0
- package/build/components/feedback/questions/SmileyQuestion.d.ts +3 -0
- package/build/components/feedback/questions/TextQuestion.d.ts +3 -0
- package/build/components/feedback/questions/index.d.ts +6 -0
- package/build/components/feedback/questions/smileyUtils.d.ts +4 -0
- package/build/components/feedback/types.d.ts +86 -0
- package/build/components/feedback/utils.d.ts +4 -0
- package/build/components/index.d.ts +3 -0
- package/build/components/message/DismissButton.d.ts +5 -0
- package/build/components/message/FormErrorMessage.d.ts +14 -0
- package/build/components/message/Message.d.ts +19 -0
- package/build/components/message/index.d.ts +2 -0
- package/build/components/popover/Popover.d.ts +114 -0
- package/build/components/popover/index.d.ts +1 -0
- package/build/components/popover/utils.d.ts +4 -0
- package/build/es/components/datepicker/DatePicker.js +1 -1
- package/build/es/components/datepicker/DatePicker.js.map +1 -1
- package/build/es/components/datepicker/internal/Calendar.js +1 -1
- package/build/es/components/datepicker/internal/Calendar.js.map +1 -1
- package/build/es/components/feedback/Feedback.js +2 -0
- package/build/es/components/feedback/Feedback.js.map +1 -0
- package/build/es/components/feedback/FeedbackSuccess.js +2 -0
- package/build/es/components/feedback/FeedbackSuccess.js.map +1 -0
- package/build/es/components/feedback/FeedbackValues.js +2 -0
- package/build/es/components/feedback/FeedbackValues.js.map +1 -0
- package/build/es/components/feedback/feedbackContext.js +2 -0
- package/build/es/components/feedback/feedbackContext.js.map +1 -0
- package/build/es/components/feedback/followup/Followup.js +2 -0
- package/build/es/components/feedback/followup/Followup.js.map +1 -0
- package/build/es/components/feedback/followup/followupContext.js +2 -0
- package/build/es/components/feedback/followup/followupContext.js.map +1 -0
- package/build/es/components/feedback/followup/useFollowup.js +2 -0
- package/build/es/components/feedback/followup/useFollowup.js.map +1 -0
- package/build/es/components/feedback/index.js +2 -0
- package/build/es/components/feedback/index.js.map +1 -0
- package/build/es/components/feedback/main-question/MainQuestion.js +2 -0
- package/build/es/components/feedback/main-question/MainQuestion.js.map +1 -0
- package/build/es/components/feedback/main-question/mainQuestionContext.js +2 -0
- package/build/es/components/feedback/main-question/mainQuestionContext.js.map +1 -0
- package/build/es/components/feedback/main-question/useMainQuestion.js +2 -0
- package/build/es/components/feedback/main-question/useMainQuestion.js.map +1 -0
- package/build/es/components/feedback/presets.js +2 -0
- package/build/es/components/feedback/presets.js.map +1 -0
- package/build/es/components/feedback/questions/AddonQuestion.js +2 -0
- package/build/es/components/feedback/questions/AddonQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/CheckboxQuestion.js +2 -0
- package/build/es/components/feedback/questions/CheckboxQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/ContactQuestion.js +2 -0
- package/build/es/components/feedback/questions/ContactQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/RadioQuestion.js +2 -0
- package/build/es/components/feedback/questions/RadioQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/SmileyQuestion.js +2 -0
- package/build/es/components/feedback/questions/SmileyQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/TextQuestion.js +2 -0
- package/build/es/components/feedback/questions/TextQuestion.js.map +1 -0
- package/build/es/components/feedback/questions/index.js +2 -0
- package/build/es/components/feedback/questions/index.js.map +1 -0
- package/build/es/components/feedback/questions/smileyUtils.js +2 -0
- package/build/es/components/feedback/questions/smileyUtils.js.map +1 -0
- package/build/es/components/feedback/types.js +2 -0
- package/build/es/components/feedback/types.js.map +1 -0
- package/build/es/components/feedback/utils.js +2 -0
- package/build/es/components/feedback/utils.js.map +1 -0
- package/build/es/components/index.js +1 -1
- package/build/es/components/message/DismissButton.js +2 -0
- package/build/es/components/message/DismissButton.js.map +1 -0
- package/build/es/components/message/FormErrorMessage.js +2 -0
- package/build/es/components/message/FormErrorMessage.js.map +1 -0
- package/build/es/components/message/Message.js +2 -0
- package/build/es/components/message/Message.js.map +1 -0
- package/build/es/components/message/index.js +2 -0
- package/build/es/components/message/index.js.map +1 -0
- package/build/es/components/popover/Popover.js +2 -0
- package/build/es/components/popover/Popover.js.map +1 -0
- package/build/es/components/popover/index.js +2 -0
- package/build/es/components/popover/index.js.map +1 -0
- package/build/es/components/popover/utils.js +2 -0
- package/build/es/components/popover/utils.js.map +1 -0
- package/build/es/components/select/NativeSelect.js +1 -1
- package/build/es/components/select/Select.js +1 -1
- package/build/es/components/select/index.js +1 -1
- package/build/es/components/text-input/BaseTextInput.js +1 -1
- package/build/es/components/text-input/BaseTextInput.js.map +1 -1
- package/build/es/components/text-input/TextArea.js +1 -1
- package/build/es/components/text-input/TextArea.js.map +1 -1
- package/build/es/components/text-input/TextInput.js +1 -1
- package/build/es/components/text-input/TextInput.js.map +1 -1
- package/build/es/components/tooltip/TooltipContent.js +1 -1
- package/build/es/components/tooltip/TooltipContent.js.map +1 -1
- package/build/es/index.js +1 -1
- package/build/es/utilities/index.js +1 -1
- package/build/es/utilities/validators/hasMinimumWords/hasMinimumWords.js +2 -0
- package/build/es/utilities/validators/hasMinimumWords/hasMinimumWords.js.map +1 -0
- package/build/es/utilities/validators/hasNoIllegalCharacters/hasNoIllegalCharacters.js +2 -0
- package/build/es/utilities/validators/hasNoIllegalCharacters/hasNoIllegalCharacters.js.map +1 -0
- package/build/es/utilities/validators/index.js +2 -0
- package/build/es/utilities/validators/index.js.map +1 -0
- package/build/es/utilities/validators/isExactLength/isExactLength.js +2 -0
- package/build/es/utilities/validators/isExactLength/isExactLength.js.map +1 -0
- package/build/es/utilities/validators/isInteger/isInteger.js +2 -0
- package/build/es/utilities/validators/isInteger/isInteger.js.map +1 -0
- package/build/es/utilities/validators/isValidChassisnummer/isValidChassisnummer.js +2 -0
- package/build/es/utilities/validators/isValidChassisnummer/isValidChassisnummer.js.map +1 -0
- package/build/es/utilities/validators/isValidDogId/isValidDogId.js +2 -0
- package/build/es/utilities/validators/isValidDogId/isValidDogId.js.map +1 -0
- package/build/es/utilities/validators/isValidEpost/isValidEpost.js +2 -0
- package/build/es/utilities/validators/isValidEpost/isValidEpost.js.map +1 -0
- package/build/es/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.js +2 -0
- package/build/es/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.js.map +1 -0
- package/build/es/utilities/validators/isValidKortnummer/isValidKortnummer.js +2 -0
- package/build/es/utilities/validators/isValidKortnummer/isValidKortnummer.js.map +1 -0
- package/build/es/utilities/validators/isValidName/isValidName.js +2 -0
- package/build/es/utilities/validators/isValidName/isValidName.js.map +1 -0
- package/build/es/utilities/validators/isValidOrganisasjonsnummer/isValidOrganisasjonsnummer.js +2 -0
- package/build/es/utilities/validators/isValidOrganisasjonsnummer/isValidOrganisasjonsnummer.js.map +1 -0
- package/build/es/utilities/validators/isValidRegistreringsnummer/isValidRegistreringsnummer.js +2 -0
- package/build/es/utilities/validators/isValidRegistreringsnummer/isValidRegistreringsnummer.js.map +1 -0
- package/build/es/utilities/validators/isValidTelefonnummer/isValidTelefonnummer.js +2 -0
- package/build/es/utilities/validators/isValidTelefonnummer/isValidTelefonnummer.js.map +1 -0
- package/build/utilities/index.d.ts +1 -0
- package/build/utilities/validators/hasMinimumWords/hasMinimumWords.d.ts +10 -0
- package/build/utilities/validators/hasNoIllegalCharacters/hasNoIllegalCharacters.d.ts +7 -0
- package/build/utilities/validators/index.d.ts +12 -0
- package/build/utilities/validators/isExactLength/isExactLength.d.ts +7 -0
- package/build/utilities/validators/isInteger/isInteger.d.ts +7 -0
- package/build/utilities/validators/isValidChassisnummer/isValidChassisnummer.d.ts +7 -0
- package/build/utilities/validators/isValidDogId/isValidDogId.d.ts +7 -0
- package/build/utilities/validators/isValidEpost/isValidEpost.d.ts +7 -0
- package/build/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.d.ts +30 -0
- package/build/utilities/validators/isValidKortnummer/isValidKortnummer.d.ts +6 -0
- package/build/utilities/validators/isValidName/isValidName.d.ts +7 -0
- package/build/utilities/validators/isValidOrganisasjonsnummer/isValidOrganisasjonsnummer.d.ts +6 -0
- package/build/utilities/validators/isValidRegistreringsnummer/isValidRegistreringsnummer.d.ts +12 -0
- package/build/utilities/validators/isValidTelefonnummer/isValidTelefonnummer.d.ts +7 -0
- package/package.json +12 -6
- package/src/components/button/styles/button.css +4 -4
- package/src/components/button/styles/button.min.css +1 -1
- package/src/components/card/styles/card.min.css +1 -1
- package/src/components/checkbox/styles/checkbox.css +4 -4
- package/src/components/checkbox/styles/checkbox.min.css +1 -1
- package/src/components/combobox/styles/combobox.min.css +1 -1
- package/src/components/cookie-consent/styles/cookie-consent.min.css +1 -1
- package/src/components/datepicker/styles/datepicker.min.css +1 -1
- package/src/components/feedback/styles/_index.scss +1 -0
- package/src/components/feedback/styles/feedback.css +104 -0
- package/src/components/feedback/styles/feedback.min.css +1 -0
- package/src/components/feedback/styles/feedback.scss +103 -0
- package/src/components/icon/styles/icon.min.css +1 -1
- package/src/components/link/styles/link.min.css +1 -1
- package/src/components/list/styles/list.min.css +1 -1
- package/src/components/loader/styles/loader.css +6 -6
- package/src/components/loader/styles/loader.min.css +1 -1
- package/src/components/loader/styles/skeleton-loader.css +5 -5
- package/src/components/loader/styles/skeleton-loader.min.css +1 -1
- package/src/components/message/styles/_index.scss +1 -0
- package/src/components/message/styles/message.css +203 -0
- package/src/components/message/styles/message.min.css +1 -0
- package/src/components/message/styles/message.scss +180 -0
- package/src/components/popover/styles/_index.scss +1 -0
- package/src/components/popover/styles/popover.css +10 -0
- package/src/components/popover/styles/popover.min.css +1 -0
- package/src/components/popover/styles/popover.scss +9 -0
- package/src/components/radio-button/styles/radio-button.css +2 -2
- package/src/components/radio-button/styles/radio-button.min.css +1 -1
- package/src/components/select/styles/select.min.css +1 -1
- package/src/components/tag/styles/tag.min.css +1 -1
- package/src/components/text-input/styles/text-input.min.css +1 -1
- package/src/components/tooltip/styles/tooltip.min.css +1 -1
- package/src/core/styles/core.min.css +1 -1
- package/src/core/styles/vind.min.css +1 -1
- package/build/NativeSelect-DSmX3GZo.cjs +0 -2
- package/build/NativeSelect-EidDABsT.js +0 -2
- package/build/components/tooltip/Tooltip.d.ts +0 -122
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("../../../clsx-E3yX_9sL.cjs"),n=require("date-fns/startOfDay"),o=require("react"),i=require("react-dom"),s=require("../../hooks/useAnimatedHeight/useAnimatedHeight.js");require("../../hooks/useScreen/useScreen.js");const t=require("../../hooks/useClickOutside/useClickOutside.js"),a=require("../../hooks/useFocusOutside/useFocusOutside.js");require("../../hooks/useId/useId.js");const u=require("../../hooks/useKeyListener/useKeyListener.js");require("../icon/Icon.js"),require("../icon/icons/animated/ArrowVerticalAnimated.js"),require("../icon/icons/animated/ArrowHorizontalAnimated.js"),require("../icon/icons/animated/PlusRemoveAnimated.js"),require("../icon/icons/ArrowDownIcon.js"),require("../icon/icons/ArrowLeftIcon.js"),require("../icon/icons/ArrowNorthEastIcon.js"),require("../icon/icons/ArrowRightIcon.js"),require("../icon/icons/ArrowUpIcon.js");const c=require("../icon/icons/CalendarIcon.js");require("../icon/icons/CheckIcon.js"),require("../icon/icons/ChevronDownIcon.js"),require("../icon/icons/ChevronLeftIcon.js"),require("../icon/icons/ChevronRightIcon.js"),require("../icon/icons/ChevronUpIcon.js"),require("../icon/icons/CloseIcon.js"),require("../icon/icons/CopyIcon.js"),require("../icon/icons/DotsIcon.js"),require("../icon/icons/DragIcon.js"),require("../icon/icons/ErrorIcon.js"),require("../icon/icons/GreenCheckIcon.js"),require("../icon/icons/HamburgerIcon.js"),require("../icon/icons/InfoIcon.js"),require("../icon/icons/LinkIcon.js"),require("../icon/icons/PlusIcon.js"),require("../icon/icons/QuestionIcon.js"),require("../icon/icons/RedCrossIcon.js"),require("../icon/icons/SearchIcon.js"),require("../icon/icons/SuccessIcon.js"),require("../icon/icons/WarningIcon.js"),require("../icon/icons/MinusIcon.js"),require("../icon/icons/ThumbDownIcon.js"),require("../icon/icons/ThumbUpIcon.js"),require("../icon/icons/TrashCanIcon.js"),require("../icon/icons/PenIcon.js"),require("../tooltip/Tooltip.js"),require("../tooltip/TooltipContent.js"),require("../tooltip/TooltipTrigger.js");const l=require("../input-group/InputGroup.js");require("../text-input/BaseTextArea.js");const d=require("../text-input/BaseTextInput.js");require("../text-input/TextArea.js"),require("../text-input/TextInput.js");const p=require("./internal/Calendar.js"),j=require("./internal/utils.js"),q=require("./utils.js"),k=require("./validation.js"),h=o.forwardRef(((h,I)=>{const{"data-testautoid":b,id:v,className:m="",label:C="Velg dato",labelProps:f,defaultValue:y,defaultShow:g=!1,value:D,disableBeforeDate:w,disableAfterDate:x,yearsToShow:L,name:T,helpLabel:S,errorLabel:A,invalid:O,density:P,days:_,months:E,monthLabel:R,yearLabel:N,placeholder:B="dd.mm.åååå",width:U="11.25rem",onChange:K,onBlur:H,onFocus:V,onKeyDown:F,action:W,showCalendarLabel:G="Åpne kalender",hideCalendarLabel:M="Lukk kalender",supportLabelProps:z,tooltipProps:Q,...J}=h;"production"!==process.env.NODE_ENV&&D&&y&&console.warn("DatePicker må enten være controlled eller uncontrolled. Hvis du bruker defaultValue og value sammen vil defaultValue bli ignorert.");const X=q.parseDateString(w),Y=X?n(X):void 0,Z=q.parseDateString(x),$=Z?n(Z):void 0,[ee,re]=o.useState(j.getInitialDate(D,y,Y,$)),[ne,oe]=o.useState(null),[ie,se]=o.useState(g),[te]=s.useAnimatedHeight(ie),ae=o.useRef(null),ue=o.useRef(null),ce=o.useCallback((e=>{ue.current=e,I&&("function"==typeof I?I(e):I.current=e)}),[ue,I]),le=o.useRef(null),de=o.useCallback((e=>{V&&le.current&&(le.current.contains(e.relatedTarget)||V(e,ee,{error:ne,value:e.target.value}))}),[V,ee,ne]),pe=o.useCallback((e=>{H&&H(e,ee,{error:ne,value:e.target.value})}),[H,ee,ne]),je=o.useCallback((e=>{"Escape"===e.key&&(se(!1),e.preventDefault(),e.stopPropagation()),null!=W&&W.onKeyDown&&W.onKeyDown(e)}),[se,W]),qe=o.useCallback((e=>{if("Escape"===e.key&&(se(!1),e.preventDefault(),e.stopPropagation()),F){let r=e.currentTarget.value;/[\d.]/.test(e.key)&&(r+=e.key),F(e,ee,{error:ne,value:r})}}),[F,se,ee,ne]),ke=o.useCallback((e=>{let r=null,n=null;if(e.target.value){const o=q.parseDateString(e.target.value);o?Y&&!k.isWithinLowerBound(o,Y)?n="OUTSIDE_LOWER_BOUND":$&&!k.isWithinUpperBound(o,$)?n="OUTSIDE_UPPER_BOUND":se(!1):n="WRONG_FORMAT",r=o||null}oe(n),re(r),K&&K(e,r,{error:n,value:e.target.value})}),[K,oe,re,se,Y,$]),he=o.useCallback((e=>{i.flushSync((()=>{se(!ie)}));const r=te.current,n=r&&r.querySelector('[aria-pressed="true"]');n&&n.focus(),null!=W&&W.onClick&&W.onClick(e)}),[se,ie,W,te]),Ie=o.useCallback((()=>{se(!ie)}),[se,ie]),be=o.useCallback((()=>{se(!1)}),[se]),ve=o.useCallback((({date:e})=>{if(se(!1),re(e),ue.current){const r=ue.current;r.value=q.formatInput(e);const n=document.createEvent("HTMLEvents");n.initEvent("input",!0,!1),r.dispatchEvent(n),r.focus(),K&&K(n,e,{error:null,value:r.value})}}),[se,re,K]),me=o.useCallback((e=>{e.preventDefault(),se(!1),ae.current&&ae.current.focus()}),[se]);return t.useClickOutside(le,be),a.useFocusOutside(le,be),u.useKeyListener(te,["Escape"],(()=>{se(!1),ue.current&&ue.current.focus()})),e.jsx(l.InputGroup,{id:v,className:r.clsx("jkl-datepicker",m,{"jkl-datepicker--open":ie}),...J,ref:le,label:C,labelProps:f,density:P,helpLabel:S,errorLabel:A,supportLabelProps:z,tooltipProps:Q,render:r=>e.jsxs("div",{"data-testid":"jkl-datepicker__input-wrapper",className:"jkl-datepicker__input-wrapper","data-density":P,tabIndex:-1,onKeyDown:qe,children:[e.jsx(d.BaseTextInput,{ref:ce,"data-testid":"jkl-datepicker__input","data-testautoid":b,className:"jkl-datepicker__input",name:T,defaultValue:y,density:P,value:D,type:"text",placeholder:B,width:U,onFocus:de,onBlur:pe,onClick:Ie,onChange:ke,...r,action:{buttonRef:ae,icon:e.jsx(c.CalendarIcon,{}),label:ie?M:G,...W,onClick:he,onKeyDown:je}}),e.jsx("div",{className:"jkl-datepicker__calendar-wrapper",children:e.jsx(p.Calendar,{ref:te,density:P,date:ee,minDate:Y,maxDate:$,days:_,months:E,monthLabel:R,yearLabel:N,yearsToShow:L,hidden:!ie,onDateSelected:ve,onTabOutside:me})})]})})}));h.displayName="DatePicker",exports.DatePicker=h;
|
|
2
2
|
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sources":["../../../../src/components/datepicker/DatePicker.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport startOfDay from \"date-fns/startOfDay\";\nimport React, {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n forwardRef,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useAnimatedHeight, useClickOutside, useFocusOutside, useKeyListener } from \"../../hooks\";\nimport { CalendarIcon } from \"../icon\";\nimport { InputGroup } from \"../input-group\";\nimport { BaseTextInput } from \"../text-input\";\nimport { Calendar } from \"./internal/Calendar\";\nimport { getInitialDate, DateInfo } from \"./internal/utils\";\nimport { DatePickerProps, DateValidationError } from \"./types\";\nimport { formatInput, parseDateString } from \"./utils\";\nimport { isWithinLowerBound, isWithinUpperBound } from \"./validation\";\n\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>((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 density,\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 tooltipProps,\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 ? startOfDay(disableBeforeDate) : undefined;\n const disableAfterDate = parseDateString(disableAfter);\n const maxDate = disableAfterDate ? startOfDay(disableAfterDate) : undefined;\n\n const [date, setDate] = useState(getInitialDate(value, defaultValue, minDate, maxDate));\n const [error, setError] = useState<DateValidationError | null>(null);\n\n /// Calendar state\n\n const [showCalendar, setShowCalendar] = useState(defaultShow);\n const [calendarRef] = useAnimatedHeight<HTMLDivElement>(showCalendar);\n\n /// Input events\n\n const iconButtonRef = useRef<HTMLButtonElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\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 [inputRef, forwardedInputRef],\n );\n\n const datepickerRef = useRef<HTMLDivElement>(null);\n const handleFocus = useCallback(\n (e: FocusEvent<HTMLInputElement>) => {\n if (!onFocus || !datepickerRef.current) {\n return;\n }\n\n const nextFocusIsInside = datepickerRef.current.contains(e.relatedTarget as Node);\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 [setShowCalendar, action],\n );\n\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Escape\") {\n setShowCalendar(false);\n e.preventDefault();\n e.stopPropagation();\n }\n\n if (onKeyDown) {\n let nextValue = e.currentTarget.value;\n if (/[\\d.]/.test(e.key)) {\n nextValue += e.key;\n }\n onKeyDown(e, date, { error, value: nextValue });\n }\n },\n [onKeyDown, setShowCalendar, date, error],\n );\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n let nextDate: Date | null = null;\n let nextError: DateValidationError | null = null;\n\n if (e.target.value) {\n const val = parseDateString(e.target.value);\n if (!val) {\n nextError = \"WRONG_FORMAT\";\n } else if (minDate && !isWithinLowerBound(val, minDate)) {\n nextError = \"OUTSIDE_LOWER_BOUND\";\n } else if (maxDate && !isWithinUpperBound(val, maxDate)) {\n nextError = \"OUTSIDE_UPPER_BOUND\";\n } else {\n setShowCalendar(false);\n }\n nextDate = val || null;\n }\n\n setError(nextError);\n setDate(nextDate);\n\n if (onChange) {\n onChange(e, nextDate, { error: nextError, value: e.target.value });\n }\n },\n [onChange, setError, setDate, setShowCalendar, 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 = calendarEl && (calendarEl.querySelector('[aria-pressed=\"true\"]') as HTMLButtonElement);\n button && button.focus();\n\n if (action?.onClick) {\n action.onClick(e);\n }\n },\n [setShowCalendar, showCalendar, action, calendarRef],\n );\n\n const clickInput = useCallback(() => {\n setShowCalendar(!showCalendar);\n }, [setShowCalendar, showCalendar]);\n\n const hideCalendar = useCallback(() => {\n setShowCalendar(false);\n }, [setShowCalendar]);\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 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(event as unknown as ChangeEvent<HTMLInputElement>, date, {\n error: null,\n value: node.value,\n });\n }\n }\n },\n [setShowCalendar, setDate, onChange],\n );\n\n const handleTabOutsideCalendar = useCallback(\n (e: KeyboardEvent) => {\n e.preventDefault();\n setShowCalendar(false);\n iconButtonRef.current && iconButtonRef.current.focus();\n },\n [setShowCalendar],\n );\n\n useClickOutside(datepickerRef, hideCalendar);\n useFocusOutside(datepickerRef, hideCalendar);\n useKeyListener(calendarRef, [\"Escape\"], () => {\n setShowCalendar(false);\n inputRef.current && inputRef.current.focus();\n });\n\n return (\n <InputGroup\n id={id}\n className={cn(\"jkl-datepicker\", className, {\n \"jkl-datepicker--open\": showCalendar,\n })}\n {...rest}\n ref={datepickerRef}\n label={label}\n labelProps={labelProps}\n density={density}\n helpLabel={helpLabel}\n errorLabel={errorLabel}\n supportLabelProps={supportLabelProps}\n tooltipProps={tooltipProps}\n render={(inputProps) => (\n // The <div> element handles keyboard events that bubble up from <button> elements inside\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div\n data-testid=\"jkl-datepicker__input-wrapper\"\n className=\"jkl-datepicker__input-wrapper\"\n data-density={density}\n tabIndex={-1} // Må være her for Safari onBlur quirk! https://bugs.webkit.org/show_bug.cgi?id=22261\n onKeyDown={handleKeyDown}\n >\n <BaseTextInput\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 density={density}\n value={value}\n type=\"text\"\n placeholder={placeholder}\n width={width}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onClick={clickInput}\n onChange={handleChange}\n {...inputProps}\n action={{\n buttonRef: iconButtonRef,\n icon: <CalendarIcon />,\n label: showCalendar ? hideCalendarLabel : showCalendarLabel,\n ...action,\n onClick: clickCalendar,\n onKeyDown: handleKeyDownAction,\n }}\n />\n <div className=\"jkl-datepicker__calendar-wrapper\">\n <Calendar\n ref={calendarRef}\n density={density}\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 hidden={!showCalendar}\n onDateSelected={handleClickCalendarDay}\n onTabOutside={handleTabOutsideCalendar}\n />\n </div>\n </div>\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","density","days","months","monthLabel","yearLabel","placeholder","width","onChange","onBlur","onFocus","onKeyDown","action","showCalendarLabel","hideCalendarLabel","supportLabelProps","tooltipProps","rest","process","env","NODE_ENV","console","warn","parseDateString","minDate","startOfDay","maxDate","date","setDate","useState","getInitialDate","error","setError","showCalendar","setShowCalendar","calendarRef","useAnimatedHeight","iconButtonRef","useRef","inputRef","unifiedInputRef","useCallback","instance","current","datepickerRef","handleFocus","e","contains","relatedTarget","target","handleBlur","handleKeyDownAction","key","preventDefault","stopPropagation","handleKeyDown","nextValue","currentTarget","test","handleChange","nextDate","nextError","val","isWithinLowerBound","isWithinUpperBound","clickCalendar","flushSync","calendarEl","button","querySelector","focus","onClick","clickInput","hideCalendar","handleClickCalendarDay","node","formatInput","event","document","createEvent","initEvent","dispatchEvent","handleTabOutsideCalendar","useClickOutside","useFocusOutside","useKeyListener","jsx","InputGroup","cn","ref","render","inputProps","jsxs","tabIndex","children","BaseTextInput","type","buttonRef","icon","CalendarIcon","Calendar","hidden","onDateSelected","onTabOutside","displayName"],"mappings":"q6EAuBaA,EAAaC,EAAAA,YAA8C,CAACC,EAAOC,KACtE,MACF,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,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,aAAAA,KACGC,GACHnC,EAEyB,eAAzBoC,QAAQC,IAAIC,UAA6B7B,GAASF,GAC1CgC,QAAAC,KACJ,sIAKF,MAAA9B,EAAoB+B,kBAAgB9B,GACpC+B,EAAUhC,EAAoBiC,EAAWjC,QAAqB,EAC9DE,EAAmB6B,kBAAgB5B,GACnC+B,EAAUhC,EAAmB+B,EAAW/B,QAAoB,GAE3DiC,GAAMC,IAAWC,WAASC,EAAAA,eAAevC,EAAOF,EAAcmC,EAASE,KACvEK,GAAOC,IAAYH,WAAqC,OAIxDI,GAAcC,IAAmBL,WAASvC,IAC1C6C,IAAeC,EAAAA,kBAAkCH,IAIlDI,GAAgBC,SAAiC,MACjD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A,kBAAgBvC,GAAe6B,IAC/BW,kBAAgBxC,GAAe6B,IAC/BY,EAAAA,eAAelD,GAAa,CAAC,WAAW,KACpCD,IAAgB,GACPK,GAAAI,SAAWJ,GAASI,QAAQ2B,OAAM,IAI3CgB,EAAAA,IAACC,EAAAA,WAAA,CACGtG,GAAAA,EACAC,UAAWsG,EAAG,iBAAkBtG,EAAW,CACvC,uBAAwB+C,QAExBhB,EACJwE,IAAK7C,GACLzD,MAAAA,EACAC,WAAAA,EACAa,QAAAA,EACAH,UAAAA,EACAC,WAAAA,EACAgB,kBAAAA,EACAC,aAAAA,EACA0E,OAASC,GAGLC,EAAAA,KAAC,MAAA,CACG,cAAY,gCACZ1G,UAAU,gCACV,eAAce,EACd4F,UACA,EAAAlF,UAAW4C,GAEXuC,SAAA,CAAAR,EAAAA,IAACS,EAAAA,cAAA,CACGN,IAAKjD,GACL,cAAY,wBACZ,kBAAiBxD,EACjBE,UAAU,wBACVW,KAAAA,EACAR,aAAAA,EACAY,QAAAA,EACAV,MAAAA,EACAyG,KAAK,OACL1F,YAAAA,EACAC,MAAAA,EACAG,QAASmC,GACTpC,OAAQyC,GACRqB,QAASC,GACThE,SAAUmD,MACNgC,EACJ/E,OAAQ,CACJqF,UAAW5D,GACX6D,WAAOC,EAAaA,aAAA,IACpBhH,MAAO8C,GAAenB,EAAoBD,KACvCD,EACH2D,QAASN,GACTtD,UAAWwC,MAGnBmC,EAAAA,IAAC,MAAI,CAAApG,UAAU,mCACX4G,SAAAR,EAAAA,IAACc,EAAAA,SAAA,CACGX,IAAKtD,GACLlC,QAAAA,EACA0B,KAAAA,GACAH,QAAAA,EACAE,QAAAA,EACAxB,KAAAA,EACAC,OAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAT,YAAAA,EACAyG,QAASpE,GACTqE,eAAgB5B,GAChB6B,aAAcrB,WAG1B,IAMhBtG,EAAW4H,YAAc"}
|
|
1
|
+
{"version":3,"file":"DatePicker.js","sources":["../../../../src/components/datepicker/DatePicker.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport startOfDay from \"date-fns/startOfDay\";\nimport React, {\n ChangeEvent,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n forwardRef,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useAnimatedHeight, useClickOutside, useFocusOutside, useKeyListener } from \"../../hooks\";\nimport { CalendarIcon } from \"../icon\";\nimport { InputGroup } from \"../input-group\";\nimport { BaseTextInput } from \"../text-input\";\nimport { Calendar } from \"./internal/Calendar\";\nimport { getInitialDate, DateInfo } from \"./internal/utils\";\nimport { DatePickerProps, DateValidationError } from \"./types\";\nimport { formatInput, parseDateString } from \"./utils\";\nimport { isWithinLowerBound, isWithinUpperBound } from \"./validation\";\n\nexport const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>((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 density,\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 tooltipProps,\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 ? startOfDay(disableBeforeDate) : undefined;\n const disableAfterDate = parseDateString(disableAfter);\n const maxDate = disableAfterDate ? startOfDay(disableAfterDate) : undefined;\n\n const [date, setDate] = useState(getInitialDate(value, defaultValue, minDate, maxDate));\n const [error, setError] = useState<DateValidationError | null>(null);\n\n /// Calendar state\n\n const [showCalendar, setShowCalendar] = useState(defaultShow);\n const [calendarRef] = useAnimatedHeight<HTMLDivElement>(showCalendar);\n\n /// Input events\n\n const iconButtonRef = useRef<HTMLButtonElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\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 [inputRef, forwardedInputRef],\n );\n\n const datepickerRef = useRef<HTMLDivElement>(null);\n const handleFocus = useCallback(\n (e: FocusEvent<HTMLInputElement>) => {\n if (!onFocus || !datepickerRef.current) {\n return;\n }\n\n const nextFocusIsInside = datepickerRef.current.contains(e.relatedTarget as Node);\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 [setShowCalendar, action],\n );\n\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Escape\") {\n setShowCalendar(false);\n e.preventDefault();\n e.stopPropagation();\n }\n\n if (onKeyDown) {\n let nextValue = e.currentTarget.value;\n if (/[\\d.]/.test(e.key)) {\n nextValue += e.key;\n }\n onKeyDown(e, date, { error, value: nextValue });\n }\n },\n [onKeyDown, setShowCalendar, date, error],\n );\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n let nextDate: Date | null = null;\n let nextError: DateValidationError | null = null;\n\n if (e.target.value) {\n const val = parseDateString(e.target.value);\n if (!val) {\n nextError = \"WRONG_FORMAT\";\n } else if (minDate && !isWithinLowerBound(val, minDate)) {\n nextError = \"OUTSIDE_LOWER_BOUND\";\n } else if (maxDate && !isWithinUpperBound(val, maxDate)) {\n nextError = \"OUTSIDE_UPPER_BOUND\";\n } else {\n setShowCalendar(false);\n }\n nextDate = val || null;\n }\n\n setError(nextError);\n setDate(nextDate);\n\n if (onChange) {\n onChange(e, nextDate, { error: nextError, value: e.target.value });\n }\n },\n [onChange, setError, setDate, setShowCalendar, 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 = calendarEl && (calendarEl.querySelector('[aria-pressed=\"true\"]') as HTMLButtonElement);\n button && button.focus();\n\n if (action?.onClick) {\n action.onClick(e);\n }\n },\n [setShowCalendar, showCalendar, action, calendarRef],\n );\n\n const clickInput = useCallback(() => {\n setShowCalendar(!showCalendar);\n }, [setShowCalendar, showCalendar]);\n\n const hideCalendar = useCallback(() => {\n setShowCalendar(false);\n }, [setShowCalendar]);\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 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(event as unknown as ChangeEvent<HTMLInputElement>, date, {\n error: null,\n value: node.value,\n });\n }\n }\n },\n [setShowCalendar, setDate, onChange],\n );\n\n const handleTabOutsideCalendar = useCallback(\n (e: KeyboardEvent) => {\n e.preventDefault();\n setShowCalendar(false);\n iconButtonRef.current && iconButtonRef.current.focus();\n },\n [setShowCalendar],\n );\n\n useClickOutside(datepickerRef, hideCalendar);\n useFocusOutside(datepickerRef, hideCalendar);\n useKeyListener(calendarRef, [\"Escape\"], () => {\n setShowCalendar(false);\n inputRef.current && inputRef.current.focus();\n });\n\n return (\n <InputGroup\n id={id}\n className={clsx(\"jkl-datepicker\", className, {\n \"jkl-datepicker--open\": showCalendar,\n })}\n {...rest}\n ref={datepickerRef}\n label={label}\n labelProps={labelProps}\n density={density}\n helpLabel={helpLabel}\n errorLabel={errorLabel}\n supportLabelProps={supportLabelProps}\n tooltipProps={tooltipProps}\n render={(inputProps) => (\n // The <div> element handles keyboard events that bubble up from <button> elements inside\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div\n data-testid=\"jkl-datepicker__input-wrapper\"\n className=\"jkl-datepicker__input-wrapper\"\n data-density={density}\n tabIndex={-1} // Må være her for Safari onBlur quirk! https://bugs.webkit.org/show_bug.cgi?id=22261\n onKeyDown={handleKeyDown}\n >\n <BaseTextInput\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 density={density}\n value={value}\n type=\"text\"\n placeholder={placeholder}\n width={width}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onClick={clickInput}\n onChange={handleChange}\n {...inputProps}\n action={{\n buttonRef: iconButtonRef,\n icon: <CalendarIcon />,\n label: showCalendar ? hideCalendarLabel : showCalendarLabel,\n ...action,\n onClick: clickCalendar,\n onKeyDown: handleKeyDownAction,\n }}\n />\n <div className=\"jkl-datepicker__calendar-wrapper\">\n <Calendar\n ref={calendarRef}\n density={density}\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 hidden={!showCalendar}\n onDateSelected={handleClickCalendarDay}\n onTabOutside={handleTabOutsideCalendar}\n />\n </div>\n </div>\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","density","days","months","monthLabel","yearLabel","placeholder","width","onChange","onBlur","onFocus","onKeyDown","action","showCalendarLabel","hideCalendarLabel","supportLabelProps","tooltipProps","rest","process","env","NODE_ENV","console","warn","parseDateString","minDate","startOfDay","maxDate","date","setDate","useState","getInitialDate","error","setError","showCalendar","setShowCalendar","calendarRef","useAnimatedHeight","iconButtonRef","useRef","inputRef","unifiedInputRef","useCallback","instance","current","datepickerRef","handleFocus","e","contains","relatedTarget","target","handleBlur","handleKeyDownAction","key","preventDefault","stopPropagation","handleKeyDown","nextValue","currentTarget","test","handleChange","nextDate","nextError","val","isWithinLowerBound","isWithinUpperBound","clickCalendar","flushSync","calendarEl","button","querySelector","focus","onClick","clickInput","hideCalendar","handleClickCalendarDay","node","formatInput","event","document","createEvent","initEvent","dispatchEvent","handleTabOutsideCalendar","useClickOutside","useFocusOutside","useKeyListener","jsx","InputGroup","clsx","ref","render","inputProps","jsxs","tabIndex","children","BaseTextInput","type","buttonRef","icon","CalendarIcon","Calendar","hidden","onDateSelected","onTabOutside","displayName"],"mappings":"q7EAuBaA,EAAaC,EAAAA,YAA8C,CAACC,EAAOC,KACtE,MACF,kBAAmBC,EACnBC,GAAAA,EACAC,UAAAA,EAAY,GACZC,MAAAA,EAAQ,YACRC,WAAAA,EACAC,aAAAA,EACAC,YAAAA,GAAc,EACdC,MAAAA,EACAC,kBAAmBC,EACnBC,iBAAkBC,EAClBC,YAAA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AAAA,IAACS,EAAAA,cAAA,CACGN,IAAKjD,GACL,cAAY,wBACZ,kBAAiBxD,EACjBE,UAAU,wBACVW,KAAAA,EACAR,aAAAA,EACAY,QAAAA,EACAV,MAAAA,EACAyG,KAAK,OACL1F,YAAAA,EACAC,MAAAA,EACAG,QAASmC,GACTpC,OAAQyC,GACRqB,QAASC,GACThE,SAAUmD,MACNgC,EACJ/E,OAAQ,CACJqF,UAAW5D,GACX6D,WAAOC,EAAaA,aAAA,IACpBhH,MAAO8C,GAAenB,EAAoBD,KACvCD,EACH2D,QAASN,GACTtD,UAAWwC,MAGnBmC,EAAAA,IAAC,MAAI,CAAApG,UAAU,mCACX4G,SAAAR,EAAAA,IAACc,EAAAA,SAAA,CACGX,IAAKtD,GACLlC,QAAAA,EACA0B,KAAAA,GACAH,QAAAA,EACAE,QAAAA,EACAxB,KAAAA,EACAC,OAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAT,YAAAA,EACAyG,QAASpE,GACTqE,eAAgB5B,GAChB6B,aAAcrB,WAG1B,IAMhBtG,EAAW4H,YAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("../../../../clsx-E3yX_9sL.cjs"),t=require("react"),r=require("react-dom");require("../../../hooks/useScreen/useScreen.js");const a=require("../../../hooks/useId/useId.js");require("../../icon/Icon.js"),require("../../icon/icons/animated/ArrowVerticalAnimated.js"),require("../../icon/icons/animated/ArrowHorizontalAnimated.js"),require("../../icon/icons/animated/PlusRemoveAnimated.js"),require("../../icon/icons/ArrowDownIcon.js");const o=require("../../icon/icons/ArrowLeftIcon.js");require("../../icon/icons/ArrowNorthEastIcon.js");const c=require("../../icon/icons/ArrowRightIcon.js");require("../../icon/icons/ArrowUpIcon.js"),require("../../icon/icons/CalendarIcon.js"),require("../../icon/icons/CheckIcon.js");const s=require("../../icon/icons/ChevronDownIcon.js");require("../../icon/icons/ChevronLeftIcon.js"),require("../../icon/icons/ChevronRightIcon.js"),require("../../icon/icons/ChevronUpIcon.js"),require("../../icon/icons/CloseIcon.js"),require("../../icon/icons/CopyIcon.js"),require("../../icon/icons/DotsIcon.js"),require("../../icon/icons/DragIcon.js"),require("../../icon/icons/ErrorIcon.js"),require("../../icon/icons/GreenCheckIcon.js"),require("../../icon/icons/HamburgerIcon.js"),require("../../icon/icons/InfoIcon.js"),require("../../icon/icons/LinkIcon.js"),require("../../icon/icons/PlusIcon.js"),require("../../icon/icons/QuestionIcon.js"),require("../../icon/icons/RedCrossIcon.js"),require("../../icon/icons/SearchIcon.js"),require("../../icon/icons/SuccessIcon.js"),require("../../icon/icons/WarningIcon.js"),require("../../icon/icons/MinusIcon.js"),require("../../icon/icons/ThumbDownIcon.js"),require("../../icon/icons/ThumbUpIcon.js"),require("../../icon/icons/TrashCanIcon.js"),require("../../icon/icons/PenIcon.js");const i=require("./calendarReducer.js"),l=require("./useCalendar.js"),d=require("./utils.js"),u=["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"],h=["man","tir","ons","tor","fre","lør","søn"],j=t.forwardRef(((j,g)=>{const{hidden:b,date:m,defaultSelected:f,density:p,minDate:v,maxDate:k,days:q=h,months:w=u,monthLabel:D="Velg måned",yearLabel:I="Velg år",yearsToShow:x=d.DEFAULT_YEARS_TO_SHOW,onTabOutside:y,...S}=j,C=a.useId("jkl-calendar"),[{offset:A,selectedDate:_,shownDate:M},F]=t.useReducer(i.calendarReducer,d.getInitialDateShown(m,f,v,k),i.calendarInitializer),N=M.getMonth(),E=M.getFullYear();t.useEffect((()=>{F({type:"SET_SELECTED_DATE",newDate:d.getInitialDateShown(m,f,v,k)})}),[m,f,v,k]);const O=t.useCallback((e=>{F({type:"SET_OFFSET",newOffset:e})}),[]),{calendars:T,getBackProps:Y,getDateProps:$,getForwardProps:R,handleOffsetChanged:L}=l.useCalendar({date:_,selected:_,minDate:v,maxDate:k,offset:A,onOffsetChanged:O,firstDayOfWeek:1,...S}),P=t.useRef(null),U=t.useCallback((e=>{if(!P.current)return;const n=document.activeElement,t=P.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]'),a=async e=>{null==n||n.setAttribute("tabindex","-1"),e.setAttribute("tabindex","0"),e.focus()};t.forEach(((o,c)=>{const s=c+e;if(o==n)if(s<=t.length-1&&s>=0)a(t[s]);else if(e<0){if(d.isBackDisabled({calendars:T,minDate:v})||(r.flushSync((()=>{L(A-d.subtractMonth({calendars:T,offset:1,minDate:v}))})),!P.current))return;const e=P.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]');e[e.length+s]&&(e[0].setAttribute("tabindex","-1"),a(e[e.length+s]))}else{if(d.isForwardDisabled({calendars:T,maxDate:k})||(r.flushSync((()=>{L(A+d.addMonth({calendars:T,offset:1,maxDate:k}))})),!P.current))return;const e=P.current.querySelectorAll('button.jkl-calendar-date-button:not([data-adjacent="true"]');e[s-t.length]&&(e[0].setAttribute("tabindex","-1"),a(e[s-t.length]))}}))}),[L,P,A,T,k,v]),K=t.useCallback((e=>{switch(e.key){case"ArrowUp":U(-7),e.preventDefault();break;case"ArrowRight":U(1),e.preventDefault();break;case"ArrowDown":U(7),e.preventDefault();break;case"ArrowLeft":U(-1),e.preventDefault()}}),[U]),H=t.useCallback((e=>{var n;if("Tab"!==e.key)return;const t=null==(n=P.current)?void 0:n.querySelectorAll('button:not([disabled]):not([tabindex="-1"]), select');if(!t)return;const r=t[0],a=t[t.length-1];e.shiftKey||document.activeElement!==a?e.shiftKey&&document.activeElement===r&&(a.focus(),e.preventDefault()):(r.focus(),e.preventDefault())}),[]),J=t.useCallback((e=>{const{date:n,selected:t,selectable:r,prevMonth:a,nextMonth:o}=e;return!!r&&!(!t&&n.toString()!==(null==v?void 0:v.toString())&&(a||o||M.getFullYear()!==n.getFullYear()||_.getMonth()===n.getMonth()||1!==n.getDate()))}),[M,v,_]),V=t.useCallback((()=>{v&&M.getFullYear()-v.getFullYear()==0&&M.getMonth()-v.getMonth()==1?document.querySelectorAll(".jkl-calendar-navigation__arrow")[1].focus():k&&k.getFullYear()-M.getFullYear()==0&&k.getMonth()-M.getMonth()==1&&document.querySelectorAll(".jkl-calendar-navigation__arrow")[0].focus()}),[v,k,M]),W=t.useCallback((e=>{if(4!==e.target.value.length)return;const n=Number.parseInt(e.target.value);if(Number.isNaN(n))return;let t=12*(n-M.getFullYear());const r=new Date(M.getFullYear(),M.getMonth()+t,M.getDate());k&&k.getFullYear()===r.getFullYear()&&k.getMonth()<r.getMonth()?t-=r.getMonth()-k.getMonth():v&&v.getFullYear()===r.getFullYear()&&v.getMonth()>r.getMonth()&&(t+=v.getMonth()-r.getMonth()),F({type:"ADD_OFFSET",addedOffset:t})}),[M,v,k]),z=t.useCallback((e=>{if(!_&&!m)return;const n=M.getFullYear()-(_||new Date).getFullYear(),t=Number.parseInt(e.target.value)-(_||new Date).getMonth();F({type:"SET_OFFSET",newOffset:12*n+t})}),[_,m,M]),B=d.getYearSelectOptions(E,v,k,x),G=d.getMonthSelectOptions(E,w,v,k);return e.jsx("div",{ref:g,id:C,className:n.clsx("jkl-calendar",{"jkl-calendar--hidden":b}),"data-testid":"jkl-calendar",children:e.jsxs("div",{className:"jkl-calendar__padding",ref:P,onKeyDown:H,children:[e.jsxs("fieldset",{className:"jkl-calendar-navigation",children:[e.jsxs("div",{children:[e.jsx("button",{...Y({calendars:T,onClick:V}),className:"jkl-calendar-navigation__arrow",type:"button",children:e.jsx(o.ArrowLeftIcon,{variant:"medium",bold:!0})}),e.jsx("button",{...R({calendars:T,onClick:V}),className:"jkl-calendar-navigation__arrow",type:"button",children:e.jsx(c.ArrowRightIcon,{variant:"medium",bold:!0})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"jkl-calendar-navigation-dropdown",children:[e.jsx("select",{onChange:z,className:"jkl-calendar-navigation-dropdown__select","aria-label":D,value:N.toString(),children:G.map((({label:n,value:t})=>e.jsx("option",{value:t,children:n},t)))}),e.jsx(s.ChevronDownIcon,{bold:!0,className:"jkl-calendar-navigation-dropdown__chevron"})]}),e.jsxs("div",{className:"jkl-calendar-navigation-dropdown",children:[e.jsx("select",{onChange:W,className:"jkl-calendar-navigation-dropdown__select","aria-label":I,value:E.toString(),children:B.map((n=>e.jsx("option",{value:n,children:n},n)))}),e.jsx(s.ChevronDownIcon,{bold:!0,className:"jkl-calendar-navigation-dropdown__chevron"})]})]})]}),T.map((n=>e.jsxs("table",{className:"jkl-calendar-table","data-testid":"jkl-datepicker-calendar",children:[e.jsxs("caption",{className:"jkl-sr-only",children:[w[n.month],", ",n.year]}),e.jsx("thead",{children:e.jsx("tr",{children:q.map((t=>e.jsx("th",{children:t},`${n.month}${n.year}${t}`)))})}),e.jsx("tbody",{"data-testid":"jkl-datepicker-dates",children:n.weeks.map(((t,r)=>e.jsx("tr",{children:t.map(((t,a)=>{const o=`${n.month}${n.year}${r}${a}`;if("string"==typeof t)return e.jsx("td",{className:"jkl-calendar__date jkl-calendar__date--empty",children:t},o);const{date:c,selectable:s,today:i,prevMonth:l,nextMonth:d}=t;return e.jsx("td",{children:e.jsx("button",{...$({dateObj:t}),type:"button",className:"jkl-calendar-date-button",tabIndex:J(t)?0:-1,"aria-label":`${c.getDate()}. ${w[c.getMonth()].toLowerCase()}`,"aria-current":i?"date":void 0,"data-adjacent":l||d?"true":void 0,disabled:!s,onKeyDown:K,children:e.jsx("span",{"aria-hidden":"true",children:c.getDate()})})},o)}))},`${n.month}${n.year}${r}`)))})]},`${n.month}${n.year}`)))]})})}));j.displayName="Calendar",exports.Calendar=j;
|
|
2
2
|
//# sourceMappingURL=Calendar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.js","sources":["../../../../../src/components/datepicker/internal/Calendar.tsx"],"sourcesContent":["import cn from \"classnames\";\nimport React, { forwardRef, useCallback, useEffect, useReducer, useRef } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { Density } from \"../../../core\";\nimport { useId } from \"../../../hooks\";\nimport { ArrowLeftIcon, ArrowRightIcon, ChevronDownIcon } from \"../../icon\";\nimport type { YearsToShow } from \"../types\";\nimport { calendarInitializer, calendarReducer } from \"./calendarReducer\";\nimport { useCalendar, UseCalendarProps } from \"./useCalendar\";\nimport {\n addMonth,\n subtractMonth,\n isBackDisabled,\n isForwardDisabled,\n getYearSelectOptions,\n getMonthSelectOptions,\n DateInfo,\n getInitialDateShown,\n DEFAULT_YEARS_TO_SHOW,\n} from \"./utils\";\n\ninterface CalendarProps\n extends Omit<UseCalendarProps, \"date\" | \"onOffsetChanged\" | \"offset\" | \"firstDayOfWeek\" | \"selected\"> {\n date: Date | null;\n density?: Density;\n defaultSelected?: Date;\n hidden?: boolean;\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>((props, ref) => {\n const {\n hidden,\n date,\n defaultSelected,\n density,\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(date, defaultSelected, minDate, maxDate),\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 { calendars, getBackProps, getDateProps, getForwardProps, handleOffsetChanged } = 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 = 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 (newNodeKey <= buttons.length - 1 && newNodeKey >= 0) {\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(offset - subtractMonth({ calendars, offset: 1, minDate }));\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons = 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(newButtons[newButtons.length + newNodeKey]);\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(offset + addMonth({ calendars, offset: 1, maxDate }));\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons = 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(newButtons[newNodeKey - buttons.length]);\n }\n }\n }\n });\n },\n [handleOffsetChanged, calendarPaddingRef, 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((event) => {\n if (event.key !== \"Tab\") return;\n\n const focusableElements = 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 = focusableElements[focusableElements.length - 1];\n\n if (!event.shiftKey && document.activeElement === lastElement) {\n firstElement.focus();\n event.preventDefault();\n } else if (event.shiftKey && document.activeElement === firstElement) {\n lastElement.focus();\n event.preventDefault();\n }\n }, []);\n\n const isFocusableDate = useCallback(\n (dateInfo: DateInfo) => {\n const { date, selected, selectable, prevMonth, nextMonth } = 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.querySelectorAll<HTMLButtonElement>(\".jkl-calendar-navigation__arrow\")[1].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.querySelectorAll<HTMLButtonElement>(\".jkl-calendar-navigation__arrow\")[0].focus();\n }\n }, [minDate, maxDate, shownDate]);\n\n /// Extended variant events\n\n const handleYearChange = useCallback<React.ChangeEventHandler<HTMLSelectElement>>(\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(shownDate.getFullYear(), shownDate.getMonth() + offset, shownDate.getDate());\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<React.ChangeEventHandler<HTMLSelectElement>>(\n (event) => {\n if (!selectedDate && !date) {\n return;\n }\n\n const yearDiff = shownDate.getFullYear() - (selectedDate || new Date()).getFullYear();\n const monthDiff = Number.parseInt(event.target.value) - (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(shownYear, minDate, maxDate, yearsToShow);\n const monthSelectOptions = getMonthSelectOptions(shownYear, months, minDate, maxDate);\n\n return (\n <div\n ref={ref}\n id={id}\n className={cn(\"jkl-calendar\", {\n \"jkl-calendar--hidden\": hidden,\n })}\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 className=\"jkl-calendar__padding\" ref={calendarPaddingRef} onKeyDown={handleTabInside}>\n <fieldset className=\"jkl-calendar-navigation\">\n <div>\n <button\n {...getBackProps({ calendars, onClick: handleGotoEdgeMonth })}\n className=\"jkl-calendar-navigation__arrow\"\n type=\"button\"\n >\n <ArrowLeftIcon variant=\"medium\" bold />\n </button>\n <button\n {...getForwardProps({ calendars, onClick: handleGotoEdgeMonth })}\n className=\"jkl-calendar-navigation__arrow\"\n type=\"button\"\n >\n <ArrowRightIcon variant=\"medium\" bold />\n </button>\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(({ label, value }) => (\n <option key={value} value={value}>\n {label}\n </option>\n ))}\n </select>\n <ChevronDownIcon bold className=\"jkl-calendar-navigation-dropdown__chevron\" />\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 bold className=\"jkl-calendar-navigation-dropdown__chevron\" />\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 key={`${calendar.month}${calendar.year}${weekday}`}>{weekday}</th>\n ))}\n </tr>\n </thead>\n <tbody data-testid=\"jkl-datepicker-dates\">\n {calendar.weeks.map((week, weekIndex) => (\n <tr key={`${calendar.month}${calendar.year}${weekIndex}`}>\n {week.map((dateInfo, index) => {\n const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;\n if (typeof dateInfo === \"string\") {\n return (\n <td className=\"jkl-calendar__date jkl-calendar__date--empty\" key={key}>\n {dateInfo}\n </td>\n );\n }\n const { date, selectable, today, prevMonth, nextMonth } = 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={isFocusableDate(dateInfo) ? 0 : -1}\n aria-label={`${date.getDate()}. ${months[\n date.getMonth()\n ].toLowerCase()}`}\n aria-current={today ? \"date\" : undefined}\n data-adjacent={prevMonth || nextMonth ? \"true\" : undefined}\n disabled={!selectable}\n onKeyDown={handleArrowNavigation}\n >\n <span aria-hidden=\"true\">{date.getDate()}</span>\n </button>\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n ))}\n </div>\n </div>\n );\n});\n\nCalendar.displayName = \"Calendar\";\n"],"names":["defaultMonths","defaultDays","Calendar","forwardRef","props","ref","hidden","date","defaultSelected","density","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","setAttribute","nextButton","focus","forEach","el","i","newNodeKey","length","isBackDisabled","flushSync","subtractMonth","newButtons","isForwardDisabled","addMonth","handleArrowNavigation","event","key","preventDefault","handleTabInside","focusableElements","_a","firstElement","lastElement","shiftKey","isFocusableDate","dateInfo","selectable","prevMonth","nextMonth","toString","getDate","handleGotoEdgeMonth","handleYearChange","target","value","year","Number","parseInt","isNaN","expectedDate","Date","addedOffset","handleMonthChange","yearDiff","monthDiff","yearSelectOptions","getYearSelectOptions","monthSelectOptions","getMonthSelectOptions","jsx","className","cn","children","onKeyDown","jsxs","onClick","ArrowLeftIcon","variant","bold","ArrowRightIcon","onChange","map","label","ChevronDownIcon","calendar","month","weekday","weeks","week","weekIndex","index","today","dateObj","tabIndex","toLowerCase","disabled","displayName"],"mappings":"o6DAmCMA,EAAgB,CAClB,SACA,UACA,OACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,YAGEC,EAAc,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,OAElDC,EAAWC,EAAAA,YAA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B,EAAAA,IAAA,KAAA,CAAGC,UAAU,+CACTE,YAD6DpC,GAK1E,MAAQrE,KAAAA,EAAM+E,WAAAA,EAAY6C,MAAAA,EAAO5C,UAAAA,EAAWC,UAAAA,GAAcH,EAE1D,aACK,KACG,CAAA2B,SAAAH,EAAAA,IAAC,SAAA,IACOnE,EAAa,CACb0F,QAAS/C,IAEblD,KAAK,SACL2E,UAAU,2BACVuB,SAAUjD,EAAgBC,GAAY,GACtC,EAAA,aAAY,GAAG9E,EAAKmF,cAAc7E,EAC9BN,EAAKwB,YACPuG,gBACF,eAAcH,EAAQ,YAAS,EAC/B,gBAAe5C,GAAaC,EAAY,YAAS,EACjD+C,UAAWjD,EACX2B,UAAWvC,EAEXsC,eAAC,OAAK,CAAA,cAAY,OAAQA,SAAAzG,EAAKmF,eAhB9Bd,EAkBT,KA/BH,GAAGgD,EAASC,QAAQD,EAAS7B,OAAOkC,WAfhD,GAAGL,EAASC,QAAQD,EAAS7B,cAsD9C,IAKZ7F,EAASsI,YAAc"}
|
|
1
|
+
{"version":3,"file":"Calendar.js","sources":["../../../../../src/components/datepicker/internal/Calendar.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef, useCallback, useEffect, useReducer, useRef } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { Density } from \"../../../core\";\nimport { useId } from \"../../../hooks\";\nimport { ArrowLeftIcon, ArrowRightIcon, ChevronDownIcon } from \"../../icon\";\nimport type { YearsToShow } from \"../types\";\nimport { calendarInitializer, calendarReducer } from \"./calendarReducer\";\nimport { useCalendar, UseCalendarProps } from \"./useCalendar\";\nimport {\n addMonth,\n subtractMonth,\n isBackDisabled,\n isForwardDisabled,\n getYearSelectOptions,\n getMonthSelectOptions,\n DateInfo,\n getInitialDateShown,\n DEFAULT_YEARS_TO_SHOW,\n} from \"./utils\";\n\ninterface CalendarProps\n extends Omit<UseCalendarProps, \"date\" | \"onOffsetChanged\" | \"offset\" | \"firstDayOfWeek\" | \"selected\"> {\n date: Date | null;\n density?: Density;\n defaultSelected?: Date;\n hidden?: boolean;\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>((props, ref) => {\n const {\n hidden,\n date,\n defaultSelected,\n density,\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(date, defaultSelected, minDate, maxDate),\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 { calendars, getBackProps, getDateProps, getForwardProps, handleOffsetChanged } = 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 = 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 (newNodeKey <= buttons.length - 1 && newNodeKey >= 0) {\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(offset - subtractMonth({ calendars, offset: 1, minDate }));\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons = 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(newButtons[newButtons.length + newNodeKey]);\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(offset + addMonth({ calendars, offset: 1, maxDate }));\n });\n if (!calendarPaddingRef.current) {\n return;\n }\n const newButtons = 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(newButtons[newNodeKey - buttons.length]);\n }\n }\n }\n });\n },\n [handleOffsetChanged, calendarPaddingRef, 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((event) => {\n if (event.key !== \"Tab\") return;\n\n const focusableElements = 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 = focusableElements[focusableElements.length - 1];\n\n if (!event.shiftKey && document.activeElement === lastElement) {\n firstElement.focus();\n event.preventDefault();\n } else if (event.shiftKey && document.activeElement === firstElement) {\n lastElement.focus();\n event.preventDefault();\n }\n }, []);\n\n const isFocusableDate = useCallback(\n (dateInfo: DateInfo) => {\n const { date, selected, selectable, prevMonth, nextMonth } = 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.querySelectorAll<HTMLButtonElement>(\".jkl-calendar-navigation__arrow\")[1].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.querySelectorAll<HTMLButtonElement>(\".jkl-calendar-navigation__arrow\")[0].focus();\n }\n }, [minDate, maxDate, shownDate]);\n\n /// Extended variant events\n\n const handleYearChange = useCallback<React.ChangeEventHandler<HTMLSelectElement>>(\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(shownDate.getFullYear(), shownDate.getMonth() + offset, shownDate.getDate());\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<React.ChangeEventHandler<HTMLSelectElement>>(\n (event) => {\n if (!selectedDate && !date) {\n return;\n }\n\n const yearDiff = shownDate.getFullYear() - (selectedDate || new Date()).getFullYear();\n const monthDiff = Number.parseInt(event.target.value) - (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(shownYear, minDate, maxDate, yearsToShow);\n const monthSelectOptions = getMonthSelectOptions(shownYear, months, minDate, maxDate);\n\n return (\n <div\n ref={ref}\n id={id}\n className={clsx(\"jkl-calendar\", {\n \"jkl-calendar--hidden\": hidden,\n })}\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 className=\"jkl-calendar__padding\" ref={calendarPaddingRef} onKeyDown={handleTabInside}>\n <fieldset className=\"jkl-calendar-navigation\">\n <div>\n <button\n {...getBackProps({ calendars, onClick: handleGotoEdgeMonth })}\n className=\"jkl-calendar-navigation__arrow\"\n type=\"button\"\n >\n <ArrowLeftIcon variant=\"medium\" bold />\n </button>\n <button\n {...getForwardProps({ calendars, onClick: handleGotoEdgeMonth })}\n className=\"jkl-calendar-navigation__arrow\"\n type=\"button\"\n >\n <ArrowRightIcon variant=\"medium\" bold />\n </button>\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(({ label, value }) => (\n <option key={value} value={value}>\n {label}\n </option>\n ))}\n </select>\n <ChevronDownIcon bold className=\"jkl-calendar-navigation-dropdown__chevron\" />\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 bold className=\"jkl-calendar-navigation-dropdown__chevron\" />\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 key={`${calendar.month}${calendar.year}${weekday}`}>{weekday}</th>\n ))}\n </tr>\n </thead>\n <tbody data-testid=\"jkl-datepicker-dates\">\n {calendar.weeks.map((week, weekIndex) => (\n <tr key={`${calendar.month}${calendar.year}${weekIndex}`}>\n {week.map((dateInfo, index) => {\n const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;\n if (typeof dateInfo === \"string\") {\n return (\n <td className=\"jkl-calendar__date jkl-calendar__date--empty\" key={key}>\n {dateInfo}\n </td>\n );\n }\n const { date, selectable, today, prevMonth, nextMonth } = 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={isFocusableDate(dateInfo) ? 0 : -1}\n aria-label={`${date.getDate()}. ${months[\n date.getMonth()\n ].toLowerCase()}`}\n aria-current={today ? \"date\" : undefined}\n data-adjacent={prevMonth || nextMonth ? \"true\" : undefined}\n disabled={!selectable}\n onKeyDown={handleArrowNavigation}\n >\n <span aria-hidden=\"true\">{date.getDate()}</span>\n </button>\n </td>\n );\n })}\n </tr>\n ))}\n </tbody>\n </table>\n ))}\n </div>\n </div>\n );\n});\n\nCalendar.displayName = \"Calendar\";\n"],"names":["defaultMonths","defaultDays","Calendar","forwardRef","props","ref","hidden","date","defaultSelected","density","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","setAttribute","nextButton","focus","forEach","el","i","newNodeKey","length","isBackDisabled","flushSync","subtractMonth","newButtons","isForwardDisabled","addMonth","handleArrowNavigation","event","key","preventDefault","handleTabInside","focusableElements","_a","firstElement","lastElement","shiftKey","isFocusableDate","dateInfo","selectable","prevMonth","nextMonth","toString","getDate","handleGotoEdgeMonth","handleYearChange","target","value","year","Number","parseInt","isNaN","expectedDate","Date","addedOffset","handleMonthChange","yearDiff","monthDiff","yearSelectOptions","getYearSelectOptions","monthSelectOptions","getMonthSelectOptions","jsx","className","clsx","children","onKeyDown","jsxs","onClick","ArrowLeftIcon","variant","bold","ArrowRightIcon","onChange","map","label","ChevronDownIcon","calendar","month","weekday","weeks","week","weekIndex","index","today","dateObj","tabIndex","toLowerCase","disabled","displayName"],"mappings":"u7DAmCMA,EAAgB,CAClB,SACA,UACA,OACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,YAGEC,EAAc,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,OAElDC,EAAWC,EAAAA,YAA0C,CAACC,EAAOC,KAChE,MACFC,OAAAA,EACAC,KAAAA,EACAC,gBAAAA,EACAC,QAAAA,EACAC,QAAAA,EACAC,QAAAA,EACAC,KAAAA,EAAOX,EACPY,OAAAA,EAASb,EACTc,WAAAA,EAAa,aACbC,UAAAA,EAAY,UACZC,YAAAA,EAAcC,EAAAA,sBACdC,aAAAA,KACGC,GACHf,EAEEgB,EAAKC,QAAM,kBAERC,OAAAA,EAAQC,aAAAA,EAAcC,UAAAA,GAAaC,GAAYC,EAAAA,WACpDC,EAAAA,gBACAC,EAAAA,oBAAoBrB,EAAMC,EAAiBE,EAASC,GACpDkB,EAAAA,qBAGEC,EAAaN,EAAUO,WACvBC,EAAYR,EAAUS,cAE5BC,EAAAA,WAAU,KACGT,EAAA,CACLU,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SAAAzG,EAAKmF,eAhB9Bd,EAkBT,KA/BH,GAAGgD,EAASC,QAAQD,EAAS7B,OAAOkC,WAfhD,GAAGL,EAASC,QAAQD,EAAS7B,cAsD9C,IAKZ7F,EAASsI,YAAc"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),i=require("./feedbackContext.js"),r=require("./followup/Followup.js"),n=require("./main-question/MainQuestion.js");require("../checkbox/Checkbox.js"),require("../../hooks/useScreen/useScreen.js"),require("../../hooks/useId/useId.js"),require("../tooltip/Tooltip.js"),require("../tooltip/TooltipContent.js"),require("../tooltip/TooltipTrigger.js"),require("../icon/Icon.js"),require("../icon/icons/animated/ArrowVerticalAnimated.js"),require("../icon/icons/animated/ArrowHorizontalAnimated.js"),require("../icon/icons/animated/PlusRemoveAnimated.js"),require("../icon/icons/ArrowDownIcon.js"),require("../icon/icons/ArrowLeftIcon.js"),require("../icon/icons/ArrowNorthEastIcon.js"),require("../icon/icons/ArrowRightIcon.js"),require("../icon/icons/ArrowUpIcon.js"),require("../icon/icons/CalendarIcon.js"),require("../icon/icons/CheckIcon.js"),require("../icon/icons/ChevronDownIcon.js"),require("../icon/icons/ChevronLeftIcon.js"),require("../icon/icons/ChevronRightIcon.js"),require("../icon/icons/ChevronUpIcon.js"),require("../icon/icons/CloseIcon.js"),require("../icon/icons/CopyIcon.js"),require("../icon/icons/DotsIcon.js"),require("../icon/icons/DragIcon.js"),require("../icon/icons/ErrorIcon.js"),require("../icon/icons/GreenCheckIcon.js"),require("../icon/icons/HamburgerIcon.js"),require("../icon/icons/InfoIcon.js"),require("../icon/icons/LinkIcon.js"),require("../icon/icons/PlusIcon.js"),require("../icon/icons/QuestionIcon.js"),require("../icon/icons/RedCrossIcon.js"),require("../icon/icons/SearchIcon.js"),require("../icon/icons/SuccessIcon.js"),require("../icon/icons/WarningIcon.js"),require("../icon/icons/MinusIcon.js"),require("../icon/icons/ThumbDownIcon.js"),require("../icon/icons/ThumbUpIcon.js"),require("../icon/icons/TrashCanIcon.js"),require("../icon/icons/PenIcon.js"),require("../input-group/InputGroup.js"),require("./followup/followupContext.js"),require("./main-question/mainQuestionContext.js"),require("../radio-button/RadioButton.js"),require("../radio-button/radioGroupContext.js"),require("../radio-button/BaseRadioButton.js"),require("../text-input/BaseTextArea.js"),require("../text-input/BaseTextInput.js"),require("../text-input/TextArea.js"),require("../text-input/TextInput.js");const s=require("./questions/ContactQuestion.js");exports.Feedback=({className:c,followup:t,contactQuestion:u,counter:a,...j})=>{const[q,l]=o.useState(!1),[d,I]=o.useState(!1),[p,x]=o.useState(!1),[b,m]=o.useState(!1);return e.jsx("div",{className:`jkl-feedback ${c||""}`,"data-testid":"feedback",children:e.jsxs(i.FeedbackContextProvider,{value:{feedbackSubmitted:q,followupStarted:d,followupSubmitted:p,contactSubmitted:b,counter:a,setFeedbackSubmitted:l,setFollowupStarted:I,setFollowupSubmitted:x,setContactSubmitted:m},children:[!d&&e.jsx(n.MainQuestion,{...j}),q&&!b&&t&&e.jsx(r.Followup,{...t}),u&&e.jsx("div",{"aria-live":"polite",children:(!t&&q||p)&&e.jsx(s.ContactQuestion,{...u})})]})})};
|
|
2
|
+
//# sourceMappingURL=Feedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Feedback.js","sources":["../../../../src/components/feedback/Feedback.tsx"],"sourcesContent":["import React, { ReactElement, ReactNode, useState, ComponentProps } from \"react\";\nimport { BaseTextAreaProps } from \"../text-input\";\nimport { FeedbackContextProvider } from \"./feedbackContext\";\nimport { Followup } from \"./followup/Followup\";\nimport { MainQuestion } from \"./main-question/MainQuestion\";\nimport { ContactQuestion } from \"./questions\";\nimport { FeedbackOption, FeedbackType } from \"./types\";\n\ntype FollowupProps = ComponentProps<typeof Followup>;\ntype ContactQuestionProps = ComponentProps<typeof ContactQuestion>;\n\ntype Props = {\n className?: string;\n /** Velg typen alternativer, Smiley eller RadioButtons. */\n type: \"radio\" | \"smiley\";\n /** Spørsmålet som stilles til brukeren */\n label: string;\n /** Hjelpetekst til hovedspørsmålet */\n helpLabel?: string;\n /** Svaralternativer til spørsmålet */\n options: FeedbackOption[];\n /** Dersom du vil stille et åpent spørsmål i tillegg kan du sette denne til en truthy verdi */\n addOnQuestion?:\n | {\n /** Spørsmålet du vil stille */\n label?: string;\n /** Eventuell hjelpetekst. Om du ikke spesifiserer en vil det vises en påminnelse om å ikke skrive inn personling informasjon. */\n helpLabel?: string;\n }\n | boolean;\n /** Lar deg tilpasse meldingen som kommer når brukeren sender inn tilbakemeldingen. */\n successMessage?: {\n title: string;\n children: ReactNode;\n };\n /**\n * Funksjon for å håndtere innsending av tilbakemelding\n * @param value Verdien av tilbakemeldingen. Dette er et objekt med følgende egenskaper:\n * - `feedbackValue`: Selve verdien av tilbakemeldingen (format varierer etter spørsmålstype)\n * - `intentionalSubmit`: Er `true` hvis brukeren aktivt sendte inn skjemaet, `false` hvis skjemaet ble sendt inn automatisk\n * - `message`: Eventuell utfyllende melding fra bruker. Blir kun sendt inn ved aktiv innsending\n */\n onSubmit: (value: FeedbackType) => void;\n\n followup?: FollowupProps;\n contactQuestion?: ContactQuestionProps;\n} & Pick<BaseTextAreaProps, \"counter\">;\n\nexport const Feedback = ({\n className,\n followup,\n contactQuestion,\n counter,\n ...mainQuestionProps\n}: Props): ReactElement => {\n const [feedbackSubmitted, setFeedbackSubmitted] = useState(false);\n const [followupStarted, setFollowupStarted] = useState(false);\n const [followupSubmitted, setFollowupSubmitted] = useState(false);\n const [contactSubmitted, setContactSubmitted] = useState(false);\n\n return (\n <div className={`jkl-feedback ${className || \"\"}`} data-testid=\"feedback\">\n <FeedbackContextProvider\n value={{\n feedbackSubmitted,\n followupStarted,\n followupSubmitted,\n contactSubmitted,\n counter,\n setFeedbackSubmitted,\n setFollowupStarted,\n setFollowupSubmitted,\n setContactSubmitted,\n }}\n >\n {!followupStarted && <MainQuestion {...mainQuestionProps} />}\n {feedbackSubmitted && !contactSubmitted && followup && <Followup {...followup} />}\n {contactQuestion && (\n <div aria-live=\"polite\">\n {/* Show contact question after followup, or after feedback if no followup */}\n {((!followup && feedbackSubmitted) || followupSubmitted) && (\n <ContactQuestion {...contactQuestion} />\n )}\n </div>\n )}\n </FeedbackContextProvider>\n </div>\n );\n};\n"],"names":["className","followup","contactQuestion","counter","mainQuestionProps","feedbackSubmitted","setFeedbackSubmitted","useState","followupStarted","setFollowupStarted","followupSubmitted","setFollowupSubmitted","contactSubmitted","setContactSubmitted","jsx","children","jsxs","FeedbackContextProvider","value","MainQuestion","Followup","ContactQuestion"],"mappings":"23EAgDwB,EACpBA,UAAAA,EACAC,SAAAA,EACAC,gBAAAA,EACAC,QAAAA,KACGC,MAEH,MAAOC,EAAmBC,GAAwBC,YAAS,IACpDC,EAAiBC,GAAsBF,YAAS,IAChDG,EAAmBC,GAAwBJ,YAAS,IACpDK,EAAkBC,GAAuBN,YAAS,GAGrD,OAAAO,MAAC,OAAId,UAAW,gBAAgBA,GAAa,KAAM,cAAY,WAC3De,SAAAC,EAAAA,KAACC,EAAAA,wBAAA,CACGC,MAAO,CACHb,kBAAAA,EACAG,gBAAAA,EACAE,kBAAAA,EACAE,iBAAAA,EACAT,QAAAA,EACAG,qBAAAA,EACAG,mBAAAA,EACAE,qBAAAA,EACAE,oBAAAA,GAGHE,SAAA,EAACP,GAAmBM,EAAAA,IAACK,EAAcA,aAAA,IAAGf,IACtCC,IAAsBO,GAAoBX,GAAaa,EAAAA,IAAAM,WAAA,IAAanB,IACpEC,GACGY,EAAAA,IAAC,MAAI,CAAA,YAAU,SAERC,WAACd,GAAYI,GAAsBK,IAClCI,MAACO,EAAAA,gBAAiB,IAAGnB,UAKzC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("../../../clsx-E3yX_9sL.cjs"),r=require("../message/Message.js");require("../message/FormErrorMessage.js");exports.FeedbackSuccess=({children:a,className:c,...i})=>e.jsx(r.SuccessMessage,{className:s.clsx("jkl-feedback__fade-in",c),...i,"aria-live":"polite",children:a});
|
|
2
|
+
//# sourceMappingURL=FeedbackSuccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedbackSuccess.js","sources":["../../../../src/components/feedback/FeedbackSuccess.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { FC } from \"react\";\nimport { SuccessMessage, MessageProps } from \"../message\";\n\nexport const FeedbackSuccess: FC<MessageProps> = ({ children, className, ...rest }) => (\n <SuccessMessage className={clsx(\"jkl-feedback__fade-in\", className)} {...rest} aria-live=\"polite\">\n {children}\n </SuccessMessage>\n);\n"],"names":["children","className","rest","jsx","SuccessMessage","clsx"],"mappings":"kQAIiD,EAAGA,SAAAA,EAAUC,UAAAA,KAAcC,KACxEC,EAAAA,IAACC,kBAAeH,UAAWI,EAAAA,KAAK,wBAAyBJ,MAAgBC,EAAM,YAAU,SACpFF,SAAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.HAPPY={label:"Fornøyd",value:4},exports.NEUTRAL={label:"Verken fornøyd eller misfornøyd",value:3},exports.UNHAPPY={label:"Ikke fornøyd",value:2},exports.VERY_HAPPY={label:"Veldig fornøyd",value:5},exports.VERY_UNHAPPY={label:"Ikke fornøyd i det hele tatt",value:1};
|
|
2
|
+
//# sourceMappingURL=FeedbackValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedbackValues.js","sources":["../../../../src/components/feedback/FeedbackValues.tsx"],"sourcesContent":["import { FeedbackOption } from \"./types\";\n\nexport const VERY_UNHAPPY: FeedbackOption = { label: \"Ikke fornøyd i det hele tatt\", value: 1 };\nexport const UNHAPPY: FeedbackOption = { label: \"Ikke fornøyd\", value: 2 };\nexport const NEUTRAL: FeedbackOption = { label: \"Verken fornøyd eller misfornøyd\", value: 3 };\nexport const HAPPY: FeedbackOption = { label: \"Fornøyd\", value: 4 };\nexport const VERY_HAPPY: FeedbackOption = { label: \"Veldig fornøyd\", value: 5 };\n"],"names":["label","value"],"mappings":"8FAKqC,CAAEA,MAAO,UAAWC,MAAO,mBADzB,CAAED,MAAO,kCAAmCC,MAAO,mBADnD,CAAED,MAAO,eAAgBC,MAAO,sBAG7B,CAAED,MAAO,iBAAkBC,MAAO,wBAJhC,CAAED,MAAO,+BAAgCC,MAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),o=t.createContext({feedbackSubmitted:!1,followupStarted:!1,followupSubmitted:!1,contactSubmitted:!1,setFeedbackSubmitted:()=>null,setFollowupStarted:()=>null,setFollowupSubmitted:()=>null,setContactSubmitted:()=>null});exports.FeedbackContextProvider=({value:t,children:u})=>e.jsx(o.Provider,{value:t,children:u}),exports.useFeedbackContext=()=>t.useContext(o);
|
|
2
|
+
//# sourceMappingURL=feedbackContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedbackContext.js","sources":["../../../../src/components/feedback/feedbackContext.tsx"],"sourcesContent":["import React, { createContext, FC, useContext } from \"react\";\nimport { WithChildren } from \"../..\";\nimport { BaseTextAreaProps } from \"../text-input\";\n\ntype FeedbackContext = {\n feedbackSubmitted: boolean;\n followupStarted: boolean;\n followupSubmitted: boolean;\n contactSubmitted: boolean;\n setFeedbackSubmitted: (state: boolean) => void;\n setFollowupStarted: (state: boolean) => void;\n setFollowupSubmitted: (state: boolean) => void;\n setContactSubmitted: (state: boolean) => void;\n} & Pick<BaseTextAreaProps, \"counter\">;\n\nconst initialState: FeedbackContext = {\n feedbackSubmitted: false,\n followupStarted: false,\n followupSubmitted: false,\n contactSubmitted: false,\n setFeedbackSubmitted: () => null,\n setFollowupStarted: () => null,\n setFollowupSubmitted: () => null,\n setContactSubmitted: () => null,\n};\n\nconst feedbackContext = createContext(initialState);\n\nexport const useFeedbackContext = (): FeedbackContext => useContext(feedbackContext);\n\ninterface FeedbackContextProviderProps extends WithChildren {\n value: FeedbackContext;\n}\n\nexport const FeedbackContextProvider: FC<FeedbackContextProviderProps> = ({ value, children }) => (\n <feedbackContext.Provider value={value}>{children}</feedbackContext.Provider>\n);\n"],"names":["feedbackContext","createContext","feedbackSubmitted","followupStarted","followupSubmitted","contactSubmitted","setFeedbackSubmitted","setFollowupStarted","setFollowupSubmitted","setContactSubmitted","value","children","jsx","Provider","useContext"],"mappings":"wIA0BMA,EAAkBC,EAAAA,cAXc,CAClCC,mBAAmB,EACnBC,iBAAiB,EACjBC,mBAAmB,EACnBC,kBAAkB,EAClBC,qBAAsB,IAAM,KAC5BC,mBAAoB,IAAM,KAC1BC,qBAAsB,IAAM,KAC5BC,oBAAqB,IAAM,uCAW0C,EAAGC,MAAAA,EAAOC,SAAAA,KAC/EC,MAACZ,EAAgBa,SAAhB,CAAyBH,MAAAA,EAAeC,SAAAA,+BAPX,IAAuBG,EAAAA,WAAWd"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react");require("../../../hooks/useScreen/useScreen.js"),require("../../../hooks/useId/useId.js"),require("../../icon/Icon.js"),require("../../icon/icons/animated/ArrowVerticalAnimated.js"),require("../../icon/icons/animated/ArrowHorizontalAnimated.js"),require("../../icon/icons/animated/PlusRemoveAnimated.js"),require("../../icon/icons/ArrowDownIcon.js"),require("../../icon/icons/ArrowLeftIcon.js"),require("../../icon/icons/ArrowNorthEastIcon.js"),require("../../icon/icons/ArrowRightIcon.js"),require("../../icon/icons/ArrowUpIcon.js"),require("../../icon/icons/CalendarIcon.js"),require("../../icon/icons/CheckIcon.js"),require("../../icon/icons/ChevronDownIcon.js"),require("../../icon/icons/ChevronLeftIcon.js"),require("../../icon/icons/ChevronRightIcon.js"),require("../../icon/icons/ChevronUpIcon.js"),require("../../icon/icons/CloseIcon.js"),require("../../icon/icons/CopyIcon.js"),require("../../icon/icons/DotsIcon.js"),require("../../icon/icons/DragIcon.js"),require("../../icon/icons/ErrorIcon.js"),require("../../icon/icons/GreenCheckIcon.js"),require("../../icon/icons/HamburgerIcon.js"),require("../../icon/icons/InfoIcon.js"),require("../../icon/icons/LinkIcon.js"),require("../../icon/icons/PlusIcon.js"),require("../../icon/icons/QuestionIcon.js"),require("../../icon/icons/RedCrossIcon.js"),require("../../icon/icons/SearchIcon.js"),require("../../icon/icons/SuccessIcon.js"),require("../../icon/icons/WarningIcon.js"),require("../../icon/icons/MinusIcon.js"),require("../../icon/icons/ThumbDownIcon.js"),require("../../icon/icons/ThumbUpIcon.js"),require("../../icon/icons/TrashCanIcon.js"),require("../../icon/icons/PenIcon.js");const i=require("../../button/Button.js");require("../../card/Card.js"),require("../../card/CardImage.js"),require("../../card/NavCard.js"),require("../../checkbox/Checkbox.js"),require("../../combobox/Combobox.js"),require("../../cookie-consent/CookieConsentContext.js"),require("react-dom"),require("../../modal/Modal.js"),require("react-a11y-dialog"),require("../../list/List.js"),require("../../list/ListItem.js"),require("../../datepicker/DatePicker.js");const o=require("../feedbackContext.js"),s=require("../FeedbackSuccess.js");require("../../tooltip/Tooltip.js"),require("../../tooltip/TooltipContent.js"),require("../../tooltip/TooltipTrigger.js"),require("../../input-group/InputGroup.js");const n=require("./followupContext.js");require("../main-question/mainQuestionContext.js"),require("../../radio-button/RadioButton.js"),require("../../radio-button/radioGroupContext.js"),require("../../radio-button/BaseRadioButton.js"),require("../../text-input/BaseTextArea.js"),require("../../text-input/BaseTextInput.js"),require("../../text-input/TextArea.js"),require("../../text-input/TextInput.js"),require("../../../utilities/polymorphism/SlotComponent.js");const t=require("../utils.js");require("../../icon-button/IconButton.js"),require("../../link/Link.js"),require("../../link/NavLink.js"),require("../../link-list/LinkList.js"),require("../../message/Message.js"),require("../../message/FormErrorMessage.js"),require("../../popover/Popover.js"),require("../../../../NativeSelect-CNcZmpDZ.cjs"),require("../../tag/Tag.js");const c=require("./useFollowup.js"),u={title:"Takk, igjen!",children:"Vi setter pris på at du tok deg tid til å svare på flere spørsmål. Det hjelper oss med å gjøre nettsidene bedre for deg og alle andre som bruker dem."};exports.Followup=({questions:a,successMessage:l=u,onSubmit:j})=>{const[q,d]=r.useState(!1),p=r.useRef(null),m=c.useFollowup(a,j),{handleAbort:k,handleNext:b,step:x,submitted:I}=m,{followupStarted:g,setFollowupStarted:h,setFollowupSubmitted:C,contactSubmitted:f}=o.useFeedbackContext();r.useEffect((()=>{0!==x.number&&p.current&&p.current.focus()}),[x]),r.useEffect((()=>{C(I)}),[I,C]);const v=t.getQuestionFromType(a[x.number].type),S=x.isLast?i.PrimaryButton:i.SecondaryButton;return q?null:e.jsx("div",{"aria-live":"polite",children:e.jsxs(n.FollowUpProvider,{state:m,children:[!g&&e.jsxs("div",{className:"jkl-feedback__fade-in",children:[e.jsx("p",{className:"jkl-heading-4 jkl-spacing-xl--top jkl-spacing-xs--bottom",children:"Har du tid til å svare på noen flere spørsmål?"}),e.jsx("p",{className:"jkl-body jkl-spacing-xl--bottom",children:"Det tar kun et minutt, og hjelper oss å lage bedre løsninger for deg."}),e.jsx(i.PrimaryButton,{onClick:()=>h(!0),className:"jkl-spacing-xl--right",children:"Jeg har tid!"}),e.jsx(i.TertiaryButton,{onClick:()=>d(!0),children:"Nei takk"})]}),!I&&g&&e.jsxs("form",{onSubmit:b,className:"jkl-feedback__fade-in",children:[e.jsxs("p",{className:"jkl-feedback__step-counter",ref:p,children:["Steg ",x.number+1," av ",a.length]}),r.createElement(v,{...a[x.number],autoFocus:!0,key:x.number}),e.jsxs("div",{className:"jkl-spacing-xl--top","aria-live":"off",children:[e.jsx(S,{type:"submit",children:x.isLast?"Send inn":"Neste"}),e.jsx(i.TertiaryButton,{onClick:k,className:"jkl-spacing-xl--left",children:"Avbryt"})]})]}),I&&!f&&e.jsx(s.FeedbackSuccess,{...l})]})})};
|
|
2
|
+
//# sourceMappingURL=Followup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Followup.js","sources":["../../../../../src/components/feedback/followup/Followup.tsx"],"sourcesContent":["import React, { ReactNode, useEffect, useRef, useState, FC } from \"react\";\nimport { PrimaryButton, SecondaryButton, TertiaryButton } from \"../..\";\nimport { useFeedbackContext } from \"../feedbackContext\";\nimport { FeedbackSuccess } from \"../FeedbackSuccess\";\nimport { FeedbackAnswer, FollowupQuestion } from \"../types\";\nimport { getQuestionFromType } from \"../utils\";\nimport { FollowUpProvider } from \"./followupContext\";\nimport { useFollowup } from \"./useFollowup\";\n\nconst defaultSuccessMessage = {\n title: \"Takk, igjen!\",\n children:\n \"Vi setter pris på at du tok deg tid til å svare på flere spørsmål. Det hjelper oss med å gjøre nettsidene bedre for deg og alle andre som bruker dem.\",\n};\n\ninterface Props {\n /** Spørsmålet/ene som skal stilles. Kan være av typen radio, checkbox eller text */\n questions: FollowupQuestion[];\n /** Lar deg tilpasse meldingen som kommer når brukeren har svart på spørsmålene. */\n successMessage?: {\n title: string;\n children: ReactNode;\n };\n onSubmit: (values: FeedbackAnswer[]) => void;\n}\n\nexport const Followup: FC<Props> = ({ questions, successMessage = defaultSuccessMessage, onSubmit }) => {\n const [noThanks, setNoThanks] = useState(false);\n const focusRef = useRef<HTMLParagraphElement>(null);\n const followupState = useFollowup(questions, onSubmit);\n const { handleAbort, handleNext, step, submitted } = followupState;\n const { followupStarted, setFollowupStarted, setFollowupSubmitted, contactSubmitted } = useFeedbackContext();\n\n useEffect(() => {\n if (step.number === 0) {\n return;\n }\n focusRef.current && focusRef.current.focus();\n }, [step]);\n\n useEffect(() => {\n setFollowupSubmitted(submitted);\n }, [submitted, setFollowupSubmitted]);\n\n const QuestionComponent = getQuestionFromType(questions[step.number].type);\n const Button = step.isLast ? PrimaryButton : SecondaryButton;\n\n if (noThanks) {\n return null;\n }\n\n return (\n <div aria-live=\"polite\">\n <FollowUpProvider state={followupState}>\n {!followupStarted && (\n <div className=\"jkl-feedback__fade-in\">\n <p className=\"jkl-heading-4 jkl-spacing-xl--top jkl-spacing-xs--bottom\">\n Har du tid til å svare på noen flere spørsmål?\n </p>\n <p className=\"jkl-body jkl-spacing-xl--bottom\">\n Det tar kun et minutt, og hjelper oss å lage bedre løsninger for deg.\n </p>\n <PrimaryButton onClick={() => setFollowupStarted(true)} className=\"jkl-spacing-xl--right\">\n Jeg har tid!\n </PrimaryButton>\n <TertiaryButton onClick={() => setNoThanks(true)}>Nei takk</TertiaryButton>\n </div>\n )}\n {!submitted && followupStarted && (\n <form onSubmit={handleNext} className=\"jkl-feedback__fade-in\">\n <p className=\"jkl-feedback__step-counter\" ref={focusRef}>\n Steg {step.number + 1} av {questions.length}\n </p>\n {/* eslint-disable-next-line jsx-a11y/no-autofocus */}\n <QuestionComponent {...questions[step.number]} autoFocus key={step.number} />\n <div className=\"jkl-spacing-xl--top\" aria-live=\"off\">\n <Button type=\"submit\">{step.isLast ? \"Send inn\" : \"Neste\"}</Button>\n <TertiaryButton onClick={handleAbort} className=\"jkl-spacing-xl--left\">\n Avbryt\n </TertiaryButton>\n </div>\n </form>\n )}\n {submitted && !contactSubmitted && <FeedbackSuccess {...successMessage} />}\n </FollowUpProvider>\n </div>\n );\n};\n"],"names":["defaultSuccessMessage","title","children","questions","successMessage","onSubmit","noThanks","setNoThanks","useState","focusRef","useRef","followupState","useFollowup","handleAbort","handleNext","step","submitted","followupStarted","setFollowupStarted","setFollowupSubmitted","contactSubmitted","useFeedbackContext","useEffect","number","current","focus","QuestionComponent","getQuestionFromType","type","Button","isLast","PrimaryButton","SecondaryButton","jsxs","FollowUpProvider","state","className","jsx","onClick","TertiaryButton","ref","length","createElement","autoFocus","key","FeedbackSuccess"],"mappings":"4xGASMA,EAAwB,CAC1BC,MAAO,eACPC,SACI,0KAc2B,EAAGC,UAAAA,EA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AUY,EAAKQ,QAASoB,WAAS,EAACC,IAAK7B,EAAKQ,SAClEU,EAAAA,KAAA,MAAA,CAAIG,UAAU,sBAAsB,YAAU,MAC3ClC,SAAA,CAAAmC,MAACR,GAAOD,KAAK,SAAU1B,SAAKa,EAAAe,OAAS,WAAa,gBACjDS,EAAAA,eAAe,CAAAD,QAASzB,EAAauB,UAAU,uBAAuBlC,SAEvE,iBAIXc,IAAcI,GAAqBiB,EAAAA,IAAAQ,EAAAA,gBAAA,IAAoBzC,QAEhE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),r=t.createContext(void 0);exports.FollowUpProvider=({state:t,children:o})=>e.jsx(r.Provider,{value:t,children:o}),exports.useFollowUpContext=()=>t.useContext(r);
|
|
2
|
+
//# sourceMappingURL=followupContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"followupContext.js","sources":["../../../../../src/components/feedback/followup/followupContext.tsx"],"sourcesContent":["import React, { createContext, useContext } from \"react\";\nimport { WithChildren } from \"../../..\";\nimport { FollowupState } from \"../types\";\n\nconst followUpContext = createContext<FollowupState | undefined>(undefined);\n\nexport const useFollowUpContext = (): FollowupState | undefined => useContext(followUpContext);\n\ninterface FollowupContextProviderProps extends WithChildren {\n state: FollowupState;\n}\n\nexport const FollowUpProvider: React.FC<FollowupContextProviderProps> = ({ state, children }) => (\n <followUpContext.Provider value={state}>{children}</followUpContext.Provider>\n);\n"],"names":["followUpContext","createContext","state","children","jsx","Provider","value","useContext"],"mappings":"wIAIMA,EAAkBC,EAAAA,mBAAyC,4BAQO,EAAGC,MAAAA,EAAOC,SAAAA,KAC7EC,EAAAA,IAAAJ,EAAgBK,SAAhB,CAAyBC,MAAOJ,EAAQC,SAAAA,+BAPX,IAAiCI,EAAAA,WAAWP"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useFollowup=(t,u)=>{const[n,s]=e.useState(),[r,o]=e.useState({number:0,question:t[0],isLast:1===t.length}),[a,i]=e.useState(!1),[l,c]=e.useState(!1),[d,v]=e.useState(),b=e.useRef({values:n,submitted:l,onSubmit:u});e.useEffect((()=>{b.current={...b.current,values:n,submitted:l}}),[n,l]);const m=e.useCallback((()=>{!b.current.submitted&&void 0!==b.current.values&&b.current.onSubmit(b.current.values)}),[]);return e.useEffect((()=>{a&&(m(),c(!0))}),[a,m]),e.useEffect((()=>(typeof window<"u"&&window.addEventListener("beforeunload",m),()=>{m(),window.removeEventListener("beforeunload",m)})),[m]),{questions:t,values:n,step:r,currentValue:d,setCurrentValue:v,submitted:l,handleNext:function(e){null==e||e.preventDefault();const u=Array.isArray(d)?d.map((e=>e.value.toString())):null==d?void 0:d.value,n={...r.question,name:r.question.name||r.question.label,value:u};s((e=>[...(null==e?void 0:e.filter((e=>e.name!==n.name)))||[],n])),v(void 0),r.isLast?i(!0):o((e=>{const u=e.number+1;return{number:u,question:t[u],isLast:u+1>=t.length}}))},handleAbort:function(){s(void 0),v(void 0),o({number:0,question:t[0],isLast:1===t.length}),c(!0)}}};
|
|
2
|
+
//# sourceMappingURL=useFollowup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFollowup.js","sources":["../../../../../src/components/feedback/followup/useFollowup.ts"],"sourcesContent":["import { Dispatch, FormEvent, SetStateAction, useCallback, useEffect, useRef, useState } from \"react\";\nimport { FeedbackAnswer, FeedbackOption, FollowupQuestion } from \"../types\";\n\ntype CurrentValue = FeedbackOption<string | number> | FeedbackOption<string | number>[] | undefined;\n\ntype Followup = {\n questions: FollowupQuestion[];\n values: FeedbackAnswer[] | undefined;\n step: {\n number: number;\n question: FollowupQuestion;\n isLast: boolean;\n };\n currentValue: CurrentValue;\n setCurrentValue: Dispatch<SetStateAction<CurrentValue>>;\n submitted: boolean;\n handleNext: () => void;\n handleAbort: () => void;\n};\n\nexport const useFollowup = (questions: FollowupQuestion[], onSubmit: (a: FeedbackAnswer[]) => void): Followup => {\n const [values, setValues] = useState<FeedbackAnswer[]>();\n const [step, setStep] = useState({\n number: 0,\n question: questions[0],\n isLast: questions.length === 1,\n });\n const [shouldSubmit, setShouldSubmit] = useState(false);\n const [submitted, setSubmitted] = useState(false);\n const [currentValue, setCurrentValue] = useState<FeedbackOption | FeedbackOption[]>();\n\n // Store info in a ref to facilitate autosubmit on component unmount,\n // or when leaving page\n const followupRef = useRef({\n values,\n submitted,\n onSubmit,\n });\n\n // Keep values in ref updated\n useEffect(() => {\n followupRef.current = {\n ...followupRef.current,\n values,\n submitted,\n };\n }, [values, submitted]);\n\n // General method for submitting info\n const _handleSubmit = useCallback(() => {\n if (!followupRef.current.submitted && followupRef.current.values !== undefined) {\n followupRef.current.onSubmit(followupRef.current.values);\n }\n }, []);\n\n // Function for handling going to the next step in the form wizard\n function handleNext(e?: FormEvent<HTMLFormElement>) {\n e?.preventDefault();\n\n const value = Array.isArray(currentValue)\n ? currentValue.map((option) => option.value.toString())\n : currentValue?.value;\n\n const newValue = {\n ...step.question,\n name: step.question.name || step.question.label,\n value,\n };\n\n setValues((oldValues) => {\n const filteredValues = oldValues?.filter((oldValue) => oldValue.name !== newValue.name) || [];\n return [...filteredValues, newValue as FeedbackAnswer];\n });\n setCurrentValue(undefined);\n\n if (step.isLast) {\n setShouldSubmit(true);\n } else {\n setStep((currentStep) => {\n const newStepNum = currentStep.number + 1;\n return {\n number: newStepNum,\n question: questions[newStepNum],\n isLast: newStepNum + 1 >= questions.length,\n };\n });\n }\n }\n\n // Let the user abort without submitting answers\n function handleAbort() {\n setValues(undefined);\n setCurrentValue(undefined);\n setStep({\n number: 0,\n question: questions[0],\n isLast: questions.length === 1,\n });\n setSubmitted(true);\n }\n\n // Submit info after user submits last question\n useEffect(() => {\n if (shouldSubmit) {\n _handleSubmit();\n setSubmitted(true);\n }\n }, [shouldSubmit, _handleSubmit]);\n\n // Submit info if component unmounts or page unloads\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"beforeunload\", _handleSubmit);\n }\n return () => {\n _handleSubmit();\n window.removeEventListener(\"beforeunload\", _handleSubmit);\n };\n }, [_handleSubmit]);\n\n return { questions, values, step, currentValue, setCurrentValue, submitted, handleNext, handleAbort };\n};\n"],"names":["questions","onSubmit","values","setValues","useState","step","setStep","number","question","isLast","length","shouldSubmit","setShouldSubmit","submitted","setSubmitted","currentValue","setCurrentValue","followupRef","useRef","useEffect","current","_handleSubmit","useCallback","window","addEventListener","removeEventListener","handleNext","e","preventDefault","value","Array","isArray","map","option","toString","newValue","name","label","oldValues","filter","oldValue","currentStep","newStepNum","handleAbort"],"mappings":"6HAoB2B,CAACA,EAA+BC,KACvD,MAAOC,EAAQC,GAAaC,EAA2BA,YAChDC,EAAMC,GAAWF,WAAS,CAC7BG,OAAQ,EACRC,SAAUR,EAAU,GACpBS,OAA6B,IAArBT,EAAUU,UAEfC,EAAcC,GAAmBR,YAAS,IAC1CS,EAAWC,GAAgBV,YAAS,IACpCW,EAAcC,GAAmBZ,EAA4CA,WAI9Ea,EAAcC,EAAAA,OAAO,CACvBhB,OAAAA,EACAW,UAAAA,EACAZ,SAAAA,IAIJkB,EAAAA,WAAU,KACNF,EAAYG,QAAU,IACfH,EAAYG,QACflB,OAAAA,EACAW,UAAAA,EAAA,GAEL,CAACX,EAAQW,IAGN,MAAAQ,EAAgBC,EAAAA,aAAY,MACzBL,EAAYG,QAAQP,gBAA4C,IAA/BI,EAAYG,QAAQlB,QACtDe,EAAYG,QAAQnB,SAASgB,EAAYG,QAAQlB,OAAM,GAE5D,IAiDHiB,OAAAA,EAAAA,WAAU,KACFR,IACcU,IACdP,GAAa,GACjB,GACD,CAACH,EAAcU,IAGlBF,EAAAA,WAAU,YACKI,OAAW,KACXA,OAAAC,iBAAiB,eAAgBH,GAErC,KACWA,IACPE,OAAAE,oBAAoB,eAAgBJ,EAAa,IAE7D,CAACA,IAEG,CAAErB,UAAAA,EAAWE,OAAAA,EAAQG,KAAAA,EAAMU,aAAAA,EAAcC,gBAAAA,EAAiBH,UAAAA,EAAWa,WAhE5E,SAAoBC,GAChB,MAAAA,GAAAA,EAAGC,iBAEH,MAAMC,EAAQC,MAAMC,QAAQhB,GACtBA,EAAaiB,KAAKC,GAAWA,EAAOJ,MAAMK,aAC1C,MAAAnB,OAAA,EAAAA,EAAcc,MAEdM,EAAW,IACV9B,EAAKG,SACR4B,KAAM/B,EAAKG,SAAS4B,MAAQ/B,EAAKG,SAAS6B,MAC1CR,MAAAA,GAGJ1B,GAAWmC,GAEA,KADgB,MAAAA,OAAAA,EAAAA,EAAWC,QAAQC,GAAaA,EAASJ,OAASD,EAASC,SAAS,GAChED,KAE/BnB,OAAgB,GAEZX,EAAKI,OACLG,GAAgB,GAEhBN,GAASmC,IACC,MAAAC,EAAaD,EAAYlC,OAAS,EACjC,MAAA,CACHA,OAAQmC,EACRlC,SAAUR,EAAU0C,GACpBjC,OAAQiC,EAAa,GAAK1C,EAAUU,OAAA,GAIpD,EAiCwFiC,YA9BxF,WACIxC,OAAU,GACVa,OAAgB,GACRV,EAAA,CACJC,OAAQ,EACRC,SAAUR,EAAU,GACpBS,OAA6B,IAArBT,EAAUU,SAEtBI,GAAa,EACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("../../../../clsx-E3yX_9sL.cjs"),o=require("react"),r=require("../../../hooks/useAnimatedHeight/useAnimatedHeight.js");require("../../../hooks/useScreen/useScreen.js"),require("../../../hooks/useId/useId.js");const n=require("../../button/Button.js"),s=require("../feedbackContext.js"),c=require("../FeedbackSuccess.js");require("../../checkbox/Checkbox.js"),require("../../tooltip/Tooltip.js"),require("../../tooltip/TooltipContent.js"),require("../../tooltip/TooltipTrigger.js"),require("../../icon/Icon.js"),require("../../icon/icons/animated/ArrowVerticalAnimated.js"),require("../../icon/icons/animated/ArrowHorizontalAnimated.js"),require("../../icon/icons/animated/PlusRemoveAnimated.js"),require("../../icon/icons/ArrowDownIcon.js"),require("../../icon/icons/ArrowLeftIcon.js"),require("../../icon/icons/ArrowNorthEastIcon.js"),require("../../icon/icons/ArrowRightIcon.js"),require("../../icon/icons/ArrowUpIcon.js"),require("../../icon/icons/CalendarIcon.js"),require("../../icon/icons/CheckIcon.js"),require("../../icon/icons/ChevronDownIcon.js"),require("../../icon/icons/ChevronLeftIcon.js"),require("../../icon/icons/ChevronRightIcon.js"),require("../../icon/icons/ChevronUpIcon.js"),require("../../icon/icons/CloseIcon.js"),require("../../icon/icons/CopyIcon.js"),require("../../icon/icons/DotsIcon.js"),require("../../icon/icons/DragIcon.js"),require("../../icon/icons/ErrorIcon.js"),require("../../icon/icons/GreenCheckIcon.js"),require("../../icon/icons/HamburgerIcon.js"),require("../../icon/icons/InfoIcon.js"),require("../../icon/icons/LinkIcon.js"),require("../../icon/icons/PlusIcon.js"),require("../../icon/icons/QuestionIcon.js"),require("../../icon/icons/RedCrossIcon.js"),require("../../icon/icons/SearchIcon.js"),require("../../icon/icons/SuccessIcon.js"),require("../../icon/icons/WarningIcon.js"),require("../../icon/icons/MinusIcon.js"),require("../../icon/icons/ThumbDownIcon.js"),require("../../icon/icons/ThumbUpIcon.js"),require("../../icon/icons/TrashCanIcon.js"),require("../../icon/icons/PenIcon.js"),require("../../input-group/InputGroup.js"),require("../followup/followupContext.js");const t=require("./mainQuestionContext.js");require("../../radio-button/RadioButton.js"),require("../../radio-button/radioGroupContext.js"),require("../../radio-button/BaseRadioButton.js"),require("../../text-input/BaseTextArea.js"),require("../../text-input/BaseTextInput.js"),require("../../text-input/TextArea.js"),require("../../text-input/TextInput.js");const u=require("../questions/AddonQuestion.js");require("../../../utilities/polymorphism/SlotComponent.js");const a=require("../utils.js"),j=require("./useMainQuestion.js"),l={title:"Takk for tilbakemeldingen!",children:"Husk at vi ikke kan besvare meldinger fra dette skjemaet. Kontakt gjerne din forsikringsrådgiver om du har flere spørsmål."};exports.MainQuestion=({label:q,options:d,type:p,addOnQuestion:b,successMessage:I=l,helpLabel:h,onSubmit:m})=>{const x=j.useMainQuestion(m),{setFeedbackSubmitted:k,contactSubmitted:g}=s.useFeedbackContext(),{handleSubmit:C,currentValue:f,setCurrentValue:v,submitted:A}=x,[T]=r.useAnimatedHeight(void 0!==f);o.useEffect((()=>{k(A)}),[A,k]);const w=a.getQuestionFromType(p);return e.jsxs(e.Fragment,{children:[!A&&e.jsxs(t.MainQuestionContextProvider,{state:x,children:[e.jsx(w,{label:q,options:d,helpLabel:h}),e.jsxs("div",{ref:T,className:i.clsx({"jkl-feedback__submit-wrapper":!0,"jkl-feedback__submit-wrapper--hidden":void 0===f}),children:[b&&e.jsx(u.AddonQuestion,{helpLabel:"object"==typeof b?b.helpLabel:void 0,label:"object"==typeof b?b.label:void 0}),e.jsxs("div",{className:"jkl-spacing-xl--top",children:[e.jsx(n.PrimaryButton,{onClick:C,className:"jkl-spacing-xl--right",children:"Send"}),e.jsx(n.TertiaryButton,{onClick:()=>v(void 0),children:"Avbryt"})]})]})]}),A&&!g&&e.jsx(c.FeedbackSuccess,{...I})]})};
|
|
2
|
+
//# sourceMappingURL=MainQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MainQuestion.js","sources":["../../../../../src/components/feedback/main-question/MainQuestion.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { ReactNode, useEffect, FC, ComponentProps } from \"react\";\nimport { useAnimatedHeight } from \"../../../hooks\";\nimport { PrimaryButton, TertiaryButton } from \"../../button\";\nimport { Feedback } from \"../Feedback\";\nimport { useFeedbackContext } from \"../feedbackContext\";\nimport { FeedbackSuccess } from \"../FeedbackSuccess\";\nimport { AddonQuestion } from \"../questions\";\nimport { FeedbackOption, FeedbackType } from \"../types\";\nimport { getQuestionFromType } from \"../utils\";\nimport { MainQuestionContextProvider } from \"./mainQuestionContext\";\nimport { useMainQuestion } from \"./useMainQuestion\";\n\nconst defaultSuccessMessage = {\n title: \"Takk for tilbakemeldingen!\",\n children:\n \"Husk at vi ikke kan besvare meldinger fra dette skjemaet. Kontakt gjerne din forsikringsrådgiver om du har flere spørsmål.\",\n};\n\ntype Props = Pick<ComponentProps<typeof Feedback>, \"addOnQuestion\"> & {\n type: \"radio\" | \"smiley\";\n label: string;\n helpLabel?: string;\n options: FeedbackOption[];\n successMessage?: {\n title: string;\n children: ReactNode;\n };\n onSubmit: (value: FeedbackType) => void;\n};\n\nexport const MainQuestion: FC<Props> = ({\n label,\n options,\n type,\n addOnQuestion,\n successMessage = defaultSuccessMessage,\n helpLabel,\n onSubmit,\n}) => {\n const mainQuestionState = useMainQuestion(onSubmit);\n\n const { setFeedbackSubmitted, contactSubmitted } = useFeedbackContext();\n const { handleSubmit, currentValue, setCurrentValue, submitted } = mainQuestionState;\n const [submitWrapperRef] = useAnimatedHeight<HTMLDivElement>(currentValue !== undefined);\n\n useEffect(() => {\n setFeedbackSubmitted(submitted);\n }, [submitted, setFeedbackSubmitted]);\n\n const MainQuestionComp = getQuestionFromType(type);\n\n return (\n <>\n {!submitted && (\n <MainQuestionContextProvider state={mainQuestionState}>\n <MainQuestionComp label={label} options={options} helpLabel={helpLabel} />\n <div\n ref={submitWrapperRef}\n className={clsx({\n \"jkl-feedback__submit-wrapper\": true,\n \"jkl-feedback__submit-wrapper--hidden\": currentValue === undefined,\n })}\n >\n {addOnQuestion && (\n <AddonQuestion\n helpLabel={typeof addOnQuestion === \"object\" ? addOnQuestion.helpLabel : undefined}\n label={typeof addOnQuestion === \"object\" ? addOnQuestion.label : undefined}\n />\n )}\n <div className=\"jkl-spacing-xl--top\">\n <PrimaryButton onClick={handleSubmit} className=\"jkl-spacing-xl--right\">\n Send\n </PrimaryButton>\n <TertiaryButton onClick={() => setCurrentValue(undefined)}>Avbryt</TertiaryButton>\n </div>\n </div>\n </MainQuestionContextProvider>\n )}\n {submitted && !contactSubmitted && <FeedbackSuccess {...successMessage} />}\n </>\n );\n};\n"],"names":["defaultSuccessMessage","title","children","label","options","type","addOnQuestion","successMessage","helpLabel","onSubmit","mainQuestionState","useMainQuestion","setFeedbackSubmitted","contactSubmitted","useFeedbackContext","handleSubmit","currentValue","setCurrentValue","submitted","submitWrapperRef","useAnimatedHeight","useEffect","MainQuestionComp","getQuestionFromType","jsxs","Fragment","MainQuestionContextProvider","state","jsx","ref","className","clsx","AddonQuestion","PrimaryButton","onClick","TertiaryButton","FeedbackSuccess"],"mappings":"+tFAaMA,EAAwB,CAC1BC,MAAO,6BACPC,SACI,mJAe+B,EACnCC,MAAAA,EACAC,QAAAA,EACAC,KAAAA,EACAC,cAAAA,EACAC,eAAAA,EAAiBP,EACjBQ,UAAAA,EACAC,SAAAA,MAEM,MAAAC,EAAoBC,kBAAgBF,IAElCG,qBAAAA,EAAsBC,iBAAAA,GAAqBC,EAAmBA,sBAC9DC,aAAAA,EAAcC,aAAAA,EAAcC,gBAAAA,EAAiBC,UAAAA,GAAcR,GAC5DS,GAAoBC,EAAAA,uBAAmD,IAAjBJ,GAE7DK,EAAAA,WAAU,KACNT,EAAqBM,EAAS,GAC/B,CAACA,EAAWN,IAET,MAAAU,EAAmBC,sBAAoBlB,GAE7C,OAESmB,EAAAA,KAAAC,WAAA,CAAAvB,SAAA,EAACgB,GACEM,EAAAA,KAACE,EAAAA,4BAA4B,CAAAC,MAAOjB,EAChCR,SAAA,CAAC0B,EAAAA,IAAAN,EAAA,CAAiBnB,MAAAA,EAAcC,QAAAA,EAAkBI,UAAAA,IAClDgB,EAAAA,KAAC,MAAA,CACGK,IAAKV,EACLW,UAAWC,EAAAA,KAAK,CACZ,gCAAgC,EAChC,4CAAyD,IAAjBf,IAG3Cd,SAAA,CACGI,GAAAsB,EAAAA,IAACI,EAAAA,cAAA,CACGxB,UAAoC,iBAAlBF,EAA6BA,EAAcE,eAAY,EACzEL,MAAgC,iBAAlBG,EAA6BA,EAAcH,WAAQ,IAGzEqB,EAAAA,KAAC,MAAI,CAAAM,UAAU,sBACX5B,SAAA,CAAA0B,MAACK,EAAAA,cAAc,CAAAC,QAASnB,EAAce,UAAU,wBAAwB5B,SAExE,eACCiC,EAAAA,eAAe,CAAAD,QAAS,IAAMjB,OAAgB,GAAYf,SAAM,oBAKhFgB,IAAcL,GAAqBe,EAAAA,IAAAQ,EAAAA,gBAAA,IAAoB7B,MAC5D"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),r=t.createContext(void 0);exports.MainQuestionContextProvider=({state:t,children:o})=>e.jsx(r.Provider,{value:t,children:o}),exports.useMainQuestionContext=()=>t.useContext(r);
|
|
2
|
+
//# sourceMappingURL=mainQuestionContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mainQuestionContext.js","sources":["../../../../../src/components/feedback/main-question/mainQuestionContext.tsx"],"sourcesContent":["import React, { createContext, useContext } from \"react\";\nimport { WithChildren } from \"../../..\";\nimport { FeedbackState } from \"../types\";\n\nconst mainQuestionContext = createContext<FeedbackState | undefined>(undefined);\n\nexport const useMainQuestionContext = (): FeedbackState | undefined => useContext(mainQuestionContext);\n\ninterface Props extends WithChildren {\n state: FeedbackState;\n}\n\nexport const MainQuestionContextProvider: React.FC<Props> = ({ state, children }) => (\n <mainQuestionContext.Provider value={state}>{children}</mainQuestionContext.Provider>\n);\n"],"names":["mainQuestionContext","createContext","state","children","jsx","Provider","value","useContext"],"mappings":"wIAIMA,EAAsBC,EAAAA,mBAAyC,uCAQT,EAAGC,MAAAA,EAAOC,SAAAA,KACjEC,EAAAA,IAAAJ,EAAoBK,SAApB,CAA6BC,MAAOJ,EAAQC,SAAAA,mCAPX,IAAiCI,EAAAA,WAAWP"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useMainQuestion=t=>{const[u,s]=e.useState(),[r,a]=e.useState(),[n,i]=e.useState(!1),o=e.useRef({onSubmit:t,currentValue:u,message:r,submitted:n});e.useEffect((()=>{o.current={...o.current,onSubmit:t,currentValue:u,message:r,submitted:n}}),[t,u,r,n]);const l=e.useCallback(((e=!0)=>{const{message:t,currentValue:u,submitted:s,onSubmit:r}=o.current;if(!s&&void 0!==u){r({feedbackValue:Array.isArray(u)?u.map((e=>e.value)):null==u?void 0:u.value,intentionalSubmit:e,...e&&t?{message:t}:{}})}}),[]),c=e.useCallback((()=>l(!1)),[l]);return e.useEffect((()=>(typeof window<"u"&&window.addEventListener("beforeunload",c),()=>{c(),window.removeEventListener("beforeunload",c)})),[c]),{currentValue:u,setCurrentValue:s,message:r,setMessage:a,submitted:n,handleSubmit:()=>{l(),i(!0)}}};
|
|
2
|
+
//# sourceMappingURL=useMainQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMainQuestion.js","sources":["../../../../../src/components/feedback/main-question/useMainQuestion.ts"],"sourcesContent":["import { useState, useRef, useCallback, useEffect, SetStateAction, Dispatch } from \"react\";\nimport { FeedbackType, FeedbackOption } from \"../types\";\n\ntype Value = FeedbackOption<string | number> | FeedbackOption<string | number>[] | undefined;\n\ntype MainQuestion = {\n currentValue: Value;\n setCurrentValue: Dispatch<SetStateAction<Value>>;\n message: string | undefined;\n setMessage: Dispatch<SetStateAction<string | undefined>>;\n submitted: boolean;\n handleSubmit: () => void;\n};\n\nexport const useMainQuestion = (onSubmit: (f: FeedbackType) => void): MainQuestion => {\n const [currentValue, setCurrentValue] = useState<FeedbackOption | FeedbackOption[]>();\n const [message, setMessage] = useState<string>();\n const [submitted, setSubmitted] = useState(false);\n\n const feedbackRef = useRef({\n onSubmit,\n currentValue,\n message,\n submitted,\n });\n\n useEffect(() => {\n feedbackRef.current = {\n ...feedbackRef.current,\n onSubmit,\n currentValue,\n message,\n submitted,\n };\n }, [onSubmit, currentValue, message, submitted]);\n\n const submitHandler = useCallback((intentionalSubmit = true) => {\n const { message, currentValue, submitted, onSubmit } = feedbackRef.current;\n\n if (!submitted && currentValue !== undefined) {\n const feedbackValue = Array.isArray(currentValue)\n ? currentValue.map((option) => option.value)\n : currentValue?.value;\n onSubmit({\n feedbackValue,\n intentionalSubmit,\n ...(intentionalSubmit && message ? { message } : {}),\n });\n }\n }, []);\n\n const autoSubmit = useCallback(() => submitHandler(false), [submitHandler]);\n\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"beforeunload\", autoSubmit);\n }\n return () => {\n autoSubmit();\n window.removeEventListener(\"beforeunload\", autoSubmit);\n };\n }, [autoSubmit]);\n\n const handleSubmit = () => {\n submitHandler();\n setSubmitted(true);\n };\n\n return {\n currentValue,\n setCurrentValue,\n message,\n setMessage,\n submitted,\n handleSubmit,\n };\n};\n"],"names":["onSubmit","currentValue","setCurrentValue","useState","message","setMessage","submitted","setSubmitted","feedbackRef","useRef","useEffect","current","submitHandler","useCallback","intentionalSubmit","feedbackValue","Array","isArray","map","option","value","autoSubmit","window","addEventListener","removeEventListener","handleSubmit"],"mappings":"iIAcgCA,IAC5B,MAAOC,EAAcC,GAAmBC,EAA4CA,YAC7EC,EAASC,GAAcF,EAAiBA,YACxCG,EAAWC,GAAgBJ,YAAS,GAErCK,EAAcC,EAAAA,OAAO,CACvBT,SAAAA,EACAC,aAAAA,EACAG,QAAAA,EACAE,UAAAA,IAGJI,EAAAA,WAAU,KACNF,EAAYG,QAAU,IACfH,EAAYG,QACfX,SAAAA,EACAC,aAAAA,EACAG,QAAAA,EACAE,UAAAA,EAAA,GAEL,CAACN,EAAUC,EAAcG,EAASE,IAErC,MAAMM,EAAgBC,EAAAA,aAAY,CAACC,GAAoB,KAC7C,MAAEV,QAAAA,EAASH,aAAAA,EAAcK,UAAAA,EAAWN,SAAAA,GAAaQ,EAAYG,QAE/D,IAACL,QAA8B,IAAjBL,EAA4B,CAI1CD,EAAS,CACLe,cAJkBC,MAAMC,QAAQhB,GAC9BA,EAAaiB,KAAKC,GAAWA,EAAOC,QACpCnB,MAAAA,OAAAA,EAAAA,EAAcmB,MAGhBN,kBAAAA,KACIA,GAAqBV,EAAU,CAAEA,QAAAA,GAAY,CAAC,GAE1D,IACD,IAEGiB,EAAaR,EAAAA,aAAY,IAAMD,GAAc,IAAQ,CAACA,IAE5DF,OAAAA,EAAAA,WAAU,YACKY,OAAW,KACXA,OAAAC,iBAAiB,eAAgBF,GAErC,KACQA,IACJC,OAAAE,oBAAoB,eAAgBH,EAAU,IAE1D,CAACA,IAOG,CACHpB,aAAAA,EACAC,gBAAAA,EACAE,QAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAmB,aAXiB,KACHb,IACdL,GAAa,EAAI,EASjB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={type:"smiley",label:"Hvor fornøyd er du med denne nettsiden?",options:require("./questions/smileyUtils.js").defaultOptions,addOnQuestion:!0},t={"Fant du":{type:"radio",label:"Fant du det du lette etter?",options:[{label:"Ja",value:"ja",textAreaLabel:"Så bra! Har du noen tilbakemeldinger kan du skrive dem her."},{label:"Nei",value:"nei",textAreaLabel:"Det var leit! Fortell oss gjerne hva du savner, så kan vi gjøre sidene våre bedre."}],addOnQuestion:!0},"Fikk du gjort":{type:"radio",label:"Fikk du gjort det du skulle?",options:[{label:"Ja",value:"ja",textAreaLabel:"Så bra! Har du noen tilbakemeldinger kan du skrive dem her."},{label:"Nei",value:"nei",textAreaLabel:"Det var leit! Fortell oss gjerne hva du savner, så kan vi gjøre sidene våre bedre."}],addOnQuestion:!0},"Hvor fornøyd 5":e,Smileys:e};exports.PRESETS=t;
|
|
2
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sources":["../../../../src/components/feedback/presets.tsx"],"sourcesContent":["import { ComponentProps } from \"react\";\nimport { defaultOptions as smileyOptions } from \"./questions/smileyUtils\";\nimport { Feedback } from \"./\";\n\ntype FeedbackProps = ComponentProps<typeof Feedback>;\ntype PresetProperties = Pick<FeedbackProps, \"label\" | \"type\" | \"options\" | \"addOnQuestion\">;\n\nconst smileyQuestion: PresetProperties = {\n type: \"smiley\",\n label: \"Hvor fornøyd er du med denne nettsiden?\",\n options: smileyOptions,\n addOnQuestion: true,\n};\n\nexport const PRESETS: Record<string, PresetProperties> = {\n \"Fant du\": {\n type: \"radio\",\n label: \"Fant du det du lette etter?\",\n options: [\n {\n label: \"Ja\",\n value: \"ja\",\n textAreaLabel: \"Så bra! Har du noen tilbakemeldinger kan du skrive dem her.\",\n },\n {\n label: \"Nei\",\n value: \"nei\",\n textAreaLabel: \"Det var leit! Fortell oss gjerne hva du savner, så kan vi gjøre sidene våre bedre.\",\n },\n ],\n addOnQuestion: true,\n },\n \"Fikk du gjort\": {\n type: \"radio\",\n label: \"Fikk du gjort det du skulle?\",\n options: [\n {\n label: \"Ja\",\n value: \"ja\",\n textAreaLabel: \"Så bra! Har du noen tilbakemeldinger kan du skrive dem her.\",\n },\n {\n label: \"Nei\",\n value: \"nei\",\n textAreaLabel: \"Det var leit! Fortell oss gjerne hva du savner, så kan vi gjøre sidene våre bedre.\",\n },\n ],\n addOnQuestion: true,\n },\n \"Hvor fornøyd 5\": smileyQuestion,\n Smileys: smileyQuestion,\n};\n"],"names":["smileyQuestion","type","label","options","defaultOptions","addOnQuestion","PRESETS","value","textAreaLabel","Smileys"],"mappings":"sFAOMA,EAAmC,CACrCC,KAAM,SACNC,MAAO,0CACPC,8CAASC,eACTC,eAAe,GAGNC,EAA4C,CACrD,UAAW,CACPL,KAAM,QACNC,MAAO,8BACPC,QAAS,CACL,CACID,MAAO,KACPK,MAAO,KACPC,cAAe,+DAEnB,CACIN,MAAO,MACPK,MAAO,MACPC,cAAe,uFAGvBH,eAAe,GAEnB,gBAAiB,CACbJ,KAAM,QACNC,MAAO,+BACPC,QAAS,CACL,CACID,MAAO,KACPK,MAAO,KACPC,cAAe,+DAEnB,CACIN,MAAO,MACPK,MAAO,MACPC,cAAe,uFAGvBH,eAAe,GAEnB,iBAAkBL,EAClBS,QAAST"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react");require("../../text-input/BaseTextArea.js"),require("../../text-input/BaseTextInput.js");const r=require("../../text-input/TextArea.js");require("../../text-input/TextInput.js");const n=require("../feedbackContext.js"),s=require("../main-question/mainQuestionContext.js");exports.AddonQuestion=({helpLabel:i="Ikke skriv personlige opplysninger. Tilbakemeldinger som kommer inn her blir ikke besvart, men brukt i videre arbeid med å forbedre tjenestene våre.",label:l})=>{const{counter:a}=n.useFeedbackContext(),o=s.useMainQuestionContext(),[u,d]=t.useState();if(t.useEffect((()=>{var e,t,r;const n=Array.isArray(null==o?void 0:o.currentValue)?null==(e=null==o?void 0:o.currentValue[0].textAreaLabel)?void 0:e.toString():null==(r=null==(t=null==o?void 0:o.currentValue)?void 0:t.textAreaLabel)?void 0:r.toString();d(n||l)}),[null==o?void 0:o.currentValue,l]),!o)return console.error("Addon question must be used inside a MainQuestion context provider"),null;const{message:c,setMessage:x}=o;return e.jsxs(e.Fragment,{children:[void 0!==o.currentValue&&e.jsxs("div",{className:"jkl-sr-only","aria-live":"polite",children:[u," ",i]}),e.jsx(r.TextArea,{startOpen:!0,rows:4,"data-testid":"jkl-feedback__open-question",className:"jkl-spacing-xl--bottom jkl-spacing-xl--top",label:u,labelProps:{srOnly:!0},placeholder:u,helpLabel:i,value:c||"",onChange:e=>x(e.target.value),counter:a})]})};
|
|
2
|
+
//# sourceMappingURL=AddonQuestion.js.map
|