@canonical/react-ds-global-form 0.45.0 → 0.48.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 (441) hide show
  1. package/README.md +14 -9
  2. package/dist/esm/density.css +23 -28
  3. package/dist/esm/index.css +28 -13
  4. package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/ColorField.js +2 -2
  5. package/dist/esm/lib/_work_in_progress/component/ColorField/ColorField.js.map +1 -0
  6. package/dist/esm/lib/_work_in_progress/component/ColorField/index.js.map +1 -0
  7. package/dist/esm/lib/_work_in_progress/component/ColorField/types.js.map +1 -0
  8. package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/ComboboxField.js +2 -2
  9. package/dist/esm/lib/_work_in_progress/component/ComboboxField/ComboboxField.js.map +1 -0
  10. package/dist/esm/lib/_work_in_progress/component/ComboboxField/index.js.map +1 -0
  11. package/dist/esm/lib/_work_in_progress/component/ComboboxField/types.js.map +1 -0
  12. package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/RatingField.js +2 -2
  13. package/dist/esm/lib/_work_in_progress/component/RatingField/RatingField.js.map +1 -0
  14. package/dist/esm/lib/_work_in_progress/component/RatingField/index.js.map +1 -0
  15. package/dist/esm/lib/_work_in_progress/component/RatingField/types.js.map +1 -0
  16. package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/ColorInput.js.map +1 -0
  17. package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/index.js.map +1 -0
  18. package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/types.js.map +1 -0
  19. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.js.map +1 -0
  20. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.js +198 -0
  21. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.js.map +1 -0
  22. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.js +120 -0
  23. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -0
  24. package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/List.js +16 -4
  25. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/List.js.map +1 -0
  26. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/index.js.map +1 -0
  27. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/types.js.map +1 -0
  28. package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/ResetButton.js +2 -2
  29. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.js.map +1 -0
  30. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.js.map +1 -0
  31. package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/styles.css +3 -0
  32. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.js.map +1 -0
  33. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/index.js.map +1 -0
  34. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/constants.js.map +1 -0
  35. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/index.js.map +1 -0
  36. package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/messages.js +1 -0
  37. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/messages.js.map +1 -0
  38. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/types.js.map +1 -0
  39. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.js.map +1 -0
  40. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.js.map +1 -0
  41. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.js.map +1 -0
  42. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.js +7 -0
  43. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.js.map +1 -0
  44. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.js +6 -0
  45. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.js.map +1 -0
  46. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.js +10 -0
  47. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.js.map +1 -0
  48. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.js +25 -0
  49. package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.js.map +1 -0
  50. package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/RatingInput.js.map +1 -0
  51. package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/index.js.map +1 -0
  52. package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/styles.css +7 -7
  53. package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/types.js.map +1 -0
  54. package/dist/esm/lib/common/Wrapper/InvisibleWrapper.js +3 -1
  55. package/dist/esm/lib/common/Wrapper/InvisibleWrapper.js.map +1 -1
  56. package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +0 -6
  57. package/dist/esm/lib/common/Wrapper/ToggleWrapper.js +2 -1
  58. package/dist/esm/lib/common/Wrapper/ToggleWrapper.js.map +1 -1
  59. package/dist/esm/lib/common/Wrapper/Wrapper.js +10 -6
  60. package/dist/esm/lib/common/Wrapper/Wrapper.js.map +1 -1
  61. package/dist/esm/lib/common/Wrapper/createMiddleware.js +70 -0
  62. package/dist/esm/lib/common/Wrapper/createMiddleware.js.map +1 -0
  63. package/dist/esm/lib/common/Wrapper/hooks/useFieldWrapper.js +2 -2
  64. package/dist/esm/lib/common/Wrapper/hooks/useFieldWrapper.js.map +1 -1
  65. package/dist/esm/lib/common/Wrapper/withConditionalDisplay.js +17 -12
  66. package/dist/esm/lib/common/Wrapper/withConditionalDisplay.js.map +1 -1
  67. package/dist/esm/lib/common/Wrapper/withWrapper.js +16 -10
  68. package/dist/esm/lib/common/Wrapper/withWrapper.js.map +1 -1
  69. package/dist/esm/lib/component/ChoicesField/Choices.js +2 -2
  70. package/dist/esm/lib/component/ChoicesField/Choices.js.map +1 -1
  71. package/dist/esm/lib/component/ChoicesField/ChoicesField.js +3 -2
  72. package/dist/esm/lib/component/ChoicesField/ChoicesField.js.map +1 -1
  73. package/dist/esm/lib/component/ChoicesField/styles.css +3 -65
  74. package/dist/esm/lib/component/DateTimeField/DateTimeField.js +2 -1
  75. package/dist/esm/lib/component/DateTimeField/DateTimeField.js.map +1 -1
  76. package/dist/esm/lib/component/FileUploadField/FileUploadField.js +45 -41
  77. package/dist/esm/lib/component/FileUploadField/FileUploadField.js.map +1 -1
  78. package/dist/esm/lib/component/FileUploadField/fileUploadRules.js +39 -0
  79. package/dist/esm/lib/component/FileUploadField/fileUploadRules.js.map +1 -0
  80. package/dist/esm/lib/component/FileUploadField/styles.css +30 -0
  81. package/dist/esm/lib/component/RichChoicesField/RichChoices.js +2 -2
  82. package/dist/esm/lib/component/RichChoicesField/RichChoices.js.map +1 -1
  83. package/dist/esm/lib/component/RichChoicesField/RichChoicesField.js +2 -2
  84. package/dist/esm/lib/component/index.js +5 -4
  85. package/dist/esm/lib/component/index.js.map +1 -1
  86. package/dist/esm/lib/index.js.map +1 -1
  87. package/dist/esm/lib/pattern/Field/Field.js +38 -31
  88. package/dist/esm/lib/pattern/Field/Field.js.map +1 -1
  89. package/dist/esm/lib/subcomponent/DateInput/styles.css +16 -0
  90. package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -7
  91. package/dist/esm/lib/subcomponent/Field/Description/Description.js +1 -3
  92. package/dist/esm/lib/subcomponent/Field/Description/Description.js.map +1 -1
  93. package/dist/esm/lib/subcomponent/Field/Description/styles.css +4 -0
  94. package/dist/esm/lib/subcomponent/Field/Error/Error.js +4 -4
  95. package/dist/esm/lib/subcomponent/Field/Error/Error.js.map +1 -1
  96. package/dist/esm/lib/subcomponent/Field/Error/styles.css +8 -0
  97. package/dist/esm/lib/subcomponent/Field/Label/styles.css +1 -0
  98. package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js +119 -64
  99. package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js.map +1 -1
  100. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.js +52 -0
  101. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.js.map +1 -0
  102. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/index.js +2 -0
  103. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/index.js.map +1 -0
  104. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/types.js +2 -0
  105. package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/types.js.map +1 -0
  106. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.js +40 -0
  107. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.js.map +1 -0
  108. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/index.js +2 -0
  109. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/index.js.map +1 -0
  110. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/types.js +2 -0
  111. package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/types.js.map +1 -0
  112. package/dist/esm/lib/subcomponent/FileUploadInput/constants.js +3 -0
  113. package/dist/esm/lib/subcomponent/FileUploadInput/constants.js.map +1 -0
  114. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/index.js +3 -0
  115. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/index.js.map +1 -0
  116. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useFileUploads.js +148 -0
  117. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useFileUploads.js.map +1 -0
  118. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.js +22 -0
  119. package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.js.map +1 -0
  120. package/dist/esm/lib/subcomponent/FileUploadInput/messages.js +25 -0
  121. package/dist/esm/lib/subcomponent/FileUploadInput/messages.js.map +1 -0
  122. package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +255 -94
  123. package/dist/esm/lib/subcomponent/FileUploadInput/utils/formatFileSize.js +21 -0
  124. package/dist/esm/lib/subcomponent/FileUploadInput/utils/formatFileSize.js.map +1 -0
  125. package/dist/esm/lib/subcomponent/FileUploadInput/utils/getFileMessage.js +20 -0
  126. package/dist/esm/lib/subcomponent/FileUploadInput/utils/getFileMessage.js.map +1 -0
  127. package/dist/esm/lib/subcomponent/FileUploadInput/utils/index.js +4 -0
  128. package/dist/esm/lib/subcomponent/FileUploadInput/utils/index.js.map +1 -0
  129. package/dist/esm/lib/subcomponent/FileUploadInput/utils/matchesAccept.js +26 -0
  130. package/dist/esm/lib/subcomponent/FileUploadInput/utils/matchesAccept.js.map +1 -0
  131. package/dist/esm/lib/subcomponent/NumberInput/NumberInput.js +1 -1
  132. package/dist/esm/lib/subcomponent/NumberInput/NumberInput.js.map +1 -1
  133. package/dist/esm/lib/subcomponent/NumberInput/styles.css +17 -0
  134. package/dist/esm/lib/subcomponent/PasswordInput/styles.css +7 -1
  135. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +8 -2
  136. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
  137. package/dist/esm/lib/subcomponent/RadioInput/styles.css +15 -13
  138. package/dist/esm/lib/subcomponent/TextInput/TextInput.js +3 -1
  139. package/dist/esm/lib/subcomponent/TextInput/TextInput.js.map +1 -1
  140. package/dist/esm/lib/subcomponent/index.js +5 -5
  141. package/dist/esm/lib/subcomponent/index.js.map +1 -1
  142. package/dist/esm/lib/utils/hooks/useFieldAriaProperties.js +6 -4
  143. package/dist/esm/lib/utils/hooks/useFieldAriaProperties.js.map +1 -1
  144. package/dist/esm/lib/utils/hooks/useOptionAriaProperties.js +3 -3
  145. package/dist/esm/lib/utils/hooks/useOptionAriaProperties.js.map +1 -1
  146. package/dist/esm/lib/utils/middleware/addRESTOptions.js +99 -39
  147. package/dist/esm/lib/utils/middleware/addRESTOptions.js.map +1 -1
  148. package/dist/esm/lib/utils/middleware/addRESTValidation.js +246 -32
  149. package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
  150. package/dist/esm/lib/utils/middleware/index.js +1 -0
  151. package/dist/esm/lib/utils/middleware/index.js.map +1 -1
  152. package/dist/esm/testing/expectNoAxeViolations.js +30 -0
  153. package/dist/esm/testing/expectNoAxeViolations.js.map +1 -0
  154. package/dist/types/lib/{component → _work_in_progress/component}/ColorField/ColorField.d.ts +7 -12
  155. package/dist/types/lib/_work_in_progress/component/ColorField/ColorField.d.ts.map +1 -0
  156. package/dist/types/lib/_work_in_progress/component/ColorField/index.d.ts.map +1 -0
  157. package/dist/types/lib/{component → _work_in_progress/component}/ColorField/types.d.ts +1 -1
  158. package/dist/types/lib/_work_in_progress/component/ColorField/types.d.ts.map +1 -0
  159. package/dist/types/lib/_work_in_progress/component/ComboboxField/ComboboxField.d.ts +53 -0
  160. package/dist/types/lib/_work_in_progress/component/ComboboxField/ComboboxField.d.ts.map +1 -0
  161. package/dist/types/lib/_work_in_progress/component/ComboboxField/index.d.ts.map +1 -0
  162. package/dist/types/lib/{component → _work_in_progress/component}/ComboboxField/types.d.ts +1 -1
  163. package/dist/types/lib/_work_in_progress/component/ComboboxField/types.d.ts.map +1 -0
  164. package/dist/types/lib/{component → _work_in_progress/component}/RatingField/RatingField.d.ts +7 -12
  165. package/dist/types/lib/_work_in_progress/component/RatingField/RatingField.d.ts.map +1 -0
  166. package/dist/types/lib/_work_in_progress/component/RatingField/index.d.ts.map +1 -0
  167. package/dist/types/lib/{component → _work_in_progress/component}/RatingField/types.d.ts +1 -1
  168. package/dist/types/lib/_work_in_progress/component/RatingField/types.d.ts.map +1 -0
  169. package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/ColorInput.d.ts.map +1 -0
  170. package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/index.d.ts.map +1 -0
  171. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/types.d.ts +1 -1
  172. package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/types.d.ts.map +1 -0
  173. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/ComboboxInput.d.ts +13 -5
  174. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.d.ts.map +1 -0
  175. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.d.ts +24 -0
  176. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.d.ts.map +1 -0
  177. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/SingleCombobox.d.ts +19 -4
  178. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -0
  179. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/List.d.ts +1 -1
  180. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/List.d.ts.map +1 -0
  181. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/index.d.ts.map +1 -0
  182. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/types.d.ts +2 -1
  183. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/types.d.ts.map +1 -0
  184. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/ResetButton.d.ts +1 -1
  185. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.d.ts.map +1 -0
  186. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.d.ts.map +1 -0
  187. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/types.d.ts +1 -0
  188. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.d.ts.map +1 -0
  189. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/index.d.ts.map +1 -0
  190. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/constants.d.ts.map +1 -0
  191. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/index.d.ts.map +1 -0
  192. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/messages.d.ts +1 -0
  193. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/messages.d.ts.map +1 -0
  194. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/types.d.ts +52 -0
  195. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/types.d.ts.map +1 -0
  196. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.d.ts +4 -0
  197. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.d.ts.map +1 -0
  198. package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertValueToItem.d.ts +1 -1
  199. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.d.ts.map +1 -0
  200. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.d.ts +4 -0
  201. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.d.ts.map +1 -0
  202. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.d.ts +7 -0
  203. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -0
  204. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.d.ts +4 -0
  205. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.d.ts.map +1 -0
  206. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.d.ts +8 -0
  207. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.d.ts.map +1 -0
  208. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.d.ts +13 -0
  209. package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.d.ts.map +1 -0
  210. package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/RatingInput.d.ts.map +1 -0
  211. package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/index.d.ts.map +1 -0
  212. package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/types.d.ts.map +1 -0
  213. package/dist/types/lib/common/Wrapper/InvisibleWrapper.d.ts.map +1 -1
  214. package/dist/types/lib/common/Wrapper/ToggleWrapper.d.ts.map +1 -1
  215. package/dist/types/lib/common/Wrapper/Wrapper.d.ts +1 -1
  216. package/dist/types/lib/common/Wrapper/Wrapper.d.ts.map +1 -1
  217. package/dist/types/lib/common/Wrapper/createMiddleware.d.ts +43 -0
  218. package/dist/types/lib/common/Wrapper/createMiddleware.d.ts.map +1 -0
  219. package/dist/types/lib/common/Wrapper/hooks/useFieldWrapper.d.ts +2 -0
  220. package/dist/types/lib/common/Wrapper/hooks/useFieldWrapper.d.ts.map +1 -1
  221. package/dist/types/lib/common/Wrapper/withConditionalDisplay.d.ts +9 -3
  222. package/dist/types/lib/common/Wrapper/withConditionalDisplay.d.ts.map +1 -1
  223. package/dist/types/lib/common/Wrapper/withToggleWrapper.d.ts +2 -2
  224. package/dist/types/lib/common/Wrapper/withToggleWrapper.d.ts.map +1 -1
  225. package/dist/types/lib/common/Wrapper/withWrapper.d.ts +3 -5
  226. package/dist/types/lib/common/Wrapper/withWrapper.d.ts.map +1 -1
  227. package/dist/types/lib/common/types.d.ts +19 -7
  228. package/dist/types/lib/common/types.d.ts.map +1 -1
  229. package/dist/types/lib/component/CheckboxField/CheckboxField.d.ts +1 -1
  230. package/dist/types/lib/component/ChoicesField/Choices.d.ts +1 -1
  231. package/dist/types/lib/component/ChoicesField/Choices.d.ts.map +1 -1
  232. package/dist/types/lib/component/ChoicesField/ChoicesField.d.ts +9 -13
  233. package/dist/types/lib/component/ChoicesField/ChoicesField.d.ts.map +1 -1
  234. package/dist/types/lib/component/ChoicesField/types.d.ts +2 -2
  235. package/dist/types/lib/component/ChoicesField/types.d.ts.map +1 -1
  236. package/dist/types/lib/component/DateField/DateField.d.ts +6 -11
  237. package/dist/types/lib/component/DateTimeField/DateTimeField.d.ts +7 -11
  238. package/dist/types/lib/component/DateTimeField/DateTimeField.d.ts.map +1 -1
  239. package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts +299 -19
  240. package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts.map +1 -1
  241. package/dist/types/lib/component/FileUploadField/fileUploadRules.d.ts +24 -0
  242. package/dist/types/lib/component/FileUploadField/fileUploadRules.d.ts.map +1 -0
  243. package/dist/types/lib/component/HiddenField/HiddenField.d.ts +6 -11
  244. package/dist/types/lib/component/NumberField/NumberField.d.ts +6 -11
  245. package/dist/types/lib/component/PasswordField/PasswordField.d.ts +6 -11
  246. package/dist/types/lib/component/PhoneField/PhoneField.d.ts +7 -11
  247. package/dist/types/lib/component/RangeField/RangeField.d.ts +6 -11
  248. package/dist/types/lib/component/RichChoicesField/RichChoices.d.ts +1 -1
  249. package/dist/types/lib/component/RichChoicesField/RichChoices.d.ts.map +1 -1
  250. package/dist/types/lib/component/RichChoicesField/RichChoicesField.d.ts +8 -13
  251. package/dist/types/lib/component/RichChoicesField/types.d.ts +2 -2
  252. package/dist/types/lib/component/RichChoicesField/types.d.ts.map +1 -1
  253. package/dist/types/lib/component/SelectField/SelectField.d.ts +6 -11
  254. package/dist/types/lib/component/SwitchField/SwitchField.d.ts +1 -1
  255. package/dist/types/lib/component/TextField/TextField.d.ts +6 -11
  256. package/dist/types/lib/component/TextareaField/TextareaField.d.ts +6 -11
  257. package/dist/types/lib/component/TimeField/TimeField.d.ts +6 -11
  258. package/dist/types/lib/component/index.d.ts +3 -3
  259. package/dist/types/lib/component/index.d.ts.map +1 -1
  260. package/dist/types/lib/index.d.ts +1 -1
  261. package/dist/types/lib/index.d.ts.map +1 -1
  262. package/dist/types/lib/pattern/Field/Field.d.ts +9 -5
  263. package/dist/types/lib/pattern/Field/Field.d.ts.map +1 -1
  264. package/dist/types/lib/pattern/Field/types.d.ts +69 -45
  265. package/dist/types/lib/pattern/Field/types.d.ts.map +1 -1
  266. package/dist/types/lib/subcomponent/Field/Description/Description.d.ts.map +1 -1
  267. package/dist/types/lib/subcomponent/Field/Error/Error.d.ts.map +1 -1
  268. package/dist/types/lib/subcomponent/FileUploadInput/FileUploadInput.d.ts +25 -4
  269. package/dist/types/lib/subcomponent/FileUploadInput/FileUploadInput.d.ts.map +1 -1
  270. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.d.ts +15 -0
  271. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.d.ts.map +1 -0
  272. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/index.d.ts +3 -0
  273. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/index.d.ts.map +1 -0
  274. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/types.d.ts +28 -0
  275. package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/types.d.ts.map +1 -0
  276. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.d.ts +14 -0
  277. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.d.ts.map +1 -0
  278. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/index.d.ts +3 -0
  279. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/index.d.ts.map +1 -0
  280. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/types.d.ts +9 -0
  281. package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/types.d.ts.map +1 -0
  282. package/dist/types/lib/subcomponent/FileUploadInput/constants.d.ts +3 -0
  283. package/dist/types/lib/subcomponent/FileUploadInput/constants.d.ts.map +1 -0
  284. package/dist/types/lib/subcomponent/FileUploadInput/hooks/index.d.ts +3 -0
  285. package/dist/types/lib/subcomponent/FileUploadInput/hooks/index.d.ts.map +1 -0
  286. package/dist/types/lib/subcomponent/FileUploadInput/hooks/useFileUploads.d.ts +33 -0
  287. package/dist/types/lib/subcomponent/FileUploadInput/hooks/useFileUploads.d.ts.map +1 -0
  288. package/dist/types/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.d.ts +8 -0
  289. package/dist/types/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.d.ts.map +1 -0
  290. package/dist/types/lib/subcomponent/FileUploadInput/index.d.ts +1 -1
  291. package/dist/types/lib/subcomponent/FileUploadInput/index.d.ts.map +1 -1
  292. package/dist/types/lib/subcomponent/FileUploadInput/messages.d.ts +4 -0
  293. package/dist/types/lib/subcomponent/FileUploadInput/messages.d.ts.map +1 -0
  294. package/dist/types/lib/subcomponent/FileUploadInput/types.d.ts +165 -8
  295. package/dist/types/lib/subcomponent/FileUploadInput/types.d.ts.map +1 -1
  296. package/dist/types/lib/subcomponent/FileUploadInput/utils/formatFileSize.d.ts +7 -0
  297. package/dist/types/lib/subcomponent/FileUploadInput/utils/formatFileSize.d.ts.map +1 -0
  298. package/dist/types/lib/subcomponent/FileUploadInput/utils/getFileMessage.d.ts +14 -0
  299. package/dist/types/lib/subcomponent/FileUploadInput/utils/getFileMessage.d.ts.map +1 -0
  300. package/dist/types/lib/subcomponent/FileUploadInput/utils/index.d.ts +5 -0
  301. package/dist/types/lib/subcomponent/FileUploadInput/utils/index.d.ts.map +1 -0
  302. package/dist/types/lib/subcomponent/FileUploadInput/utils/matchesAccept.d.ts +10 -0
  303. package/dist/types/lib/subcomponent/FileUploadInput/utils/matchesAccept.d.ts.map +1 -0
  304. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +12 -0
  305. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
  306. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +11 -2
  307. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
  308. package/dist/types/lib/subcomponent/TextInput/TextInput.d.ts +2 -0
  309. package/dist/types/lib/subcomponent/TextInput/TextInput.d.ts.map +1 -1
  310. package/dist/types/lib/subcomponent/index.d.ts +7 -7
  311. package/dist/types/lib/subcomponent/index.d.ts.map +1 -1
  312. package/dist/types/lib/subcomponent/types.d.ts +6 -0
  313. package/dist/types/lib/subcomponent/types.d.ts.map +1 -1
  314. package/dist/types/lib/utils/hooks/useFieldAriaProperties.d.ts +2 -1
  315. package/dist/types/lib/utils/hooks/useFieldAriaProperties.d.ts.map +1 -1
  316. package/dist/types/lib/utils/hooks/useOptionAriaProperties.d.ts +3 -2
  317. package/dist/types/lib/utils/hooks/useOptionAriaProperties.d.ts.map +1 -1
  318. package/dist/types/lib/utils/middleware/addRESTOptions.d.ts +37 -4
  319. package/dist/types/lib/utils/middleware/addRESTOptions.d.ts.map +1 -1
  320. package/dist/types/lib/utils/middleware/addRESTValidation.d.ts +38 -3
  321. package/dist/types/lib/utils/middleware/addRESTValidation.d.ts.map +1 -1
  322. package/dist/types/lib/utils/middleware/index.d.ts +2 -0
  323. package/dist/types/lib/utils/middleware/index.d.ts.map +1 -1
  324. package/dist/types/testing/expectNoAxeViolations.d.ts +10 -0
  325. package/dist/types/testing/expectNoAxeViolations.d.ts.map +1 -0
  326. package/package.json +23 -18
  327. package/dist/esm/lib/component/ColorField/ColorField.js.map +0 -1
  328. package/dist/esm/lib/component/ColorField/index.js.map +0 -1
  329. package/dist/esm/lib/component/ColorField/types.js.map +0 -1
  330. package/dist/esm/lib/component/ComboboxField/ComboboxField.js.map +0 -1
  331. package/dist/esm/lib/component/ComboboxField/index.js.map +0 -1
  332. package/dist/esm/lib/component/ComboboxField/types.js.map +0 -1
  333. package/dist/esm/lib/component/RatingField/RatingField.js.map +0 -1
  334. package/dist/esm/lib/component/RatingField/index.js.map +0 -1
  335. package/dist/esm/lib/component/RatingField/types.js.map +0 -1
  336. package/dist/esm/lib/subcomponent/ColorInput/ColorInput.js.map +0 -1
  337. package/dist/esm/lib/subcomponent/ColorInput/index.js.map +0 -1
  338. package/dist/esm/lib/subcomponent/ColorInput/types.js.map +0 -1
  339. package/dist/esm/lib/subcomponent/ComboboxInput/ComboboxInput.js.map +0 -1
  340. package/dist/esm/lib/subcomponent/ComboboxInput/MultipleCombobox.js +0 -84
  341. package/dist/esm/lib/subcomponent/ComboboxInput/MultipleCombobox.js.map +0 -1
  342. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +0 -67
  343. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +0 -1
  344. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +0 -1
  345. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/index.js.map +0 -1
  346. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/types.js.map +0 -1
  347. package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/ResetButton.js.map +0 -1
  348. package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/index.js.map +0 -1
  349. package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/types.js.map +0 -1
  350. package/dist/esm/lib/subcomponent/ComboboxInput/common/index.js.map +0 -1
  351. package/dist/esm/lib/subcomponent/ComboboxInput/constants.js.map +0 -1
  352. package/dist/esm/lib/subcomponent/ComboboxInput/index.js.map +0 -1
  353. package/dist/esm/lib/subcomponent/ComboboxInput/messages.js.map +0 -1
  354. package/dist/esm/lib/subcomponent/ComboboxInput/types.js.map +0 -1
  355. package/dist/esm/lib/subcomponent/ComboboxInput/utils/convertItemToString.js.map +0 -1
  356. package/dist/esm/lib/subcomponent/ComboboxInput/utils/convertValueToItem.js.map +0 -1
  357. package/dist/esm/lib/subcomponent/ComboboxInput/utils/filterItems.js.map +0 -1
  358. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -4
  359. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +0 -1
  360. package/dist/esm/lib/subcomponent/RatingInput/RatingInput.js.map +0 -1
  361. package/dist/esm/lib/subcomponent/RatingInput/index.js.map +0 -1
  362. package/dist/esm/lib/subcomponent/RatingInput/types.js.map +0 -1
  363. package/dist/types/lib/component/ColorField/ColorField.d.ts.map +0 -1
  364. package/dist/types/lib/component/ColorField/index.d.ts.map +0 -1
  365. package/dist/types/lib/component/ColorField/types.d.ts.map +0 -1
  366. package/dist/types/lib/component/ComboboxField/ComboboxField.d.ts +0 -56
  367. package/dist/types/lib/component/ComboboxField/ComboboxField.d.ts.map +0 -1
  368. package/dist/types/lib/component/ComboboxField/index.d.ts.map +0 -1
  369. package/dist/types/lib/component/ComboboxField/types.d.ts.map +0 -1
  370. package/dist/types/lib/component/RatingField/RatingField.d.ts.map +0 -1
  371. package/dist/types/lib/component/RatingField/index.d.ts.map +0 -1
  372. package/dist/types/lib/component/RatingField/types.d.ts.map +0 -1
  373. package/dist/types/lib/subcomponent/ColorInput/ColorInput.d.ts.map +0 -1
  374. package/dist/types/lib/subcomponent/ColorInput/index.d.ts.map +0 -1
  375. package/dist/types/lib/subcomponent/ColorInput/types.d.ts.map +0 -1
  376. package/dist/types/lib/subcomponent/ComboboxInput/ComboboxInput.d.ts.map +0 -1
  377. package/dist/types/lib/subcomponent/ComboboxInput/MultipleCombobox.d.ts +0 -16
  378. package/dist/types/lib/subcomponent/ComboboxInput/MultipleCombobox.d.ts.map +0 -1
  379. package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +0 -1
  380. package/dist/types/lib/subcomponent/ComboboxInput/common/List/List.d.ts.map +0 -1
  381. package/dist/types/lib/subcomponent/ComboboxInput/common/List/index.d.ts.map +0 -1
  382. package/dist/types/lib/subcomponent/ComboboxInput/common/List/types.d.ts.map +0 -1
  383. package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/ResetButton.d.ts.map +0 -1
  384. package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/index.d.ts.map +0 -1
  385. package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/types.d.ts.map +0 -1
  386. package/dist/types/lib/subcomponent/ComboboxInput/common/index.d.ts.map +0 -1
  387. package/dist/types/lib/subcomponent/ComboboxInput/constants.d.ts.map +0 -1
  388. package/dist/types/lib/subcomponent/ComboboxInput/index.d.ts.map +0 -1
  389. package/dist/types/lib/subcomponent/ComboboxInput/messages.d.ts.map +0 -1
  390. package/dist/types/lib/subcomponent/ComboboxInput/types.d.ts +0 -27
  391. package/dist/types/lib/subcomponent/ComboboxInput/types.d.ts.map +0 -1
  392. package/dist/types/lib/subcomponent/ComboboxInput/utils/convertItemToString.d.ts +0 -4
  393. package/dist/types/lib/subcomponent/ComboboxInput/utils/convertItemToString.d.ts.map +0 -1
  394. package/dist/types/lib/subcomponent/ComboboxInput/utils/convertValueToItem.d.ts.map +0 -1
  395. package/dist/types/lib/subcomponent/ComboboxInput/utils/filterItems.d.ts +0 -4
  396. package/dist/types/lib/subcomponent/ComboboxInput/utils/filterItems.d.ts.map +0 -1
  397. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -4
  398. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +0 -1
  399. package/dist/types/lib/subcomponent/RatingInput/RatingInput.d.ts.map +0 -1
  400. package/dist/types/lib/subcomponent/RatingInput/index.d.ts.map +0 -1
  401. package/dist/types/lib/subcomponent/RatingInput/types.d.ts.map +0 -1
  402. /package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/index.js +0 -0
  403. /package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/types.js +0 -0
  404. /package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/index.js +0 -0
  405. /package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/types.js +0 -0
  406. /package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/index.js +0 -0
  407. /package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/types.js +0 -0
  408. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/ColorInput.js +0 -0
  409. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/index.js +0 -0
  410. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/styles.css +0 -0
  411. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/types.js +0 -0
  412. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/ComboboxInput.js +0 -0
  413. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/index.js +0 -0
  414. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/styles.css +0 -0
  415. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/types.js +0 -0
  416. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/index.js +0 -0
  417. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/types.js +0 -0
  418. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/index.js +0 -0
  419. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/constants.js +0 -0
  420. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/index.js +0 -0
  421. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/styles.css +0 -0
  422. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/types.js +0 -0
  423. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertItemToString.js +0 -0
  424. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertValueToItem.js +0 -0
  425. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/filterItems.js +0 -0
  426. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/RatingInput.js +0 -0
  427. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/index.js +0 -0
  428. /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/types.js +0 -0
  429. /package/dist/types/lib/{component → _work_in_progress/component}/ColorField/index.d.ts +0 -0
  430. /package/dist/types/lib/{component → _work_in_progress/component}/ComboboxField/index.d.ts +0 -0
  431. /package/dist/types/lib/{component → _work_in_progress/component}/RatingField/index.d.ts +0 -0
  432. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/ColorInput.d.ts +0 -0
  433. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/index.d.ts +0 -0
  434. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/index.d.ts +0 -0
  435. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/index.d.ts +0 -0
  436. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/index.d.ts +0 -0
  437. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/constants.d.ts +0 -0
  438. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/index.d.ts +0 -0
  439. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/RatingInput.d.ts +0 -0
  440. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/index.d.ts +0 -0
  441. /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/types.d.ts +0 -0
@@ -24,24 +24,25 @@
24
24
  background-color var(--motion-duration-fast) ease,
25
25
  border-color var(--motion-duration-fast) ease;
26
26
 
27
+ /* Ring fill = selected token, centre dot = unselected token; both
28
+ * surface-provided (flat fallback) so the control adapts to OnSurface
29
+ * stepping. */
27
30
  &:checked {
28
- /* Dot = selected token, ring fill = unselected token; both surface-provided
29
- * (flat fallback) so the control adapts to OnSurface stepping. */
30
31
  border-color: var(
31
32
  --surface-color-foreground-radio-selected,
32
33
  var(--color-foreground-radio-selected)
33
34
  );
34
35
  background: radial-gradient(
35
- var(
36
- --surface-color-foreground-radio-selected,
37
- var(--color-foreground-radio-selected)
38
- )
39
- 40%,
40
36
  var(
41
37
  --surface-color-foreground-radio-unselected,
42
38
  var(--color-foreground-radio-unselected)
43
39
  )
44
- 41%
40
+ 30%,
41
+ var(
42
+ --surface-color-foreground-radio-selected,
43
+ var(--color-foreground-radio-selected)
44
+ )
45
+ 31%
45
46
  );
46
47
  }
47
48
 
@@ -49,18 +50,19 @@
49
50
  background-color: var(--color-foreground-radio-unselected-hover);
50
51
  }
51
52
 
52
- /* Hover on a selected radio shifts only the dot's fill, not via a whole-element
53
- * brightness filter (which would also dim the ring). Re-paint the gradient with
54
- * the hovered selected shade from the `--hover--…-selected` channel. */
53
+ /* Hover on a selected radio shifts only the ring's fill, not via a
54
+ * whole-element brightness filter (which would also dim the dot).
55
+ * Re-paint the gradient with the hovered selected shade from the
56
+ * `--hover--…-selected` channel. */
55
57
  &:checked:hover:not(:disabled) {
56
58
  border-color: var(--hover--color-foreground-radio-selected);
57
59
  background: radial-gradient(
58
- var(--hover--color-foreground-radio-selected) 40%,
59
60
  var(
60
61
  --surface-color-foreground-radio-unselected,
61
62
  var(--color-foreground-radio-unselected)
62
63
  )
63
- 41%
64
+ 30%,
65
+ var(--hover--color-foreground-radio-selected) 31%
64
66
  );
65
67
  }
66
68
 
@@ -7,6 +7,8 @@ const componentCssClassName = "ds input text chrome";
7
7
  *
8
8
  * Usable standalone (controlled via `value`/`onChange`, or uncontrolled) or via
9
9
  * the field tier, which spreads react-hook-form's `register()` result onto it.
10
+ * The `id` goes on the native `<input>`, not the chrome wrapper, so a
11
+ * `<label for>` names and focuses the real control.
10
12
  * @returns {ReactElement} - Rendered Text
11
13
  *
12
14
  * `import { TextInput } from "@canonical/react-ds-global-form";`
@@ -14,7 +16,7 @@ const componentCssClassName = "ds input text chrome";
14
16
  * @implements ds:global.subcomponent.text_input
15
17
  */
16
18
  export const TextInput = forwardRef(function TextInput({ id, className, style, inputType = "text", prefix, suffix, ...nativeProps }, ref) {
17
- return (_jsxs("div", { id: id, style: style, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [prefix && _jsx("span", { className: "prefix", children: prefix }), _jsx("input", { type: inputType, ref: ref, ...nativeProps }), suffix && _jsx("span", { className: "suffix", children: suffix })] }));
19
+ return (_jsxs("div", { style: style, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [prefix && _jsx("span", { className: "prefix", children: prefix }), _jsx("input", { id: id, type: inputType, ref: ref, ...nativeProps }), suffix && _jsx("span", { className: "suffix", children: suffix })] }));
18
20
  });
19
21
  export default TextInput;
20
22
  //# sourceMappingURL=TextInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/TextInput/TextInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,OAAO,CAAC;AAEtD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CACjC,SAAS,SAAS,CAChB,EACE,EAAE,EACF,SAAS,EACT,KAAK,EACL,SAAS,GAAG,MAAM,EAClB,MAAM,EACN,MAAM,EACN,GAAG,WAAW,EACf,EACD,GAAG;IAEH,OAAO,CACL,eACE,EAAE,EAAE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;AAEF,eAAe,SAAS,CAAC"}
@@ -1,10 +1,11 @@
1
1
  // ds:Subcomponent tier barrel. Presentational input parts (no react-hook-form
2
2
  // context) + the Field chrome subcomponents (Field.Label/Description/Error).
3
- // The field/RHF-bound versions live under `component/` (via `fields/`).
4
- // Input subcomponents
3
+ // The field/RHF-bound versions live under `component/` (via `fields/`). The
4
+ // work-in-progress inputs live under `_work_in_progress/` until they are ready.
5
+ export { ColorInput } from "../_work_in_progress/subcomponent/ColorInput/index.js";
6
+ export { ComboboxInput } from "../_work_in_progress/subcomponent/ComboboxInput/index.js";
7
+ export { RatingInput } from "../_work_in_progress/subcomponent/RatingInput/index.js";
5
8
  export { CheckboxInput } from "./CheckboxInput/index.js";
6
- export { ColorInput } from "./ColorInput/index.js";
7
- export { ComboboxInput } from "./ComboboxInput/index.js";
8
9
  export { DateInput } from "./DateInput/index.js";
9
10
  export { DateTimeInput } from "./DateTimeInput/index.js";
10
11
  // Field chrome subcomponents (Field.Label / Field.Description / Field.Error)
@@ -16,7 +17,6 @@ export { PasswordInput } from "./PasswordInput/index.js";
16
17
  export { PhoneInput } from "./PhoneInput/index.js";
17
18
  export { RadioInput } from "./RadioInput/index.js";
18
19
  export { RangeInput } from "./RangeInput/index.js";
19
- export { RatingInput } from "./RatingInput/index.js";
20
20
  export { SelectInput } from "./SelectInput/index.js";
21
21
  export { SwitchInput } from "./SwitchInput/index.js";
22
22
  export { TextareaInput } from "./TextareaInput/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/subcomponent/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,wEAAwE;AAIxE,sBAAsB;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,SAAS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AAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AAUjC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,gFAAgF;AAChF,cAAc,YAAY,CAAC"}
@@ -4,9 +4,10 @@ import { useId, useMemo } from "react";
4
4
  * @param {string} name - The name of the field.
5
5
  * @param {boolean} isError - Indicates if the field is in an error state.
6
6
  * @param {boolean} [isRequired] - Whether the field is required (drives `aria-required`, independent of error state).
7
+ * @param {boolean} [hasDescription] - Whether a description is rendered. `aria-describedby` only references ids that are in the document.
7
8
  * @returns An object containing ARIA attributes for input, label, description, and error state.
8
9
  */
9
- const useFieldAriaProps = (name, isError, isRequired = false) => {
10
+ const useFieldAriaProps = (name, isError, isRequired = false, hasDescription = false) => {
10
11
  const uniqueId = useId();
11
12
  const props = useMemo(() => {
12
13
  const baseId = `${uniqueId}-${name}`;
@@ -17,8 +18,9 @@ const useFieldAriaProps = (name, isError, isRequired = false) => {
17
18
  input: {
18
19
  id: baseId,
19
20
  "aria-labelledby": labelId,
20
- "aria-describedby": [descriptionId, isError ? errorId : ""].filter(Boolean).join(" ") ||
21
- undefined,
21
+ "aria-describedby": [hasDescription ? descriptionId : "", isError ? errorId : ""]
22
+ .filter(Boolean)
23
+ .join(" ") || undefined,
22
24
  "aria-errormessage": isError ? errorId : undefined,
23
25
  "aria-invalid": isError,
24
26
  // Required state is a property of the field's optionality, NOT its
@@ -36,7 +38,7 @@ const useFieldAriaProps = (name, isError, isRequired = false) => {
36
38
  // role: "alert",
37
39
  },
38
40
  };
39
- }, [name, isError, isRequired, uniqueId]);
41
+ }, [name, isError, isRequired, hasDescription, uniqueId]);
40
42
  return props;
41
43
  };
42
44
  export default useFieldAriaProps;
@@ -1 +1 @@
1
- {"version":3,"file":"useFieldAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFieldAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CACxB,IAAY,EACZ,OAAgB,EAChB,UAAU,GAAG,KAAK,EAClB,EAAE;IACF,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAClC,MAAM,aAAa,GAAG,GAAG,MAAM,cAAc,CAAC;QAC9C,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAElC,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,MAAM;gBACV,iBAAiB,EAAE,OAAO;gBAC1B,kBAAkB,EAChB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;oBACjE,SAAS;gBACX,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAClD,cAAc,EAAE,OAAO;gBACvB,mEAAmE;gBACnE,wEAAwE;gBACxE,4DAA4D;gBAC5D,eAAe,EAAE,UAAU,IAAI,SAAS;aACzC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,OAAO,EAAE,MAAM;aAChB;YACD,WAAW,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE;YAClC,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,iBAAiB;aAClB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"useFieldAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFieldAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,CACxB,IAAY,EACZ,OAAgB,EAChB,UAAU,GAAG,KAAK,EAClB,cAAc,GAAG,KAAK,EACtB,EAAE;IACF,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAClC,MAAM,aAAa,GAAG,GAAG,MAAM,cAAc,CAAC;QAC9C,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAElC,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,MAAM;gBACV,iBAAiB,EAAE,OAAO;gBAC1B,kBAAkB,EAChB,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC1D,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS;gBAC3B,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAClD,cAAc,EAAE,OAAO;gBACvB,mEAAmE;gBACnE,wEAAwE;gBACxE,4DAA4D;gBAC5D,eAAe,EAAE,UAAU,IAAI,SAAS;aACzC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,OAAO,EAAE,MAAM;aAChB;YACD,WAAW,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE;YAClC,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,iBAAiB;aAClB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -2,7 +2,9 @@ import { useId, useMemo } from "react";
2
2
  /**
3
3
  * Generates ARIA properties for a specific option in a choice-style field.
4
4
  * Pure (no react-hook-form) — lives in the presentational tier so option-group
5
- * inputs (Choices, RichChoices) can use it standalone.
5
+ * inputs (Choices, RichChoices) can use it standalone. Options carry no
6
+ * `aria-describedby`: the field description describes the whole group, so it is
7
+ * referenced from the group's fieldset instead.
6
8
  * @param {string} name - The base name of the input field.
7
9
  * @param {string} optionValue - The value of the specific option.
8
10
  * @returns An object containing ARIA attributes for the option.
@@ -11,14 +13,12 @@ const useOptionAriaProps = (name, optionValue) => {
11
13
  const uniqueId = useId();
12
14
  const props = useMemo(() => {
13
15
  const baseId = `${uniqueId}-${name}`;
14
- const descriptionId = `${baseId}-description`;
15
16
  const optionBaseId = `${baseId}-${optionValue}`;
16
17
  const optionLabelId = `${optionBaseId}-label`;
17
18
  return {
18
19
  input: {
19
20
  id: optionBaseId,
20
21
  "aria-labelledby": optionLabelId,
21
- "aria-describedby": descriptionId,
22
22
  },
23
23
  label: {
24
24
  id: optionLabelId,
@@ -1 +1 @@
1
- {"version":3,"file":"useOptionAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useOptionAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,aAAa,GAAG,GAAG,MAAM,cAAc,CAAC;QAE9C,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;QAChD,MAAM,aAAa,GAAG,GAAG,YAAY,QAAQ,CAAC;QAE9C,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,YAAY;gBAChB,iBAAiB,EAAE,aAAa;gBAChC,kBAAkB,EAAE,aAAa;aAClC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,aAAa;gBACjB,OAAO,EAAE,YAAY;aACtB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"useOptionAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useOptionAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;QAChD,MAAM,aAAa,GAAG,GAAG,YAAY,QAAQ,CAAC;QAE9C,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,YAAY;gBAChB,iBAAiB,EAAE,aAAa;aACjC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,aAAa;gBACjB,OAAO,EAAE,YAAY;aACtB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -1,44 +1,104 @@
1
- import { createElement, useEffect, useState } from "react";
2
- function addRESTFieldOptions(url, options = {}) {
3
- const { method = "GET", headers = {}, transformData = (data) => data, } = options;
4
- return (WrappedComponent) => {
5
- return function ExtendedComponent(props) {
6
- const [optionsData, setOptionsData] = useState([]);
7
- const [loading, setLoading] = useState(true);
8
- const [error, setError] = useState(null);
9
- useEffect(() => {
10
- fetch(url, {
11
- method,
12
- headers,
13
- })
14
- .then((response) => {
15
- if (!response.ok) {
16
- throw new Error("Failed to fetch options");
17
- }
18
- return response.json();
19
- })
20
- .then((data) => {
21
- const transformed = transformData(data);
22
- setOptionsData(transformed);
23
- setLoading(false);
24
- })
25
- .catch((err) => {
26
- setError(err.message);
27
- setLoading(false);
1
+ import { createElement, useEffect, useEffectEvent, useState, } from "react";
2
+ import { useFormContext } from "react-hook-form";
3
+ import createMiddleware, {} from "../../common/Wrapper/createMiddleware.js";
4
+ /** The error type the middleware sets, so it only ever clears its own error. */
5
+ const REST_OPTIONS_ERROR_TYPE = "restOptions";
6
+ /** The options of a field before, or without, a successful request. */
7
+ const NO_OPTIONS = [];
8
+ /** Reads a displayable message from whatever a failed request rejected with. */
9
+ const readErrorMessage = (error) => error instanceof Error ? error.message : String(error);
10
+ /**
11
+ * Requests the options and transforms the body.
12
+ * @note Impure: performs a network request.
13
+ */
14
+ const requestOptions = async (url, { method, headers, transform }, signal) => {
15
+ const response = await fetch(url, { method, headers, signal });
16
+ if (!response.ok) {
17
+ throw new Error("Failed to fetch options");
18
+ }
19
+ return transform(await response.json());
20
+ };
21
+ /** Builds the component that fetches the options and passes them on. */
22
+ const buildRESTOptions = (WrappedComponent, useSettings) => {
23
+ function WithRESTOptions(props) {
24
+ const { name } = props;
25
+ const settings = useSettings();
26
+ const { url } = settings;
27
+ const { setError, clearErrors, getFieldState } = useFormContext();
28
+ const [status, setStatus] = useState("loading");
29
+ const [fetchedOptions, setFetchedOptions] = useState(NO_OPTIONS);
30
+ // The request reads the newest method, headers and transform, but only a
31
+ // new URL starts one.
32
+ const fetchOptions = useEffectEvent((requestUrl, signal) => requestOptions(requestUrl, settings, signal));
33
+ useEffect(() => {
34
+ const controller = new AbortController();
35
+ /** Clears the field's error when this middleware set it. */
36
+ const clearOwnError = () => {
37
+ if (getFieldState(name).error?.type === REST_OPTIONS_ERROR_TYPE) {
38
+ clearErrors(name);
39
+ }
40
+ };
41
+ // The failure of the previous URL is part of its answer: drop it too.
42
+ clearOwnError();
43
+ setStatus("loading");
44
+ setFetchedOptions(NO_OPTIONS);
45
+ fetchOptions(url, controller.signal)
46
+ .then((result) => {
47
+ if (controller.signal.aborted)
48
+ return;
49
+ setFetchedOptions(result);
50
+ setStatus("ready");
51
+ clearOwnError();
52
+ })
53
+ .catch((error) => {
54
+ if (controller.signal.aborted)
55
+ return;
56
+ setStatus("failed");
57
+ setError(name, {
58
+ type: REST_OPTIONS_ERROR_TYPE,
59
+ message: readErrorMessage(error),
28
60
  });
29
- }, []);
30
- if (loading) {
31
- return createElement("div", null, "Loading options...");
32
- }
33
- if (error) {
34
- return createElement("div", null, `Error: ${error}`);
35
- }
36
- return createElement(WrappedComponent, {
37
- ...props,
38
- options: optionsData,
39
61
  });
40
- };
41
- };
62
+ return () => controller.abort();
63
+ }, [url, name, setError, clearErrors, getFieldState]);
64
+ const isLoading = status === "loading";
65
+ return createElement(WrappedComponent, {
66
+ ...props,
67
+ options: fetchedOptions,
68
+ disabled: props.disabled || isLoading,
69
+ "aria-busy": isLoading || undefined,
70
+ });
71
+ }
72
+ return WithRESTOptions;
73
+ };
74
+ const configureRESTOptions = createMiddleware(buildRESTOptions);
75
+ /**
76
+ * Fetches a field's options from a REST endpoint and passes them as the
77
+ * `options` prop.
78
+ *
79
+ * The field keeps its normal markup in every state. While loading it is
80
+ * disabled, marked `aria-busy`, and has no options. A failed request is set as
81
+ * the field's error, so it shows where the field shows any other error, and
82
+ * leaves the field enabled. The middleware can be created inline: the field
83
+ * keeps one instance, which fetches again only when the URL changes, and
84
+ * drops the answer for the previous URL, its error included. The request is
85
+ * aborted when the field unmounts. Use one per field: an inner instance's
86
+ * options replace the outer one's.
87
+ *
88
+ * @param url - The endpoint returning the options.
89
+ * @param options - Request and transform options.
90
+ * @returns A middleware for any field that takes `options`.
91
+ *
92
+ * `import { addRESTOptions } from "@canonical/react-ds-global-form";`
93
+ */
94
+ function addRESTFieldOptions(url, options = {}) {
95
+ const { method = "GET", headers = {}, transformData } = options;
96
+ return configureRESTOptions({
97
+ url,
98
+ method,
99
+ headers,
100
+ transform: (data) => transformData ? transformData(data) : data,
101
+ });
42
102
  }
43
103
  export default addRESTFieldOptions;
44
104
  //# sourceMappingURL=addRESTOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"addRESTOptions.js","sourceRoot":"","sources":["../../../../../src/lib/utils/middleware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X,OAAO,GAA8B,EAAE;IAEvC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAG,EAAE,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAChE,OAAO,oBAAoB,CAAC;QAC1B,GAAG;QACH,MAAM;QACN,OAAO;QACP,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,IAAY,CAAC,CAAC,CAAC,CAAE,IAAiB;KACnE,CAAC,CAAC;AACL,CAAC;AAED,eAAe,mBAAmB,CAAC"}
@@ -1,38 +1,252 @@
1
- import { debounce } from "@canonical/ds-utils";
2
- import { createElement, useCallback, useEffect } from "react";
3
- import { useFormContext } from "react-hook-form";
4
- function addRESTFieldValidation(url, options = {}) {
5
- const { method = "POST", headers = { "Content-Type": "application/json" }, bodyFormatter = (value) => ({ value }), errorExtractor = async () => "Validation failed", minLength = 3, debounceWait = 300, } = options;
6
- return (WrappedComponent) => {
7
- return function ExtendedComponent(props) {
8
- const { name } = props;
9
- const { setError, clearErrors, watch } = useFormContext();
10
- const value = watch(name);
11
- const debouncedFetch = useCallback(debounce(async (val) => {
12
- const response = await fetch(url, {
13
- method,
14
- headers,
15
- body: JSON.stringify(bodyFormatter(val)),
16
- });
17
- if (!response.ok) {
18
- const errorMessage = await errorExtractor(response);
19
- setError(name, { type: "manual", message: errorMessage });
20
- }
21
- else {
22
- clearErrors(name);
1
+ import { createElement, useEffect, useEffectEvent, useRef, } from "react";
2
+ import { useFormContext, useWatch, } from "react-hook-form";
3
+ import createMiddleware, {} from "../../common/Wrapper/createMiddleware.js";
4
+ /**
5
+ * The error type the middleware sets, and the name of the `validate` rule it
6
+ * registers, so it only ever clears its own error.
7
+ */
8
+ const REST_VALIDATION_ERROR_TYPE = "restValidation";
9
+ /** The message shown when the endpoint rejects a value without a readable one. */
10
+ const DEFAULT_ERROR_MESSAGE = "Validation failed";
11
+ const VALID = { kind: "valid" };
12
+ const NO_ANSWER = { kind: "none" };
13
+ /** Reads the message of an error set by a REST check, if it is one. */
14
+ const readRESTMessage = (error) => error?.type === REST_VALIDATION_ERROR_TYPE ? error.message : undefined;
15
+ /** Whether a value is long enough, and a string, to be sent. */
16
+ const isCheckable = (value, minLength) => typeof value === "string" && value.length >= minLength;
17
+ /**
18
+ * Reads the message of a rejected value, falling back to the default when
19
+ * `errorExtractor` cannot read the response, so the value still shows as
20
+ * rejected.
21
+ */
22
+ const readErrorMessage = async (response, errorExtractor) => {
23
+ try {
24
+ return await errorExtractor(response);
25
+ }
26
+ catch {
27
+ return DEFAULT_ERROR_MESSAGE;
28
+ }
29
+ };
30
+ /**
31
+ * Sends the value and reads the endpoint's answer. A request that fails to
32
+ * complete says nothing about the value. An aborted request's answer is never
33
+ * read: `startCheck` settles the check before it aborts the request.
34
+ * @note Impure: performs a network request.
35
+ */
36
+ const requestAnswer = async (url, value, { method, headers, bodyFormatter, errorExtractor }, signal) => {
37
+ try {
38
+ const response = await fetch(url, {
39
+ method,
40
+ headers,
41
+ body: JSON.stringify(bodyFormatter(value)),
42
+ signal,
43
+ });
44
+ if (response.ok)
45
+ return VALID;
46
+ const message = await readErrorMessage(response, errorExtractor);
47
+ return { kind: "invalid", message };
48
+ }
49
+ catch {
50
+ return NO_ANSWER;
51
+ }
52
+ };
53
+ /**
54
+ * Starts a check that sends the value once `debounceWait` has passed, and
55
+ * gives up on the request after `timeout`.
56
+ * @note Impure: schedules timers and a network request.
57
+ */
58
+ const startCheck = (url, value, settings) => {
59
+ const controller = new AbortController();
60
+ let settle;
61
+ const answer = new Promise((resolve) => {
62
+ settle = resolve;
63
+ });
64
+ let requestTimer;
65
+ const cancel = () => {
66
+ clearTimeout(debounceTimer);
67
+ clearTimeout(requestTimer);
68
+ settle(NO_ANSWER);
69
+ controller.abort();
70
+ };
71
+ const debounceTimer = setTimeout(() => {
72
+ requestTimer = setTimeout(cancel, settings.timeout);
73
+ requestAnswer(url, value, settings, controller.signal).then((result) => {
74
+ clearTimeout(requestTimer);
75
+ settle(result);
76
+ });
77
+ }, settings.debounceWait);
78
+ return { url, value, answer, cancel };
79
+ };
80
+ /** Whether a `validate` rule's result lets the value through. */
81
+ const isPassing = (result) => result === true || result === undefined || result === null;
82
+ /**
83
+ * Runs two `validate` rules together and returns the first failure, so a
84
+ * second REST check on the field keeps the first one under the same name.
85
+ */
86
+ const combineRules = (first, second) => async (value, formValues) => {
87
+ const [firstResult, secondResult] = await Promise.all([
88
+ first(value, formValues),
89
+ second(value, formValues),
90
+ ]);
91
+ return isPassing(firstResult) ? secondResult : firstResult;
92
+ };
93
+ /**
94
+ * Adds a rule to the field's `validate` rules, keeping the rules it has. A
95
+ * single `validate` function stays under the `validate` name, the error type
96
+ * react-hook-form gives it. A `restValidation` rule already there, from
97
+ * another REST check on the field, runs together with the new one.
98
+ */
99
+ const addValidateRule = (registerProps, rule) => {
100
+ const validate = registerProps?.validate;
101
+ const rules = typeof validate === "function" ? { validate } : validate;
102
+ const previous = rules?.[REST_VALIDATION_ERROR_TYPE];
103
+ return {
104
+ ...registerProps,
105
+ validate: {
106
+ ...rules,
107
+ [REST_VALIDATION_ERROR_TYPE]: previous
108
+ ? combineRules(previous, rule)
109
+ : rule,
110
+ },
111
+ };
112
+ };
113
+ /** Builds the component that checks the value and owns the REST error. */
114
+ const buildRESTValidation = (WrappedComponent, useSettings) => {
115
+ function WithRESTValidation(props) {
116
+ const { name } = props;
117
+ const settings = useSettings();
118
+ const { url } = settings;
119
+ const { setError, clearErrors, getFieldState } = useFormContext();
120
+ const value = useWatch({ name });
121
+ const pending = useRef(null);
122
+ // The message this instance last gave, so a second REST check on the
123
+ // field cannot clear or keep the other one's message. A REST message left
124
+ // from before the field mounted is adopted, so it can still be cleared.
125
+ const ownMessage = useRef(readRESTMessage(getFieldState(name).error));
126
+ /** Reads the field's error message when this instance set it. */
127
+ const readOwnMessage = () => {
128
+ const message = readRESTMessage(getFieldState(name).error);
129
+ return message === ownMessage.current ? message : undefined;
130
+ };
131
+ /** Clears the field's error when this instance set it. */
132
+ const clearOwnError = () => {
133
+ if (readOwnMessage() !== undefined)
134
+ clearErrors(name);
135
+ ownMessage.current = undefined;
136
+ };
137
+ /** Sets the endpoint's rejection as the field's error. */
138
+ const setOwnError = (message) => {
139
+ ownMessage.current = message;
140
+ setError(name, { type: REST_VALIDATION_ERROR_TYPE, message });
141
+ };
142
+ /** Stops the pending check, if any. */
143
+ const cancelPending = () => {
144
+ pending.current?.cancel();
145
+ pending.current = null;
146
+ };
147
+ /**
148
+ * Resolves to the answer for a value, sharing the pending check when it is
149
+ * for the same value and URL, so typing and submitting send one request.
150
+ * A newer value cancels the previous check, so only the answer for the
151
+ * latest value is ever used. A check that got no answer is dropped, so the
152
+ * next one asks again.
153
+ */
154
+ const check = (checkUrl, checkValue) => {
155
+ const current = pending.current;
156
+ if (current?.url === checkUrl && current.value === checkValue) {
157
+ return current.answer;
158
+ }
159
+ cancelPending();
160
+ const next = startCheck(checkUrl, checkValue, settings);
161
+ pending.current = next;
162
+ next.answer.then((answer) => {
163
+ if (answer.kind === "none" && pending.current === next) {
164
+ pending.current = null;
23
165
  }
24
- }, debounceWait), []);
25
- useEffect(() => {
26
- if (value && value.length >= minLength) {
27
- debouncedFetch(value);
166
+ });
167
+ return next.answer;
168
+ };
169
+ /**
170
+ * The `validate` rule react-hook-form runs, on submit among others, so a
171
+ * value the endpoint rejected cannot be submitted. Without an answer it
172
+ * keeps the message this middleware last set.
173
+ */
174
+ const validateRemotely = async (fieldValue) => {
175
+ if (!isCheckable(fieldValue, settings.minLength))
176
+ return true;
177
+ const answer = await check(url, fieldValue);
178
+ if (answer.kind === "valid") {
179
+ ownMessage.current = undefined;
180
+ return true;
181
+ }
182
+ if (answer.kind === "invalid") {
183
+ ownMessage.current = answer.message;
184
+ return answer.message;
185
+ }
186
+ return readOwnMessage() || true;
187
+ };
188
+ const followValue = useEffectEvent((nextValue, nextUrl) => {
189
+ if (!isCheckable(nextValue, settings.minLength)) {
190
+ cancelPending();
191
+ clearOwnError();
192
+ return;
193
+ }
194
+ check(nextUrl, nextValue).then((answer) => {
195
+ if (answer.kind === "valid") {
196
+ clearOwnError();
28
197
  }
29
- else {
30
- clearErrors(name);
198
+ else if (answer.kind === "invalid") {
199
+ setOwnError(answer.message);
31
200
  }
32
- }, [value, debouncedFetch, name, clearErrors]);
33
- return createElement(WrappedComponent, props);
34
- };
35
- };
201
+ // A check without an answer leaves the field's error as it is.
202
+ });
203
+ });
204
+ useEffect(() => followValue(value, url), [value, url]);
205
+ useEffect(() => () => {
206
+ pending.current?.cancel();
207
+ pending.current = null;
208
+ }, []);
209
+ return createElement(WrappedComponent, {
210
+ ...props,
211
+ registerProps: addValidateRule(props.registerProps, validateRemotely),
212
+ });
213
+ }
214
+ return WithRESTValidation;
215
+ };
216
+ const configureRESTValidation = createMiddleware(buildRESTValidation);
217
+ /**
218
+ * Validates a field's value against a REST endpoint once the user stops
219
+ * typing, and sets the field's error when the endpoint rejects it.
220
+ *
221
+ * The check is also registered as the field's `restValidation` rule, so
222
+ * submitting re-checks the value and a rejected value blocks the submit. Each
223
+ * change cancels the pending timer and aborts the request in flight, so only
224
+ * the answer for the latest value can set or clear the error; unmounting the
225
+ * field does the same. A request that fails to complete keeps the previous
226
+ * message, and a request still unanswered after `timeout` is given up. It
227
+ * only clears the error it set, so an error from the field's own rules or
228
+ * another middleware stays in place. Two instances on one field each keep
229
+ * their own message, and submit runs both checks. The middleware can be
230
+ * created inline: the field keeps one instance.
231
+ *
232
+ * @param url - The endpoint validating the value.
233
+ * @param options - Request, debounce and error options.
234
+ * @returns A middleware for any field.
235
+ *
236
+ * `import { addRESTValidation } from "@canonical/react-ds-global-form";`
237
+ */
238
+ function addRESTFieldValidation(url, options = {}) {
239
+ const { method = "POST", headers = { "Content-Type": "application/json" }, bodyFormatter = (value) => ({ value }), errorExtractor = () => DEFAULT_ERROR_MESSAGE, minLength = 3, debounceWait = 300, timeout = 10000, } = options;
240
+ return configureRESTValidation({
241
+ url,
242
+ method,
243
+ headers,
244
+ bodyFormatter,
245
+ errorExtractor,
246
+ minLength,
247
+ debounceWait,
248
+ timeout,
249
+ });
36
250
  }
37
251
  export default addRESTFieldValidation;
38
252
  //# sourceMappingURL=addRESTValidation.js.map