@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,479 +1,467 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.FormAutocompleteMultiselect = 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 _FormSelectContent = require("./FormSelectContent");
10
- var _FormSelectArrow = require("./FormSelectArrow");
11
- var _Label = require("../Form/Label");
12
- var _FormSelectSearch = require("./FormSelectSearch");
13
- var _FormSelectLoading = require("./FormSelectLoading");
14
- var _Input = require("../Form/Input.styles");
15
- var _Form = require("../Form");
16
- var _ = require("../");
17
- var _md = require("react-icons/md");
18
- var _jsxRuntime = require("theme-ui/jsx-runtime");
19
- var _excluded = ["autoFilter", "className", "debounce", "displayMenu", "dropdownArrow", "errorMessage", "forLabel", "getOptionLabel", "getOptionValue", "hasError", "isInline", "label", "loading", "minLength", "noOptionsMessage", "onChange", "onInputChange", "options", "required", "searchIcon", "showAllValues", "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
- }, baseBorderTextColors, {
37
- py: 0,
38
- minHeight: '36px',
39
- lineHeight: '36px',
40
- '&:focus': function focus(theme) {
41
- return theme.outline;
42
- },
43
- '&:focus-visible': function focusVisible(theme) {
44
- return theme.outline;
45
- },
46
- '&:focus-within': function focusWithin(theme) {
47
- return theme.outline;
48
- },
49
- '&.autocomplete__input--focused': function autocomplete__inputFocused(theme) {
50
- return theme.outline;
51
- },
52
- '& .autocomplete__input': {
53
- width: '100%',
54
- paddingLeft: 3,
55
- py: 0,
56
- borderWidth: 0,
57
- color: 'text',
58
- minHeight: '36px',
59
- lineHeight: '36px',
60
- '&:focus': {
61
- outlineWidth: 0,
62
- boxShadow: 'none'
63
- },
64
- '&:focus-visible': {
65
- outlineWidth: 0,
66
- boxShadow: 'none'
67
- },
68
- '&:focus-within': {
69
- outlineWidth: 0,
70
- boxShadow: 'none'
71
- },
72
- '&.autocomplete__input--focused': {
73
- outlineWidth: 0,
74
- boxShadow: 'none'
75
- },
76
- '&.autocomplete__input--show-all-values': {
77
- paddingRight: '40px'
78
- },
79
- '&::placeholder': {
80
- color: 'input.text.placeholder',
81
- opacity: 1
82
- }
83
- },
84
- '& .autocomplete__menu': _extends({}, baseBorderTextColors),
85
- '& .autocomplete__hint, & .autocomplete__input, & .autocomplete__option': {
86
- fontSize: 'inherit'
87
- },
88
- '& .autocomplete__wrapper': {
89
- width: '100%'
90
- },
91
- '& .autocomplete__option': {
92
- borderColor: _Input.baseControlBorderStyle.borderColor
93
- },
94
- '& .autocomplete__option--odd': {
95
- bg: 'backgroundSecondary'
96
- },
97
- '& .autocomplete__option:hover, & .autocomplete__option--focused': {
98
- bg: 'midnight',
99
- borderColor: 'midnight'
100
- },
101
- '& .autocomplete__input--show-all-values': {
102
- paddingRight: 0
103
- },
104
- '& .autocomplete__hint': {
105
- border: 'none',
106
- paddingLeft: 3,
107
- minHeight: '27px',
108
- lineHeight: '27px'
109
- }
110
- });
111
- var inlineStyles = {
112
- 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 { FormSelectContent } from './FormSelectContent';
15
+ import { FormSelectArrow } from './FormSelectArrow';
16
+ import { Label } from '../Form/Label';
17
+ import { FormSelectSearch } from './FormSelectSearch';
18
+ import { FormSelectLoading } from './FormSelectLoading';
19
+ import { baseControlBorderStyle, inputBaseBackground, inputBaseText } from '../Form/Input.styles';
20
+ import { Validation } from '../Form';
21
+ import { Button, Flex } from '../';
22
+ import { MdClose } from 'react-icons/md';
23
+
24
+ const baseBorderTextColors = {
25
+ ...baseControlBorderStyle,
26
+ backgroundColor: inputBaseBackground,
27
+ color: inputBaseText,
28
+ borderRadius: 1,
29
+ };
30
+
31
+ const defaultStyles = {
32
+ width: '100%',
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
+ '&::placeholder': {
56
+ color: 'input.text.placeholder',
57
+ opacity: 1,
58
+ },
59
+ },
60
+ '& .autocomplete__menu': {
61
+ ...baseBorderTextColors,
62
+ },
63
+ '& .autocomplete__hint, & .autocomplete__input, & .autocomplete__option': {
64
+ fontSize: 'inherit',
65
+ },
66
+ '& .autocomplete__wrapper': {
67
+ width: '100%',
68
+ },
69
+ '& .autocomplete__option': {
70
+ borderColor: baseControlBorderStyle.borderColor,
71
+ },
72
+ '& .autocomplete__option--odd': {
73
+ bg: 'backgroundSecondary',
74
+ },
75
+ '& .autocomplete__option:hover, & .autocomplete__option--focused': {
76
+ bg: 'midnight',
77
+ borderColor: 'midnight',
78
+ },
79
+ '& .autocomplete__input--show-all-values': {
80
+ paddingRight: 0,
81
+ },
82
+ '& .autocomplete__hint': {
83
+ border: 'none',
84
+ paddingLeft: 3,
85
+ minHeight: '27px',
86
+ lineHeight: '27px',
87
+ },
113
88
  };
114
- var searchIconStyles = {
115
- '& .autocomplete__input.autocomplete__input': {
116
- paddingLeft: 4
117
- }
89
+
90
+ const inlineStyles = {
91
+ borderWidth: 0,
118
92
  };
119
- var DefaultArrow = function DefaultArrow(config) {
120
- return (0, _jsxRuntime.jsx)(_FormSelectArrow.FormSelectArrow, {
121
- classNames: config.className
122
- });
93
+
94
+ const searchIconStyles = {
95
+ '& .autocomplete__input.autocomplete__input': {
96
+ paddingLeft: 4,
97
+ },
123
98
  };
124
- var AddSelectionStatus = function AddSelectionStatus(_ref) {
125
- var status = _ref.status;
126
- return (0, _jsxRuntime.jsx)("div", {
127
- sx: {
128
- border: '0',
129
- clip: 'rect(0 0 0 0)',
130
- height: '1px',
131
- marginBottom: '-1px',
132
- marginRight: '-1px',
133
- overflow: 'hidden',
134
- padding: '0',
135
- position: 'absolute',
136
- whiteSpace: 'nowrap',
137
- width: '1px'
138
- },
139
- id: "vip-autocompletemultiselect-status",
140
- role: "status",
141
- "aria-atomic": "true",
142
- "aria-live": "assertive",
143
- children: status
144
- });
99
+
100
+ const DefaultArrow = config => <FormSelectArrow classNames={ config.className } />;
101
+
102
+ const AddSelectionStatus = ( { status } ) => {
103
+ return (
104
+ <div
105
+ sx={ {
106
+ border: '0',
107
+ clip: 'rect(0 0 0 0)',
108
+ height: '1px',
109
+ marginBottom: '-1px',
110
+ marginRight: '-1px',
111
+ overflow: 'hidden',
112
+ padding: '0',
113
+ position: 'absolute',
114
+ whiteSpace: 'nowrap',
115
+ width: '1px',
116
+ } }
117
+ id="vip-autocompletemultiselect-status"
118
+ role="status"
119
+ aria-atomic="true"
120
+ aria-live="assertive"
121
+ >
122
+ { status }
123
+ </div>
124
+ );
145
125
  };
126
+
146
127
  AddSelectionStatus.propTypes = {
147
- status: _propTypes["default"].string.isRequired
128
+ status: PropTypes.string.isRequired,
148
129
  };
149
- var SelectedOptions = function SelectedOptions(_ref2) {
150
- var index = _ref2.index,
151
- option = _ref2.option,
152
- unselectValue = _ref2.unselectValue;
153
- return (0, _jsxRuntime.jsx)("div", {
154
- sx: {
155
- mr: 1,
156
- maxWidth: '100%'
157
- },
158
- children: (0, _jsxRuntime.jsxs)(_.Button, {
159
- variant: "tertiary",
160
- onClick: function onClick(e) {
161
- e.preventDefault();
162
- unselectValue(option, index);
163
- },
164
- sx: {
165
- mt: 1,
166
- fontSize: 1,
167
- maxWidth: '100%'
168
- },
169
- children: [(0, _jsxRuntime.jsx)("div", {
170
- sx: {
171
- overflow: 'hidden',
172
- textOverflow: 'ellipsis',
173
- whiteSpace: 'nowrap'
174
- },
175
- children: option
176
- }), (0, _jsxRuntime.jsx)(_md.MdClose, {
177
- sx: {
178
- ml: 2
179
- }
180
- })]
181
- })
182
- }, index);
130
+
131
+ const SelectedOptions = ( { index, option, unselectValue } ) => {
132
+ return (
133
+ <div key={ index } sx={ { mr: 1, maxWidth: '100%' } }>
134
+ <Button
135
+ variant="tertiary"
136
+ onClick={ e => {
137
+ e.preventDefault();
138
+ unselectValue( option, index );
139
+ } }
140
+ sx={ {
141
+ mt: 1,
142
+ fontSize: 1,
143
+ maxWidth: '100%',
144
+ } }
145
+ >
146
+ <div
147
+ sx={ {
148
+ overflow: 'hidden',
149
+ textOverflow: 'ellipsis',
150
+ whiteSpace: 'nowrap',
151
+ } }
152
+ >
153
+ { option }
154
+ </div>
155
+ <MdClose sx={ { ml: 2 } } />
156
+ </Button>
157
+ </div>
158
+ );
183
159
  };
160
+
184
161
  SelectedOptions.propTypes = {
185
- index: _propTypes["default"].number.isRequired,
186
- option: _propTypes["default"].string.isRequired,
187
- unselectValue: _propTypes["default"].func.isRequired
162
+ index: PropTypes.number.isRequired,
163
+ option: PropTypes.string.isRequired,
164
+ unselectValue: PropTypes.func.isRequired,
188
165
  };
189
- var FormAutocompleteMultiselect = /*#__PURE__*/_react["default"].forwardRef(function (_ref3, forwardRef) {
190
- var _ref3$autoFilter = _ref3.autoFilter,
191
- autoFilter = _ref3$autoFilter === void 0 ? true : _ref3$autoFilter,
192
- className = _ref3.className,
193
- _ref3$debounce = _ref3.debounce,
194
- debounce = _ref3$debounce === void 0 ? 0 : _ref3$debounce,
195
- _ref3$displayMenu = _ref3.displayMenu,
196
- displayMenu = _ref3$displayMenu === void 0 ? 'overlay' : _ref3$displayMenu,
197
- _ref3$dropdownArrow = _ref3.dropdownArrow,
198
- dropdownArrow = _ref3$dropdownArrow === void 0 ? DefaultArrow : _ref3$dropdownArrow,
199
- errorMessage = _ref3.errorMessage,
200
- _ref3$forLabel = _ref3.forLabel,
201
- forLabel = _ref3$forLabel === void 0 ? 'vip-autocompletemultiselect' : _ref3$forLabel,
202
- getOptionLabel = _ref3.getOptionLabel,
203
- getOptionValue = _ref3.getOptionValue,
204
- hasError = _ref3.hasError,
205
- isInline = _ref3.isInline,
206
- label = _ref3.label,
207
- loading = _ref3.loading,
208
- _ref3$minLength = _ref3.minLength,
209
- minLength = _ref3$minLength === void 0 ? 0 : _ref3$minLength,
210
- _ref3$noOptionsMessag = _ref3.noOptionsMessage,
211
- noOptionsMessage = _ref3$noOptionsMessag === void 0 ? function () {
212
- return 'No results found. Type to search.';
213
- } : _ref3$noOptionsMessag,
214
- _ref3$onChange = _ref3.onChange,
215
- onChange = _ref3$onChange === void 0 ? function () {} : _ref3$onChange,
216
- onInputChange = _ref3.onInputChange,
217
- _ref3$options = _ref3.options,
218
- options = _ref3$options === void 0 ? [] : _ref3$options,
219
- required = _ref3.required,
220
- searchIcon = _ref3.searchIcon,
221
- _ref3$showAllValues = _ref3.showAllValues,
222
- showAllValues = _ref3$showAllValues === void 0 ? false : _ref3$showAllValues,
223
- source = _ref3.source,
224
- value = _ref3.value,
225
- props = _objectWithoutPropertiesLoose(_ref3, _excluded);
226
- var OPTION_ACTION = {
227
- ADD: 'add',
228
- REMOVE: 'remove',
229
- NONE: 'none'
230
- };
231
- var _useState = (0, _react.useState)(false),
232
- isDirty = _useState[0],
233
- setIsDirty = _useState[1];
234
- var _useState2 = (0, _react.useState)([]),
235
- selectedOptions = _useState2[0],
236
- setSelectedOptions = _useState2[1];
237
- var _useState3 = (0, _react.useState)(''),
238
- addStatus = _useState3[0],
239
- setAddStatus = _useState3[1];
240
- var _useState4 = (0, _react.useState)({
241
- action: OPTION_ACTION.NONE,
242
- option: null,
243
- index: -1
244
- }),
245
- currentOption = _useState4[0],
246
- setCurrentOption = _useState4[1];
247
- var debounceTimeout;
248
- forwardRef = forwardRef || /*#__PURE__*/_react["default"].createRef();
249
-
250
- /**
251
- * Reset the underlying component state to show the selected value
252
- */
253
- var resetInputState = (0, _react.useCallback)(function () {
254
- var _forwardRef;
255
- if ((_forwardRef = forwardRef) != null && _forwardRef.current) {
256
- // resets the input field to the selected value or the empty string
257
- forwardRef.current.setState(_extends({}, forwardRef.current.state, {
258
- query: '' // selected value should not be null or the component will crash
259
- }));
260
- }
261
- }, [forwardRef]);
262
- var SelectLabel = function SelectLabel() {
263
- return (0, _jsxRuntime.jsx)(_Label.Label, {
264
- required: required,
265
- htmlFor: forLabel,
266
- children: label
267
- });
268
- };
269
- var inlineLabel = !!(isInline && label);
270
- var optionLabel = (0, _react.useCallback)(function (option) {
271
- return getOptionLabel ? getOptionLabel(option) : option.label;
272
- }, [getOptionLabel]);
273
- var getOptionByLabel = (0, _react.useCallback)(function (inputValue) {
274
- return getAllOptions.find(function (option) {
275
- return "" + optionLabel(option) === "" + inputValue;
276
- });
277
- }, [getAllOptions, optionLabel]);
278
- var getAllOptions = (0, _react.useMemo)(function () {
279
- return [].concat(options.filter(function (option) {
280
- return !option.options;
281
- }), options.filter(function (option) {
282
- return option.options;
283
- }).map(function (option) {
284
- return option.options;
285
- })).reduce(function (a, b) {
286
- return a.concat(b);
287
- }, []);
288
- }, [options]);
289
- var onValueChange = (0, _react.useCallback)(function (inputValue) {
290
- if (inputValue && !selectedOptions.includes(inputValue)) {
291
- setCurrentOption({
292
- action: OPTION_ACTION.ADD,
293
- option: inputValue
294
- });
295
- setSelectedOptions([].concat(selectedOptions, [inputValue]));
296
- }
297
- }, [getOptionByLabel, setSelectedOptions, selectedOptions, setCurrentOption]);
298
- var unselectValue = (0, _react.useCallback)(function (inputValue, index) {
299
- if (inputValue) {
300
- setSelectedOptions(selectedOptions.filter(function (option) {
301
- return ((option == null ? void 0 : option.label) || option) !== inputValue;
302
- }));
303
- setCurrentOption({
304
- action: OPTION_ACTION.REMOVE,
305
- option: inputValue,
306
- index: index
307
- });
308
- }
309
- }, [getOptionByLabel, setSelectedOptions, selectedOptions, setCurrentOption]);
310
- var handleTypeChange = (0, _react.useCallback)(function (query) {
311
- return options.filter(function (option) {
312
- return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
313
- });
314
- }, [options]);
315
- var handleInputChange = (0, _react.useCallback)(function (query) {
316
- if (!debounce) {
317
- return onInputChange(query);
318
- }
319
- clearTimeout(debounceTimeout);
320
- if (!query.length || query.length >= minLength) {
321
- debounceTimeout = setTimeout(function () {
322
- onInputChange(query);
323
- }, debounce);
324
- }
325
- }, [onInputChange, debounce, minLength]);
326
- var suggest = (0, _react.useCallback)(function (query, populateResults) {
327
- var _data;
328
- var data = options;
329
- if (isDirty && onInputChange) {
330
- handleInputChange(query);
331
- }
332
- if (isDirty && autoFilter) {
333
- data = handleTypeChange(query);
334
- }
335
- var optionForDisplay = (_data = data) == null ? void 0 : _data.map(function (option) {
336
- return optionLabel(option);
337
- });
338
- populateResults(optionForDisplay.filter(function (option) {
339
- return !selectedOptions.includes(option);
340
- }));
341
- }, [autoFilter, isDirty, onInputChange, options, selectedOptions]);
342
- (0, _react.useEffect)(function () {
343
- global.document.querySelector('.autocomplete__input').removeAttribute('aria-activedescendant');
344
- }, []);
345
- (0, _react.useEffect)(function () {
346
- global.document.querySelector('.autocomplete__menu').setAttribute('aria-label', label + " list");
347
- }, [label]);
348
- (0, _react.useEffect)(function () {
349
- var input = global.document.querySelector("#" + forLabel);
350
- if (!input || required === undefined) {
351
- return;
352
- }
353
- input.setAttribute('aria-required', required);
354
- }, [required]);
355
- (0, _react.useEffect)(function () {
356
- global.document.querySelector("#" + forLabel).addEventListener('keydown', function () {
357
- setIsDirty(true);
358
- });
359
- }, [setIsDirty]);
360
-
361
- // For accessibility, we need to add the error message to the aria-describedby attribute
362
- (0, _react.useEffect)(function () {
363
- var input = global.document.querySelector("#" + forLabel);
364
- input == null ? void 0 : input.setAttribute('aria-describedby', "describe-" + forLabel + "-validation " + input.getAttribute('aria-describedby'));
365
- }, []);
366
-
367
- // Update selectedOption and reset the input state on select input change
368
-
369
- (0, _react.useEffect)(function () {
370
- onChange(selectedOptions, selectedOptions.map(function (option) {
371
- return (option == null ? void 0 : option.label) || option;
372
- }));
373
- resetInputState();
374
- }, [selectedOptions]);
375
-
376
- // Update the select status for screen readers
377
- (0, _react.useEffect)(function () {
378
- if (currentOption.action === OPTION_ACTION.ADD) {
379
- setAddStatus(currentOption.option + " added to the list.");
380
- setCurrentOption({
381
- action: OPTION_ACTION.NONE,
382
- option: null
383
- });
384
- } else if (currentOption.index === selectedOptions.length && selectedOptions.length > 0) {
385
- // Move focus to the first selected item, if the last element is removed and there are other elements in the list
386
- global.document.querySelector('.vip-button-component').focus();
387
- } else if (selectedOptions.length === 0) {
388
- // Move focus to the input field if the last element is removed and there are no other elements in the list
389
- global.document.querySelector('.autocomplete__input').focus();
390
- }
391
- }, [currentOption]);
392
- return (0, _jsxRuntime.jsxs)("div", {
393
- className: (0, _classnames["default"])('vip-form-autocomplete-component', className),
394
- children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
395
- sx: _extends({}, defaultStyles, isInline && inlineStyles, searchIcon && searchIconStyles),
396
- children: (0, _jsxRuntime.jsxs)(_FormSelectContent.FormSelectContent, {
397
- isInline: inlineLabel,
398
- label: inlineLabel ? (0, _jsxRuntime.jsx)(SelectLabel, {}) : null,
399
- children: [searchIcon && (0, _jsxRuntime.jsx)(_FormSelectSearch.FormSelectSearch, {}), (0, _jsxRuntime.jsx)(_react2["default"], _extends({
400
- id: forLabel,
401
- "aria-busy": loading,
402
- showAllValues: showAllValues,
403
- ref: forwardRef,
404
- source: source || suggest,
405
- defaultValue: value,
406
- displayMenu: displayMenu,
407
- onConfirm: onValueChange,
408
- tNoResults: noOptionsMessage,
409
- required: required,
410
- dropdownArrow: showAllValues ? dropdownArrow : function () {
411
- return '';
412
- },
413
- confirmOnBlur: false
414
- }, props)), addStatus && (0, _jsxRuntime.jsx)(AddSelectionStatus, {
415
- status: addStatus
416
- }), loading && (0, _jsxRuntime.jsx)(_FormSelectLoading.FormSelectLoading, {
417
- sx: {
418
- right: showAllValues ? 40 : 10
419
- }
420
- })]
421
- })
422
- }), (0, _jsxRuntime.jsxs)(_.Flex, {
423
- sx: {
424
- mt: 2,
425
- justifyContent: 'space-between'
426
- },
427
- children: [hasError && errorMessage && (0, _jsxRuntime.jsx)(_Form.Validation, {
428
- isValid: false,
429
- describedId: forLabel,
430
- children: errorMessage
431
- }), (0, _jsxRuntime.jsxs)("div", {
432
- sx: {
433
- fontSize: 1
434
- },
435
- children: [selectedOptions.length, " item", selectedOptions.length > 1 ? 's' : '', " selected"]
436
- })]
437
- }), (0, _jsxRuntime.jsx)("div", {
438
- sx: {
439
- display: 'inline-flex',
440
- flexWrap: 'wrap',
441
- maxWidth: '100%'
442
- },
443
- children: selectedOptions && selectedOptions.map(function (option, idx) {
444
- return (0, _jsxRuntime.jsx)(SelectedOptions, {
445
- index: idx,
446
- option: option,
447
- unselectValue: unselectValue
448
- }, idx);
449
- })
450
- })]
451
- });
452
- });
453
- exports.FormAutocompleteMultiselect = FormAutocompleteMultiselect;
166
+
167
+ const FormAutocompleteMultiselect = React.forwardRef(
168
+ (
169
+ {
170
+ autoFilter = true,
171
+ className,
172
+ debounce = 0,
173
+ displayMenu = 'overlay',
174
+ dropdownArrow = DefaultArrow,
175
+ errorMessage,
176
+ forLabel = 'vip-autocompletemultiselect',
177
+ getOptionLabel,
178
+ getOptionValue,
179
+ hasError,
180
+ isInline,
181
+ label,
182
+ loading,
183
+ minLength = 0,
184
+ noOptionsMessage = () => 'No results found. Type to search.',
185
+ onChange = () => {},
186
+ onInputChange,
187
+ options = [],
188
+ required,
189
+ searchIcon,
190
+ showAllValues = false,
191
+ source,
192
+ value,
193
+ ...props
194
+ },
195
+ forwardRef
196
+ ) => {
197
+ const OPTION_ACTION = {
198
+ ADD: 'add',
199
+ REMOVE: 'remove',
200
+ NONE: 'none',
201
+ };
202
+ const [ isDirty, setIsDirty ] = useState( false );
203
+ const [ selectedOptions, setSelectedOptions ] = useState( [] );
204
+ const [ addStatus, setAddStatus ] = useState( '' );
205
+ const [ currentOption, setCurrentOption ] = useState( {
206
+ action: OPTION_ACTION.NONE,
207
+ option: null,
208
+ index: -1,
209
+ } );
210
+ let debounceTimeout;
211
+ forwardRef = forwardRef || React.createRef();
212
+
213
+ /**
214
+ * Reset the underlying component state to show the selected value
215
+ */
216
+ const resetInputState = useCallback( () => {
217
+ if ( forwardRef?.current ) {
218
+ // resets the input field to the selected value or the empty string
219
+ forwardRef.current.setState( {
220
+ ...forwardRef.current.state,
221
+ query: '', // selected value should not be null or the component will crash
222
+ } );
223
+ }
224
+ }, [ forwardRef ] );
225
+
226
+ const SelectLabel = () => (
227
+ <Label required={ required } htmlFor={ forLabel }>
228
+ { label }
229
+ </Label>
230
+ );
231
+
232
+ const inlineLabel = !! ( isInline && label );
233
+
234
+ const optionLabel = useCallback(
235
+ option => ( getOptionLabel ? getOptionLabel( option ) : option.label ),
236
+ [ getOptionLabel ]
237
+ );
238
+
239
+ const getOptionByLabel = useCallback(
240
+ inputValue =>
241
+ getAllOptions.find( option => `${ optionLabel( option ) }` === `${ inputValue }` ),
242
+ [ getAllOptions, optionLabel ]
243
+ );
244
+
245
+ const getAllOptions = useMemo(
246
+ () =>
247
+ [
248
+ ...options.filter( option => ! option.options ),
249
+ ...options.filter( option => option.options ).map( option => option.options ),
250
+ ].reduce( ( a, b ) => a.concat( b ), [] ),
251
+ [ options ]
252
+ );
253
+
254
+ const onValueChange = useCallback(
255
+ inputValue => {
256
+ if ( inputValue && ! selectedOptions.includes( inputValue ) ) {
257
+ setCurrentOption( { action: OPTION_ACTION.ADD, option: inputValue } );
258
+ setSelectedOptions( [ ...selectedOptions, inputValue ] );
259
+ }
260
+ },
261
+ [ getOptionByLabel, setSelectedOptions, selectedOptions, setCurrentOption ]
262
+ );
263
+
264
+ const unselectValue = useCallback(
265
+ ( inputValue, index ) => {
266
+ if ( inputValue ) {
267
+ setSelectedOptions(
268
+ selectedOptions.filter( option => ( option?.label || option ) !== inputValue )
269
+ );
270
+ setCurrentOption( {
271
+ action: OPTION_ACTION.REMOVE,
272
+ option: inputValue,
273
+ index,
274
+ } );
275
+ }
276
+ },
277
+ [ getOptionByLabel, setSelectedOptions, selectedOptions, setCurrentOption ]
278
+ );
279
+
280
+ const handleTypeChange = useCallback(
281
+ query =>
282
+ options.filter(
283
+ option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
284
+ ),
285
+ [ options ]
286
+ );
287
+
288
+ const handleInputChange = useCallback(
289
+ query => {
290
+ if ( ! debounce ) {
291
+ return onInputChange( query );
292
+ }
293
+ clearTimeout( debounceTimeout );
294
+ if ( ! query.length || query.length >= minLength ) {
295
+ debounceTimeout = setTimeout( () => {
296
+ onInputChange( query );
297
+ }, debounce );
298
+ }
299
+ },
300
+ [ onInputChange, debounce, minLength ]
301
+ );
302
+
303
+ const suggest = useCallback(
304
+ ( query, populateResults ) => {
305
+ let data = options;
306
+ if ( isDirty && onInputChange ) {
307
+ handleInputChange( query );
308
+ }
309
+ if ( isDirty && autoFilter ) {
310
+ data = handleTypeChange( query );
311
+ }
312
+ const optionForDisplay = data?.map( option => optionLabel( option ) );
313
+ populateResults(
314
+ optionForDisplay.filter( option => ! selectedOptions.includes( option ) )
315
+ );
316
+ },
317
+ [ autoFilter, isDirty, onInputChange, options, selectedOptions ]
318
+ );
319
+
320
+ useEffect( () => {
321
+ global.document
322
+ .querySelector( '.autocomplete__input' )
323
+ .removeAttribute( 'aria-activedescendant' );
324
+ }, [] );
325
+
326
+ useEffect( () => {
327
+ global.document
328
+ .querySelector( '.autocomplete__menu' )
329
+ .setAttribute( 'aria-label', `${ label } list` );
330
+ }, [ label ] );
331
+
332
+ useEffect( () => {
333
+ const input = global.document.querySelector( `#${ forLabel }` );
334
+ if ( ! input || required === undefined ) {
335
+ return;
336
+ }
337
+ input.setAttribute( 'aria-required', required );
338
+ }, [ required ] );
339
+
340
+ useEffect( () => {
341
+ global.document.querySelector( `#${ forLabel }` ).addEventListener( 'keydown', () => {
342
+ setIsDirty( true );
343
+ } );
344
+ }, [ setIsDirty ] );
345
+
346
+ // For accessibility, we need to add the error message to the aria-describedby attribute
347
+ useEffect( () => {
348
+ const input = global.document.querySelector( `#${ forLabel }` );
349
+ input?.setAttribute(
350
+ 'aria-describedby',
351
+ `describe-${ forLabel }-validation ${ input.getAttribute( 'aria-describedby' ) }`
352
+ );
353
+ }, [] );
354
+
355
+ // Update selectedOption and reset the input state on select input change
356
+
357
+ useEffect( () => {
358
+ onChange(
359
+ selectedOptions,
360
+ selectedOptions.map( option => option?.label || option )
361
+ );
362
+ resetInputState();
363
+ }, [ selectedOptions ] );
364
+
365
+ // Update the select status for screen readers
366
+ useEffect( () => {
367
+ if ( currentOption.action === OPTION_ACTION.ADD ) {
368
+ setAddStatus( `${ currentOption.option } added to the list.` );
369
+ setCurrentOption( { action: OPTION_ACTION.NONE, option: null } );
370
+ } else if ( currentOption.index === selectedOptions.length && selectedOptions.length > 0 ) {
371
+ // Move focus to the first selected item, if the last element is removed and there are other elements in the list
372
+ global.document.querySelector( '.vip-button-component' ).focus();
373
+ } else if ( selectedOptions.length === 0 ) {
374
+ // Move focus to the input field if the last element is removed and there are no other elements in the list
375
+ global.document.querySelector( '.autocomplete__input' ).focus();
376
+ }
377
+ }, [ currentOption ] );
378
+
379
+ return (
380
+ <div className={ classNames( 'vip-form-autocomplete-component', className ) }>
381
+ { label && ! isInline && <SelectLabel /> }
382
+ <div
383
+ sx={ {
384
+ ...defaultStyles,
385
+ ...( isInline && inlineStyles ),
386
+ ...( searchIcon && searchIconStyles ),
387
+ } }
388
+ >
389
+ <FormSelectContent
390
+ isInline={ inlineLabel }
391
+ label={ inlineLabel ? <SelectLabel /> : null }
392
+ >
393
+ { searchIcon && <FormSelectSearch /> }
394
+ <Autocomplete
395
+ id={ forLabel }
396
+ aria-busy={ loading }
397
+ showAllValues={ showAllValues }
398
+ ref={ forwardRef }
399
+ source={ source || suggest }
400
+ defaultValue={ value }
401
+ displayMenu={ displayMenu }
402
+ onConfirm={ onValueChange }
403
+ tNoResults={ noOptionsMessage }
404
+ required={ required }
405
+ dropdownArrow={ showAllValues ? dropdownArrow : () => '' }
406
+ confirmOnBlur={ false }
407
+ { ...props }
408
+ />
409
+ { addStatus && <AddSelectionStatus status={ addStatus } /> }
410
+ { loading && <FormSelectLoading sx={ { right: showAllValues ? 40 : 10 } } /> }
411
+ </FormSelectContent>
412
+ </div>
413
+ <Flex sx={ { mt: 2, justifyContent: 'space-between' } }>
414
+ { hasError && errorMessage && (
415
+ <Validation isValid={ false } describedId={ forLabel }>
416
+ { errorMessage }
417
+ </Validation>
418
+ ) }
419
+ <div sx={ { fontSize: 1 } }>
420
+ { selectedOptions.length } item{ selectedOptions.length > 1 ? 's' : '' } selected
421
+ </div>
422
+ </Flex>
423
+ <div sx={ { display: 'inline-flex', flexWrap: 'wrap', maxWidth: '100%' } }>
424
+ { selectedOptions &&
425
+ selectedOptions.map( ( option, idx ) => (
426
+ <SelectedOptions
427
+ key={ idx }
428
+ index={ idx }
429
+ option={ option }
430
+ unselectValue={ unselectValue }
431
+ />
432
+ ) ) }
433
+ </div>
434
+ </div>
435
+ );
436
+ }
437
+ );
438
+
454
439
  FormAutocompleteMultiselect.propTypes = {
455
- autoFilter: _propTypes["default"].bool,
456
- className: _propTypes["default"].any,
457
- debounce: _propTypes["default"].number,
458
- displayMenu: _propTypes["default"].string,
459
- errorMessage: _propTypes["default"].string,
460
- forLabel: _propTypes["default"].string,
461
- getOptionLabel: _propTypes["default"].func,
462
- getOptionValue: _propTypes["default"].func,
463
- hasError: _propTypes["default"].bool,
464
- isInline: _propTypes["default"].bool,
465
- label: _propTypes["default"].string,
466
- loading: _propTypes["default"].bool,
467
- minLength: _propTypes["default"].number,
468
- noOptionsMessage: _propTypes["default"].func,
469
- onChange: _propTypes["default"].func,
470
- onInputChange: _propTypes["default"].func,
471
- options: _propTypes["default"].array,
472
- required: _propTypes["default"].bool,
473
- searchIcon: _propTypes["default"].bool,
474
- showAllValues: _propTypes["default"].bool,
475
- source: _propTypes["default"].func,
476
- value: _propTypes["default"].string,
477
- dropdownArrow: _propTypes["default"].node
440
+ autoFilter: PropTypes.bool,
441
+ className: PropTypes.any,
442
+ debounce: PropTypes.number,
443
+ displayMenu: PropTypes.string,
444
+ errorMessage: PropTypes.string,
445
+ forLabel: PropTypes.string,
446
+ getOptionLabel: PropTypes.func,
447
+ getOptionValue: PropTypes.func,
448
+ hasError: PropTypes.bool,
449
+ isInline: PropTypes.bool,
450
+ label: PropTypes.string,
451
+ loading: PropTypes.bool,
452
+ minLength: PropTypes.number,
453
+ noOptionsMessage: PropTypes.func,
454
+ onChange: PropTypes.func,
455
+ onInputChange: PropTypes.func,
456
+ options: PropTypes.array,
457
+ required: PropTypes.bool,
458
+ searchIcon: PropTypes.bool,
459
+ showAllValues: PropTypes.bool,
460
+ source: PropTypes.func,
461
+ value: PropTypes.string,
462
+ dropdownArrow: PropTypes.node,
478
463
  };
479
- FormAutocompleteMultiselect.displayName = 'FormAutocompleteMultiselect';
464
+
465
+ FormAutocompleteMultiselect.displayName = 'FormAutocompleteMultiselect';
466
+
467
+ export { FormAutocompleteMultiselect };