@boxcustodia/library 2.0.0-alpha.10 → 2.0.0-alpha.12

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 (352) hide show
  1. package/dist/index.cjs.js +70 -70
  2. package/dist/index.css +2 -0
  3. package/dist/index.d.ts +420 -272
  4. package/dist/index.es.js +34448 -27816
  5. package/dist/theme.css +1 -1
  6. package/package.json +11 -6
  7. package/src/__doc__/Changelog.mdx +6 -0
  8. package/src/__doc__/Components.mdx +73 -0
  9. package/src/__doc__/Examples.tsx +69 -0
  10. package/src/__doc__/Icons.mdx +41 -0
  11. package/src/__doc__/Intro.mdx +138 -0
  12. package/src/__doc__/MCP.mdx +71 -0
  13. package/src/__doc__/Migration.mdx +475 -0
  14. package/src/__doc__/Theme.mdx +132 -0
  15. package/src/__doc__/Types.mdx +252 -0
  16. package/src/components/alert/alert.stories.tsx +142 -0
  17. package/src/components/alert/alert.tsx +109 -0
  18. package/src/components/alert/index.ts +7 -0
  19. package/src/components/alert-dialog/alert-dialog.stories.tsx +173 -0
  20. package/src/components/alert-dialog/alert-dialog.test.tsx +49 -0
  21. package/src/components/alert-dialog/alert-dialog.tsx +265 -0
  22. package/src/components/alert-dialog/index.ts +1 -0
  23. package/src/components/auto-complete/auto-complete-primitives.tsx +155 -0
  24. package/src/components/auto-complete/auto-complete.stories.tsx +241 -0
  25. package/src/components/auto-complete/auto-complete.tsx +82 -0
  26. package/src/components/auto-complete/index.ts +2 -0
  27. package/src/components/avatar/avatar.stories.tsx +84 -0
  28. package/src/components/avatar/avatar.test.tsx +61 -0
  29. package/src/components/avatar/avatar.tsx +104 -0
  30. package/src/components/avatar/index.ts +1 -0
  31. package/src/components/background-image/background-image.stories.tsx +21 -0
  32. package/src/components/background-image/background-image.test.tsx +29 -0
  33. package/src/components/background-image/background-image.tsx +23 -0
  34. package/src/components/background-image/index.ts +1 -0
  35. package/src/components/button/button.stories.tsx +396 -0
  36. package/src/components/button/button.test.tsx +58 -0
  37. package/src/components/button/button.tsx +31 -0
  38. package/src/components/button/button.variants.ts +44 -0
  39. package/src/components/button/components/base-button.tsx +86 -0
  40. package/src/components/button/components/loader-overlay.tsx +21 -0
  41. package/src/components/button/components/loading-icon.tsx +47 -0
  42. package/src/components/button/index.ts +3 -0
  43. package/src/components/calendar/calendar.model.ts +86 -0
  44. package/src/components/calendar/calendar.stories.tsx +155 -0
  45. package/src/components/calendar/calendar.test.tsx +12 -0
  46. package/src/components/calendar/calendar.tsx +185 -0
  47. package/src/components/calendar/components/calendar-navigation.tsx +141 -0
  48. package/src/components/calendar/components/day.tsx +61 -0
  49. package/src/components/calendar/components/decade-view.tsx +45 -0
  50. package/src/components/calendar/components/index.ts +6 -0
  51. package/src/components/calendar/components/month-view.tsx +58 -0
  52. package/src/components/calendar/components/week-days.tsx +27 -0
  53. package/src/components/calendar/components/year-view.tsx +29 -0
  54. package/src/components/calendar/hooks/index.ts +4 -0
  55. package/src/components/calendar/hooks/use-calendar-navigation.ts +79 -0
  56. package/src/components/calendar/hooks/use-calendar.ts +90 -0
  57. package/src/components/calendar/hooks/use-multiple-calendar.ts +34 -0
  58. package/src/components/calendar/hooks/use-range-calendar.ts +91 -0
  59. package/src/components/calendar/hooks/use-single-calendar.ts +18 -0
  60. package/src/components/calendar/index.ts +1 -0
  61. package/src/components/calendar/utils/typeguards.ts +7 -0
  62. package/src/components/card/card.stories.tsx +116 -0
  63. package/src/components/card/card.tsx +74 -0
  64. package/src/components/card/index.ts +1 -0
  65. package/src/components/center/center.stories.tsx +81 -0
  66. package/src/components/center/center.tsx +24 -0
  67. package/src/components/center/index.ts +1 -0
  68. package/src/components/checkbox/checkbox.stories.tsx +307 -0
  69. package/src/components/checkbox/checkbox.tsx +273 -0
  70. package/src/components/checkbox/index.ts +1 -0
  71. package/src/components/checkbox-group/checkbox-group.stories.tsx +104 -0
  72. package/src/components/checkbox-group/checkbox-group.tsx +16 -0
  73. package/src/components/checkbox-group/index.ts +1 -0
  74. package/src/components/combobox/combobox.stories.tsx +339 -0
  75. package/src/components/combobox/combobox.tsx +892 -0
  76. package/src/components/combobox/index.ts +1 -0
  77. package/src/components/date-picker/date-input.stories.tsx +158 -0
  78. package/src/components/date-picker/date-input.tsx +163 -0
  79. package/src/components/date-picker/date-picker.model.ts +90 -0
  80. package/src/components/date-picker/date-picker.stories.tsx +200 -0
  81. package/src/components/date-picker/date-picker.test.tsx +23 -0
  82. package/src/components/date-picker/date-picker.tsx +298 -0
  83. package/src/components/date-picker/date-picker.utils.ts +260 -0
  84. package/src/components/date-picker/index.ts +3 -0
  85. package/src/components/date-picker/use-date-input-popover.ts +48 -0
  86. package/src/components/date-picker/use-date-input.ts +125 -0
  87. package/src/components/dialog/dialog.stories.tsx +171 -0
  88. package/src/components/dialog/dialog.test.tsx +68 -0
  89. package/src/components/dialog/dialog.tsx +277 -0
  90. package/src/components/dialog/index.ts +1 -0
  91. package/src/components/divider/divider.stories.tsx +70 -0
  92. package/src/components/divider/divider.test.tsx +22 -0
  93. package/src/components/divider/divider.tsx +23 -0
  94. package/src/components/divider/index.ts +1 -0
  95. package/src/components/dropzone/dropzone.stories.tsx +210 -0
  96. package/src/components/dropzone/dropzone.tsx +154 -0
  97. package/src/components/dropzone/file-types.ts +64 -0
  98. package/src/components/dropzone/index.ts +3 -0
  99. package/src/components/dropzone/upload-primitives.tsx +310 -0
  100. package/src/components/dropzone/use-dropzone.ts +122 -0
  101. package/src/components/empty-state/empty-state.stories.tsx +56 -0
  102. package/src/components/empty-state/empty-state.tsx +39 -0
  103. package/src/components/empty-state/index.ts +1 -0
  104. package/src/components/field/field.stories.tsx +223 -0
  105. package/src/components/field/field.tsx +229 -0
  106. package/src/components/field/index.ts +1 -0
  107. package/src/components/form/form.stories.tsx +594 -0
  108. package/src/components/form/form.tsx +30 -0
  109. package/src/components/form/index.ts +1 -0
  110. package/src/components/heading/heading.stories.tsx +74 -0
  111. package/src/components/heading/heading.tsx +28 -0
  112. package/src/components/heading/heading.variants.ts +27 -0
  113. package/src/components/heading/index.ts +1 -0
  114. package/src/components/index.ts +46 -0
  115. package/src/components/input/index.ts +1 -0
  116. package/src/components/input/input.stories.tsx +104 -0
  117. package/src/components/input/input.tsx +75 -0
  118. package/src/components/kbd/index.ts +1 -0
  119. package/src/components/kbd/kbd.stories.tsx +40 -0
  120. package/src/components/kbd/kbd.tsx +31 -0
  121. package/src/components/kbd/kbd.variants.ts +26 -0
  122. package/src/components/label/index.ts +1 -0
  123. package/src/components/label/label.stories.tsx +68 -0
  124. package/src/components/label/label.test.tsx +61 -0
  125. package/src/components/label/label.tsx +62 -0
  126. package/src/components/loader/index.ts +1 -0
  127. package/src/components/loader/loader.stories.tsx +60 -0
  128. package/src/components/loader/loader.test.tsx +26 -0
  129. package/src/components/loader/loader.tsx +60 -0
  130. package/src/components/menu/index.ts +2 -0
  131. package/src/components/menu/menu-primitives.tsx +248 -0
  132. package/src/components/menu/menu.stories.tsx +203 -0
  133. package/src/components/menu/menu.tsx +100 -0
  134. package/src/components/menu/util/render-menu-item.tsx +54 -0
  135. package/src/components/multi-select/hooks/use-multi-select.ts +66 -0
  136. package/src/components/multi-select/index.ts +1 -0
  137. package/src/components/multi-select/multi-select.stories.tsx +294 -0
  138. package/src/components/multi-select/multi-select.tsx +300 -0
  139. package/src/components/multi-select/multi-select.variants.ts +22 -0
  140. package/src/components/number-input/index.ts +1 -0
  141. package/src/components/number-input/number-input.stories.tsx +209 -0
  142. package/src/components/number-input/number-input.test.tsx +87 -0
  143. package/src/components/number-input/number-input.tsx +230 -0
  144. package/src/components/pagination/components/pagination-option.tsx +27 -0
  145. package/src/components/pagination/index.ts +1 -0
  146. package/src/components/pagination/pagination.stories.tsx +80 -0
  147. package/src/components/pagination/pagination.test.tsx +76 -0
  148. package/src/components/pagination/pagination.tsx +102 -0
  149. package/src/components/password/index.ts +1 -0
  150. package/src/components/password/password.stories.tsx +104 -0
  151. package/src/components/password/password.tsx +71 -0
  152. package/src/components/popover/index.ts +1 -0
  153. package/src/components/popover/popover.stories.tsx +213 -0
  154. package/src/components/popover/popover.tsx +203 -0
  155. package/src/components/progress/index.ts +1 -0
  156. package/src/components/progress/progress.stories.tsx +124 -0
  157. package/src/components/progress/progress.test.tsx +25 -0
  158. package/src/components/progress/progress.tsx +124 -0
  159. package/src/components/scroll-area/index.ts +1 -0
  160. package/src/components/scroll-area/scroll-area.stories.tsx +166 -0
  161. package/src/components/scroll-area/scroll-area.tsx +64 -0
  162. package/src/components/select/index.ts +1 -0
  163. package/src/components/select/select.stories.tsx +253 -0
  164. package/src/components/select/select.tsx +430 -0
  165. package/src/components/show/index.ts +1 -0
  166. package/src/components/show/show.stories.tsx +197 -0
  167. package/src/components/show/show.test.tsx +41 -0
  168. package/src/components/show/show.tsx +16 -0
  169. package/src/components/skeleton/index.ts +1 -0
  170. package/src/components/skeleton/skeleton.stories.tsx +36 -0
  171. package/src/components/skeleton/skeleton.test.tsx +14 -0
  172. package/src/components/skeleton/skeleton.tsx +15 -0
  173. package/src/components/stack/index.ts +1 -0
  174. package/src/components/stack/stack.stories.tsx +194 -0
  175. package/src/components/stack/stack.tsx +52 -0
  176. package/src/components/stepper/Stepper.tsx +190 -0
  177. package/src/components/stepper/context/stepper-context.tsx +11 -0
  178. package/src/components/stepper/index.ts +1 -0
  179. package/src/components/stepper/stepper.stories.tsx +130 -0
  180. package/src/components/stepper/stepper.test.tsx +91 -0
  181. package/src/components/switch/index.ts +1 -0
  182. package/src/components/switch/switch.stories.tsx +122 -0
  183. package/src/components/switch/switch.test.tsx +30 -0
  184. package/src/components/switch/switch.tsx +86 -0
  185. package/src/components/table/index.ts +3 -0
  186. package/src/components/table/table-primitives.tsx +122 -0
  187. package/src/components/table/table.model.ts +20 -0
  188. package/src/components/table/table.stories.tsx +169 -0
  189. package/src/components/table/table.test.tsx +91 -0
  190. package/src/components/table/table.tsx +109 -0
  191. package/src/components/table-pagination/index.ts +2 -0
  192. package/src/components/table-pagination/table-pagination.model.ts +2 -0
  193. package/src/components/table-pagination/table-pagination.stories.tsx +23 -0
  194. package/src/components/table-pagination/table-pagination.test.tsx +32 -0
  195. package/src/components/table-pagination/table-pagination.tsx +108 -0
  196. package/src/components/tabs/context/tabs-context.tsx +14 -0
  197. package/src/components/tabs/index.ts +1 -0
  198. package/src/components/tabs/tabs.stories.tsx +182 -0
  199. package/src/components/tabs/tabs.test.tsx +61 -0
  200. package/src/components/tabs/tabs.tsx +175 -0
  201. package/src/components/tag/index.ts +2 -0
  202. package/src/components/tag/tag.stories.tsx +170 -0
  203. package/src/components/tag/tag.test.tsx +18 -0
  204. package/src/components/tag/tag.tsx +99 -0
  205. package/src/components/tag/tag.variants.ts +31 -0
  206. package/src/components/textarea/index.ts +1 -0
  207. package/src/components/textarea/textarea.stories.tsx +73 -0
  208. package/src/components/textarea/textarea.tsx +105 -0
  209. package/src/components/timeline/index.ts +1 -0
  210. package/src/components/timeline/timeline-status.ts +5 -0
  211. package/src/components/timeline/timeline.stories.tsx +84 -0
  212. package/src/components/timeline/timeline.tsx +147 -0
  213. package/src/components/toast/index.ts +1 -0
  214. package/src/components/toast/toast.stories.tsx +392 -0
  215. package/src/components/toast/toast.test.tsx +50 -0
  216. package/src/components/toast/toast.tsx +411 -0
  217. package/src/components/tooltip/index.ts +1 -0
  218. package/src/components/tooltip/tooltip.stories.tsx +226 -0
  219. package/src/components/tooltip/tooltip.test.tsx +46 -0
  220. package/src/components/tooltip/tooltip.tsx +171 -0
  221. package/src/components/tree/hooks/use-controllable-tree-state.ts +80 -0
  222. package/src/components/tree/index.ts +2 -0
  223. package/src/components/tree/tree-primitives.tsx +126 -0
  224. package/src/components/tree/tree.stories.tsx +468 -0
  225. package/src/components/tree/tree.tsx +42 -0
  226. package/src/hooks/index.ts +26 -0
  227. package/src/hooks/useArray/__doc__/useArray.stories.tsx +100 -0
  228. package/src/hooks/useArray/__test__/useArray.test.tsx +88 -0
  229. package/src/hooks/useArray/index.ts +1 -0
  230. package/src/hooks/useArray/useArray.ts +76 -0
  231. package/src/hooks/useAsync/__doc__/useAsync.stories.tsx +149 -0
  232. package/src/hooks/useAsync/__test__/useAsync.test.tsx +68 -0
  233. package/src/hooks/useAsync/index.ts +1 -0
  234. package/src/hooks/useAsync/useAsync.ts +58 -0
  235. package/src/hooks/useClickOutside/__doc__/useClickOutside.stories.tsx +40 -0
  236. package/src/hooks/useClickOutside/__test__/useClickOutside.test.tsx +33 -0
  237. package/src/hooks/useClickOutside/index.ts +1 -0
  238. package/src/hooks/useClickOutside/useClickOutside.ts +26 -0
  239. package/src/hooks/useClipboard/__doc__/useClipboard.stories.tsx +45 -0
  240. package/src/hooks/useClipboard/__test__/useClipboard.test.tsx +19 -0
  241. package/src/hooks/useClipboard/index.ts +1 -0
  242. package/src/hooks/useClipboard/useClipboard.tsx +28 -0
  243. package/src/hooks/useDebounceCallback/__doc__/useDebouncedCallback.stories.tsx +84 -0
  244. package/src/hooks/useDebounceCallback/index.ts +1 -0
  245. package/src/hooks/useDebounceCallback/useDebouncedCallback.ts +23 -0
  246. package/src/hooks/useDebounceValue/__doc__/useDebouncedValue.stories.tsx +75 -0
  247. package/src/hooks/useDebounceValue/index.ts +1 -0
  248. package/src/hooks/useDebounceValue/useDebouncedValue.ts +17 -0
  249. package/src/hooks/useDisclosure/__doc__/useDisclosure.stories.tsx +39 -0
  250. package/src/hooks/useDisclosure/__test__/useDisclosure.test.ts +43 -0
  251. package/src/hooks/useDisclosure/index.ts +1 -0
  252. package/src/hooks/useDisclosure/useDisclosure.ts +37 -0
  253. package/src/hooks/useDocumentTitle/__doc__/useDocumentTitle.stories.tsx +26 -0
  254. package/src/hooks/useDocumentTitle/index.ts +1 -0
  255. package/src/hooks/useDocumentTitle/useDocumentTitle.tsx +11 -0
  256. package/src/hooks/useEventListener/__doc__/useEventListener.stories.tsx +28 -0
  257. package/src/hooks/useEventListener/__test__/useEventListener.test.tsx +26 -0
  258. package/src/hooks/useEventListener/index.ts +1 -0
  259. package/src/hooks/useEventListener/useEventListener.ts +25 -0
  260. package/src/hooks/useFocusTrap/__doc__/useFocusTrap.stories.tsx +37 -0
  261. package/src/hooks/useFocusTrap/index.ts +1 -0
  262. package/src/hooks/useFocusTrap/scopeTab.ts +38 -0
  263. package/src/hooks/useFocusTrap/tabbable.ts +70 -0
  264. package/src/hooks/useFocusTrap/useFocusTrap.ts +78 -0
  265. package/src/hooks/useHotkey/__docs__/useHotkey.stories.tsx +116 -0
  266. package/src/hooks/useHotkey/__test__/useHotkey.test.tsx +105 -0
  267. package/src/hooks/useHotkey/__utils__/create-hotkey-listener.ts +25 -0
  268. package/src/hooks/useHotkey/__utils__/index.ts +3 -0
  269. package/src/hooks/useHotkey/__utils__/is-input-field.ts +14 -0
  270. package/src/hooks/useHotkey/__utils__/match-key-modifiers.ts +25 -0
  271. package/src/hooks/useHotkey/index.ts +1 -0
  272. package/src/hooks/useHotkey/useHotkey.ts +34 -0
  273. package/src/hooks/useHover/__doc__/useHover.stories.tsx +41 -0
  274. package/src/hooks/useHover/__test__/useHover.test.tsx +45 -0
  275. package/src/hooks/useHover/index.ts +1 -0
  276. package/src/hooks/useHover/useHover.tsx +40 -0
  277. package/src/hooks/useIsVisible/__doc__/useIsVisible.stories.tsx +60 -0
  278. package/src/hooks/useIsVisible/index.ts +1 -0
  279. package/src/hooks/useIsVisible/useIsVisible.tsx +50 -0
  280. package/src/hooks/useLocalStorage/__doc__/useLocalStorage.stories.tsx +86 -0
  281. package/src/hooks/useLocalStorage/__test__/useLocalStorage.test.ts +85 -0
  282. package/src/hooks/useLocalStorage/index.ts +1 -0
  283. package/src/hooks/useLocalStorage/useLocalStorage.ts +57 -0
  284. package/src/hooks/useMediaQuery/__doc__/useMediaQuery.stories.tsx +39 -0
  285. package/src/hooks/useMediaQuery/index.ts +1 -0
  286. package/src/hooks/useMediaQuery/useMediaQuery.ts +22 -0
  287. package/src/hooks/useMemoizedFn/index.ts +1 -0
  288. package/src/hooks/useMemoizedFn/useMemoizedFn.ts +32 -0
  289. package/src/hooks/useMutation/__doc__/useMutation.stories.tsx +111 -0
  290. package/src/hooks/useMutation/__test__/useMutation.test.tsx +83 -0
  291. package/src/hooks/useMutation/index.ts +1 -0
  292. package/src/hooks/useMutation/useMutation.tsx +60 -0
  293. package/src/hooks/useObject/__doc__/useObject.stories.tsx +119 -0
  294. package/src/hooks/useObject/__test__/useObject.test.tsx +87 -0
  295. package/src/hooks/useObject/index.ts +1 -0
  296. package/src/hooks/useObject/useObject.tsx +48 -0
  297. package/src/hooks/usePagination/__doc__/usePagination.stories.tsx +72 -0
  298. package/src/hooks/usePagination/__test__/usePagination.test.tsx +98 -0
  299. package/src/hooks/usePagination/index.ts +2 -0
  300. package/src/hooks/usePagination/usePagination.tsx +74 -0
  301. package/src/hooks/usePortal/__doc__/usePortal.stories.tsx +19 -0
  302. package/src/hooks/usePortal/__test__/usePortal.test.tsx +20 -0
  303. package/src/hooks/usePortal/index.ts +1 -0
  304. package/src/hooks/usePortal/usePortal.ts +40 -0
  305. package/src/hooks/usePreventCloseWindow/__doc__/usePreventCloseWindow.stories.tsx +32 -0
  306. package/src/hooks/usePreventCloseWindow/index.ts +1 -0
  307. package/src/hooks/usePreventCloseWindow/usePreventCloseWindow.ts +33 -0
  308. package/src/hooks/useRangePagination/__test__/useRangePagination.test.tsx +63 -0
  309. package/src/hooks/useRangePagination/index.ts +2 -0
  310. package/src/hooks/useRangePagination/useRangePagination.tsx +72 -0
  311. package/src/hooks/useSelection/__doc__/useSelection.stories.tsx +140 -0
  312. package/src/hooks/useSelection/__test__/useSelection.test.tsx +57 -0
  313. package/src/hooks/useSelection/index.ts +1 -0
  314. package/src/hooks/useSelection/useSelection.ts +121 -0
  315. package/src/hooks/useStep/__doc__/useStep.stories.tsx +98 -0
  316. package/src/hooks/useStep/__test__/useStep.test.ts +51 -0
  317. package/src/hooks/useStep/index.ts +1 -0
  318. package/src/hooks/useStep/useStep.ts +57 -0
  319. package/src/hooks/useToggle/__doc__/useToggle.stories.tsx +25 -0
  320. package/src/hooks/useToggle/__test__/useToggle.test.tsx +43 -0
  321. package/src/hooks/useToggle/index.ts +1 -0
  322. package/src/hooks/useToggle/useToggle.ts +16 -0
  323. package/src/index.ts +6 -0
  324. package/src/lib/cn.ts +8 -0
  325. package/src/lib/index.ts +1 -0
  326. package/src/models/Generic.model.ts +67 -0
  327. package/src/models/index.ts +1 -0
  328. package/src/providers/index.ts +2 -0
  329. package/src/providers/library-provider.tsx +44 -0
  330. package/src/providers/theme/ThemeProvider.tsx +25 -0
  331. package/src/providers/theme/index.ts +3 -0
  332. package/src/providers/theme/types.ts +11 -0
  333. package/src/providers/theme/useThemeProps.ts +25 -0
  334. package/src/stores/theme.store.ts +31 -0
  335. package/src/styles/components.css +4 -0
  336. package/src/styles/index.css +2 -0
  337. package/src/styles/library.css +2 -0
  338. package/src/styles/theme.css +232 -0
  339. package/src/utils/dates/parseDateRange.utility.ts +39 -0
  340. package/src/utils/form.tsx +91 -0
  341. package/src/utils/functions/createSafeContext.ts +17 -0
  342. package/src/utils/functions/ensureReactElement.tsx +30 -0
  343. package/src/utils/functions/getFormData.ts +19 -0
  344. package/src/utils/functions/index.ts +4 -0
  345. package/src/utils/functions/mergeRefs.ts +18 -0
  346. package/src/utils/index.ts +3 -0
  347. package/src/utils/strings/extractInitials.utility.ts +10 -0
  348. package/src/utils/strings/index.ts +1 -0
  349. package/src/utils/tests/click.ts +3 -0
  350. package/src/utils/tests/index.ts +2 -0
  351. package/src/utils/tests/keyboard.ts +21 -0
  352. package/src/utils/tests/type.ts +6 -0
@@ -0,0 +1,66 @@
1
+ type Props = {
2
+ valueKey: string | number | symbol;
3
+ values: string[];
4
+ setValues: (values: string[]) => void;
5
+ items: any[];
6
+ maxCount: number;
7
+ setIsPopoverOpen: (open: any) => void;
8
+ };
9
+
10
+ export const useMultiSelect = ({
11
+ valueKey,
12
+ values,
13
+ setValues,
14
+ items,
15
+ maxCount,
16
+ setIsPopoverOpen,
17
+ }: Props) => {
18
+ const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
19
+ if (event.key === "Enter") {
20
+ setIsPopoverOpen(true);
21
+ } else if (event.key === "Backspace" && !event.currentTarget.value) {
22
+ const newSelectedValues = [...values];
23
+ newSelectedValues.pop();
24
+ setValues?.(newSelectedValues);
25
+ }
26
+ };
27
+
28
+ const toggleOption = (option: string) => {
29
+ const newSelectedValues = values.includes(option)
30
+ ? values.filter((value) => value !== option)
31
+ : [...values, option];
32
+ setValues?.(newSelectedValues);
33
+ };
34
+
35
+ const handleClear = () => {
36
+ setValues?.([]);
37
+ };
38
+
39
+ const handleTogglePopover = () => {
40
+ setIsPopoverOpen((prev: boolean) => !prev);
41
+ };
42
+
43
+ const clearExtraOptions = () => {
44
+ const newSelectedValues = values.slice(0, maxCount);
45
+ setValues?.(newSelectedValues);
46
+ };
47
+
48
+ const toggleAll = () => {
49
+ const allowedItems = items.filter((option) => !option.disabled);
50
+ if (values.length === allowedItems.length) {
51
+ handleClear();
52
+ } else {
53
+ const allValues = allowedItems.map((option) => option[valueKey]);
54
+ setValues?.(allValues);
55
+ }
56
+ };
57
+
58
+ return {
59
+ handleInputKeyDown,
60
+ toggleOption,
61
+ handleClear,
62
+ handleTogglePopover,
63
+ clearExtraOptions,
64
+ toggleAll,
65
+ };
66
+ };
@@ -0,0 +1 @@
1
+ export * from "./multi-select";
@@ -0,0 +1,294 @@
1
+ import { faker } from "@faker-js/faker";
2
+ import { Meta, StoryObj } from "@storybook/react-vite";
3
+ import { useState } from "react";
4
+ import { Avatar, Button, MultiSelect } from "../../components";
5
+
6
+ const generateRandomOption = () => ({
7
+ label: faker.person.fullName(),
8
+ value: faker.string.uuid(),
9
+ });
10
+
11
+ const items = faker.helpers.multiple(generateRandomOption, { count: 10 });
12
+
13
+ const meta: Meta<typeof MultiSelect> = {
14
+ title: "Data entry/MultiSelect",
15
+ component: MultiSelect,
16
+ args: {
17
+ items,
18
+ },
19
+ parameters: {
20
+ badges: ["new"],
21
+ },
22
+ };
23
+
24
+ export default meta;
25
+
26
+ type Story = StoryObj<typeof MultiSelect>;
27
+
28
+ export const Default: Story = {
29
+ args: {
30
+ withCheckbox: false,
31
+ defaultValue: [items[0].value],
32
+ },
33
+ };
34
+
35
+ export const Primary: Story = {
36
+ args: {
37
+ variant: "primary",
38
+ defaultValue: [items[0].value],
39
+ },
40
+ };
41
+
42
+ export const Secondary: Story = {
43
+ args: {
44
+ variant: "secondary",
45
+ defaultValue: [items[0].value],
46
+ },
47
+ };
48
+
49
+ export const OnlyOptions: Story = {
50
+ args: {
51
+ showSelectAll: false,
52
+ showSearch: false,
53
+ defaultValue: [items[0].value],
54
+ },
55
+ };
56
+
57
+ export const Destructive: Story = {
58
+ args: {
59
+ variant: "error",
60
+ defaultValue: [items[0].value],
61
+ },
62
+ };
63
+
64
+ /**
65
+ * Por defecto el componente `MultiSelect` espera `items` con la siguiente interfaz
66
+ *
67
+ * ```tsx
68
+ * interface Option = {
69
+ * label: string;
70
+ * value: string;
71
+ * }
72
+ * ```
73
+ *
74
+ * En caso de tener un objeto con otra interfaz utilizar la propiedad `valueKey` para identificar el valor y `labelKey` para identificar el label
75
+ *
76
+ * ```tsx
77
+ * type Animal = {
78
+ * key: string;
79
+ * name: string;
80
+ * emoji: string;
81
+ * }
82
+ *
83
+ * const animals: Animal[] = [
84
+ * { key: "cat", name: "Cat", emoji: "🐱" },
85
+ * { key: "dog", name: "Dog", emoji: "🐶" },
86
+ * ];
87
+ *
88
+ * <MultiSelect
89
+ * valueKey="key"
90
+ * labelKey="name"
91
+ * items={animals}
92
+ * />
93
+ *
94
+ * ```
95
+ */
96
+
97
+ export const CustomObject: Story = {
98
+ render: () => {
99
+ type Animal = {
100
+ key: string;
101
+ name: string;
102
+ emoji: string;
103
+ };
104
+
105
+ const animals: Animal[] = [
106
+ { key: "cat", name: "Cat", emoji: "🐱" },
107
+ { key: "dog", name: "Dog", emoji: "🐶" },
108
+ ];
109
+
110
+ return (
111
+ <MultiSelect<Animal>
112
+ items={animals}
113
+ valueKey="key"
114
+ labelKey="name"
115
+ renderOption={(item: Animal) => `${item.emoji} ${item.name}`}
116
+ />
117
+ );
118
+ },
119
+ };
120
+
121
+ const dataDisabled = [
122
+ {
123
+ label: faker.person.fullName(),
124
+ value: faker.string.uuid(),
125
+ disabled: true,
126
+ },
127
+ {
128
+ label: faker.person.fullName(),
129
+ value: faker.string.uuid(),
130
+ disabled: false,
131
+ },
132
+ {
133
+ label: faker.person.fullName(),
134
+ value: faker.string.uuid(),
135
+ disabled: true,
136
+ },
137
+ {
138
+ label: faker.person.fullName(),
139
+ value: faker.string.uuid(),
140
+ disabled: false,
141
+ },
142
+ ];
143
+
144
+ /**
145
+ * Se puede deshabilitar cada opción
146
+ *
147
+ * ```tsx
148
+ * const data = [
149
+ * {
150
+ * label: faker.person.fullName(),
151
+ * value: faker.string.uuid(),
152
+ * disabled: true,
153
+ * }
154
+ * ]
155
+ *
156
+ * ```
157
+ */
158
+ export const WithDisabledOptions: Story = {
159
+ args: {
160
+ items: dataDisabled,
161
+ },
162
+ };
163
+
164
+ const data = [
165
+ {
166
+ label: faker.person.fullName(),
167
+ value: faker.string.uuid(),
168
+ image: faker.image.avatar(),
169
+ },
170
+ {
171
+ label: faker.person.fullName(),
172
+ value: faker.string.uuid(),
173
+ image: faker.image.avatar(),
174
+ },
175
+ {
176
+ label: faker.person.fullName(),
177
+ value: faker.string.uuid(),
178
+ image: faker.image.avatar(),
179
+ },
180
+ {
181
+ label: faker.person.fullName(),
182
+ value: faker.string.uuid(),
183
+ image: faker.image.avatar(),
184
+ },
185
+ ];
186
+
187
+ /**
188
+ * Se puede customizar el contenido que se renderiza por cada opción
189
+ *
190
+ * ```tsx
191
+ * const data = [
192
+ * {
193
+ * label: faker.person.fullName(),
194
+ * value: faker.string.uuid(),
195
+ * image: faker.image.avatar(),
196
+ * }
197
+ * ]
198
+ *
199
+ * <MultiSelect
200
+ * items={data}
201
+ * renderOption={(option) => (
202
+ * <div className="flex items-center gap-2">
203
+ * <Avatar
204
+ * src={option.image}
205
+ * alt={option.label}
206
+ * className="w-6 h-6"
207
+ * />
208
+ * {option.label}
209
+ * </div>
210
+ * )}
211
+ * />
212
+ * ```
213
+ */
214
+ export const CustomRender: Story = {
215
+ args: {
216
+ items: data,
217
+ renderOption: (option) => (
218
+ <div className="flex items-center gap-2">
219
+ <Avatar src={option.image} alt={option.label} className="w-6 h-6" />
220
+ {option.label}
221
+ </div>
222
+ ),
223
+ },
224
+ };
225
+
226
+ export const Disabled: Story = {
227
+ args: {
228
+ disabled: true,
229
+ },
230
+ };
231
+
232
+ export const ControlledValue: Story = {
233
+ args: {
234
+ defaultValue: [items[0].value],
235
+ },
236
+ render: (args) => {
237
+ const [value, setValue] = useState([items[0].value]);
238
+ return (
239
+ <div className="space-y-2">
240
+ <div className="flex gap-2 items-center ">
241
+ <Button onClick={() => setValue([items[0].value])}>
242
+ Seleccionar primera opción
243
+ </Button>
244
+ <Button onClick={() => setValue([])}>Limpiar selección</Button>
245
+ <Button onClick={() => setValue(items.map((item) => item.value))}>
246
+ Seleccionar todas las opciones
247
+ </Button>
248
+ </div>
249
+
250
+ <MultiSelect {...args} value={value} onChange={setValue} />
251
+ <pre className="rounded-md bg-slate-950 p-4 text-white">
252
+ <code className="block">
253
+ Selected:{" "}
254
+ <span className="text-blue-300">
255
+ {JSON.stringify(value, null, 2)}
256
+ </span>
257
+ </code>
258
+ </pre>
259
+ </div>
260
+ );
261
+ },
262
+ };
263
+
264
+ /**
265
+ * Se puede controlar el estado de apertura del popover
266
+ *
267
+ * ```tsx
268
+ * type OpenProps = {
269
+ * open?: boolean;
270
+ * onOpenChange?: (open: boolean) => void;
271
+ * defaultOpen?: boolean;
272
+ * };
273
+ * ```
274
+ */
275
+ export const ControlledOpen: Story = {
276
+ render: () => {
277
+ const [open, setOpen] = useState(false);
278
+ return (
279
+ <div className="space-y-2">
280
+ <div className="flex gap-2 items-center">
281
+ <Button onClick={() => setOpen(true)}>Abrir</Button>
282
+ <Button onClick={() => setOpen(false)}>Cerrar</Button>
283
+ </div>
284
+
285
+ <MultiSelect
286
+ open={open}
287
+ onOpenChange={setOpen}
288
+ items={items}
289
+ defaultOpen
290
+ />
291
+ </div>
292
+ );
293
+ },
294
+ };
@@ -0,0 +1,300 @@
1
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ import { CheckIcon, ChevronsUpDown, XIcon } from "lucide-react";
4
+ import * as React from "react";
5
+ import { Option, OverrideProps } from "@/models";
6
+ import { Tag } from "../../components/tag";
7
+ import { cn } from "../../lib";
8
+ import {
9
+ AutoCompleteEmpty,
10
+ AutoCompleteGroup,
11
+ AutoCompleteInput,
12
+ AutoCompleteItem,
13
+ AutoCompleteList,
14
+ AutoCompleteRoot,
15
+ } from "../auto-complete";
16
+ import { Divider } from "../divider";
17
+ import { PopoverPopup, PopoverRoot, PopoverTrigger } from "../popover";
18
+ import { useMultiSelect } from "./hooks/use-multi-select";
19
+ import { multiSelectVariants } from "./multi-select.variants";
20
+
21
+ type OpenProps = {
22
+ open?: boolean;
23
+ onOpenChange?: (open: boolean) => void;
24
+ defaultOpen?: boolean;
25
+ };
26
+
27
+ type MultiSelectProps<TItem extends Record<string, any>> = OverrideProps<
28
+ React.ButtonHTMLAttributes<HTMLButtonElement> &
29
+ OpenProps &
30
+ VariantProps<typeof multiSelectVariants>,
31
+ {
32
+ items: TItem[];
33
+ /**
34
+ * Identificador del valor del elemento
35
+ * @default "value"
36
+ */
37
+ valueKey?: keyof TItem;
38
+ /**
39
+ * Identificador del label del elemento
40
+ * @default "label"
41
+ */
42
+ value?: string[];
43
+ onChange?: (value: string[]) => void;
44
+ defaultValue?: string[];
45
+ labelKey?: keyof TItem;
46
+ placeholder?: string;
47
+ /**
48
+ * Cantidad máxima de elementos que se van a visualizar
49
+ * @default 3
50
+ */
51
+ maxCount?: number;
52
+ className?: string;
53
+ renderOption?: (item: TItem) => React.ReactNode;
54
+ withCheckbox?: boolean;
55
+ /**
56
+ * Para mostrar o no la barra de búsqueda
57
+ * @default true
58
+ */
59
+ showSearch?: boolean;
60
+ /**
61
+ * Para mostrar o no el "Seleccionar todos"
62
+ * @default true
63
+ */
64
+ showSelectAll?: boolean;
65
+ /**
66
+ * Props del PopoverRoot
67
+ */
68
+ rootProps?: React.ComponentPropsWithoutRef<typeof PopoverRoot>;
69
+ }
70
+ >;
71
+
72
+ export const MultiSelect = <TItem extends Record<string, any> = Option>({
73
+ items = [],
74
+ value,
75
+ valueKey = "value" as keyof TItem,
76
+ labelKey = "label" as keyof TItem,
77
+ onChange,
78
+ variant,
79
+ defaultValue = [],
80
+ placeholder = "Seleccionar",
81
+ maxCount = 3,
82
+ className,
83
+ renderOption = (item: TItem) => item[labelKey],
84
+ withCheckbox = false,
85
+ showSearch = true,
86
+ showSelectAll = true,
87
+ rootProps,
88
+ ...props
89
+ }: MultiSelectProps<TItem>) => {
90
+ const [values = [], setValues] = useControllableState<string[]>({
91
+ prop: value,
92
+ onChange: onChange,
93
+ defaultProp: defaultValue,
94
+ });
95
+
96
+ const [isPopoverOpen, setIsPopoverOpen] = useControllableState({
97
+ prop: props.open,
98
+ onChange: props.onOpenChange,
99
+ defaultProp: props.defaultOpen || false,
100
+ });
101
+
102
+ const allowedOptions = React.useMemo(
103
+ () => items.filter((i: TItem): boolean => !i.disabled),
104
+ [items],
105
+ );
106
+
107
+ const {
108
+ handleInputKeyDown,
109
+ toggleOption,
110
+ handleClear,
111
+ handleTogglePopover,
112
+ clearExtraOptions,
113
+ toggleAll,
114
+ } = useMultiSelect({
115
+ valueKey,
116
+ values,
117
+ setValues,
118
+ items,
119
+ maxCount,
120
+ setIsPopoverOpen,
121
+ });
122
+
123
+ return (
124
+ <PopoverRoot
125
+ open={isPopoverOpen}
126
+ onOpenChange={setIsPopoverOpen}
127
+ data-slot="multi-select"
128
+ {...rootProps}
129
+ >
130
+ <PopoverTrigger
131
+ {...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}
132
+ data-slot="multi-select-trigger"
133
+ onClick={handleTogglePopover}
134
+ className={cn(
135
+ "flex w-full p-1 rounded-md border border-input min-h-10 h-auto items-center justify-between bg-inherit hover:bg-inherit",
136
+ className,
137
+ )}
138
+ >
139
+ {values.length > 0 ? (
140
+ <div className="flex justify-between items-center w-full">
141
+ <div
142
+ className="flex flex-wrap items-center"
143
+ data-slot="multi-select-tags"
144
+ >
145
+ {values.slice(0, maxCount).map((value) => {
146
+ const option = items.find((o) => o[valueKey] === value);
147
+ const IconComponent = option?.icon;
148
+ return (
149
+ <Tag
150
+ key={value}
151
+ data-slot="multi-select-tag"
152
+ className={cn(multiSelectVariants({ variant }))}
153
+ closable
154
+ onClose={() => toggleOption(value)}
155
+ >
156
+ {IconComponent && (
157
+ <IconComponent className="h-4 w-4 mr-2" />
158
+ )}
159
+ {option && renderOption?.(option)}
160
+ </Tag>
161
+ );
162
+ })}
163
+ {values.length > maxCount && (
164
+ <Tag
165
+ data-slot="multi-select-tag"
166
+ className={cn(multiSelectVariants({ variant }))}
167
+ closable
168
+ onClose={clearExtraOptions}
169
+ >
170
+ {`+ ${values.length - maxCount} más`}
171
+ </Tag>
172
+ )}
173
+ </div>
174
+ <div className="flex items-center justify-between">
175
+ <XIcon
176
+ data-slot="multi-select-clear"
177
+ className="h-4 mx-2 cursor-pointer text-muted-foreground"
178
+ onClick={(event) => {
179
+ event.stopPropagation();
180
+ handleClear();
181
+ }}
182
+ />
183
+ <Divider
184
+ data-slot="multi-select-divider"
185
+ orientation="vertical"
186
+ className="flex min-h-6 h-full"
187
+ />
188
+ <ChevronsUpDown
189
+ data-slot="multi-select-trigger-icon"
190
+ className="h-4 mx-2 cursor-pointer text-muted-foreground"
191
+ />
192
+ </div>
193
+ </div>
194
+ ) : (
195
+ <div
196
+ className="flex items-center justify-between w-full mx-auto"
197
+ data-slot="multi-select-trigger-empty"
198
+ >
199
+ <span
200
+ className="text-sm text-foreground font-normal mx-2"
201
+ data-slot="multi-select-placeholder"
202
+ >
203
+ {placeholder}
204
+ </span>
205
+ <ChevronsUpDown
206
+ data-slot="multi-select-trigger-icon"
207
+ className="h-4 cursor-pointer text-muted-foreground mx-2"
208
+ />
209
+ </div>
210
+ )}
211
+ </PopoverTrigger>
212
+ <PopoverPopup
213
+ data-slot="multi-select-content"
214
+ className="p-0 min-w-(--anchor-width)"
215
+ align="start"
216
+ >
217
+ <AutoCompleteRoot>
218
+ {showSearch && (
219
+ <AutoCompleteInput
220
+ data-slot="multi-select-input"
221
+ placeholder="Buscar..."
222
+ onKeyDown={handleInputKeyDown}
223
+ />
224
+ )}
225
+ <AutoCompleteList data-slot="multi-select-list">
226
+ <AutoCompleteEmpty data-slot="multi-select-empty">
227
+ No results found.
228
+ </AutoCompleteEmpty>
229
+ <AutoCompleteGroup data-slot="multi-select-group">
230
+ {showSelectAll && (
231
+ <AutoCompleteItem
232
+ data-slot="multi-select-item"
233
+ key="all"
234
+ onSelect={toggleAll}
235
+ className={cn(
236
+ "cursor-pointer",
237
+ !withCheckbox &&
238
+ values.length === allowedOptions.length &&
239
+ "bg-accent text-accent-foreground",
240
+ )}
241
+ >
242
+ {withCheckbox && (
243
+ <div
244
+ className={cn(
245
+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
246
+ values.length === allowedOptions.length
247
+ ? "bg-primary text-primary-foreground"
248
+ : "opacity-50 [&_svg]:invisible",
249
+ )}
250
+ >
251
+ <CheckIcon className="h-4 w-4" />
252
+ </div>
253
+ )}
254
+ <span>(Seleccionar todo)</span>
255
+ </AutoCompleteItem>
256
+ )}
257
+ {items.map((option) => {
258
+ const isSelected = values.includes(option[valueKey]);
259
+ return (
260
+ <AutoCompleteItem
261
+ data-slot="multi-select-item"
262
+ key={option[valueKey]}
263
+ onSelect={() =>
264
+ !option.disabled && toggleOption(option[valueKey])
265
+ }
266
+ className={cn(
267
+ option.disabled
268
+ ? "!bg-neutral-50 !text-neutral-400"
269
+ : "cursor-pointer",
270
+ !withCheckbox &&
271
+ isSelected &&
272
+ "!bg-accent !text-accent-foreground",
273
+ )}
274
+ >
275
+ {withCheckbox && (
276
+ <div
277
+ className={cn(
278
+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
279
+ isSelected
280
+ ? "bg-primary text-primary-foreground"
281
+ : "opacity-50 [&_svg]:invisible",
282
+ )}
283
+ >
284
+ <CheckIcon className="h-4 w-4" />
285
+ </div>
286
+ )}
287
+ {option.icon && (
288
+ <option.icon className="mr-2 h-4 w-4 text-muted-foreground" />
289
+ )}
290
+ <span>{renderOption?.(option)}</span>
291
+ </AutoCompleteItem>
292
+ );
293
+ })}
294
+ </AutoCompleteGroup>
295
+ </AutoCompleteList>
296
+ </AutoCompleteRoot>
297
+ </PopoverPopup>
298
+ </PopoverRoot>
299
+ );
300
+ };
@@ -0,0 +1,22 @@
1
+ import { cva } from "class-variance-authority";
2
+
3
+ export const multiSelectVariants = cva(
4
+ "m-1 transition ease-in-out delay-150 duration-300",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ default:
9
+ "border-foreground/10 border text-foreground bg-card hover:bg-card/80",
10
+ primary:
11
+ "border-foreground/10 border text-foreground bg-primary text-primary-foreground hover:bg-primary/80",
12
+ secondary:
13
+ "border-foreground/60 border bg-secondary text-secondary-foreground hover:bg-secondary/80",
14
+ error:
15
+ "border-transparent bg-error text-error-foreground hover:bg-error/80",
16
+ },
17
+ },
18
+ defaultVariants: {
19
+ variant: "default",
20
+ },
21
+ },
22
+ );
@@ -0,0 +1 @@
1
+ export * from "./number-input";