@cnamts/synapse 0.0.3-alpha → 0.0.5-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.
Files changed (300) hide show
  1. package/dist/design-system-v3.d.ts +1461 -68
  2. package/dist/design-system-v3.js +4775 -1673
  3. package/dist/design-system-v3.umd.cjs +10 -1
  4. package/dist/style.css +1 -1
  5. package/package.json +6 -2
  6. package/src/assets/tokens.scss +0 -1
  7. package/src/components/Alert/Accessibilite.mdx +14 -0
  8. package/src/components/Alert/Accessibilite.stories.ts +166 -0
  9. package/src/components/Alert/AccessibiliteItems.ts +152 -0
  10. package/src/components/Alert/Alert.mdx +1 -1
  11. package/src/components/Alert/Alert.stories.ts +91 -1
  12. package/src/components/Alert/constants/ExpertiseLevelEnum.ts +4 -0
  13. package/src/components/BackBtn/Accessibilite.mdx +14 -0
  14. package/src/components/BackBtn/Accessibilite.stories.ts +166 -0
  15. package/src/components/BackBtn/AccessibiliteItems.ts +132 -0
  16. package/src/components/BackBtn/BackBtn.mdx +1 -1
  17. package/src/components/BackBtn/BackBtn.stories.ts +84 -1
  18. package/src/components/BackBtn/constants/ExpertiseLevelEnum.ts +4 -0
  19. package/src/components/BackToTopBtn/Accessibilite.mdx +14 -0
  20. package/src/components/BackToTopBtn/Accessibilite.stories.ts +166 -0
  21. package/src/components/BackToTopBtn/AccessibiliteItems.ts +82 -0
  22. package/src/components/BackToTopBtn/BackToTopBtn.mdx +3 -3
  23. package/src/components/BackToTopBtn/BackToTopBtn.stories.ts +172 -11
  24. package/src/components/BackToTopBtn/constants/ExpertiseLevelEnum.ts +4 -0
  25. package/src/components/CollapsibleList/Accessibilite.mdx +14 -0
  26. package/src/components/CollapsibleList/Accessibilite.stories.ts +166 -0
  27. package/src/components/CollapsibleList/AccessibiliteItems.ts +129 -0
  28. package/src/components/CollapsibleList/CollapsibleList.mdx +2 -2
  29. package/src/components/CollapsibleList/CollapsibleList.stories.ts +37 -1
  30. package/src/components/CollapsibleList/constants/ExpertiseLevelEnum.ts +4 -0
  31. package/src/components/CopyBtn/Accessibilite.mdx +14 -0
  32. package/src/components/CopyBtn/Accessibilite.stories.ts +166 -0
  33. package/src/components/CopyBtn/AccessibiliteItems.ts +135 -0
  34. package/src/components/CopyBtn/CopyBtn.mdx +1 -1
  35. package/src/components/CopyBtn/CopyBtn.stories.ts +120 -1
  36. package/src/components/CopyBtn/CopyBtn.vue +1 -1
  37. package/src/components/CopyBtn/config.ts +2 -0
  38. package/src/components/CopyBtn/constants/ExpertiseLevelEnum.ts +4 -0
  39. package/src/components/Customs/SyBtnSelect/SyBtnSelect.mdx +44 -0
  40. package/src/components/Customs/SyBtnSelect/SyBtnSelect.stories.ts +606 -0
  41. package/src/components/Customs/SyBtnSelect/SyBtnSelect.vue +246 -0
  42. package/src/components/Customs/SyBtnSelect/tests/SyBtnSelect.spec.ts +168 -0
  43. package/src/components/Customs/SyInputSelect/SyInputSelect.mdx +40 -0
  44. package/src/components/Customs/SyInputSelect/SyInputSelect.stories.ts +420 -0
  45. package/src/components/Customs/{CustomInputSelect/CustomInputSelect.vue → SyInputSelect/SyInputSelect.vue} +89 -54
  46. package/src/components/Customs/SyInputSelect/config.ts +10 -0
  47. package/src/components/Customs/SyInputSelect/tests/SyInputSelect.spec.ts +140 -0
  48. package/src/components/Customs/{CustomSelect/CustomSelect.mdx → SySelect/SySelect.mdx} +10 -10
  49. package/src/components/Customs/SySelect/SySelect.stories.ts +338 -0
  50. package/src/components/Customs/{CustomSelect/CustomSelect.vue → SySelect/SySelect.vue} +34 -11
  51. package/src/components/Customs/{CustomInputSelect/tests/CustomInputSelect.spec.ts → SySelect/tests/SySelect.spec.ts} +48 -71
  52. package/src/components/Customs/SyTextField/SyTextField.mdx +44 -0
  53. package/src/components/Customs/SyTextField/SyTextField.stories.ts +403 -0
  54. package/src/components/Customs/SyTextField/SyTextField.vue +110 -0
  55. package/src/components/Customs/SyTextField/tests/SyTextField.spec.ts +93 -0
  56. package/src/components/Customs/SyTextField/tests/__snapshots__/SyTextField.spec.ts.snap +57 -0
  57. package/src/components/Customs/SyTextField/types.d.ts +3 -0
  58. package/src/components/DataList/DataList.mdx +77 -0
  59. package/src/components/DataList/DataList.stories.ts +960 -0
  60. package/src/components/DataList/DataList.vue +140 -0
  61. package/src/components/DataList/DataListLoading/DataListLoading.vue +56 -0
  62. package/src/components/DataList/DataListLoading/tests/DataListLoading.spec.ts +23 -0
  63. package/src/components/DataList/locales.ts +3 -0
  64. package/src/components/DataList/tests/DataList.spec.ts +194 -0
  65. package/src/components/DataList/types.d.ts +23 -0
  66. package/src/components/DataListGroup/DataListGroup.mdx +77 -0
  67. package/src/components/DataListGroup/DataListGroup.stories.ts +987 -0
  68. package/src/components/DataListGroup/DataListGroup.vue +59 -0
  69. package/src/components/DataListGroup/tests/DataListGroup.spec.ts +54 -0
  70. package/src/components/DataListGroup/tests/data/dataListGroupItems.ts +41 -0
  71. package/src/components/DataListGroup/types.d.ts +15 -0
  72. package/src/components/DataListItem/DataListItem.vue +135 -0
  73. package/src/components/DataListItem/config.ts +17 -0
  74. package/src/components/DataListItem/locales.ts +3 -0
  75. package/src/components/DataListItem/tests/DataListItem.spec.ts +156 -0
  76. package/src/components/DataListItem/types.d.ts +23 -0
  77. package/src/components/DialogBox/DialogBox.mdx +14 -0
  78. package/src/components/DialogBox/DialogBox.stories.ts +798 -0
  79. package/src/components/DialogBox/DialogBox.vue +181 -0
  80. package/src/components/DialogBox/config.ts +25 -0
  81. package/src/components/DialogBox/locales.ts +5 -0
  82. package/src/components/DialogBox/tests/DialogBox.spec.ts +329 -0
  83. package/src/components/DialogBox/tests/__snapshots__/DialogBox.spec.ts.snap +46 -0
  84. package/src/components/DownloadBtn/Accessibilite.mdx +14 -0
  85. package/src/components/DownloadBtn/Accessibilite.stories.ts +166 -0
  86. package/src/components/DownloadBtn/AccessibiliteItems.ts +129 -0
  87. package/src/components/DownloadBtn/DownloadBtn.mdx +5 -6
  88. package/src/components/DownloadBtn/DownloadBtn.stories.ts +207 -2
  89. package/src/components/DownloadBtn/constants/ExpertiseLevelEnum.ts +4 -0
  90. package/src/components/ErrorPage/ErrorPage.mdx +21 -0
  91. package/src/components/ErrorPage/ErrorPage.stories.ts +133 -0
  92. package/src/components/ErrorPage/ErrorPage.vue +93 -0
  93. package/src/components/ErrorPage/locales.ts +5 -0
  94. package/src/components/ErrorPage/tests/ErrorPage.spec.ts +40 -0
  95. package/src/components/ErrorPage/tests/__snapshots__/ErrorPage.spec.ts.snap +78 -0
  96. package/src/components/FooterBar/FooterBar.mdx +2 -2
  97. package/src/components/FooterBar/FooterBar.stories.ts +557 -9
  98. package/src/components/FooterBar/config.ts +2 -3
  99. package/src/components/FooterBar/tests/FooterBar.spec.ts +1 -1
  100. package/src/components/FooterBar/tests/FooterBarConfig.spec.ts +1 -1
  101. package/src/components/FooterBar/tests/__snapshots__/FooterBar.spec.ts.snap +2 -2
  102. package/src/components/FranceConnectBtn/Accessibilite.mdx +14 -0
  103. package/src/components/FranceConnectBtn/Accessibilite.stories.ts +194 -0
  104. package/src/components/FranceConnectBtn/AccessibiliteItems.ts +199 -0
  105. package/src/components/FranceConnectBtn/FranceConnectBtn.mdx +1 -1
  106. package/src/components/FranceConnectBtn/FranceConnectBtn.stories.ts +58 -1
  107. package/src/components/FranceConnectBtn/constants/ExpertiseLevelEnum.ts +4 -0
  108. package/src/components/HeaderBar/HeaderBar.mdx +164 -45
  109. package/src/components/HeaderBar/HeaderBar.stories.ts +618 -16
  110. package/src/components/HeaderBar/HeaderBar.vue +60 -22
  111. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderBurgerMenu.mdx +433 -0
  112. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderBurgerMenu.stories.ts +1089 -0
  113. package/src/components/HeaderBar/{HeaderComplexMenu/HeaderComplexMenu.vue → HeaderBurgerMenu/HeaderBurgerMenu.vue} +74 -45
  114. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderMenuItem/HeaderMenuItem.mdx +38 -0
  115. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderMenuItem/HeaderMenuItem.stories.ts +89 -0
  116. package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderMenuItem/tests/__snapshots__/HeaderMenuItem.spec.ts.snap +1 -1
  117. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderMenuSection/HeaderMenuSection.mdx +17 -0
  118. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderMenuSection/HeaderMenuSection.stories.ts +121 -0
  119. package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderMenuSection/HeaderMenuSection.vue +2 -2
  120. package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderMenuSection/tests/HeaderMenuSection.spec.ts +1 -3
  121. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderSubMenu/HeaderSubMenu.mdx +43 -0
  122. package/src/components/HeaderBar/HeaderBurgerMenu/HeaderSubMenu/HeaderSubMenu.stories.ts +261 -0
  123. package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderSubMenu/HeaderSubMenu.vue +17 -3
  124. package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderSubMenu/tests/HeaderSubMenu.spec.ts +1 -1
  125. package/src/components/HeaderBar/HeaderBurgerMenu/tests/HeaderBurgerMenu.spec.ts +180 -0
  126. package/src/components/HeaderBar/HeaderBurgerMenu/tests/__snapshots__/HeaderBurgerMenu.spec.ts.snap +13 -0
  127. package/src/components/HeaderBar/HeaderBurgerMenu/tests/__snapshots__/HeaderComplexMenu.spec.ts.snap +13 -0
  128. package/src/components/HeaderBar/HeaderLogo/HeaderLogo.vue +62 -25
  129. package/src/components/HeaderBar/HeaderLogo/tests/HeaderLogo.spec.ts +49 -1
  130. package/src/components/HeaderBar/HeaderMenuBtn/HeaderMenuBtn.vue +19 -23
  131. package/src/components/HeaderBar/HeaderMenuBtn/tests/HeaderMenuBtn.spec.ts +70 -0
  132. package/src/components/HeaderBar/Usages.mdx +85 -0
  133. package/src/components/HeaderBar/consts.scss +0 -1
  134. package/src/components/HeaderBar/tests/HeaderBar.spec.ts +8 -2
  135. package/src/components/HeaderBar/tests/__snapshots__/HeaderBar.spec.ts.snap +5 -10
  136. package/src/components/HeaderLoading/HeaderLoading.mdx +28 -0
  137. package/src/components/HeaderLoading/HeaderLoading.stories.ts +62 -0
  138. package/src/components/HeaderLoading/HeaderLoading.vue +45 -0
  139. package/src/components/HeaderLoading/tests/HeaderLoading.spec.ts +22 -0
  140. package/src/components/HeaderNavigationBar/HeaderNavigationBar.mdx +128 -0
  141. package/src/components/HeaderNavigationBar/HeaderNavigationBar.stories.ts +784 -0
  142. package/src/components/HeaderNavigationBar/HeaderNavigationBar.vue +194 -0
  143. package/src/components/HeaderNavigationBar/HorizontalNavbar/HorizontalNavbar.vue +74 -0
  144. package/src/components/HeaderNavigationBar/HorizontalNavbar/config.ts +18 -0
  145. package/src/components/HeaderNavigationBar/tests/HeaderNavigationBar.spec.ts +127 -0
  146. package/src/components/HeaderNavigationBar/types.ts +7 -0
  147. package/src/components/HeaderToolbar/HeaderToolbar.mdx +31 -0
  148. package/src/components/HeaderToolbar/HeaderToolbar.stories.ts +343 -0
  149. package/src/components/HeaderToolbar/HeaderToolbar.vue +487 -0
  150. package/src/components/HeaderToolbar/tests/HeaderToolbar.spec.ts +230 -0
  151. package/src/components/HeaderToolbar/types.d.ts +20 -0
  152. package/src/components/LangBtn/Accessibilite.mdx +14 -0
  153. package/src/components/LangBtn/Accessibilite.stories.ts +166 -0
  154. package/src/components/LangBtn/AccessibiliteItems.ts +132 -0
  155. package/src/components/LangBtn/LangBtn.mdx +1 -1
  156. package/src/components/LangBtn/LangBtn.stories.ts +125 -8
  157. package/src/components/LangBtn/constants/ExpertiseLevelEnum.ts +4 -0
  158. package/src/components/LangBtn/tests/LangBtn.spec.ts +1 -1
  159. package/src/components/LangBtn/tests/__snapshots__/LangBtn.spec.ts.snap +1 -1
  160. package/src/components/Logo/Logo.mdx +2 -2
  161. package/src/components/Logo/Logo.stories.ts +147 -1
  162. package/src/components/LogoBrandSection/LogoBrandSection.mdx +14 -0
  163. package/src/components/LogoBrandSection/LogoBrandSection.stories.ts +158 -0
  164. package/src/components/LogoBrandSection/LogoBrandSection.vue +312 -0
  165. package/src/components/LogoBrandSection/assets/ameli-pro.svg +1 -0
  166. package/src/components/LogoBrandSection/assets/ameli.svg +1 -0
  167. package/src/components/LogoBrandSection/assets/cnam.svg +1 -0
  168. package/src/components/LogoBrandSection/assets/compte-ameli.svg +1 -0
  169. package/src/components/LogoBrandSection/dividerDimensionsMapping.ts +14 -0
  170. package/src/components/LogoBrandSection/locales.ts +14 -0
  171. package/src/components/LogoBrandSection/secondaryLogoMapping.ts +24 -0
  172. package/src/components/LogoBrandSection/tests/LogoBrandSection.spec.ts +365 -0
  173. package/src/components/LogoBrandSection/tests/__snapshots__/LogoBrandSection.spec.ts.snap +14 -0
  174. package/src/components/LogoBrandSection/types.ts +8 -0
  175. package/src/components/MaintenancePage/MaintenancePage.mdx +11 -0
  176. package/src/components/MaintenancePage/MaintenancePage.stories.ts +41 -0
  177. package/src/components/MaintenancePage/MaintenancePage.vue +25 -0
  178. package/src/components/MaintenancePage/assets/maintenance.svg +1 -0
  179. package/src/components/MaintenancePage/index.ts +3 -0
  180. package/src/components/MaintenancePage/locales.ts +5 -0
  181. package/src/components/MaintenancePage/tests/MaintenancePage.spec.ts +12 -0
  182. package/src/components/MaintenancePage/tests/__snapshots__/MaintenancePage.spec.ts.snap +3 -0
  183. package/src/components/NotFoundPage/NotFoundPage.mdx +19 -0
  184. package/src/components/NotFoundPage/NotFoundPage.stories.ts +76 -0
  185. package/src/components/NotFoundPage/NotFoundPage.vue +52 -0
  186. package/src/components/NotFoundPage/assets/not-found.svg +1 -0
  187. package/src/components/NotFoundPage/locales.ts +6 -0
  188. package/src/components/NotFoundPage/tests/NotFoundPage.spec.ts +38 -0
  189. package/src/components/NotFoundPage/tests/__snapshots__/NotFoundPage.spec.ts.snap +76 -0
  190. package/src/components/NotificationBar/Accessibilite.mdx +14 -0
  191. package/src/components/NotificationBar/Accessibilite.stories.ts +166 -0
  192. package/src/components/NotificationBar/AccessibiliteItems.ts +174 -0
  193. package/src/components/NotificationBar/NotificationBar.mdx +6 -6
  194. package/src/components/NotificationBar/NotificationBar.stories.ts +1 -1
  195. package/src/components/NotificationBar/NotificationBar.vue +2 -2
  196. package/src/components/NotificationBar/constants/ExpertiseLevelEnum.ts +4 -0
  197. package/src/components/NotificationBar/options.ts +1 -0
  198. package/src/components/NotificationBar/tests/NotificationBar.spec.ts +1 -1
  199. package/src/components/PageContainer/Accessibilite.mdx +14 -0
  200. package/src/components/PageContainer/Accessibilite.stories.ts +166 -0
  201. package/src/components/PageContainer/AccessibiliteItems.ts +52 -0
  202. package/src/components/PageContainer/PageContainer.mdx +1 -1
  203. package/src/components/PageContainer/PageContainer.stories.ts +86 -1
  204. package/src/components/PageContainer/constants/ExpertiseLevelEnum.ts +4 -0
  205. package/src/components/PhoneField/PhoneField.mdx +49 -0
  206. package/src/components/PhoneField/PhoneField.stories.ts +869 -0
  207. package/src/components/PhoneField/PhoneField.vue +230 -0
  208. package/src/components/PhoneField/indicatifs.ts +104 -0
  209. package/src/components/PhoneField/locales.ts +4 -0
  210. package/src/components/PhoneField/tests/PhoneField.spec.ts +179 -0
  211. package/src/components/SkipLink/Accessibilite.mdx +14 -0
  212. package/src/components/SkipLink/Accessibilite.stories.ts +167 -0
  213. package/src/components/SkipLink/AccessibiliteItems.ts +77 -0
  214. package/src/components/SkipLink/SkipLink.stories.ts +50 -1
  215. package/src/components/SkipLink/constants/ExpertiseLevelEnum.ts +4 -0
  216. package/src/components/SocialMediaLinks/SocialMediaLinks.mdx +33 -2
  217. package/src/components/SocialMediaLinks/SocialMediaLinks.stories.ts +38 -1
  218. package/src/components/SocialMediaLinks/tests/SocialMediaLinks.spec.ts +1 -1
  219. package/src/components/SocialMediaLinks/tests/__snapshots__/SocialMediaLinks.spec.ts.snap +2 -2
  220. package/src/components/SubHeader/SubHeader.mdx +31 -0
  221. package/src/components/SubHeader/SubHeader.stories.ts +1032 -0
  222. package/src/components/SubHeader/SubHeader.vue +185 -0
  223. package/src/components/SubHeader/config.ts +12 -0
  224. package/src/components/SubHeader/locales.ts +3 -0
  225. package/src/components/SubHeader/tests/SubHeader.spec.ts +144 -0
  226. package/src/components/UserMenuBtn/UserMenuBtn.mdx +35 -0
  227. package/src/components/UserMenuBtn/UserMenuBtn.stories.ts +438 -0
  228. package/src/components/UserMenuBtn/UserMenuBtn.vue +105 -0
  229. package/src/components/UserMenuBtn/config.ts +24 -0
  230. package/src/components/UserMenuBtn/tests/UserMenuBtn.spec.ts +125 -0
  231. package/src/components/index.ts +33 -7
  232. package/src/composables/index.ts +8 -0
  233. package/src/composables/rules/tests/useFieldValidation.spec.ts +82 -0
  234. package/src/composables/rules/useFieldValidation.ts +53 -0
  235. package/src/composables/widthable/index.ts +29 -0
  236. package/src/composables/widthable/tests/widthable.spec.ts +52 -0
  237. package/src/designTokens/index.ts +2 -0
  238. package/src/designTokens/tokens/cnam/cnamDarkTheme.ts +5 -0
  239. package/src/designTokens/tokens/cnam/cnamLightTheme.ts +3 -2
  240. package/src/main.ts +3 -0
  241. package/src/modules.d.ts +4 -0
  242. package/src/services/index.ts +1 -0
  243. package/src/stories/Demarrer/Accueil.mdx +10 -0
  244. package/src/stories/Demarrer/Accueil.stories.ts +76 -0
  245. package/src/stories/Demarrer/PolitiqueDeConfidentialite.mdx +9 -0
  246. package/src/stories/Demarrer/PolitiqueDeConfidentialite.stories.ts +20 -0
  247. package/src/stories/Fondamentaux/Arrondis.mdx +24 -0
  248. package/src/stories/{Guidelines → Fondamentaux}/Colors.mdx +1 -1
  249. package/src/stories/Fondamentaux/Conteneurs.mdx +7 -0
  250. package/src/stories/Fondamentaux/CustomisationEtThemes.mdx +7 -0
  251. package/src/stories/Fondamentaux/Elevations.mdx +14 -0
  252. package/src/stories/Fondamentaux/Espacements.mdx +29 -0
  253. package/src/stories/{Guidelines → Fondamentaux}/Introduction.mdx +1 -1
  254. package/src/stories/Fondamentaux/StylesTypographiques.mdx +33 -0
  255. package/src/stories/Fondamentaux/Typographie.mdx +58 -0
  256. package/src/stories/GuideDuDev/CommentUtiliserLesRules.mdx +132 -0
  257. package/src/stories/GuideDuDev/moduleDeNotification.mdx +52 -48
  258. package/src/stories/GuideDuDev/vuetifyOptions.mdx +31 -28
  259. package/src/stories/{Fondamentaux → Guidelines}/Accessibilite/Accessibilite.mdx +1 -2
  260. package/src/stories/{Fondamentaux → Guidelines}/Accessibilite/Accessibilite.stories.ts +1 -1
  261. package/src/stories/{Fondamentaux → Guidelines}/EcoConception/Econception.stories.ts +2 -2
  262. package/src/utils/functions/throttleDisplayFn/tests/throttleDisplayFn.spec.ts +47 -0
  263. package/src/utils/functions/throttleDisplayFn/throttleDisplayFn.ts +26 -0
  264. package/src/utils/rules/exactLength/index.ts +33 -0
  265. package/src/utils/rules/exactLength/locales.ts +6 -0
  266. package/src/utils/rules/required/index.ts +25 -0
  267. package/src/utils/rules/required/locales.ts +5 -0
  268. package/src/utils/rules/required/ruleMessageHelper.ts +14 -0
  269. package/src/utils/rules/required/tests/index.spec.ts +47 -0
  270. package/src/utils/rules/required/tests/rulesMessageHelper.spec.ts +22 -0
  271. package/src/utils/rules/types.d.ts +15 -0
  272. package/src/components/Beta/beta.mdx +0 -5
  273. package/src/components/Customs/CustomInputSelect/CustomInputSelect.mdx +0 -42
  274. package/src/components/Customs/CustomInputSelect/CustomInputSelect.stories.ts +0 -154
  275. package/src/components/Customs/CustomSelect/CustomSelect.stories.ts +0 -182
  276. package/src/components/Customs/CustomSelect/tests/CustomSelect.spec.ts +0 -236
  277. package/src/components/Deprecated/deprecated.mdx +0 -5
  278. package/src/components/HeaderBar/HeaderComplexMenu/HeaderComplexMenu.stories.ts +0 -272
  279. package/src/components/HeaderBar/HeaderComplexMenu/HeaderMenuItem/HeaderMenuItem.stories.ts +0 -49
  280. package/src/components/HeaderBar/HeaderComplexMenu/HeaderMenuSection/HeaderMenuSection.stories.ts +0 -56
  281. package/src/components/HeaderBar/HeaderComplexMenu/HeaderSubMenu/HeaderSubMenu.stories.ts +0 -137
  282. package/src/components/HeaderBar/HeaderComplexMenu/tests/HeaderComplexMenu.spec.ts +0 -129
  283. package/src/components/HeaderBar/HeaderComplexMenu/tests/__snapshots__/HeaderComplexMenu.spec.ts.snap +0 -18
  284. package/src/stories/Guidelines/CustomisationEtThemes.mdx +0 -3
  285. package/src/stories/Guidelines/Typo.mdx +0 -53
  286. package/src/stories/Home/Accueil.mdx +0 -7
  287. package/src/stories/Home/PolitiqueDeConfidentialite.mdx +0 -4
  288. package/src/stories/Home/synapse.webp +0 -0
  289. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderMenuItem/HeaderMenuItem.vue +0 -0
  290. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/HeaderMenuItem/tests/HeaderMenuItem.spec.ts +0 -0
  291. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/conts.ts +0 -0
  292. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/locals.ts +0 -0
  293. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/tests/useHandleSubMenus.spec.ts +0 -0
  294. /package/src/components/HeaderBar/{HeaderComplexMenu → HeaderBurgerMenu}/useHandleSubMenus.ts +0 -0
  295. /package/src/components/Logo/{types.d.ts → types.ts} +0 -0
  296. /package/src/stories/{Fondamentaux → Guidelines}/Accessibilite/AccessibiliteItems.ts +0 -0
  297. /package/src/stories/{Fondamentaux → Guidelines}/Accessibilite/constants/ExpertiseLevelEnum.ts +0 -0
  298. /package/src/stories/{Fondamentaux → Guidelines}/Accessibilite/constants/RGAALevelEnum.ts +0 -0
  299. /package/src/stories/{Fondamentaux → Guidelines}/EcoConception/EcoConception.mdx +0 -0
  300. /package/src/stories/{Fondamentaux → Guidelines}/EcoConception/ecoDesignItems.ts +0 -0
@@ -0,0 +1,132 @@
1
+ import {Meta, Source} from '@storybook/addon-docs/blocks';
2
+
3
+ <Meta title="Guide Du Dev/Comment utiliser les rules"/>
4
+
5
+ # Comment utiliser les règles de validation
6
+
7
+ Ce guide décrit comment utiliser le composable `useFieldValidation` pour créer des règles de validation flexibles et personnalisées dans votre projet Vue.js.
8
+
9
+ ---
10
+
11
+ ## Introduction
12
+
13
+ Le composable `useFieldValidation` vous permet de définir des règles de validation dynamiques pour différents champs dans vos formulaires. Ce composable est conçu pour être flexible, réutilisable et facilement intégrable avec des bibliothèques comme Vuetify.
14
+
15
+ ---
16
+
17
+ ## Structure du composable
18
+
19
+ ### Type `RuleOptions`
20
+
21
+ <Source dark code={`
22
+ type RuleOptions = {
23
+ fieldName?: string; // Nom du champ utilisé dans les messages d'erreur
24
+ message?: string; // Message personnalisé pour la règle
25
+ length?: number; // Longueur minimale ou maximale
26
+ value?: number; // Valeur minimale ou maximale
27
+ pattern?: RegExp; // Motif à valider
28
+ ignoreSpace?: boolean; // Ignorer les espaces lors de la validation de longueur
29
+ };
30
+ `} />
31
+
32
+ ---
33
+
34
+ ## Exemple d'intégration
35
+
36
+ ### Script Vue.js
37
+
38
+ <Source dark code={`
39
+ <script lang="ts" setup>
40
+ import {ref} from 'vue';
41
+ import {useFieldValidation} from '@cnamts/synapse';
42
+
43
+ const {generateRules} = useFieldValidation();
44
+
45
+ const firstName = ref('');
46
+ const email = ref('');
47
+ const age = ref('');
48
+
49
+ const rules = {
50
+ firstName: generateRules([
51
+ {type: 'required', options: {message: 'Ce champ est requis.'}},
52
+ {type: 'minLength', options: {length: 3, ignoreSpace: true}},
53
+ {type: 'maxLength', options: {length: 20}},
54
+ ]),
55
+ email: generateRules([
56
+ {type: 'required', options: {fieldName: 'Email'}},
57
+ {type: 'email'},
58
+ ]),
59
+ age: generateRules([
60
+ {type: 'min', options: {value: 18}},
61
+ {type: 'max', options: {value: 99}},
62
+ ]),
63
+ };
64
+
65
+ const validateField = (field: string) => {
66
+ return rules[field].every((rule) => rule(field));
67
+ };
68
+
69
+ const handleSubmit = () => {
70
+ if (validateField('firstName') && validateField('email') && validateField('age')) {
71
+ alert('Formulaire valide.');
72
+ } else {
73
+ alert('Merci de vérifier les champs.');
74
+ }
75
+ };
76
+ </script>
77
+ `} />
78
+ ---
79
+
80
+ ### Template Vue.js
81
+
82
+ <Source dark code={`
83
+ <template>
84
+ <v-form
85
+ @submit.prevent="handleSubmit">
86
+ <v-text-field
87
+ v-model="firstName"
88
+ :rules="rules.firstName"
89
+ label="Prénom"
90
+ @blur="validateField('firstName')"
91
+ />
92
+ <v-text-field
93
+ v-model="email"
94
+ :rules="rules.email"
95
+ label="Email"
96
+ @blur="validateField('email')"
97
+ />
98
+ <v-text-field
99
+ v-model="age"
100
+ :rules="rules.age"
101
+ label="Âge"
102
+ @blur="validateField('age')"
103
+ />
104
+ <v-btn block class="mt-2" type="submit">Soumettre</v-btn>
105
+ </v-form>
106
+ </template>
107
+ `} />
108
+ ---
109
+
110
+ ## Fonctionnalités supportées
111
+
112
+ - **Validation requise** (`required`)
113
+ - **Longueur minimale** (`minLength`)
114
+ - **Longueur maximale** (`maxLength`)
115
+ - **Valeur minimale** (`min`)
116
+ - **Valeur maximale** (`max`)
117
+ - **Validation par motif** (`matchPattern`)
118
+ - **Validation d'email** (`email`)
119
+
120
+ ---
121
+
122
+ ## Bonnes pratiques
123
+
124
+ - Toujours tester les messages d'erreur personnalisés pour garantir une bonne expérience utilisateur.
125
+ - Centraliser la logique de validation pour une meilleure maintenance.
126
+ - Documenter les règles complexes pour aider votre équipe à comprendre leur fonctionnement.
127
+
128
+ ---
129
+
130
+ ## Conclusion
131
+
132
+ Avec `useFieldValidation`, vous disposez d'un moyen simple et flexible pour gérer vos validations de formulaires dans Vue.js. Combinez-le avec des bibliothèques comme Vuetify pour une expérience utilisateur optimisée.
@@ -1,4 +1,4 @@
1
- import { Meta } from '@storybook/addon-docs/blocks';
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  <Meta title="Guide Du Dev/Services/useNotificationService" />
4
4
  # useNotificationService
@@ -7,78 +7,82 @@ import { Meta } from '@storybook/addon-docs/blocks';
7
7
 
8
8
  ## Importation et utilisation
9
9
 
10
- ```
11
- import { useNotificationService } from '@/services/useNotificationService'
10
+ <Source dark code={`
11
+ import { useNotificationService } from '@cnamts/synapse/src/services/useNotificationService'
12
12
 
13
13
  const { notificationQueue, addNotification, removeNotification, clearQueue } = useNotificationService()
14
- ```
14
+ `} />
15
15
 
16
- Propriétés et Méthodes:
16
+ ## Propriétés et méthodes :
17
17
 
18
- ```
18
+ <Source dark code={`
19
19
  notificationQueue: Ref<Notification[]>
20
- ```
20
+ `} />
21
21
 
22
22
  Une référence réactive à la file d'attente des notifications. Elle contient un tableau d'objets de type Notification.
23
23
 
24
- ``` addNotification(notification: Notification): void ```
24
+ <Source dark code={`
25
+ addNotification(notification: Notification): void
26
+ `} />
25
27
 
26
28
  Ajoute une nouvelle notification à la file d'attente, à condition qu'une notification avec le même id ne soit pas déjà présente.
27
29
 
28
- ```
30
+ <Source dark code={`
29
31
  addNotification({
30
32
  id: 'notif-1',
31
33
  message: 'Notification 1',
32
34
  type: 'info',
33
35
  duration: 5000
34
36
  })
35
- ```
37
+ `} />
36
38
 
37
- ```
39
+ <Source dark code={`
38
40
  removeNotification(id: string): void
39
- ```
41
+ `} />
40
42
  Supprime une notification de la file d'attente en fonction de son id.
41
43
 
42
- ```
44
+ <Source dark code={`
43
45
  removeNotification('notif-1')
44
- ```
46
+ `} />
45
47
 
46
- ```
48
+ <Source dark code={`
47
49
  clearQueue(): void
48
- ```
50
+ `} />
49
51
 
50
52
  Efface toutes les notifications de la file d'attente.
51
53
 
52
54
 
53
- ```
55
+ <Source dark code={`
54
56
  clearQueue()
55
- ```
57
+ `} />
56
58
 
57
- Typage de Notification
59
+ ## Typage de Notification
58
60
 
59
61
  Le type Notification est défini comme suit :
60
62
 
61
- ```
62
-
63
+ <Source dark code={`
63
64
  type Notification = {
64
65
  id: string
65
66
  message: string
66
67
  type: 'success' | 'error' | 'info' | 'warning'
67
68
  duration?: number
68
69
  }
69
- ```
70
+ `} />
71
+
70
72
  Propriétés de Notification
71
- ```
73
+
74
+ <Source dark code={`
72
75
  id: string — Identifiant unique de la notification.
73
76
  message: string — Le texte à afficher dans la notification.
74
77
  type: 'success' | 'error' | 'info' | 'warning' — Le type de la notification, qui peut influencer son apparence.
75
78
  duration?: number — Durée pendant laquelle la notification sera visible (en millisecondes).
76
- ```
77
- Exemples d'utilisation
78
- Ajouter une notification
79
+ `} />
79
80
 
80
- ```
81
+ ## Exemples d'utilisation
81
82
 
83
+ Ajouter une notification
84
+
85
+ <Source dark code={`
82
86
  const { addNotification } = useNotificationService()
83
87
 
84
88
  addNotification({
@@ -87,39 +91,40 @@ addNotification({
87
91
  type: 'success',
88
92
  duration: 3000
89
93
  })
90
- ```
94
+ `} />
95
+
91
96
  Supprimer une notification
92
97
 
93
- ```
98
+ <Source dark code={`
94
99
  const { removeNotification } = useNotificationService()
95
100
 
96
101
  removeNotification('notif-2')
97
- ```
98
- Effacer la file d'attente de notifications
102
+ `} />
99
103
 
100
- ```
104
+ Effacer la file d'attente de notifications
101
105
 
106
+ <Source dark code={`
102
107
  const { clearQueue } = useNotificationService()
103
108
 
104
109
  clearQueue()
105
- ```
110
+ `} />
106
111
 
107
112
  Accéder à la file d'attente
108
113
 
109
- ```
114
+ <Source dark code={`
110
115
  const { notificationQueue } = useNotificationService()
111
116
 
112
117
  console.log(notificationQueue.value) // Affiche toutes les notifications présentes dans la file d'attente
113
- ```
118
+ `} />
119
+
114
120
  Utilisation dans un composant Vue
115
121
 
116
- ```
117
- <script setup lang="ts">
122
+ <Source dark code={`
118
123
  <script setup lang="ts">
119
124
  import { VBtn } from 'vuetify/components'
120
- import NotificationBar from '@/components/NotificationBar/NotificationBar.vue'
121
- import { useNotificationService } from '@/services/NotificationService'
122
- import type { Notification } from '@/components/NotificationBar/types'
125
+ import NotificationBar from '@cnamts/synapse'
126
+ import { useNotificationService } from '@cnamts/synapse/src/services/NotificationService'
127
+ import type { Notification } from '@cnamts/synapse/src/components/NotificationBar/types'
123
128
 
124
129
  const { addNotification } = useNotificationService()
125
130
 
@@ -171,12 +176,11 @@ Utilisation dans un composant Vue
171
176
  </template>
172
177
 
173
178
  <style scoped>
174
- .button-group {
175
- display: flex;
176
- flex-direction: column;
177
- gap: 16px;
178
- margin-top: 20px;
179
- }
179
+ .button-group {
180
+ display: flex;
181
+ flex-direction: column;
182
+ gap: 16px;
183
+ margin-top: 20px;
184
+ }
180
185
  </style>
181
-
182
- ```
186
+ `} />
@@ -1,4 +1,4 @@
1
- import { Meta } from '@storybook/addon-docs/blocks';
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  <Meta title="Guide Du Dev/VuetifyOptions" />
4
4
 
@@ -13,60 +13,63 @@ Utilisation de vuetifyOptions
13
13
  Certains composants du design system acceptent une prop vuetifyOptions qui vous permet de personnaliser le comportement et le style du composant basé sur Vuetify.
14
14
  Vous trouverez des exemples de configurations directement dans la documentation de chaque composant que nous proposons pour mieux comprendre comment les personnaliser.
15
15
 
16
- Exemple d'utilisation dans un composant vuetify:
16
+ ## Exemple d'utilisation dans un composant Vuetify:
17
17
 
18
18
  Prenons l'exemple d'un bouton (VBtn).
19
19
 
20
20
  Voici un exemple d'utilisation du composant :
21
21
 
22
- ```vue
23
-
22
+ <Source dark code={`
24
23
  <MyButton
25
- :title="'Cliquez ici'"
26
- :vuetifyOptions="{ btn: { color: 'secondary', icon: true } }"
27
- />
28
- ```
24
+ :title="'Cliquez ici'"
25
+ :vuetifyOptions="{ btn: { color: 'secondary', icon: true } }"
26
+ />
27
+ `} />
28
+
29
29
  Dans cet exemple :
30
30
 
31
- Le texte du bouton est défini via la prop title.
32
- Vous pouvez passer un objet vuetifyOptions pour personnaliser les propriétés du composant Vuetify sous-jacent (ici, VBtn).
31
+ > Le texte du bouton est défini via la prop title.
33
32
 
34
- Explication
33
+ > Vous pouvez passer un objet vuetifyOptions pour personnaliser les propriétés du composant Vuetify sous-jacent (ici, VBtn).
35
34
 
36
- Propriétés de Vuetify : Vous pouvez configurer n'importe quelle option reconnue par Vuetify. Par exemple, pour un bouton (VBtn), vous pourriez ajuster sa couleur, son icône, son style (outlined, elevation, etc.).
35
+ <b>Explication</b>
37
36
 
38
- Fusion des options : Le design system gère la fusion des options par défaut et celles que vous fournissez dans vuetifyOptions. Si vous ne définissez pas une option spécifique, la valeur par défaut sera utilisée.
37
+ > Propriétés de Vuetify : Vous pouvez configurer n'importe quelle option reconnue par Vuetify. Par exemple, pour un bouton (VBtn), vous pourriez ajuster sa couleur, son icône, son style (outlined, elevation, etc.).
39
38
 
40
- Exemple détaillé
39
+ > Fusion des options : Le design system gère la fusion des options par défaut et celles que vous fournissez dans vuetifyOptions. Si vous ne définissez pas une option spécifique, la valeur par défaut sera utilisée.
40
+
41
+ <b>Exemple détaillé</b>
41
42
 
42
43
  Voici un exemple plus complet :
43
- ```
44
- vue
45
44
 
45
+ <Source dark code={`
46
46
  <MyButton
47
- :title="'Valider'"
48
- :vuetifyOptions="{ btn: { color: 'primary', outlined: false, icon: true } }"
49
- />
50
- ```
47
+ :title="'Valider'"
48
+ :vuetifyOptions="{ btn: { color: 'primary', outlined: false, icon: true } }"
49
+ />
50
+ `} />
51
+
51
52
  Dans cet exemple :
52
53
 
53
- Le bouton sera bleu (color: 'primary').
54
- Il n'aura pas de contour (outlined: false).
55
- Une icône sera affichée sur le bouton (icon: true).
54
+ > Le bouton sera bleu (color: 'primary').
56
55
 
57
- Options par défaut
56
+ > Il n'aura pas de contour (outlined: false).
57
+
58
+ > Une icône sera affichée sur le bouton (icon: true).
59
+
60
+ ## Options par défaut
58
61
 
59
62
  Chaque composant du design system dispose d'options par défaut qui lui assurent un style et un comportement cohérents. Cependant, si vous souhaitez personnaliser ces options, vous pouvez utiliser la prop vuetifyOptions pour adapter ces composants à vos besoins spécifiques sans compromettre la structure de base du design system.
60
63
  Exemple de bouton par défaut
61
64
 
62
65
  Sans fournir de vuetifyOptions, le bouton pourrait ressembler à ceci :
63
66
 
64
- ```vue
65
-
67
+ <Source dark code={`
66
68
  <MyButton :title="'Par défaut'" />
67
- ```
69
+ `} />
70
+
68
71
  Ce bouton utilisera les options par défaut définies dans le design system, telles que la couleur, le style de bordure ou les icônes.
69
72
 
70
- Conclusion
73
+ ## Conclusion
71
74
 
72
75
  L'intégration des vuetifyOptions dans les composants de ce design system vous offre une grande flexibilité pour personnaliser les composants en fonction de vos besoins spécifiques. Grâce à ce mécanisme, vous pouvez ajuster des propriétés telles que la couleur, les icônes et d'autres configurations Vuetify tout en vous appuyant sur des valeurs par défaut bien définies. Vous n'avez pas à vous soucier de la gestion interne des options : il vous suffit de passer les options personnalisées via la prop vuetifyOptions, et le composant s'adaptera automatiquement.
@@ -13,8 +13,7 @@ En tant que personne morale de droit public nous concevons les composants de not
13
13
 
14
14
  Le RGAA est un outil méthodologique de certification permettant d'assurer par le respect de ses critères une manipulation des produits numériques dans le domaine du Web de manière égale entre chaque citoyen, qu'il soit ou non en situation de handicap (visuel, auditif, moteur, trouble dys...). Basé sur les travaux du W3C Web Accessibility Initiative (WAI) il vise à garantir quatre indices de performance:**la bonne perceptibilité de l'information**, une **manipulation efficiente dans la navigation**, une **bonne compréhension** et une **robustesse efficace** dans l'usage des produits numériques.
15
15
 
16
- [En savoir plus sur le RGAA](https://www.numerique.gouv.fr/publications/rgaa-accessibilite/#contenu)
17
-
16
+ [En savoir plus sur le RGAA](https://www.numerique.gouv.fr/publications/rgaa-accessibilite/#contenu)<br/>
18
17
  [En savoir plus sur le W3C WAI](https://www.w3.org/WAI/fundamentals/)
19
18
 
20
19
  [](https://digital-design-system.netlify.app/fondamentaux/accessibilite#quels-sont-les-criteres-du-rgaa)Quels sont les critères du RGAA?
@@ -3,7 +3,7 @@ import type { StoryObj } from '@storybook/vue3'
3
3
  import { AccessibiliteItems } from './AccessibiliteItems'
4
4
 
5
5
  export default {
6
- title: 'Fondamentaux/Accessibilite',
6
+ title: 'Guidelines/Accessibilité',
7
7
  }
8
8
 
9
9
  export const AccessibilitePanel: StoryObj = {
@@ -1,9 +1,9 @@
1
1
  import { VExpansionPanels, VExpansionPanel } from 'vuetify/components'
2
2
  import type { StoryObj } from '@storybook/vue3'
3
- import { ecoDesignItems } from '@/stories/Fondamentaux/EcoConception/ecoDesignItems'
3
+ import { ecoDesignItems } from '@/stories/Guidelines/EcoConception/ecoDesignItems'
4
4
 
5
5
  export default {
6
- title: 'Fondamentaux/EcoConception',
6
+ title: 'Guidelines/Éco-conception',
7
7
  }
8
8
 
9
9
  export const EcoPanel: StoryObj = {
@@ -0,0 +1,47 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import throttleDisplayFn from '../throttleDisplayFn'
3
+
4
+ describe('throttleDisplayFn', () => {
5
+ vi.stubGlobal('requestAnimationFrame', (fn: () => void) => fn())
6
+
7
+ beforeEach(() => {
8
+ vi.useFakeTimers()
9
+ })
10
+
11
+ afterEach(() => {
12
+ vi.restoreAllMocks()
13
+ vi.clearAllTimers()
14
+ })
15
+
16
+ it('should call the function immediately if delay has passed', () => {
17
+ const mockFn = vi.fn()
18
+ const delay = 100
19
+ const throttledFn = throttleDisplayFn(mockFn, delay)
20
+
21
+ throttledFn()
22
+ expect(mockFn).toHaveBeenCalledTimes(1)
23
+
24
+ vi.spyOn(performance, 'now').mockReturnValue(performance.now() + delay + 1)
25
+ throttledFn()
26
+ expect(mockFn).toHaveBeenCalledTimes(2)
27
+ })
28
+
29
+ it('should call the function after the delay if called multiple times within the delay', () => {
30
+ const mockFn = vi.fn()
31
+ const delay = 100
32
+ const throttledFn = throttleDisplayFn(mockFn, delay)
33
+
34
+ throttledFn()
35
+ expect(mockFn).toHaveBeenCalledTimes(1)
36
+
37
+ throttledFn()
38
+ throttledFn()
39
+
40
+ expect(mockFn).toHaveBeenCalledTimes(1)
41
+
42
+ // Advance timers to trigger the setTimeout
43
+ vi.advanceTimersByTime(delay)
44
+
45
+ expect(mockFn).toHaveBeenCalledTimes(2)
46
+ })
47
+ })
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Returns a throttled version of the provided function that will only be called once every `delay` milliseconds.
3
+ */
4
+ export default function throttleDisplayFn<
5
+ F extends (...args: unknown[]) => void,
6
+ >(fn: F, delay: number) {
7
+ let timeout: number | null = null
8
+ let lastCalled = 0
9
+
10
+ return function (...args: Parameters<F>) {
11
+ if (timeout !== null) {
12
+ window.clearTimeout(timeout)
13
+ }
14
+
15
+ if (performance.now() - lastCalled >= delay) {
16
+ window.requestAnimationFrame(() => fn(...args))
17
+ lastCalled = performance.now()
18
+ }
19
+ else {
20
+ timeout = window.setTimeout(() => {
21
+ fn(...args)
22
+ lastCalled = performance.now()
23
+ }, delay)
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,33 @@
1
+ import { ruleMessage } from '../required/ruleMessageHelper'
2
+ import type {
3
+ ValidationRule,
4
+ ValidationResult,
5
+ ErrorMessages,
6
+ Value,
7
+ } from '../types'
8
+
9
+ import { defaultErrorMessages } from './locales'
10
+
11
+ /** Check that the value does not exceeds the specified length */
12
+ export function exactLengthFn(
13
+ lengthValue: number,
14
+ ignoreSpaces = false,
15
+ errorMessages: ErrorMessages<number> = defaultErrorMessages,
16
+ ): ValidationRule {
17
+ return (value: Value): ValidationResult => {
18
+ if (!value) {
19
+ return true
20
+ }
21
+
22
+ if (ignoreSpaces) {
23
+ value = value.replace(/\s/g, '')
24
+ }
25
+
26
+ return (
27
+ value.length === lengthValue
28
+ || ruleMessage(errorMessages, 'default', [lengthValue])
29
+ )
30
+ }
31
+ }
32
+
33
+ export const exactLength = exactLengthFn
@@ -0,0 +1,6 @@
1
+ import type { ErrorMessages } from '../types'
2
+
3
+ export const defaultErrorMessages: ErrorMessages<number> = {
4
+ default: (length: number) =>
5
+ `La longueur du champ doit être de ${length} caractères.`,
6
+ }
@@ -0,0 +1,25 @@
1
+ import { ruleMessage } from './ruleMessageHelper'
2
+ import type { ValidationRule, ValidationResult, ErrorMessages } from '../types'
3
+
4
+ import { defaultErrorMessages } from './locales'
5
+
6
+ export type Value = string | string[] | null
7
+
8
+ export function requiredFn(
9
+ errorMessages: ErrorMessages = defaultErrorMessages,
10
+ ): ValidationRule<Value> {
11
+ return (value: Value): ValidationResult => {
12
+ let valid: boolean
13
+
14
+ if (Array.isArray(value)) {
15
+ valid = value.length !== 0
16
+ }
17
+ else {
18
+ valid = Boolean(typeof value === 'string' ? value.trim() : value)
19
+ }
20
+
21
+ return valid || ruleMessage(errorMessages, 'default')
22
+ }
23
+ }
24
+
25
+ export const required = requiredFn()
@@ -0,0 +1,5 @@
1
+ import type { ErrorMessages } from '../types'
2
+
3
+ export const defaultErrorMessages: ErrorMessages = {
4
+ default: 'Le champ est requis.',
5
+ }
@@ -0,0 +1,14 @@
1
+ import type { ErrorMessages, GenericFnOpt } from '../types'
2
+
3
+ /** Get the value of an error message */
4
+ export function ruleMessage<T>(
5
+ errorMessages: ErrorMessages<T>,
6
+ key: string,
7
+ args: T[] = [],
8
+ ): string {
9
+ if (typeof errorMessages[key] === 'function') {
10
+ return (errorMessages[key] as GenericFnOpt<T>)(...args)
11
+ }
12
+
13
+ return errorMessages[key] as string
14
+ }
@@ -0,0 +1,47 @@
1
+ import { requiredFn } from '../index'
2
+ import { describe, it, expect } from 'vitest'
3
+
4
+ describe('requiredFn', () => {
5
+ it('returns true for non-empty string', () => {
6
+ const rule = requiredFn()
7
+ const result = rule('non-empty')
8
+ expect(result).toBe(true)
9
+ })
10
+
11
+ it('returns false for empty string', () => {
12
+ const rule = requiredFn()
13
+ const result = rule('')
14
+ expect(result).toBe('Le champ est requis.')
15
+ })
16
+
17
+ it('returns true for non-empty array', () => {
18
+ const rule = requiredFn()
19
+ const result = rule(['item'])
20
+ expect(result).toBe(true)
21
+ })
22
+
23
+ it('returns false for empty array', () => {
24
+ const rule = requiredFn()
25
+ const result = rule([])
26
+ expect(result).toBe('Le champ est requis.')
27
+ })
28
+
29
+ it('returns true for non-null value', () => {
30
+ const rule = requiredFn()
31
+ const result = rule('value')
32
+ expect(result).toBe(true)
33
+ })
34
+
35
+ it('returns false for null value', () => {
36
+ const rule = requiredFn()
37
+ const result = rule(null)
38
+ expect(result).toBe('Le champ est requis.')
39
+ })
40
+
41
+ it('returns custom error message for empty string', () => {
42
+ const customMessages = { default: 'Custom required message' }
43
+ const rule = requiredFn(customMessages)
44
+ const result = rule('')
45
+ expect(result).toBe('Custom required message')
46
+ })
47
+ })