@workday/canvas-kit-react 9.0.0-alpha.419-next.21 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/breadcrumbs/lib/BreadcrumbsItem.tsx +1 -1
  2. package/collection/index.ts +2 -0
  3. package/collection/lib/ListBox.tsx +12 -10
  4. package/collection/lib/useBaseListModel.tsx +6 -4
  5. package/collection/lib/useCursorListModel.tsx +1 -1
  6. package/collection/lib/useListActiveDescendant.ts +24 -0
  7. package/collection/lib/useListItemAllowChildStrings.ts +2 -1
  8. package/collection/lib/useListItemRegister.tsx +10 -3
  9. package/collection/lib/useListItemSelect.tsx +1 -1
  10. package/collection/lib/useListKeyboardHandler.ts +28 -0
  11. package/collection/lib/useListLoader.ts +116 -54
  12. package/collection/lib/useOverflowListItemMeasure.tsx +2 -2
  13. package/collection/lib/useOverflowListMeasure.ts +11 -13
  14. package/collection/lib/useOverflowListTarget.tsx +28 -30
  15. package/collection/lib/useSelectionListModel.tsx +1 -0
  16. package/combobox/LICENSE +52 -0
  17. package/combobox/README.md +7 -0
  18. package/combobox/index.ts +8 -0
  19. package/combobox/lib/Combobox.tsx +32 -0
  20. package/combobox/lib/ComboboxCard.tsx +33 -0
  21. package/combobox/lib/ComboboxInput.tsx +104 -0
  22. package/combobox/lib/ComboboxMenu.tsx +67 -0
  23. package/combobox/lib/ComboboxMenuItem.tsx +74 -0
  24. package/combobox/lib/ComboboxMenuList.tsx +45 -0
  25. package/combobox/lib/useComboboxInputOpenWithArrowKeys.ts +21 -0
  26. package/combobox/lib/useComboboxLoader.ts +72 -0
  27. package/combobox/lib/useComboboxModel.tsx +85 -0
  28. package/combobox/package.json +6 -0
  29. package/common/lib/utils/components.ts +15 -16
  30. package/common/lib/utils/models.ts +2 -2
  31. package/dist/commonjs/action-bar/lib/ActionBar.d.ts +2 -2
  32. package/dist/commonjs/action-bar/lib/ActionBarList.d.ts +1 -1
  33. package/dist/commonjs/action-bar/lib/useActionBarModel.d.ts +2 -2
  34. package/dist/commonjs/breadcrumbs/lib/Breadcrumbs.d.ts +2 -2
  35. package/dist/commonjs/breadcrumbs/lib/BreadcrumbsMenu.d.ts +1 -1
  36. package/dist/commonjs/breadcrumbs/lib/hooks/useBreadcrumbsModel.d.ts +2 -2
  37. package/dist/commonjs/collection/index.d.ts +2 -0
  38. package/dist/commonjs/collection/index.d.ts.map +1 -1
  39. package/dist/commonjs/collection/index.js +2 -0
  40. package/dist/commonjs/collection/lib/ListBox.d.ts +7 -6
  41. package/dist/commonjs/collection/lib/ListBox.d.ts.map +1 -1
  42. package/dist/commonjs/collection/lib/ListBox.js +5 -3
  43. package/dist/commonjs/collection/lib/useBaseListModel.d.ts.map +1 -1
  44. package/dist/commonjs/collection/lib/useBaseListModel.js +4 -4
  45. package/dist/commonjs/collection/lib/useCursorListModel.d.ts +0 -34
  46. package/dist/commonjs/collection/lib/useCursorListModel.d.ts.map +1 -1
  47. package/dist/commonjs/collection/lib/useCursorListModel.js +1 -1
  48. package/dist/commonjs/collection/lib/useListActiveDescendant.d.ts +68 -0
  49. package/dist/commonjs/collection/lib/useListActiveDescendant.d.ts.map +1 -0
  50. package/dist/commonjs/collection/lib/useListActiveDescendant.js +25 -0
  51. package/dist/commonjs/collection/lib/useListItemAllowChildStrings.d.ts +2 -1
  52. package/dist/commonjs/collection/lib/useListItemAllowChildStrings.d.ts.map +1 -1
  53. package/dist/commonjs/collection/lib/useListItemAllowChildStrings.js +2 -1
  54. package/dist/commonjs/collection/lib/useListItemRegister.d.ts.map +1 -1
  55. package/dist/commonjs/collection/lib/useListItemRegister.js +5 -1
  56. package/dist/commonjs/collection/lib/useListKeyboardHandler.d.ts +66 -0
  57. package/dist/commonjs/collection/lib/useListKeyboardHandler.d.ts.map +1 -0
  58. package/dist/commonjs/collection/lib/useListKeyboardHandler.js +27 -0
  59. package/dist/commonjs/collection/lib/useListLoader.d.ts +46 -7
  60. package/dist/commonjs/collection/lib/useListLoader.d.ts.map +1 -1
  61. package/dist/commonjs/collection/lib/useListLoader.js +61 -35
  62. package/dist/commonjs/collection/lib/useOverflowListMeasure.d.ts +1 -1
  63. package/dist/commonjs/collection/lib/useOverflowListMeasure.d.ts.map +1 -1
  64. package/dist/commonjs/collection/lib/useOverflowListTarget.d.ts +5 -2
  65. package/dist/commonjs/collection/lib/useOverflowListTarget.d.ts.map +1 -1
  66. package/dist/commonjs/collection/lib/useOverflowListTarget.js +1 -1
  67. package/dist/commonjs/collection/lib/useSelectionListModel.d.ts.map +1 -1
  68. package/dist/commonjs/collection/lib/useSelectionListModel.js +1 -0
  69. package/dist/commonjs/combobox/index.d.ts +9 -0
  70. package/dist/commonjs/combobox/index.d.ts.map +1 -0
  71. package/dist/commonjs/combobox/index.js +19 -0
  72. package/dist/commonjs/combobox/lib/Combobox.d.ts +2075 -0
  73. package/dist/commonjs/combobox/lib/Combobox.d.ts.map +1 -0
  74. package/dist/commonjs/combobox/lib/Combobox.js +29 -0
  75. package/dist/commonjs/combobox/lib/ComboboxCard.d.ts +166 -0
  76. package/dist/commonjs/combobox/lib/ComboboxCard.d.ts.map +1 -0
  77. package/dist/commonjs/combobox/lib/ComboboxCard.js +25 -0
  78. package/dist/commonjs/combobox/lib/ComboboxInput.d.ts +186 -0
  79. package/dist/commonjs/combobox/lib/ComboboxInput.d.ts.map +1 -0
  80. package/dist/commonjs/combobox/lib/ComboboxInput.js +84 -0
  81. package/dist/commonjs/combobox/lib/ComboboxMenu.d.ts +428 -0
  82. package/dist/commonjs/combobox/lib/ComboboxMenu.d.ts.map +1 -0
  83. package/dist/commonjs/combobox/lib/ComboboxMenu.js +63 -0
  84. package/dist/commonjs/combobox/lib/ComboboxMenuItem.d.ts +178 -0
  85. package/dist/commonjs/combobox/lib/ComboboxMenuItem.d.ts.map +1 -0
  86. package/dist/commonjs/combobox/lib/ComboboxMenuItem.js +50 -0
  87. package/dist/commonjs/combobox/lib/ComboboxMenuList.d.ts +164 -0
  88. package/dist/commonjs/combobox/lib/ComboboxMenuList.d.ts.map +1 -0
  89. package/dist/commonjs/combobox/lib/ComboboxMenuList.js +31 -0
  90. package/dist/commonjs/combobox/lib/useComboboxInputOpenWithArrowKeys.d.ts +84 -0
  91. package/dist/commonjs/combobox/lib/useComboboxInputOpenWithArrowKeys.d.ts.map +1 -0
  92. package/dist/commonjs/combobox/lib/useComboboxInputOpenWithArrowKeys.js +20 -0
  93. package/dist/commonjs/combobox/lib/useComboboxLoader.d.ts +28 -0
  94. package/dist/commonjs/combobox/lib/useComboboxLoader.d.ts.map +1 -0
  95. package/dist/commonjs/combobox/lib/useComboboxLoader.js +65 -0
  96. package/dist/commonjs/combobox/lib/useComboboxModel.d.ts +1998 -0
  97. package/dist/commonjs/combobox/lib/useComboboxModel.d.ts.map +1 -0
  98. package/dist/commonjs/combobox/lib/useComboboxModel.js +82 -0
  99. package/dist/commonjs/common/lib/utils/components.d.ts +9 -23
  100. package/dist/commonjs/common/lib/utils/components.d.ts.map +1 -1
  101. package/dist/commonjs/common/lib/utils/components.js +2 -2
  102. package/dist/commonjs/common/lib/utils/models.js +2 -2
  103. package/dist/commonjs/index.d.ts +1 -0
  104. package/dist/commonjs/index.d.ts.map +1 -1
  105. package/dist/commonjs/index.js +1 -0
  106. package/dist/commonjs/menu/index.d.ts +1 -1
  107. package/dist/commonjs/menu/index.d.ts.map +1 -1
  108. package/dist/commonjs/menu/index.js +2 -1
  109. package/dist/commonjs/menu/lib/Menu.d.ts +7 -5
  110. package/dist/commonjs/menu/lib/Menu.d.ts.map +1 -1
  111. package/dist/commonjs/menu/lib/Menu.js +6 -4
  112. package/dist/commonjs/menu/lib/MenuContextTarget.d.ts +2 -2
  113. package/dist/commonjs/menu/lib/MenuItem.d.ts +7 -1
  114. package/dist/commonjs/menu/lib/MenuItem.d.ts.map +1 -1
  115. package/dist/commonjs/menu/lib/MenuItem.js +9 -11
  116. package/dist/commonjs/menu/lib/MenuList.d.ts +3 -3
  117. package/dist/commonjs/menu/lib/MenuList.d.ts.map +1 -1
  118. package/dist/commonjs/menu/lib/MenuList.js +3 -2
  119. package/dist/commonjs/menu/lib/MenuPopper.d.ts +1 -1
  120. package/dist/commonjs/menu/lib/MenuTarget.d.ts +2 -2
  121. package/dist/commonjs/menu/lib/useMenuModel.d.ts +2 -2
  122. package/dist/commonjs/menu/lib/useMenuModel.d.ts.map +1 -1
  123. package/dist/commonjs/menu/lib/useMenuModel.js +3 -5
  124. package/dist/commonjs/popup/lib/hooks/usePopupPopper.d.ts +1 -1
  125. package/dist/commonjs/popup/lib/hooks/usePopupTarget.d.ts +1 -1
  126. package/dist/commonjs/popup/lib/hooks/usePopupTargetContext.d.ts +1 -1
  127. package/dist/commonjs/tabs/lib/Tabs.d.ts +18 -120
  128. package/dist/commonjs/tabs/lib/Tabs.d.ts.map +1 -1
  129. package/dist/commonjs/tabs/lib/TabsItem.d.ts +0 -1
  130. package/dist/commonjs/tabs/lib/TabsItem.d.ts.map +1 -1
  131. package/dist/commonjs/tabs/lib/TabsItem.js +0 -1
  132. package/dist/commonjs/tabs/lib/TabsList.d.ts +1 -1
  133. package/dist/commonjs/tabs/lib/TabsMenuPopper.d.ts +1 -1
  134. package/dist/commonjs/tabs/lib/TabsPanel.d.ts.map +1 -1
  135. package/dist/commonjs/tabs/lib/useTabsModel.d.ts +8 -20
  136. package/dist/commonjs/tabs/lib/useTabsModel.d.ts.map +1 -1
  137. package/dist/commonjs/tabs/lib/useTabsModel.js +1 -0
  138. package/dist/es6/action-bar/lib/ActionBar.d.ts +2 -2
  139. package/dist/es6/action-bar/lib/ActionBarList.d.ts +1 -1
  140. package/dist/es6/action-bar/lib/useActionBarModel.d.ts +2 -2
  141. package/dist/es6/breadcrumbs/lib/Breadcrumbs.d.ts +2 -2
  142. package/dist/es6/breadcrumbs/lib/BreadcrumbsMenu.d.ts +1 -1
  143. package/dist/es6/breadcrumbs/lib/hooks/useBreadcrumbsModel.d.ts +2 -2
  144. package/dist/es6/collection/index.d.ts +2 -0
  145. package/dist/es6/collection/index.d.ts.map +1 -1
  146. package/dist/es6/collection/index.js +2 -0
  147. package/dist/es6/collection/lib/ListBox.d.ts +7 -6
  148. package/dist/es6/collection/lib/ListBox.d.ts.map +1 -1
  149. package/dist/es6/collection/lib/ListBox.js +6 -4
  150. package/dist/es6/collection/lib/useBaseListModel.d.ts.map +1 -1
  151. package/dist/es6/collection/lib/useBaseListModel.js +4 -4
  152. package/dist/es6/collection/lib/useCursorListModel.d.ts +0 -34
  153. package/dist/es6/collection/lib/useCursorListModel.d.ts.map +1 -1
  154. package/dist/es6/collection/lib/useCursorListModel.js +1 -1
  155. package/dist/es6/collection/lib/useListActiveDescendant.d.ts +68 -0
  156. package/dist/es6/collection/lib/useListActiveDescendant.d.ts.map +1 -0
  157. package/dist/es6/collection/lib/useListActiveDescendant.js +22 -0
  158. package/dist/es6/collection/lib/useListItemAllowChildStrings.d.ts +2 -1
  159. package/dist/es6/collection/lib/useListItemAllowChildStrings.d.ts.map +1 -1
  160. package/dist/es6/collection/lib/useListItemAllowChildStrings.js +2 -1
  161. package/dist/es6/collection/lib/useListItemRegister.d.ts.map +1 -1
  162. package/dist/es6/collection/lib/useListItemRegister.js +5 -1
  163. package/dist/es6/collection/lib/useListKeyboardHandler.d.ts +66 -0
  164. package/dist/es6/collection/lib/useListKeyboardHandler.d.ts.map +1 -0
  165. package/dist/es6/collection/lib/useListKeyboardHandler.js +24 -0
  166. package/dist/es6/collection/lib/useListLoader.d.ts +46 -7
  167. package/dist/es6/collection/lib/useListLoader.d.ts.map +1 -1
  168. package/dist/es6/collection/lib/useListLoader.js +61 -35
  169. package/dist/es6/collection/lib/useOverflowListMeasure.d.ts +1 -1
  170. package/dist/es6/collection/lib/useOverflowListMeasure.d.ts.map +1 -1
  171. package/dist/es6/collection/lib/useOverflowListTarget.d.ts +5 -2
  172. package/dist/es6/collection/lib/useOverflowListTarget.d.ts.map +1 -1
  173. package/dist/es6/collection/lib/useOverflowListTarget.js +1 -1
  174. package/dist/es6/collection/lib/useSelectionListModel.d.ts.map +1 -1
  175. package/dist/es6/collection/lib/useSelectionListModel.js +1 -0
  176. package/dist/es6/combobox/index.d.ts +9 -0
  177. package/dist/es6/combobox/index.d.ts.map +1 -0
  178. package/dist/es6/combobox/index.js +8 -0
  179. package/dist/es6/combobox/lib/Combobox.d.ts +2075 -0
  180. package/dist/es6/combobox/lib/Combobox.d.ts.map +1 -0
  181. package/dist/es6/combobox/lib/Combobox.js +23 -0
  182. package/dist/es6/combobox/lib/ComboboxCard.d.ts +166 -0
  183. package/dist/es6/combobox/lib/ComboboxCard.d.ts.map +1 -0
  184. package/dist/es6/combobox/lib/ComboboxCard.js +19 -0
  185. package/dist/es6/combobox/lib/ComboboxInput.d.ts +186 -0
  186. package/dist/es6/combobox/lib/ComboboxInput.d.ts.map +1 -0
  187. package/dist/es6/combobox/lib/ComboboxInput.js +78 -0
  188. package/dist/es6/combobox/lib/ComboboxMenu.d.ts +428 -0
  189. package/dist/es6/combobox/lib/ComboboxMenu.d.ts.map +1 -0
  190. package/dist/es6/combobox/lib/ComboboxMenu.js +57 -0
  191. package/dist/es6/combobox/lib/ComboboxMenuItem.d.ts +178 -0
  192. package/dist/es6/combobox/lib/ComboboxMenuItem.d.ts.map +1 -0
  193. package/dist/es6/combobox/lib/ComboboxMenuItem.js +44 -0
  194. package/dist/es6/combobox/lib/ComboboxMenuList.d.ts +164 -0
  195. package/dist/es6/combobox/lib/ComboboxMenuList.d.ts.map +1 -0
  196. package/dist/es6/combobox/lib/ComboboxMenuList.js +25 -0
  197. package/dist/es6/combobox/lib/useComboboxInputOpenWithArrowKeys.d.ts +84 -0
  198. package/dist/es6/combobox/lib/useComboboxInputOpenWithArrowKeys.d.ts.map +1 -0
  199. package/dist/es6/combobox/lib/useComboboxInputOpenWithArrowKeys.js +17 -0
  200. package/dist/es6/combobox/lib/useComboboxLoader.d.ts +28 -0
  201. package/dist/es6/combobox/lib/useComboboxLoader.d.ts.map +1 -0
  202. package/dist/es6/combobox/lib/useComboboxLoader.js +58 -0
  203. package/dist/es6/combobox/lib/useComboboxModel.d.ts +1998 -0
  204. package/dist/es6/combobox/lib/useComboboxModel.d.ts.map +1 -0
  205. package/dist/es6/combobox/lib/useComboboxModel.js +76 -0
  206. package/dist/es6/common/lib/utils/components.d.ts +9 -23
  207. package/dist/es6/common/lib/utils/components.d.ts.map +1 -1
  208. package/dist/es6/common/lib/utils/components.js +2 -2
  209. package/dist/es6/common/lib/utils/models.js +2 -2
  210. package/dist/es6/index.d.ts +1 -0
  211. package/dist/es6/index.d.ts.map +1 -1
  212. package/dist/es6/index.js +1 -0
  213. package/dist/es6/menu/index.d.ts +1 -1
  214. package/dist/es6/menu/index.d.ts.map +1 -1
  215. package/dist/es6/menu/index.js +1 -1
  216. package/dist/es6/menu/lib/Menu.d.ts +7 -5
  217. package/dist/es6/menu/lib/Menu.d.ts.map +1 -1
  218. package/dist/es6/menu/lib/Menu.js +6 -4
  219. package/dist/es6/menu/lib/MenuContextTarget.d.ts +2 -2
  220. package/dist/es6/menu/lib/MenuItem.d.ts +7 -1
  221. package/dist/es6/menu/lib/MenuItem.d.ts.map +1 -1
  222. package/dist/es6/menu/lib/MenuItem.js +8 -10
  223. package/dist/es6/menu/lib/MenuList.d.ts +3 -3
  224. package/dist/es6/menu/lib/MenuList.d.ts.map +1 -1
  225. package/dist/es6/menu/lib/MenuList.js +4 -3
  226. package/dist/es6/menu/lib/MenuPopper.d.ts +1 -1
  227. package/dist/es6/menu/lib/MenuTarget.d.ts +2 -2
  228. package/dist/es6/menu/lib/useMenuModel.d.ts +2 -2
  229. package/dist/es6/menu/lib/useMenuModel.d.ts.map +1 -1
  230. package/dist/es6/menu/lib/useMenuModel.js +4 -6
  231. package/dist/es6/popup/lib/hooks/usePopupPopper.d.ts +1 -1
  232. package/dist/es6/popup/lib/hooks/usePopupTarget.d.ts +1 -1
  233. package/dist/es6/popup/lib/hooks/usePopupTargetContext.d.ts +1 -1
  234. package/dist/es6/tabs/lib/Tabs.d.ts +18 -120
  235. package/dist/es6/tabs/lib/Tabs.d.ts.map +1 -1
  236. package/dist/es6/tabs/lib/TabsItem.d.ts +0 -1
  237. package/dist/es6/tabs/lib/TabsItem.d.ts.map +1 -1
  238. package/dist/es6/tabs/lib/TabsItem.js +0 -1
  239. package/dist/es6/tabs/lib/TabsList.d.ts +1 -1
  240. package/dist/es6/tabs/lib/TabsMenuPopper.d.ts +1 -1
  241. package/dist/es6/tabs/lib/TabsPanel.d.ts.map +1 -1
  242. package/dist/es6/tabs/lib/useTabsModel.d.ts +8 -20
  243. package/dist/es6/tabs/lib/useTabsModel.d.ts.map +1 -1
  244. package/dist/es6/tabs/lib/useTabsModel.js +1 -0
  245. package/index.ts +1 -0
  246. package/menu/index.ts +1 -1
  247. package/menu/lib/Menu.tsx +6 -4
  248. package/menu/lib/MenuItem.tsx +9 -12
  249. package/menu/lib/MenuList.tsx +16 -10
  250. package/menu/lib/useMenuModel.tsx +4 -7
  251. package/modal/lib/hooks/useModalHeading.ts +2 -2
  252. package/package.json +3 -3
  253. package/tabs/lib/TabsItem.tsx +10 -13
  254. package/tabs/lib/TabsPanel.tsx +1 -5
  255. package/tabs/lib/useTabsModel.tsx +1 -0
@@ -0,0 +1,52 @@
1
+ Apache License, Version 2.0 Apache License Version 2.0, January 2004
2
+
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
9
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
10
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
11
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
12
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
13
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
14
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
15
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
16
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
17
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
18
+
19
+ 2. Grant of Copyright License.
20
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
21
+
22
+ 3. Grant of Patent License.
23
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
24
+
25
+ 4. Redistribution.
26
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
27
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
28
+
29
+ 5. Submission of Contributions.
30
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
31
+
32
+ 6. Trademarks.
33
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
34
+
35
+ 7. Disclaimer of Warranty.
36
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
37
+
38
+ 8. Limitation of Liability.
39
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
40
+
41
+ 9. Accepting Warranty or Additional Liability.
42
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
43
+
44
+ END OF TERMS AND CONDITIONS
45
+
46
+ ©2021 Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders.
47
+
48
+
49
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
50
+ http://www.apache.org/licenses/LICENSE-2.0
51
+
52
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
@@ -0,0 +1,7 @@
1
+ # Canvas Kit Combobox
2
+
3
+ Combobox
4
+
5
+ View the
6
+ [documentation for Combobox](https://workday.github.io/canvas-kit/?path=/docs/features-combobox--autocomplete)
7
+ on Storybook.
@@ -0,0 +1,8 @@
1
+ export {Combobox} from './lib/Combobox';
2
+ export {useComboboxCard} from './lib/ComboboxCard';
3
+ export {useComboboxMenuItem} from './lib/ComboboxMenuItem';
4
+ export {useComboboxMenuList} from './lib/ComboboxMenuList';
5
+ export {useComboboxInput} from './lib/ComboboxInput';
6
+ export {useComboboxLoader} from './lib/useComboboxLoader';
7
+ export {useComboboxModel} from './lib/useComboboxModel';
8
+ export {useComboboxInputOpenWithArrowKeys as useComboboxOpenWithArrowKeys} from './lib/useComboboxInputOpenWithArrowKeys';
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+
3
+ import {createContainer} from '@workday/canvas-kit-react/common';
4
+
5
+ import {useComboboxModel} from './useComboboxModel';
6
+ import {ComboboxInput} from './ComboboxInput';
7
+ import {ComboboxMenu} from './ComboboxMenu';
8
+ export interface ComboboxProps {
9
+ /**
10
+ * Children of the `Combobox`. Should contain a `Combobox.Input` and a `Combobox.Menu`
11
+ */
12
+ children: React.ReactNode;
13
+ }
14
+
15
+ export const Combobox = createContainer()({
16
+ displayName: 'Combobox',
17
+ modelHook: useComboboxModel,
18
+ subComponents: {
19
+ /**
20
+ * The input of the `Combobox`. This element will have `role="combobox"` applied, along with
21
+ * `aria-haspopup="true"`
22
+ */
23
+ Input: ComboboxInput,
24
+ /**
25
+ * A custom {@link Menu} component that uses `aria-activedescendant` instead of roving tab index
26
+ * to keep the focus on the {@link ComboboxInput Combobox.Input}.
27
+ */
28
+ Menu: ComboboxMenu,
29
+ },
30
+ })<ComboboxProps>(({children}, _, model) => {
31
+ return <ComboboxMenu model={model}>{children}</ComboboxMenu>;
32
+ });
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ createElemPropsHook,
5
+ createSubcomponent,
6
+ ExtractProps,
7
+ } from '@workday/canvas-kit-react/common';
8
+ import {Menu} from '@workday/canvas-kit-react/menu';
9
+
10
+ import {useComboboxModel} from './useComboboxModel';
11
+
12
+ export interface ComboboxCardProps extends ExtractProps<typeof Menu.Card> {}
13
+
14
+ /**
15
+ * This hook sets the `minWidth` style attribute to match the width of the
16
+ * {@link ComboboxInput Combobox.Input} component.
17
+ */
18
+ export const useComboboxCard = createElemPropsHook(useComboboxModel)(model => {
19
+ return {
20
+ minWidth: model.state.width,
21
+ } as const;
22
+ });
23
+
24
+ export const ComboboxCard = createSubcomponent('div')({
25
+ modelHook: useComboboxModel,
26
+ elemPropsHook: useComboboxCard,
27
+ })<ComboboxCardProps>(({children, ...elemProps}, Element) => {
28
+ return (
29
+ <Menu.Card as={Element} {...elemProps}>
30
+ {children}
31
+ </Menu.Card>
32
+ );
33
+ });
@@ -0,0 +1,104 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ composeHooks,
5
+ createElemPropsHook,
6
+ createSubcomponent,
7
+ dispatchInputEvent,
8
+ ExtractProps,
9
+ useForkRef,
10
+ } from '@workday/canvas-kit-react/common';
11
+ import {TextInput} from '@workday/canvas-kit-react/text-input';
12
+ import {usePopupTarget} from '@workday/canvas-kit-react/popup';
13
+ import {
14
+ useListActiveDescendant,
15
+ useListKeyboardHandler,
16
+ } from '@workday/canvas-kit-react/collection';
17
+
18
+ import {useComboboxModel} from './useComboboxModel';
19
+ import {useComboboxInputOpenWithArrowKeys} from './useComboboxInputOpenWithArrowKeys';
20
+
21
+ /**
22
+ * Adds all attributes necessary to start with a {@link ComboboxInput Combobox.Input}. It opens the
23
+ * menu with arrow keys, uses {@link useListActiveDescendant}, and handles keyboard arrows to
24
+ * navigate items of the menu. You may also compose this hook to add more specific behaviors for
25
+ * your {@link ComboboxInput Combobox.Input}.
26
+ */
27
+ export const useComboboxInput = composeHooks(
28
+ createElemPropsHook(useComboboxModel)((model, ref) => {
29
+ const elementRef = useForkRef(ref, model.state.inputRef);
30
+
31
+ React.useEffect(() => {
32
+ if (model.state.cursorId && model.state.visibility === 'visible') {
33
+ const item = model.navigation.getItem(model.state.cursorId, model);
34
+ if (model.state.isVirtualized && item) {
35
+ model.state.UNSTABLE_virtual.scrollToIndex(item.index);
36
+ } else {
37
+ const listboxId = model.state.inputRef.current?.getAttribute('aria-controls');
38
+ if (listboxId) {
39
+ const menuItem = document.querySelector(
40
+ `[id="${listboxId}"] [data-id="${model.state.cursorId}"]`
41
+ );
42
+ if (menuItem) {
43
+ menuItem.scrollIntoView({block: 'nearest'});
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ // we only want to run this effect if the cursor changes and not any other time
50
+ // eslint-disable-next-line react-hooks/exhaustive-deps
51
+ }, [model.state.cursorId]);
52
+
53
+ return {
54
+ onKeyDown(event: React.KeyboardEvent) {
55
+ if (event.key === 'Escape') {
56
+ dispatchInputEvent(event.currentTarget as HTMLElement, '');
57
+ }
58
+ if (event.key === 'Enter' && !event.metaKey && model.state.visibility === 'visible') {
59
+ if (
60
+ document
61
+ .querySelector(`[data-id="${model.state.cursorId}"]`)
62
+ ?.getAttribute('aria-disabled') !== 'true'
63
+ ) {
64
+ model.events.select({id: model.state.cursorId});
65
+ if (model.state.mode === 'single') {
66
+ model.events.hide(event);
67
+ }
68
+ }
69
+
70
+ // We don't want to submit forms while the combobox is open
71
+ event.preventDefault();
72
+ }
73
+ },
74
+ onBlur(event: React.FocusEvent) {
75
+ model.events.hide(event);
76
+ },
77
+ onChange: model.onChange,
78
+ onClick(event: React.MouseEvent) {
79
+ if (model.state.visibility === 'hidden') {
80
+ model.events.setWidth(event.currentTarget.clientWidth);
81
+ }
82
+ },
83
+ value: model.state.value,
84
+ role: 'combobox',
85
+ 'aria-haspopup': true,
86
+ 'aria-expanded': model.state.visibility === 'visible',
87
+ 'aria-autocomplete': 'list',
88
+ 'aria-controls': `${model.state.id}-list`,
89
+ id: model.state.id,
90
+ ref: elementRef,
91
+ } as const;
92
+ }),
93
+ useComboboxInputOpenWithArrowKeys,
94
+ useListActiveDescendant,
95
+ useListKeyboardHandler,
96
+ usePopupTarget
97
+ );
98
+
99
+ export const ComboboxInput = createSubcomponent(TextInput)({
100
+ modelHook: useComboboxModel,
101
+ elemPropsHook: useComboboxInput,
102
+ })<ExtractProps<typeof TextInput, never>>(({children, ...elemProps}, Element) => {
103
+ return <Element {...elemProps}>{children}</Element>;
104
+ });
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+
3
+ import {createSubcomponent} from '@workday/canvas-kit-react/common';
4
+ import {Menu} from '@workday/canvas-kit-react/menu';
5
+
6
+ import {useComboboxModel} from './useComboboxModel';
7
+ import {ComboboxMenuList} from './ComboboxMenuList';
8
+ import {ComboboxMenuItem} from './ComboboxMenuItem';
9
+ import {ComboboxCard} from './ComboboxCard';
10
+
11
+ export interface ComboboxMenuProps {
12
+ /**
13
+ * Children of the {@link ComboboxMenu Combobox.Menu}.
14
+ */
15
+ children: React.ReactNode;
16
+ }
17
+
18
+ export const ComboboxMenu = createSubcomponent()({
19
+ modelHook: useComboboxModel,
20
+ subComponents: {
21
+ /**
22
+ * The "Popper" of a {@link ComboboxMenu Combobox.Menu}. The popper will appear around the
23
+ * {@link ComboboxInput Combobox.Input}. It renders a `div` element that is portalled to the
24
+ * `document.body` which is controlled by the {@link PopupStack}. The `PopupStack` is not part
25
+ * of React. This means no extra props given to this component will be forwarded to the `div`
26
+ * element, but the `ref` will be forwarded.
27
+ */
28
+ Popper: Menu.Popper,
29
+ /**
30
+ * The combobox menu list follows the Collections API. A list can either contain static items or
31
+ * a render prop and `items` to the model.
32
+ *
33
+ * ```tsx
34
+ * const MyComponent = () => {
35
+ * const model = useComboboxModel({
36
+ * items: ['First Item', 'Second Item']
37
+ * })
38
+ *
39
+ * return (
40
+ * <Combobox model={model}>
41
+ * // other combobox subcomponents
42
+ * <Combobox.Menu.List>
43
+ * {(item) => <Combobox.Menu.Item>{item}</Combobox.Menu.Item>}
44
+ * </Combobox.Menu.List>
45
+ * </Combobox>
46
+ * )
47
+ * }
48
+ * ```
49
+ */
50
+ List: ComboboxMenuList,
51
+ /**
52
+ * `Combobox.Menu.Item` has an optional `data-id` prop that identifies the item in the
53
+ * `Combobox.Menu.List` and will be passed to the optional `onSelect` callback of the
54
+ * `ComboboxModel`. `Combobox.Menu.Item` can contain any HTML.
55
+ */
56
+ Item: ComboboxMenuItem,
57
+ /**
58
+ * `Combobox.Menu.Card` is a non-semantic element used to give the dropdown menu its distinct visual
59
+ * cue that the dropdown menu is floating above other content. `Combobox.Menu.Card` usually contains a
60
+ * `Combobox.Menu.List`, but it can also contain other elements like a header or footer.
61
+ */
62
+ Card: ComboboxCard,
63
+ Divider: Menu.Divider,
64
+ },
65
+ })<ComboboxMenuProps>(({children}, _, model) => {
66
+ return <Menu model={model}>{children}</Menu>;
67
+ });
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ composeHooks,
5
+ createElemPropsHook,
6
+ createSubcomponent,
7
+ } from '@workday/canvas-kit-react/common';
8
+ import {StyledMenuItem, useMenuModel} from '@workday/canvas-kit-react/menu';
9
+ import {
10
+ useListItemAllowChildStrings,
11
+ useListItemRegister,
12
+ } from '@workday/canvas-kit-react/collection';
13
+ import {OverflowTooltip} from '@workday/canvas-kit-react/tooltip';
14
+
15
+ import {useComboboxModel} from './useComboboxModel';
16
+
17
+ export interface ComboboxMenuItemProps {
18
+ children: React.ReactNode;
19
+ }
20
+
21
+ /**
22
+ * This hook sets up accessibility and behavior of a {@link ComboboxMenuItem Combobox.Menu.Item}
23
+ * component. It prevents focus when clicking so the focus stays on the
24
+ * {@link ComboboxInput Combobox.Input} component and selects an item when the user clicks on it. It
25
+ * also prevents items with an `aria-disabled` attribute from being selected. A `focus` CSS class is
26
+ * added when the item has "focus" (when the cursor is on the item).
27
+ */
28
+ export const useComboboxMenuItem = composeHooks(
29
+ createElemPropsHook(useMenuModel)((model, _, elemProps: {'data-id'?: string} = {}) => {
30
+ const id = elemProps['data-id'] || '';
31
+ const onMouseDown = (event: React.MouseEvent<HTMLElement>) => {
32
+ if (
33
+ model.state.nonInteractiveIds.includes(id) ||
34
+ event.currentTarget.hasAttribute('aria-disabled')
35
+ ) {
36
+ return;
37
+ }
38
+ if (event.currentTarget.getAttribute('aria-disabled') !== 'true') {
39
+ model.events.select({id});
40
+ if (model.state.mode === 'single') {
41
+ model.events.hide(event);
42
+ }
43
+ }
44
+
45
+ // prevent focus changes
46
+ event.preventDefault();
47
+ };
48
+
49
+ const selected = model.state.cursorId === id;
50
+
51
+ return {
52
+ role: 'option',
53
+ 'aria-selected': selected || undefined,
54
+ onMouseDown,
55
+ className:
56
+ model.state.cursorId && model.state.cursorId === elemProps['data-id'] ? 'focus' : '',
57
+ } as const;
58
+ }),
59
+ useListItemRegister,
60
+ useListItemAllowChildStrings
61
+ );
62
+
63
+ export const ComboboxMenuItem = createSubcomponent('li')({
64
+ modelHook: useComboboxModel,
65
+ elemPropsHook: useComboboxMenuItem,
66
+ })<ComboboxMenuItemProps>(({children, ...elemProps}, Element) => {
67
+ return (
68
+ <OverflowTooltip placement="left">
69
+ <StyledMenuItem minHeight="xl" as={Element} {...(elemProps as any)}>
70
+ {children}
71
+ </StyledMenuItem>
72
+ </OverflowTooltip>
73
+ );
74
+ });
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+
3
+ import {commonColors} from '@workday/canvas-kit-react/tokens';
4
+ import {createElemPropsHook, createSubcomponent} from '@workday/canvas-kit-react/common';
5
+ import {useMenuModel} from '@workday/canvas-kit-react/menu';
6
+ import {ListBox, ListBoxProps} from '@workday/canvas-kit-react/collection';
7
+
8
+ import {useComboboxModel} from './useComboboxModel';
9
+
10
+ export interface ComboboxMenuListProps<T = any> extends ListBoxProps<T> {}
11
+
12
+ /**
13
+ * The `listbox` uses `aria-labelledby` pointing to the {@link ComboboxInput Combobox.Input}. This
14
+ * input should be labelled by a form field label for proper accessibility. Use {@link FormField} to
15
+ * ensure proper accessibility.
16
+ */
17
+ export const useComboboxMenuList = createElemPropsHook(useMenuModel)(model => {
18
+ return {
19
+ role: 'listbox',
20
+ 'aria-labelledby': model.state.id,
21
+ id: `${model.state.id}-list`,
22
+ flexDirection: model.state.orientation === 'vertical' ? 'column' : 'row',
23
+ } as const;
24
+ });
25
+
26
+ export const ComboboxMenuList = createSubcomponent('ul')({
27
+ modelHook: useComboboxModel,
28
+ elemPropsHook: useComboboxMenuList,
29
+ })<ComboboxMenuListProps>(({children, ...elemProps}, Element, model) => {
30
+ return (
31
+ <ListBox
32
+ as={Element}
33
+ model={model}
34
+ background={commonColors.background}
35
+ borderRadius="zero"
36
+ padding="zero"
37
+ marginY="xxs"
38
+ gap="zero"
39
+ overflowY="auto"
40
+ {...elemProps}
41
+ >
42
+ {children}
43
+ </ListBox>
44
+ );
45
+ });
@@ -0,0 +1,21 @@
1
+ import {createElemPropsHook} from '@workday/canvas-kit-react/common';
2
+
3
+ import {useComboboxModel} from './useComboboxModel';
4
+
5
+ /**
6
+ * Opens a `Combobox` with the up/down arrow keys. This should be used only on a
7
+ * {@link ComboboxInput Combobox.Input}. It adds a keydown listener for the up/down arrow keys.
8
+ */
9
+ export const useComboboxInputOpenWithArrowKeys = createElemPropsHook(useComboboxModel)(model => {
10
+ return {
11
+ onKeyDown(event: React.KeyboardEvent) {
12
+ if (
13
+ event.key === 'ArrowDown' ||
14
+ (event.key === 'ArrowUp' && model.state.visibility !== 'visible')
15
+ ) {
16
+ model.events.show(event);
17
+ model.events.setWidth(event.currentTarget.clientWidth);
18
+ }
19
+ },
20
+ };
21
+ });
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+
3
+ import {useListLoader} from '@workday/canvas-kit-react/collection';
4
+ import {useComboboxModel} from './useComboboxModel';
5
+
6
+ const useDebounce = () => {
7
+ const debounceTimer = React.useRef(-1);
8
+
9
+ React.useEffect(() => {
10
+ return () => {
11
+ // We want to clear any timeout on unload. We disable the ESLint rule because this is actually
12
+ // what we want
13
+
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ clearTimeout(debounceTimer.current);
16
+ };
17
+ }, []);
18
+
19
+ return (fn: (...args: any[]) => any, wait: number) => {
20
+ clearTimeout(debounceTimer.current);
21
+
22
+ debounceTimer.current = (setTimeout(fn, wait) as any) as number; // We don't actually care what the real return type of setTimeout is. It is a number in the browser and something else in Node
23
+ };
24
+ };
25
+
26
+ /**
27
+ * Creates a `Combobox` data loader and a model. The `Combobox` loader extends the
28
+ * {@link useListLoader} and connects a {@link ComboboxInput Combobox.Input} to the filter of the
29
+ * data loader. A simple loader using
30
+ * [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) could look like the
31
+ * following:
32
+ *
33
+ * ```ts
34
+ * const {model, loader} = useComboboxLoader(
35
+ * {
36
+ * total: 0,
37
+ * pageSize: 20,
38
+ * async load({pageNumber, pageSize, filter}) {
39
+ * // `filter` will be a `string`
40
+ * return fetch(`/myUrl?filter=${filter}`)
41
+ * .then(response => response.json())
42
+ * .then(response => {
43
+ * return {total: response.total, items: response.items};
44
+ * });
45
+ * },
46
+ * },
47
+ * useComboboxModel
48
+ * );
49
+ * ```
50
+ */
51
+ export const useComboboxLoader: typeof useListLoader = (config, modelHook) => {
52
+ const debounce = useDebounce();
53
+ const list = useListLoader(
54
+ {
55
+ shouldLoad(params, state) {
56
+ return (
57
+ (config.shouldLoad ? config.shouldLoad(params, state) : true) &&
58
+ state.visibility !== 'hidden'
59
+ );
60
+ },
61
+ ...(modelHook.mergeConfig(config, {
62
+ onChange(event) {
63
+ const value = event.currentTarget.value;
64
+ debounce(() => list.loader.updateFilter(value), 150);
65
+ },
66
+ } as typeof useComboboxModel.TConfig) as typeof config),
67
+ },
68
+ modelHook
69
+ );
70
+
71
+ return list;
72
+ };
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import {createModelHook, dispatchInputEvent} from '@workday/canvas-kit-react/common';
3
+ import {useMenuModel} from '@workday/canvas-kit-react/menu';
4
+
5
+ /**
6
+ * An input model can be used by compound components that need to work with form fields. Some form
7
+ * libraries use `onChange` and `value` to update a form object. Others use `onChange` and `ref` to
8
+ * avoid rerendering. Also autocomplete and test libraries may use the `value` `HTMLInputElement`
9
+ * property. We need to normalize these use cases so subcomponents can have correct data and all
10
+ * use-cases are supported.
11
+ */
12
+ export const useInputModel = createModelHook({
13
+ defaultConfig: {
14
+ value: undefined as string | undefined,
15
+
16
+ onChange(event: React.ChangeEvent<HTMLInputElement>) {
17
+ return;
18
+ },
19
+ },
20
+ })(config => {
21
+ const inputRef = React.createRef<HTMLInputElement>();
22
+
23
+ return {
24
+ onChange: config.onChange,
25
+ state: {value: config.value, inputRef},
26
+ events: {},
27
+ };
28
+ });
29
+
30
+ /**
31
+ * `ComboboxModel` extends the {@link ListModel} and the {@link InputModel}. Selecting items from
32
+ * the menu will dispatch an
33
+ * [input](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) event on the
34
+ * input which should work with form libraries, automation, and autofill.
35
+ *
36
+ * ```tsx
37
+ * const model = useComboboxModel()
38
+ *
39
+ * <Combobox model={model}>{Combobox child components}</Combobox>
40
+ * ```
41
+ */
42
+ export const useComboboxModel = createModelHook({
43
+ defaultConfig: {
44
+ ...useInputModel.defaultConfig,
45
+ ...useMenuModel.defaultConfig,
46
+ },
47
+ requiredConfig: {
48
+ ...useInputModel.requiredConfig,
49
+ ...useMenuModel.requiredConfig,
50
+ },
51
+ })(config => {
52
+ const input = useInputModel(config);
53
+ const menu = useMenuModel(
54
+ useMenuModel.mergeConfig(config, {
55
+ shouldVirtualize: true,
56
+ onSelect({id}) {
57
+ dispatchInputEvent(menu.state.targetRef.current, id);
58
+ },
59
+ })
60
+ );
61
+ const [width, setWidth] = React.useState(0);
62
+
63
+ const state = {
64
+ /**
65
+ * The width of the combobox input. This is used to make sure the UI renders the menu the same
66
+ * width as the input.
67
+ */
68
+ width,
69
+ ...input.state,
70
+ ...menu.state,
71
+ };
72
+
73
+ const events = {
74
+ ...input.events,
75
+ ...menu.events,
76
+ /**
77
+ * Change the width of the menu. Usually this is set to the width of the input.
78
+ */
79
+ setWidth(width: number) {
80
+ setWidth(width);
81
+ },
82
+ };
83
+
84
+ return {...menu, ...input, state, events};
85
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/commonjs/combobox",
3
+ "module": "../dist/es6/combobox",
4
+ "sideEffects": false,
5
+ "types": "../dist/es6/combobox"
6
+ }