@flipdish/ui-library 0.50.0 → 0.52.0

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 (409) hide show
  1. package/README.md +17 -16
  2. package/dist/components/atoms/Checkbox/index.cjs +11 -3
  3. package/dist/components/atoms/Checkbox/index.cjs.map +1 -1
  4. package/dist/components/atoms/Checkbox/index.d.ts.map +1 -1
  5. package/dist/components/atoms/Checkbox/index.js +12 -4
  6. package/dist/components/atoms/Checkbox/index.js.map +1 -1
  7. package/dist/components/atoms/Slider/index.cjs +2 -2
  8. package/dist/components/atoms/Slider/index.cjs.map +1 -1
  9. package/dist/components/atoms/Slider/index.d.ts +3 -1
  10. package/dist/components/atoms/Slider/index.d.ts.map +1 -1
  11. package/dist/components/atoms/Slider/index.js +2 -2
  12. package/dist/components/atoms/Slider/index.js.map +1 -1
  13. package/dist/components/forms/Form/hooks/useForm.cjs +26 -0
  14. package/dist/components/forms/Form/hooks/useForm.cjs.map +1 -0
  15. package/dist/components/forms/Form/hooks/useForm.d.ts +13 -0
  16. package/dist/components/forms/Form/hooks/useForm.d.ts.map +1 -0
  17. package/dist/components/forms/Form/hooks/useForm.js +24 -0
  18. package/dist/components/forms/Form/hooks/useForm.js.map +1 -0
  19. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs +28 -0
  20. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs.map +1 -0
  21. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts +10 -0
  22. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts.map +1 -0
  23. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js +26 -0
  24. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js.map +1 -0
  25. package/dist/components/forms/Form/index.cjs +43 -0
  26. package/dist/components/forms/Form/index.cjs.map +1 -0
  27. package/dist/components/forms/Form/index.d.ts +30 -0
  28. package/dist/components/forms/Form/index.d.ts.map +1 -0
  29. package/dist/components/forms/Form/index.js +40 -0
  30. package/dist/components/forms/Form/index.js.map +1 -0
  31. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs +23 -0
  32. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs.map +1 -0
  33. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts +14 -0
  34. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts.map +1 -0
  35. package/dist/components/forms/Form/utilities/formSubmit.utils.js +21 -0
  36. package/dist/components/forms/Form/utilities/formSubmit.utils.js.map +1 -0
  37. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs +39 -0
  38. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs.map +1 -0
  39. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts +17 -0
  40. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts.map +1 -0
  41. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js +37 -0
  42. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js.map +1 -0
  43. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs +26 -0
  44. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs.map +1 -0
  45. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts +9 -0
  46. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts.map +1 -0
  47. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js +24 -0
  48. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js.map +1 -0
  49. package/dist/components/forms/FormFooter/index.cjs +41 -0
  50. package/dist/components/forms/FormFooter/index.cjs.map +1 -0
  51. package/dist/components/forms/FormFooter/index.d.ts +52 -0
  52. package/dist/components/forms/FormFooter/index.d.ts.map +1 -0
  53. package/dist/components/forms/FormFooter/index.js +39 -0
  54. package/dist/components/forms/FormFooter/index.js.map +1 -0
  55. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs +21 -0
  56. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs.map +1 -0
  57. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts +12 -0
  58. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts.map +1 -0
  59. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js +19 -0
  60. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js.map +1 -0
  61. package/dist/components/forms/FormSection/FormSection.styles.cjs +15 -0
  62. package/dist/components/forms/FormSection/FormSection.styles.cjs.map +1 -0
  63. package/dist/components/forms/FormSection/FormSection.styles.d.ts +9 -0
  64. package/dist/components/forms/FormSection/FormSection.styles.d.ts.map +1 -0
  65. package/dist/components/forms/FormSection/FormSection.styles.js +13 -0
  66. package/dist/components/forms/FormSection/FormSection.styles.js.map +1 -0
  67. package/dist/components/forms/FormSection/index.cjs +43 -0
  68. package/dist/components/forms/FormSection/index.cjs.map +1 -0
  69. package/dist/components/forms/FormSection/index.d.ts +41 -0
  70. package/dist/components/forms/FormSection/index.d.ts.map +1 -0
  71. package/dist/components/forms/FormSection/index.js +41 -0
  72. package/dist/components/forms/FormSection/index.js.map +1 -0
  73. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs +28 -0
  74. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs.map +1 -0
  75. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts +12 -0
  76. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts.map +1 -0
  77. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js +26 -0
  78. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js.map +1 -0
  79. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +68 -0
  80. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -0
  81. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts +26 -0
  82. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -0
  83. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +66 -0
  84. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -0
  85. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs +142 -0
  86. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -0
  87. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +35 -0
  88. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -0
  89. package/dist/components/forms/__internal__/formField/hooks/useFormField.js +140 -0
  90. package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -0
  91. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs +12 -0
  92. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs.map +1 -0
  93. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts +7 -0
  94. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts.map +1 -0
  95. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js +10 -0
  96. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js.map +1 -0
  97. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs +39 -0
  98. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs.map +1 -0
  99. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts +21 -0
  100. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts.map +1 -0
  101. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js +37 -0
  102. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js.map +1 -0
  103. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs +40 -0
  104. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs.map +1 -0
  105. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts +18 -0
  106. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts.map +1 -0
  107. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js +37 -0
  108. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js.map +1 -0
  109. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs +21 -0
  110. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs.map +1 -0
  111. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts +11 -0
  112. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts.map +1 -0
  113. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js +19 -0
  114. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js.map +1 -0
  115. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs +128 -0
  116. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs.map +1 -0
  117. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts +72 -0
  118. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts.map +1 -0
  119. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js +121 -0
  120. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js.map +1 -0
  121. package/dist/components/forms/fields/FormCheckbox/index.cjs +34 -0
  122. package/dist/components/forms/fields/FormCheckbox/index.cjs.map +1 -0
  123. package/dist/components/forms/fields/FormCheckbox/index.d.ts +16 -0
  124. package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -0
  125. package/dist/components/forms/fields/FormCheckbox/index.js +32 -0
  126. package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -0
  127. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs +33 -0
  128. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -0
  129. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +16 -0
  130. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -0
  131. package/dist/components/forms/fields/FormCheckboxGroup/index.js +31 -0
  132. package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -0
  133. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs +26 -0
  134. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs.map +1 -0
  135. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts +11 -0
  136. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts.map +1 -0
  137. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js +24 -0
  138. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js.map +1 -0
  139. package/dist/components/forms/fields/FormColorPicker/index.cjs +33 -0
  140. package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -0
  141. package/dist/components/forms/fields/FormColorPicker/index.d.ts +21 -0
  142. package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -0
  143. package/dist/components/forms/fields/FormColorPicker/index.js +31 -0
  144. package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -0
  145. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs +20 -0
  146. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs.map +1 -0
  147. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts +17 -0
  148. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts.map +1 -0
  149. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js +18 -0
  150. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js.map +1 -0
  151. package/dist/components/forms/fields/FormDatePicker/index.cjs +35 -0
  152. package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -0
  153. package/dist/components/forms/fields/FormDatePicker/index.d.ts +17 -0
  154. package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -0
  155. package/dist/components/forms/fields/FormDatePicker/index.js +33 -0
  156. package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -0
  157. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs +23 -0
  158. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs.map +1 -0
  159. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts +9 -0
  160. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts.map +1 -0
  161. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js +21 -0
  162. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js.map +1 -0
  163. package/dist/components/forms/fields/FormInput/index.cjs +27 -0
  164. package/dist/components/forms/fields/FormInput/index.cjs.map +1 -0
  165. package/dist/components/forms/fields/FormInput/index.d.ts +16 -0
  166. package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -0
  167. package/dist/components/forms/fields/FormInput/index.js +25 -0
  168. package/dist/components/forms/fields/FormInput/index.js.map +1 -0
  169. package/dist/components/forms/fields/FormMultiSelect/index.cjs +44 -0
  170. package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -0
  171. package/dist/components/forms/fields/FormMultiSelect/index.d.ts +17 -0
  172. package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -0
  173. package/dist/components/forms/fields/FormMultiSelect/index.js +42 -0
  174. package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -0
  175. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs +36 -0
  176. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -0
  177. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +29 -0
  178. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -0
  179. package/dist/components/forms/fields/FormRadioCardGroup/index.js +34 -0
  180. package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -0
  181. package/dist/components/forms/fields/FormRadioGroup/index.cjs +31 -0
  182. package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -0
  183. package/dist/components/forms/fields/FormRadioGroup/index.d.ts +17 -0
  184. package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -0
  185. package/dist/components/forms/fields/FormRadioGroup/index.js +29 -0
  186. package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -0
  187. package/dist/components/forms/fields/FormSelect/index.cjs +30 -0
  188. package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -0
  189. package/dist/components/forms/fields/FormSelect/index.d.ts +16 -0
  190. package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -0
  191. package/dist/components/forms/fields/FormSelect/index.js +28 -0
  192. package/dist/components/forms/fields/FormSelect/index.js.map +1 -0
  193. package/dist/components/forms/fields/FormSlider/index.cjs +43 -0
  194. package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -0
  195. package/dist/components/forms/fields/FormSlider/index.d.ts +17 -0
  196. package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -0
  197. package/dist/components/forms/fields/FormSlider/index.js +41 -0
  198. package/dist/components/forms/fields/FormSlider/index.js.map +1 -0
  199. package/dist/components/forms/fields/FormTextArea/index.cjs +27 -0
  200. package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -0
  201. package/dist/components/forms/fields/FormTextArea/index.d.ts +16 -0
  202. package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -0
  203. package/dist/components/forms/fields/FormTextArea/index.js +25 -0
  204. package/dist/components/forms/fields/FormTextArea/index.js.map +1 -0
  205. package/dist/components/forms/fields/FormToggle/index.cjs +32 -0
  206. package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -0
  207. package/dist/components/forms/fields/FormToggle/index.d.ts +16 -0
  208. package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -0
  209. package/dist/components/forms/fields/FormToggle/index.js +30 -0
  210. package/dist/components/forms/fields/FormToggle/index.js.map +1 -0
  211. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +39 -0
  212. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -0
  213. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +15 -0
  214. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -0
  215. package/dist/components/forms/validation/hooks/useSchemaResolver.js +37 -0
  216. package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -0
  217. package/dist/components/forms/validation/index.cjs +309 -0
  218. package/dist/components/forms/validation/index.cjs.map +1 -0
  219. package/dist/components/forms/validation/index.d.ts +214 -0
  220. package/dist/components/forms/validation/index.d.ts.map +1 -0
  221. package/dist/components/forms/validation/index.js +293 -0
  222. package/dist/components/forms/validation/index.js.map +1 -0
  223. package/dist/components/forms/validation/utilities/validation.utils.cjs +42 -0
  224. package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -0
  225. package/dist/components/forms/validation/utilities/validation.utils.d.ts +20 -0
  226. package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -0
  227. package/dist/components/forms/validation/utilities/validation.utils.js +39 -0
  228. package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -0
  229. package/dist/components/forms/validation/validation.types.d.ts +8 -0
  230. package/dist/components/forms/validation/validation.types.d.ts.map +1 -0
  231. package/dist/components/molecules/Alert/index.cjs +5 -25
  232. package/dist/components/molecules/Alert/index.cjs.map +1 -1
  233. package/dist/components/molecules/Alert/index.d.ts +9 -94
  234. package/dist/components/molecules/Alert/index.d.ts.map +1 -1
  235. package/dist/components/molecules/Alert/index.js +5 -25
  236. package/dist/components/molecules/Alert/index.js.map +1 -1
  237. package/dist/components/molecules/Alerts/components/Alert.cjs +39 -0
  238. package/dist/components/molecules/Alerts/components/Alert.cjs.map +1 -0
  239. package/dist/components/molecules/Alerts/components/Alert.d.ts +104 -0
  240. package/dist/components/molecules/Alerts/components/Alert.d.ts.map +1 -0
  241. package/dist/components/molecules/Alerts/components/Alert.js +36 -0
  242. package/dist/components/molecules/Alerts/components/Alert.js.map +1 -0
  243. package/dist/components/molecules/Alerts/components/SaveErrorAlert.cjs +26 -0
  244. package/dist/components/molecules/Alerts/components/SaveErrorAlert.cjs.map +1 -0
  245. package/dist/components/molecules/Alerts/components/SaveErrorAlert.d.ts +25 -0
  246. package/dist/components/molecules/Alerts/components/SaveErrorAlert.d.ts.map +1 -0
  247. package/dist/components/molecules/Alerts/components/SaveErrorAlert.js +24 -0
  248. package/dist/components/molecules/Alerts/components/SaveErrorAlert.js.map +1 -0
  249. package/dist/components/molecules/Alerts/hooks/useAlertActions.cjs +26 -0
  250. package/dist/components/molecules/Alerts/hooks/useAlertActions.cjs.map +1 -0
  251. package/dist/components/molecules/Alerts/hooks/useAlertActions.d.ts +13 -0
  252. package/dist/components/molecules/Alerts/hooks/useAlertActions.d.ts.map +1 -0
  253. package/dist/components/molecules/Alerts/hooks/useAlertActions.js +24 -0
  254. package/dist/components/molecules/Alerts/hooks/useAlertActions.js.map +1 -0
  255. package/dist/components/molecules/Alerts/index.cjs +11 -0
  256. package/dist/components/molecules/Alerts/index.cjs.map +1 -0
  257. package/dist/components/molecules/Alerts/index.d.ts +12 -0
  258. package/dist/components/molecules/Alerts/index.d.ts.map +1 -0
  259. package/dist/components/molecules/Alerts/index.js +3 -0
  260. package/dist/components/molecules/Alerts/index.js.map +1 -0
  261. package/dist/components/molecules/Modal/index.cjs +9 -39
  262. package/dist/components/molecules/Modal/index.cjs.map +1 -1
  263. package/dist/components/molecules/Modal/index.d.ts +13 -36
  264. package/dist/components/molecules/Modal/index.d.ts.map +1 -1
  265. package/dist/components/molecules/Modal/index.js +8 -38
  266. package/dist/components/molecules/Modal/index.js.map +1 -1
  267. package/dist/components/molecules/Modals/components/ConfirmationModal.cjs +32 -0
  268. package/dist/components/molecules/Modals/components/ConfirmationModal.cjs.map +1 -0
  269. package/dist/components/molecules/Modals/components/ConfirmationModal.d.ts +28 -0
  270. package/dist/components/molecules/Modals/components/ConfirmationModal.d.ts.map +1 -0
  271. package/dist/components/molecules/Modals/components/ConfirmationModal.js +30 -0
  272. package/dist/components/molecules/Modals/components/ConfirmationModal.js.map +1 -0
  273. package/dist/components/molecules/Modals/components/Modal.cjs +48 -0
  274. package/dist/components/molecules/Modals/components/Modal.cjs.map +1 -0
  275. package/dist/components/molecules/Modals/components/Modal.d.ts +37 -0
  276. package/dist/components/molecules/Modals/components/Modal.d.ts.map +1 -0
  277. package/dist/components/molecules/Modals/components/Modal.js +43 -0
  278. package/dist/components/molecules/Modals/components/Modal.js.map +1 -0
  279. package/dist/components/molecules/Modals/components/UnsavedChangesModal.cjs +30 -0
  280. package/dist/components/molecules/Modals/components/UnsavedChangesModal.cjs.map +1 -0
  281. package/dist/components/molecules/Modals/components/UnsavedChangesModal.d.ts +14 -0
  282. package/dist/components/molecules/Modals/components/UnsavedChangesModal.d.ts.map +1 -0
  283. package/dist/components/molecules/Modals/components/UnsavedChangesModal.js +28 -0
  284. package/dist/components/molecules/Modals/components/UnsavedChangesModal.js.map +1 -0
  285. package/dist/components/molecules/Modals/index.cjs +15 -0
  286. package/dist/components/molecules/Modals/index.cjs.map +1 -0
  287. package/dist/components/molecules/Modals/index.d.ts +14 -0
  288. package/dist/components/molecules/Modals/index.d.ts.map +1 -0
  289. package/dist/components/molecules/Modals/index.js +4 -0
  290. package/dist/components/molecules/Modals/index.js.map +1 -0
  291. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs +13 -3
  292. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs.map +1 -1
  293. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts +1 -1
  294. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts.map +1 -1
  295. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js +13 -3
  296. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js.map +1 -1
  297. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs +2 -2
  298. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs.map +1 -1
  299. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts +1 -0
  300. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts.map +1 -1
  301. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js +2 -2
  302. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js.map +1 -1
  303. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.cjs +1 -1
  304. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.js +1 -1
  305. package/dist/components/organisms/ColorPicker/index.cjs +1 -1
  306. package/dist/components/organisms/ColorPicker/index.d.ts.map +1 -1
  307. package/dist/components/organisms/ColorPicker/index.js +1 -1
  308. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts +1 -1
  309. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts.map +1 -1
  310. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.cjs.map +1 -0
  311. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.d.ts.map +1 -0
  312. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.js.map +1 -0
  313. package/dist/components/organisms/DatePicker/components/CalendarOverlay.cjs +2 -2
  314. package/dist/components/organisms/DatePicker/components/CalendarOverlay.cjs.map +1 -1
  315. package/dist/components/organisms/DatePicker/components/CalendarOverlay.js +1 -1
  316. package/dist/components/organisms/DatePicker/components/DateRangePicker.cjs +4 -1
  317. package/dist/components/organisms/DatePicker/components/DateRangePicker.cjs.map +1 -1
  318. package/dist/components/organisms/DatePicker/components/DateRangePicker.d.ts.map +1 -1
  319. package/dist/components/organisms/DatePicker/components/DateRangePicker.js +5 -2
  320. package/dist/components/organisms/DatePicker/components/DateRangePicker.js.map +1 -1
  321. package/dist/components/organisms/GradientPicker/components/GradientStopRow.cjs +1 -1
  322. package/dist/components/organisms/GradientPicker/components/GradientStopRow.js +1 -1
  323. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs +48 -0
  324. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs.map +1 -0
  325. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts +23 -0
  326. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts.map +1 -0
  327. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js +45 -0
  328. package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js.map +1 -0
  329. package/dist/hooks/useUnsavedChangesGuard/index.cjs +28 -0
  330. package/dist/hooks/useUnsavedChangesGuard/index.cjs.map +1 -0
  331. package/dist/hooks/useUnsavedChangesGuard/index.d.ts +18 -0
  332. package/dist/hooks/useUnsavedChangesGuard/index.d.ts.map +1 -0
  333. package/dist/hooks/useUnsavedChangesGuard/index.js +26 -0
  334. package/dist/hooks/useUnsavedChangesGuard/index.js.map +1 -0
  335. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.cjs +8 -0
  336. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.cjs.map +1 -0
  337. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.d.ts +13 -0
  338. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.d.ts.map +1 -0
  339. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.js +6 -0
  340. package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.js.map +1 -0
  341. package/dist/localization/en.json.cjs +98 -0
  342. package/dist/localization/en.json.cjs.map +1 -0
  343. package/dist/localization/en.json.js +81 -0
  344. package/dist/localization/en.json.js.map +1 -0
  345. package/dist/native/components/forms/Form/index.d.ts +12 -0
  346. package/dist/native/components/forms/FormFooter/index.d.ts +12 -0
  347. package/dist/native/components/forms/FormSection/index.d.ts +12 -0
  348. package/dist/native/components/forms/fields/FormCheckbox/index.d.ts +12 -0
  349. package/dist/native/components/forms/fields/FormCheckboxGroup/index.d.ts +12 -0
  350. package/dist/native/components/forms/fields/FormColorPicker/index.d.ts +12 -0
  351. package/dist/native/components/forms/fields/FormDatePicker/index.d.ts +12 -0
  352. package/dist/native/components/forms/fields/FormInput/index.d.ts +12 -0
  353. package/dist/native/components/forms/fields/FormMultiSelect/index.d.ts +12 -0
  354. package/dist/native/components/forms/fields/FormRadioCardGroup/index.d.ts +12 -0
  355. package/dist/native/components/forms/fields/FormRadioGroup/index.d.ts +12 -0
  356. package/dist/native/components/forms/fields/FormSelect/index.d.ts +12 -0
  357. package/dist/native/components/forms/fields/FormSlider/index.d.ts +12 -0
  358. package/dist/native/components/forms/fields/FormTextArea/index.d.ts +12 -0
  359. package/dist/native/components/forms/fields/FormToggle/index.d.ts +12 -0
  360. package/dist/native/components/forms/validation/index.d.ts +12 -0
  361. package/dist/native/components/molecules/Alerts/index.d.ts +12 -0
  362. package/dist/native/components/molecules/Modals/index.d.ts +12 -0
  363. package/dist/native/hooks/useUnsavedChangesGuard/index.d.ts +12 -0
  364. package/dist/native/providers/UnsavedChangesGuardProvider/index.d.ts +12 -0
  365. package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs +70 -0
  366. package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs.map +1 -0
  367. package/dist/providers/UIProvider/hooks/useBrowserRouter.d.ts +12 -0
  368. package/dist/providers/UIProvider/hooks/useBrowserRouter.d.ts.map +1 -0
  369. package/dist/providers/UIProvider/hooks/useBrowserRouter.js +68 -0
  370. package/dist/providers/UIProvider/hooks/useBrowserRouter.js.map +1 -0
  371. package/dist/providers/UIProvider/index.cjs +19 -6
  372. package/dist/providers/UIProvider/index.cjs.map +1 -1
  373. package/dist/providers/UIProvider/index.d.ts +2 -2
  374. package/dist/providers/UIProvider/index.d.ts.map +1 -1
  375. package/dist/providers/UIProvider/index.js +20 -7
  376. package/dist/providers/UIProvider/index.js.map +1 -1
  377. package/dist/providers/UnsavedChangesGuardProvider/index.cjs +191 -0
  378. package/dist/providers/UnsavedChangesGuardProvider/index.cjs.map +1 -0
  379. package/dist/providers/UnsavedChangesGuardProvider/index.d.ts +10 -0
  380. package/dist/providers/UnsavedChangesGuardProvider/index.d.ts.map +1 -0
  381. package/dist/providers/UnsavedChangesGuardProvider/index.js +189 -0
  382. package/dist/providers/UnsavedChangesGuardProvider/index.js.map +1 -0
  383. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.cjs +7 -0
  384. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.cjs.map +1 -0
  385. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.d.ts +3 -0
  386. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.d.ts.map +1 -0
  387. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.js +5 -0
  388. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.js.map +1 -0
  389. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.types.d.ts +21 -0
  390. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.types.d.ts.map +1 -0
  391. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs +97 -0
  392. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs.map +1 -0
  393. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts +62 -0
  394. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts.map +1 -0
  395. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js +88 -0
  396. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js.map +1 -0
  397. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs +74 -0
  398. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs.map +1 -0
  399. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +51 -0
  400. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -0
  401. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js +68 -0
  402. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js.map +1 -0
  403. package/package.json +41 -6
  404. package/dist/components/organisms/ColorPicker/colorPicker.utils.cjs.map +0 -1
  405. package/dist/components/organisms/ColorPicker/colorPicker.utils.d.ts.map +0 -1
  406. package/dist/components/organisms/ColorPicker/colorPicker.utils.js.map +0 -1
  407. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.cjs → utilities/colorPicker.utils.cjs} +0 -0
  408. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.d.ts → utilities/colorPicker.utils.d.ts} +0 -0
  409. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.js → utilities/colorPicker.utils.js} +0 -0
@@ -0,0 +1,17 @@
1
+ import { RadioGroup } from '@flipdish/ui-library/components/atoms/RadioButton';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ export interface FormRadioGroupProps<TValues extends FieldValues = FieldValues> extends Omit<ComponentProps<typeof RadioGroup>, 'name' | 'value' | 'defaultValue' | 'onChange' | 'onBlur' | 'isInvalid' | 'ref'> {
5
+ /** The field's path in the form values, such as `plan` or `delivery.method`. */
6
+ name: FieldPath<TValues>;
7
+ /** Other fields whose rule reads this one, such as a postcode that depends on this country; they re-validate when this changes. */
8
+ revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
9
+ }
10
+ /**
11
+ * A `RadioGroup` bound to a react-hook-form field: choosing an option writes its value to the form and validates it
12
+ * at once, and the field's error shows beneath the group. Use it when the user picks one of a few visible options.
13
+ *
14
+ * @summary radio group bound to a react-hook-form field
15
+ */
16
+ export declare const FormRadioGroup: <TValues extends FieldValues = FieldValues>({ name, revalidates, children, ...radioGroupProps }: FormRadioGroupProps<TValues>) => import("react").JSX.Element;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormRadioGroup/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,mDAAmD,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAC5E,SAAQ,IAAI,CAAC,cAAc,CAAC,OAAO,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,CAAC;IAChI,gFAAgF;IAChF,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB,mIAAmI;IACnI,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,qDAKvE,mBAAmB,CAAC,OAAO,CAAC,gCA+B9B,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { HintText } from '@flipdish/ui-library/components/atoms/Input';
3
+ import { RadioGroup } from '@flipdish/ui-library/components/atoms/RadioButton';
4
+ import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
5
+ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
6
+
7
+ /**
8
+ * A `RadioGroup` bound to a react-hook-form field: choosing an option writes its value to the form and validates it
9
+ * at once, and the field's error shows beneath the group. Use it when the user picks one of a few visible options.
10
+ *
11
+ * @summary radio group bound to a react-hook-form field
12
+ */
13
+ const FormRadioGroup = ({ name, revalidates, children, ...radioGroupProps }) => {
14
+ const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
15
+ // `RadioGroup` takes no ref, so a layout-neutral wrapper hands the form the chosen radio, or the first when none is.
16
+ const focusRef = useFocusTarget(ref, 'input:checked:not(:disabled)', 'input:not(:disabled)');
17
+ return (jsx("div", { ref: focusRef, className: "contents", children: jsxs(RadioGroup
18
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
19
+ , {
20
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
21
+ validationBehavior: "aria", ...radioGroupProps, name: name,
22
+ // An unset field is `undefined`, which would flip the group between uncontrolled and controlled.
23
+ value: value ?? null, onChange: onCommit, onBlur: onBlur, isInvalid: isInvalid, isDisabled: radioGroupProps.isDisabled || isDisabled,
24
+ // Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
25
+ isReadOnly: radioGroupProps.isReadOnly || isLocked, children: [children, isInvalid && errorMessage && (jsx(HintText, { isInvalid: true, role: "alert", children: errorMessage }))] }) }));
26
+ };
27
+
28
+ export { FormRadioGroup };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormRadioGroup/index.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs"],"mappings":";;;;;;AAiBA;;;;;AAKG;AACI,MAAM,cAAc,GAAG,CAA4C,EACxE,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,GAAG,eAAe,EACW,KAAI;IACjC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;;IAExI,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,8BAA8B,EAAE,sBAAsB,CAAC;IAE5F,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,EAAA,QAAA,EACtCC,IAAA,CAAC;;;;AAEC,YAAA,kBAAkB,EAAC,MAAM,EAAA,GACrB,eAAe,EACnB,IAAI,EAAE,IAAI;;YAEV,KAAK,EAAE,KAAK,IAAI,IAAI,EACpB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,UAAU;;AAEpD,YAAA,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,QAAQ,EAAA,QAAA,EAAA,CAEjD,QAAQ,EAER,SAAS,IAAI,YAAY,KACxBD,GAAA,CAAC,QAAQ,EAAA,EAAC,SAAS,EAAA,IAAA,EAAC,IAAI,EAAC,OAAO,EAAA,QAAA,EAC7B,YAAY,EAAA,CACJ,CACZ,CAAA,EAAA,CACU,EAAA,CACT;AAEV;;"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var Select = require('@flipdish/ui-library/components/molecules/Select');
5
+ var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
6
+ var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
7
+
8
+ /**
9
+ * A `Select` bound to a react-hook-form field: choosing an option writes its `id` to the form and validates it at once,
10
+ * and the field's error shows in place of `hint`. Use it when the user picks one option from a list in a react-hook-form form.
11
+ *
12
+ * @summary single-option select bound to a react-hook-form field
13
+ */
14
+ const FormSelect = ({ name, revalidates, hint, ...selectProps }) => {
15
+ const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
16
+ // `Select`'s ref is its wrapper div; the trigger is its only direct button child (the label's tooltip is nested).
17
+ const focusRef = useFocusTarget.useFocusTarget(ref, ':scope > button');
18
+ return (jsxRuntime.jsx(Select.Select
19
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
20
+ , {
21
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
22
+ validationBehavior: "aria", ...selectProps, ref: focusRef, name: name,
23
+ // An unset field is `undefined`, which would flip the select between uncontrolled and controlled.
24
+ value: value ?? null, onChange: onCommit, onBlur: onBlur, isInvalid: isInvalid, hint: errorMessage ?? hint,
25
+ // Disabled while the form submits, having no read-only mode: a change made meanwhile would be lost to the save.
26
+ isDisabled: selectProps.isDisabled || isDisabled || isLocked }));
27
+ };
28
+
29
+ exports.FormSelect = FormSelect;
30
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormSelect/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","_jsx","Select"],"mappings":";;;;;;;AAmBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAsB,IAAI,EAAE,WAAW,CAAC;;IAG5I,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,iBAAiB,CAAC;IAEvD,QACEC,eAACC;;;;QAEC,kBAAkB,EAAC,MAAM,EAAA,GACrB,WAAW,EACf,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI;;QAEV,KAAK,EAAE,KAAK,IAAI,IAAI,EACpB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI;;QAE1B,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQ,EAAA,CAC5D;AAEN;;"}
@@ -0,0 +1,16 @@
1
+ import { type SelectProps } from '@flipdish/ui-library/components/molecules/Select';
2
+ import type { FieldPath, FieldValues } from 'react-hook-form';
3
+ export interface FormSelectProps<TValues extends FieldValues = FieldValues> extends Omit<SelectProps, 'name' | 'value' | 'defaultValue' | 'onChange' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange' | 'onBlur' | 'isInvalid' | 'ref'> {
4
+ /** The field's path in the form values, such as `country` or `address.country`. */
5
+ name: FieldPath<TValues>;
6
+ /** Other fields whose rule reads this one, such as a postcode that depends on this country; they re-validate when this changes. */
7
+ revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
8
+ }
9
+ /**
10
+ * A `Select` bound to a react-hook-form field: choosing an option writes its `id` to the form and validates it at once,
11
+ * and the field's error shows in place of `hint`. Use it when the user picks one option from a list in a react-hook-form form.
12
+ *
13
+ * @summary single-option select bound to a react-hook-form field
14
+ */
15
+ export declare const FormSelect: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...selectProps }: FormSelectProps<TValues>) => import("react").JSX.Element;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormSelect/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,kDAAkD,CAAC;AAE5F,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CACxE,SAAQ,IAAI,CACV,WAAW,EACX,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,aAAa,GAAG,oBAAoB,GAAG,mBAAmB,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,CAC7I;IACD,mFAAmF;IACnF,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB,mIAAmI;IACnI,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,6CAA6C,eAAe,CAAC,OAAO,CAAC,gCAuB1I,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Select } from '@flipdish/ui-library/components/molecules/Select';
3
+ import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
4
+ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
5
+
6
+ /**
7
+ * A `Select` bound to a react-hook-form field: choosing an option writes its `id` to the form and validates it at once,
8
+ * and the field's error shows in place of `hint`. Use it when the user picks one option from a list in a react-hook-form form.
9
+ *
10
+ * @summary single-option select bound to a react-hook-form field
11
+ */
12
+ const FormSelect = ({ name, revalidates, hint, ...selectProps }) => {
13
+ const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
14
+ // `Select`'s ref is its wrapper div; the trigger is its only direct button child (the label's tooltip is nested).
15
+ const focusRef = useFocusTarget(ref, ':scope > button');
16
+ return (jsx(Select
17
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
18
+ , {
19
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
20
+ validationBehavior: "aria", ...selectProps, ref: focusRef, name: name,
21
+ // An unset field is `undefined`, which would flip the select between uncontrolled and controlled.
22
+ value: value ?? null, onChange: onCommit, onBlur: onBlur, isInvalid: isInvalid, hint: errorMessage ?? hint,
23
+ // Disabled while the form submits, having no read-only mode: a change made meanwhile would be lost to the save.
24
+ isDisabled: selectProps.isDisabled || isDisabled || isLocked }));
25
+ };
26
+
27
+ export { FormSelect };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormSelect/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;AAmBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAsB,IAAI,EAAE,WAAW,CAAC;;IAG5I,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,iBAAiB,CAAC;IAEvD,QACEA,IAAC;;;;QAEC,kBAAkB,EAAC,MAAM,EAAA,GACrB,WAAW,EACf,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI;;QAEV,KAAK,EAAE,KAAK,IAAI,IAAI,EACpB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI;;QAE1B,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQ,EAAA,CAC5D;AAEN;;"}
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var Input = require('@flipdish/ui-library/components/atoms/Input');
5
+ var Slider = require('@flipdish/ui-library/components/atoms/Slider');
6
+ var React = require('react');
7
+ var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
8
+ var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
9
+ var ariaIds_utils = require('../../../../utilities/__internal__/ariaIdsUtils/ariaIds.utils.cjs');
10
+
11
+ /**
12
+ * A single-thumb `Slider` bound to a react-hook-form field: moving the thumb updates the field's number, and releasing
13
+ * it validates, with the field's error shown beneath the slider in place of `hint`. Use it for a bounded number the user
14
+ * adjusts by feel.
15
+ *
16
+ * @summary single-thumb slider bound to a react-hook-form field
17
+ */
18
+ const FormSlider = ({ name, revalidates, minValue = 0, hint, ...sliderProps }) => {
19
+ const { value, ref, onDraft, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
20
+ // `Slider` takes no ref, so the wrapper hands the form the thumb's input.
21
+ const focusRef = useFocusTarget.useFocusTarget(ref, 'input');
22
+ const errorId = React.useId();
23
+ const describedBy = ariaIds_utils.joinIds(sliderProps['aria-describedby'], errorMessage && errorId);
24
+ // A single thumb reports a number; the range type of `Slider` also allows an array.
25
+ const toNumber = (next) => (Array.isArray(next) ? next[0] : next);
26
+ // `Slider` has no `onBlur`, so the wrapper hears the thumb's: leaving the slider untouched still marks the field visited and validates it.
27
+ const blur = (event) => {
28
+ if (!event.currentTarget.contains(event.relatedTarget))
29
+ onBlur();
30
+ };
31
+ return (
32
+ // biome-ignore lint/a11y/noStaticElementInteractions: it only hears the thumb's blur as it bubbles, and takes no interaction itself
33
+ jsxRuntime.jsxs("div", { ref: focusRef, onBlur: blur, className: "flex w-full flex-col gap-1.5", children: [jsxRuntime.jsx(Slider.Slider, { ...sliderProps, minValue: minValue,
34
+ // The error takes the hint's place, as it does on the other fields.
35
+ hint: errorMessage ? undefined : hint,
36
+ // An unset field is `undefined`, which would flip the slider between uncontrolled and controlled.
37
+ value: value ?? minValue, onChange: (next) => onDraft(toNumber(next)), onChangeEnd: (next) => onCommit(toNumber(next)), "aria-describedby": describedBy, isInvalid: isInvalid,
38
+ // Disabled while the form submits, having no read-only mode: a change made meanwhile would be lost to the save.
39
+ isDisabled: sliderProps.isDisabled || isDisabled || isLocked }), errorMessage && (jsxRuntime.jsx(Input.HintText, { isInvalid: true, id: errorId, children: errorMessage }))] }));
40
+ };
41
+
42
+ exports.FormSlider = FormSlider;
43
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormSlider/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","useId","joinIds","_jsxs","_jsx","Slider","HintText"],"mappings":";;;;;;;;;;AAkBA;;;;;;AAMG;MACU,UAAU,GAAG,CAA4C,EACpE,IAAI,EACJ,WAAW,EACX,QAAQ,GAAG,CAAC,EACZ,IAAI,EACJ,GAAG,WAAW,EACW,KAAI;IAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;;IAEjJ,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAC7C,IAAA,MAAM,OAAO,GAAGC,WAAK,EAAE;AACvB,IAAA,MAAM,WAAW,GAAGC,qBAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,YAAY,IAAI,OAAO,CAAC;;IAErF,MAAM,QAAQ,GAAG,CAAC,IAAuB,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;;AAEpF,IAAA,MAAM,IAAI,GAAG,CAAC,KAAiC,KAAI;QACjD,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC;AAAE,YAAA,MAAM,EAAE;AAClE,IAAA,CAAC;IAED;;AAEE,IAAAC,eAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAC,8BAA8B,EAAA,QAAA,EAAA,CACxEC,eAACC,aAAM,EAAA,EAAA,GACD,WAAW,EACf,QAAQ,EAAE,QAAQ;;gBAElB,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;;AAErC,gBAAA,KAAK,EAAE,KAAK,IAAI,QAAQ,EACxB,QAAQ,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAC3C,WAAW,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAA,kBAAA,EAC7B,WAAW,EAC7B,SAAS,EAAE,SAAS;;gBAEpB,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQ,EAAA,CAC5D,EACD,YAAY,KACXD,cAAA,CAACE,cAAQ,EAAA,EAAC,SAAS,EAAA,IAAA,EAAC,EAAE,EAAE,OAAO,EAAA,QAAA,EAC5B,YAAY,EAAA,CACJ,CACZ,CAAA,EAAA,CACG;AAEV;;"}
@@ -0,0 +1,17 @@
1
+ import { type SliderProps } from '@flipdish/ui-library/components/atoms/Slider';
2
+ import type { FieldPath, FieldValues } from 'react-hook-form';
3
+ export interface FormSliderProps<TValues extends FieldValues = FieldValues> extends Omit<SliderProps, 'name' | 'value' | 'defaultValue' | 'onChange' | 'onChangeEnd' | 'isInvalid'> {
4
+ /** The field's path in the form values, such as `discount` or `tip.percent`. */
5
+ name: FieldPath<TValues>;
6
+ /** Other fields whose rule reads this one, such as a postcode that depends on this country; they re-validate when this changes. */
7
+ revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
8
+ }
9
+ /**
10
+ * A single-thumb `Slider` bound to a react-hook-form field: moving the thumb updates the field's number, and releasing
11
+ * it validates, with the field's error shown beneath the slider in place of `hint`. Use it for a bounded number the user
12
+ * adjusts by feel.
13
+ *
14
+ * @summary single-thumb slider bound to a react-hook-form field
15
+ */
16
+ export declare const FormSlider: <TValues extends FieldValues = FieldValues>({ name, revalidates, minValue, hint, ...sliderProps }: FormSliderProps<TValues>) => import("react").JSX.Element;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormSlider/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAExF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK9D,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CACxE,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,aAAa,GAAG,WAAW,CAAC;IACvG,gFAAgF;IAChF,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB,mIAAmI;IACnI,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,uDAMnE,eAAe,CAAC,OAAO,CAAC,gCAqC1B,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { HintText } from '@flipdish/ui-library/components/atoms/Input';
3
+ import { Slider } from '@flipdish/ui-library/components/atoms/Slider';
4
+ import { useId } from 'react';
5
+ import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
6
+ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
7
+ import { joinIds } from '../../../../utilities/__internal__/ariaIdsUtils/ariaIds.utils.js';
8
+
9
+ /**
10
+ * A single-thumb `Slider` bound to a react-hook-form field: moving the thumb updates the field's number, and releasing
11
+ * it validates, with the field's error shown beneath the slider in place of `hint`. Use it for a bounded number the user
12
+ * adjusts by feel.
13
+ *
14
+ * @summary single-thumb slider bound to a react-hook-form field
15
+ */
16
+ const FormSlider = ({ name, revalidates, minValue = 0, hint, ...sliderProps }) => {
17
+ const { value, ref, onDraft, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
18
+ // `Slider` takes no ref, so the wrapper hands the form the thumb's input.
19
+ const focusRef = useFocusTarget(ref, 'input');
20
+ const errorId = useId();
21
+ const describedBy = joinIds(sliderProps['aria-describedby'], errorMessage && errorId);
22
+ // A single thumb reports a number; the range type of `Slider` also allows an array.
23
+ const toNumber = (next) => (Array.isArray(next) ? next[0] : next);
24
+ // `Slider` has no `onBlur`, so the wrapper hears the thumb's: leaving the slider untouched still marks the field visited and validates it.
25
+ const blur = (event) => {
26
+ if (!event.currentTarget.contains(event.relatedTarget))
27
+ onBlur();
28
+ };
29
+ return (
30
+ // biome-ignore lint/a11y/noStaticElementInteractions: it only hears the thumb's blur as it bubbles, and takes no interaction itself
31
+ jsxs("div", { ref: focusRef, onBlur: blur, className: "flex w-full flex-col gap-1.5", children: [jsx(Slider, { ...sliderProps, minValue: minValue,
32
+ // The error takes the hint's place, as it does on the other fields.
33
+ hint: errorMessage ? undefined : hint,
34
+ // An unset field is `undefined`, which would flip the slider between uncontrolled and controlled.
35
+ value: value ?? minValue, onChange: (next) => onDraft(toNumber(next)), onChangeEnd: (next) => onCommit(toNumber(next)), "aria-describedby": describedBy, isInvalid: isInvalid,
36
+ // Disabled while the form submits, having no read-only mode: a change made meanwhile would be lost to the save.
37
+ isDisabled: sliderProps.isDisabled || isDisabled || isLocked }), errorMessage && (jsx(HintText, { isInvalid: true, id: errorId, children: errorMessage }))] }));
38
+ };
39
+
40
+ export { FormSlider };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormSlider/index.tsx"],"sourcesContent":[null],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;AAkBA;;;;;;AAMG;MACU,UAAU,GAAG,CAA4C,EACpE,IAAI,EACJ,WAAW,EACX,QAAQ,GAAG,CAAC,EACZ,IAAI,EACJ,GAAG,WAAW,EACW,KAAI;IAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;;IAEjJ,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAC7C,IAAA,MAAM,OAAO,GAAG,KAAK,EAAE;AACvB,IAAA,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,YAAY,IAAI,OAAO,CAAC;;IAErF,MAAM,QAAQ,GAAG,CAAC,IAAuB,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;;AAEpF,IAAA,MAAM,IAAI,GAAG,CAAC,KAAiC,KAAI;QACjD,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC;AAAE,YAAA,MAAM,EAAE;AAClE,IAAA,CAAC;IAED;;AAEE,IAAAA,IAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAC,8BAA8B,EAAA,QAAA,EAAA,CACxEC,IAAC,MAAM,EAAA,EAAA,GACD,WAAW,EACf,QAAQ,EAAE,QAAQ;;gBAElB,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;;AAErC,gBAAA,KAAK,EAAE,KAAK,IAAI,QAAQ,EACxB,QAAQ,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAC3C,WAAW,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAA,kBAAA,EAC7B,WAAW,EAC7B,SAAS,EAAE,SAAS;;gBAEpB,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQ,EAAA,CAC5D,EACD,YAAY,KACXA,GAAA,CAAC,QAAQ,EAAA,EAAC,SAAS,EAAA,IAAA,EAAC,EAAE,EAAE,OAAO,EAAA,QAAA,EAC5B,YAAY,EAAA,CACJ,CACZ,CAAA,EAAA,CACG;AAEV;;"}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var TextArea = require('@flipdish/ui-library/components/molecules/TextArea');
5
+ var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
6
+
7
+ /**
8
+ * A `TextArea` bound to a react-hook-form field: it reads and writes the field's value, marks itself invalid and shows
9
+ * the field's error in place of `hint`. Use it for every multi-line text field in a form built with react-hook-form.
10
+ *
11
+ * @summary multi-line text field bound to a react-hook-form field
12
+ */
13
+ const FormTextArea = ({ name, revalidates, hint, ...textAreaProps }) => {
14
+ const { value, ref, onChange, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
15
+ return (jsxRuntime.jsx(TextArea.TextArea
16
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
17
+ , {
18
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
19
+ validationBehavior: "aria", ...textAreaProps, name: name, textAreaRef: ref, onChange: onChange, onBlur: onBlur,
20
+ // An unset field is `undefined`, which would flip the textarea between uncontrolled and controlled.
21
+ value: value ?? '', isInvalid: isInvalid, hint: errorMessage ?? hint, isDisabled: textAreaProps.isDisabled || isDisabled,
22
+ // Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
23
+ isReadOnly: textAreaProps.isReadOnly || isLocked }));
24
+ };
25
+
26
+ exports.FormTextArea = FormTextArea;
27
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormTextArea/index.tsx"],"sourcesContent":[null],"names":["useFormField","_jsx","TextArea"],"mappings":";;;;;;AAcA;;;;;AAKG;AACI,MAAM,YAAY,GAAG,CAA4C,EACtE,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,GAAG,aAAa,EACW,KAAI;IAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;IAExI,QACEC,eAACC;;;;AAEC,QAAA,kBAAkB,EAAC,MAAM,EAAA,GACrB,aAAa,EACjB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,GAAG,EAChB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM;;QAEd,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI,EAC1B,UAAU,EAAE,aAAa,CAAC,UAAU,IAAI,UAAU;;QAElD,UAAU,EAAE,aAAa,CAAC,UAAU,IAAI,QAAQ,EAAA,CAChD;AAEN;;"}
@@ -0,0 +1,16 @@
1
+ import { type TextFieldProps } from '@flipdish/ui-library/components/molecules/TextArea';
2
+ import type { FieldPath, FieldValues } from 'react-hook-form';
3
+ export interface FormTextAreaProps<TValues extends FieldValues = FieldValues> extends Omit<TextFieldProps, 'name' | 'value' | 'defaultValue' | 'onChange' | 'onBlur' | 'isInvalid' | 'ref' | 'textAreaRef'> {
4
+ /** The field's path in the form values, such as `notes` or `address.line2`. */
5
+ name: FieldPath<TValues>;
6
+ /** Other fields whose rule reads this one, such as a postcode that depends on this country; they re-validate when this changes. */
7
+ revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
8
+ }
9
+ /**
10
+ * A `TextArea` bound to a react-hook-form field: it reads and writes the field's value, marks itself invalid and shows
11
+ * the field's error in place of `hint`. Use it for every multi-line text field in a form built with react-hook-form.
12
+ *
13
+ * @summary multi-line text field bound to a react-hook-form field
14
+ */
15
+ export declare const FormTextArea: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...textAreaProps }: FormTextAreaProps<TValues>) => import("react").JSX.Element;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormTextArea/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAC1E,SAAQ,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,GAAG,aAAa,CAAC;IAC7H,+EAA+E;IAC/E,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB,mIAAmI;IACnI,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,+CAKrE,iBAAiB,CAAC,OAAO,CAAC,gCAqB5B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { TextArea } from '@flipdish/ui-library/components/molecules/TextArea';
3
+ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
4
+
5
+ /**
6
+ * A `TextArea` bound to a react-hook-form field: it reads and writes the field's value, marks itself invalid and shows
7
+ * the field's error in place of `hint`. Use it for every multi-line text field in a form built with react-hook-form.
8
+ *
9
+ * @summary multi-line text field bound to a react-hook-form field
10
+ */
11
+ const FormTextArea = ({ name, revalidates, hint, ...textAreaProps }) => {
12
+ const { value, ref, onChange, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
13
+ return (jsx(TextArea
14
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
15
+ , {
16
+ // The form's schema validates; the browser's own `required` check would block the submit before it runs.
17
+ validationBehavior: "aria", ...textAreaProps, name: name, textAreaRef: ref, onChange: onChange, onBlur: onBlur,
18
+ // An unset field is `undefined`, which would flip the textarea between uncontrolled and controlled.
19
+ value: value ?? '', isInvalid: isInvalid, hint: errorMessage ?? hint, isDisabled: textAreaProps.isDisabled || isDisabled,
20
+ // Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
21
+ isReadOnly: textAreaProps.isReadOnly || isLocked }));
22
+ };
23
+
24
+ export { FormTextArea };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormTextArea/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;AAcA;;;;;AAKG;AACI,MAAM,YAAY,GAAG,CAA4C,EACtE,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,GAAG,aAAa,EACW,KAAI;IAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;IAExI,QACEA,IAAC;;;;AAEC,QAAA,kBAAkB,EAAC,MAAM,EAAA,GACrB,aAAa,EACjB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,GAAG,EAChB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM;;QAEd,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI,EAC1B,UAAU,EAAE,aAAa,CAAC,UAAU,IAAI,UAAU;;QAElD,UAAU,EAAE,aAAa,CAAC,UAAU,IAAI,QAAQ,EAAA,CAChD;AAEN;;"}
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var Toggle = require('@flipdish/ui-library/components/atoms/Toggle');
5
+ var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
6
+ var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
7
+
8
+ /**
9
+ * A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
10
+ * the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
11
+ *
12
+ * @summary toggle bound to a react-hook-form field
13
+ */
14
+ const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
15
+ const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
16
+ // react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
17
+ const invalidProps = { isInvalid };
18
+ // `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
19
+ const focusRef = useFocusTarget.useFocusTarget(ref, 'input');
20
+ return (jsxRuntime.jsx("div", { ref: focusRef, className: "contents", children: jsxRuntime.jsx(Toggle.Toggle, { ...toggleProps, ...invalidProps, name: name,
21
+ // An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
22
+ isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
23
+ // Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
24
+ isReadOnly: toggleProps.isReadOnly || isLocked,
25
+ // The control gives its hint no error colour, so the message brings its own.
26
+ hint: errorMessage ? (
27
+ // An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
28
+ jsxRuntime.jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
29
+ };
30
+
31
+ exports.FormToggle = FormToggle;
32
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","_jsx","Toggle"],"mappings":";;;;;;;AAeA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEC,cAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,cAAA,CAACC,aAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVD,cAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
@@ -0,0 +1,16 @@
1
+ import { type ToggleProps } from '@flipdish/ui-library/components/atoms/Toggle';
2
+ import type { FieldPath, FieldValues } from 'react-hook-form';
3
+ export interface FormToggleProps<TValues extends FieldValues = FieldValues> extends Omit<ToggleProps, 'name' | 'isSelected' | 'defaultSelected' | 'onChange' | 'onBlur' | 'ref'> {
4
+ /** The field's path in the form values, such as `isPublished` or `notifications.email`. */
5
+ name: FieldPath<TValues>;
6
+ /** Other fields whose rule reads this one, such as a postcode that depends on this country; they re-validate when this changes. */
7
+ revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
8
+ }
9
+ /**
10
+ * A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
11
+ * the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
12
+ *
13
+ * @summary toggle bound to a react-hook-form field
14
+ */
15
+ export declare const FormToggle: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...toggleProps }: FormToggleProps<TValues>) => import("react").JSX.Element;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CACxE,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;IACpG,2FAA2F;IAC3F,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB,mIAAmI;IACnI,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,6CAA6C,eAAe,CAAC,OAAO,CAAC,gCAkC1I,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Toggle } from '@flipdish/ui-library/components/atoms/Toggle';
3
+ import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
4
+ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
5
+
6
+ /**
7
+ * A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
8
+ * the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
9
+ *
10
+ * @summary toggle bound to a react-hook-form field
11
+ */
12
+ const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
13
+ const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
14
+ // react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
15
+ const invalidProps = { isInvalid };
16
+ // `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
17
+ const focusRef = useFocusTarget(ref, 'input');
18
+ return (jsx("div", { ref: focusRef, className: "contents", children: jsx(Toggle, { ...toggleProps, ...invalidProps, name: name,
19
+ // An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
20
+ isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
21
+ // Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
22
+ isReadOnly: toggleProps.isReadOnly || isLocked,
23
+ // The control gives its hint no error colour, so the message brings its own.
24
+ hint: errorMessage ? (
25
+ // An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
26
+ jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
27
+ };
28
+
29
+ export { FormToggle };
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;AAeA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,GAAA,CAAC,MAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVA,GAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var resolvers = require('@hookform/resolvers');
4
+ var React = require('react');
5
+ var validation_utils = require('../utilities/validation.utils.cjs');
6
+
7
+ /**
8
+ * Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
9
+ * `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
10
+ * as `useForm`'s `resolver` in place of `zodResolver`.
11
+ *
12
+ * @param schema The form's zod schema.
13
+ * @param translate The app's translation function, called with a message and the values for its placeholders. Without
14
+ * one a message is shown as written, with its `{name}` placeholders filled.
15
+ * @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks.
16
+ */
17
+ const useSchemaResolver = (schema, translate) => React.useMemo(() => {
18
+ // An app's `translate` often takes only its own keys; a message it does not know comes back as written.
19
+ const toText = validation_utils.messageText(translate);
20
+ return async (values, _context, options) => {
21
+ const result = await schema.safeParseAsync(values);
22
+ if (result.success) {
23
+ // Clears the message a failed parse left on each input, or the browser goes on calling a corrected field invalid.
24
+ if (options.shouldUseNativeValidation)
25
+ resolvers.validateFieldsNatively({}, options);
26
+ return { values: result.data, errors: {} };
27
+ }
28
+ // No prototype: a field named `toString` would otherwise look as if it already had an error, and lose its own.
29
+ const errors = Object.create(null);
30
+ for (const issue of result.error.issues) {
31
+ const path = issue.path.join('.');
32
+ errors[path] ?? (errors[path] = { type: issue.code, message: toText(issue.message, validation_utils.valuesOf(issue)) });
33
+ }
34
+ return { values: {}, errors: resolvers.toNestErrors(errors, options) };
35
+ };
36
+ }, [schema, translate]);
37
+
38
+ exports.useSchemaResolver = useSchemaResolver;
39
+ //# sourceMappingURL=useSchemaResolver.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSchemaResolver.cjs","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"sourcesContent":[null],"names":["useMemo","messageText","validateFieldsNatively","valuesOf","toNestErrors"],"mappings":";;;;;;AAOA;;;;;;;;;AASG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAe,EACf,SAAyD,KAEzDA,aAAO,CAAC,MAAK;;AAEX,IAAA,MAAM,MAAM,GAAGC,4BAAW,CAAC,SAAkC,CAAC;IAE9D,OAAO,OAAO,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAI;QACzC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,MAAM,CAAC,OAAO,EAAE;;YAElB,IAAI,OAAO,CAAC,yBAAyB;AAAE,gBAAAC,gCAAsB,CAAC,EAAE,EAAE,OAAO,CAAC;YAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C;;QAGA,MAAM,MAAM,GAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjC,YAAA,MAAM,CAAC,IAAI,CAAA,KAAX,MAAM,CAAC,IAAI,CAAA,GAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAEC,yBAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;QACxF;AACA,QAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAEC,sBAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;AAC9D,IAAA,CAAC;AACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;;"}
@@ -0,0 +1,15 @@
1
+ import type { FieldValues, Resolver } from 'react-hook-form';
2
+ import type { z } from 'zod';
3
+ import type { MessageValues } from '../validation.types';
4
+ /**
5
+ * Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
6
+ * `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
7
+ * as `useForm`'s `resolver` in place of `zodResolver`.
8
+ *
9
+ * @param schema The form's zod schema.
10
+ * @param translate The app's translation function, called with a message and the values for its placeholders. Without
11
+ * one a message is shown as written, with its `{name}` placeholders filled.
12
+ * @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks.
13
+ */
14
+ export declare const useSchemaResolver: <TSchema extends z.ZodType<FieldValues, FieldValues>, TKey extends string = string>(schema: TSchema, translate?: (key: TKey, values?: MessageValues) => string) => Resolver<z.input<TSchema>, unknown, z.output<TSchema>>;
15
+ //# sourceMappingURL=useSchemaResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSchemaResolver.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,qBAAqB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,EACjH,QAAQ,OAAO,EACf,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,aAAa,KAAK,MAAM,KACxD,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAqB/B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
2
+ import { useMemo } from 'react';
3
+ import { valuesOf, messageText } from '../utilities/validation.utils.js';
4
+
5
+ /**
6
+ * Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
7
+ * `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
8
+ * as `useForm`'s `resolver` in place of `zodResolver`.
9
+ *
10
+ * @param schema The form's zod schema.
11
+ * @param translate The app's translation function, called with a message and the values for its placeholders. Without
12
+ * one a message is shown as written, with its `{name}` placeholders filled.
13
+ * @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks.
14
+ */
15
+ const useSchemaResolver = (schema, translate) => useMemo(() => {
16
+ // An app's `translate` often takes only its own keys; a message it does not know comes back as written.
17
+ const toText = messageText(translate);
18
+ return async (values, _context, options) => {
19
+ const result = await schema.safeParseAsync(values);
20
+ if (result.success) {
21
+ // Clears the message a failed parse left on each input, or the browser goes on calling a corrected field invalid.
22
+ if (options.shouldUseNativeValidation)
23
+ validateFieldsNatively({}, options);
24
+ return { values: result.data, errors: {} };
25
+ }
26
+ // No prototype: a field named `toString` would otherwise look as if it already had an error, and lose its own.
27
+ const errors = Object.create(null);
28
+ for (const issue of result.error.issues) {
29
+ const path = issue.path.join('.');
30
+ errors[path] ?? (errors[path] = { type: issue.code, message: toText(issue.message, valuesOf(issue)) });
31
+ }
32
+ return { values: {}, errors: toNestErrors(errors, options) };
33
+ };
34
+ }, [schema, translate]);
35
+
36
+ export { useSchemaResolver };
37
+ //# sourceMappingURL=useSchemaResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSchemaResolver.js","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA;;;;;;;;;AASG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAe,EACf,SAAyD,KAEzD,OAAO,CAAC,MAAK;;AAEX,IAAA,MAAM,MAAM,GAAG,WAAW,CAAC,SAAkC,CAAC;IAE9D,OAAO,OAAO,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAI;QACzC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,MAAM,CAAC,OAAO,EAAE;;YAElB,IAAI,OAAO,CAAC,yBAAyB;AAAE,gBAAA,sBAAsB,CAAC,EAAE,EAAE,OAAO,CAAC;YAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C;;QAGA,MAAM,MAAM,GAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjC,YAAA,MAAM,CAAC,IAAI,CAAA,KAAX,MAAM,CAAC,IAAI,CAAA,GAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;QACxF;AACA,QAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;AAC9D,IAAA,CAAC;AACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;;"}