@cnamts/synapse 0.0.11-alpha → 0.0.13-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/design-system-v3.js +5394 -3813
- package/dist/design-system-v3.umd.cjs +1 -1
- package/dist/src/components/Amelipro/types/types.d.ts +38 -0
- package/dist/src/components/CookieBanner/CookieBanner.d.ts +1 -1
- package/dist/src/components/Customs/SyInputSelect/SyInputSelect.d.ts +2 -0
- package/dist/src/components/Customs/SyTextField/SyTextField.d.ts +31 -23
- package/dist/src/components/Customs/SyTextField/types.d.ts +1 -0
- package/dist/src/components/DatePicker/DatePicker.d.ts +105 -102
- package/dist/src/components/DatePicker/DateTextInput.d.ts +82 -74
- package/dist/src/components/ErrorPage/ErrorPage.d.ts +1 -1
- package/dist/src/components/FileList/FileList.d.ts +1 -0
- package/dist/src/components/FileList/UploadItem/UploadItem.d.ts +1 -1
- package/dist/src/components/FilterInline/AccessibiliteItems.d.ts +30 -0
- package/dist/src/components/FilterInline/constants/ExpertiseLevelEnum.d.ts +4 -0
- package/dist/src/components/FilterSideBar/AccessibiliteItems.d.ts +29 -0
- package/dist/src/components/FilterSideBar/FilterSideBar.d.ts +31 -0
- package/dist/src/components/FilterSideBar/constants/ExpertiseLevelEnum.d.ts +4 -0
- package/dist/src/components/FilterSideBar/locales.d.ts +7 -0
- package/dist/src/components/LangBtn/LangBtn.d.ts +2 -2
- package/dist/src/components/NirField/NirField.d.ts +952 -0
- package/dist/src/components/NotificationBar/NotificationBar.d.ts +6 -6
- package/dist/src/components/PasswordField/PasswordField.d.ts +42 -8
- package/dist/src/components/PeriodField/PeriodField.d.ts +259 -235
- package/dist/src/components/PhoneField/PhoneField.d.ts +33 -3
- package/dist/src/components/RatingPicker/EmotionPicker/EmotionPicker.d.ts +1 -1
- package/dist/src/components/RatingPicker/NumberPicker/NumberPicker.d.ts +1 -1
- package/dist/src/components/RatingPicker/StarsPicker/StarsPicker.d.ts +1 -1
- package/dist/src/components/UploadWorkflow/AccessibiliteItems.d.ts +29 -0
- package/dist/src/components/UploadWorkflow/config.d.ts +29 -0
- package/dist/src/components/UploadWorkflow/constants/ExpertiseLevelEnum.d.ts +4 -0
- package/dist/src/components/UploadWorkflow/locales.d.ts +7 -0
- package/dist/src/components/UploadWorkflow/types.d.ts +19 -0
- package/dist/src/components/UploadWorkflow/useFileList.d.ts +10 -0
- package/dist/src/components/UploadWorkflow/useFileUploadJourney.d.ts +9 -0
- package/dist/src/components/Usages/Usages.d.ts +10 -0
- package/dist/src/components/index.d.ts +5 -0
- package/dist/src/composables/date/tests/useDateFormat.spec.d.ts +1 -0
- package/dist/src/composables/date/tests/useDateInitialization.spec.d.ts +1 -0
- package/dist/src/composables/date/tests/useDatePickerAccessibility.spec.d.ts +1 -0
- package/dist/src/composables/date/useDateFormat.d.ts +26 -0
- package/dist/src/composables/date/useDateInitialization.d.ts +18 -0
- package/dist/src/composables/date/useDatePickerAccessibility.d.ts +8 -0
- package/dist/src/composables/rules/useFieldValidation.d.ts +1 -0
- package/dist/src/composables/useFilterable/useFilterable.d.ts +1 -1
- package/dist/src/composables/validation/tests/useValidation.spec.d.ts +1 -0
- package/dist/src/composables/validation/useValidation.d.ts +40 -0
- package/dist/src/designTokens/index.d.ts +3 -1
- package/dist/src/main.d.ts +1 -0
- package/dist/src/utils/formatDate/index.d.ts +3 -0
- package/dist/src/utils/formatDate/tests/formatDate.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isDateAfter/index.d.ts +2 -0
- package/dist/src/utils/functions/validation/isDateAfter/tests/isDateAfter.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isDateBefore/index.d.ts +2 -0
- package/dist/src/utils/functions/validation/isDateBefore/tests/isDateBefore.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isDateInRange/index.d.ts +3 -0
- package/dist/src/utils/functions/validation/isDateInRange/tests/isDateInRange.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isDateValid/index.d.ts +9 -0
- package/dist/src/utils/functions/validation/isDateValid/tests/isDateValid.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isEmailValid/tests/isEmailValid.spec.d.ts +1 -0
- package/dist/src/utils/functions/validation/isWeekend/index.d.ts +3 -0
- package/dist/src/utils/functions/validation/isWeekend/tests/isWeekend.spec.d.ts +1 -0
- package/dist/src/utils/parseDate/index.d.ts +3 -0
- package/dist/src/utils/parseDate/tests/parseDate.spec.d.ts +1 -0
- package/dist/src/utils/rules/doMatchPattern/index.d.ts +3 -0
- package/dist/src/utils/rules/doMatchPattern/tests/matchPattern.spec.d.ts +1 -0
- package/dist/src/utils/rules/index.d.ts +11 -0
- package/dist/src/utils/rules/isDateValid/index.d.ts +4 -0
- package/dist/src/utils/rules/isDateValid/tests/isDateValid.spec.d.ts +1 -0
- package/dist/src/utils/rules/isExactLength/index.d.ts +3 -0
- package/dist/src/utils/rules/isExactLength/locales.d.ts +2 -0
- package/dist/src/utils/rules/isExactLength/tests/exactLength.spec.d.ts +1 -0
- package/dist/src/utils/rules/isMaxLength/index.d.ts +3 -0
- package/dist/src/utils/rules/isMaxLength/locales.d.ts +2 -0
- package/dist/src/utils/rules/isMaxLength/tests/isMaxLength.spec.d.ts +1 -0
- package/dist/src/utils/rules/isMinLength/index.d.ts +3 -0
- package/dist/src/utils/rules/isMinLength/locales.d.ts +2 -0
- package/dist/src/utils/rules/isMinLength/tests/isMinLength.spec.d.ts +1 -0
- package/dist/src/utils/rules/isNotAfterDate/index.d.ts +3 -0
- package/dist/src/utils/rules/isNotAfterDate/tests/isNotAfterDate.spec.d.ts +1 -0
- package/dist/src/utils/rules/isNotAfterToday/index.d.ts +4 -0
- package/dist/src/utils/rules/isNotAfterToday/locales.d.ts +2 -0
- package/dist/src/utils/rules/isNotAfterToday/tests/isNotAfterToday.spec.d.ts +1 -0
- package/dist/src/utils/rules/isNotBeforeDate/index.d.ts +3 -0
- package/dist/src/utils/rules/isNotBeforeDate/locales.d.ts +2 -0
- package/dist/src/utils/rules/isNotBeforeDate/tests/IsNotBeforeDate.spec.d.ts +1 -0
- package/dist/src/utils/rules/isNotBeforeToday/index.d.ts +4 -0
- package/dist/src/utils/rules/isNotBeforeToday/locales.d.ts +2 -0
- package/dist/src/utils/rules/isNotBeforeToday/tests/notBeforeToday.spec.d.ts +1 -0
- package/dist/src/utils/rules/isRequired/index.d.ts +4 -0
- package/dist/src/utils/rules/isRequired/locales.d.ts +2 -0
- package/dist/src/utils/rules/isRequired/tests/isRequred.spec.d.ts +1 -0
- package/dist/src/utils/rules/isValidEmail/index.d.ts +4 -0
- package/dist/src/utils/rules/isValidEmail/locales.d.ts +2 -0
- package/dist/src/utils/rules/isValidEmail/tests/isValidEmail.spec.d.ts +1 -0
- package/dist/src/vuetifyConfig.d.ts +81 -0
- package/dist/style.css +1 -1
- package/package.json +3 -1
- package/src/assets/_elevations.scss +89 -0
- package/src/assets/_fonts.scss +6 -0
- package/src/assets/_radius.scss +92 -0
- package/src/assets/_spacers.scss +149 -0
- package/src/assets/settings.scss +15 -3
- package/src/assets/tokens.scss +32 -29
- package/src/components/Amelipro/types/types.ts +40 -0
- package/src/components/ChipList/ChipList.stories.ts +26 -27
- package/src/components/ChipList/ChipList.vue +5 -1
- package/src/components/ChipList/config.ts +1 -0
- package/src/components/CookiesSelection/CookiesInformation/CookiesInformation.vue +2 -2
- package/src/components/Customs/SyBtnSelect/SyBtnSelect.mdx +1 -1
- package/src/components/Customs/SyInputSelect/SyInputSelect.mdx +1 -1
- package/src/components/Customs/SyInputSelect/SyInputSelect.stories.ts +65 -0
- package/src/components/Customs/SyInputSelect/SyInputSelect.vue +13 -3
- package/src/components/Customs/SySelect/SySelect.mdx +1 -1
- package/src/components/Customs/SySelect/SySelect.stories.ts +88 -5
- package/src/components/Customs/SySelect/SySelect.vue +55 -14
- package/src/components/Customs/SySelect/tests/SySelect.spec.ts +135 -2
- package/src/components/Customs/SyTextField/SyTextField.mdx +2 -2
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +809 -79
- package/src/components/Customs/SyTextField/SyTextField.vue +135 -104
- package/src/components/Customs/SyTextField/tests/SyTextField.spec.ts +190 -38
- package/src/components/Customs/SyTextField/types.d.ts +1 -0
- package/src/components/DatePicker/DatePicker.stories.ts +177 -5
- package/src/components/DatePicker/DatePicker.vue +302 -233
- package/src/components/DatePicker/DateTextInput.vue +101 -246
- package/src/components/DatePicker/tests/DatePicker.spec.ts +123 -60
- package/src/components/DatePicker/tests/DateTextInput.spec.ts +202 -6
- package/src/components/FileList/Accessibilite.stories.ts +1 -1
- package/src/components/FileList/AccessibiliteItems.ts +22 -0
- package/src/components/FileList/FileList.vue +2 -1
- package/src/components/FileList/UploadItem/UploadItem.vue +10 -0
- package/src/components/FileUpload/FileUpload.stories.ts +93 -7
- package/src/components/FileUpload/FileUpload.vue +1 -0
- package/src/components/FileUpload/tests/FileUpload.spec.ts +4 -4
- package/src/components/FilterInline/Accessibilite.mdx +14 -0
- package/src/components/FilterInline/Accessibilite.stories.ts +216 -0
- package/src/components/FilterInline/AccessibiliteItems.ts +132 -0
- package/src/components/FilterInline/FilterInline.mdx +180 -34
- package/src/components/FilterInline/FilterInline.stories.ts +363 -6
- package/src/components/FilterInline/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/FilterSideBar/Accessibilite.mdx +14 -0
- package/src/components/FilterSideBar/Accessibilite.stories.ts +216 -0
- package/src/components/FilterSideBar/AccessibiliteItems.ts +153 -0
- package/src/components/FilterSideBar/FilterSideBar.mdx +237 -0
- package/src/components/FilterSideBar/FilterSideBar.stories.ts +798 -0
- package/src/components/FilterSideBar/FilterSideBar.vue +193 -0
- package/src/components/FilterSideBar/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/FilterSideBar/locales.ts +8 -0
- package/src/components/FilterSideBar/tests/FilterSideBar.spec.ts +305 -0
- package/src/components/FilterSideBar/tests/__snapshots__/FilterSideBar.spec.ts.snap +39 -0
- package/src/components/HeaderBar/Usages.mdx +1 -1
- package/src/components/NirField/NirField.stories.ts +738 -29
- package/src/components/NirField/NirField.vue +401 -359
- package/src/components/NirField/examples//342/200/257dataset/342/200/257.md +12 -0
- package/src/components/NirField/tests/NirField.spec.ts +88 -52
- package/src/components/NirField/tests/config.spec.ts +65 -0
- package/src/components/NotificationBar/Accessibilite.stories.ts +4 -0
- package/src/components/NotificationBar/NotificationBar.mdx +2 -2
- package/src/components/NotificationBar/NotificationBar.stories.ts +66 -13
- package/src/components/NotificationBar/NotificationBar.vue +42 -114
- package/src/components/NotificationBar/tests/NotificationBar.spec.ts +28 -33
- package/src/components/NotificationBar/tests/__snapshots__/NotificationBar.spec.ts.snap +1 -1
- package/src/components/PaginatedTable/PaginatedTable.vue +6 -10
- package/src/components/PaginatedTable/tests/__snapshots__/PaginatedTable.spec.ts.snap +4 -4
- package/src/components/PasswordField/PasswordField.mdx +129 -47
- package/src/components/PasswordField/PasswordField.stories.ts +1111 -120
- package/src/components/PasswordField/PasswordField.vue +212 -99
- package/src/components/PasswordField/tests/PasswordField.spec.ts +138 -9
- package/src/components/PeriodField/PeriodField.stories.ts +214 -118
- package/src/components/PeriodField/PeriodField.vue +238 -190
- package/src/components/PeriodField/tests/PeriodField.spec.ts +146 -0
- package/src/components/PhoneField/PhoneField.stories.ts +170 -0
- package/src/components/PhoneField/PhoneField.vue +76 -17
- package/src/components/PhoneField/indicatifs.ts +1 -1
- package/src/components/PhoneField/tests/PhoneField.spec.ts +40 -0
- package/src/components/RatingPicker/RatingPicker.stories.ts +7 -7
- package/src/components/SearchListField/SearchListField.stories.ts +1 -1
- package/src/components/UploadWorkflow/Accessibilite.mdx +14 -0
- package/src/components/UploadWorkflow/Accessibilite.stories.ts +216 -0
- package/src/components/UploadWorkflow/AccessibiliteItems.ts +192 -0
- package/src/components/UploadWorkflow/UploadWorkflow.mdx +75 -0
- package/src/components/UploadWorkflow/UploadWorkflow.stories.ts +943 -0
- package/src/components/UploadWorkflow/UploadWorkflow.vue +230 -0
- package/src/components/UploadWorkflow/config.ts +29 -0
- package/src/components/UploadWorkflow/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/UploadWorkflow/locales.ts +8 -0
- package/src/components/UploadWorkflow/tests/UploadWorkflow.spec.ts +257 -0
- package/src/components/UploadWorkflow/tests/__snapshots__/UploadWorkflow.spec.ts.snap +54 -0
- package/src/components/UploadWorkflow/types.ts +21 -0
- package/src/components/UploadWorkflow/useFileList.ts +84 -0
- package/src/components/UploadWorkflow/useFileUploadJourney.ts +18 -0
- package/src/components/Usages/tests/Usages.spec.ts +183 -0
- package/src/components/index.ts +5 -0
- package/src/composables/date/tests/useDateFormat.spec.ts +67 -0
- package/src/composables/date/tests/useDateInitialization.spec.ts +89 -0
- package/src/composables/date/tests/useDatePickerAccessibility.spec.ts +102 -0
- package/src/composables/date/useDateFormat.ts +94 -0
- package/src/composables/date/useDateInitialization.ts +92 -0
- package/src/composables/date/useDatePickerAccessibility.ts +78 -0
- package/src/composables/rules/tests/useFieldValidation.spec.ts +385 -4
- package/src/composables/rules/useFieldValidation.ts +5 -2
- package/src/composables/useFilterable/useFilterable.ts +5 -4
- package/src/composables/validation/tests/useValidation.spec.ts +154 -0
- package/src/composables/validation/useValidation.ts +180 -0
- package/src/designTokens/index.ts +4 -0
- package/src/main.ts +1 -0
- package/src/stories/Accessibilite/Aculturation/AuditDesignSystem.mdx +28 -0
- package/src/stories/Accessibilite/Aculturation/SensibilisationAccessibilite.mdx +2 -2
- package/src/stories/Accessibilite/Audit/RGAA.mdx +6 -6
- package/src/stories/Accessibilite/Introduction.mdx +2 -1
- package/src/stories/Accessibilite/KitDePreAudit/Echantillonnage.mdx +1 -1
- package/src/stories/Accessibilite/KitDePreAudit/Introduction.mdx +1 -1
- package/src/stories/Accessibilite/KitDePreAudit/Outils/Introduction.mdx +8 -11
- package/src/stories/Accessibilite/KitDePreAudit/Outils/LecteursDEcran.mdx +77 -0
- package/src/stories/Accessibilite/KitDePreAudit/Outils/Tanaguru.mdx +9 -3
- package/src/stories/Accessibilite/KitDePreAudit/Preaudit.mdx +2 -2
- package/src/stories/Demarrer/Accueil.mdx +1 -1
- package/src/stories/Demarrer/Introduction.stories.ts +3 -3
- package/src/stories/Demarrer/Releases.mdx +8 -0
- package/src/stories/Demarrer/Releases.stories.ts +66 -0
- package/src/stories/DesignTokens/Conteneurs.stories.ts +3 -3
- package/src/stories/DesignTokens/ThemePA.mdx +4 -30
- package/src/stories/GuideDuDev/LesBreackingChanges.mdx +36 -0
- package/src/stories/GuideDuDev/UtiliserLesRules.mdx +321 -78
- package/src/stories/GuideDuDev/moduleDeNotification.mdx +1 -1
- package/src/utils/formatDate/index.ts +6 -0
- package/src/utils/formatDate/tests/formatDate.spec.ts +18 -0
- package/src/utils/functions/validation/isDateAfter/index.ts +9 -0
- package/src/utils/functions/validation/isDateAfter/tests/isDateAfter.spec.ts +18 -0
- package/src/utils/functions/validation/isDateBefore/index.ts +9 -0
- package/src/utils/functions/validation/isDateBefore/tests/isDateBefore.spec.ts +23 -0
- package/src/utils/functions/validation/isDateInRange/index.ts +22 -0
- package/src/utils/functions/validation/isDateInRange/tests/isDateInRange.spec.ts +28 -0
- package/src/utils/functions/validation/isDateValid/index.ts +67 -0
- package/src/utils/functions/validation/isDateValid/tests/isDateValid.spec.ts +46 -0
- package/src/utils/functions/validation/isEmailValid/index.ts +9 -0
- package/src/utils/functions/validation/isWeekend/index.ts +10 -0
- package/src/utils/functions/validation/isWeekend/tests/isWeekend.spec.ts +16 -0
- package/src/utils/parseDate/index.ts +29 -0
- package/src/utils/parseDate/tests/parseDate.spec.ts +52 -0
- package/src/utils/rules/Rules.mdx +16 -0
- package/src/utils/rules/doMatchPattern/DoMachPattern.mdx +66 -0
- package/src/utils/rules/doMatchPattern/DoMatchPattern.stories.ts +106 -0
- package/src/utils/rules/doMatchPattern/index.ts +28 -0
- package/src/utils/rules/doMatchPattern/locales.ts +5 -0
- package/src/utils/rules/doMatchPattern/tests/matchPattern.spec.ts +38 -0
- package/src/utils/rules/index.ts +11 -0
- package/src/utils/rules/isDateValid/IsDateValid.mdx +87 -0
- package/src/utils/rules/isDateValid/IsDateValid.stories.ts +113 -0
- package/src/utils/rules/isDateValid/index.ts +32 -0
- package/src/utils/rules/isDateValid/locales.ts +10 -0
- package/src/utils/rules/isDateValid/tests/isDateValid.spec.ts +27 -0
- package/src/utils/rules/isExactLength/IsExactLenght.mdx +68 -0
- package/src/utils/rules/isExactLength/IsExactLength.stories.ts +151 -0
- package/src/utils/rules/{exactLength → isExactLength}/index.ts +2 -4
- package/src/utils/rules/isExactLength/tests/exactLength.spec.ts +48 -0
- package/src/utils/rules/isMaxLength/IsMaxLength.mdx +68 -0
- package/src/utils/rules/isMaxLength/IsMaxLength.stories.ts +152 -0
- package/src/utils/rules/isMaxLength/index.ts +30 -0
- package/src/utils/rules/isMaxLength/locales.ts +6 -0
- package/src/utils/rules/isMaxLength/tests/isMaxLength.spec.ts +42 -0
- package/src/utils/rules/isMinLength/IsMinLength.mdx +68 -0
- package/src/utils/rules/isMinLength/IsMinLength.stories.ts +152 -0
- package/src/utils/rules/isMinLength/index.ts +30 -0
- package/src/utils/rules/isMinLength/locales.ts +6 -0
- package/src/utils/rules/isMinLength/tests/isMinLength.spec.ts +42 -0
- package/src/utils/rules/isNotAfterDate/IsNotAfterDate.mdx +68 -0
- package/src/utils/rules/isNotAfterDate/IsNotAfterDate.stories.ts +109 -0
- package/src/utils/rules/isNotAfterDate/index.ts +25 -0
- package/src/utils/rules/isNotAfterDate/locales.ts +6 -0
- package/src/utils/rules/isNotAfterDate/tests/isNotAfterDate.spec.ts +25 -0
- package/src/utils/rules/isNotAfterToday/IsNotAfterToday.mdx +83 -0
- package/src/utils/rules/isNotAfterToday/IsNotAfterToday.stories.ts +110 -0
- package/src/utils/rules/isNotAfterToday/index.ts +28 -0
- package/src/utils/rules/isNotAfterToday/locales.ts +5 -0
- package/src/utils/rules/isNotAfterToday/tests/isNotAfterToday.spec.ts +30 -0
- package/src/utils/rules/isNotBeforeDate/IsNotBeforeDate.mdx +68 -0
- package/src/utils/rules/isNotBeforeDate/IsNotBeforeDate.stories.ts +114 -0
- package/src/utils/rules/isNotBeforeDate/index.ts +25 -0
- package/src/utils/rules/isNotBeforeDate/locales.ts +6 -0
- package/src/utils/rules/isNotBeforeDate/tests/IsNotBeforeDate.spec.ts +25 -0
- package/src/utils/rules/isNotBeforeToday/IsNotBeforeToday.mdx +83 -0
- package/src/utils/rules/isNotBeforeToday/IsNotBeforeToday.stories.ts +110 -0
- package/src/utils/rules/isNotBeforeToday/index.ts +28 -0
- package/src/utils/rules/isNotBeforeToday/locales.ts +5 -0
- package/src/utils/rules/isNotBeforeToday/tests/notBeforeToday.spec.ts +36 -0
- package/src/utils/rules/isRequired/IsRequired.mdx +81 -0
- package/src/utils/rules/isRequired/IsRequired.stories.ts +101 -0
- package/src/utils/rules/{required → isRequired}/index.ts +3 -3
- package/src/utils/rules/{required/tests/index.spec.ts → isRequired/tests/isRequred.spec.ts} +9 -9
- package/src/utils/rules/isValidEmail/IsValidEmail.mdx +81 -0
- package/src/utils/rules/isValidEmail/IsValidEmail.stories.ts +101 -0
- package/src/utils/rules/{email → isValidEmail}/index.ts +3 -5
- package/src/utils/rules/{email/tests/email.spec.ts → isValidEmail/tests/isValidEmail.spec.ts} +5 -5
- package/src/vuetifyConfig.ts +61 -0
- package/dist/src/utils/rules/email/index.d.ts +0 -4
- package/dist/src/utils/rules/exactLength/index.d.ts +0 -4
- package/dist/src/utils/rules/required/index.d.ts +0 -4
- package/dist/src/utils/rules/required/ruleMessageHelper.d.ts +0 -3
- package/src/components/Customs/SyTextField/tests/__snapshots__/SyTextField.spec.ts.snap +0 -58
- package/src/composables/useFilterable/__snapshots__/useFilterable.spec.ts.snap +0 -3
- package/src/utils/functions/isEmailValid/index.ts +0 -8
- package/src/utils/rules/required/ruleMessageHelper.ts +0 -14
- package/src/utils/rules/required/tests/rulesMessageHelper.spec.ts +0 -22
- /package/dist/src/{utils/functions/isEmailValid/tests/isEmailValid.spec.d.ts → components/FilterSideBar/tests/FilterSideBar.spec.d.ts} +0 -0
- /package/dist/src/{utils/rules/email/tests/email.spec.d.ts → components/NirField/tests/config.spec.d.ts} +0 -0
- /package/dist/src/{utils/rules/required/tests/index.spec.d.ts → components/UploadWorkflow/tests/UploadWorkflow.spec.d.ts} +0 -0
- /package/dist/src/{utils/rules/required/tests/rulesMessageHelper.spec.d.ts → components/Usages/tests/Usages.spec.d.ts} +0 -0
- /package/dist/src/utils/functions/{isEmailValid → validation/isEmailValid}/index.d.ts +0 -0
- /package/dist/src/utils/rules/{exactLength → doMatchPattern}/locales.d.ts +0 -0
- /package/dist/src/utils/rules/{email → isDateValid}/locales.d.ts +0 -0
- /package/dist/src/utils/rules/{required → isNotAfterDate}/locales.d.ts +0 -0
- /package/src/utils/functions/{isEmailValid → validation/isEmailValid}/tests/isEmailValid.spec.ts +0 -0
- /package/src/utils/rules/{exactLength → isExactLength}/locales.ts +0 -0
- /package/src/utils/rules/{required → isRequired}/locales.ts +0 -0
- /package/src/utils/rules/{email → isValidEmail}/locales.ts +0 -0
|
@@ -1,108 +1,351 @@
|
|
|
1
|
-
import {Meta, Source} from '@storybook/addon-docs/blocks';
|
|
1
|
+
import { Meta, Source } from '@storybook/addon-docs/blocks';
|
|
2
2
|
|
|
3
|
-
<Meta title="Guide Du Dev/Utiliser
|
|
3
|
+
<Meta title="Guide Du Dev/Utiliser le système de validation"/>
|
|
4
4
|
|
|
5
|
-
# Utiliser
|
|
5
|
+
# Utiliser le système de validation
|
|
6
6
|
|
|
7
|
-
Ce guide décrit comment utiliser le
|
|
7
|
+
Ce guide décrit comment utiliser le système de validation de formulaires du Design System pour créer des validations flexibles et intuitives.
|
|
8
8
|
|
|
9
9
|
## Introduction
|
|
10
10
|
|
|
11
|
-
Le
|
|
11
|
+
Le système de validation repose sur deux composables principaux :
|
|
12
|
+
- `useFieldValidation` : Gère la création des règles de validation
|
|
13
|
+
- `useValidation` : Gère l'état de validation et l'affichage des messages
|
|
14
|
+
|
|
15
|
+
## Les 3 types de validation
|
|
16
|
+
|
|
17
|
+
Notre système supporte trois types de retours de validation :
|
|
18
|
+
|
|
19
|
+
1. **Erreurs** (rouge 🔴) : Bloquent la soumission du formulaire
|
|
20
|
+
2. **Avertissements** (orange 🟠) : Informent l'utilisateur sans bloquer
|
|
21
|
+
3. **Succès** (vert 🟢) : Confirment la validité du champ
|
|
22
|
+
|
|
23
|
+
### Priorité des validations
|
|
24
|
+
|
|
25
|
+
Les validations suivent un ordre de priorité :
|
|
26
|
+
1. Si une erreur est présente, elle est affichée en priorité
|
|
27
|
+
2. S'il n'y a pas d'erreur mais des avertissements, ils sont affichés
|
|
28
|
+
3. S'il n'y a ni erreur ni avertissement, les messages de succès sont affichés
|
|
29
|
+
|
|
30
|
+
## Structure des types
|
|
31
|
+
|
|
32
|
+
### Type `ValidationOptions`
|
|
33
|
+
|
|
34
|
+
Options de configuration pour la validation :
|
|
35
|
+
|
|
36
|
+
<Source dark code={`
|
|
37
|
+
interface ValidationOptions {
|
|
38
|
+
showSuccessMessages?: boolean; // Activer/désactiver les messages de succès
|
|
39
|
+
fieldIdentifier?: string; // Nom du champ pour les messages
|
|
40
|
+
customRules?: ValidationRule[]; // Règles personnalisées
|
|
41
|
+
warningRules?: ValidationRule[]; // Règles d'avertissement
|
|
42
|
+
successRules?: ValidationRule[]; // Règles de succès
|
|
43
|
+
}
|
|
44
|
+
`}/>
|
|
45
|
+
|
|
46
|
+
### Type `ValidationRule`
|
|
47
|
+
|
|
48
|
+
Structure d'une règle de validation :
|
|
49
|
+
|
|
50
|
+
<Source dark code={`
|
|
51
|
+
type ValidationRule = {
|
|
52
|
+
type: string; // Type de règle (ex: 'required', 'email')
|
|
53
|
+
options: RuleOptions;
|
|
54
|
+
}
|
|
55
|
+
`}/>
|
|
12
56
|
|
|
13
|
-
## Structure du composable
|
|
14
|
-
#
|
|
15
57
|
### Type `RuleOptions`
|
|
16
58
|
|
|
59
|
+
Options disponibles pour configurer une règle :
|
|
60
|
+
|
|
17
61
|
<Source dark code={`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
62
|
+
interface RuleOptions {
|
|
63
|
+
message?: string; // Message d'erreur personnalisé
|
|
64
|
+
successMessage?: string; // Message de succès personnalisé
|
|
65
|
+
warningMessage?: string; // Message d'avertissement personnalisé
|
|
66
|
+
fieldName?: string; // Nom du champ pour les messages
|
|
67
|
+
fieldIdentifier?: string; // Identifiant du champ
|
|
68
|
+
value?: any; // Valeur pour les règles min/max
|
|
69
|
+
length?: number; // Longueur pour minLength/maxLength
|
|
70
|
+
pattern?: RegExp; // Expression régulière
|
|
71
|
+
ignoreSpace?: boolean; // Ignorer les espaces
|
|
72
|
+
isWarning?: boolean; // Traiter comme un avertissement
|
|
26
73
|
validate?: (value: any) => boolean | string; // Validation personnalisée
|
|
27
|
-
}
|
|
28
|
-
`}
|
|
29
|
-
|
|
74
|
+
}
|
|
75
|
+
`}/>
|
|
76
|
+
|
|
77
|
+
## Exemple complet d'utilisation
|
|
78
|
+
|
|
79
|
+
### Avec un input simple
|
|
80
|
+
|
|
81
|
+
Voici un exemple complet montrant les différentes possibilités de validation :
|
|
82
|
+
|
|
83
|
+
<Source dark code={`
|
|
84
|
+
<script lang="ts" setup>
|
|
85
|
+
import { ref } from 'vue'
|
|
86
|
+
import { useValidation } from '@cnamts/synapse'
|
|
87
|
+
|
|
88
|
+
const password = ref('')
|
|
89
|
+
|
|
90
|
+
const { validateField, hasError, hasWarning, hasSuccess, errors, warnings, successes } = useValidation({
|
|
91
|
+
fieldIdentifier: 'Mot de passe',
|
|
92
|
+
showSuccessMessages: true
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// Règles d'erreur (bloquantes)
|
|
96
|
+
const errorRules = [
|
|
97
|
+
{
|
|
98
|
+
type: 'required',
|
|
99
|
+
options: { message: 'Le mot de passe est requis' }
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: 'minLength',
|
|
103
|
+
options: { length: 6, message: 'Le mot de passe doit contenir au moins 6 caractères' }
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
// Règles d'avertissement (non-bloquantes)
|
|
108
|
+
const warningRules = [
|
|
109
|
+
{
|
|
110
|
+
type: 'minLength',
|
|
111
|
+
options: {
|
|
112
|
+
length: 8,
|
|
113
|
+
warningMessage: 'Un mot de passe de 8 caractères minimum est recommandé'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
]
|
|
30
117
|
|
|
31
|
-
|
|
118
|
+
// Règles de succès (messages positifs)
|
|
119
|
+
const successRules = [
|
|
120
|
+
{
|
|
121
|
+
type: 'minLength',
|
|
122
|
+
options: {
|
|
123
|
+
length: 12,
|
|
124
|
+
successMessage: 'Excellent ! Votre mot de passe est très sécurisé'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
const validate = () => {
|
|
130
|
+
const result = validateField(
|
|
131
|
+
password.value,
|
|
132
|
+
errorRules,
|
|
133
|
+
warningRules,
|
|
134
|
+
successRules
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
// result contient :
|
|
138
|
+
// - hasError: boolean
|
|
139
|
+
// - hasWarning: boolean
|
|
140
|
+
// - hasSuccess: boolean
|
|
141
|
+
// - state: { errors, warnings, successes }
|
|
142
|
+
}
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<template>
|
|
146
|
+
<div>
|
|
147
|
+
<input
|
|
148
|
+
v-model="password"
|
|
149
|
+
@input="validate"
|
|
150
|
+
:class="{
|
|
151
|
+
'error': hasError,
|
|
152
|
+
'warning': hasWarning && !hasError,
|
|
153
|
+
'success': hasSuccess
|
|
154
|
+
}"
|
|
155
|
+
/>
|
|
156
|
+
|
|
157
|
+
<!-- Affichage des messages -->
|
|
158
|
+
<div v-if="hasError" class="error-messages">
|
|
159
|
+
<p v-for="error in errors" :key="error">{{ error }}</p>
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
<div v-else-if="hasWarning" class="warning-messages">
|
|
163
|
+
<p v-for="warning in warnings" :key="warning">{{ warning }}</p>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<div v-else-if="hasSuccess" class="success-messages">
|
|
167
|
+
<p v-for="success in successes" :key="success">{{ success }}</p>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
</template>
|
|
171
|
+
`}/>
|
|
172
|
+
|
|
173
|
+
### Avec SyTextField
|
|
174
|
+
|
|
175
|
+
Le `SyTextField` intègre nativement notre système de validation. Voici un exemple complet :
|
|
32
176
|
|
|
33
177
|
<Source dark code={`
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
`}
|
|
39
|
-
/>
|
|
178
|
+
<script lang="ts" setup>
|
|
179
|
+
import { ref } from 'vue'
|
|
180
|
+
import { SyTextField } from '@cnamts/synapse'
|
|
40
181
|
|
|
41
|
-
|
|
182
|
+
const password = ref('')
|
|
183
|
+
|
|
184
|
+
// Règles d'erreur (bloquantes)
|
|
185
|
+
const rules = [
|
|
186
|
+
{
|
|
187
|
+
type: 'required',
|
|
188
|
+
options: { message: 'Le mot de passe est requis' }
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: 'minLength',
|
|
192
|
+
options: { length: 6, message: 'Le mot de passe doit contenir au moins 6 caractères' }
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
// Règles d'avertissement (non-bloquantes)
|
|
197
|
+
const warningRules = [
|
|
198
|
+
{
|
|
199
|
+
type: 'minLength',
|
|
200
|
+
options: {
|
|
201
|
+
length: 8,
|
|
202
|
+
warningMessage: 'Un mot de passe de 8 caractères minimum est recommandé'
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
|
|
207
|
+
// Règles de succès (messages positifs)
|
|
208
|
+
const successRules = [
|
|
209
|
+
{
|
|
210
|
+
type: 'minLength',
|
|
211
|
+
options: {
|
|
212
|
+
length: 12,
|
|
213
|
+
successMessage: 'Excellent ! Votre mot de passe est très sécurisé'
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
</script>
|
|
42
218
|
|
|
43
|
-
|
|
219
|
+
<template>
|
|
220
|
+
<SyTextField
|
|
221
|
+
v-model="password"
|
|
222
|
+
label="Mot de passe"
|
|
223
|
+
type="password"
|
|
224
|
+
:customRules="rules"
|
|
225
|
+
:customWarningRules="warningRules"
|
|
226
|
+
:customSuccessRules="successRules"
|
|
227
|
+
placeholder="Entrez votre mot de passe"
|
|
228
|
+
/>
|
|
229
|
+
</template>
|
|
230
|
+
`}/>
|
|
231
|
+
|
|
232
|
+
Le composant affichera automatiquement :
|
|
233
|
+
- Une icône et un message d'erreur en rouge si le champ est vide ou contient moins de 6 caractères
|
|
234
|
+
- Une icône et un message d'avertissement en orange si le mot de passe fait entre 6 et 8 caractères
|
|
235
|
+
- Une icône et un message de succès en vert si le mot de passe fait 12 caractères ou plus
|
|
236
|
+
|
|
237
|
+
### Validation personnalisée avec SyTextField
|
|
238
|
+
|
|
239
|
+
Voici un exemple plus avancé avec une validation personnalisée :
|
|
44
240
|
|
|
45
241
|
<Source dark code={`
|
|
46
242
|
<script lang="ts" setup>
|
|
47
|
-
import { ref } from 'vue'
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
243
|
+
import { ref } from 'vue'
|
|
244
|
+
import { SyTextField } from '@cnamts/synapse'
|
|
245
|
+
|
|
246
|
+
const email = ref('')
|
|
247
|
+
|
|
248
|
+
// Règle personnalisée pour vérifier le domaine ameli.fr
|
|
249
|
+
const rules = [
|
|
250
|
+
{
|
|
251
|
+
type: 'required',
|
|
252
|
+
options: { message: 'L\'email est requis' }
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
type: 'email',
|
|
256
|
+
options: { message: 'Format d\'email invalide' }
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'custom',
|
|
260
|
+
options: {
|
|
261
|
+
validate: (value: string) => {
|
|
262
|
+
if (!value.endsWith('@ameli.fr')) {
|
|
263
|
+
return 'L\'email doit être un email ameli.fr'
|
|
264
|
+
}
|
|
265
|
+
return true
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
|
|
271
|
+
// Règle d'avertissement pour le format prénom.nom
|
|
272
|
+
const warningRules = [
|
|
273
|
+
{
|
|
274
|
+
type: 'custom',
|
|
275
|
+
options: {
|
|
276
|
+
validate: (value: string) => {
|
|
277
|
+
const [localPart] = value.split('@')
|
|
278
|
+
if (!/^[a-z]+\.[a-z]+$/.test(localPart)) {
|
|
279
|
+
return 'Format recommandé : prenom.nom@ameli.fr'
|
|
280
|
+
}
|
|
281
|
+
return true
|
|
282
|
+
},
|
|
283
|
+
isWarning: true
|
|
284
|
+
}
|
|
81
285
|
}
|
|
82
|
-
|
|
286
|
+
]
|
|
83
287
|
</script>
|
|
84
|
-
`}
|
|
85
|
-
/>
|
|
86
288
|
|
|
87
|
-
|
|
289
|
+
<template>
|
|
290
|
+
<SyTextField
|
|
291
|
+
v-model="email"
|
|
292
|
+
label="Email professionnel"
|
|
293
|
+
:customRules="rules"
|
|
294
|
+
:customWarningRules="warningRules"
|
|
295
|
+
placeholder="prenom.nom@ameli.fr"
|
|
296
|
+
/>
|
|
297
|
+
</template>
|
|
298
|
+
`}/>
|
|
88
299
|
|
|
89
|
-
|
|
300
|
+
Dans cet exemple :
|
|
301
|
+
- Le champ est invalide si l'email n'est pas au format @ameli.fr
|
|
302
|
+
- Un avertissement s'affiche si l'email ne suit pas le format prenom.nom
|
|
303
|
+
- La validation se fait automatiquement à la perte du focus
|
|
304
|
+
- Les icônes et couleurs sont gérées automatiquement par le composant
|
|
90
305
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- **
|
|
94
|
-
- **
|
|
95
|
-
- **
|
|
96
|
-
- **
|
|
97
|
-
- **
|
|
98
|
-
- **
|
|
306
|
+
## Règles de validation disponibles
|
|
307
|
+
|
|
308
|
+
- **required** : Vérifie qu'un champ est rempli
|
|
309
|
+
- **email** : Valide le format d'une adresse email
|
|
310
|
+
- **minLength** : Vérifie une longueur minimale
|
|
311
|
+
- **maxLength** : Vérifie une longueur maximale
|
|
312
|
+
- **min** : Vérifie une valeur minimale (nombre)
|
|
313
|
+
- **max** : Vérifie une valeur maximale (nombre)
|
|
314
|
+
- **pattern** : Valide avec une expression régulière
|
|
315
|
+
- **custom** : Validation personnalisée via une fonction
|
|
99
316
|
|
|
100
317
|
## Bonnes pratiques
|
|
101
318
|
|
|
102
|
-
|
|
103
|
-
|
|
319
|
+
1. **Messages clairs** : Utilisez des messages explicites qui guident l'utilisateur
|
|
320
|
+
2. **Validation progressive** : Validez au fur et à mesure de la saisie
|
|
321
|
+
3. **Avertissements utiles** : Utilisez les warnings pour des recommandations non-bloquantes
|
|
322
|
+
4. **Messages de succès** : Encouragez les bonnes pratiques avec des messages positifs
|
|
323
|
+
5. **Identifiants de champs** : Utilisez `fieldIdentifier` pour des messages contextuels
|
|
104
324
|
|
|
105
|
-
##
|
|
325
|
+
## Exemple de validation personnalisée
|
|
326
|
+
|
|
327
|
+
<Source dark code={`
|
|
328
|
+
const customRules = [
|
|
329
|
+
{
|
|
330
|
+
type: 'custom',
|
|
331
|
+
options: {
|
|
332
|
+
validate: (value: string) => {
|
|
333
|
+
const hasNumber = /\d/.test(value)
|
|
334
|
+
const hasUpper = /[A-Z]/.test(value)
|
|
335
|
+
const hasLower = /[a-z]/.test(value)
|
|
336
|
+
|
|
337
|
+
if (!hasNumber || !hasUpper || !hasLower) {
|
|
338
|
+
return 'Le mot de passe doit contenir au moins un chiffre, une majuscule et une minuscule'
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return true
|
|
342
|
+
},
|
|
343
|
+
successMessage: 'Votre mot de passe respecte les critères de sécurité'
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
`}/>
|
|
106
348
|
|
|
107
|
-
|
|
349
|
+
## Conclusion
|
|
108
350
|
|
|
351
|
+
Le système de validation du Design System offre une grande flexibilité tout en restant simple à utiliser. La combinaison des erreurs, avertissements et succès permet de créer une expérience utilisateur riche et intuitive.
|
|
@@ -8,7 +8,7 @@ import { Meta, Source } from '@storybook/addon-docs/blocks';
|
|
|
8
8
|
## Importation et utilisation
|
|
9
9
|
|
|
10
10
|
<Source dark code={`
|
|
11
|
-
import { useNotificationService } from '@cnamts/
|
|
11
|
+
import { useNotificationService } from '@cnamts/synpase'
|
|
12
12
|
|
|
13
13
|
const { notificationQueue, addNotification, removeNotification, clearQueue } = useNotificationService()
|
|
14
14
|
`} />
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import dayjs from 'dayjs'
|
|
2
|
+
import { describe, it, expect } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { formatDate } from '../'
|
|
5
|
+
|
|
6
|
+
describe('formatDate', () => {
|
|
7
|
+
it('formats a valid date', () => {
|
|
8
|
+
const date = dayjs('2022-01-01')
|
|
9
|
+
|
|
10
|
+
expect(formatDate(date)).toEqual('01/01/2022')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('does not format an invalid date', () => {
|
|
14
|
+
const date = dayjs(null)
|
|
15
|
+
|
|
16
|
+
expect(formatDate(date)).toEqual('Invalid Date')
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { parseDate } from '@/utils/parseDate'
|
|
2
|
+
|
|
3
|
+
/** Check if a date is after another date (DD/MM/YYYY format) */
|
|
4
|
+
export function isDateAfter(maxDate: string, value: string): boolean {
|
|
5
|
+
const parsedValue = parseDate(value)
|
|
6
|
+
const parsedMaxDate = parseDate(maxDate)
|
|
7
|
+
|
|
8
|
+
return parsedValue.isAfter(parsedMaxDate)
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import dayjs from 'dayjs'
|
|
3
|
+
import { formatDate } from '@/utils/formatDate'
|
|
4
|
+
import { isDateAfter } from '..'
|
|
5
|
+
|
|
6
|
+
describe('isDateAfter', () => {
|
|
7
|
+
const today = formatDate(dayjs())
|
|
8
|
+
const pasteDate = formatDate(dayjs().subtract(1, 'year'))
|
|
9
|
+
const futureDate = formatDate(dayjs().add(1, 'year'))
|
|
10
|
+
|
|
11
|
+
it('returns true with a future date', () => {
|
|
12
|
+
expect(isDateAfter(today, futureDate)).toBeTruthy()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns false with a past date', () => {
|
|
16
|
+
expect(isDateAfter(today, pasteDate)).toBeFalsy()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { parseDate } from '@/utils/parseDate'
|
|
2
|
+
|
|
3
|
+
/** Check if a date is before another date (DD/MM/YYYY format) */
|
|
4
|
+
export function isDateBefore(minDate: string, value: string): boolean {
|
|
5
|
+
const parsedValue = parseDate(value)
|
|
6
|
+
const parsedMinDate = parseDate(minDate)
|
|
7
|
+
|
|
8
|
+
return parsedValue.isBefore(parsedMinDate)
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isDateBefore } from '../'
|
|
2
|
+
import { describe, it, expect } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import dayjs from 'dayjs'
|
|
5
|
+
import { formatDate } from '@/utils/formatDate'
|
|
6
|
+
|
|
7
|
+
describe('isDateBefore', () => {
|
|
8
|
+
const today = formatDate(dayjs())
|
|
9
|
+
const pasteDate = formatDate(dayjs().subtract(1, 'year'))
|
|
10
|
+
const futureDate = formatDate(dayjs().add(1, 'year'))
|
|
11
|
+
|
|
12
|
+
it('returns true with a past date', () => {
|
|
13
|
+
expect(isDateBefore(today, pasteDate)).toBeTruthy()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('returns false with a future date', () => {
|
|
17
|
+
expect(isDateBefore(today, futureDate)).toBeFalsy()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('returns false with the current date', () => {
|
|
21
|
+
expect(isDateBefore(today, today)).toBeFalsy()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import dayjs from 'dayjs'
|
|
2
|
+
|
|
3
|
+
import isBetween from 'dayjs/plugin/isBetween'
|
|
4
|
+
dayjs.extend(isBetween)
|
|
5
|
+
|
|
6
|
+
export type Interval = '()' | '[]' | '[)' | '(]'
|
|
7
|
+
|
|
8
|
+
/** Check if a date is in a range */
|
|
9
|
+
export function isDateInRange(
|
|
10
|
+
date: string,
|
|
11
|
+
startDate: string,
|
|
12
|
+
endDate: string,
|
|
13
|
+
interval: Interval = '[)', // '[' indicates inclusion, '(' indicates exclusion
|
|
14
|
+
): boolean {
|
|
15
|
+
const rangePositive = dayjs(startDate).isBefore(dayjs(endDate))
|
|
16
|
+
|
|
17
|
+
if (rangePositive) {
|
|
18
|
+
return dayjs(date).isBetween(startDate, endDate, null, interval)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isDateInRange } from '../'
|
|
2
|
+
import { describe, it, expect } from 'vitest'
|
|
3
|
+
|
|
4
|
+
const start = '2019-10-21'
|
|
5
|
+
const end = '2019-10-27'
|
|
6
|
+
|
|
7
|
+
const date = '2019-10-23'
|
|
8
|
+
|
|
9
|
+
describe('isDateInRange', () => {
|
|
10
|
+
it('returns true if the date is in the range', () => {
|
|
11
|
+
expect(isDateInRange(date, start, end)).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns false if the range is negative', () => {
|
|
15
|
+
// Invert start & end date to create a negative range
|
|
16
|
+
expect(isDateInRange(date, end, start)).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('works with a custom interval', () => {
|
|
20
|
+
const start = '2019-10-21'
|
|
21
|
+
const end = '2019-10-27'
|
|
22
|
+
|
|
23
|
+
const date = '2019-10-27'
|
|
24
|
+
|
|
25
|
+
// We change the interval to allow the last day in the range
|
|
26
|
+
expect(isDateInRange(date, start, end, '[]')).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseDate } from '@/utils/parseDate'
|
|
2
|
+
import dayjs from 'dayjs'
|
|
3
|
+
|
|
4
|
+
import isLeapYear from 'dayjs/plugin/isLeapYear'
|
|
5
|
+
|
|
6
|
+
dayjs.extend(isLeapYear)
|
|
7
|
+
|
|
8
|
+
const DATE_SEPARATORS = /[- /.]/
|
|
9
|
+
/** Matches DD/MM/YYYY with one of the DATE_SEPARATORS */
|
|
10
|
+
export const DATE_FORMAT_REGEX
|
|
11
|
+
= /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\d{4}/
|
|
12
|
+
|
|
13
|
+
export enum DateErrorCodes {
|
|
14
|
+
WRONG_FORMAT = 'wrongFormat',
|
|
15
|
+
MONTH_NOT_MATCH = 'monthNotMatch',
|
|
16
|
+
NOT_LEAP_YEAR = 'notALeapYear',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Check if a date is valid */
|
|
20
|
+
export function isDateValid(date: string): string | true {
|
|
21
|
+
if (!date.match(DATE_FORMAT_REGEX)) {
|
|
22
|
+
return DateErrorCodes.WRONG_FORMAT
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DAYS_IN_MONTH = [
|
|
26
|
+
31,
|
|
27
|
+
28, // Check leap year later
|
|
28
|
+
31,
|
|
29
|
+
30,
|
|
30
|
+
31,
|
|
31
|
+
30,
|
|
32
|
+
31,
|
|
33
|
+
31,
|
|
34
|
+
30,
|
|
35
|
+
31,
|
|
36
|
+
30,
|
|
37
|
+
31,
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
const parsedDate = date.split(DATE_SEPARATORS)
|
|
41
|
+
|
|
42
|
+
const day = parseInt(parsedDate[0], 10)
|
|
43
|
+
const month = parseInt(parsedDate[1], 10)
|
|
44
|
+
|
|
45
|
+
if (month !== 2) {
|
|
46
|
+
if (day > DAYS_IN_MONTH[month - 1]) {
|
|
47
|
+
return DateErrorCodes.MONTH_NOT_MATCH
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const parsed = parseDate(date)
|
|
55
|
+
const isLeap = parsed.isLeapYear()
|
|
56
|
+
|
|
57
|
+
if (isLeap && day > 29) {
|
|
58
|
+
return DateErrorCodes.MONTH_NOT_MATCH
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!isLeap && day >= 29) {
|
|
62
|
+
return DateErrorCodes.NOT_LEAP_YEAR
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
}
|