@automattic/vip-design-system 1.2.0 → 1.2.2

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 (455) hide show
  1. package/.storybook/decorators/withBoundingBox.tsx +11 -0
  2. package/.storybook/decorators/{withThemeProvider.jsx → withThemeProvider.tsx} +1 -5
  3. package/.storybook/{preview.js → preview.tsx} +12 -3
  4. package/build/declaration.d.js +1 -0
  5. package/build/system/Accordion/Accordion.d.ts +41 -0
  6. package/build/system/Accordion/Accordion.js +10 -35
  7. package/build/system/Accordion/Accordion.stories.d.ts +13 -0
  8. package/build/system/Accordion/Accordion.stories.js +4 -7
  9. package/build/system/Accordion/Accordion.test.d.ts +2 -0
  10. package/build/system/Accordion/Accordion.test.js +5 -7
  11. package/build/system/Accordion/index.d.ts +5 -0
  12. package/build/system/Avatar/Avatar.d.ts +13 -0
  13. package/build/system/Avatar/Avatar.js +7 -20
  14. package/build/system/Avatar/Avatar.stories.d.ts +16 -0
  15. package/build/system/Avatar/Avatar.stories.js +5 -7
  16. package/build/system/Avatar/Avatar.test.d.ts +1 -0
  17. package/build/system/Avatar/Avatar.test.js +5 -7
  18. package/build/system/Avatar/index.d.ts +4 -0
  19. package/build/system/Avatar/index.js +1 -0
  20. package/build/system/Badge/Badge.d.ts +6 -0
  21. package/build/system/Badge/Badge.js +6 -15
  22. package/build/system/Badge/Badge.stories.d.ts +18 -0
  23. package/build/system/Badge/Badge.stories.js +70 -71
  24. package/build/system/Badge/Badge.test.d.ts +1 -0
  25. package/build/system/Badge/Badge.test.js +6 -8
  26. package/build/system/Badge/index.d.ts +4 -0
  27. package/build/system/Badge/index.js +1 -0
  28. package/build/system/Box/Box.d.ts +3 -0
  29. package/build/system/{Form/Label.stories.js → Box/Box.js} +15 -31
  30. package/build/system/Box/Box.stories.d.ts +16 -0
  31. package/build/system/Box/Box.stories.js +21 -0
  32. package/build/system/Box/index.d.ts +2 -0
  33. package/build/system/Box/index.js +5 -4
  34. package/build/system/Button/Button.d.ts +12 -0
  35. package/build/system/Button/Button.js +10 -18
  36. package/build/system/Button/Button.stories.d.ts +30 -0
  37. package/build/system/Button/Button.stories.js +10 -20
  38. package/build/system/Button/Button.test.d.ts +1 -0
  39. package/build/system/Button/Button.test.js +45 -74
  40. package/build/system/Button/ButtonSubmit.d.ts +2 -0
  41. package/build/system/Button/ButtonSubmit.js +60 -70
  42. package/build/system/Button/ButtonSubmit.stories.d.ts +38 -0
  43. package/build/system/Button/ButtonSubmit.stories.jsx +40 -0
  44. package/build/system/Button/ButtonSubmit.test.d.ts +1 -0
  45. package/build/system/Button/ButtonSubmit.test.js +32 -60
  46. package/build/system/Button/index.d.ts +3 -0
  47. package/build/system/Button/index.js +7 -6
  48. package/build/system/Button/variants.d.ts +2 -0
  49. package/build/system/Button/variants.js +1 -6
  50. package/build/system/Card/Card.d.ts +9 -0
  51. package/build/system/Card/Card.js +2 -10
  52. package/build/system/Card/Card.stories.d.ts +7 -0
  53. package/build/system/Card/Card.stories.js +4 -6
  54. package/build/system/Card/Card.test.d.ts +1 -0
  55. package/build/system/Card/Card.test.js +5 -7
  56. package/build/system/Card/index.d.ts +4 -0
  57. package/build/system/Card/index.js +1 -0
  58. package/build/system/Code/Code.d.ts +15 -0
  59. package/build/system/Code/Code.js +14 -21
  60. package/build/system/Code/Code.stories.d.ts +18 -0
  61. package/build/system/Code/Code.stories.js +31 -23
  62. package/build/system/Code/Code.test.d.ts +1 -0
  63. package/build/system/Code/Code.test.js +10 -11
  64. package/build/system/Code/index.d.ts +4 -0
  65. package/build/system/Code/index.js +1 -0
  66. package/build/system/ConfirmationDialog/ConfirmationDialog.d.ts +35 -0
  67. package/build/system/ConfirmationDialog/ConfirmationDialog.js +68 -94
  68. package/build/system/ConfirmationDialog/ConfirmationDialog.stories.d.ts +7 -0
  69. package/build/system/ConfirmationDialog/ConfirmationDialog.stories.jsx +29 -0
  70. package/build/system/ConfirmationDialog/index.d.ts +3 -0
  71. package/build/system/ConfirmationDialog/index.js +5 -5
  72. package/build/system/Dialog/Dialog.d.ts +18 -0
  73. package/build/system/Dialog/Dialog.js +81 -94
  74. package/build/system/Dialog/Dialog.stories.d.ts +7 -0
  75. package/build/system/Dialog/Dialog.stories.jsx +60 -0
  76. package/build/system/Dialog/DialogButton.d.ts +16 -0
  77. package/build/system/Dialog/DialogButton.js +51 -66
  78. package/build/system/Dialog/DialogContent.d.ts +18 -0
  79. package/build/system/Dialog/DialogContent.js +142 -137
  80. package/build/system/Dialog/DialogDivider.d.ts +5 -0
  81. package/build/system/Dialog/DialogDivider.js +5 -16
  82. package/build/system/Dialog/DialogMenu.d.ts +5 -0
  83. package/build/system/Dialog/DialogMenu.js +5 -18
  84. package/build/system/Dialog/DialogMenuItem.d.ts +13 -0
  85. package/build/system/Dialog/DialogMenuItem.js +64 -71
  86. package/build/system/Dialog/DialogTrigger.d.ts +1 -0
  87. package/build/system/Dialog/DialogTrigger.js +10 -16
  88. package/build/system/Dialog/index.d.ts +8 -0
  89. package/build/system/Dialog/index.js +19 -16
  90. package/build/system/Dropdown/Dropdown.d.ts +37 -0
  91. package/build/system/Dropdown/Dropdown.js +96 -93
  92. package/build/system/Dropdown/Dropdown.stories.d.ts +34 -0
  93. package/build/system/Dropdown/Dropdown.stories.jsx +170 -0
  94. package/build/system/Dropdown/Dropdown.test.d.ts +1 -0
  95. package/build/system/Dropdown/Dropdown.test.js +30 -52
  96. package/build/system/Dropdown/DropdownContent.d.ts +11 -0
  97. package/build/system/Dropdown/DropdownContent.js +40 -49
  98. package/build/system/Dropdown/DropdownItem.d.ts +32 -0
  99. package/build/system/Dropdown/DropdownItem.js +91 -95
  100. package/build/system/Dropdown/DropdownLabel.d.ts +8 -0
  101. package/build/system/Dropdown/DropdownLabel.js +24 -33
  102. package/build/system/Dropdown/DropdownSeparator.d.ts +7 -0
  103. package/build/system/Dropdown/DropdownSeparator.js +23 -32
  104. package/build/system/Dropdown/index.d.ts +40 -0
  105. package/build/system/Dropdown/index.js +49 -37
  106. package/build/system/Flex/Flex.d.ts +2 -0
  107. package/build/system/Flex/Flex.js +6 -8
  108. package/build/system/Flex/Flex.stories.d.ts +7 -0
  109. package/build/system/Flex/Flex.stories.js +3 -5
  110. package/build/system/Flex/index.d.ts +4 -0
  111. package/build/system/Flex/index.js +1 -0
  112. package/build/system/Form/Checkbox.d.ts +10 -0
  113. package/build/system/Form/Checkbox.js +61 -62
  114. package/build/system/Form/Checkbox.stories.d.ts +7 -0
  115. package/build/system/Form/Checkbox.stories.jsx +54 -0
  116. package/build/system/Form/Input.d.ts +2 -0
  117. package/build/system/Form/Input.js +70 -69
  118. package/build/system/Form/Input.stories.d.ts +5 -0
  119. package/build/system/Form/Input.stories.jsx +38 -0
  120. package/build/system/Form/Input.styles.d.ts +32 -0
  121. package/build/system/Form/Input.styles.js +29 -40
  122. package/build/system/Form/InputWithCopyButton.d.ts +2 -0
  123. package/build/system/Form/InputWithCopyButton.js +109 -105
  124. package/build/system/Form/InputWithCopyButton.stories.d.ts +5 -0
  125. package/build/system/Form/InputWithCopyButton.stories.jsx +30 -0
  126. package/build/system/Form/Label.d.ts +9 -0
  127. package/build/system/Form/Label.js +41 -47
  128. package/build/system/Form/Label.stories.d.ts +6 -0
  129. package/build/system/Form/Label.stories.jsx +36 -0
  130. package/build/system/Form/Radio.d.ts +2 -0
  131. package/build/system/Form/Radio.js +185 -169
  132. package/build/system/Form/Radio.stories.d.ts +7 -0
  133. package/build/system/Form/Radio.stories.jsx +100 -0
  134. package/build/system/Form/RadioBoxGroup.d.ts +2 -0
  135. package/build/system/Form/RadioBoxGroup.js +193 -187
  136. package/build/system/Form/RadioBoxGroup.stories.d.ts +8 -0
  137. package/build/system/Form/RadioBoxGroup.stories.jsx +60 -0
  138. package/build/system/Form/RequiredLabel.d.ts +5 -0
  139. package/build/system/Form/RequiredLabel.js +7 -17
  140. package/build/system/Form/Textarea.d.ts +2 -0
  141. package/build/system/Form/Textarea.js +18 -20
  142. package/build/system/Form/Textarea.stories.d.ts +34 -0
  143. package/build/system/Form/Textarea.stories.jsx +40 -0
  144. package/build/system/Form/Toggle.d.ts +2 -0
  145. package/build/system/Form/Toggle.js +67 -81
  146. package/build/system/Form/Toggle.stories.d.ts +19 -0
  147. package/build/system/Form/Toggle.stories.jsx +96 -0
  148. package/build/system/Form/Toggle.test.d.ts +1 -0
  149. package/build/system/Form/Toggle.test.js +21 -39
  150. package/build/system/Form/ToggleRow.d.ts +22 -0
  151. package/build/system/Form/ToggleRow.js +66 -95
  152. package/build/system/Form/Validation.d.ts +14 -0
  153. package/build/system/Form/Validation.js +33 -42
  154. package/build/system/Form/index.d.ts +11 -0
  155. package/build/system/Form/index.js +25 -22
  156. package/build/system/Grid/Grid.d.ts +6 -0
  157. package/build/system/Grid/Grid.js +4 -5
  158. package/build/system/Grid/Grid.stories.d.ts +7 -0
  159. package/build/system/Grid/Grid.stories.js +3 -5
  160. package/build/system/Grid/index.d.ts +4 -0
  161. package/build/system/Grid/index.js +1 -0
  162. package/build/system/Heading/Heading.d.ts +6 -0
  163. package/build/system/Heading/Heading.js +33 -0
  164. package/build/system/Heading/Heading.stories.d.ts +7 -0
  165. package/build/system/Heading/Heading.stories.js +33 -0
  166. package/build/system/Heading/index.d.ts +2 -0
  167. package/build/system/Heading/index.js +5 -4
  168. package/build/system/Link/Link.d.ts +6 -0
  169. package/build/system/Link/Link.js +5 -12
  170. package/build/system/Link/Link.stories.d.ts +16 -0
  171. package/build/system/Link/Link.stories.js +12 -13
  172. package/build/system/Link/index.d.ts +4 -0
  173. package/build/system/Link/index.js +1 -0
  174. package/build/system/NewConfirmationDialog/NewConfirmationDialog.d.ts +23 -0
  175. package/build/system/NewConfirmationDialog/NewConfirmationDialog.js +86 -99
  176. package/build/system/NewConfirmationDialog/NewConfirmationDialog.stories.d.ts +8 -0
  177. package/build/system/NewConfirmationDialog/NewConfirmationDialog.stories.jsx +34 -0
  178. package/build/system/NewConfirmationDialog/NewConfirmationDialog.test.d.ts +1 -0
  179. package/build/system/NewConfirmationDialog/NewConfirmationDialog.test.js +43 -66
  180. package/build/system/NewConfirmationDialog/index.d.ts +2 -0
  181. package/build/system/NewConfirmationDialog/index.js +5 -4
  182. package/build/system/NewDialog/DialogClose.d.ts +6 -0
  183. package/build/system/NewDialog/DialogClose.js +50 -69
  184. package/build/system/NewDialog/DialogClose.test.d.ts +1 -0
  185. package/build/system/NewDialog/DialogClose.test.js +29 -46
  186. package/build/system/NewDialog/DialogContent.d.ts +18 -0
  187. package/build/system/NewDialog/DialogContent.js +14 -21
  188. package/build/system/NewDialog/DialogDescription.d.ts +5 -0
  189. package/build/system/NewDialog/DialogDescription.js +31 -38
  190. package/build/system/NewDialog/DialogDescription.test.d.ts +1 -0
  191. package/build/system/NewDialog/DialogDescription.test.js +44 -67
  192. package/build/system/NewDialog/DialogOverlay.d.ts +2 -0
  193. package/build/system/NewDialog/DialogOverlay.js +28 -32
  194. package/build/system/NewDialog/DialogOverlay.test.d.ts +1 -0
  195. package/build/system/NewDialog/DialogOverlay.test.js +26 -42
  196. package/build/system/NewDialog/DialogTitle.d.ts +11 -0
  197. package/build/system/NewDialog/DialogTitle.js +19 -34
  198. package/build/system/NewDialog/DialogTitle.test.d.ts +1 -0
  199. package/build/system/NewDialog/DialogTitle.test.js +44 -67
  200. package/build/system/NewDialog/NewDialog.d.ts +29 -0
  201. package/build/system/NewDialog/NewDialog.js +74 -89
  202. package/build/system/NewDialog/NewDialog.stories.d.ts +38 -0
  203. package/build/system/NewDialog/NewDialog.stories.jsx +192 -0
  204. package/build/system/NewDialog/index.d.ts +31 -0
  205. package/build/system/NewDialog/index.js +9 -13
  206. package/build/system/NewForm/Fieldset.d.ts +2 -0
  207. package/build/system/NewForm/Fieldset.js +38 -43
  208. package/build/system/NewForm/Form.d.ts +2 -0
  209. package/build/system/NewForm/Form.js +21 -28
  210. package/build/system/NewForm/FormAutocomplete.d.ts +2 -0
  211. package/build/system/NewForm/FormAutocomplete.js +386 -381
  212. package/build/system/NewForm/FormAutocomplete.stories.d.ts +156 -0
  213. package/build/system/NewForm/FormAutocomplete.stories.jsx +159 -0
  214. package/build/system/NewForm/FormAutocomplete.test.d.ts +1 -0
  215. package/build/system/NewForm/FormAutocomplete.test.js +40 -73
  216. package/build/system/NewForm/FormAutocompleteMultiselect.d.ts +2 -0
  217. package/build/system/NewForm/FormAutocompleteMultiselect.js +456 -468
  218. package/build/system/NewForm/FormAutocompleteMultiselect.stories.d.ts +45 -0
  219. package/build/system/NewForm/FormAutocompleteMultiselect.stories.jsx +162 -0
  220. package/build/system/NewForm/FormAutocompleteMultiselect.test.d.ts +1 -0
  221. package/build/system/NewForm/FormAutocompleteMultiselect.test.js +37 -73
  222. package/build/system/NewForm/FormSelect.d.ts +2 -0
  223. package/build/system/NewForm/FormSelect.js +159 -140
  224. package/build/system/NewForm/FormSelect.stories.d.ts +137 -0
  225. package/build/system/NewForm/FormSelect.stories.jsx +138 -0
  226. package/build/system/NewForm/FormSelect.test.d.ts +1 -0
  227. package/build/system/NewForm/FormSelect.test.js +131 -227
  228. package/build/system/NewForm/FormSelectArrow.d.ts +2 -0
  229. package/build/system/NewForm/FormSelectArrow.js +35 -35
  230. package/build/system/NewForm/FormSelectContent.d.ts +2 -0
  231. package/build/system/NewForm/FormSelectContent.js +27 -34
  232. package/build/system/NewForm/FormSelectInline.d.ts +30 -0
  233. package/build/system/NewForm/FormSelectInline.js +41 -38
  234. package/build/system/NewForm/FormSelectLoading.d.ts +2 -0
  235. package/build/system/NewForm/FormSelectLoading.js +36 -45
  236. package/build/system/NewForm/FormSelectSearch.d.ts +2 -0
  237. package/build/system/NewForm/FormSelectSearch.js +23 -25
  238. package/build/system/NewForm/Legend.d.ts +2 -0
  239. package/build/system/NewForm/Legend.js +32 -37
  240. package/build/system/NewForm/index.d.ts +12 -0
  241. package/build/system/NewForm/index.js +30 -30
  242. package/build/system/Notice/Notice.d.ts +18 -0
  243. package/build/system/Notice/Notice.js +41 -55
  244. package/build/system/Notice/Notice.stories.d.ts +13 -0
  245. package/build/system/Notice/Notice.stories.js +3 -5
  246. package/build/system/Notice/index.d.ts +5 -0
  247. package/build/system/OptionRow/OptionRow.d.ts +2 -0
  248. package/build/system/OptionRow/OptionRow.js +146 -159
  249. package/build/system/OptionRow/OptionRow.stories.d.ts +8 -0
  250. package/build/system/OptionRow/OptionRow.stories.jsx +53 -0
  251. package/build/system/OptionRow/OptionRow.test.d.ts +1 -0
  252. package/build/system/OptionRow/OptionRow.test.js +38 -67
  253. package/build/system/OptionRow/index.d.ts +2 -0
  254. package/build/system/OptionRow/index.js +5 -4
  255. package/build/system/Progress/Progress.d.ts +2 -0
  256. package/build/system/Progress/Progress.js +69 -84
  257. package/build/system/Progress/Progress.stories.d.ts +8 -0
  258. package/build/system/Progress/Progress.stories.jsx +25 -0
  259. package/build/system/Progress/index.d.ts +2 -0
  260. package/build/system/Progress/index.js +5 -4
  261. package/build/system/ScreenReaderText/ScreenReader.test.d.ts +1 -0
  262. package/build/system/ScreenReaderText/ScreenReader.test.js +21 -25
  263. package/build/system/ScreenReaderText/ScreenReaderText.d.ts +14 -0
  264. package/build/system/ScreenReaderText/ScreenReaderText.js +13 -21
  265. package/build/system/ScreenReaderText/index.d.ts +3 -0
  266. package/build/system/ScreenReaderText/index.js +6 -8
  267. package/build/system/Spinner/Spinner.d.ts +9 -0
  268. package/build/system/Spinner/Spinner.js +12 -19
  269. package/build/system/Spinner/Spinner.stories.d.ts +7 -0
  270. package/build/system/Spinner/Spinner.stories.js +3 -5
  271. package/build/system/Spinner/Spinner.test.d.ts +1 -0
  272. package/build/system/Spinner/Spinner.test.js +59 -0
  273. package/build/system/Spinner/index.d.ts +1 -0
  274. package/build/system/Spinner/index.js +1 -0
  275. package/build/system/Table/Table.d.ts +14 -0
  276. package/build/system/Table/Table.js +7 -21
  277. package/build/system/Table/Table.stories.d.ts +9 -0
  278. package/build/system/Table/Table.stories.js +5 -12
  279. package/build/system/Table/TableCell.d.ts +15 -0
  280. package/build/system/Table/TableCell.js +13 -18
  281. package/build/system/Table/TableRow.d.ts +14 -0
  282. package/build/system/Table/TableRow.js +19 -24
  283. package/build/system/Table/index.d.ts +6 -0
  284. package/build/system/Table/index.js +1 -0
  285. package/build/system/Tabs/Tabs.d.ts +5 -0
  286. package/build/system/Tabs/Tabs.js +40 -38
  287. package/build/system/Tabs/Tabs.stories.d.ts +9 -0
  288. package/build/system/Tabs/Tabs.stories.jsx +69 -0
  289. package/build/system/Tabs/TabsContent.d.ts +16 -0
  290. package/build/system/Tabs/TabsContent.js +23 -30
  291. package/build/system/Tabs/TabsList.d.ts +15 -0
  292. package/build/system/Tabs/TabsList.js +24 -32
  293. package/build/system/Tabs/TabsTrigger.d.ts +2 -0
  294. package/build/system/Tabs/TabsTrigger.js +58 -66
  295. package/build/system/Tabs/index.d.ts +5 -0
  296. package/build/system/Tabs/index.js +8 -10
  297. package/build/system/Text/Text.d.ts +2 -0
  298. package/build/system/Text/Text.js +5 -13
  299. package/build/system/Text/Text.stories.d.ts +8 -0
  300. package/build/system/Text/Text.stories.js +4 -5
  301. package/build/system/Text/index.d.ts +4 -0
  302. package/build/system/Text/index.js +1 -0
  303. package/build/system/Tooltip/Tooltip.css +96 -0
  304. package/build/system/Tooltip/Tooltip.d.ts +15 -0
  305. package/build/system/Tooltip/Tooltip.js +23 -93
  306. package/build/system/Tooltip/Tooltip.stories.d.ts +15 -0
  307. package/build/system/Tooltip/Tooltip.stories.js +83 -21
  308. package/build/system/Tooltip/index.d.ts +5 -0
  309. package/build/system/Wizard/Wizard.d.ts +2 -0
  310. package/build/system/Wizard/Wizard.js +94 -103
  311. package/build/system/Wizard/Wizard.stories.d.ts +9 -0
  312. package/build/system/Wizard/Wizard.stories.jsx +145 -0
  313. package/build/system/Wizard/WizardStep.d.ts +2 -0
  314. package/build/system/Wizard/WizardStep.js +188 -198
  315. package/build/system/Wizard/WizardStepHorizontal.d.ts +2 -0
  316. package/build/system/Wizard/WizardStepHorizontal.js +43 -55
  317. package/build/system/Wizard/index.d.ts +4 -0
  318. package/build/system/Wizard/index.js +7 -8
  319. package/build/system/index.d.ts +51 -0
  320. package/build/system/index.js +104 -86
  321. package/build/system/theme/colors.d.ts +2 -0
  322. package/build/system/theme/colors.js +7 -12
  323. package/build/system/theme/getColor.d.ts +8 -0
  324. package/build/system/theme/getColor.js +47 -46
  325. package/build/system/theme/index.d.ts +322 -0
  326. package/build/system/theme/index.js +494 -396
  327. package/build/system/theme/textStyles.d.ts +71 -0
  328. package/build/system/theme/textStyles.js +45 -50
  329. package/build/system/utils/random.d.ts +1 -0
  330. package/build/system/utils/random.js +3 -7
  331. package/package.json +31 -37
  332. package/src/declaration.d.ts +1 -0
  333. package/src/system/Accordion/{Accordion.test.js → Accordion.test.tsx} +2 -2
  334. package/src/system/Accordion/{Accordion.js → Accordion.tsx} +87 -80
  335. package/src/system/Avatar/Avatar.stories.tsx +18 -0
  336. package/src/system/Avatar/{Avatar.test.js → Avatar.test.tsx} +2 -2
  337. package/src/system/Avatar/{Avatar.js → Avatar.tsx} +17 -19
  338. package/src/system/Avatar/index.ts +4 -0
  339. package/src/system/Badge/Badge.stories.tsx +57 -0
  340. package/src/system/Badge/{Badge.test.js → Badge.test.tsx} +3 -3
  341. package/src/system/Badge/{Badge.js → Badge.tsx} +10 -15
  342. package/src/system/Badge/index.ts +4 -0
  343. package/src/system/Box/Box.stories.tsx +13 -1
  344. package/src/system/Box/Box.tsx +4 -8
  345. package/src/system/Button/Button.stories.tsx +110 -0
  346. package/src/system/Button/Button.tsx +67 -0
  347. package/src/system/Card/{Card.stories.jsx → Card.stories.tsx} +1 -1
  348. package/src/system/Card/{Card.test.js → Card.test.tsx} +2 -2
  349. package/src/system/Card/Card.tsx +40 -0
  350. package/src/system/Card/index.ts +4 -0
  351. package/src/system/Code/Code.stories.tsx +44 -0
  352. package/src/system/Code/{Code.test.js → Code.test.tsx} +6 -4
  353. package/src/system/Code/{Code.js → Code.tsx} +27 -22
  354. package/src/system/Code/index.ts +4 -0
  355. package/src/system/Flex/Flex.tsx +11 -0
  356. package/src/system/Flex/index.ts +4 -0
  357. package/src/system/Grid/Grid.tsx +11 -0
  358. package/src/system/Grid/index.ts +4 -0
  359. package/src/system/Heading/Heading.tsx +8 -17
  360. package/src/system/Link/Link.stories.tsx +23 -0
  361. package/src/system/Link/Link.tsx +43 -0
  362. package/src/system/Link/index.ts +4 -0
  363. package/src/system/NewForm/FormAutocomplete.js +2 -2
  364. package/src/system/Notice/Notice.tsx +129 -0
  365. package/src/system/OptionRow/OptionRow.test.js +1 -1
  366. package/src/system/ScreenReaderText/ScreenReaderText.tsx +40 -0
  367. package/src/system/Spinner/Spinner.test.tsx +30 -0
  368. package/src/system/Spinner/Spinner.tsx +34 -0
  369. package/src/system/Spinner/index.ts +1 -0
  370. package/src/system/Table/{Table.stories.jsx → Table.stories.tsx} +6 -6
  371. package/src/system/Table/{Table.js → Table.tsx} +14 -18
  372. package/src/system/Table/{TableCell.js → TableCell.tsx} +14 -12
  373. package/src/system/Table/TableRow.tsx +63 -0
  374. package/src/system/Table/index.ts +6 -0
  375. package/src/system/Text/{Text.stories.jsx → Text.stories.tsx} +1 -0
  376. package/src/system/Text/Text.tsx +25 -0
  377. package/src/system/Text/index.ts +4 -0
  378. package/src/system/Tooltip/Tooltip.css +96 -0
  379. package/src/system/Tooltip/Tooltip.stories.tsx +133 -0
  380. package/src/system/Tooltip/Tooltip.tsx +39 -0
  381. package/src/system/index.js +1 -2
  382. package/src/system/theme/index.js +21 -1
  383. package/test/fileMock.ts +1 -0
  384. package/test/setupAfterEnv.ts +5 -0
  385. package/tsconfig.definition.json +12 -0
  386. package/.storybook/decorators/withBoundingBox.jsx +0 -22
  387. package/build/system/Box/Box.stories.tsx +0 -11
  388. package/build/system/Box/Box.tsx +0 -22
  389. package/build/system/Button/ButtonSubmit.stories.js +0 -58
  390. package/build/system/ConfirmationDialog/ConfirmationDialog.stories.js +0 -42
  391. package/build/system/Dialog/Dialog.stories.js +0 -70
  392. package/build/system/Dropdown/Dropdown.stories.js +0 -197
  393. package/build/system/Form/Checkbox.stories.js +0 -73
  394. package/build/system/Form/Input.stories.js +0 -51
  395. package/build/system/Form/InputWithCopyButton.stories.js +0 -39
  396. package/build/system/Form/Radio.stories.js +0 -115
  397. package/build/system/Form/RadioBoxGroup.stories.js +0 -62
  398. package/build/system/Form/Textarea.stories.js +0 -59
  399. package/build/system/Form/Toggle.stories.js +0 -104
  400. package/build/system/Heading/Heading.stories.tsx +0 -19
  401. package/build/system/Heading/Heading.tsx +0 -38
  402. package/build/system/NewConfirmationDialog/NewConfirmationDialog.stories.js +0 -46
  403. package/build/system/NewDialog/NewDialog.stories.js +0 -247
  404. package/build/system/NewForm/FormAutocomplete.stories.js +0 -220
  405. package/build/system/NewForm/FormAutocompleteMultiselect.stories.js +0 -231
  406. package/build/system/NewForm/FormSelect.stories.js +0 -171
  407. package/build/system/Notification/Notification.js +0 -97
  408. package/build/system/Notification/Notification.stories.js +0 -29
  409. package/build/system/Notification/index.js +0 -5
  410. package/build/system/OptionRow/OptionRow.stories.js +0 -64
  411. package/build/system/Progress/Progress.stories.js +0 -36
  412. package/build/system/Tabs/Tabs.stories.js +0 -113
  413. package/build/system/Wizard/Wizard.stories.js +0 -182
  414. package/src/system/Avatar/Avatar.stories.jsx +0 -11
  415. package/src/system/Avatar/index.js +0 -6
  416. package/src/system/Badge/Badge.stories.jsx +0 -43
  417. package/src/system/Badge/index.js +0 -6
  418. package/src/system/Button/Button.js +0 -63
  419. package/src/system/Button/Button.stories.jsx +0 -87
  420. package/src/system/Card/Card.js +0 -39
  421. package/src/system/Card/index.js +0 -6
  422. package/src/system/Code/Code.stories.jsx +0 -37
  423. package/src/system/Code/index.js +0 -6
  424. package/src/system/Flex/Flex.js +0 -15
  425. package/src/system/Flex/index.js +0 -6
  426. package/src/system/Grid/Grid.js +0 -16
  427. package/src/system/Grid/index.js +0 -6
  428. package/src/system/Link/Link.js +0 -42
  429. package/src/system/Link/Link.stories.jsx +0 -15
  430. package/src/system/Link/index.js +0 -6
  431. package/src/system/Notice/Notice.js +0 -136
  432. package/src/system/Notification/Notification.js +0 -66
  433. package/src/system/Notification/Notification.stories.jsx +0 -16
  434. package/src/system/Notification/index.js +0 -6
  435. package/src/system/ScreenReaderText/ScreenReaderText.js +0 -39
  436. package/src/system/Spinner/Spinner.js +0 -34
  437. package/src/system/Spinner/index.js +0 -6
  438. package/src/system/Table/TableRow.js +0 -50
  439. package/src/system/Table/index.js +0 -8
  440. package/src/system/Text/Text.js +0 -33
  441. package/src/system/Text/index.js +0 -6
  442. package/src/system/Tooltip/Tooltip.js +0 -79
  443. package/src/system/Tooltip/Tooltip.stories.jsx +0 -22
  444. package/test/fileMock.js +0 -1
  445. package/test/setupAfterEnv.js +0 -13
  446. package/test/setupTests.js +0 -4
  447. /package/.storybook/decorators/{withColorMode.jsx → withColorMode.tsx} +0 -0
  448. /package/src/system/Accordion/{Accordion.stories.jsx → Accordion.stories.tsx} +0 -0
  449. /package/src/system/Accordion/{index.js → index.ts} +0 -0
  450. /package/src/system/Flex/{Flex.stories.jsx → Flex.stories.tsx} +0 -0
  451. /package/src/system/Grid/{Grid.stories.jsx → Grid.stories.tsx} +0 -0
  452. /package/src/system/Notice/{Notice.stories.jsx → Notice.stories.tsx} +0 -0
  453. /package/src/system/Notice/{index.js → index.ts} +0 -0
  454. /package/src/system/Spinner/{Spinner.stories.jsx → Spinner.stories.tsx} +0 -0
  455. /package/src/system/Tooltip/{index.js → index.ts} +0 -0
@@ -1,386 +1,391 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.FormAutocomplete = void 0;
5
- var _react = _interopRequireWildcard(require("react"));
6
- var _propTypes = _interopRequireDefault(require("prop-types"));
7
- var _react2 = _interopRequireDefault(require("accessible-autocomplete/react"));
8
- var _classnames = _interopRequireDefault(require("classnames"));
9
- var _FormAutocomplete = _interopRequireDefault(require("./FormAutocomplete.css"));
10
- exports.css = _FormAutocomplete["default"];
11
- var _FormSelectContent = require("./FormSelectContent");
12
- var _FormSelectArrow = require("./FormSelectArrow");
13
- var _Label = require("../Form/Label");
14
- var _FormSelectSearch = require("./FormSelectSearch");
15
- var _FormSelectLoading = require("./FormSelectLoading");
16
- var _Input = require("../Form/Input.styles");
17
- var _Form = require("../Form");
18
- var _jsxRuntime = require("theme-ui/jsx-runtime");
19
- var _excluded = ["autoFilter", "className", "debounce", "displayMenu", "dropdownArrow", "forLabel", "getOptionLabel", "getOptionValue", "errorMessage", "hasError", "isInline", "label", "loading", "minLength", "noOptionsMessage", "onChange", "onInputChange", "options", "required", "searchIcon", "showAllValues", "resetOnBlur", "source", "value"];
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
24
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /** @jsxImportSource theme-ui */ /**
25
- * External dependencies
26
- */ /**
27
- * Internal dependencies
28
- */
29
- var baseBorderTextColors = _extends({}, _Input.baseControlBorderStyle, {
30
- backgroundColor: _Input.inputBaseBackground,
31
- color: _Input.inputBaseText,
32
- borderRadius: 1
33
- });
34
- var defaultStyles = _extends({
35
- width: '100%',
36
- mb: 2
37
- }, baseBorderTextColors, {
38
- py: 0,
39
- minHeight: '36px',
40
- lineHeight: '36px',
41
- '&:focus': function focus(theme) {
42
- return theme.outline;
43
- },
44
- '&:focus-visible': function focusVisible(theme) {
45
- return theme.outline;
46
- },
47
- '&:focus-within': function focusWithin(theme) {
48
- return theme.outline;
49
- },
50
- '&.autocomplete__input--focused': function autocomplete__inputFocused(theme) {
51
- return theme.outline;
52
- },
53
- '& .autocomplete__input': {
54
- width: '100%',
55
- paddingLeft: 3,
56
- py: 0,
57
- borderWidth: 0,
58
- color: 'text',
59
- minHeight: '36px',
60
- lineHeight: '36px',
61
- '&:focus': {
62
- outlineWidth: 0,
63
- boxShadow: 'none'
64
- },
65
- '&:focus-visible': {
66
- outlineWidth: 0,
67
- boxShadow: 'none'
68
- },
69
- '&:focus-within': {
70
- outlineWidth: 0,
71
- boxShadow: 'none'
72
- },
73
- '&.autocomplete__input--focused': {
74
- outlineWidth: 0,
75
- boxShadow: 'none'
76
- },
77
- '&.autocomplete__input--show-all-values': {
78
- paddingRight: '40px'
79
- }
80
- },
81
- '& .autocomplete__menu': _extends({}, baseBorderTextColors),
82
- '& .autocomplete__hint, & .autocomplete__input, & .autocomplete__option': {
83
- fontSize: 'inherit'
84
- },
85
- '& .autocomplete__wrapper': {
86
- width: '100%'
87
- },
88
- '& .autocomplete__option': {
89
- borderColor: _Input.baseControlBorderStyle.borderColor
90
- },
91
- '& .autocomplete__option--odd': {
92
- bg: 'backgroundSecondary'
93
- },
94
- '& .autocomplete__option:hover, & .autocomplete__option--focused': {
95
- bg: 'midnight',
96
- borderColor: 'midnight'
97
- },
98
- '& .autocomplete__input--show-all-values': {
99
- paddingRight: 0
100
- },
101
- '& .autocomplete__hint': {
102
- border: 'none',
103
- paddingLeft: 3,
104
- minHeight: '27px',
105
- lineHeight: '27px'
106
- }
107
- });
108
- var inlineStyles = {
109
- borderWidth: 0
1
+ /** @jsxImportSource theme-ui */
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import Autocomplete from 'accessible-autocomplete/react';
9
+ import classNames from 'classnames';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import './FormAutocomplete.css';
15
+ import { FormSelectContent } from './FormSelectContent';
16
+ import { FormSelectArrow } from './FormSelectArrow';
17
+ import { Label } from '../Form/Label';
18
+ import { FormSelectSearch } from './FormSelectSearch';
19
+ import { FormSelectLoading } from './FormSelectLoading';
20
+ import { baseControlBorderStyle, inputBaseBackground, inputBaseText } from '../Form/Input.styles';
21
+ import { Validation } from '../Form';
22
+
23
+ const baseBorderTextColors = {
24
+ ...baseControlBorderStyle,
25
+ backgroundColor: inputBaseBackground,
26
+ color: inputBaseText,
27
+ borderRadius: 1,
110
28
  };
111
- var searchIconStyles = {
112
- '& .autocomplete__input.autocomplete__input': {
113
- paddingLeft: 4
114
- }
29
+
30
+ const defaultStyles = {
31
+ width: '100%',
32
+ mb: 2,
33
+ ...baseBorderTextColors,
34
+
35
+ py: 0,
36
+ minHeight: '36px',
37
+ lineHeight: '36px',
38
+ '&:focus': theme => theme.outline,
39
+ '&:focus-visible': theme => theme.outline,
40
+ '&:focus-within': theme => theme.outline,
41
+ '&.autocomplete__input--focused': theme => theme.outline,
42
+ '& .autocomplete__input': {
43
+ width: '100%',
44
+ paddingLeft: 3,
45
+ py: 0,
46
+ borderWidth: 0,
47
+ color: 'text',
48
+ minHeight: '36px',
49
+ lineHeight: '36px',
50
+ '&:focus': { outlineWidth: 0, boxShadow: 'none' },
51
+ '&:focus-visible': { outlineWidth: 0, boxShadow: 'none' },
52
+ '&:focus-within': { outlineWidth: 0, boxShadow: 'none' },
53
+ '&.autocomplete__input--focused': { outlineWidth: 0, boxShadow: 'none' },
54
+ '&.autocomplete__input--show-all-values': { paddingRight: '40px' },
55
+ },
56
+ '& .autocomplete__menu': {
57
+ ...baseBorderTextColors,
58
+ },
59
+ '& .autocomplete__hint, & .autocomplete__input, & .autocomplete__option': {
60
+ fontSize: 'inherit',
61
+ },
62
+ '& .autocomplete__wrapper': {
63
+ width: '100%',
64
+ },
65
+ '& .autocomplete__option': {
66
+ borderColor: baseControlBorderStyle.borderColor,
67
+ },
68
+ '& .autocomplete__option--odd': {
69
+ bg: 'backgroundSecondary',
70
+ },
71
+ '& .autocomplete__option:hover, & .autocomplete__option--focused': {
72
+ bg: 'midnight',
73
+ borderColor: 'midnight',
74
+ },
75
+ '& .autocomplete__input--show-all-values': {
76
+ paddingRight: 0,
77
+ },
78
+ '& .autocomplete__hint': {
79
+ border: 'none',
80
+ paddingLeft: 3,
81
+ minHeight: '27px',
82
+ lineHeight: '27px',
83
+ },
115
84
  };
116
- var DefaultArrow = function DefaultArrow(config) {
117
- return (0, _jsxRuntime.jsx)(_FormSelectArrow.FormSelectArrow, {
118
- classNames: config.className
119
- });
85
+
86
+ const inlineStyles = {
87
+ borderWidth: 0,
88
+ };
89
+
90
+ const searchIconStyles = {
91
+ '& .autocomplete__input.autocomplete__input': {
92
+ paddingLeft: 4,
93
+ },
120
94
  };
121
- var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRef) {
122
- var _ref$autoFilter = _ref.autoFilter,
123
- autoFilter = _ref$autoFilter === void 0 ? true : _ref$autoFilter,
124
- className = _ref.className,
125
- _ref$debounce = _ref.debounce,
126
- debounce = _ref$debounce === void 0 ? 0 : _ref$debounce,
127
- _ref$displayMenu = _ref.displayMenu,
128
- displayMenu = _ref$displayMenu === void 0 ? 'overlay' : _ref$displayMenu,
129
- _ref$dropdownArrow = _ref.dropdownArrow,
130
- dropdownArrow = _ref$dropdownArrow === void 0 ? DefaultArrow : _ref$dropdownArrow,
131
- _ref$forLabel = _ref.forLabel,
132
- forLabel = _ref$forLabel === void 0 ? 'vip-autocomplete' : _ref$forLabel,
133
- getOptionLabel = _ref.getOptionLabel,
134
- getOptionValue = _ref.getOptionValue,
135
- errorMessage = _ref.errorMessage,
136
- hasError = _ref.hasError,
137
- isInline = _ref.isInline,
138
- label = _ref.label,
139
- loading = _ref.loading,
140
- _ref$minLength = _ref.minLength,
141
- minLength = _ref$minLength === void 0 ? 0 : _ref$minLength,
142
- _ref$noOptionsMessage = _ref.noOptionsMessage,
143
- noOptionsMessage = _ref$noOptionsMessage === void 0 ? function () {
144
- return 'No results found. Type to search.';
145
- } : _ref$noOptionsMessage,
146
- _ref$onChange = _ref.onChange,
147
- onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
148
- onInputChange = _ref.onInputChange,
149
- _ref$options = _ref.options,
150
- options = _ref$options === void 0 ? [] : _ref$options,
151
- required = _ref.required,
152
- searchIcon = _ref.searchIcon,
153
- _ref$showAllValues = _ref.showAllValues,
154
- showAllValues = _ref$showAllValues === void 0 ? false : _ref$showAllValues,
155
- _ref$resetOnBlur = _ref.resetOnBlur,
156
- resetOnBlur = _ref$resetOnBlur === void 0 ? false : _ref$resetOnBlur,
157
- source = _ref.source,
158
- value = _ref.value,
159
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
160
- var _useState = (0, _react.useState)(false),
161
- isDirty = _useState[0],
162
- setIsDirty = _useState[1];
163
- var _useState2 = (0, _react.useState)(null),
164
- sourceDebounceTimeout = _useState2[0],
165
- setSourceDebounceTimeout = _useState2[1];
166
- var _useState3 = (0, _react.useState)(value || ''),
167
- selectedValue = _useState3[0],
168
- setSelectedValue = _useState3[1];
169
- var _useState4 = (0, _react.useState)(value),
170
- inputQuery = _useState4[0],
171
- setInputQuery = _useState4[1];
172
- var debounceTimeout;
173
- if (!forwardRef) {
174
- forwardRef = /*#__PURE__*/_react["default"].createRef();
175
- }
176
- var SelectLabel = function SelectLabel() {
177
- return (0, _jsxRuntime.jsx)(_Label.Label, {
178
- required: required,
179
- htmlFor: forLabel,
180
- children: label
181
- });
182
- };
183
- var inlineLabel = !!(isInline && label);
184
- var optionLabel = (0, _react.useCallback)(function (option) {
185
- return getOptionLabel ? getOptionLabel(option) : option.label;
186
- }, [getOptionLabel]);
187
- var getAllOptions = (0, _react.useMemo)(function () {
188
- return [].concat(options.filter(function (option) {
189
- return !option.options;
190
- }), options.filter(function (option) {
191
- return option.options;
192
- }).map(function (option) {
193
- return option.options;
194
- })).reduce(function (a, b) {
195
- return a.concat(b);
196
- }, []);
197
- }, [options]);
198
- var getOptionByLabel = (0, _react.useCallback)(function (inputValue) {
199
- return getAllOptions.find(function (option) {
200
- return "" + optionLabel(option) === "" + inputValue;
201
- });
202
- }, [getAllOptions, optionLabel]);
203
- /**
204
- * Reset the underlying component state to show the selected value
205
- */
206
- var resetInputState = (0, _react.useCallback)(function () {
207
- var _forwardRef;
208
- if (resetOnBlur && (_forwardRef = forwardRef) != null && _forwardRef.current && inputQuery !== selectedValue) {
209
- // resets the input field to the selected value or the empty string
210
- forwardRef.current.setState(_extends({}, forwardRef.current.state, {
211
- query: inputQuery && inputQuery !== '' ? selectedValue != null ? selectedValue : '' : '' // selected value should not be null or the component will crash
212
- }));
213
- }
214
- }, [forwardRef]);
215
- // sets the internal state variables and calls the onChange callback
216
- var setAutocompleteState = function setAutocompleteState(inputValue) {
217
- setInputQuery(inputValue);
218
- setSelectedValue(inputValue);
219
- onChange(getOptionByLabel(inputValue), inputValue);
220
- setIsDirty(false);
221
- };
222
- // this method gets called when we confirm the selection via click/enter
223
- var onValueChange = (0, _react.useCallback)(function (inputValue) {
224
- if (inputValue) {
225
- setAutocompleteState(inputValue);
226
- } else if (resetOnBlur && inputQuery !== selectedValue) {
227
- if (inputQuery && inputQuery !== '') {
228
- // reset the content to the selected value
229
- setAutocompleteState(selectedValue);
230
- } else {
231
- // reset the content to empty if there's no match
232
- setAutocompleteState(null);
233
- }
234
- }
235
- }, [onChange, getOptionByLabel, setAutocompleteState]);
236
- var handleTypeChange = (0, _react.useCallback)(function (query) {
237
- return options.filter(function (option) {
238
- return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
239
- });
240
- }, [options]);
241
- var handleInputChange = (0, _react.useCallback)(function (query) {
242
- if (!debounce) {
243
- return onInputChange(query);
244
- }
245
- clearTimeout(debounceTimeout);
246
- if (!query.length || query.length >= minLength) {
247
- debounceTimeout = setTimeout(function () {
248
- onInputChange(query);
249
- }, debounce);
250
- }
251
- }, [onInputChange, debounce, minLength]);
252
- var suggest = (0, _react.useCallback)(function (query, populateResults) {
253
- var _data;
254
- var data = options;
255
- if (isDirty && onInputChange) {
256
- handleInputChange(query);
257
- }
258
- if (isDirty && autoFilter) {
259
- data = handleTypeChange(query);
260
- }
261
- populateResults((_data = data) == null ? void 0 : _data.map(function (option) {
262
- return optionLabel(option);
263
- }));
264
- }, [autoFilter, isDirty, onInputChange, options]);
265
- // internal function to save the inputQuery
266
- var handleSource = function handleSource(query, populateResults) {
267
- setInputQuery(query);
268
- // user function to fetch the results has the precedence
269
- if (source) {
270
- if (!debounce) {
271
- source(query, populateResults);
272
- return;
273
- }
274
- if (sourceDebounceTimeout) {
275
- clearTimeout(sourceDebounceTimeout);
276
- setSourceDebounceTimeout(null);
277
- }
278
- if (!query.length || query.length >= minLength) {
279
- setSourceDebounceTimeout(setTimeout(function () {
280
- source(query, populateResults);
281
- setSourceDebounceTimeout(null);
282
- }, debounce));
283
- }
284
- } else {
285
- suggest(query, populateResults);
286
- }
287
- };
288
- (0, _react.useEffect)(function () {
289
- global.document.querySelector('.autocomplete__input').setAttribute('aria-activedescendant', '');
290
- }, []);
291
- (0, _react.useEffect)(function () {
292
- global.document.querySelector('.autocomplete__menu').setAttribute('aria-label', label + " list");
293
- }, [label]);
294
- (0, _react.useEffect)(function () {
295
- var input = global.document.querySelector("#" + forLabel);
296
- if (!input || required === undefined) {
297
- return;
298
- }
299
- input.setAttribute('aria-required', required);
300
- }, [required]);
301
- (0, _react.useEffect)(function () {
302
- global.document.querySelector("#" + forLabel).addEventListener('keydown', function (e) {
303
- // pressed escape, we want to reset the status
304
- if (e.keyCode === 27 && resetOnBlur) {
305
- resetInputState();
306
- } else {
307
- setIsDirty(true);
308
- }
309
- });
310
- }, [setIsDirty]);
311
-
312
- // For accessibility, we need to add the error message to the aria-describedby attribute
313
- (0, _react.useEffect)(function () {
314
- var input = global.document.querySelector("#" + forLabel);
315
- input == null ? void 0 : input.setAttribute('aria-describedby', "describe-" + forLabel + "-validation " + input.getAttribute('aria-describedby'));
316
- }, []);
317
- (0, _react.useEffect)(function () {
318
- global.document.querySelector("#" + forLabel).addEventListener('blur', function () {
319
- setInputQuery(global.document.querySelector("#" + forLabel).value);
320
- resetInputState();
321
- });
322
- }, [forwardRef]);
323
- return (0, _jsxRuntime.jsxs)("div", {
324
- className: (0, _classnames["default"])('vip-form-autocomplete-component', className),
325
- children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
326
- sx: _extends({}, defaultStyles, isInline && inlineStyles, searchIcon && searchIconStyles, hasError ? {
327
- borderColor: 'input.border.error'
328
- } : {}),
329
- children: (0, _jsxRuntime.jsxs)(_FormSelectContent.FormSelectContent, {
330
- isInline: inlineLabel,
331
- label: inlineLabel ? (0, _jsxRuntime.jsx)(SelectLabel, {}) : null,
332
- children: [searchIcon && (0, _jsxRuntime.jsx)(_FormSelectSearch.FormSelectSearch, {}), (0, _jsxRuntime.jsx)(_react2["default"], _extends({
333
- id: forLabel,
334
- "aria-busy": loading,
335
- showAllValues: showAllValues,
336
- ref: forwardRef,
337
- source: handleSource,
338
- defaultValue: value,
339
- displayMenu: displayMenu,
340
- onConfirm: onValueChange,
341
- tNoResults: noOptionsMessage,
342
- required: required,
343
- dropdownArrow: showAllValues ? dropdownArrow : function () {
344
- return '';
345
- }
346
- }, props)), loading && (0, _jsxRuntime.jsx)(_FormSelectLoading.FormSelectLoading, {
347
- sx: {
348
- right: showAllValues ? 40 : 10
349
- }
350
- })]
351
- })
352
- }), hasError && errorMessage && (0, _jsxRuntime.jsx)(_Form.Validation, {
353
- isValid: false,
354
- describedId: forLabel,
355
- children: errorMessage
356
- })]
357
- });
358
- });
359
- exports.FormAutocomplete = FormAutocomplete;
95
+
96
+ const DefaultArrow = config => <FormSelectArrow classNames={ config.className } />;
97
+
98
+ const FormAutocomplete = React.forwardRef(
99
+ (
100
+ {
101
+ autoFilter = true,
102
+ className,
103
+ debounce = 0,
104
+ displayMenu = 'overlay',
105
+ dropdownArrow = DefaultArrow,
106
+ forLabel = 'vip-autocomplete',
107
+ getOptionLabel,
108
+ getOptionValue,
109
+ errorMessage,
110
+ hasError,
111
+ isInline,
112
+ label,
113
+ loading,
114
+ minLength = 0,
115
+ noOptionsMessage = () => 'No results found. Type to search.',
116
+ onChange = () => {},
117
+ onInputChange,
118
+ options = [],
119
+ required,
120
+ searchIcon,
121
+ showAllValues = false,
122
+ resetOnBlur = false, // resets the input value to the selection if the input is blurred. Returns null if selection is empty
123
+ source,
124
+ value,
125
+ ...props
126
+ },
127
+ forwardRef
128
+ ) => {
129
+ const [ isDirty, setIsDirty ] = useState( false );
130
+ const [ sourceDebounceTimeout, setSourceDebounceTimeout ] = useState( null );
131
+ const [ selectedValue, setSelectedValue ] = useState( value || '' );
132
+ const [ inputQuery, setInputQuery ] = useState( value );
133
+ let debounceTimeout;
134
+ if ( ! forwardRef ) {
135
+ forwardRef = React.createRef();
136
+ }
137
+
138
+ const SelectLabel = () => (
139
+ <Label required={ required } htmlFor={ forLabel }>
140
+ { label }
141
+ </Label>
142
+ );
143
+
144
+ const inlineLabel = !! ( isInline && label );
145
+
146
+ const optionLabel = useCallback(
147
+ option => ( getOptionLabel ? getOptionLabel( option ) : option.label ),
148
+ [ getOptionLabel ]
149
+ );
150
+
151
+ const getAllOptions = useMemo(
152
+ () =>
153
+ [
154
+ ...options.filter( option => ! option.options ),
155
+ ...options.filter( option => option.options ).map( option => option.options ),
156
+ ].reduce( ( a, b ) => a.concat( b ), [] ),
157
+ [ options ]
158
+ );
159
+
160
+ const getOptionByLabel = useCallback(
161
+ inputValue =>
162
+ getAllOptions.find( option => `${ optionLabel( option ) }` === `${ inputValue }` ),
163
+ [ getAllOptions, optionLabel ]
164
+ );
165
+ /**
166
+ * Reset the underlying component state to show the selected value
167
+ */
168
+ const resetInputState = useCallback( () => {
169
+ if ( resetOnBlur && forwardRef?.current && inputQuery !== selectedValue ) {
170
+ // resets the input field to the selected value or the empty string
171
+ forwardRef.current.setState( {
172
+ ...forwardRef.current.state,
173
+ query: inputQuery && inputQuery !== '' ? selectedValue ?? '' : '', // selected value should not be null or the component will crash
174
+ } );
175
+ }
176
+ }, [ forwardRef ] );
177
+ // sets the internal state variables and calls the onChange callback
178
+ const setAutocompleteState = inputValue => {
179
+ setInputQuery( inputValue );
180
+ setSelectedValue( inputValue );
181
+ onChange( getOptionByLabel( inputValue ), inputValue );
182
+ setIsDirty( false );
183
+ };
184
+ // this method gets called when we confirm the selection via click/enter
185
+ const onValueChange = useCallback(
186
+ inputValue => {
187
+ if ( inputValue ) {
188
+ setAutocompleteState( inputValue );
189
+ } else if ( resetOnBlur && inputQuery !== selectedValue ) {
190
+ if ( inputQuery && inputQuery !== '' ) {
191
+ // reset the content to the selected value
192
+ setAutocompleteState( selectedValue );
193
+ } else {
194
+ // reset the content to empty if there's no match
195
+ setAutocompleteState( null );
196
+ }
197
+ }
198
+ },
199
+ [ onChange, getOptionByLabel, setAutocompleteState ]
200
+ );
201
+
202
+ const handleTypeChange = useCallback(
203
+ query => {
204
+ return options.filter(
205
+ option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
206
+ );
207
+ },
208
+ [ options ]
209
+ );
210
+
211
+ const handleInputChange = useCallback(
212
+ query => {
213
+ if ( ! debounce ) {
214
+ return onInputChange( query );
215
+ }
216
+ clearTimeout( debounceTimeout );
217
+
218
+ if ( ! query.length || query.length >= minLength ) {
219
+ debounceTimeout = setTimeout( () => {
220
+ onInputChange( query );
221
+ }, debounce );
222
+ }
223
+ },
224
+ [ onInputChange, debounce, minLength ]
225
+ );
226
+
227
+ const suggest = useCallback(
228
+ ( query, populateResults ) => {
229
+ let data = options;
230
+ if ( isDirty && onInputChange ) {
231
+ handleInputChange( query );
232
+ }
233
+ if ( isDirty && autoFilter ) {
234
+ data = handleTypeChange( query );
235
+ }
236
+ populateResults( data?.map( option => optionLabel( option ) ) );
237
+ },
238
+ [ autoFilter, isDirty, onInputChange, options ]
239
+ );
240
+ // internal function to save the inputQuery
241
+ const handleSource = ( query, populateResults ) => {
242
+ setInputQuery( query );
243
+ // user function to fetch the results has the precedence
244
+ if ( source ) {
245
+ if ( ! debounce ) {
246
+ source( query, populateResults );
247
+ return;
248
+ }
249
+ if ( sourceDebounceTimeout ) {
250
+ clearTimeout( sourceDebounceTimeout );
251
+ setSourceDebounceTimeout( null );
252
+ }
253
+
254
+ if ( ! query.length || query.length >= minLength ) {
255
+ setSourceDebounceTimeout(
256
+ setTimeout( () => {
257
+ source( query, populateResults );
258
+ setSourceDebounceTimeout( null );
259
+ }, debounce )
260
+ );
261
+ }
262
+ } else {
263
+ suggest( query, populateResults );
264
+ }
265
+ };
266
+ useEffect( () => {
267
+ global.document
268
+ .querySelector( '.autocomplete__input' )
269
+ .setAttribute( 'aria-activedescendant', '' );
270
+ }, [] );
271
+
272
+ useEffect( () => {
273
+ global.document
274
+ .querySelector( '.autocomplete__menu' )
275
+ .setAttribute( 'aria-label', `${ label } list` );
276
+ }, [ label ] );
277
+
278
+ useEffect( () => {
279
+ const input = global.document.querySelector( `#${ forLabel }` );
280
+
281
+ if ( ! input || required === undefined ) {
282
+ return;
283
+ }
284
+
285
+ input.setAttribute( 'aria-required', required );
286
+ }, [ required ] );
287
+
288
+ useEffect( () => {
289
+ global.document.querySelector( `#${ forLabel }` ).addEventListener( 'keydown', e => {
290
+ // pressed escape, we want to reset the status
291
+ if ( e.keyCode === 27 && resetOnBlur ) {
292
+ resetInputState();
293
+ } else {
294
+ setIsDirty( true );
295
+ }
296
+ } );
297
+ }, [ setIsDirty ] );
298
+
299
+ // For accessibility, we need to add the error message to the aria-describedby attribute
300
+ useEffect( () => {
301
+ const input = global.document.querySelector( `#${ forLabel }` );
302
+
303
+ input?.setAttribute(
304
+ 'aria-describedby',
305
+ `describe-${ forLabel }-validation ${ input.getAttribute( 'aria-describedby' ) }`
306
+ );
307
+ }, [] );
308
+
309
+ useEffect( () => {
310
+ global.document.querySelector( `#${ forLabel }` ).addEventListener( 'blur', () => {
311
+ setInputQuery( global.document.querySelector( `#${ forLabel }` ).value );
312
+ resetInputState();
313
+ } );
314
+ }, [ forwardRef ] );
315
+ return (
316
+ <div className={ classNames( 'vip-form-autocomplete-component', className ) }>
317
+ { label && ! isInline && <SelectLabel /> }
318
+
319
+ <div
320
+ sx={ {
321
+ ...defaultStyles,
322
+ ...( isInline && inlineStyles ),
323
+ ...( searchIcon && searchIconStyles ),
324
+ ...( hasError ? { borderColor: 'input.border.error' } : {} ),
325
+ } }
326
+ >
327
+ <FormSelectContent
328
+ isInline={ inlineLabel }
329
+ label={ inlineLabel ? <SelectLabel /> : null }
330
+ >
331
+ { searchIcon && <FormSelectSearch /> }
332
+
333
+ <Autocomplete
334
+ id={ forLabel }
335
+ aria-busy={ loading }
336
+ showAllValues={ showAllValues }
337
+ ref={ forwardRef }
338
+ source={ handleSource }
339
+ defaultValue={ value }
340
+ displayMenu={ displayMenu }
341
+ onConfirm={ onValueChange }
342
+ tNoResults={ noOptionsMessage }
343
+ required={ required }
344
+ dropdownArrow={ showAllValues ? dropdownArrow : () => '' }
345
+ { ...props }
346
+ />
347
+
348
+ { loading && <FormSelectLoading sx={ { right: showAllValues ? 40 : 10 } } /> }
349
+ </FormSelectContent>
350
+ </div>
351
+
352
+ { hasError && errorMessage && (
353
+ <Validation isValid={ false } describedId={ forLabel }>
354
+ { errorMessage }
355
+ </Validation>
356
+ ) }
357
+ </div>
358
+ );
359
+ }
360
+ );
361
+
360
362
  FormAutocomplete.propTypes = {
361
- autoFilter: _propTypes["default"].bool,
362
- className: _propTypes["default"].any,
363
- debounce: _propTypes["default"].number,
364
- displayMenu: _propTypes["default"].string,
365
- errorMessage: _propTypes["default"].string,
366
- forLabel: _propTypes["default"].string,
367
- getOptionLabel: _propTypes["default"].func,
368
- getOptionValue: _propTypes["default"].func,
369
- hasError: _propTypes["default"].bool,
370
- isInline: _propTypes["default"].bool,
371
- label: _propTypes["default"].string,
372
- loading: _propTypes["default"].bool,
373
- minLength: _propTypes["default"].number,
374
- noOptionsMessage: _propTypes["default"].func,
375
- onChange: _propTypes["default"].func,
376
- onInputChange: _propTypes["default"].func,
377
- options: _propTypes["default"].array,
378
- required: _propTypes["default"].bool,
379
- searchIcon: _propTypes["default"].bool,
380
- showAllValues: _propTypes["default"].bool,
381
- resetOnBlur: _propTypes["default"].bool,
382
- source: _propTypes["default"].func,
383
- value: _propTypes["default"].string,
384
- dropdownArrow: _propTypes["default"].node
363
+ autoFilter: PropTypes.bool,
364
+ className: PropTypes.any,
365
+ debounce: PropTypes.number,
366
+ displayMenu: PropTypes.string,
367
+ errorMessage: PropTypes.string,
368
+ forLabel: PropTypes.string,
369
+ getOptionLabel: PropTypes.func,
370
+ getOptionValue: PropTypes.func,
371
+ hasError: PropTypes.bool,
372
+ isInline: PropTypes.bool,
373
+ label: PropTypes.string,
374
+ loading: PropTypes.bool,
375
+ minLength: PropTypes.number,
376
+ noOptionsMessage: PropTypes.func,
377
+ onChange: PropTypes.func,
378
+ onInputChange: PropTypes.func,
379
+ options: PropTypes.array,
380
+ required: PropTypes.bool,
381
+ searchIcon: PropTypes.bool,
382
+ showAllValues: PropTypes.bool,
383
+ resetOnBlur: PropTypes.bool,
384
+ source: PropTypes.func,
385
+ value: PropTypes.string,
386
+ dropdownArrow: PropTypes.node,
385
387
  };
386
- FormAutocomplete.displayName = 'FormAutocomplete';
388
+
389
+ FormAutocomplete.displayName = 'FormAutocomplete';
390
+
391
+ export { FormAutocomplete };