@cnamts/synapse 0.0.8-alpha → 0.0.10-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.d.ts +1152 -127
- package/dist/design-system-v3.js +4888 -2605
- package/dist/design-system-v3.umd.cjs +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/assets/settings.scss +1 -1
- package/src/components/ContextualMenu/Accessibilite.mdx +14 -0
- package/src/components/ContextualMenu/Accessibilite.stories.ts +191 -0
- package/src/components/ContextualMenu/AccessibiliteItems.ts +89 -0
- package/src/components/ContextualMenu/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/Customs/SySelect/SySelect.stories.ts +7 -7
- package/src/components/Customs/SySelect/SySelect.vue +9 -4
- package/src/components/Customs/SySelect/tests/SySelect.spec.ts +2 -2
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +187 -2
- package/src/components/Customs/SyTextField/SyTextField.vue +185 -16
- package/src/components/Customs/SyTextField/tests/SyTextField.spec.ts +2 -4
- package/src/components/Customs/SyTextField/tests/__snapshots__/SyTextField.spec.ts.snap +18 -16
- package/src/components/Customs/SyTextField/types.d.ts +2 -2
- package/src/components/DatePicker/Accessibilite.mdx +14 -0
- package/src/components/DatePicker/Accessibilite.stories.ts +191 -0
- package/src/components/DatePicker/AccessibiliteItems.ts +233 -0
- package/src/components/DatePicker/DatePicker.mdx +186 -0
- package/src/components/DatePicker/DatePicker.stories.ts +787 -0
- package/src/components/DatePicker/DatePicker.vue +574 -0
- package/src/components/DatePicker/DateTextInput.vue +409 -0
- package/src/components/DatePicker/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/DatePicker/tests/DatePicker.spec.ts +266 -0
- package/src/components/DialogBox/DialogBox.stories.ts +1 -1
- package/src/components/ExternalLinks/Accessibilite.mdx +14 -0
- package/src/components/ExternalLinks/Accessibilite.stories.ts +191 -0
- package/src/components/ExternalLinks/AccessibiliteItems.ts +197 -0
- package/src/components/ExternalLinks/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/ExternalLinks/tests/__snapshots__/ExternalLinks.spec.ts.snap +9 -9
- package/src/components/FileList/FileList.mdx +103 -0
- package/src/components/FileList/FileList.stories.ts +562 -0
- package/src/components/FileList/FileList.vue +78 -0
- package/src/components/FileList/UploadItem/UploadItem.vue +270 -0
- package/src/components/FileList/UploadItem/locales.ts +9 -0
- package/src/components/FileList/tests/FileList.spec.ts +176 -0
- package/src/components/FilePreview/FilePreview.mdx +82 -0
- package/src/components/FilePreview/FilePreview.stories.ts +242 -0
- package/src/components/FilePreview/FilePreview.vue +68 -0
- package/src/components/FilePreview/config.ts +10 -0
- package/src/components/FilePreview/locales.ts +4 -0
- package/src/components/FilePreview/tests/FilePreview.spec.ts +124 -0
- package/src/components/FilePreview/tests/__snapshots__/FilePreview.spec.ts.snap +11 -0
- package/src/components/FileUpload/FileUpload.mdx +165 -0
- package/src/components/FileUpload/FileUpload.stories.ts +429 -0
- package/src/components/FileUpload/FileUpload.vue +195 -0
- package/src/components/FileUpload/FileUploadContent.vue +109 -0
- package/src/components/FileUpload/locales.ts +10 -0
- package/src/components/FileUpload/tests/FileUpload.spec.ts +332 -0
- package/src/components/FileUpload/tests/__snapshots__/FileUpload.spec.ts.snap +7 -0
- package/src/components/FileUpload/useFileDrop.ts +23 -0
- package/src/components/FileUpload/validateFiles.ts +39 -0
- package/src/components/NirField/NirField.stories.ts +1 -1
- package/src/components/NirField/NirField.vue +2 -1
- package/src/components/PasswordField/Accessibilite.mdx +14 -0
- package/src/components/PasswordField/Accessibilite.stories.ts +191 -0
- package/src/components/PasswordField/AccessibiliteItems.ts +184 -0
- package/src/components/PasswordField/PasswordField.vue +3 -3
- package/src/components/PasswordField/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/PeriodField/PeriodField.mdx +32 -0
- package/src/components/PeriodField/PeriodField.stories.ts +807 -0
- package/src/components/PeriodField/PeriodField.vue +355 -0
- package/src/components/PeriodField/tests/PeriodField.spec.ts +348 -0
- package/src/components/PhoneField/PhoneField.vue +44 -60
- package/src/components/PhoneField/tests/PhoneField.spec.ts +0 -15
- package/src/components/RangeField/Accessibilite.mdx +14 -0
- package/src/components/RangeField/Accessibilite.stories.ts +191 -0
- package/src/components/RangeField/AccessibiliteItems.ts +179 -0
- package/src/components/RangeField/RangeField.mdx +54 -0
- package/src/components/RangeField/RangeField.stories.ts +189 -0
- package/src/components/RangeField/RangeField.vue +157 -0
- package/src/components/RangeField/RangeSlider/RangeSlider.vue +387 -0
- package/src/components/RangeField/RangeSlider/Tooltip/Tooltip.vue +64 -0
- package/src/components/RangeField/RangeSlider/tests/__snapshots__/rangeSlider.spec.ts.snap +27 -0
- package/src/components/RangeField/RangeSlider/tests/rangeSlider.spec.ts +100 -0
- package/src/components/RangeField/RangeSlider/tests/useDoubleSlider.spec.ts +246 -0
- package/src/components/RangeField/RangeSlider/tests/useMouseSlide.spec.ts +204 -0
- package/src/components/RangeField/RangeSlider/tests/useThumb.spec.ts +22 -0
- package/src/components/RangeField/RangeSlider/tests/useThumbKeyboard.spec.ts +233 -0
- package/src/components/RangeField/RangeSlider/tests/useTooltipsNudge.spec.ts +150 -0
- package/src/components/RangeField/RangeSlider/tests/useTrack.spec.ts +314 -0
- package/src/components/RangeField/RangeSlider/tests/vAnimateClick.spec.ts +32 -0
- package/src/components/RangeField/RangeSlider/types.ts +15 -0
- package/src/components/RangeField/RangeSlider/useMouseSlide.ts +109 -0
- package/src/components/RangeField/RangeSlider/useRangeSlider.ts +126 -0
- package/src/components/RangeField/RangeSlider/useThumb.ts +18 -0
- package/src/components/RangeField/RangeSlider/useThumbKeyboard.ts +84 -0
- package/src/components/RangeField/RangeSlider/useTooltipsNudge.ts +92 -0
- package/src/components/RangeField/RangeSlider/useTrack.ts +116 -0
- package/src/components/RangeField/RangeSlider/vAnimateClick.ts +19 -0
- package/src/components/RangeField/config.ts +7 -0
- package/src/components/RangeField/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/RangeField/locales.ts +4 -0
- package/src/components/RangeField/tests/RangeField.spec.ts +224 -0
- package/src/components/RangeField/tests/__snapshots__/RangeField.spec.ts.snap +379 -0
- package/src/components/RatingPicker/Accessibilite.mdx +14 -0
- package/src/components/RatingPicker/Accessibilite.stories.ts +191 -0
- package/src/components/RatingPicker/AccessibiliteItems.ts +208 -0
- package/src/components/RatingPicker/EmotionPicker/EmotionPicker.vue +205 -0
- package/src/components/RatingPicker/EmotionPicker/locales.ts +3 -0
- package/src/components/RatingPicker/EmotionPicker/tests/EmotionPicker.spec.ts +104 -0
- package/src/components/RatingPicker/EmotionPicker/tests/__snapshots__/EmotionPicker.spec.ts.snap +66 -0
- package/src/components/RatingPicker/NumberPicker/NumberPicker.vue +159 -0
- package/src/components/RatingPicker/NumberPicker/locales.ts +4 -0
- package/src/components/RatingPicker/NumberPicker/tests/NumberPicker.spec.ts +73 -0
- package/src/components/RatingPicker/NumberPicker/tests/__snapshots__/NumberPicker.spec.ts.snap +105 -0
- package/src/components/RatingPicker/Rating.ts +45 -0
- package/src/components/RatingPicker/RatingPicker.mdx +56 -0
- package/src/components/RatingPicker/RatingPicker.stories.ts +515 -0
- package/src/components/RatingPicker/RatingPicker.vue +122 -0
- package/src/components/RatingPicker/StarsPicker/StarsPicker.vue +116 -0
- package/src/components/RatingPicker/StarsPicker/tests/StarsPicker.spec.ts +95 -0
- package/src/components/RatingPicker/StarsPicker/tests/__snapshots__/StarsPicker.spec.ts.snap +36 -0
- package/src/components/RatingPicker/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/RatingPicker/locales.ts +3 -0
- package/src/components/RatingPicker/tests/Rating.spec.ts +104 -0
- package/src/components/RatingPicker/tests/RatingPicker.spec.ts +187 -0
- package/src/components/RatingPicker/tests/__snapshots__/RatingPicker.spec.ts.snap +108 -0
- package/src/components/SearchListField/Accessibilite.mdx +14 -0
- package/src/components/SearchListField/Accessibilite.stories.ts +191 -0
- package/src/components/SearchListField/AccessibiliteItems.ts +310 -0
- package/src/components/SearchListField/SearchListField.mdx +74 -0
- package/src/components/SearchListField/SearchListField.stories.ts +126 -0
- package/src/components/SearchListField/SearchListField.vue +194 -0
- package/src/components/SearchListField/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/SearchListField/locales.ts +5 -0
- package/src/components/SearchListField/tests/SearchListField.spec.ts +323 -0
- package/src/components/SearchListField/types.d.ts +4 -0
- package/src/components/SelectBtnField/Accessibilite.mdx +14 -0
- package/src/components/SelectBtnField/Accessibilite.stories.ts +191 -0
- package/src/components/SelectBtnField/AccessibiliteItems.ts +191 -0
- package/src/components/SelectBtnField/SelectBtnField.mdx +50 -0
- package/src/components/SelectBtnField/SelectBtnField.stories.ts +763 -0
- package/src/components/SelectBtnField/SelectBtnField.vue +283 -0
- package/src/components/SelectBtnField/config.ts +11 -0
- package/src/components/SelectBtnField/constants/ExpertiseLevelEnum.ts +4 -0
- package/src/components/SelectBtnField/tests/SelectBtnField.spec.ts +327 -0
- package/src/components/SelectBtnField/tests/__snapshots__/SelectBtnField.spec.ts.snap +125 -0
- package/src/components/SelectBtnField/types.d.ts +11 -0
- package/src/components/SyAlert/SyAlert.vue +11 -9
- package/src/components/TableToolbar/TableToolbar.mdx +130 -0
- package/src/components/TableToolbar/TableToolbar.stories.ts +935 -0
- package/src/components/TableToolbar/TableToolbar.vue +168 -0
- package/src/components/TableToolbar/config.ts +24 -0
- package/src/components/TableToolbar/locales.ts +6 -0
- package/src/components/TableToolbar/tests/TableToolbar.spec.ts +166 -0
- package/src/components/TableToolbar/tests/__snapshots__/TableToolbar.spec.ts.snap +359 -0
- package/src/components/index.ts +11 -1
- package/src/composables/rules/useFieldValidation.ts +174 -44
- package/src/designTokens/index.ts +3 -3
- package/src/stories/Fondamentaux/CustomisationEtThemes.mdx +52 -2
- package/src/utils/calcHumanFileSize/index.ts +12 -0
- package/src/utils/calcHumanFileSize/tests/calcHumanFileSize.spec.ts +21 -0
|
@@ -1,88 +1,218 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
1
|
+
export type ValidationResult = {
|
|
2
|
+
success?: string
|
|
3
|
+
error?: string
|
|
4
|
+
warning?: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type RuleOptions = {
|
|
3
8
|
message?: string
|
|
4
9
|
successMessage?: string
|
|
10
|
+
warningMessage?: string
|
|
11
|
+
fieldName?: string
|
|
12
|
+
fieldIdentifier?: string
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This is a generic type
|
|
14
|
+
value?: any
|
|
5
15
|
length?: number
|
|
6
|
-
value?: number
|
|
7
16
|
pattern?: RegExp
|
|
8
17
|
ignoreSpace?: boolean
|
|
9
|
-
|
|
18
|
+
isWarning?: boolean // Si true, la règle génère un warning au lieu d'une erreur
|
|
10
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This is a generic type
|
|
11
20
|
validate?: (value: any) => boolean | string
|
|
21
|
+
date?: string | Date // Date de référence pour les règles notBeforeDate et notAfterDate
|
|
12
22
|
}
|
|
13
23
|
|
|
14
|
-
type ValidationResult = {
|
|
15
|
-
success?: string
|
|
16
|
-
error?: string
|
|
17
|
-
}
|
|
18
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This is a generic type
|
|
19
|
-
type ValidationRule = (value: any) => ValidationResult
|
|
25
|
+
export type ValidationRule = (value: any) => ValidationResult
|
|
20
26
|
|
|
21
27
|
export function useFieldValidation() {
|
|
28
|
+
const getValueLength = (value: string, ignoreSpace?: boolean): number => {
|
|
29
|
+
return ignoreSpace ? value.replace(/\s/g, '').length : value.length
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
const createRule = (type: string, options: RuleOptions = {}): ValidationRule => {
|
|
23
|
-
const getValueLength = (value: string) => {
|
|
24
|
-
return options.ignoreSpace ? value.replace(/\s/g, '').length : value.length
|
|
25
|
-
}
|
|
26
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This is a generic type
|
|
27
|
-
return (value: any) => {
|
|
34
|
+
return (value: any): ValidationResult => {
|
|
35
|
+
// Gestion des champs vides non obligatoires
|
|
28
36
|
if (type !== 'required' && typeof value === 'string' && value.trim() === '') {
|
|
29
37
|
return {}
|
|
30
38
|
}
|
|
39
|
+
|
|
40
|
+
// Identifier de champ pour personnaliser les messages
|
|
41
|
+
const identifier = options.fieldIdentifier
|
|
42
|
+
? `${options.fieldIdentifier}`
|
|
43
|
+
: options.fieldName || 'ce champ'
|
|
44
|
+
|
|
45
|
+
const baseMessages = {
|
|
46
|
+
success: options.successMessage || 'Le champ est valide.',
|
|
47
|
+
error: options.message || `Validation échouée pour ${identifier}.`,
|
|
48
|
+
warning: options.warningMessage || `Attention : ${identifier} peut contenir une erreur.`,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const createValidationResult = (isValid: boolean, message?: string): ValidationResult => {
|
|
52
|
+
if (isValid) {
|
|
53
|
+
return { success: baseMessages.success }
|
|
54
|
+
}
|
|
55
|
+
return options.isWarning
|
|
56
|
+
? { warning: message || baseMessages.warning }
|
|
57
|
+
: { error: message || baseMessages.error }
|
|
58
|
+
}
|
|
59
|
+
|
|
31
60
|
switch (type) {
|
|
32
61
|
case 'required':
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
return createValidationResult(
|
|
63
|
+
(typeof value === 'string' && value.trim() !== '')
|
|
64
|
+
|| (value instanceof Date)
|
|
65
|
+
|| (typeof value === 'object' && value !== null),
|
|
66
|
+
options.message || options.warningMessage || `Vous devez renseigner ${identifier}.`,
|
|
67
|
+
)
|
|
36
68
|
|
|
37
69
|
case 'min':
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
case 'minLength':
|
|
43
|
-
return typeof value === 'string' && getValueLength(value) >= (options.length ?? 0)
|
|
44
|
-
? { success: options.successMessage || 'Le champ est valide.' }
|
|
45
|
-
: { error: options.message || `Ce champ doit avoir au moins ${options.length} caractères.` }
|
|
70
|
+
return createValidationResult(
|
|
71
|
+
typeof value === 'number' && value >= (options.value ?? 0),
|
|
72
|
+
options.message || options.warningMessage || `La valeur de ${identifier} doit être supérieure ou égale à ${options.value}.`,
|
|
73
|
+
)
|
|
46
74
|
|
|
47
75
|
case 'max':
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
return createValidationResult(
|
|
77
|
+
typeof value === 'number' && value <= (options.value ?? Infinity),
|
|
78
|
+
options.message || options.warningMessage || `La valeur de ${identifier} doit être inférieure ou égale à ${options.value}.`,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
case 'minLength':
|
|
82
|
+
return createValidationResult(
|
|
83
|
+
typeof value === 'string' && getValueLength(value, options.ignoreSpace) >= (options.length ?? 0),
|
|
84
|
+
options.message || options.warningMessage || `${identifier} doit contenir au moins ${options.length} caractères.`,
|
|
85
|
+
)
|
|
51
86
|
|
|
52
87
|
case 'maxLength':
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
88
|
+
return createValidationResult(
|
|
89
|
+
typeof value === 'string' && getValueLength(value, options.ignoreSpace) <= (options.length ?? Infinity),
|
|
90
|
+
options.message || options.warningMessage || `${identifier} ne doit pas dépasser ${options.length} caractères.`,
|
|
91
|
+
)
|
|
56
92
|
|
|
57
93
|
case 'exactLength':
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
94
|
+
return createValidationResult(
|
|
95
|
+
typeof value === 'string' && getValueLength(value, options.ignoreSpace) === (options.length ?? 0),
|
|
96
|
+
options.message || options.warningMessage || `${identifier} doit contenir exactement ${options.length} caractères.`,
|
|
97
|
+
)
|
|
61
98
|
|
|
62
99
|
case 'email':
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
return createValidationResult(
|
|
101
|
+
typeof value === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
|
|
102
|
+
options.message || options.warningMessage || `${identifier} doit être un email valide.`,
|
|
103
|
+
)
|
|
66
104
|
|
|
67
105
|
case 'matchPattern':
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
return createValidationResult(
|
|
107
|
+
typeof value === 'string' && !!options.pattern && options.pattern.test(value),
|
|
108
|
+
options.message || options.warningMessage || `Le format de ${identifier} est invalide.`,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
case 'notWeekend': {
|
|
112
|
+
const dateValue = new Date(value)
|
|
113
|
+
return createValidationResult(
|
|
114
|
+
!(dateValue.getDay() === 0 || dateValue.getDay() === 6),
|
|
115
|
+
options.message || options.warningMessage || `${identifier} ne peut pas être un jour de weekend.`,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
case 'notBeforeToday': {
|
|
120
|
+
const dateValue = new Date(value)
|
|
121
|
+
return createValidationResult(
|
|
122
|
+
dateValue >= new Date(),
|
|
123
|
+
options.message || options.warningMessage || `${identifier} ne peut pas être antérieur à aujourd'hui.`,
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
case 'notAfterToday': {
|
|
128
|
+
const dateValue = new Date(value)
|
|
129
|
+
return createValidationResult(
|
|
130
|
+
dateValue <= new Date(),
|
|
131
|
+
options.message || options.warningMessage || `${identifier} ne peut pas être postérieur à aujourd'hui.`,
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case 'notBeforeDate': {
|
|
136
|
+
if (!options.date) {
|
|
137
|
+
return { error: 'Configuration de la règle invalide' }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const dateValue = new Date(value)
|
|
141
|
+
|
|
142
|
+
// Check if options.date is a string and in DD/MM/YYYY format
|
|
143
|
+
if (typeof options.date !== 'string') {
|
|
144
|
+
throw new Error('Date reference must be a string in DD/MM/YYYY format')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Convert reference date from DD/MM/YYYY format to YYYY-MM-DD
|
|
148
|
+
const [day, month, year] = options.date.split('/')
|
|
149
|
+
const referenceDate = new Date(`${year}-${month}-${day}`)
|
|
150
|
+
|
|
151
|
+
return createValidationResult(
|
|
152
|
+
dateValue >= referenceDate,
|
|
153
|
+
options.message || options.warningMessage || `${identifier} ne peut pas être avant le ${options.date}.`,
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
case 'notAfterDate': {
|
|
158
|
+
if (!options.date) {
|
|
159
|
+
return { error: 'Configuration de la règle invalide' }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const dateValue = new Date(value)
|
|
163
|
+
|
|
164
|
+
// Check if options.date is a string and in DD/MM/YYYY format
|
|
165
|
+
if (typeof options.date !== 'string') {
|
|
166
|
+
throw new Error('Date reference must be a string in DD/MM/YYYY format')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Convert reference date from DD/MM/YYYY format to YYYY-MM-DD
|
|
170
|
+
const [day, month, year] = options.date.split('/')
|
|
171
|
+
const referenceDate = new Date(`${year}-${month}-${day}`)
|
|
172
|
+
|
|
173
|
+
return createValidationResult(
|
|
174
|
+
dateValue <= referenceDate,
|
|
175
|
+
options.message || options.warningMessage || `${identifier} ne peut pas être après le ${options.date}.`,
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
case 'dateExact': {
|
|
180
|
+
if (!options.date) {
|
|
181
|
+
return { error: 'Configuration de la règle invalide' }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const dateValue = new Date(value)
|
|
185
|
+
|
|
186
|
+
if (typeof options.date !== 'string') {
|
|
187
|
+
throw new Error('Date reference must be a string in DD/MM/YYYY format')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const [day, month, year] = options.date.split('/')
|
|
191
|
+
const referenceDate = new Date(`${year}-${month}-${day}`)
|
|
192
|
+
|
|
193
|
+
return createValidationResult(
|
|
194
|
+
dateValue.getTime() === referenceDate.getTime(),
|
|
195
|
+
options.message || options.warningMessage || `${identifier} doit être exactement le ${options.date}.`,
|
|
196
|
+
)
|
|
197
|
+
}
|
|
71
198
|
|
|
72
199
|
case 'custom': {
|
|
73
200
|
const result = options.validate?.(value)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
201
|
+
if (result === true) {
|
|
202
|
+
return { success: baseMessages.success }
|
|
203
|
+
}
|
|
204
|
+
return options.isWarning
|
|
205
|
+
? { warning: typeof result === 'string' ? result : baseMessages.warning }
|
|
206
|
+
: { error: typeof result === 'string' ? result : baseMessages.error }
|
|
77
207
|
}
|
|
78
208
|
|
|
79
209
|
default:
|
|
80
|
-
return { error: `La règle spécifiée n'existe pas.` }
|
|
210
|
+
return { error: `La règle spécifiée pour ${identifier} n'existe pas.` }
|
|
81
211
|
}
|
|
82
212
|
}
|
|
83
213
|
}
|
|
84
214
|
|
|
85
|
-
const generateRules = (fieldRules: Array<{ type: string, options?: RuleOptions }>) => {
|
|
215
|
+
const generateRules = (fieldRules: Array<{ type: string, options?: RuleOptions }>): ValidationRule[] => {
|
|
86
216
|
return fieldRules.map(rule => createRule(rule.type, rule.options))
|
|
87
217
|
}
|
|
88
218
|
|
|
@@ -3,9 +3,9 @@ import { cnamContextualTokens } from './tokens/cnam/cnamContextual'
|
|
|
3
3
|
import { cnamColorsTokens } from './tokens/cnam/cnamColors'
|
|
4
4
|
import { cnamLightTheme } from './tokens/cnam/cnamLightTheme'
|
|
5
5
|
import { cnamDarkTheme } from './tokens/cnam/cnamDarkTheme'
|
|
6
|
-
import { paColorsTokens } from '
|
|
7
|
-
import { paLightTheme } from '
|
|
8
|
-
import { paDarkTheme } from '
|
|
6
|
+
import { paColorsTokens } from './tokens/pa/paColors'
|
|
7
|
+
import { paLightTheme } from './tokens/pa/paLightTheme'
|
|
8
|
+
import { paDarkTheme } from './tokens/pa/paDarkTheme'
|
|
9
9
|
|
|
10
10
|
export {
|
|
11
11
|
cnamColorsTokens,
|
|
@@ -1,7 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Meta, Source} from '@storybook/addon-docs/blocks';
|
|
2
2
|
|
|
3
3
|
<Meta title="Fondamentaux/Customisation et thèmes" />
|
|
4
4
|
|
|
5
5
|
# Customisation et thèmes
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Étapes pour changer le thème du Design System aux couleurs Portail Agent
|
|
8
|
+
|
|
9
|
+
### 1. Modification du fichier nuxt.config.ts
|
|
10
|
+
|
|
11
|
+
1. Ouvrez le fichier nuxt.config.ts dans votre éditeur de code.
|
|
12
|
+
2. Remplacer les valeurs des thèmes `cnamLightTheme` et `cnamDarkTheme` par les valeurs de la charte PA : `paLightTheme` et `paDarkTheme`.
|
|
13
|
+
|
|
14
|
+
<Source dark code={`
|
|
15
|
+
import {paLightTheme} from '@cnamts/synapse/designTokens/tokens/pa/paLightTheme'
|
|
16
|
+
import {paDarkTheme} from '@cnamts/synapse/designTokens/tokens/pa/paDarkTheme'
|
|
17
|
+
`}
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
3. Localisez la configuration de base de Vuetify (ligne 31 dans le fichier `nuxt.config.ts`).
|
|
21
|
+
4. Mettez à jour le thème en configurant les couleurs selon la charte PA si nécessaire :
|
|
22
|
+
|
|
23
|
+
<Source dark code={`
|
|
24
|
+
theme: {
|
|
25
|
+
defaultTheme: 'light',
|
|
26
|
+
themes: {
|
|
27
|
+
light: {
|
|
28
|
+
colors: {
|
|
29
|
+
...paLightTheme,
|
|
30
|
+
// ...customLightTheme
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
dark: {
|
|
34
|
+
colors: {
|
|
35
|
+
...paDarkTheme,
|
|
36
|
+
//...customDarkTheme,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
`}
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
NB : les thèmes `customLightTheme` et `customDarkTheme` sont à votre disposition pour ajouter des couleurs supplémentaires.
|
|
45
|
+
|
|
46
|
+
### 2. Relancer le projet
|
|
47
|
+
|
|
48
|
+
Après avoir effectué les modifications dans le fichier de configuration, relancez le serveur de développement pour appliquer les changements :
|
|
49
|
+
|
|
50
|
+
<Source dark code={`
|
|
51
|
+
pnpm dev
|
|
52
|
+
`}
|
|
53
|
+
/>
|
|
54
|
+
|
|
55
|
+
### 3. Vérification
|
|
56
|
+
|
|
57
|
+
Une fois le projet redémarré, vérifiez que la charte PA est bien appliquée.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Compute a size in bytes into an human readable value */
|
|
2
|
+
export function calcHumanFileSize(
|
|
3
|
+
size: number,
|
|
4
|
+
fileSizeUnits: string[],
|
|
5
|
+
separator = ' ',
|
|
6
|
+
): string {
|
|
7
|
+
const index = Math.floor(Math.log(size) / Math.log(1024))
|
|
8
|
+
|
|
9
|
+
const computedSize = Number((size / Math.pow(1024, index)).toFixed(2)) * 1
|
|
10
|
+
|
|
11
|
+
return computedSize + separator + fileSizeUnits[index]
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { calcHumanFileSize } from '../'
|
|
4
|
+
|
|
5
|
+
const sizeMax = 4096 * 1024 // 4MB
|
|
6
|
+
|
|
7
|
+
const fileSizeUnits = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
8
|
+
|
|
9
|
+
describe('calcHumanFileSize', () => {
|
|
10
|
+
it('returns the readable size', () => {
|
|
11
|
+
expect(calcHumanFileSize(sizeMax, fileSizeUnits)).toEqual('4 MB')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns the readable size with a custom text separator', () => {
|
|
15
|
+
const separator = '_'
|
|
16
|
+
|
|
17
|
+
expect(calcHumanFileSize(sizeMax, fileSizeUnits, separator)).toEqual(
|
|
18
|
+
'4_MB',
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
})
|