@cnamts/synapse 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AutocompleteFilter-DXd4szWO.js → AutocompleteFilter-CGF33skz.js} +1 -1
- package/dist/{DateFilter-BD59Kgwf.js → DateFilter-D7-MsKtx.js} +1 -1
- package/dist/{NumberFilter-BSMZE7uw.js → NumberFilter-bjQPPfsj.js} +1 -1
- package/dist/{PeriodFilter-keUdSSk0.js → PeriodFilter-B3wJpK8-.js} +1 -1
- package/dist/{SelectFilter-Dhvvwazl.js → SelectFilter-BN6DbKAV.js} +1 -1
- package/dist/{TextFilter-CU8FpXz0.js → TextFilter-BffP0J2f.js} +1 -1
- package/dist/{apLightTheme2026-DbS7BPUf.js → apLightTheme2026-C4ygwMHC.js} +11 -11
- package/dist/components/Amelipro/AmeliproAutoCompleteField/AmeliproAutoCompleteField.d.ts +6 -6
- package/dist/components/Amelipro/AmeliproSelect/AmeliproSelect.d.ts +6 -6
- package/dist/components/Amelipro/AmeliproTabs/AmeliproTabs.d.ts +6 -6
- package/dist/components/Captcha/Captcha.d.ts +27 -16
- package/dist/components/Captcha/CaptchaForm.d.ts +29 -3
- package/dist/components/Captcha/types.d.ts +14 -0
- package/dist/components/Captcha/useCaptchaValidation.d.ts +37 -0
- package/dist/components/Customs/Selects/SelectBtnField/SelectBtnField.d.ts +33 -13
- package/dist/components/Customs/Selects/SelectBtnField/composables/useSelectBtnFieldValidation.d.ts +23 -0
- package/dist/components/Customs/Selects/SyAutocomplete/composables/useSyAutocompleteValidation.d.ts +2 -2
- package/dist/components/Customs/Selects/SySelect/composables/useSySelectValidation.d.ts +2 -2
- package/dist/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.d.ts +17 -48
- package/dist/components/Customs/SyCheckBoxGroup/composables/useSyCheckBoxGroupValidation.d.ts +29 -0
- package/dist/components/Customs/SyCheckBoxGroup/types.d.ts +46 -0
- package/dist/components/Customs/SyCheckbox/SyCheckbox.d.ts +16 -51
- package/dist/components/Customs/SyCheckbox/composables/useSyCheckboxValidation.d.ts +27 -0
- package/dist/components/Customs/SyCheckbox/types.d.ts +49 -0
- package/dist/components/Customs/SyTextField/FieldState.d.ts +5 -0
- package/dist/components/Customs/SyTextField/useSyTextFieldValidation.d.ts +3 -3
- package/dist/components/DialogBox/DialogBox.d.ts +2 -0
- package/dist/components/DialogBox/locales.d.ts +1 -0
- package/dist/components/FilterSideBar/FilterSideBar.d.ts +4 -0
- package/dist/components/LunarCalendar/LunarCalendar.d.ts +43 -14
- package/dist/components/LunarCalendar/types.d.ts +35 -0
- package/dist/components/LunarCalendar/useLunarCalendarValidation.d.ts +11 -12
- package/dist/components/MonthPicker/MonthPicker.d.ts +72 -1747
- package/dist/components/MonthPicker/MonthPickerText/MonthPickerInput.d.ts +21 -1733
- package/dist/components/MonthPicker/MonthPickerText/useTextField.d.ts +5 -0
- package/dist/components/MonthPicker/locales.d.ts +1 -0
- package/dist/components/MonthPicker/types.d.ts +11 -0
- package/dist/components/MonthPicker/useMonthPickerValidation.d.ts +37 -24
- package/dist/components/NirField/NirField.d.ts +6 -4
- package/dist/components/NirField/useNirValidation.d.ts +7 -5
- package/dist/components/PageContainer/PageContainer.d.ts +8 -0
- package/dist/components/PasswordField/PasswordField.d.ts +2 -2
- package/dist/components/PasswordField/usePasswordFieldValidation.d.ts +2 -2
- package/dist/components/PhoneField/PhoneField.d.ts +960 -1938
- package/dist/components/PhoneField/indicatifs.d.ts +715 -8
- package/dist/components/PhoneField/locales.d.ts +7 -0
- package/dist/components/PhoneField/types.d.ts +29 -0
- package/dist/components/PhoneField/usePhoneFieldValidation.d.ts +45 -0
- package/dist/components/PhoneField/usePhoneIndicatifs.d.ts +947 -0
- package/dist/components/SyTextArea/composables/useSyTextAreaValidation.d.ts +2 -2
- package/dist/composables/unifyValidation/documentationValidationProps.d.ts +1 -1
- package/dist/composables/unifyValidation/useValidation.d.ts +4 -5
- package/dist/design-system-v3.js +2 -2
- package/dist/designTokens/tokens/amelipro/apLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/baseTokens.d.ts +18 -18
- package/dist/designTokens/tokens/cnam/cnamLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/pa/paLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/semanticTokens.d.ts +14 -14
- package/dist/{main-D8ryUoS5.js → main-C4wAktOs.js} +13718 -12991
- package/dist/synapse.css +1 -1
- package/dist/vuetifyConfig.js +1 -1
- package/package.json +7 -7
- package/src/assets/compat/_legacy-tokens.scss +91 -0
- package/src/assets/overrides/_utilities.scss +23 -0
- package/src/components/Accordion/Accordion.stories.ts +121 -1
- package/src/components/BackBtn/BackBtn.mdx +1 -1
- package/src/components/BackToTopBtn/BackToTopBtn.mdx +0 -1
- package/src/components/Captcha/Captcha.stories.ts +134 -31
- package/src/components/Captcha/Captcha.vue +95 -28
- package/src/components/Captcha/CaptchaForm.vue +51 -22
- package/src/components/Captcha/tests/Captcha.focus.spec.ts +214 -0
- package/src/components/Captcha/tests/Captcha.spec.ts +233 -24
- package/src/components/Captcha/tests/CaptchaForm.spec.ts +82 -0
- package/src/components/Captcha/tests/__snapshots__/Captcha.spec.ts.snap +16 -42
- package/src/components/Captcha/types.ts +15 -0
- package/src/components/Captcha/useCaptchaValidation.ts +87 -0
- package/src/components/Captcha/validation/validation.stories.ts +1194 -0
- package/src/components/ChipList/ChipList.mdx +0 -1
- package/src/components/CollapsibleList/CollapsibleList.mdx +0 -1
- package/src/components/CookieBanner/CookieBanner.mdx +0 -1
- package/src/components/CopyBtn/CopyBtn.mdx +0 -1
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.stories.ts +123 -439
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.vue +147 -41
- package/src/components/Customs/Selects/SelectBtnField/Validation/Validation.stories.ts +600 -0
- package/src/components/Customs/Selects/SelectBtnField/composables/useSelectBtnFieldValidation.ts +87 -0
- package/src/components/Customs/Selects/SelectBtnField/tests/SelectBtnField.spec.ts +402 -33
- package/src/components/Customs/Selects/SelectBtnField/tests/__snapshots__/SelectBtnField.spec.ts.snap +52 -38
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.stories.ts +342 -162
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.vue +77 -129
- package/src/components/Customs/SyCheckBoxGroup/Validation/Validation.stories.ts +1008 -0
- package/src/components/Customs/SyCheckBoxGroup/composables/useSyCheckBoxGroupValidation.ts +107 -0
- package/src/components/Customs/SyCheckBoxGroup/tests/SyCheckBoxGroup.spec.ts +180 -7
- package/src/components/Customs/SyCheckBoxGroup/types.ts +49 -0
- package/src/components/Customs/SyCheckbox/SyCheckbox.stories.ts +41 -161
- package/src/components/Customs/SyCheckbox/SyCheckbox.vue +71 -148
- package/src/components/Customs/SyCheckbox/Validation/Validation.stories.ts +654 -0
- package/src/components/Customs/SyCheckbox/composables/useSyCheckboxValidation.ts +105 -0
- package/src/components/Customs/SyCheckbox/tests/SyCheckbox.spec.ts +106 -0
- package/src/components/Customs/SyCheckbox/tests/useSyCheckboxValidation.spec.ts +98 -0
- package/src/components/Customs/SyCheckbox/types.ts +51 -0
- package/src/components/Customs/SyTextField/FieldState.vue +50 -0
- package/src/components/Customs/SyTextField/SyTextField.vue +12 -9
- package/src/components/Customs/SyTextField/useSyTextFieldValidation.ts +2 -11
- package/src/components/DataList/DataList.mdx +0 -1
- package/src/components/DataListGroup/DataListGroup.mdx +0 -1
- package/src/components/DiacriticPicker/DiacriticPicker.mdx +0 -1
- package/src/components/DialogBox/DialogBox.mdx +0 -1
- package/src/components/DialogBox/DialogBox.stories.ts +399 -4
- package/src/components/DialogBox/DialogBox.vue +20 -0
- package/src/components/DialogBox/locales.ts +1 -0
- package/src/components/DialogBox/tests/DialogBox.spec.ts +73 -0
- package/src/components/DialogBox/tests/DialogBox.visual.cy.ts +24 -0
- package/src/components/ErrorPage/ErrorPage.mdx +1 -1
- package/src/components/ExternalLinks/ExternalLinks.mdx +0 -1
- package/src/components/FileList/FileList.mdx +0 -1
- package/src/components/FilterInline/FilterInline.mdx +0 -1
- package/src/components/FilterSideBar/FilterSideBar.mdx +8 -1
- package/src/components/FilterSideBar/FilterSideBar.stories.ts +133 -1
- package/src/components/FilterSideBar/FilterSideBar.vue +19 -2
- package/src/components/FilterSideBar/tests/FilterSideBar.spec.ts +55 -0
- package/src/components/FooterBar/FooterBar.mdx +0 -1
- package/src/components/FranceConnectBtn/FranceConnectBtn.mdx +0 -1
- package/src/components/HeaderBar/HeaderBar.mdx +0 -1
- package/src/components/HeaderLoading/HeaderLoading.mdx +0 -1
- package/src/components/LangBtn/LangBtn.mdx +0 -1
- package/src/components/Logo/Logo.mdx +1 -1
- package/src/components/LunarCalendar/LunarCalendar.mdx +6 -9
- package/src/components/LunarCalendar/LunarCalendar.stories.ts +243 -46
- package/src/components/LunarCalendar/LunarCalendar.vue +61 -26
- package/src/components/LunarCalendar/Validation/Validation.stories.ts +717 -0
- package/src/components/LunarCalendar/tests/LunarCalendar.a11y.spec.ts +1 -1
- package/src/components/LunarCalendar/tests/LunarCalendar.spec.ts +197 -6
- package/src/components/LunarCalendar/tests/useLunarCalendarValidation.spec.ts +287 -0
- package/src/components/LunarCalendar/types.ts +39 -0
- package/src/components/LunarCalendar/useLunarCalendarValidation.ts +115 -39
- package/src/components/MonthPicker/MonthPicker.stories.ts +38 -281
- package/src/components/MonthPicker/MonthPicker.vue +66 -17
- package/src/components/MonthPicker/MonthPickerText/MonthPickerInput.vue +44 -20
- package/src/components/MonthPicker/MonthPickerText/useTextField.ts +5 -0
- package/src/components/MonthPicker/Validation/Validation.stories.ts +1117 -0
- package/src/components/MonthPicker/locales.ts +1 -0
- package/src/components/MonthPicker/tests/MonthPicker.spec.ts +353 -2
- package/src/components/MonthPicker/tests/__snapshots__/MonthPicker.spec.ts.snap +12 -8
- package/src/components/MonthPicker/types.ts +16 -0
- package/src/components/MonthPicker/useMonthPickerValidation.ts +64 -27
- package/src/components/NirField/NirField.mdx +120 -66
- package/src/components/NirField/NirField.stories.ts +216 -0
- package/src/components/NirField/useNirValidation.ts +16 -17
- package/src/components/NotFoundPage/tests/__snapshots__/NotFoundPage.spec.ts.snap +263 -245
- package/src/components/NotificationBar/NotificationBar.mdx +0 -1
- package/src/components/PageContainer/PageContainer.mdx +0 -1
- package/src/components/PageContainer/PageContainer.stories.ts +170 -2
- package/src/components/PageContainer/PageContainer.vue +63 -8
- package/src/components/PageContainer/tests/__snapshots__/PageContainer.spec.ts.snap +19 -11
- package/src/components/PaginatedTable/PaginatedTable.mdx +0 -1
- package/src/components/PeriodField/PeriodField.mdx +0 -1
- package/src/components/PhoneField/PhoneField.mdx +2 -3
- package/src/components/PhoneField/PhoneField.stories.ts +227 -410
- package/src/components/PhoneField/PhoneField.vue +204 -438
- package/src/components/PhoneField/indicatifs.ts +1 -1
- package/src/components/PhoneField/locales.ts +7 -0
- package/src/components/PhoneField/tests/PhoneField.a11y.spec.ts +0 -1
- package/src/components/PhoneField/tests/PhoneField.spec.ts +517 -220
- package/src/components/PhoneField/types.ts +30 -0
- package/src/components/PhoneField/usePhoneFieldValidation.ts +119 -0
- package/src/components/PhoneField/usePhoneIndicatifs.ts +89 -0
- package/src/components/PhoneField/validation/validation.stories.ts +717 -0
- package/src/components/RangeField/RangeField.mdx +0 -1
- package/src/components/RatingPicker/RatingPicker.mdx +0 -1
- package/src/components/SocialMediaLinks/SocialMediaLinks.mdx +0 -1
- package/src/components/StatusPage/StatusPage.vue +1 -0
- package/src/components/StatusPage/tests/__snapshots__/StatusPage.spec.ts.snap +248 -230
- package/src/components/SubHeader/SubHeader.mdx +5 -6
- package/src/components/Tables/common/tests/SyTableFilter.spec.ts +11 -12
- package/src/components/UploadWorkflow/UploadWorkflow.mdx +0 -1
- package/src/components/UserMenuBtn/UserMenuBtn.mdx +0 -1
- package/src/components/UserMenuBtn/UserMenuBtn.stories.ts +177 -0
- package/src/composables/unifyValidation/documentationValidationProps.ts +1 -1
- package/src/composables/unifyValidation/tests/useValidation.spec.ts +13 -1
- package/src/composables/unifyValidation/useValidation.ts +37 -33
- package/src/composantsVuetify/VCard/VCard.mdx +4 -0
- package/src/composantsVuetify/VCard/v-card.stories.ts +93 -1
- package/src/composantsVuetify/VCarousel/VCarousel.mdx +74 -0
- package/src/composantsVuetify/VCarousel/v-carousel.stories.ts +531 -0
- package/src/composantsVuetify/VNavigationDrawer/VNavgationDrawer.mdx +53 -0
- package/src/composantsVuetify/VNavigationDrawer/v-navigation-drawer.stories.ts +310 -0
- package/src/composantsVuetify/VSlideGroup/VSlideGroup.mdx +105 -0
- package/src/composantsVuetify/VSlideGroup/v-slide-group.stories.ts +463 -0
- package/src/designTokens/tokens/baseColors.ts +1 -1
- package/src/designTokens/tokens/baseTokens.ts +18 -18
- package/src/stories/Components/Components.stories.ts +34 -1
- package/src/stories/Demarrer/Releases.stories.ts +16 -2
- package/src/stories/DesignTokens/Arrondis.mdx +1 -1
- package/src/stories/DesignTokens/Correspondances.mdx +219 -0
- package/src/stories/DesignTokens/UtiliserLesTokens.mdx +235 -0
- package/src/stories/DesignTokens/colors.stories.ts +569 -569
- package/src/stories/GuideDuDev/Amelipro.stories.ts +335 -267
- package/dist/components/LunarCalendar/useLunarCalendarRules.d.ts +0 -5
- package/dist/components/PhoneField/tests/types.d.ts +0 -18
- package/src/components/LunarCalendar/tests/useLunarCalendarRules.spec.ts +0 -184
- package/src/components/LunarCalendar/useLunarCalendarRules.ts +0 -96
- package/src/components/PhoneField/tests/types.d.ts +0 -19
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type FieldValidationProps } from '@/composables/unifyValidation/useValidation'
|
|
2
|
+
import { type locales as defaultLocales } from './locales'
|
|
3
|
+
|
|
4
|
+
export type DisplayFormat = 'code' | 'code-abbreviation' | 'code-country' | 'country' | 'abbreviation'
|
|
5
|
+
export type Indicatif = {
|
|
6
|
+
code: string
|
|
7
|
+
abbreviation: string
|
|
8
|
+
country: string
|
|
9
|
+
countryFr?: string
|
|
10
|
+
mask?: string
|
|
11
|
+
phoneLength?: number
|
|
12
|
+
}
|
|
13
|
+
export type PhoneFieldProps = FieldValidationProps & {
|
|
14
|
+
modelValue?: string
|
|
15
|
+
isClearable?: boolean
|
|
16
|
+
dialCodeModel?: string | Indicatif
|
|
17
|
+
outlined?: boolean
|
|
18
|
+
withCountryCode?: boolean
|
|
19
|
+
displayFormat?: DisplayFormat
|
|
20
|
+
customIndicatifs?: Indicatif[]
|
|
21
|
+
useCustomIndicatifsOnly?: boolean
|
|
22
|
+
displayAsterisk?: boolean
|
|
23
|
+
bgColor?: string
|
|
24
|
+
helpText?: string
|
|
25
|
+
hideDetails?: boolean
|
|
26
|
+
autocompleteCountryCode?: string
|
|
27
|
+
autocompletePhone?: string
|
|
28
|
+
withoutFieldset?: boolean
|
|
29
|
+
locales?: typeof defaultLocales
|
|
30
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type ValidationRule } from '@/composables/validation/useValidation'
|
|
2
|
+
import { computed, ref, type Ref } from 'vue'
|
|
3
|
+
import { useValidation } from '@/composables/unifyValidation/useValidation'
|
|
4
|
+
import type { locales } from './locales'
|
|
5
|
+
import type { VuetifyValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
6
|
+
import type { Indicatif } from './types'
|
|
7
|
+
|
|
8
|
+
export function usePhoneFieldValidation(params: {
|
|
9
|
+
modelValue: Ref<string>
|
|
10
|
+
readonly: Ref<boolean>
|
|
11
|
+
disabled: Ref<boolean>
|
|
12
|
+
required: Ref<boolean>
|
|
13
|
+
counter: Ref<number>
|
|
14
|
+
phoneFieldIdentifier: Ref<string>
|
|
15
|
+
shouldDisableErrorHandling: Ref<boolean>
|
|
16
|
+
hasError: Ref<boolean>
|
|
17
|
+
hasWarning: Ref<boolean>
|
|
18
|
+
hasSuccess: Ref<boolean>
|
|
19
|
+
showSuccessMessages: Ref<boolean>
|
|
20
|
+
disableErrorHandling: Ref<boolean>
|
|
21
|
+
isValidateOnBlur: Ref<boolean>
|
|
22
|
+
focused: Ref<boolean>
|
|
23
|
+
customRules: Ref<ValidationRule[]>
|
|
24
|
+
warningRules?: Ref<ValidationRule[]>
|
|
25
|
+
successRules?: Ref<ValidationRule[]>
|
|
26
|
+
rules?: Ref<VuetifyValidationRule[] | undefined>
|
|
27
|
+
errorMessages?: Ref<string[] | null | undefined>
|
|
28
|
+
warningMessages?: Ref<string[] | null | undefined>
|
|
29
|
+
successMessages?: Ref<string[] | null | undefined>
|
|
30
|
+
locales: Ref<typeof locales>
|
|
31
|
+
useVuetifyValidation?: Ref<boolean>
|
|
32
|
+
dialCode?: Ref<Indicatif>
|
|
33
|
+
withCountryCode?: Ref<boolean>
|
|
34
|
+
}) {
|
|
35
|
+
const validationRules = computed<ValidationRule[]>(() => {
|
|
36
|
+
const rules = [] as ValidationRule[]
|
|
37
|
+
|
|
38
|
+
rules.push({
|
|
39
|
+
type: 'exactLength',
|
|
40
|
+
options: {
|
|
41
|
+
length: params.counter.value,
|
|
42
|
+
ignoreSpace: true,
|
|
43
|
+
message: params.locales.value.errorLength(params.counter.value),
|
|
44
|
+
successMessage: params.locales.value.success(params.phoneFieldIdentifier.value),
|
|
45
|
+
fieldIdentifier: params.phoneFieldIdentifier.value,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
if (params.required.value) {
|
|
50
|
+
rules.unshift({
|
|
51
|
+
type: 'required',
|
|
52
|
+
options: {
|
|
53
|
+
length: params.counter.value,
|
|
54
|
+
ignoreSpace: true,
|
|
55
|
+
message: params.locales.value.errorRequired(params.phoneFieldIdentifier.value),
|
|
56
|
+
fieldIdentifier: params.phoneFieldIdentifier.value,
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return rules
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const { hasError, hasWarning, hasSuccess, errors, warnings, successes, state, validate, clearValidation } = useValidation({
|
|
65
|
+
modelValue: params.modelValue,
|
|
66
|
+
readonly: params.readonly,
|
|
67
|
+
disabled: params.disabled,
|
|
68
|
+
required: params.required,
|
|
69
|
+
isValidateOnBlur: params.isValidateOnBlur,
|
|
70
|
+
showSuccessMessages: params.showSuccessMessages,
|
|
71
|
+
disableErrorHandling: params.disableErrorHandling,
|
|
72
|
+
label: params.phoneFieldIdentifier,
|
|
73
|
+
focused: params.focused,
|
|
74
|
+
customRules: computed(() => [
|
|
75
|
+
...validationRules.value,
|
|
76
|
+
...params.customRules.value,
|
|
77
|
+
]),
|
|
78
|
+
customWarningRules: params.warningRules ?? ref([]),
|
|
79
|
+
customSuccessRules: params.successRules ?? ref([]),
|
|
80
|
+
useVuetifyValidation: params.useVuetifyValidation ?? ref(false),
|
|
81
|
+
rules: params.rules ?? ref(undefined),
|
|
82
|
+
hasErrorProp: params.hasError,
|
|
83
|
+
hasWarningProp: params.hasWarning,
|
|
84
|
+
hasSuccessProp: params.hasSuccess,
|
|
85
|
+
errorMessages: params.errorMessages,
|
|
86
|
+
warningMessages: params.warningMessages,
|
|
87
|
+
successMessages: params.successMessages,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const iconColor = computed(() => {
|
|
91
|
+
if (params.shouldDisableErrorHandling.value) return '#222324'
|
|
92
|
+
if (hasError.value) return 'error'
|
|
93
|
+
if (hasWarning.value) return 'warning'
|
|
94
|
+
if (hasSuccess.value) return 'success'
|
|
95
|
+
return '#222324'
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const clearButtonColorClass = computed(() => {
|
|
99
|
+
if (hasError.value) return 'error-field'
|
|
100
|
+
if (hasWarning.value) return 'warning-field'
|
|
101
|
+
if (hasSuccess.value) return 'success-field'
|
|
102
|
+
return 'text-iconBase'
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
errors,
|
|
107
|
+
warnings,
|
|
108
|
+
successes,
|
|
109
|
+
hasError,
|
|
110
|
+
hasWarning,
|
|
111
|
+
hasSuccess,
|
|
112
|
+
iconColor,
|
|
113
|
+
clearButtonColorClass,
|
|
114
|
+
validationRules,
|
|
115
|
+
state,
|
|
116
|
+
validate,
|
|
117
|
+
clearValidation,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { computed, ref, watch, type Ref } from 'vue'
|
|
2
|
+
import { indicatifs } from './indicatifs'
|
|
3
|
+
import type { Indicatif, DisplayFormat } from './types'
|
|
4
|
+
|
|
5
|
+
export function usePhoneIndicatifs(
|
|
6
|
+
dialCodeProp: Ref<string | Indicatif>,
|
|
7
|
+
displayFormat: Ref<DisplayFormat>,
|
|
8
|
+
customIndicatifs: Ref<Indicatif[]>,
|
|
9
|
+
useCustomIndicatifsOnly: Ref<boolean>,
|
|
10
|
+
) {
|
|
11
|
+
function getIndicatifDisplayText(indicatif: Indicatif): string {
|
|
12
|
+
switch (displayFormat.value) {
|
|
13
|
+
case 'code-abbreviation':
|
|
14
|
+
return `${indicatif.code} (${indicatif.abbreviation})`
|
|
15
|
+
case 'code-country':
|
|
16
|
+
return `${indicatif.code} ${indicatif.countryFr || indicatif.country}`
|
|
17
|
+
case 'country':
|
|
18
|
+
return indicatif.countryFr || indicatif.country
|
|
19
|
+
case 'abbreviation':
|
|
20
|
+
return indicatif.abbreviation
|
|
21
|
+
default:
|
|
22
|
+
return indicatif.code
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dialCodeList = computed(() => {
|
|
27
|
+
const mergedDialCodes = useCustomIndicatifsOnly.value ? customIndicatifs.value : [...indicatifs, ...customIndicatifs.value]
|
|
28
|
+
return mergedDialCodes.map((indicatif) => {
|
|
29
|
+
const countryName = indicatif.countryFr || indicatif.country
|
|
30
|
+
const plainDisplayText = getIndicatifDisplayText(indicatif)
|
|
31
|
+
let displayText = escapeHtml(plainDisplayText)
|
|
32
|
+
|
|
33
|
+
if (displayFormat.value === 'code-abbreviation' || displayFormat.value === 'abbreviation') {
|
|
34
|
+
const safeCountry = escapeHtml(countryName)
|
|
35
|
+
const safeAbbr = escapeHtml(indicatif.abbreviation)
|
|
36
|
+
displayText = displayText.replace(safeAbbr, `<abbr title="${safeCountry}">${safeAbbr}</abbr>`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...indicatif,
|
|
41
|
+
displayText,
|
|
42
|
+
plainDisplayText,
|
|
43
|
+
phoneLength: indicatif.phoneLength || indicatif.mask?.replace(/[^#]/g, '').length,
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const internalDialCode = ref<Indicatif>(
|
|
49
|
+
getIndicatif(dialCodeProp.value) || getFallbackIndicatif(),
|
|
50
|
+
)
|
|
51
|
+
watch(dialCodeList, () => {
|
|
52
|
+
const foundIndicatif = getIndicatif(internalDialCode.value)
|
|
53
|
+
if (!foundIndicatif) {
|
|
54
|
+
internalDialCode.value = getFallbackIndicatif()
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
watch(dialCodeProp, (newVal) => {
|
|
59
|
+
const foundIndicatif = getIndicatif(newVal)
|
|
60
|
+
if (foundIndicatif) {
|
|
61
|
+
internalDialCode.value = foundIndicatif
|
|
62
|
+
}
|
|
63
|
+
}, { immediate: true })
|
|
64
|
+
|
|
65
|
+
function getIndicatif(dialCode: string | Indicatif | null | undefined): Indicatif | undefined {
|
|
66
|
+
const countryCode = (typeof dialCode === 'string' ? dialCode : dialCode?.code)
|
|
67
|
+
return dialCodeList.value.find(indicatif => indicatif.code === countryCode)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getFallbackIndicatif(): Indicatif {
|
|
71
|
+
return dialCodeList.value.find(indicatif => indicatif.code === '+33')
|
|
72
|
+
|| dialCodeList.value[0]
|
|
73
|
+
|| indicatifs.find(indicatif => indicatif.code === '+33')!
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
internalDialCode,
|
|
78
|
+
dialCodeList,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function escapeHtml(value: string): string {
|
|
83
|
+
return value
|
|
84
|
+
.replace(/&/g, '&')
|
|
85
|
+
.replace(/</g, '<')
|
|
86
|
+
.replace(/>/g, '>')
|
|
87
|
+
.replace(/"/g, '"')
|
|
88
|
+
.replace(/'/g, ''')
|
|
89
|
+
}
|