@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,1008 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import SyCheckBoxGroup from '../SyCheckBoxGroup.vue'
|
|
4
|
+
import SyForm from '../../SyForm/SyForm.vue'
|
|
5
|
+
import { VBtn, VForm } from 'vuetify/components'
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof SyCheckBoxGroup> = {
|
|
8
|
+
title: 'Composants/Formulaires/SyCheckBoxGroup/Validation',
|
|
9
|
+
component: SyCheckBoxGroup,
|
|
10
|
+
parameters: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component: 'Stories démontrant les différents cas de validation avec SyCheckBoxGroup.',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
argTypes: {
|
|
18
|
+
label: { control: 'text', description: 'Label du groupe' },
|
|
19
|
+
options: { control: 'object', description: 'Liste des options' },
|
|
20
|
+
required: { control: 'boolean', description: 'Champ requis' },
|
|
21
|
+
disabled: { control: 'boolean', description: 'Désactivé' },
|
|
22
|
+
readonly: { control: 'boolean', description: 'Lecture seule' },
|
|
23
|
+
useVuetifyValidation: { control: 'boolean', description: 'Validation Vuetify native' },
|
|
24
|
+
showSuccessMessages: { control: 'boolean', description: 'Afficher les messages de succès' },
|
|
25
|
+
multiple: { control: 'boolean', description: 'Sélection multiple' },
|
|
26
|
+
},
|
|
27
|
+
args: {
|
|
28
|
+
label: 'Choisissez une ou plusieurs options',
|
|
29
|
+
options: [
|
|
30
|
+
{ label: 'Option A', value: 'a' },
|
|
31
|
+
{ label: 'Option B', value: 'b' },
|
|
32
|
+
{ label: 'Option C', value: 'c' },
|
|
33
|
+
],
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default meta
|
|
39
|
+
type Story = StoryObj<typeof SyCheckBoxGroup>
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validation avec customRules (règles personnalisées Synapse)
|
|
43
|
+
* Utilise le système de validation personnalisé du design system
|
|
44
|
+
*/
|
|
45
|
+
export const WithError: Story = {
|
|
46
|
+
parameters: {
|
|
47
|
+
docs: {
|
|
48
|
+
description: {
|
|
49
|
+
story: `
|
|
50
|
+
### Validation avec customRules
|
|
51
|
+
Utilise les **customRules** pour définir des règles de validation personnalisées.
|
|
52
|
+
|
|
53
|
+
**Caractéristiques :**
|
|
54
|
+
- Règles de type ValidationRule (Synapse)
|
|
55
|
+
- Support des messages d'erreur, warning, success
|
|
56
|
+
- Validation programmatique via validateOnSubmit
|
|
57
|
+
`,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
sourceCode: [
|
|
61
|
+
{
|
|
62
|
+
name: 'Template',
|
|
63
|
+
code: `
|
|
64
|
+
<template>
|
|
65
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
66
|
+
<SyCheckBoxGroup
|
|
67
|
+
v-model="selected"
|
|
68
|
+
label="Sélectionnez au moins 2 options"
|
|
69
|
+
:options="options"
|
|
70
|
+
:custom-rules="customRules"
|
|
71
|
+
:multiple="true"
|
|
72
|
+
required
|
|
73
|
+
/>
|
|
74
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
75
|
+
</SyForm>
|
|
76
|
+
</template>`,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'Script',
|
|
80
|
+
code: `<script setup lang="ts">
|
|
81
|
+
import { ref } from 'vue'
|
|
82
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
83
|
+
import { VBtn } from 'vuetify/components'
|
|
84
|
+
import type { ValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
85
|
+
|
|
86
|
+
const selected = ref<string[]>([])
|
|
87
|
+
|
|
88
|
+
const options = [
|
|
89
|
+
{ label: 'Option A', value: 'a' },
|
|
90
|
+
{ label: 'Option B', value: 'b' },
|
|
91
|
+
{ label: 'Option C', value: 'c' },
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
const customRules: ValidationRule[] = [
|
|
95
|
+
{
|
|
96
|
+
type: 'custom',
|
|
97
|
+
options: {
|
|
98
|
+
validate: (value: unknown) => Array.isArray(value) && value.length >= 2,
|
|
99
|
+
message: 'Vous devez sélectionner au moins 2 options',
|
|
100
|
+
fieldIdentifier: 'Options',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
106
|
+
if (event.isValid) {
|
|
107
|
+
alert('Formulaire valide !')
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
</script>`,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
render: args => ({
|
|
116
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
117
|
+
setup() {
|
|
118
|
+
const selected = ref<string[]>(['a'])
|
|
119
|
+
|
|
120
|
+
const customRules = [
|
|
121
|
+
{
|
|
122
|
+
type: 'custom',
|
|
123
|
+
options: {
|
|
124
|
+
validate: (value: unknown) => Array.isArray(value) && value.length >= 2,
|
|
125
|
+
message: 'Vous devez sélectionner au moins 2 options',
|
|
126
|
+
fieldIdentifier: 'Options',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
132
|
+
alert(event.isValid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { args, selected, customRules, onSubmit }
|
|
136
|
+
},
|
|
137
|
+
template: `
|
|
138
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
139
|
+
<SyCheckBoxGroup
|
|
140
|
+
v-model="selected"
|
|
141
|
+
v-bind="args"
|
|
142
|
+
:custom-rules="customRules"
|
|
143
|
+
:multiple="true"
|
|
144
|
+
/>
|
|
145
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
146
|
+
</SyForm>
|
|
147
|
+
`,
|
|
148
|
+
}),
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Validation avec customWarningRules (règles d'avertissement Synapse)
|
|
153
|
+
* La soumission est autorisée malgré le warning
|
|
154
|
+
*/
|
|
155
|
+
export const WithWarning: Story = {
|
|
156
|
+
parameters: {
|
|
157
|
+
docs: {
|
|
158
|
+
description: {
|
|
159
|
+
story: `
|
|
160
|
+
### Validation avec customWarningRules
|
|
161
|
+
Utilise les **customWarningRules** pour afficher un avertissement non bloquant.
|
|
162
|
+
|
|
163
|
+
**Caractéristiques :**
|
|
164
|
+
- Le warning n'empêche pas la soumission du formulaire
|
|
165
|
+
- Affiché avec la couleur warning (orange)
|
|
166
|
+
- Utile pour des conseils ou recommandations
|
|
167
|
+
`,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
sourceCode: [
|
|
171
|
+
{
|
|
172
|
+
name: 'Template',
|
|
173
|
+
code: `
|
|
174
|
+
<template>
|
|
175
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
176
|
+
<SyCheckBoxGroup
|
|
177
|
+
v-model="selected"
|
|
178
|
+
label="Choisissez une option"
|
|
179
|
+
:options="options"
|
|
180
|
+
:custom-warning-rules="customWarningRules"
|
|
181
|
+
/>
|
|
182
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
183
|
+
</SyForm>
|
|
184
|
+
</template>`,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'Script',
|
|
188
|
+
code: `<script setup lang="ts">
|
|
189
|
+
import { ref } from 'vue'
|
|
190
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
191
|
+
import { VBtn } from 'vuetify/components'
|
|
192
|
+
import type { ValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
193
|
+
|
|
194
|
+
const selected = ref<string | null>('b')
|
|
195
|
+
|
|
196
|
+
const options = [
|
|
197
|
+
{ label: 'Option A (recommandée)', value: 'a' },
|
|
198
|
+
{ label: 'Option B', value: 'b' },
|
|
199
|
+
{ label: 'Option C', value: 'c' },
|
|
200
|
+
]
|
|
201
|
+
|
|
202
|
+
const customWarningRules: ValidationRule[] = [
|
|
203
|
+
{
|
|
204
|
+
type: 'custom',
|
|
205
|
+
options: {
|
|
206
|
+
validate: (value: unknown) => value === 'a',
|
|
207
|
+
message: "L'option A est recommandée",
|
|
208
|
+
fieldIdentifier: 'Option',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
214
|
+
alert('Formulaire soumis (les warnings ne bloquent pas la soumission)')
|
|
215
|
+
}
|
|
216
|
+
</script>`,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
render: args => ({
|
|
222
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
223
|
+
setup() {
|
|
224
|
+
const selected = ref<string | null>('b')
|
|
225
|
+
|
|
226
|
+
const customWarningRules = [
|
|
227
|
+
{
|
|
228
|
+
type: 'custom',
|
|
229
|
+
options: {
|
|
230
|
+
validate: (value: unknown) => value === 'a',
|
|
231
|
+
message: 'L\'option A est recommandée',
|
|
232
|
+
fieldIdentifier: 'Option',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
|
|
237
|
+
const onSubmit = () => {
|
|
238
|
+
alert('Formulaire soumis (les warnings ne bloquent pas la soumission)')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return { args, selected, customWarningRules, onSubmit }
|
|
242
|
+
},
|
|
243
|
+
template: `
|
|
244
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
245
|
+
<SyCheckBoxGroup
|
|
246
|
+
v-model="selected"
|
|
247
|
+
v-bind="args"
|
|
248
|
+
:custom-warning-rules="customWarningRules"
|
|
249
|
+
/>
|
|
250
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
251
|
+
</SyForm>
|
|
252
|
+
`,
|
|
253
|
+
}),
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Validation avec customSuccessRules (règles de succès Synapse)
|
|
258
|
+
* Affiche un message de succès quand une option valide est sélectionnée
|
|
259
|
+
*/
|
|
260
|
+
export const WithSuccess: Story = {
|
|
261
|
+
parameters: {
|
|
262
|
+
docs: {
|
|
263
|
+
description: {
|
|
264
|
+
story: 'Une option valide est présélectionnée et déclenche la confirmation de succès au chargement.',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
sourceCode: [
|
|
268
|
+
{
|
|
269
|
+
name: 'Template',
|
|
270
|
+
code: `
|
|
271
|
+
<template>
|
|
272
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
273
|
+
<SyCheckBoxGroup
|
|
274
|
+
v-model="selected"
|
|
275
|
+
label="Choisissez une option"
|
|
276
|
+
:options="options"
|
|
277
|
+
show-success-messages
|
|
278
|
+
:custom-success-rules="customSuccessRules"
|
|
279
|
+
/>
|
|
280
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
281
|
+
</SyForm>
|
|
282
|
+
</template>`,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: 'Script',
|
|
286
|
+
code: `<script setup lang="ts">
|
|
287
|
+
import { ref } from 'vue'
|
|
288
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
289
|
+
import { VBtn } from 'vuetify/components'
|
|
290
|
+
import type { ValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
291
|
+
|
|
292
|
+
const selected = ref<string | null>('a')
|
|
293
|
+
|
|
294
|
+
const options = [
|
|
295
|
+
{ label: 'Option A', value: 'a' },
|
|
296
|
+
{ label: 'Option B', value: 'b' },
|
|
297
|
+
{ label: 'Option C', value: 'c' },
|
|
298
|
+
]
|
|
299
|
+
|
|
300
|
+
const customSuccessRules: ValidationRule[] = [
|
|
301
|
+
{
|
|
302
|
+
type: 'custom',
|
|
303
|
+
options: {
|
|
304
|
+
validate: (value: unknown) => value !== null && value !== undefined,
|
|
305
|
+
successMessage: 'Sélection confirmée.',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
]
|
|
309
|
+
|
|
310
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
311
|
+
if (event.isValid) {
|
|
312
|
+
alert('Formulaire valide !')
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
</script>`,
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
render: args => ({
|
|
321
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
322
|
+
setup() {
|
|
323
|
+
const selected = ref<string | null>('a')
|
|
324
|
+
|
|
325
|
+
const customSuccessRules = [
|
|
326
|
+
{
|
|
327
|
+
type: 'custom',
|
|
328
|
+
options: {
|
|
329
|
+
validate: (value: unknown) => value !== null && value !== undefined,
|
|
330
|
+
successMessage: 'Sélection confirmée.',
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
336
|
+
alert(event.isValid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return { args, selected, customSuccessRules, onSubmit }
|
|
340
|
+
},
|
|
341
|
+
template: `
|
|
342
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
343
|
+
<SyCheckBoxGroup
|
|
344
|
+
v-model="selected"
|
|
345
|
+
v-bind="args"
|
|
346
|
+
show-success-messages
|
|
347
|
+
:custom-success-rules="customSuccessRules"
|
|
348
|
+
/>
|
|
349
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
350
|
+
</SyForm>
|
|
351
|
+
`,
|
|
352
|
+
}),
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* disableErrorHandling: true — la validation est complètement désactivée
|
|
357
|
+
*/
|
|
358
|
+
export const DisableErrorHandling: Story = {
|
|
359
|
+
parameters: {
|
|
360
|
+
docs: {
|
|
361
|
+
description: {
|
|
362
|
+
story: `
|
|
363
|
+
### disableErrorHandling à true
|
|
364
|
+
Avec **disableErrorHandling: true**, toute la validation est désactivée : aucun message d'erreur, warning ou succès ne s'affiche, quelle que soit la valeur.
|
|
365
|
+
|
|
366
|
+
**Caractéristiques :**
|
|
367
|
+
- Aucune règle n'est évaluée
|
|
368
|
+
- Le champ ne passe jamais dans un état d'erreur visuel
|
|
369
|
+
- Utile pour des champs en lecture contrôlée par le parent
|
|
370
|
+
`,
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
sourceCode: [
|
|
374
|
+
{
|
|
375
|
+
name: 'Template',
|
|
376
|
+
code: `
|
|
377
|
+
<template>
|
|
378
|
+
<SyForm>
|
|
379
|
+
<SyCheckBoxGroup
|
|
380
|
+
v-model="selected"
|
|
381
|
+
label="Choisissez une option"
|
|
382
|
+
:options="options"
|
|
383
|
+
disable-error-handling
|
|
384
|
+
required
|
|
385
|
+
/>
|
|
386
|
+
<VBtn type="submit" color="primary">Valider (aucune erreur)</VBtn>
|
|
387
|
+
</SyForm>
|
|
388
|
+
</template>`,
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: 'Script',
|
|
392
|
+
code: `<script setup lang="ts">
|
|
393
|
+
import { ref } from 'vue'
|
|
394
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
395
|
+
import { VBtn } from 'vuetify/components'
|
|
396
|
+
|
|
397
|
+
const selected = ref<string | null>(null)
|
|
398
|
+
|
|
399
|
+
const options = [
|
|
400
|
+
{ label: 'Option A', value: 'a' },
|
|
401
|
+
{ label: 'Option B', value: 'b' },
|
|
402
|
+
{ label: 'Option C', value: 'c' },
|
|
403
|
+
]
|
|
404
|
+
</script>`,
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
render: args => ({
|
|
410
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
411
|
+
setup() {
|
|
412
|
+
const selected = ref<string | null>(null)
|
|
413
|
+
return { args, selected }
|
|
414
|
+
},
|
|
415
|
+
template: `
|
|
416
|
+
<SyForm>
|
|
417
|
+
<SyCheckBoxGroup
|
|
418
|
+
v-model="selected"
|
|
419
|
+
v-bind="args"
|
|
420
|
+
disable-error-handling
|
|
421
|
+
/>
|
|
422
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider (aucune erreur)</VBtn>
|
|
423
|
+
</SyForm>
|
|
424
|
+
`,
|
|
425
|
+
}),
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Validation avec SyForm (composant formulaire du design system)
|
|
430
|
+
* Utilise le système de validation unifié avec useValidation et useValidatable
|
|
431
|
+
*/
|
|
432
|
+
export const SyFormValidation: Story = {
|
|
433
|
+
parameters: {
|
|
434
|
+
docs: {
|
|
435
|
+
description: {
|
|
436
|
+
story: `
|
|
437
|
+
### Validation avec SyForm
|
|
438
|
+
Utilise le composant **SyForm** du design system qui intègre le système de validation unifié.
|
|
439
|
+
|
|
440
|
+
**Caractéristiques :**
|
|
441
|
+
- Validation automatique à la soumission
|
|
442
|
+
- Gestion des erreurs via le composable useValidation
|
|
443
|
+
- Support des customRules, warningRules, successRules
|
|
444
|
+
- Messages de validation traduits
|
|
445
|
+
`,
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
sourceCode: [
|
|
449
|
+
{
|
|
450
|
+
name: 'Template',
|
|
451
|
+
code: `
|
|
452
|
+
<template>
|
|
453
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
454
|
+
<SyCheckBoxGroup
|
|
455
|
+
v-model="selected"
|
|
456
|
+
label="Choisissez une option"
|
|
457
|
+
:options="options"
|
|
458
|
+
required
|
|
459
|
+
/>
|
|
460
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
461
|
+
</SyForm>
|
|
462
|
+
</template>`,
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
name: 'Script',
|
|
466
|
+
code: `<script setup lang="ts">
|
|
467
|
+
import { ref } from 'vue'
|
|
468
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
469
|
+
import { VBtn } from 'vuetify/components'
|
|
470
|
+
|
|
471
|
+
const selected = ref<string | null>(null)
|
|
472
|
+
|
|
473
|
+
const options = [
|
|
474
|
+
{ label: 'Option A', value: 'a' },
|
|
475
|
+
{ label: 'Option B', value: 'b' },
|
|
476
|
+
{ label: 'Option C', value: 'c' },
|
|
477
|
+
]
|
|
478
|
+
|
|
479
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
480
|
+
if (event.isValid) {
|
|
481
|
+
alert('Formulaire valide !')
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
</script>`,
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
},
|
|
488
|
+
|
|
489
|
+
render: args => ({
|
|
490
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
491
|
+
setup() {
|
|
492
|
+
const selected = ref<string | null>(null)
|
|
493
|
+
|
|
494
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
495
|
+
alert(event.isValid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return { args, selected, onSubmit }
|
|
499
|
+
},
|
|
500
|
+
template: `
|
|
501
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
502
|
+
<SyCheckBoxGroup
|
|
503
|
+
v-model="selected"
|
|
504
|
+
v-bind="args"
|
|
505
|
+
/>
|
|
506
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
507
|
+
</SyForm>
|
|
508
|
+
`,
|
|
509
|
+
}),
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Validation avec VForm natif (sans useVuetifyValidation)
|
|
514
|
+
* Utilise VForm de Vuetify avec la validation Synapse
|
|
515
|
+
*/
|
|
516
|
+
export const VFormValidation: Story = {
|
|
517
|
+
parameters: {
|
|
518
|
+
docs: {
|
|
519
|
+
description: {
|
|
520
|
+
story: `
|
|
521
|
+
### Validation avec VForm natif
|
|
522
|
+
Intégration avec **VForm** natif Vuetify en conservant la validation Synapse. La soumission appelle **validateOnSubmit()** manuellement sur le composant pour déclencher la validation.
|
|
523
|
+
|
|
524
|
+
**Caractéristiques :**
|
|
525
|
+
- Validation Synapse (customRules, required, etc.)
|
|
526
|
+
- Pas de useVuetifyValidation
|
|
527
|
+
- Appel manuel de validateOnSubmit() sur le ref du composant
|
|
528
|
+
`,
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
sourceCode: [
|
|
532
|
+
{
|
|
533
|
+
name: 'Template',
|
|
534
|
+
code: `
|
|
535
|
+
<template>
|
|
536
|
+
<VForm @submit.prevent="onSubmit">
|
|
537
|
+
<SyCheckBoxGroup
|
|
538
|
+
ref="checkboxRef"
|
|
539
|
+
v-model="selected"
|
|
540
|
+
label="Choisissez une option"
|
|
541
|
+
:options="options"
|
|
542
|
+
required
|
|
543
|
+
class="mb-4"
|
|
544
|
+
/>
|
|
545
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
546
|
+
</VForm>
|
|
547
|
+
</template>`,
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
name: 'Script',
|
|
551
|
+
code: `<script setup lang="ts">
|
|
552
|
+
import { ref } from 'vue'
|
|
553
|
+
import { SyCheckBoxGroup } from '@cnamts/synapse'
|
|
554
|
+
import { VBtn, VForm } from 'vuetify/components'
|
|
555
|
+
|
|
556
|
+
const selected = ref<string | null>(null)
|
|
557
|
+
const checkboxRef = ref(null)
|
|
558
|
+
|
|
559
|
+
const options = [
|
|
560
|
+
{ label: 'Option A', value: 'a' },
|
|
561
|
+
{ label: 'Option B', value: 'b' },
|
|
562
|
+
{ label: 'Option C', value: 'c' },
|
|
563
|
+
]
|
|
564
|
+
|
|
565
|
+
async function onSubmit() {
|
|
566
|
+
const isValid = await checkboxRef.value?.validateOnSubmit()
|
|
567
|
+
if (isValid) {
|
|
568
|
+
alert('Formulaire valide : ' + JSON.stringify(selected.value))
|
|
569
|
+
} else {
|
|
570
|
+
alert('Formulaire invalide : veuillez choisir une option.')
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
</script>`,
|
|
574
|
+
},
|
|
575
|
+
],
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
render: args => ({
|
|
579
|
+
components: { SyCheckBoxGroup, VForm, VBtn },
|
|
580
|
+
setup() {
|
|
581
|
+
const selected = ref<string | null>(null)
|
|
582
|
+
const checkboxRef = ref<{ validateOnSubmit: () => Promise<boolean> } | null>(null)
|
|
583
|
+
|
|
584
|
+
async function onSubmit() {
|
|
585
|
+
const isValid = await checkboxRef.value?.validateOnSubmit()
|
|
586
|
+
if (isValid) {
|
|
587
|
+
alert(`Formulaire valide : ${JSON.stringify(selected.value)}`)
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
alert('Formulaire invalide : veuillez choisir une option.')
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return { args, selected, checkboxRef, onSubmit }
|
|
595
|
+
},
|
|
596
|
+
template: `
|
|
597
|
+
<VForm @submit.prevent="onSubmit">
|
|
598
|
+
<SyCheckBoxGroup
|
|
599
|
+
ref="checkboxRef"
|
|
600
|
+
v-model="selected"
|
|
601
|
+
v-bind="args"
|
|
602
|
+
/>
|
|
603
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
604
|
+
</VForm>
|
|
605
|
+
`,
|
|
606
|
+
}),
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Mode de validation natif Vuetify (`useVuetifyValidation`) intégré à `SyForm`.
|
|
611
|
+
* Les règles sont de simples fonctions `(value) => true | 'message'`, comme la prop `rules` de Vuetify.
|
|
612
|
+
*/
|
|
613
|
+
export const SyFormVuetifyValidation: Story = {
|
|
614
|
+
parameters: {
|
|
615
|
+
docs: {
|
|
616
|
+
description: {
|
|
617
|
+
story: 'Avec `use-vuetify-validation`, le groupe délègue sa validation à Vuetify via la prop `rules` (fonctions natives), tout en restant intégré à `SyForm`.',
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
sourceCode: [
|
|
621
|
+
{
|
|
622
|
+
name: 'Template',
|
|
623
|
+
code: `
|
|
624
|
+
<template>
|
|
625
|
+
<SyForm @submit="onSubmit">
|
|
626
|
+
<SyCheckBoxGroup
|
|
627
|
+
v-model="selected"
|
|
628
|
+
label="Choisissez une option"
|
|
629
|
+
:options="options"
|
|
630
|
+
:use-vuetify-validation="true"
|
|
631
|
+
:rules="vuetifyRules"
|
|
632
|
+
/>
|
|
633
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
634
|
+
</SyForm>
|
|
635
|
+
</template>`,
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: 'Script',
|
|
639
|
+
code: `<script setup lang="ts">
|
|
640
|
+
import { ref } from 'vue'
|
|
641
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
642
|
+
import { VBtn } from 'vuetify/components'
|
|
643
|
+
|
|
644
|
+
const selected = ref<string | null>(null)
|
|
645
|
+
|
|
646
|
+
const options = [
|
|
647
|
+
{ label: 'Option A', value: 'a' },
|
|
648
|
+
{ label: 'Option B', value: 'b' },
|
|
649
|
+
{ label: 'Option C', value: 'c' },
|
|
650
|
+
]
|
|
651
|
+
|
|
652
|
+
const vuetifyRules = [
|
|
653
|
+
(value: unknown) => (Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined) || 'Veuillez sélectionner au moins une option.',
|
|
654
|
+
]
|
|
655
|
+
|
|
656
|
+
function onSubmit(e: { isValid: boolean }) {
|
|
657
|
+
alert(e.isValid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
658
|
+
}
|
|
659
|
+
</script>`,
|
|
660
|
+
},
|
|
661
|
+
],
|
|
662
|
+
},
|
|
663
|
+
render: args => ({
|
|
664
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
665
|
+
setup() {
|
|
666
|
+
const selected = ref<string | null>(null)
|
|
667
|
+
|
|
668
|
+
const vuetifyRules = [
|
|
669
|
+
(value: unknown) => (Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined) || 'Veuillez sélectionner au moins une option.',
|
|
670
|
+
]
|
|
671
|
+
|
|
672
|
+
function onSubmit(e: { isValid: boolean }) {
|
|
673
|
+
alert(e.isValid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return { args, selected, vuetifyRules, onSubmit }
|
|
677
|
+
},
|
|
678
|
+
template: `
|
|
679
|
+
<SyForm @submit="onSubmit">
|
|
680
|
+
<SyCheckBoxGroup
|
|
681
|
+
v-bind="args"
|
|
682
|
+
v-model="selected"
|
|
683
|
+
:use-vuetify-validation="true"
|
|
684
|
+
:rules="vuetifyRules"
|
|
685
|
+
/>
|
|
686
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
687
|
+
</SyForm>
|
|
688
|
+
`,
|
|
689
|
+
}),
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Mode de validation natif Vuetify (`useVuetifyValidation`) dans un `VForm` Vuetify.
|
|
694
|
+
*/
|
|
695
|
+
export const VFormVuetifyValidation: Story = {
|
|
696
|
+
parameters: {
|
|
697
|
+
docs: {
|
|
698
|
+
description: {
|
|
699
|
+
story: 'Validation déléguée à Vuetify (`use-vuetify-validation` + `rules`) dans un `VForm` natif.',
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
sourceCode: [
|
|
703
|
+
{
|
|
704
|
+
name: 'Template',
|
|
705
|
+
code: `
|
|
706
|
+
<template>
|
|
707
|
+
<VForm @submit.prevent="onSubmit">
|
|
708
|
+
<SyCheckBoxGroup
|
|
709
|
+
v-model="selected"
|
|
710
|
+
label="Choisissez une option"
|
|
711
|
+
:options="options"
|
|
712
|
+
:use-vuetify-validation="true"
|
|
713
|
+
:rules="vuetifyRules"
|
|
714
|
+
/>
|
|
715
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
716
|
+
</VForm>
|
|
717
|
+
</template>`,
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
name: 'Script',
|
|
721
|
+
code: `<script setup lang="ts">
|
|
722
|
+
import { ref } from 'vue'
|
|
723
|
+
import { SyCheckBoxGroup } from '@cnamts/synapse'
|
|
724
|
+
import { VBtn, VForm } from 'vuetify/components'
|
|
725
|
+
|
|
726
|
+
const selected = ref<string | null>(null)
|
|
727
|
+
|
|
728
|
+
const options = [
|
|
729
|
+
{ label: 'Option A', value: 'a' },
|
|
730
|
+
{ label: 'Option B', value: 'b' },
|
|
731
|
+
{ label: 'Option C', value: 'c' },
|
|
732
|
+
]
|
|
733
|
+
|
|
734
|
+
const vuetifyRules = [
|
|
735
|
+
(value: unknown) => (Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined) || 'Veuillez sélectionner au moins une option.',
|
|
736
|
+
]
|
|
737
|
+
|
|
738
|
+
async function onSubmit(e: Promise<{ valid: boolean }>) {
|
|
739
|
+
const { valid } = await e
|
|
740
|
+
alert(valid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
741
|
+
}
|
|
742
|
+
</script>`,
|
|
743
|
+
},
|
|
744
|
+
],
|
|
745
|
+
},
|
|
746
|
+
render: args => ({
|
|
747
|
+
components: { SyCheckBoxGroup, VForm, VBtn },
|
|
748
|
+
setup() {
|
|
749
|
+
const selected = ref<string | null>(null)
|
|
750
|
+
|
|
751
|
+
const vuetifyRules = [
|
|
752
|
+
(value: unknown) => (Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined) || 'Veuillez sélectionner au moins une option.',
|
|
753
|
+
]
|
|
754
|
+
|
|
755
|
+
async function onSubmit(e: Promise<{ valid: boolean }>) {
|
|
756
|
+
const { valid } = await e
|
|
757
|
+
alert(valid ? 'Formulaire valide !' : 'Veuillez corriger les erreurs.')
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
return { args, selected, vuetifyRules, onSubmit }
|
|
761
|
+
},
|
|
762
|
+
template: `
|
|
763
|
+
<VForm @submit.prevent="onSubmit">
|
|
764
|
+
<SyCheckBoxGroup
|
|
765
|
+
v-bind="args"
|
|
766
|
+
v-model="selected"
|
|
767
|
+
:use-vuetify-validation="true"
|
|
768
|
+
:rules="vuetifyRules"
|
|
769
|
+
/>
|
|
770
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
771
|
+
</VForm>
|
|
772
|
+
`,
|
|
773
|
+
}),
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Validation multiple avec customRules
|
|
778
|
+
* Valide qu'au moins N options sont sélectionnées
|
|
779
|
+
*/
|
|
780
|
+
export const MultipleSelectionValidation: Story = {
|
|
781
|
+
parameters: {
|
|
782
|
+
docs: {
|
|
783
|
+
description: {
|
|
784
|
+
story: `
|
|
785
|
+
### Validation de sélection multiple
|
|
786
|
+
Exemple de validation sur un groupe de checkboxes avec **multiple="true"**.
|
|
787
|
+
Valide que l'utilisateur a sélectionné au moins 2 options.
|
|
788
|
+
|
|
789
|
+
**Caractéristiques :**
|
|
790
|
+
- Mode multiple activé
|
|
791
|
+
- Règle personnalisée sur la taille du tableau
|
|
792
|
+
`,
|
|
793
|
+
},
|
|
794
|
+
},
|
|
795
|
+
sourceCode: [
|
|
796
|
+
{
|
|
797
|
+
name: 'Template',
|
|
798
|
+
code: `
|
|
799
|
+
<template>
|
|
800
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
801
|
+
<SyCheckBoxGroup
|
|
802
|
+
v-model="selected"
|
|
803
|
+
label="Sélectionnez au moins 2 options"
|
|
804
|
+
:options="options"
|
|
805
|
+
:multiple="true"
|
|
806
|
+
:custom-rules="minSelectionRules"
|
|
807
|
+
required
|
|
808
|
+
/>
|
|
809
|
+
<VBtn type="submit" color="primary">Valider</VBtn>
|
|
810
|
+
</SyForm>
|
|
811
|
+
</template>`,
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
name: 'Script',
|
|
815
|
+
code: `<script setup lang="ts">
|
|
816
|
+
import { ref } from 'vue'
|
|
817
|
+
import { SyCheckBoxGroup, SyForm } from '@cnamts/synapse'
|
|
818
|
+
import { VBtn } from 'vuetify/components'
|
|
819
|
+
import type { ValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
820
|
+
|
|
821
|
+
const selected = ref<string[]>([])
|
|
822
|
+
|
|
823
|
+
const options = [
|
|
824
|
+
{ label: 'Option A', value: 'a' },
|
|
825
|
+
{ label: 'Option B', value: 'b' },
|
|
826
|
+
{ label: 'Option C', value: 'c' },
|
|
827
|
+
{ label: 'Option D', value: 'd' },
|
|
828
|
+
]
|
|
829
|
+
|
|
830
|
+
const minSelectionRules: ValidationRule[] = [
|
|
831
|
+
{
|
|
832
|
+
type: 'custom',
|
|
833
|
+
options: {
|
|
834
|
+
validate: (value: unknown) => Array.isArray(value) && value.length >= 2,
|
|
835
|
+
message: 'Veuillez sélectionner au moins 2 options',
|
|
836
|
+
fieldIdentifier: 'Sélection',
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
]
|
|
840
|
+
|
|
841
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
842
|
+
if (event.isValid) {
|
|
843
|
+
alert('Formulaire valide ! Sélection : ' + JSON.stringify(selected.value))
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
</script>`,
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
},
|
|
850
|
+
|
|
851
|
+
render: args => ({
|
|
852
|
+
components: { SyCheckBoxGroup, SyForm, VBtn },
|
|
853
|
+
setup() {
|
|
854
|
+
const selected = ref<string[]>([])
|
|
855
|
+
|
|
856
|
+
const minSelectionRules = [
|
|
857
|
+
{
|
|
858
|
+
type: 'custom',
|
|
859
|
+
options: {
|
|
860
|
+
validate: (value: unknown) => Array.isArray(value) && value.length >= 2,
|
|
861
|
+
message: 'Veuillez sélectionner au moins 2 options',
|
|
862
|
+
fieldIdentifier: 'Sélection',
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
]
|
|
866
|
+
|
|
867
|
+
const onSubmit = (event: { isValid: boolean }) => {
|
|
868
|
+
alert(event.isValid ? 'Formulaire valide ! Sélection : ' + JSON.stringify(selected.value) : 'Veuillez corriger les erreurs.')
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
return { args, selected, minSelectionRules, onSubmit }
|
|
872
|
+
},
|
|
873
|
+
template: `
|
|
874
|
+
<SyForm ref="form" @submit="onSubmit">
|
|
875
|
+
<SyCheckBoxGroup
|
|
876
|
+
v-model="selected"
|
|
877
|
+
v-bind="args"
|
|
878
|
+
:multiple="true"
|
|
879
|
+
:custom-rules="minSelectionRules"
|
|
880
|
+
/>
|
|
881
|
+
<VBtn type="submit" class="mt-2" color="primary">Valider</VBtn>
|
|
882
|
+
</SyForm>
|
|
883
|
+
`,
|
|
884
|
+
}),
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Validation avec customRules combinées (warning + success)
|
|
889
|
+
* Démonstration de l'utilisation simultanée des règles warning et success
|
|
890
|
+
*/
|
|
891
|
+
export const CustomRules: Story = {
|
|
892
|
+
parameters: {
|
|
893
|
+
docs: {
|
|
894
|
+
description: {
|
|
895
|
+
story: `
|
|
896
|
+
### Validation combinée avec customRules
|
|
897
|
+
Ce story démontre l'utilisation simultanée des **customWarningRules** et **customSuccessRules**.
|
|
898
|
+
|
|
899
|
+
**Caractéristiques :**
|
|
900
|
+
- Warning si l'option A n'est pas sélectionnée
|
|
901
|
+
- Message de succès si l'option A est sélectionnée
|
|
902
|
+
- Validation immédiate (isValidateOnBlur: false)
|
|
903
|
+
`,
|
|
904
|
+
},
|
|
905
|
+
},
|
|
906
|
+
sourceCode: [
|
|
907
|
+
{
|
|
908
|
+
name: 'Template',
|
|
909
|
+
code: `
|
|
910
|
+
<template>
|
|
911
|
+
<SyCheckBoxGroup
|
|
912
|
+
v-model="selected"
|
|
913
|
+
:options="options"
|
|
914
|
+
label="Options"
|
|
915
|
+
:custom-warning-rules="warningRules"
|
|
916
|
+
:custom-success-rules="successRules"
|
|
917
|
+
:is-validate-on-blur="false"
|
|
918
|
+
/>
|
|
919
|
+
</template>`,
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
name: 'Script',
|
|
923
|
+
code: `<script setup lang="ts">
|
|
924
|
+
import { ref } from 'vue'
|
|
925
|
+
import { SyCheckBoxGroup } from '@cnamts/synapse'
|
|
926
|
+
import type { ValidationRule } from '@/composables/unifyValidation/useValidation'
|
|
927
|
+
|
|
928
|
+
const selected = ref<string | null>('A')
|
|
929
|
+
|
|
930
|
+
const options = [
|
|
931
|
+
{ label: 'Option A', value: 'A' },
|
|
932
|
+
{ label: 'Option B', value: 'B' },
|
|
933
|
+
]
|
|
934
|
+
|
|
935
|
+
const warningRules: ValidationRule[] = [
|
|
936
|
+
{
|
|
937
|
+
type: 'custom',
|
|
938
|
+
options: {
|
|
939
|
+
validate: (value: string | null) => {
|
|
940
|
+
if (value !== 'A') {
|
|
941
|
+
return "Vous devez sélectionner l'option A"
|
|
942
|
+
}
|
|
943
|
+
return true
|
|
944
|
+
},
|
|
945
|
+
fieldIdentifier: 'option',
|
|
946
|
+
},
|
|
947
|
+
},
|
|
948
|
+
]
|
|
949
|
+
|
|
950
|
+
const successRules: ValidationRule[] = [
|
|
951
|
+
{
|
|
952
|
+
type: 'custom',
|
|
953
|
+
options: {
|
|
954
|
+
validate: (value: string | null) => value === 'A',
|
|
955
|
+
successMessage: 'Option A sélectionnée',
|
|
956
|
+
fieldIdentifier: 'option',
|
|
957
|
+
},
|
|
958
|
+
},
|
|
959
|
+
]
|
|
960
|
+
</script>`,
|
|
961
|
+
},
|
|
962
|
+
],
|
|
963
|
+
},
|
|
964
|
+
|
|
965
|
+
render: args => ({
|
|
966
|
+
components: { SyCheckBoxGroup },
|
|
967
|
+
setup() {
|
|
968
|
+
const selected = ref<string | null>('A')
|
|
969
|
+
const options = [
|
|
970
|
+
{ label: 'Option A', value: 'A' },
|
|
971
|
+
{ label: 'Option B', value: 'B' },
|
|
972
|
+
]
|
|
973
|
+
const warningRules = [
|
|
974
|
+
{
|
|
975
|
+
type: 'custom',
|
|
976
|
+
options: {
|
|
977
|
+
validate: (value: string | null) => {
|
|
978
|
+
if (value !== 'A') {
|
|
979
|
+
return 'Vous devez sélectionner l\'option A'
|
|
980
|
+
}
|
|
981
|
+
return true
|
|
982
|
+
},
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
]
|
|
986
|
+
const successRules = [
|
|
987
|
+
{
|
|
988
|
+
type: 'custom',
|
|
989
|
+
options: {
|
|
990
|
+
validate: (value: string | null) => value === 'A',
|
|
991
|
+
successMessage: 'Option A sélectionnée',
|
|
992
|
+
},
|
|
993
|
+
},
|
|
994
|
+
]
|
|
995
|
+
return { args, selected, options, warningRules, successRules }
|
|
996
|
+
},
|
|
997
|
+
template: `
|
|
998
|
+
<SyCheckBoxGroup
|
|
999
|
+
v-model="selected"
|
|
1000
|
+
label="Options"
|
|
1001
|
+
:options="options"
|
|
1002
|
+
:custom-warning-rules="warningRules"
|
|
1003
|
+
:custom-success-rules="successRules"
|
|
1004
|
+
:is-validate-on-blur="false"
|
|
1005
|
+
/>
|
|
1006
|
+
`,
|
|
1007
|
+
}),
|
|
1008
|
+
}
|