@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,43 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var Divider = require('@flipdish/ui-library/components/atoms/Divider');
5
+ var Skeleton = require('@flipdish/ui-library/components/atoms/Skeleton');
6
+ var SectionHeader = require('@flipdish/ui-library/components/molecules/SectionHeader');
7
+ var cx = require('@flipdish/ui-library/utilities/cx');
8
+ var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
9
+ var React = require('react');
10
+ var FormSection_styles = require('./FormSection.styles.cjs');
11
+
12
+ /** Upper bound on placeholder sections and fields, guarding against a malformed count. */
13
+ const MAX_SKELETON_COUNT = 12;
14
+ const toCount = (count) => (Number.isFinite(count) ? Math.min(Math.max(Math.trunc(count), 0), MAX_SKELETON_COUNT) : 0);
15
+ /** Puts two short fields on one line, such as a city and its postcode. */
16
+ const FormSectionRow = ({ children, className }) => jsxRuntime.jsx("div", { className: cx.cx(FormSection_styles.styles.row, className), children: children });
17
+ /** The placeholder a form shows while its values load, in the same two columns as its sections, so nothing shifts when they arrive. */
18
+ const FormSectionSkeleton = ({ label, sectionCount = 2, fieldCount = 3, 'data-testid': dataTestId }) => {
19
+ const rootTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'form-section-skeleton', rootName: 'form-section-skeleton' });
20
+ const sections = Array.from({ length: toCount(sectionCount) }, (_, index) => index);
21
+ const fields = Array.from({ length: toCount(fieldCount) }, (_, index) => index);
22
+ // Filled in after it mounts, and kept outside the busy region: a status region that arrives already filled is not
23
+ // reliably announced, and a screen reader may hold back what changes inside a busy one.
24
+ const [announcement, setAnnouncement] = React.useState('');
25
+ React.useEffect(() => setAnnouncement(label), [label]);
26
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("output", { className: "sr-only", children: announcement }), jsxRuntime.jsx("div", { "aria-busy": "true", "data-testid": rootTestId, className: FormSection_styles.styles.stack, children: sections.map((section) => (jsxRuntime.jsxs(React.Fragment, { children: [section > 0 && jsxRuntime.jsx(Divider.Divider, {}), jsxRuntime.jsxs("div", { className: FormSection_styles.styles.root, children: [jsxRuntime.jsxs("div", { className: cx.cx(FormSection_styles.styles.labelColumn, 'gap-2'), children: [jsxRuntime.jsx(Skeleton.Skeleton, { width: "40%", height: 20 }), jsxRuntime.jsx(Skeleton.SkeletonText, { lines: 2 })] }), jsxRuntime.jsx("div", { className: FormSection_styles.styles.fieldColumn, children: fields.map((field) => (jsxRuntime.jsx(Skeleton.Skeleton, { height: 44 }, field))) })] })] }, section))) })] }));
27
+ };
28
+ /**
29
+ * One titled section of a form: its name and description in a column on the left, its fields on the right, stacked
30
+ * below `lg`. Use one per group of related fields, with a `Divider` between sections.
31
+ *
32
+ * @summary titled form section with a label column and a field column
33
+ */
34
+ const FormSection = ({ title, description, children, className, 'data-testid': dataTestId }) => {
35
+ const rootTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'form-section', rootName: 'form-section' });
36
+ const headingId = React.useId();
37
+ return (jsxRuntime.jsxs("section", { "aria-labelledby": headingId, "data-testid": rootTestId, className: cx.cx(FormSection_styles.styles.root, className), children: [jsxRuntime.jsx(testIdUtils.TestIdProvider, { value: rootTestId, children: jsxRuntime.jsxs("div", { className: cx.cx(FormSection_styles.styles.labelColumn, 'gap-1'), children: [jsxRuntime.jsx(SectionHeader.SectionHeader.Heading, { id: headingId, children: title }), description && jsxRuntime.jsx(SectionHeader.SectionHeader.Subheading, { children: description })] }) }), jsxRuntime.jsx("div", { "data-testid": testIdUtils.joinTestId(rootTestId, 'fields'), className: FormSection_styles.styles.fieldColumn, children: children })] }));
38
+ };
39
+ FormSection.Row = FormSectionRow;
40
+ FormSection.Skeleton = FormSectionSkeleton;
41
+
42
+ exports.FormSection = FormSection;
43
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../../src/components/forms/FormSection/index.tsx"],"sourcesContent":[null],"names":["_jsx","cx","styles","useResolvedTestId","useState","useEffect","_jsxs","_Fragment","Fragment","Divider","Skeleton","SkeletonText","useId","TestIdProvider","SectionHeader","joinTestId"],"mappings":";;;;;;;;;;;AAUA;AACA,MAAM,kBAAkB,GAAG,EAAE;AAE7B,MAAM,OAAO,GAAG,CAAC,KAAa,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAsB9H;AACA,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAuB,KAAKA,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAEC,KAAE,CAACC,yBAAM,CAAC,GAAG,EAAE,SAAS,CAAC,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAO;AAapI;AACA,MAAM,mBAAmB,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,EAAE,aAAa,EAAE,UAAU,EAA4B,KAAI;AAC/H,IAAA,MAAM,UAAU,GAA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K,GAAyB,EACpE,WAAW,IAAId,cAAA,CAACc,2BAAa,CAAC,UAAU,EAAA,EAAA,QAAA,EAAE,WAAW,GAA4B,CAAA,EAAA,CAC9E,EAAA,CACS,EACjBd,cAAA,CAAA,KAAA,EAAA,EAAA,aAAA,EAAkBe,sBAAU,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAEb,yBAAM,CAAC,WAAW,EAAA,QAAA,EAC9E,QAAQ,EAAA,CACL,CAAA,EAAA,CACE;AAEd;AAEA,WAAW,CAAC,GAAG,GAAG,cAAc;AAChC,WAAW,CAAC,QAAQ,GAAG,mBAAmB;;"}
@@ -0,0 +1,41 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface FormSectionProps {
3
+ /** The section's name, rendered as its heading in the label column. */
4
+ title: string;
5
+ /** One line on what the section holds, beneath the title. */
6
+ description?: ReactNode;
7
+ /** The section's fields, stacked in the field column. */
8
+ children: ReactNode;
9
+ /** Extra classes merged onto the section element. */
10
+ className?: string;
11
+ /** Overrides the root `data-testid` (defaults to `fd-form-section`); the heading and description derive theirs from it. */
12
+ 'data-testid'?: string;
13
+ }
14
+ export interface FormSectionRowProps {
15
+ /** Two short fields, side by side from `sm` and stacked below it. */
16
+ children: ReactNode;
17
+ /** Extra classes merged onto the row element. */
18
+ className?: string;
19
+ }
20
+ export interface FormSectionSkeletonProps {
21
+ /** What is loading, announced to screen readers, such as "Loading general settings". */
22
+ label: string;
23
+ /** How many placeholder sections to show, with a divider between each. */
24
+ sectionCount?: number;
25
+ /** How many placeholder fields each section shows. */
26
+ fieldCount?: number;
27
+ /** Overrides the root `data-testid` (defaults to `fd-form-section-skeleton`). */
28
+ 'data-testid'?: string;
29
+ }
30
+ /**
31
+ * One titled section of a form: its name and description in a column on the left, its fields on the right, stacked
32
+ * below `lg`. Use one per group of related fields, with a `Divider` between sections.
33
+ *
34
+ * @summary titled form section with a label column and a field column
35
+ */
36
+ export declare const FormSection: {
37
+ ({ title, description, children, className, "data-testid": dataTestId }: FormSectionProps): import("react").JSX.Element;
38
+ Row: ({ children, className }: FormSectionRowProps) => import("react").JSX.Element;
39
+ Skeleton: ({ label, sectionCount, fieldCount, "data-testid": dataTestId }: FormSectionSkeletonProps) => import("react").JSX.Element;
40
+ };
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/FormSection/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAY,KAAK,SAAS,EAA8B,MAAM,OAAO,CAAC;AAQ7E,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,yDAAyD;IACzD,QAAQ,EAAE,SAAS,CAAC;IACpB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2HAA2H;IAC3H,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,QAAQ,EAAE,SAAS,CAAC;IACpB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,MAAM,WAAW,wBAAwB;IACvC,wFAAwF;IACxF,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAqCD;;;;;GAKG;AACH,eAAO,MAAM,WAAW;6EAA4E,gBAAgB;mCAtDnE,mBAAmB;+EAciC,wBAAwB;CA0D5H,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { Divider } from '@flipdish/ui-library/components/atoms/Divider';
3
+ import { Skeleton, SkeletonText } from '@flipdish/ui-library/components/atoms/Skeleton';
4
+ import { SectionHeader } from '@flipdish/ui-library/components/molecules/SectionHeader';
5
+ import { cx } from '@flipdish/ui-library/utilities/cx';
6
+ import { useResolvedTestId, TestIdProvider, joinTestId } from '@flipdish/ui-library/utilities/testIdUtils';
7
+ import { useId, useState, useEffect, Fragment as Fragment$1 } from 'react';
8
+ import { styles } from './FormSection.styles.js';
9
+
10
+ /** Upper bound on placeholder sections and fields, guarding against a malformed count. */
11
+ const MAX_SKELETON_COUNT = 12;
12
+ const toCount = (count) => (Number.isFinite(count) ? Math.min(Math.max(Math.trunc(count), 0), MAX_SKELETON_COUNT) : 0);
13
+ /** Puts two short fields on one line, such as a city and its postcode. */
14
+ const FormSectionRow = ({ children, className }) => jsx("div", { className: cx(styles.row, className), children: children });
15
+ /** The placeholder a form shows while its values load, in the same two columns as its sections, so nothing shifts when they arrive. */
16
+ const FormSectionSkeleton = ({ label, sectionCount = 2, fieldCount = 3, 'data-testid': dataTestId }) => {
17
+ const rootTestId = useResolvedTestId({ testId: dataTestId, segment: 'form-section-skeleton', rootName: 'form-section-skeleton' });
18
+ const sections = Array.from({ length: toCount(sectionCount) }, (_, index) => index);
19
+ const fields = Array.from({ length: toCount(fieldCount) }, (_, index) => index);
20
+ // Filled in after it mounts, and kept outside the busy region: a status region that arrives already filled is not
21
+ // reliably announced, and a screen reader may hold back what changes inside a busy one.
22
+ const [announcement, setAnnouncement] = useState('');
23
+ useEffect(() => setAnnouncement(label), [label]);
24
+ return (jsxs(Fragment, { children: [jsx("output", { className: "sr-only", children: announcement }), jsx("div", { "aria-busy": "true", "data-testid": rootTestId, className: styles.stack, children: sections.map((section) => (jsxs(Fragment$1, { children: [section > 0 && jsx(Divider, {}), jsxs("div", { className: styles.root, children: [jsxs("div", { className: cx(styles.labelColumn, 'gap-2'), children: [jsx(Skeleton, { width: "40%", height: 20 }), jsx(SkeletonText, { lines: 2 })] }), jsx("div", { className: styles.fieldColumn, children: fields.map((field) => (jsx(Skeleton, { height: 44 }, field))) })] })] }, section))) })] }));
25
+ };
26
+ /**
27
+ * One titled section of a form: its name and description in a column on the left, its fields on the right, stacked
28
+ * below `lg`. Use one per group of related fields, with a `Divider` between sections.
29
+ *
30
+ * @summary titled form section with a label column and a field column
31
+ */
32
+ const FormSection = ({ title, description, children, className, 'data-testid': dataTestId }) => {
33
+ const rootTestId = useResolvedTestId({ testId: dataTestId, segment: 'form-section', rootName: 'form-section' });
34
+ const headingId = useId();
35
+ return (jsxs("section", { "aria-labelledby": headingId, "data-testid": rootTestId, className: cx(styles.root, className), children: [jsx(TestIdProvider, { value: rootTestId, children: jsxs("div", { className: cx(styles.labelColumn, 'gap-1'), children: [jsx(SectionHeader.Heading, { id: headingId, children: title }), description && jsx(SectionHeader.Subheading, { children: description })] }) }), jsx("div", { "data-testid": joinTestId(rootTestId, 'fields'), className: styles.fieldColumn, children: children })] }));
36
+ };
37
+ FormSection.Row = FormSectionRow;
38
+ FormSection.Skeleton = FormSectionSkeleton;
39
+
40
+ export { FormSection };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/forms/FormSection/index.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","_Fragment","Fragment"],"mappings":";;;;;;;;;AAUA;AACA,MAAM,kBAAkB,GAAG,EAAE;AAE7B,MAAM,OAAO,GAAG,CAAC,KAAa,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAsB9H;AACA,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAuB,KAAKA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,EAAA,QAAA,EAAG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AAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAAA,QAAA,EAAA,CAC7CD,IAAC,aAAa,CAAC,OAAO,EAAA,EAAC,EAAE,EAAE,SAAS,EAAA,QAAA,EAAG,KAAK,GAAyB,EACpE,WAAW,IAAIA,GAAA,CAAC,aAAa,CAAC,UAAU,EAAA,EAAA,QAAA,EAAE,WAAW,GAA4B,CAAA,EAAA,CAC9E,EAAA,CACS,EACjBA,GAAA,CAAA,KAAA,EAAA,EAAA,aAAA,EAAkB,UAAU,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,WAAW,EAAA,QAAA,EAC9E,QAAQ,EAAA,CACL,CAAA,EAAA,CACE;AAEd;AAEA,WAAW,CAAC,GAAG,GAAG,cAAc;AAChC,WAAW,CAAC,QAAQ,GAAG,mBAAmB;;"}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ /**
6
+ * Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
7
+ * focusable element inside the wrapper, so a failed submit can still land on the field.
8
+ *
9
+ * @param ref The field's ref from `useFormField`.
10
+ * @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
11
+ * @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
12
+ * @returns A ref for the wrapper element.
13
+ */
14
+ const useFocusTarget = (ref, selector, fallbackSelector) => React.useCallback((wrapper) => {
15
+ // Passed on, so the form lets go of a wrapper that has left the page.
16
+ if (!wrapper)
17
+ return ref(null);
18
+ const find = () => wrapper.querySelector(selector) ?? (fallbackSelector ? wrapper.querySelector(fallbackSelector) : null);
19
+ ref({
20
+ focus: () => find()?.focus(),
21
+ contains: (node) => wrapper.contains(node),
22
+ ownerDocument: wrapper.ownerDocument,
23
+ element: wrapper,
24
+ });
25
+ }, [ref, selector, fallbackSelector]);
26
+
27
+ exports.useFocusTarget = useFocusTarget;
28
+ //# sourceMappingURL=useFocusTarget.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTarget.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"sourcesContent":[null],"names":["useCallback"],"mappings":";;;;AAGA;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,GAAgB,EAAE,QAAgB,EAAE,gBAAyB,KAC1FA,iBAAW,CACT,CAAC,OAA2B,KAAI;;AAE9B,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,GAAG,CAAC,IAAI,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,MACX,OAAO,CAAC,aAAa,CAAc,QAAQ,CAAC,KAAK,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAc,gBAAgB,CAAC,GAAG,IAAI,CAAC;AAClI,IAAA,GAAG,CAAC;QACF,KAAK,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE;QAC5B,QAAQ,EAAE,CAAC,IAAiB,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,OAAO,CAAC,aAAa;AACpC,QAAA,OAAO,EAAE,OAAO;AACjB,KAAA,CAAC;AACJ,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC;;"}
@@ -0,0 +1,12 @@
1
+ import type { RefCallBack } from 'react-hook-form';
2
+ /**
3
+ * Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
4
+ * focusable element inside the wrapper, so a failed submit can still land on the field.
5
+ *
6
+ * @param ref The field's ref from `useFormField`.
7
+ * @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
8
+ * @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
9
+ * @returns A ref for the wrapper element.
10
+ */
11
+ export declare const useFocusTarget: (ref: RefCallBack, selector: string, fallbackSelector?: string) => (wrapper: HTMLElement | null) => void;
12
+ //# sourceMappingURL=useFocusTarget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTarget.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,EAAE,UAAU,MAAM,EAAE,mBAAmB,MAAM,eAE9E,WAAW,GAAG,IAAI,SAa7B,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { useCallback } from 'react';
2
+
3
+ /**
4
+ * Lets the form focus a control whose own ref is a wrapper element, or that takes no ref at all: the form is handed the
5
+ * focusable element inside the wrapper, so a failed submit can still land on the field.
6
+ *
7
+ * @param ref The field's ref from `useFormField`.
8
+ * @param selector Finds the focusable element inside the wrapper, such as `input` or `:scope > button`.
9
+ * @param fallbackSelector Tried when `selector` matches nothing, such as any radio when none is checked.
10
+ * @returns A ref for the wrapper element.
11
+ */
12
+ const useFocusTarget = (ref, selector, fallbackSelector) => useCallback((wrapper) => {
13
+ // Passed on, so the form lets go of a wrapper that has left the page.
14
+ if (!wrapper)
15
+ return ref(null);
16
+ const find = () => wrapper.querySelector(selector) ?? (fallbackSelector ? wrapper.querySelector(fallbackSelector) : null);
17
+ ref({
18
+ focus: () => find()?.focus(),
19
+ contains: (node) => wrapper.contains(node),
20
+ ownerDocument: wrapper.ownerDocument,
21
+ element: wrapper,
22
+ });
23
+ }, [ref, selector, fallbackSelector]);
24
+
25
+ export { useFocusTarget };
26
+ //# sourceMappingURL=useFocusTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTarget.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusTarget.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,GAAgB,EAAE,QAAgB,EAAE,gBAAyB,KAC1F,WAAW,CACT,CAAC,OAA2B,KAAI;;AAE9B,IAAA,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,GAAG,CAAC,IAAI,CAAC;AAC9B,IAAA,MAAM,IAAI,GAAG,MACX,OAAO,CAAC,aAAa,CAAc,QAAQ,CAAC,KAAK,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAc,gBAAgB,CAAC,GAAG,IAAI,CAAC;AAClI,IAAA,GAAG,CAAC;QACF,KAAK,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE;QAC5B,QAAQ,EAAE,CAAC,IAAiB,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvD,aAAa,EAAE,OAAO,CAAC,aAAa;AACpC,QAAA,OAAO,EAAE,OAAO;AACjB,KAAA,CAAC;AACJ,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC;;"}
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ /**
6
+ * Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
7
+ * read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
8
+ * such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
9
+ *
10
+ * @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
11
+ * @param isSubmitting Whether the form is submitting.
12
+ * @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
13
+ */
14
+ const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
15
+ const target = React.useRef(null);
16
+ const focus = React.useRef({ heldBy: null, wasLost: false, isOwed: false });
17
+ // The lock follows the submit by one render, so focus can be read first: a browser drops it the moment a control is disabled.
18
+ const [hasReadFocus, setHasReadFocus] = React.useState(false);
19
+ const isLocked = isSubmitting && hasReadFocus;
20
+ const ref = React.useCallback((instance) => {
21
+ target.current = instance;
22
+ if (!instance)
23
+ return fieldRef(null);
24
+ fieldRef({
25
+ focus: () => {
26
+ instance.focus();
27
+ focus.current.isOwed = !instance.contains(instance.ownerDocument.activeElement);
28
+ },
29
+ select: () => instance.select?.(),
30
+ });
31
+ }, [fieldRef]);
32
+ React.useLayoutEffect(() => {
33
+ const state = focus.current;
34
+ const control = target.current;
35
+ if (!control)
36
+ return setHasReadFocus(isSubmitting);
37
+ const { ownerDocument } = control;
38
+ if (isSubmitting && !hasReadFocus) {
39
+ const focused = ownerDocument.activeElement;
40
+ state.heldBy = control.contains(focused) ? focused : null;
41
+ // A request the control refused before this submit is stale: only one made while it is locked is owed.
42
+ state.isOwed = false;
43
+ return setHasReadFocus(true);
44
+ }
45
+ if (isSubmitting) {
46
+ // Only a control the lock disabled loses focus to it; a read-only one keeps it, and must not take it back later.
47
+ state.wasLost = state.heldBy?.matches(':disabled') ?? false;
48
+ // Focus the user puts elsewhere meanwhile is theirs: it is not pulled back, even if another form's submit then drops
49
+ // it, and neither is focus the form had sent here before the user moved on.
50
+ const forget = () => {
51
+ state.wasLost = false;
52
+ state.isOwed = false;
53
+ };
54
+ ownerDocument.addEventListener('focusin', forget);
55
+ return () => ownerDocument.removeEventListener('focusin', forget);
56
+ }
57
+ setHasReadFocus(false);
58
+ // Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
59
+ const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
60
+ if (state.isOwed || isStillLost)
61
+ control.focus();
62
+ focus.current = { heldBy: null, wasLost: false, isOwed: false };
63
+ }, [isSubmitting, hasReadFocus]);
64
+ return { ref, isLocked };
65
+ };
66
+
67
+ exports.useFocusThroughSubmit = useFocusThroughSubmit;
68
+ //# sourceMappingURL=useFocusThroughSubmit.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusThroughSubmit.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":["useRef","useState","useCallback","useLayoutEffect"],"mappings":";;;;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GA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AG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,IAAI;;AAEzD,YAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACpB,YAAA,OAAO,eAAe,CAAC,IAAI,CAAC;QAC9B;QACA,IAAI,YAAY,EAAE;;AAEhB,YAAA,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK;;;YAG3D,MAAM,MAAM,GAAG,MAAK;AAClB,gBAAA,KAAK,CAAC,OAAO,GAAG,KAAK;AACrB,gBAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACtB,YAAA,CAAC;AACD,YAAA,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC;YACjD,OAAO,MAAM,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC;QACnE;QACA,eAAe,CAAC,KAAK,CAAC;;AAEtB,QAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,IAAI,aAAa,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI;AACvF,QAAA,IAAI,KAAK,CAAC,MAAM,IAAI,WAAW;YAAE,OAAO,CAAC,KAAK,EAAE;AAChD,QAAA,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;AACjE,IAAA,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAEhC,IAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;AAC1B;;"}
@@ -0,0 +1,26 @@
1
+ import type { RefCallBack } from 'react-hook-form';
2
+ /** What a wrapper hands the form to focus: the control's own element, or `useFocusTarget`'s stand-in for one inside a wrapper. */
3
+ export interface FocusTarget {
4
+ focus: () => void;
5
+ /** Whether the node is the control or sits inside it, which tells the form where focus was when a submit began. */
6
+ contains: (node: Node | null) => boolean;
7
+ /** The document the control is in, which is where focus is read from. */
8
+ ownerDocument: Document;
9
+ select?: () => void;
10
+ /** The element the control occupies on the page, from a stand-in that is not an element itself. */
11
+ element?: Element;
12
+ }
13
+ /**
14
+ * Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
15
+ * read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
16
+ * such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
17
+ *
18
+ * @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
19
+ * @param isSubmitting Whether the form is submitting.
20
+ * @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
21
+ */
22
+ export declare const useFocusThroughSubmit: (fieldRef: RefCallBack, isSubmitting: boolean) => {
23
+ ref: (instance: FocusTarget | null) => void;
24
+ isLocked: boolean;
25
+ };
26
+ //# sourceMappingURL=useFocusThroughSubmit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusThroughSubmit.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,kIAAkI;AAClI,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,QAAQ,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,mGAAmG;IACnG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,WAAW,EAAE,cAAc,OAAO;oBAQnE,WAAW,GAAG,IAAI;;CA8ChC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { useRef, useState, useCallback, useLayoutEffect } from 'react';
2
+
3
+ /**
4
+ * Locks a field's control while the form submits, and keeps keyboard focus on it through the submit. A control with no
5
+ * read-only mode is disabled for the lock, which drops focus onto the page and refuses any focus the form sends it,
6
+ * such as to the field the server rejected. Once the submit is over, the control takes back the focus it held or was sent.
7
+ *
8
+ * @param fieldRef The field's ref from `useController`, which the form calls to focus the field.
9
+ * @param isSubmitting Whether the form is submitting.
10
+ * @returns The `ref` for the control, to pass on in place of `fieldRef`, and `isLocked`, which is when to make it read-only or disabled.
11
+ */
12
+ const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
13
+ const target = useRef(null);
14
+ const focus = useRef({ heldBy: null, wasLost: false, isOwed: false });
15
+ // The lock follows the submit by one render, so focus can be read first: a browser drops it the moment a control is disabled.
16
+ const [hasReadFocus, setHasReadFocus] = useState(false);
17
+ const isLocked = isSubmitting && hasReadFocus;
18
+ const ref = useCallback((instance) => {
19
+ target.current = instance;
20
+ if (!instance)
21
+ return fieldRef(null);
22
+ fieldRef({
23
+ focus: () => {
24
+ instance.focus();
25
+ focus.current.isOwed = !instance.contains(instance.ownerDocument.activeElement);
26
+ },
27
+ select: () => instance.select?.(),
28
+ });
29
+ }, [fieldRef]);
30
+ useLayoutEffect(() => {
31
+ const state = focus.current;
32
+ const control = target.current;
33
+ if (!control)
34
+ return setHasReadFocus(isSubmitting);
35
+ const { ownerDocument } = control;
36
+ if (isSubmitting && !hasReadFocus) {
37
+ const focused = ownerDocument.activeElement;
38
+ state.heldBy = control.contains(focused) ? focused : null;
39
+ // A request the control refused before this submit is stale: only one made while it is locked is owed.
40
+ state.isOwed = false;
41
+ return setHasReadFocus(true);
42
+ }
43
+ if (isSubmitting) {
44
+ // Only a control the lock disabled loses focus to it; a read-only one keeps it, and must not take it back later.
45
+ state.wasLost = state.heldBy?.matches(':disabled') ?? false;
46
+ // Focus the user puts elsewhere meanwhile is theirs: it is not pulled back, even if another form's submit then drops
47
+ // it, and neither is focus the form had sent here before the user moved on.
48
+ const forget = () => {
49
+ state.wasLost = false;
50
+ state.isOwed = false;
51
+ };
52
+ ownerDocument.addEventListener('focusin', forget);
53
+ return () => ownerDocument.removeEventListener('focusin', forget);
54
+ }
55
+ setHasReadFocus(false);
56
+ // Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
57
+ const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
58
+ if (state.isOwed || isStillLost)
59
+ control.focus();
60
+ focus.current = { heldBy: null, wasLost: false, isOwed: false };
61
+ }, [isSubmitting, hasReadFocus]);
62
+ return { ref, isLocked };
63
+ };
64
+
65
+ export { useFocusThroughSubmit };
66
+ //# sourceMappingURL=useFocusThroughSubmit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusThroughSubmit.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CAAC,QAAqB,EAAE,YAAqB,KAAI;AACpF,IAAA,MAAM,MAAM,GAAG,MAAM,CAAqB,IAAI,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAgE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;IAEpI,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,QAAQ,GAAG,YAAY,IAAI,YAAY;AAE7C,IAAA,MAAM,GAAG,GAAG,WAAW,CACrB,CAAC,QAA4B,KAAI;AAC/B,QAAA,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACpC,QAAA,QAAQ,CAAC;YACP,KAAK,EAAE,MAAK;gBACV,QAAQ,CAAC,KAAK,EAAE;AAChB,gBAAA,KAAK,CAAC,OAAO,CAAC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aAAa,KAAK,aAAa,CAAC,IAAI;AACvF,QAAA,IAAI,KAAK,CAAC,MAAM,IAAI,WAAW;YAAE,OAAO,CAAC,KAAK,EAAE;AAChD,QAAA,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;AACjE,IAAA,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAEhC,IAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;AAC1B;;"}
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var reactHookForm = require('react-hook-form');
5
+ var FieldElements_context = require('../providers/FieldElements.context.cjs');
6
+ var fieldValue_utils = require('../utilities/fieldValue.utils.cjs');
7
+ var validationQueue_utils = require('../utilities/validationQueue.utils.cjs');
8
+ var useFocusThroughSubmit = require('./useFocusThroughSubmit.cjs');
9
+
10
+ const toList = (value) => {
11
+ if (value === undefined)
12
+ return [];
13
+ return Array.isArray(value) ? value : [value];
14
+ };
15
+ /**
16
+ * Binds one control to a react-hook-form field, for the `components/forms` wrappers. In a form that validates and
17
+ * re-validates on blur (`mode` and `reValidateMode` both `'onBlur'`) it re-validates a field on every change while that field is invalid, so an error raised by a blur,
18
+ * a submit, `trigger()` or the server clears as soon as the user fixes it, and a valid field stays quiet until blur.
19
+ * It also reports the form's lock: disabled for good, or locked while it submits.
20
+ *
21
+ * @param name The field's path in the form values.
22
+ * @param revalidates Other fields whose rule reads this one. Typing here re-validates those already invalid; finishing the edit also re-validates those the user has filled in or visited.
23
+ * @returns The field's `value`, `onChange`, `onCommit`, `onDraft`, `onBlur`, `ref` and `name`, with `isInvalid`, its `errorMessage`, and the form's lock as `isDisabled` and `isLocked`.
24
+ */
25
+ const useFormField = (name, revalidates) => {
26
+ const form = reactHookForm.useFormContext();
27
+ if (!form)
28
+ throw new Error('A components/forms field needs a react-hook-form FormProvider above it.');
29
+ const { control, trigger, getFieldState, getValues } = form;
30
+ const { field, fieldState, formState } = reactHookForm.useController({ name, control });
31
+ const { ref: focusRef, isLocked } = useFocusThroughSubmit.useFocusThroughSubmit(field.ref, formState.isSubmitting);
32
+ const fieldElements = React.useContext(FieldElements_context.FieldElementsContext);
33
+ // `Form` reads where each field sits, so a failed submit focuses the first invalid one in page order.
34
+ const ref = React.useCallback((instance) => {
35
+ focusRef(instance);
36
+ const element = instance instanceof Element ? instance : instance?.element;
37
+ if (element)
38
+ fieldElements?.set(name, element);
39
+ else
40
+ fieldElements?.delete(name);
41
+ }, [focusRef, fieldElements, name]);
42
+ const { onChange: setValue } = field;
43
+ const isInvalid = fieldState.invalid;
44
+ const { error } = fieldState;
45
+ const errorMessage = error?.message;
46
+ // `trigger` is only on the form, not on `control`, which is why the wrappers need a FormProvider.
47
+ const validate = React.useCallback((names) => trigger(names), [trigger]);
48
+ const validation = validationQueue_utils.validationQueueOf(control);
49
+ // Typing only ever clears an error or changes its message, so it asks only while the field is invalid.
50
+ const isInvalidNow = React.useCallback((field) => getFieldState(field).invalid, [getFieldState]);
51
+ const revalidate = React.useCallback(() => validationQueue_utils.runInTurn(validation, [name], isInvalidNow, validate), [validation, name, isInvalidNow, validate]);
52
+ // Whether a finished edit still stands when a check it asked for comes up: the field holds that value, and counts as
53
+ // visited or changed. A reset leaves it neither, even one to the value just chosen, and validating then would put an error on a form just discarded.
54
+ const standingEdit = React.useCallback(() => {
55
+ const edited = getValues(name);
56
+ return () => {
57
+ const editor = getFieldState(name);
58
+ // By what it holds: leaving the field copies a list or a group, so the same choice comes back as a new object.
59
+ return fieldValue_utils.isSameValue(getValues(name), edited) && (editor.isTouched || editor.isDirty);
60
+ };
61
+ }, [name, getFieldState, getValues]);
62
+ // The end of an edit: react-hook-form marks the field visited and validates it, by itself and outside the queue.
63
+ const { onBlur: validateOnBlur } = field;
64
+ const finishEdit = React.useCallback(() => {
65
+ const isAwaited = validationQueue_utils.isAwaitingAnswer(validation, name);
66
+ // Typed as returning nothing, but react-hook-form (7.92) returns the validation it started; without it no turn is held back.
67
+ const answer = validateOnBlur();
68
+ validationQueue_utils.holdTurnsUntil(validation, name, answer);
69
+ // An answer on its way is for an older value and may land after this one: asked again in turn, so it is not the last word.
70
+ if (isAwaited)
71
+ void validationQueue_utils.runInTurn(validation, [name], standingEdit(), validate);
72
+ }, [validation, name, validateOnBlur, standingEdit, validate]);
73
+ // A cross-field rule puts its error on another field, which the form never re-checks when this one changes. Typing
74
+ // only clears such an error; a finished edit may also raise one, on a dependent the user has filled in or visited.
75
+ const revalidateDependents = React.useCallback((isEditFinished) => {
76
+ // The edit that asks. If it is gone when the turn comes, only an error already on screen is worth re-checking.
77
+ const isEditStanding = standingEdit();
78
+ const isWanted = (dependent) => {
79
+ const { invalid, isTouched } = getFieldState(dependent);
80
+ if (invalid)
81
+ return true;
82
+ return isEditFinished && isEditStanding() && (isTouched || fieldValue_utils.isFilledIn(getValues(dependent)));
83
+ };
84
+ const dependents = toList(revalidates);
85
+ if (dependents.length > 0)
86
+ void validationQueue_utils.runInTurn(validation, dependents, isWanted, validate);
87
+ }, [revalidates, standingEdit, getFieldState, getValues, validation, validate]);
88
+ // Typed into since the dependents were last checked in full, which leaving the field then does.
89
+ const hasTyped = React.useRef(false);
90
+ const onChange = React.useCallback((next) => {
91
+ setValue(next);
92
+ const isAwaited = validationQueue_utils.isAwaitingAnswer(validation, name);
93
+ // Leaving the field checks it again, so nothing withdrawn here is lost.
94
+ validationQueue_utils.withdrawAsks(validation, name);
95
+ // Read from the form, not from the last render: an error that landed between two keystrokes is not on screen yet.
96
+ // Also while an answer is on its way: the error may have cleared since, and that answer is for an older value.
97
+ if (getFieldState(name).invalid || isAwaited)
98
+ void revalidate();
99
+ hasTyped.current = true;
100
+ revalidateDependents(false);
101
+ }, [setValue, getFieldState, validation, name, revalidate, revalidateDependents]);
102
+ // The value the current error was raised against. Leaving the field without changing it cannot make it valid, and
103
+ // re-validating would wipe an error only the server can judge, such as a name that is already taken.
104
+ const erroredValue = React.useRef(undefined);
105
+ const { value } = field;
106
+ // biome-ignore lint/correctness/useExhaustiveDependencies: recorded when the error appears or changes, not on every keystroke
107
+ React.useEffect(() => {
108
+ erroredValue.current = error ? value : undefined;
109
+ }, [error]);
110
+ const onBlur = React.useCallback(() => {
111
+ const hadTyped = hasTyped.current;
112
+ hasTyped.current = false;
113
+ // First, so the field counts as visited before its dependents are asked about, which they are only while it does.
114
+ if (!(error && fieldValue_utils.isSameValue(value, erroredValue.current)))
115
+ finishEdit();
116
+ // Leaving a field the user only passed through must not raise an error on another one.
117
+ if (hadTyped)
118
+ revalidateDependents(true);
119
+ }, [error, value, finishEdit, revalidateDependents]);
120
+ // A choice has no typing phase to wait out, so it counts as changed and left in one step.
121
+ const onCommit = React.useCallback((next) => {
122
+ setValue(next);
123
+ finishEdit();
124
+ revalidateDependents(true);
125
+ }, [setValue, finishEdit, revalidateDependents]);
126
+ return {
127
+ name: field.name,
128
+ value: value,
129
+ ref,
130
+ onBlur,
131
+ onDraft: setValue,
132
+ onChange,
133
+ onCommit,
134
+ isInvalid,
135
+ errorMessage,
136
+ isDisabled: field.disabled ?? false,
137
+ isLocked,
138
+ };
139
+ };
140
+
141
+ exports.useFormField = useFormField;
142
+ //# sourceMappingURL=useFormField.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormField.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"sourcesContent":[null],"names":["useFormContext","useController","useFocusThroughSubmit","useContext","FieldElementsContext","useCallback","validationQueueOf","runInTurn","isSameValue","isAwaitingAnswer","holdTurnsUntil","isFilledIn","useRef","withdrawAsks","useEffect"],"mappings":";;;;;;;;;AA8BA,MAAM,MAAM,GAAG,CAAQ,KAAkC,KAAa;IACpE,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,EAAE;AAClC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,K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AAA,UAAU,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK;QACnC,QAAQ;KACT;AACH;;"}
@@ -0,0 +1,35 @@
1
+ import { type FieldPath, type FieldValues, type RefCallBack } from 'react-hook-form';
2
+ /** What a `components/forms` wrapper spreads onto its control. */
3
+ export interface FormField<TValue> {
4
+ name: string;
5
+ /** The field's value in the form; `undefined` when the form has no default for it. */
6
+ value: TValue | undefined;
7
+ /** Lets the form focus the control, such as the first invalid field after a failed submit. */
8
+ ref: RefCallBack;
9
+ onBlur: () => void;
10
+ /** Sets the value with no validation of its own, for a value still in motion such as a slider mid-drag. */
11
+ onDraft: (value: TValue) => void;
12
+ /** For a control the user types into: sets the value, and re-validates while the field is invalid. */
13
+ onChange: (value: TValue) => void;
14
+ /** For a control where one action is the whole edit (a choice, a toggle, a picked date): sets the value and validates it. */
15
+ onCommit: (value: TValue) => void;
16
+ isInvalid: boolean;
17
+ /** The message validation gave the field's error. */
18
+ errorMessage: string | undefined;
19
+ /** The whole form is disabled, through `useForm({ disabled })`. */
20
+ isDisabled: boolean;
21
+ /** The form is submitting: the control is read-only meanwhile, or disabled where it has no read-only mode. */
22
+ isLocked: boolean;
23
+ }
24
+ /**
25
+ * Binds one control to a react-hook-form field, for the `components/forms` wrappers. In a form that validates and
26
+ * re-validates on blur (`mode` and `reValidateMode` both `'onBlur'`) it re-validates a field on every change while that field is invalid, so an error raised by a blur,
27
+ * a submit, `trigger()` or the server clears as soon as the user fixes it, and a valid field stays quiet until blur.
28
+ * It also reports the form's lock: disabled for good, or locked while it submits.
29
+ *
30
+ * @param name The field's path in the form values.
31
+ * @param revalidates Other fields whose rule reads this one. Typing here re-validates those already invalid; finishing the edit also re-validates those the user has filled in or visited.
32
+ * @returns The field's `value`, `onChange`, `onCommit`, `onDraft`, `onBlur`, `ref` and `name`, with `isInvalid`, its `errorMessage`, and the form's lock as `isDisabled` and `isLocked`.
33
+ */
34
+ export declare const useFormField: <TValues extends FieldValues, TValue = unknown>(name: FieldPath<TValues>, revalidates?: FieldPath<TValues> | FieldPath<TValues>[]) => FormField<TValue>;
35
+ //# sourceMappingURL=useFormField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAiC,MAAM,iBAAiB,CAAC;AAMpH,kEAAkE;AAClE,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,8FAA8F;IAC9F,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,2GAA2G;IAC3G,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,sGAAsG;IACtG,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,6HAA6H;IAC7H,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAC;IACpB,8GAA8G;IAC9G,QAAQ,EAAE,OAAO,CAAC;CACnB;AAOD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,WAAW,EAAE,MAAM,GAAG,OAAO,EACxE,MAAM,SAAS,CAAC,OAAO,CAAC,EACxB,cAAc,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,KACtD,SAAS,CAAC,MAAM,CA8HlB,CAAC"}