@canonical/svelte-ds-global-form 0.0.0-stage → 0.47.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 (467) hide show
  1. package/README.md +260 -2
  2. package/dist/_work_in_progress/DensityTestbed/SPIKE.md +198 -0
  3. package/dist/_work_in_progress/DensityTestbed/baseline-system.css +88 -0
  4. package/dist/_work_in_progress/DensityTestbed/density.testbed.css +157 -0
  5. package/dist/_work_in_progress/component/ColorField/ColorField.svelte +21 -0
  6. package/dist/_work_in_progress/component/ColorField/ColorField.svelte.d.ts +12 -0
  7. package/dist/_work_in_progress/component/ColorField/index.d.ts +2 -0
  8. package/dist/_work_in_progress/component/ColorField/index.js +1 -0
  9. package/dist/_work_in_progress/component/ColorField/types.d.ts +7 -0
  10. package/dist/_work_in_progress/component/ColorField/types.js +1 -0
  11. package/dist/_work_in_progress/component/ComboboxField/ComboboxField.svelte +23 -0
  12. package/dist/_work_in_progress/component/ComboboxField/ComboboxField.svelte.d.ts +14 -0
  13. package/dist/_work_in_progress/component/ComboboxField/index.d.ts +2 -0
  14. package/dist/_work_in_progress/component/ComboboxField/index.js +1 -0
  15. package/dist/_work_in_progress/component/ComboboxField/types.d.ts +7 -0
  16. package/dist/_work_in_progress/component/ComboboxField/types.js +1 -0
  17. package/dist/_work_in_progress/component/RatingField/RatingField.svelte +26 -0
  18. package/dist/_work_in_progress/component/RatingField/RatingField.svelte.d.ts +11 -0
  19. package/dist/_work_in_progress/component/RatingField/index.d.ts +2 -0
  20. package/dist/_work_in_progress/component/RatingField/index.js +1 -0
  21. package/dist/_work_in_progress/component/RatingField/types.d.ts +7 -0
  22. package/dist/_work_in_progress/component/RatingField/types.js +1 -0
  23. package/dist/_work_in_progress/index.d.ts +6 -0
  24. package/dist/_work_in_progress/index.js +7 -0
  25. package/dist/_work_in_progress/subcomponent/ColorInput/ColorInput.svelte +111 -0
  26. package/dist/_work_in_progress/subcomponent/ColorInput/ColorInput.svelte.d.ts +13 -0
  27. package/dist/_work_in_progress/subcomponent/ColorInput/constants.d.ts +5 -0
  28. package/dist/_work_in_progress/subcomponent/ColorInput/constants.js +23 -0
  29. package/dist/_work_in_progress/subcomponent/ColorInput/index.d.ts +2 -0
  30. package/dist/_work_in_progress/subcomponent/ColorInput/index.js +1 -0
  31. package/dist/_work_in_progress/subcomponent/ColorInput/styles.css +204 -0
  32. package/dist/_work_in_progress/subcomponent/ColorInput/types.d.ts +24 -0
  33. package/dist/_work_in_progress/subcomponent/ColorInput/types.js +1 -0
  34. package/dist/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.svelte +29 -0
  35. package/dist/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.svelte.d.ts +15 -0
  36. package/dist/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.svelte +254 -0
  37. package/dist/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.svelte.d.ts +23 -0
  38. package/dist/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.svelte +157 -0
  39. package/dist/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.svelte.d.ts +19 -0
  40. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/List.svelte +54 -0
  41. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/List.svelte.d.ts +9 -0
  42. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/index.d.ts +2 -0
  43. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/index.js +1 -0
  44. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/styles.css +41 -0
  45. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/types.d.ts +40 -0
  46. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/List/types.js +1 -0
  47. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.svelte +23 -0
  48. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.svelte.d.ts +9 -0
  49. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.d.ts +2 -0
  50. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.js +1 -0
  51. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/styles.css +28 -0
  52. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.d.ts +19 -0
  53. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.js +1 -0
  54. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/index.d.ts +2 -0
  55. package/dist/_work_in_progress/subcomponent/ComboboxInput/common/index.js +2 -0
  56. package/dist/_work_in_progress/subcomponent/ComboboxInput/constants.d.ts +2 -0
  57. package/dist/_work_in_progress/subcomponent/ComboboxInput/constants.js +2 -0
  58. package/dist/_work_in_progress/subcomponent/ComboboxInput/createCombobox.svelte.d.ts +148 -0
  59. package/dist/_work_in_progress/subcomponent/ComboboxInput/createCombobox.svelte.js +414 -0
  60. package/dist/_work_in_progress/subcomponent/ComboboxInput/createMultipleSelection.svelte.d.ts +48 -0
  61. package/dist/_work_in_progress/subcomponent/ComboboxInput/createMultipleSelection.svelte.js +147 -0
  62. package/dist/_work_in_progress/subcomponent/ComboboxInput/index.d.ts +2 -0
  63. package/dist/_work_in_progress/subcomponent/ComboboxInput/index.js +1 -0
  64. package/dist/_work_in_progress/subcomponent/ComboboxInput/messages.d.ts +5 -0
  65. package/dist/_work_in_progress/subcomponent/ComboboxInput/messages.js +4 -0
  66. package/dist/_work_in_progress/subcomponent/ComboboxInput/styles.css +73 -0
  67. package/dist/_work_in_progress/subcomponent/ComboboxInput/types.d.ts +55 -0
  68. package/dist/_work_in_progress/subcomponent/ComboboxInput/types.js +1 -0
  69. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.d.ts +3 -0
  70. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.js +4 -0
  71. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.d.ts +3 -0
  72. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.js +5 -0
  73. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.d.ts +3 -0
  74. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.js +5 -0
  75. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/getHighlightedIndex.d.ts +11 -0
  76. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/getHighlightedIndex.js +22 -0
  77. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/index.d.ts +6 -0
  78. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/index.js +6 -0
  79. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.d.ts +2 -0
  80. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.js +4 -0
  81. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.d.ts +7 -0
  82. package/dist/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.js +9 -0
  83. package/dist/_work_in_progress/subcomponent/RatingInput/RatingInput.svelte +76 -0
  84. package/dist/_work_in_progress/subcomponent/RatingInput/RatingInput.svelte.d.ts +13 -0
  85. package/dist/_work_in_progress/subcomponent/RatingInput/index.d.ts +2 -0
  86. package/dist/_work_in_progress/subcomponent/RatingInput/index.js +1 -0
  87. package/dist/_work_in_progress/subcomponent/RatingInput/styles.css +163 -0
  88. package/dist/_work_in_progress/subcomponent/RatingInput/types.d.ts +30 -0
  89. package/dist/_work_in_progress/subcomponent/RatingInput/types.js +1 -0
  90. package/dist/common/Adornment/Adornment.svelte +11 -0
  91. package/dist/common/Adornment/Adornment.svelte.d.ts +8 -0
  92. package/dist/common/Wrapper/ToggleWrapper.css +77 -0
  93. package/dist/common/Wrapper/ToggleWrapper.svelte +75 -0
  94. package/dist/common/Wrapper/ToggleWrapper.svelte.d.ts +11 -0
  95. package/dist/common/Wrapper/Wrapper.svelte +72 -0
  96. package/dist/common/Wrapper/Wrapper.svelte.d.ts +12 -0
  97. package/dist/common/Wrapper/createControlProps.d.ts +9 -0
  98. package/dist/common/Wrapper/createControlProps.js +21 -0
  99. package/dist/common/Wrapper/index.d.ts +3 -0
  100. package/dist/common/Wrapper/index.js +3 -0
  101. package/dist/common/Wrapper/styles.css +41 -0
  102. package/dist/common/constants.d.ts +6 -0
  103. package/dist/common/constants.js +6 -0
  104. package/dist/common/index.d.ts +3 -0
  105. package/dist/common/index.js +3 -0
  106. package/dist/common/splitChromeProps.d.ts +17 -0
  107. package/dist/common/splitChromeProps.js +38 -0
  108. package/dist/common/types.d.ts +99 -0
  109. package/dist/common/types.js +1 -0
  110. package/dist/common/useConditionalDisplay.svelte.d.ts +13 -0
  111. package/dist/common/useConditionalDisplay.svelte.js +32 -0
  112. package/dist/common/useNativeValidity.svelte.d.ts +18 -0
  113. package/dist/common/useNativeValidity.svelte.js +66 -0
  114. package/dist/component/CheckboxField/CheckboxField.svelte +20 -0
  115. package/dist/component/CheckboxField/CheckboxField.svelte.d.ts +11 -0
  116. package/dist/component/CheckboxField/index.d.ts +2 -0
  117. package/dist/component/CheckboxField/index.js +1 -0
  118. package/dist/component/CheckboxField/types.d.ts +10 -0
  119. package/dist/component/CheckboxField/types.js +1 -0
  120. package/dist/component/ChoicesField/Choices.svelte +61 -0
  121. package/dist/component/ChoicesField/Choices.svelte.d.ts +9 -0
  122. package/dist/component/ChoicesField/ChoicesField.svelte +23 -0
  123. package/dist/component/ChoicesField/ChoicesField.svelte.d.ts +13 -0
  124. package/dist/component/ChoicesField/common/Option/Option.svelte +33 -0
  125. package/dist/component/ChoicesField/common/Option/Option.svelte.d.ts +8 -0
  126. package/dist/component/ChoicesField/common/Option/index.d.ts +2 -0
  127. package/dist/component/ChoicesField/common/Option/index.js +1 -0
  128. package/dist/component/ChoicesField/common/Option/types.d.ts +13 -0
  129. package/dist/component/ChoicesField/common/Option/types.js +1 -0
  130. package/dist/component/ChoicesField/common/index.d.ts +1 -0
  131. package/dist/component/ChoicesField/common/index.js +1 -0
  132. package/dist/component/ChoicesField/index.d.ts +3 -0
  133. package/dist/component/ChoicesField/index.js +2 -0
  134. package/dist/component/ChoicesField/isChoiceChecked.d.ts +5 -0
  135. package/dist/component/ChoicesField/isChoiceChecked.js +9 -0
  136. package/dist/component/ChoicesField/styles.css +162 -0
  137. package/dist/component/ChoicesField/toggleChoice.d.ts +7 -0
  138. package/dist/component/ChoicesField/toggleChoice.js +13 -0
  139. package/dist/component/ChoicesField/types.d.ts +37 -0
  140. package/dist/component/ChoicesField/types.js +1 -0
  141. package/dist/component/DateField/DateField.svelte +20 -0
  142. package/dist/component/DateField/DateField.svelte.d.ts +11 -0
  143. package/dist/component/DateField/index.d.ts +2 -0
  144. package/dist/component/DateField/index.js +1 -0
  145. package/dist/component/DateField/types.d.ts +7 -0
  146. package/dist/component/DateField/types.js +1 -0
  147. package/dist/component/DateTimeField/DateTimeField.svelte +21 -0
  148. package/dist/component/DateTimeField/DateTimeField.svelte.d.ts +11 -0
  149. package/dist/component/DateTimeField/index.d.ts +2 -0
  150. package/dist/component/DateTimeField/index.js +1 -0
  151. package/dist/component/DateTimeField/types.d.ts +7 -0
  152. package/dist/component/DateTimeField/types.js +1 -0
  153. package/dist/component/FileUploadField/FileUploadField.svelte +92 -0
  154. package/dist/component/FileUploadField/FileUploadField.svelte.d.ts +20 -0
  155. package/dist/component/FileUploadField/findFileUploadError.d.ts +21 -0
  156. package/dist/component/FileUploadField/findFileUploadError.js +28 -0
  157. package/dist/component/FileUploadField/index.d.ts +2 -0
  158. package/dist/component/FileUploadField/index.js +1 -0
  159. package/dist/component/FileUploadField/styles.css +30 -0
  160. package/dist/component/FileUploadField/types.d.ts +9 -0
  161. package/dist/component/FileUploadField/types.js +1 -0
  162. package/dist/component/HiddenField/HiddenField.svelte +31 -0
  163. package/dist/component/HiddenField/HiddenField.svelte.d.ts +12 -0
  164. package/dist/component/HiddenField/index.d.ts +2 -0
  165. package/dist/component/HiddenField/index.js +1 -0
  166. package/dist/component/HiddenField/types.d.ts +13 -0
  167. package/dist/component/HiddenField/types.js +1 -0
  168. package/dist/component/NumberField/NumberField.svelte +20 -0
  169. package/dist/component/NumberField/NumberField.svelte.d.ts +11 -0
  170. package/dist/component/NumberField/index.d.ts +2 -0
  171. package/dist/component/NumberField/index.js +1 -0
  172. package/dist/component/NumberField/types.d.ts +7 -0
  173. package/dist/component/NumberField/types.js +1 -0
  174. package/dist/component/PasswordField/PasswordField.svelte +20 -0
  175. package/dist/component/PasswordField/PasswordField.svelte.d.ts +11 -0
  176. package/dist/component/PasswordField/index.d.ts +2 -0
  177. package/dist/component/PasswordField/index.js +1 -0
  178. package/dist/component/PasswordField/types.d.ts +7 -0
  179. package/dist/component/PasswordField/types.js +1 -0
  180. package/dist/component/PhoneField/PhoneField.svelte +23 -0
  181. package/dist/component/PhoneField/PhoneField.svelte.d.ts +14 -0
  182. package/dist/component/PhoneField/index.d.ts +2 -0
  183. package/dist/component/PhoneField/index.js +1 -0
  184. package/dist/component/PhoneField/types.d.ts +7 -0
  185. package/dist/component/PhoneField/types.js +1 -0
  186. package/dist/component/RangeField/RangeField.svelte +21 -0
  187. package/dist/component/RangeField/RangeField.svelte.d.ts +12 -0
  188. package/dist/component/RangeField/common/RangeControl/RangeControl.svelte +54 -0
  189. package/dist/component/RangeField/common/RangeControl/RangeControl.svelte.d.ts +9 -0
  190. package/dist/component/RangeField/common/RangeControl/clampToSlider.d.ts +7 -0
  191. package/dist/component/RangeField/common/RangeControl/clampToSlider.js +11 -0
  192. package/dist/component/RangeField/common/RangeControl/index.d.ts +2 -0
  193. package/dist/component/RangeField/common/RangeControl/index.js +1 -0
  194. package/dist/component/RangeField/common/RangeControl/styles.css +46 -0
  195. package/dist/component/RangeField/common/RangeControl/types.d.ts +16 -0
  196. package/dist/component/RangeField/common/RangeControl/types.js +1 -0
  197. package/dist/component/RangeField/common/index.d.ts +1 -0
  198. package/dist/component/RangeField/common/index.js +1 -0
  199. package/dist/component/RangeField/index.d.ts +2 -0
  200. package/dist/component/RangeField/index.js +1 -0
  201. package/dist/component/RangeField/types.d.ts +7 -0
  202. package/dist/component/RangeField/types.js +1 -0
  203. package/dist/component/RichChoicesField/RichChoices.svelte +52 -0
  204. package/dist/component/RichChoicesField/RichChoices.svelte.d.ts +10 -0
  205. package/dist/component/RichChoicesField/RichChoicesField.svelte +23 -0
  206. package/dist/component/RichChoicesField/RichChoicesField.svelte.d.ts +13 -0
  207. package/dist/component/RichChoicesField/common/Option/Option.svelte +38 -0
  208. package/dist/component/RichChoicesField/common/Option/Option.svelte.d.ts +8 -0
  209. package/dist/component/RichChoicesField/common/Option/index.d.ts +2 -0
  210. package/dist/component/RichChoicesField/common/Option/index.js +1 -0
  211. package/dist/component/RichChoicesField/common/Option/types.d.ts +13 -0
  212. package/dist/component/RichChoicesField/common/Option/types.js +1 -0
  213. package/dist/component/RichChoicesField/common/index.d.ts +1 -0
  214. package/dist/component/RichChoicesField/common/index.js +1 -0
  215. package/dist/component/RichChoicesField/index.d.ts +3 -0
  216. package/dist/component/RichChoicesField/index.js +2 -0
  217. package/dist/component/RichChoicesField/styles.css +103 -0
  218. package/dist/component/RichChoicesField/types.d.ts +37 -0
  219. package/dist/component/RichChoicesField/types.js +1 -0
  220. package/dist/component/SelectField/SelectField.svelte +20 -0
  221. package/dist/component/SelectField/SelectField.svelte.d.ts +11 -0
  222. package/dist/component/SelectField/index.d.ts +2 -0
  223. package/dist/component/SelectField/index.js +1 -0
  224. package/dist/component/SelectField/types.d.ts +7 -0
  225. package/dist/component/SelectField/types.js +1 -0
  226. package/dist/component/SwitchField/SwitchField.svelte +23 -0
  227. package/dist/component/SwitchField/SwitchField.svelte.d.ts +13 -0
  228. package/dist/component/SwitchField/index.d.ts +2 -0
  229. package/dist/component/SwitchField/index.js +1 -0
  230. package/dist/component/SwitchField/types.d.ts +10 -0
  231. package/dist/component/SwitchField/types.js +1 -0
  232. package/dist/component/TextField/TextField.svelte +20 -0
  233. package/dist/component/TextField/TextField.svelte.d.ts +11 -0
  234. package/dist/component/TextField/index.d.ts +2 -0
  235. package/dist/component/TextField/index.js +1 -0
  236. package/dist/component/TextField/types.d.ts +7 -0
  237. package/dist/component/TextField/types.js +1 -0
  238. package/dist/component/TextareaField/TextareaField.svelte +20 -0
  239. package/dist/component/TextareaField/TextareaField.svelte.d.ts +11 -0
  240. package/dist/component/TextareaField/index.d.ts +2 -0
  241. package/dist/component/TextareaField/index.js +1 -0
  242. package/dist/component/TextareaField/types.d.ts +7 -0
  243. package/dist/component/TextareaField/types.js +1 -0
  244. package/dist/component/TimeField/TimeField.svelte +20 -0
  245. package/dist/component/TimeField/TimeField.svelte.d.ts +11 -0
  246. package/dist/component/TimeField/index.d.ts +2 -0
  247. package/dist/component/TimeField/index.js +1 -0
  248. package/dist/component/TimeField/types.d.ts +7 -0
  249. package/dist/component/TimeField/types.js +1 -0
  250. package/dist/component/index.d.ts +16 -0
  251. package/dist/component/index.js +18 -0
  252. package/dist/density.css +367 -0
  253. package/dist/index.css +409 -0
  254. package/dist/index.d.ts +17 -0
  255. package/dist/index.js +5 -0
  256. package/dist/pattern/Field/Field.svelte +95 -0
  257. package/dist/pattern/Field/Field.svelte.d.ts +35 -0
  258. package/dist/pattern/Field/index.d.ts +2 -0
  259. package/dist/pattern/Field/index.js +1 -0
  260. package/dist/pattern/Field/types.d.ts +90 -0
  261. package/dist/pattern/Field/types.js +1 -0
  262. package/dist/pattern/Form/Form.svelte +49 -0
  263. package/dist/pattern/Form/Form.svelte.d.ts +40 -0
  264. package/dist/pattern/Form/index.d.ts +2 -0
  265. package/dist/pattern/Form/index.js +1 -0
  266. package/dist/pattern/Form/types.d.ts +18 -0
  267. package/dist/pattern/Form/types.js +1 -0
  268. package/dist/pattern/index.d.ts +2 -0
  269. package/dist/pattern/index.js +2 -0
  270. package/dist/subcomponent/CheckboxInput/CheckboxInput.svelte +24 -0
  271. package/dist/subcomponent/CheckboxInput/CheckboxInput.svelte.d.ts +12 -0
  272. package/dist/subcomponent/CheckboxInput/index.d.ts +2 -0
  273. package/dist/subcomponent/CheckboxInput/index.js +1 -0
  274. package/dist/subcomponent/CheckboxInput/styles.css +135 -0
  275. package/dist/subcomponent/CheckboxInput/types.d.ts +6 -0
  276. package/dist/subcomponent/CheckboxInput/types.js +1 -0
  277. package/dist/subcomponent/DateInput/DateInput.svelte +28 -0
  278. package/dist/subcomponent/DateInput/DateInput.svelte.d.ts +14 -0
  279. package/dist/subcomponent/DateInput/index.d.ts +2 -0
  280. package/dist/subcomponent/DateInput/index.js +1 -0
  281. package/dist/subcomponent/DateInput/styles.css +47 -0
  282. package/dist/subcomponent/DateInput/types.d.ts +10 -0
  283. package/dist/subcomponent/DateInput/types.js +1 -0
  284. package/dist/subcomponent/DateTimeInput/DateTimeInput.svelte +29 -0
  285. package/dist/subcomponent/DateTimeInput/DateTimeInput.svelte.d.ts +14 -0
  286. package/dist/subcomponent/DateTimeInput/index.d.ts +2 -0
  287. package/dist/subcomponent/DateTimeInput/index.js +1 -0
  288. package/dist/subcomponent/DateTimeInput/styles.css +49 -0
  289. package/dist/subcomponent/DateTimeInput/types.d.ts +12 -0
  290. package/dist/subcomponent/DateTimeInput/types.js +1 -0
  291. package/dist/subcomponent/Field/Description/Description.svelte +17 -0
  292. package/dist/subcomponent/Field/Description/Description.svelte.d.ts +11 -0
  293. package/dist/subcomponent/Field/Description/index.d.ts +2 -0
  294. package/dist/subcomponent/Field/Description/index.js +1 -0
  295. package/dist/subcomponent/Field/Description/styles.css +14 -0
  296. package/dist/subcomponent/Field/Description/types.d.ts +12 -0
  297. package/dist/subcomponent/Field/Description/types.js +1 -0
  298. package/dist/subcomponent/Field/Error/Error.svelte +16 -0
  299. package/dist/subcomponent/Field/Error/Error.svelte.d.ts +10 -0
  300. package/dist/subcomponent/Field/Error/index.d.ts +2 -0
  301. package/dist/subcomponent/Field/Error/index.js +1 -0
  302. package/dist/subcomponent/Field/Error/styles.css +18 -0
  303. package/dist/subcomponent/Field/Error/types.d.ts +12 -0
  304. package/dist/subcomponent/Field/Error/types.js +1 -0
  305. package/dist/subcomponent/Field/Label/Label.svelte +52 -0
  306. package/dist/subcomponent/Field/Label/Label.svelte.d.ts +11 -0
  307. package/dist/subcomponent/Field/Label/index.d.ts +2 -0
  308. package/dist/subcomponent/Field/Label/index.js +1 -0
  309. package/dist/subcomponent/Field/Label/styles.css +30 -0
  310. package/dist/subcomponent/Field/Label/types.d.ts +37 -0
  311. package/dist/subcomponent/Field/Label/types.js +1 -0
  312. package/dist/subcomponent/Field/index.d.ts +3 -0
  313. package/dist/subcomponent/Field/index.js +3 -0
  314. package/dist/subcomponent/FileUploadInput/FileUploadInput.svelte +189 -0
  315. package/dist/subcomponent/FileUploadInput/FileUploadInput.svelte.d.ts +34 -0
  316. package/dist/subcomponent/FileUploadInput/common/FileItem/FileItem.svelte +76 -0
  317. package/dist/subcomponent/FileUploadInput/common/FileItem/FileItem.svelte.d.ts +13 -0
  318. package/dist/subcomponent/FileUploadInput/common/FileItem/index.d.ts +2 -0
  319. package/dist/subcomponent/FileUploadInput/common/FileItem/index.js +1 -0
  320. package/dist/subcomponent/FileUploadInput/common/FileItem/types.d.ts +27 -0
  321. package/dist/subcomponent/FileUploadInput/common/FileItem/types.js +1 -0
  322. package/dist/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.svelte +12 -0
  323. package/dist/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.svelte.d.ts +8 -0
  324. package/dist/subcomponent/FileUploadInput/common/Thumbnail/index.d.ts +2 -0
  325. package/dist/subcomponent/FileUploadInput/common/Thumbnail/index.js +1 -0
  326. package/dist/subcomponent/FileUploadInput/common/Thumbnail/types.d.ts +7 -0
  327. package/dist/subcomponent/FileUploadInput/common/Thumbnail/types.js +1 -0
  328. package/dist/subcomponent/FileUploadInput/constants.d.ts +2 -0
  329. package/dist/subcomponent/FileUploadInput/constants.js +2 -0
  330. package/dist/subcomponent/FileUploadInput/hooks/index.d.ts +2 -0
  331. package/dist/subcomponent/FileUploadInput/hooks/index.js +2 -0
  332. package/dist/subcomponent/FileUploadInput/hooks/useFileUploads.svelte.d.ts +38 -0
  333. package/dist/subcomponent/FileUploadInput/hooks/useFileUploads.svelte.js +139 -0
  334. package/dist/subcomponent/FileUploadInput/hooks/useObjectUrl.svelte.d.ts +11 -0
  335. package/dist/subcomponent/FileUploadInput/hooks/useObjectUrl.svelte.js +27 -0
  336. package/dist/subcomponent/FileUploadInput/index.d.ts +2 -0
  337. package/dist/subcomponent/FileUploadInput/index.js +1 -0
  338. package/dist/subcomponent/FileUploadInput/messages.d.ts +3 -0
  339. package/dist/subcomponent/FileUploadInput/messages.js +24 -0
  340. package/dist/subcomponent/FileUploadInput/styles.css +305 -0
  341. package/dist/subcomponent/FileUploadInput/types.d.ts +175 -0
  342. package/dist/subcomponent/FileUploadInput/types.js +1 -0
  343. package/dist/subcomponent/FileUploadInput/utils/formatFileSize.d.ts +6 -0
  344. package/dist/subcomponent/FileUploadInput/utils/formatFileSize.js +20 -0
  345. package/dist/subcomponent/FileUploadInput/utils/getFileMessage.d.ts +13 -0
  346. package/dist/subcomponent/FileUploadInput/utils/getFileMessage.js +19 -0
  347. package/dist/subcomponent/FileUploadInput/utils/index.d.ts +4 -0
  348. package/dist/subcomponent/FileUploadInput/utils/index.js +3 -0
  349. package/dist/subcomponent/FileUploadInput/utils/matchesAccept.d.ts +9 -0
  350. package/dist/subcomponent/FileUploadInput/utils/matchesAccept.js +25 -0
  351. package/dist/subcomponent/HiddenInput/HiddenInput.svelte +23 -0
  352. package/dist/subcomponent/HiddenInput/HiddenInput.svelte.d.ts +11 -0
  353. package/dist/subcomponent/HiddenInput/index.d.ts +2 -0
  354. package/dist/subcomponent/HiddenInput/index.js +1 -0
  355. package/dist/subcomponent/HiddenInput/types.d.ts +6 -0
  356. package/dist/subcomponent/HiddenInput/types.js +1 -0
  357. package/dist/subcomponent/NumberInput/NumberInput.svelte +29 -0
  358. package/dist/subcomponent/NumberInput/NumberInput.svelte.d.ts +13 -0
  359. package/dist/subcomponent/NumberInput/index.d.ts +2 -0
  360. package/dist/subcomponent/NumberInput/index.js +1 -0
  361. package/dist/subcomponent/NumberInput/styles.css +54 -0
  362. package/dist/subcomponent/NumberInput/types.d.ts +11 -0
  363. package/dist/subcomponent/NumberInput/types.js +1 -0
  364. package/dist/subcomponent/PasswordInput/PasswordInput.svelte +49 -0
  365. package/dist/subcomponent/PasswordInput/PasswordInput.svelte.d.ts +13 -0
  366. package/dist/subcomponent/PasswordInput/index.d.ts +2 -0
  367. package/dist/subcomponent/PasswordInput/index.js +1 -0
  368. package/dist/subcomponent/PasswordInput/styles.css +76 -0
  369. package/dist/subcomponent/PasswordInput/types.d.ts +12 -0
  370. package/dist/subcomponent/PasswordInput/types.js +1 -0
  371. package/dist/subcomponent/PhoneInput/PhoneInput.svelte +214 -0
  372. package/dist/subcomponent/PhoneInput/PhoneInput.svelte.d.ts +21 -0
  373. package/dist/subcomponent/PhoneInput/index.d.ts +2 -0
  374. package/dist/subcomponent/PhoneInput/index.js +1 -0
  375. package/dist/subcomponent/PhoneInput/styles.css +62 -0
  376. package/dist/subcomponent/PhoneInput/types.d.ts +50 -0
  377. package/dist/subcomponent/PhoneInput/types.js +1 -0
  378. package/dist/subcomponent/RadioInput/RadioInput.svelte +56 -0
  379. package/dist/subcomponent/RadioInput/RadioInput.svelte.d.ts +13 -0
  380. package/dist/subcomponent/RadioInput/index.d.ts +2 -0
  381. package/dist/subcomponent/RadioInput/index.js +1 -0
  382. package/dist/subcomponent/RadioInput/styles.css +81 -0
  383. package/dist/subcomponent/RadioInput/types.d.ts +6 -0
  384. package/dist/subcomponent/RadioInput/types.js +1 -0
  385. package/dist/subcomponent/RangeInput/RangeInput.svelte +38 -0
  386. package/dist/subcomponent/RangeInput/RangeInput.svelte.d.ts +13 -0
  387. package/dist/subcomponent/RangeInput/index.d.ts +2 -0
  388. package/dist/subcomponent/RangeInput/index.js +1 -0
  389. package/dist/subcomponent/RangeInput/styles.css +97 -0
  390. package/dist/subcomponent/RangeInput/types.d.ts +10 -0
  391. package/dist/subcomponent/RangeInput/types.js +1 -0
  392. package/dist/subcomponent/SelectInput/SelectInput.svelte +59 -0
  393. package/dist/subcomponent/SelectInput/SelectInput.svelte.d.ts +13 -0
  394. package/dist/subcomponent/SelectInput/index.d.ts +2 -0
  395. package/dist/subcomponent/SelectInput/index.js +1 -0
  396. package/dist/subcomponent/SelectInput/styles.css +56 -0
  397. package/dist/subcomponent/SelectInput/types.d.ts +10 -0
  398. package/dist/subcomponent/SelectInput/types.js +1 -0
  399. package/dist/subcomponent/SwitchInput/SwitchInput.svelte +26 -0
  400. package/dist/subcomponent/SwitchInput/SwitchInput.svelte.d.ts +13 -0
  401. package/dist/subcomponent/SwitchInput/index.d.ts +2 -0
  402. package/dist/subcomponent/SwitchInput/index.js +1 -0
  403. package/dist/subcomponent/SwitchInput/styles.css +109 -0
  404. package/dist/subcomponent/SwitchInput/types.d.ts +9 -0
  405. package/dist/subcomponent/SwitchInput/types.js +1 -0
  406. package/dist/subcomponent/TextInput/TextInput.svelte +30 -0
  407. package/dist/subcomponent/TextInput/TextInput.svelte.d.ts +14 -0
  408. package/dist/subcomponent/TextInput/index.d.ts +2 -0
  409. package/dist/subcomponent/TextInput/index.js +1 -0
  410. package/dist/subcomponent/TextInput/styles.css +34 -0
  411. package/dist/subcomponent/TextInput/types.d.ts +15 -0
  412. package/dist/subcomponent/TextInput/types.js +1 -0
  413. package/dist/subcomponent/TextareaInput/TextareaInput.svelte +24 -0
  414. package/dist/subcomponent/TextareaInput/TextareaInput.svelte.d.ts +12 -0
  415. package/dist/subcomponent/TextareaInput/index.d.ts +2 -0
  416. package/dist/subcomponent/TextareaInput/index.js +1 -0
  417. package/dist/subcomponent/TextareaInput/styles.css +16 -0
  418. package/dist/subcomponent/TextareaInput/types.d.ts +6 -0
  419. package/dist/subcomponent/TextareaInput/types.js +1 -0
  420. package/dist/subcomponent/TimeInput/TimeInput.svelte +29 -0
  421. package/dist/subcomponent/TimeInput/TimeInput.svelte.d.ts +14 -0
  422. package/dist/subcomponent/TimeInput/index.d.ts +2 -0
  423. package/dist/subcomponent/TimeInput/index.js +1 -0
  424. package/dist/subcomponent/TimeInput/styles.css +27 -0
  425. package/dist/subcomponent/TimeInput/types.d.ts +12 -0
  426. package/dist/subcomponent/TimeInput/types.js +1 -0
  427. package/dist/subcomponent/index.d.ts +17 -0
  428. package/dist/subcomponent/index.js +19 -0
  429. package/dist/subcomponent/types.d.ts +30 -0
  430. package/dist/subcomponent/types.js +1 -0
  431. package/dist/utils/index.d.ts +5 -0
  432. package/dist/utils/index.js +5 -0
  433. package/dist/utils/middleware/createRemoteOptions.svelte.d.ts +30 -0
  434. package/dist/utils/middleware/createRemoteOptions.svelte.js +83 -0
  435. package/dist/utils/middleware/fetchOptions.d.ts +20 -0
  436. package/dist/utils/middleware/fetchOptions.js +25 -0
  437. package/dist/utils/middleware/index.d.ts +4 -0
  438. package/dist/utils/middleware/index.js +3 -0
  439. package/dist/utils/middleware/types.d.ts +69 -0
  440. package/dist/utils/middleware/types.js +1 -0
  441. package/dist/utils/middleware/validateRemotely.d.ts +34 -0
  442. package/dist/utils/middleware/validateRemotely.js +263 -0
  443. package/dist/utils/owner/bindField.d.ts +16 -0
  444. package/dist/utils/owner/bindField.js +22 -0
  445. package/dist/utils/owner/createBinding.d.ts +8 -0
  446. package/dist/utils/owner/createBinding.js +23 -0
  447. package/dist/utils/owner/createFormState.svelte.d.ts +17 -0
  448. package/dist/utils/owner/createFormState.svelte.js +101 -0
  449. package/dist/utils/owner/createValidatedBinding.d.ts +15 -0
  450. package/dist/utils/owner/createValidatedBinding.js +70 -0
  451. package/dist/utils/owner/formOwnerContext.d.ts +15 -0
  452. package/dist/utils/owner/formOwnerContext.js +17 -0
  453. package/dist/utils/owner/index.d.ts +7 -0
  454. package/dist/utils/owner/index.js +6 -0
  455. package/dist/utils/owner/runLatest.d.ts +13 -0
  456. package/dist/utils/owner/runLatest.js +31 -0
  457. package/dist/utils/owner/types.d.ts +107 -0
  458. package/dist/utils/owner/types.js +1 -0
  459. package/dist/utils/phone/index.d.ts +1 -0
  460. package/dist/utils/phone/index.js +1 -0
  461. package/dist/utils/phone/phone.d.ts +30 -0
  462. package/dist/utils/phone/phone.js +121 -0
  463. package/dist/utils/readEditedChoices.d.ts +11 -0
  464. package/dist/utils/readEditedChoices.js +17 -0
  465. package/dist/utils/readEditedSelection.d.ts +9 -0
  466. package/dist/utils/readEditedSelection.js +16 -0
  467. package/package.json +99 -4
package/README.md CHANGED
@@ -1,3 +1,261 @@
1
- # Temporary Holding Version
1
+ # @canonical/svelte-ds-global-form
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Svelte 5 form fields for the Pragma design system. The markup, class names and
4
+ stylesheets are the same as `@canonical/react-ds-global-form`; the API is
5
+ Svelte's: every value is `$bindable`, and native attributes, handlers and
6
+ attachments are spread onto the real control.
7
+
8
+ ```svelte
9
+ <script lang="ts">
10
+ import "@canonical/styles";
11
+ import "@canonical/svelte-ds-global-form/index.css";
12
+ import { Field, Form } from "@canonical/svelte-ds-global-form";
13
+
14
+ let { form } = $props(); // for example a SvelteKit action result
15
+ let email = $state("");
16
+ let newsletter = $state(false);
17
+ </script>
18
+
19
+ <Form method="POST">
20
+ <Field inputType="email" name="email" label="Email" bind:value={email} error={form?.errors?.email} />
21
+ <Field inputType="checkbox" name="newsletter" label="Send me news" isOptional bind:value={newsletter} />
22
+ <Field
23
+ inputType="text"
24
+ name="company"
25
+ label="Company"
26
+ isOptional
27
+ condition={() => email.endsWith("@example.com")}
28
+ />
29
+ <button type="submit">Send</button>
30
+ </Form>
31
+ ```
32
+
33
+ ## Styles
34
+
35
+ Import the global Pragma styles once, then either every form stylesheet:
36
+
37
+ ```css
38
+ @import url("@canonical/styles");
39
+ @import url("@canonical/svelte-ds-global-form/index.css");
40
+ ```
41
+
42
+ or nothing more: each component imports its own stylesheet, so a bundler that
43
+ handles CSS imports (Vite, SvelteKit) loads only the styles of the components
44
+ you use. The package marks `**/*.css` as side effects so they are not
45
+ tree-shaken.
46
+
47
+ ## Fields
48
+
49
+ - `Field` routes on `inputType` (`text`, `email`, `tel`, `url`, `password`,
50
+ `number`, `textarea`, `select`, `checkbox`, `switch`, `choices`,
51
+ `rich-choices`, `range`, `date`, `time`, `datetime`, `file`, `phone`,
52
+ `hidden`, `custom`, and the work-in-progress `color`, `rating`, `combobox`).
53
+ - `value` is bindable and its type follows `inputType`: a string for text-like
54
+ inputs, a number (or `null` while empty) for `number` and `range`, a boolean
55
+ for `checkbox` and `switch`, a `string[]` for multiple `select` and
56
+ `choices`, `File[]` for `file`. An unbound value is local state, so a plain
57
+ HTML form works unchanged and server rendering shows the value.
58
+ - Fields are required unless `isOptional`. Pass a validation message with
59
+ `error`.
60
+ - `condition: (values) => boolean` decides whether a field is shown. Inside a
61
+ `Form` with an owner it receives the owner's values; otherwise it closes over
62
+ your own state (it receives `{}`). A hidden field is not rendered, so it is
63
+ not submitted; when a shown field becomes hidden, its value becomes
64
+ `undefined` (in the owner, or in your binding), as in React.
65
+ - `inputType: "custom"` renders `component` with no field chrome, as React's
66
+ `CustomComponent`: it receives every prop but `inputType` and `component`
67
+ (`CustomControlProps<Value>` plus any extra props), binds `value`, and
68
+ renders its own label, description and error.
69
+ - `Form` renders `form.ds.form.subgrid` and passes native attributes through.
70
+ Use SvelteKit's `enhance` as an attachment:
71
+ `<Form {@attach fromAction(enhance)}>` (`fromAction` from `svelte/attachments`).
72
+
73
+ ## Form owners
74
+
75
+ Without an `owner`, `Form` is native: fields hold their own values and the
76
+ browser posts them, so it works with SvelteKit actions and without JavaScript.
77
+ Give `Form` an `owner` and every `Field` inside reads and writes its value,
78
+ error and blur through it by `name`, and the owner sees each submit first. An
79
+ explicit `bind:value` (when defined) or `error` on a field wins. A field shows
80
+ every error the owner returns; when errors appear is the owner's business.
81
+
82
+ `createFormState()` is the package's owner, opted into per form. It holds
83
+ values, errors and touched fields in `$state`, with react-hook-form's options:
84
+
85
+ ```svelte
86
+ <Form
87
+ owner={createFormState({
88
+ defaultValues: { email: "" },
89
+ validate: (values) => ({ email: values.email ? undefined : "Email is required" }),
90
+ mode: "onSubmit", // or "onChange", "onBlur", "onTouched"
91
+ onSubmit: (values) => save(values), // unset: a valid form posts natively
92
+ })}
93
+ >
94
+ ```
95
+
96
+ Every mode validates on submit, and after the first submit a field again on
97
+ its every change. An invalid submit does not post and focuses the first
98
+ invalid control. The browser's own validation runs first; add `novalidate` to
99
+ show the owner's message for a missing required value. The owner also exposes
100
+ `errors`, `touched`, `isSubmitted`, `isSubmitting` and `reset()`.
101
+
102
+ The owner sees each submit before the form's other listeners, and a submit it
103
+ stops reaches `onsubmit` but none of them, so `<Form method="POST" owner={…}
104
+ {@attach fromAction(enhance)}>` posts only a valid form.
105
+
106
+ Any object meeting the contract is an owner:
107
+
108
+ ```ts
109
+ type FormOwner<Values> = {
110
+ readonly values: Values; // must be reactive under runes, as `$state` is
111
+ setValue(name, value): void; // `undefined` drops the value
112
+ getError?(name): string | undefined;
113
+ blur?(name): void;
114
+ submit?(event: SubmitEvent): void; // may call event.preventDefault()
115
+ };
116
+ ```
117
+
118
+ - `createBinding(source)` adapts a store that is not reactive under runes, such
119
+ as TanStack Form (`getValues`, `setValue`, `subscribe`, plus the optional
120
+ methods above), into an owner.
121
+ - `createValidatedBinding(owner, checks)` adds latest-only asynchronous checks
122
+ per field to an owner that can `reset`. A field keeps its previous message
123
+ while its check runs and when the check fails; a submit is stopped while a
124
+ check's message shows; `validate()` waits for every check.
125
+ - `runLatest(work)` runs asynchronous work so only its latest run counts.
126
+ - Outside a `Form` with an owner, bind a field yourself:
127
+ `bind:value={() => owner.values.email, (v) => owner.setValue("email", v)}`
128
+ and spread `{...bindField(owner, "email")}` for `error` and `onblur`.
129
+
130
+ ## Remote validation and options
131
+
132
+ Middleware that changes the control is a Svelte attachment. `{@attach}` on a
133
+ `Field` or field component is forwarded to its control, as native attributes
134
+ and handlers are.
135
+
136
+ `validateRemotely(target, options)` checks the value once the user stops
137
+ typing and sets the answer as the control's custom validity, so the browser
138
+ blocks the submit and the field shows the message:
139
+
140
+ ```svelte
141
+ <Field
142
+ inputType="text"
143
+ name="username"
144
+ label="Username"
145
+ {@attach validateRemotely("/api/validate-username", {
146
+ errorExtractor: async (response) => (await response.json()).error,
147
+ })}
148
+ />
149
+ ```
150
+
151
+ - `target` is a REST endpoint (`POST { value }` by default; `method`, `headers`,
152
+ `bodyFormatter`, `errorExtractor`), or your own check:
153
+ `(value, signal) => Promise<string | undefined>`, resolving to a message or
154
+ `undefined` when valid.
155
+ - `minLength` (3), `debounceWait` (300 ms) and `timeout` (10000 ms) set when it
156
+ checks and how long it waits. Each change cancels the pending check, so only
157
+ the answer for the latest value counts.
158
+ - A check that fails to complete, or times out, keeps the previous message.
159
+ A value shorter than `minLength` clears it. Each attachment clears only the
160
+ message it set.
161
+ - A submit of a value not yet answered waits for its check, then submits again
162
+ when the value passed. In a `novalidate` form a rejected value still blocks
163
+ the submit.
164
+ - Only string values typed or picked by the user are followed; a value written
165
+ by code is checked on submit. Without JavaScript nothing is checked, so
166
+ validate on the server too.
167
+
168
+ Options are data. Fetch them in a SvelteKit `load` for server rendering, with
169
+ `fetchOptions(url, { fetch, transformData })`, and pass them as `options`. To
170
+ fetch them in the browser, and again when the URL changes, use
171
+ `createRemoteOptions`:
172
+
173
+ ```svelte
174
+ <script>
175
+ const fruits = createRemoteOptions(() => `/api/fruits?season=${season}`);
176
+ </script>
177
+
178
+ <Field inputType="select" name="fruit" label="Fruit" {...fruits.fieldProps} />
179
+ ```
180
+
181
+ While loading the field is disabled, `aria-busy` and empty; a failed request
182
+ becomes its `error` and leaves it enabled; a new URL clears the options and
183
+ error while the new ones load. Spread `fieldProps` before your own props.
184
+
185
+ ## Native validity
186
+
187
+ A field given no `error` (by you or by the owner) shows its control's native
188
+ `validationMessage`, from the control's first `invalid` event: a failed
189
+ submit, `checkValidity()`, `reportValidity()` or a `validateRemotely`
190
+ rejection. From then on it reads the message again on `input`, `change`,
191
+ `focusout` and the `ds:validity` event (`VALIDITY_EVENT`), so a fixed value
192
+ clears it. A form reset, or hiding the field, stops it until the next
193
+ `invalid`. If you call `setCustomValidity("")` yourself, dispatch
194
+ `new Event("ds:validity", { bubbles: true })` on the control afterwards, since
195
+ the browser fires no event. A custom `component` renders its own error.
196
+
197
+ ## Without JavaScript
198
+
199
+ Fields render their values on the server, carry native `name`, `required` and
200
+ constraint attributes, and post with the form, so a `Form` without an owner
201
+ works with SvelteKit actions and with JavaScript disabled. Pass the action's
202
+ messages back as `error`. Owners, `condition`, `validateRemotely` and
203
+ `createRemoteOptions` need JavaScript; fetch options in `load` to have them on
204
+ the server.
205
+
206
+ `file` fields post their files without JavaScript: the named file input mirrors
207
+ the bound files, including dropped ones. A plain form needs
208
+ `enctype="multipart/form-data"` for the browser to send file contents:
209
+ `<Form method="POST" enctype="multipart/form-data">`.
210
+
211
+ Text typed, options chosen and boxes checked before the page hydrates are kept:
212
+ the bound value adopts them. `RadioInput` and `PhoneInput` find their server
213
+ markup by `id`, which every field provides; used on their own without an `id`,
214
+ they lose edits made before hydration.
215
+
216
+ ## Inputs
217
+
218
+ The presentational inputs work outside a form, for example in a filter bar:
219
+ `TextInput`, `NumberInput`, `PasswordInput`, `TextareaInput`, `SelectInput`,
220
+ `DateInput`, `TimeInput`, `DateTimeInput`, `RangeInput`, `HiddenInput` and
221
+ `PhoneInput` bind `value`; `CheckboxInput`, `SwitchInput` and `RadioInput` bind
222
+ `checked`; `FileUploadInput` binds `files`.
223
+
224
+ ## File upload
225
+
226
+ `inputType: "file"` (and `FileUploadInput`) binds `File[]`. An `upload`
227
+ function makes it live: each valid file is sent as soon as it is chosen, with
228
+ an abort signal and a progress callback, and closing a running upload removes
229
+ the file. Upload state stays in the input; the bound value is always the
230
+ chosen files.
231
+
232
+ ```svelte
233
+ <script lang="ts">
234
+ import { Field, type UploadFunction } from "@canonical/svelte-ds-global-form";
235
+
236
+ const upload: UploadFunction = async (file, { signal }) => {
237
+ const response = await fetch("/api/files", { method: "POST", body: file, signal });
238
+ if (!response.ok) throw new Error(response.statusText);
239
+ };
240
+ </script>
241
+
242
+ <Field inputType="file" name="attachments" label="Attachments" multiple
243
+ accept=".pdf,image/*" maxSize={10 * 1024 * 1024} maxFiles={5} {upload} />
244
+ ```
245
+
246
+ `accept`, `maxSize` and `validateFile` put a warning or an error under a file.
247
+ `maxFiles`, a file with an error, and an upload still running or failed make
248
+ the field invalid: the message is the file input's custom validity, so the
249
+ browser holds the submit back, as for `required`. In a `novalidate` form the
250
+ field stops the submit itself. `messages` replaces any text, and
251
+ `onuploadstatuschange` reports the running and failed uploads.
252
+
253
+ ## Phone
254
+
255
+ `PhoneInput` (and `inputType: "phone"`) binds an E.164 string, or a structured
256
+ `{ countryCode, number }` with `valueFormat="structured"`. Countries come from
257
+ `phoneCountries` in `@canonical/ds-utils`. With a `name`, both controls post
258
+ without JavaScript: the number as `<name>` and the country code as
259
+ `<name>-country`. On the server, `decodePhone(formData, name)` turns the two
260
+ entries into both formats (pass a third `countries` argument for a custom
261
+ dataset).
@@ -0,0 +1,198 @@
1
+ # Baseline-alignment spike — findings
2
+
3
+ Exploratory spike, not a production refactor. It covers two linked changes:
4
+
5
+ 1. Moving the baseline unit from **8px to 4px**.
6
+ 2. An alternative baseline-alignment model for **boxed controls** (buttons,
7
+ inputs, nav items, list/table rows) that stops forcing the bottom border onto
8
+ the grid.
9
+
10
+ Everything is scoped to `_work_in_progress`; the only shared-package edits are
11
+ the 4px default (in `styles`, not tokens) and the grid overlay (in
12
+ `styles-debug`), both called out below.
13
+
14
+ ---
15
+
16
+ ## 1. What the shipped engine does today
17
+
18
+ The typography engine (`@canonical/styles-typography`, default
19
+ `baseline-cap.css`) snaps each text element's box to the grid with two padding
20
+ nudges computed live in CSS:
21
+
22
+ ```
23
+ --start-nudge = baseline − mod(baseline-position, baseline) /* seat the text baseline */
24
+ --end-nudge = baseline − start-nudge /* fill to a whole grid multiple */
25
+
26
+ padding-block-start: var(--start-nudge);
27
+ padding-block-end: var(--end-nudge);
28
+ ```
29
+
30
+ Because `start-nudge + end-nudge = baseline`, the box height is always a whole
31
+ number of baseline units **and both the top and bottom borders sit on the grid**.
32
+
33
+ The cost: whenever `start-nudge ≠ end-nudge`, the interior is asymmetric — the
34
+ text is nudged down from the top by one amount and up from the bottom by a
35
+ different amount. On a control with a visible border and a fixed look (a 24px or
36
+ 32px button), that reads as the label sitting slightly high or low in its box.
37
+
38
+ ## 2. The proposed model
39
+
40
+ Keep the top alignment; make the interior symmetric; move the leftover outside
41
+ the box:
42
+
43
+ ```
44
+ padding-block-start: var(--start-nudge); /* unchanged — seat the baseline */
45
+ padding-block-end: var(--start-nudge); /* MIRROR the top nudge, not end-nudge */
46
+
47
+ /* the box is now NOT a whole grid multiple, so compensate outside it */
48
+ --visible: calc(2*border + 2*start-nudge + line-height);
49
+ margin-block-end: calc(round(up, var(--visible), var(--baseline-height)) − var(--visible));
50
+ ```
51
+
52
+ - Top border stays on the grid.
53
+ - Interior spacing above and below the text is equal → visually balanced.
54
+ - Bottom border floats where it naturally lands.
55
+ - External `margin-block-end` (0…<1 baseline) pads the *occupied* height back to
56
+ a 4px multiple, so downstream layout rhythm is preserved.
57
+
58
+ Worked example (the brief's numbers): borders + top nudge + line-height + bottom
59
+ nudge come to a 21px visible box → `margin-block-end: 3px` → 24px occupied.
60
+
61
+ The alternative (top-align + external-margin) model was prototyped and then
62
+ dropped: the testbed now renders the **shipped engine model only** (the asymmetric
63
+ start/end nudges), with no `.model-current` / `.model-proposed` toggle. This
64
+ section is kept as the record of what was considered and why the external-margin
65
+ approach was not adopted (see §4).
66
+
67
+ ---
68
+
69
+ ## 3. Architectural & token changes required
70
+
71
+ **Baseline unit (4px).** Set in `packages/styles/main/src/spacing.css`:
72
+ `--space-baseline: 0.25rem`, no longer reading `--dimension-size-height-baseline`
73
+ (which stays 8px). Promoting 4px into `@canonical/design-tokens` is a **separate
74
+ tokens PR** — not done here on purpose. The engine reads `--baseline-height`
75
+ live, so nothing else changed to move the grid.
76
+
77
+ **Grid overlay (debug).** `packages/styles/debug/src/baseline-grid.css` now
78
+ defaults to 4px and paints **alternating bands** (tinted 4px / clear 4px) plus a
79
+ major line every 4th baseline, so the denser grid stays readable. Applied only
80
+ via the plugin — the story opts in with `parameters: { baseline: true }` and
81
+ `storybook-addon-utils` toggles `.with-baseline-grid`. (The addon was extended to
82
+ honor that parameter, not just the toolbar global; its `dist` must be rebuilt for
83
+ the change to take effect.)
84
+
85
+ **The alignment model itself** would live in the engine
86
+ (`baseline-cap.css` / `-metrics` / `-trim`), because that is where `start-nudge`
87
+ / `end-nudge` are defined. Concretely:
88
+
89
+ - Add an opt-in mode (class or custom property, e.g. `.baseline-boxed` /
90
+ `--baseline-mode: boxed`) that swaps `padding-block-end` from `--end-nudge` to
91
+ `--start-nudge` and emits the compensating `margin-block-end`.
92
+ - The engine currently reserves `margin-block-end` for `--space-after`
93
+ (editorial). The boxed mode has to **add to** that margin, not overwrite it:
94
+ `margin-block-end: calc(space-after-margin + compensation)`. This is the one
95
+ real coupling to untangle.
96
+ - `round()` is already relied on elsewhere in the engine, so no new browser
97
+ floor.
98
+
99
+ **Per-component.** Boxed controls (`Button`, form inputs, future Tabs/SideNav
100
+ items, list/table rows) opt into the boxed mode on their outer element. Their
101
+ own `padding-block` (where they set it) must be reconciled with the nudges so the
102
+ two don't stack.
103
+
104
+ ---
105
+
106
+ ## 4. Risks introduced by external margin compensation
107
+
108
+ - **Margin collapsing.** `margin-block-end` collapses with adjacent block
109
+ margins and through empty parents. In flex/grid containers margins don't
110
+ collapse (safe — that is where most controls live), but in plain block flow a
111
+ control's compensation can merge with a following sibling's top margin and the
112
+ rhythm silently shifts. The engine deliberately used *padding* to avoid exactly
113
+ this; the proposed model reintroduces the hazard by design.
114
+ - **Last-child / container edges.** Trailing compensation adds phantom space at
115
+ the bottom of a container (extra gap under the last row of a table, below the
116
+ last field in a form). Needs a `:last-child` reset in boxed contexts —
117
+ analogous to the existing `.content-flow > :last-child { margin-bottom: 0 }`.
118
+ - **`gap` double-counts.** In a flex/grid layout that already sets `gap`, each
119
+ item's external margin **adds to** the gap, so spacing between controls grows
120
+ by the compensation amount. Either the layout drops `gap` in favour of the
121
+ margins, or boxed controls suppress their margin when a gap owns the spacing.
122
+ (The testbed sets `gap: 0` on the control column precisely so the compensation
123
+ stays visible instead of being masked.)
124
+ - **Backgrounds / borders / dividers.** The compensation is outside the box, so
125
+ a full-bleed row background or a shared list divider stops at the border, not
126
+ at the occupied edge — a 3px unpainted strip appears between rows. The
127
+ shared-border list case in the testbed is there to show this.
128
+ - **Vertical centering.** Anything relying on the control's *box* being a grid
129
+ multiple to center it (icon next to label, absolutely-positioned affordances)
130
+ now centers against a non-grid box; the external margin doesn't participate.
131
+ - **Sticky / scroll math.** Occupied height ≠ border-box height means
132
+ `scroll-margin`, sticky offsets and `IntersectionObserver` thresholds computed
133
+ from `getBoundingClientRect()` are off by the compensation.
134
+
135
+ ## 5. Where this model should NOT be used
136
+
137
+ - **Inline text / prose.** Paragraphs and inline runs already balance naturally;
138
+ the whole point of the symmetric-interior model is boxed controls with a
139
+ visible border. Prose keeps the current engine (`.p`, headings unchanged).
140
+ - **Controls whose height is externally fixed** (`height: 32px`, icon-only
141
+ square buttons). If the height is pinned, interior symmetry is governed by
142
+ `align-items`, not the nudges, and the external margin just adds stray space.
143
+ - **Grid/flex items that must fill a track** (`align-items: stretch`, table cells
144
+ with row-spanning). Stretch overrides the box height and the compensation
145
+ margin is ignored or fights the track.
146
+ - **Anything inside `gap`-based layouts** unless the gap-vs-margin
147
+ double-count is resolved for that container.
148
+ - **Overlapping / absolutely positioned** elements — margin does nothing there.
149
+
150
+ ## 6. Recommended implementation strategy
151
+
152
+ Ship it as an **opt-in engine mode**, defaulted off, so nothing changes until a
153
+ component asks for it.
154
+
155
+ 1. **Engine flag.** Add `--baseline-mode: grid | boxed` (default `grid`). In
156
+ `boxed`, `padding-block-end` mirrors `--start-nudge` and the engine emits
157
+ `margin-block-end: calc(var(--space-after-margin) + var(--baseline-compensation))`.
158
+ Keep `grid` byte-for-byte as today.
159
+ 2. **Container reset.** Provide a `.baseline-boxed-flow` (or reuse
160
+ `content-flow`) that zeroes the trailing compensation on the last child and
161
+ documents the gap-vs-margin rule.
162
+ 3. **Adopt on one control first** (Button), verify against prose in the testbed
163
+ at several sizes, then inputs, then nav items, then list/table rows (the
164
+ shared-border case last, since it exposes the divider gap).
165
+ 4. **Only then** consider promoting 4px + a `density: boxed` token set into
166
+ `@canonical/design-tokens`.
167
+
168
+ ### Before / after
169
+
170
+ ```css
171
+ /* BEFORE — grid mode (ships today): both borders on grid, interior can be asymmetric */
172
+ .ds.button > .p {
173
+ padding-block-start: var(--start-nudge); /* e.g. 3px */
174
+ padding-block-end: var(--end-nudge); /* e.g. 1px → text sits high */
175
+ }
176
+
177
+ /* AFTER — boxed mode: symmetric interior, bottom border free, rhythm via margin */
178
+ .ds.button {
179
+ --visible: calc(2px + calc(2 * var(--start-nudge)) + var(--computed-line-height));
180
+ margin-block-end: calc(
181
+ var(--space-after-margin, 0px) +
182
+ (round(up, var(--visible), var(--baseline-height)) - var(--visible))
183
+ );
184
+ }
185
+ .ds.button > .p {
186
+ padding-block-start: var(--start-nudge); /* 3px */
187
+ padding-block-end: var(--start-nudge); /* 3px → text balanced */
188
+ }
189
+ ```
190
+
191
+ ### Caveat surfaced by the testbed
192
+
193
+ At the default body size on a 4px grid, `start-nudge ≈ end-nudge`, so the two
194
+ models render nearly identically — the asymmetry the model fixes only becomes
195
+ visible at particular font-size / line-height / border combinations. Any adoption
196
+ decision should be made against a size where the current asymmetry is actually
197
+ visible, not the default paragraph tier. The testbed should grow a row at such a
198
+ size before this is taken forward.
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Testbed chrome for the baseline/density spike (WORK IN PROGRESS).
3
+ *
4
+ * The density + baseline MODEL now lives in the package: src/density.css
5
+ * (imported by src/index.css), so real components consume it by default. This
6
+ * file keeps only the TESTBED-ONLY helpers: the size-agnostic `.baseline` proof
7
+ * class and the `.spike-baseline-boxed` prototype + their proof surfaces.
8
+ *
9
+ * Layer: ds.components.global (@canonical/styles README, "Cascade layers").
10
+ */
11
+
12
+ @layer ds.components.global {
13
+ /* ── DS.01 — .baseline: snap any element to the grid, whatever its size ──────
14
+ * Reads whatever --font-size / --line-height is present and computes the same
15
+ * cap-unit nudges the engine uses on h1..h6/p, without assigning a tier. The
16
+ * maths is font-relative, so it holds at any size. */
17
+ .baseline {
18
+ --bl-line-height-ratio: var(--line-height-ratio, 1.4);
19
+ --bl-computed-line-height: var(
20
+ --line-height,
21
+ round(up, calc(1em * var(--bl-line-height-ratio)), var(--baseline-height))
22
+ );
23
+ line-height: var(--bl-computed-line-height);
24
+
25
+ --bl-baseline-position: calc((var(--bl-computed-line-height) + 1cap) / 2);
26
+ --bl-start-nudge: calc(
27
+ var(--baseline-height) -
28
+ mod(var(--bl-baseline-position), var(--baseline-height))
29
+ );
30
+ --bl-end-nudge: calc(var(--baseline-height) - var(--bl-start-nudge));
31
+
32
+ padding-block-start: var(--bl-start-nudge);
33
+ padding-block-end: var(--bl-end-nudge);
34
+ margin-block: 0;
35
+ }
36
+
37
+ /* ── DS.02 — .spike-baseline-boxed: PROTOTYPE ONLY, NOT CORE API ─────────────
38
+ * `.baseline` with a density-chosen line-height; the box height is snapped to the
39
+ * grid (intrinsic snap via calc-size where supported, fixed grid-multiple
40
+ * fallback). Testbed only; never export. */
41
+ .spike-baseline-boxed {
42
+ --line-height: var(--density-line-height, calc(var(--baseline-height) * 6));
43
+ box-sizing: border-box;
44
+ block-size: var(--density-line-height, calc(var(--baseline-height) * 6));
45
+ }
46
+ @supports (block-size: calc-size(min-content, size)) {
47
+ .spike-baseline-boxed {
48
+ block-size: calc-size(
49
+ min-content,
50
+ round(up, size, var(--baseline-height))
51
+ );
52
+ }
53
+ }
54
+
55
+ /* ── Proof surface for .baseline (DS.01) — off-scale sizes on one line ─────── */
56
+ .baseline-proof {
57
+ display: flex;
58
+ align-items: flex-start;
59
+ gap: calc(var(--baseline-height) * 4);
60
+ overflow-x: auto;
61
+ white-space: nowrap;
62
+ }
63
+ .baseline-proof > .baseline {
64
+ font-family: inherit;
65
+ }
66
+
67
+ /* ── Proof surface for .spike-baseline-boxed (DS.02) — mixed sizes, 2 densities ── */
68
+ .boxed-proof {
69
+ display: flex;
70
+ align-items: flex-start;
71
+ gap: calc(var(--baseline-height) * 3);
72
+ overflow-x: auto;
73
+ white-space: nowrap;
74
+ margin-block: calc(var(--baseline-height) * 2);
75
+ }
76
+ .boxed-proof > .spike-baseline-boxed {
77
+ border: 1px solid var(--color-border, #b3b3b3);
78
+ border-radius: var(--dimension-radius-100, 0.25rem);
79
+ padding-inline: calc(var(--baseline-height) * 2);
80
+ background: transparent; /* let the grid overlay show through */
81
+ }
82
+ .boxed-proof.is-dense {
83
+ --density-line-height: calc(var(--baseline-height) * 6); /* 24px */
84
+ }
85
+ .boxed-proof.is-comfortable {
86
+ --density-line-height: calc(var(--baseline-height) * 8); /* 32px */
87
+ }
88
+ }