@brightlocal/ui-components 3.1.0 → 3.3.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 (463) hide show
  1. package/AI_USAGE.md +10 -0
  2. package/README.md +8 -1
  3. package/component-meta.json +1591 -123
  4. package/deprecations.json +45 -1
  5. package/dist/_virtual/_rolldown/runtime.cjs +1 -0
  6. package/dist/accordion.cjs +1 -1
  7. package/dist/accordion.js +73 -102
  8. package/dist/alert-dialog.cjs +1 -1
  9. package/dist/alert-dialog.d.ts +36 -5
  10. package/dist/alert-dialog.d.ts.map +1 -1
  11. package/dist/alert-dialog.js +83 -128
  12. package/dist/alert.cjs +1 -1
  13. package/dist/alert.d.ts +4 -4
  14. package/dist/alert.d.ts.map +1 -1
  15. package/dist/alert.js +116 -177
  16. package/dist/aspect-ratio.cjs +1 -1
  17. package/dist/aspect-ratio.js +13 -16
  18. package/dist/avatar.cjs +1 -1
  19. package/dist/avatar.js +30 -45
  20. package/dist/badge.cjs +1 -1
  21. package/dist/badge.d.ts +32 -1
  22. package/dist/badge.d.ts.map +1 -1
  23. package/dist/badge.js +90 -71
  24. package/dist/banner.cjs +1 -0
  25. package/dist/banner.d.ts +81 -0
  26. package/dist/banner.d.ts.map +1 -0
  27. package/dist/banner.js +130 -0
  28. package/dist/blocks/empty-state.cjs +1 -1
  29. package/dist/blocks/empty-state.d.ts +24 -6
  30. package/dist/blocks/empty-state.d.ts.map +1 -1
  31. package/dist/blocks/empty-state.js +74 -140
  32. package/dist/blocks/input-list.cjs +2 -2
  33. package/dist/blocks/input-list.d.ts +2 -2
  34. package/dist/blocks/input-list.d.ts.map +1 -1
  35. package/dist/blocks/input-list.js +136 -176
  36. package/dist/blocks/progress-state.cjs +1 -1
  37. package/dist/blocks/progress-state.d.ts +2 -2
  38. package/dist/blocks/progress-state.js +223 -347
  39. package/dist/blocks/sidebar.cjs +1 -1
  40. package/dist/blocks/sidebar.d.ts +28 -6
  41. package/dist/blocks/sidebar.d.ts.map +1 -1
  42. package/dist/blocks/sidebar.js +763 -1086
  43. package/dist/brand-illustration-motif.cjs +1 -1
  44. package/dist/brand-illustration-motif.d.ts +1 -1
  45. package/dist/brand-illustration-motif.js +40 -61
  46. package/dist/breadcrumb.cjs +1 -1
  47. package/dist/breadcrumb.js +62 -102
  48. package/dist/button-group.cjs +1 -1
  49. package/dist/button-group.js +23 -31
  50. package/dist/button.cjs +1 -1
  51. package/dist/button.d.ts +4 -2
  52. package/dist/button.d.ts.map +1 -1
  53. package/dist/button.js +149 -189
  54. package/dist/calendar.cjs +1 -1
  55. package/dist/calendar.d.ts +87 -3
  56. package/dist/calendar.d.ts.map +1 -1
  57. package/dist/calendar.js +116 -173
  58. package/dist/callout.cjs +1 -1
  59. package/dist/callout.js +73 -96
  60. package/dist/card.cjs +1 -1
  61. package/dist/card.d.ts +92 -6
  62. package/dist/card.d.ts.map +1 -1
  63. package/dist/card.js +240 -234
  64. package/dist/carousel.cjs +1 -1
  65. package/dist/carousel.d.ts +3 -3
  66. package/dist/carousel.d.ts.map +1 -1
  67. package/dist/carousel.js +174 -268
  68. package/dist/centred-layout.cjs +1 -1
  69. package/dist/centred-layout.js +27 -48
  70. package/dist/chart-empty.cjs +1 -1
  71. package/dist/chart-empty.js +18 -27
  72. package/dist/chart.cjs +7 -7
  73. package/dist/chart.d.ts +253 -25
  74. package/dist/chart.d.ts.map +1 -1
  75. package/dist/chart.js +465 -511
  76. package/dist/checkbox.cjs +1 -1
  77. package/dist/checkbox.d.ts +1 -1
  78. package/dist/checkbox.d.ts.map +1 -1
  79. package/dist/checkbox.js +37 -69
  80. package/dist/chip.cjs +1 -1
  81. package/dist/chip.js +116 -173
  82. package/dist/collapsible.cjs +1 -1
  83. package/dist/collapsible.d.ts.map +1 -1
  84. package/dist/collapsible.js +35 -41
  85. package/dist/combobox.cjs +3 -3
  86. package/dist/combobox.d.ts +14 -4
  87. package/dist/combobox.d.ts.map +1 -1
  88. package/dist/combobox.js +440 -639
  89. package/dist/command.cjs +1 -1
  90. package/dist/command.d.ts.map +1 -1
  91. package/dist/command.js +273 -420
  92. package/dist/context-menu.cjs +1 -1
  93. package/dist/context-menu.d.ts +5 -5
  94. package/dist/context-menu.d.ts.map +1 -1
  95. package/dist/context-menu.js +121 -191
  96. package/dist/data-table.cjs +1 -1
  97. package/dist/data-table.d.ts +442 -144
  98. package/dist/data-table.d.ts.map +1 -1
  99. package/dist/data-table.js +708 -835
  100. package/dist/date-picker.cjs +1 -1
  101. package/dist/date-picker.d.ts +15 -4
  102. package/dist/date-picker.d.ts.map +1 -1
  103. package/dist/date-picker.js +156 -231
  104. package/dist/delta.cjs +1 -0
  105. package/dist/delta.d.ts +79 -0
  106. package/dist/delta.d.ts.map +1 -0
  107. package/dist/delta.js +62 -0
  108. package/dist/description.cjs +1 -1
  109. package/dist/description.js +11 -20
  110. package/dist/dialog.cjs +1 -1
  111. package/dist/dialog.d.ts +1 -1
  112. package/dist/dialog.d.ts.map +1 -1
  113. package/dist/dialog.js +76 -116
  114. package/dist/drawer.cjs +1 -1
  115. package/dist/drawer.d.ts +11 -11
  116. package/dist/drawer.d.ts.map +1 -1
  117. package/dist/drawer.js +76 -134
  118. package/dist/dropdown-menu.cjs +1 -1
  119. package/dist/dropdown-menu.d.ts +6 -6
  120. package/dist/dropdown-menu.d.ts.map +1 -1
  121. package/dist/dropdown-menu.js +179 -300
  122. package/dist/field.cjs +1 -1
  123. package/dist/field.d.ts +9 -9
  124. package/dist/field.d.ts.map +1 -1
  125. package/dist/field.js +166 -286
  126. package/dist/global-layout.cjs +1 -1
  127. package/dist/global-layout.js +203 -342
  128. package/dist/grid.cjs +1 -1
  129. package/dist/grid.d.ts +24 -1
  130. package/dist/grid.d.ts.map +1 -1
  131. package/dist/grid.js +16 -29
  132. package/dist/header.cjs +1 -1
  133. package/dist/header.js +21 -38
  134. package/dist/height-transition.cjs +1 -1
  135. package/dist/height-transition.js +38 -55
  136. package/dist/hooks/use-breakpoint.cjs +1 -1
  137. package/dist/hooks/use-breakpoint.d.ts +1 -1
  138. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  139. package/dist/hooks/use-breakpoint.js +10 -9
  140. package/dist/hooks/use-debounce.cjs +1 -1
  141. package/dist/hooks/use-debounce.js +12 -11
  142. package/dist/hooks/use-delayed-pending.cjs +1 -1
  143. package/dist/hooks/use-delayed-pending.js +8 -9
  144. package/dist/hooks/use-filter-search-params.cjs +1 -0
  145. package/dist/hooks/use-filter-search-params.d.ts +93 -0
  146. package/dist/hooks/use-filter-search-params.d.ts.map +1 -0
  147. package/dist/hooks/use-filter-search-params.js +122 -0
  148. package/dist/hooks/use-mobile.cjs +1 -1
  149. package/dist/hooks/use-mobile.js +6 -6
  150. package/dist/hooks/use-overlay-pointer-lock.cjs +1 -1
  151. package/dist/hooks/use-overlay-pointer-lock.js +8 -9
  152. package/dist/hooks/use-prefers-reduced-motion.cjs +1 -1
  153. package/dist/hooks/use-prefers-reduced-motion.js +5 -8
  154. package/dist/hover-card.cjs +1 -1
  155. package/dist/hover-card.d.ts +1 -1
  156. package/dist/hover-card.d.ts.map +1 -1
  157. package/dist/hover-card.js +30 -62
  158. package/dist/index.cjs +1 -1
  159. package/dist/index.d.ts +11 -0
  160. package/dist/index.d.ts.map +1 -1
  161. package/dist/index.js +636 -582
  162. package/dist/info-tooltip.cjs +1 -0
  163. package/dist/info-tooltip.d.ts +39 -0
  164. package/dist/info-tooltip.d.ts.map +1 -0
  165. package/dist/info-tooltip.js +27 -0
  166. package/dist/input-chip.cjs +1 -1
  167. package/dist/input-chip.d.ts +32 -3
  168. package/dist/input-chip.d.ts.map +1 -1
  169. package/dist/input-chip.js +182 -231
  170. package/dist/input-group.cjs +1 -1
  171. package/dist/input-group.d.ts +33 -2
  172. package/dist/input-group.d.ts.map +1 -1
  173. package/dist/input-group.js +188 -122
  174. package/dist/input-otp.cjs +1 -1
  175. package/dist/input-otp.d.ts +3 -3
  176. package/dist/input-otp.d.ts.map +1 -1
  177. package/dist/input-otp.js +102 -146
  178. package/dist/input-password.cjs +1 -1
  179. package/dist/input-password.d.ts +26 -8
  180. package/dist/input-password.d.ts.map +1 -1
  181. package/dist/input-password.js +139 -171
  182. package/dist/input.cjs +1 -1
  183. package/dist/input.d.ts.map +1 -1
  184. package/dist/input.js +51 -73
  185. package/dist/label.cjs +1 -1
  186. package/dist/label.js +20 -38
  187. package/dist/lib/block-illustration.cjs +1 -1
  188. package/dist/lib/block-illustration.d.ts +5 -2
  189. package/dist/lib/block-illustration.d.ts.map +1 -1
  190. package/dist/lib/block-illustration.js +16 -17
  191. package/dist/lib/compose-event-handlers.cjs +1 -0
  192. package/dist/lib/compose-event-handlers.d.ts +9 -0
  193. package/dist/lib/compose-event-handlers.d.ts.map +1 -0
  194. package/dist/lib/compose-event-handlers.js +8 -0
  195. package/dist/lib/download-file.cjs +1 -0
  196. package/dist/lib/download-file.d.ts +14 -0
  197. package/dist/lib/download-file.d.ts.map +1 -0
  198. package/dist/lib/download-file.js +40 -0
  199. package/dist/lib/empty-canvas.cjs +1 -1
  200. package/dist/lib/empty-canvas.js +28 -56
  201. package/dist/lib/empty-chip.cjs +1 -1
  202. package/dist/lib/empty-chip.d.ts +14 -3
  203. package/dist/lib/empty-chip.d.ts.map +1 -1
  204. package/dist/lib/empty-chip.js +15 -11
  205. package/dist/lib/field-aria.cjs +1 -0
  206. package/dist/lib/field-aria.d.ts +34 -0
  207. package/dist/lib/field-aria.d.ts.map +1 -0
  208. package/dist/lib/field-aria.js +52 -0
  209. package/dist/lib/image-file-info.cjs +1 -0
  210. package/dist/lib/image-file-info.d.ts +25 -0
  211. package/dist/lib/image-file-info.d.ts.map +1 -0
  212. package/dist/lib/image-file-info.js +67 -0
  213. package/dist/lib/media-viewer-content.cjs +1 -0
  214. package/dist/lib/media-viewer-content.d.ts +102 -0
  215. package/dist/lib/media-viewer-content.d.ts.map +1 -0
  216. package/dist/lib/media-viewer-content.js +650 -0
  217. package/dist/lib/media-viewer-internal.cjs +1 -0
  218. package/dist/lib/media-viewer-internal.d.ts +98 -0
  219. package/dist/lib/media-viewer-internal.d.ts.map +1 -0
  220. package/dist/lib/media-viewer-internal.js +61 -0
  221. package/dist/lib/media-viewer-motion.cjs +1 -0
  222. package/dist/lib/media-viewer-motion.d.ts +40 -0
  223. package/dist/lib/media-viewer-motion.d.ts.map +1 -0
  224. package/dist/lib/media-viewer-motion.js +37 -0
  225. package/dist/lib/motion.cjs +1 -1
  226. package/dist/lib/motion.d.ts +8 -0
  227. package/dist/lib/motion.d.ts.map +1 -1
  228. package/dist/lib/motion.js +11 -10
  229. package/dist/lib/optical-center.cjs +1 -1
  230. package/dist/lib/optical-center.d.ts +1 -1
  231. package/dist/lib/optical-center.d.ts.map +1 -1
  232. package/dist/lib/optical-center.js +12 -5
  233. package/dist/lib/spring-settle.cjs +1 -1
  234. package/dist/lib/spring-settle.js +1 -1
  235. package/dist/lib/table-internal.cjs +1 -0
  236. package/dist/lib/table-internal.d.ts +62 -0
  237. package/dist/lib/table-internal.d.ts.map +1 -0
  238. package/dist/lib/table-internal.js +18 -0
  239. package/dist/lib/use-controllable.cjs +1 -0
  240. package/dist/lib/use-controllable.d.ts +12 -0
  241. package/dist/lib/use-controllable.d.ts.map +1 -0
  242. package/dist/lib/use-controllable.js +15 -0
  243. package/dist/lib/use-dev-warning.cjs +1 -1
  244. package/dist/lib/utils.cjs +1 -1
  245. package/dist/lib/utils.d.ts.map +1 -1
  246. package/dist/lib/utils.js +29 -35
  247. package/dist/link.cjs +1 -1
  248. package/dist/link.d.ts +1 -1
  249. package/dist/link.js +78 -124
  250. package/dist/list.cjs +1 -1
  251. package/dist/list.d.ts +8 -0
  252. package/dist/list.d.ts.map +1 -1
  253. package/dist/list.js +94 -156
  254. package/dist/loading.cjs +1 -1
  255. package/dist/loading.js +124 -151
  256. package/dist/logo-mark.cjs +1 -0
  257. package/dist/logo-mark.d.ts +79 -0
  258. package/dist/logo-mark.d.ts.map +1 -0
  259. package/dist/logo-mark.js +219 -0
  260. package/dist/logo.cjs +1 -1
  261. package/dist/logo.d.ts +1 -1
  262. package/dist/logo.d.ts.map +1 -1
  263. package/dist/logo.js +51 -87
  264. package/dist/map.cjs +1 -1
  265. package/dist/map.d.ts.map +1 -1
  266. package/dist/map.js +390 -586
  267. package/dist/media-empty.cjs +1 -1
  268. package/dist/media-empty.js +27 -42
  269. package/dist/media-viewer.cjs +1 -0
  270. package/dist/media-viewer.d.ts +224 -0
  271. package/dist/media-viewer.d.ts.map +1 -0
  272. package/dist/media-viewer.js +295 -0
  273. package/dist/menubar.cjs +1 -1
  274. package/dist/menubar.d.ts +14 -14
  275. package/dist/menubar.d.ts.map +1 -1
  276. package/dist/menubar.js +130 -267
  277. package/dist/multi-select-filter.cjs +1 -0
  278. package/dist/multi-select-filter.d.ts +186 -0
  279. package/dist/multi-select-filter.d.ts.map +1 -0
  280. package/dist/multi-select-filter.js +374 -0
  281. package/dist/navigation-menu.cjs +1 -1
  282. package/dist/navigation-menu.js +108 -172
  283. package/dist/pagination.cjs +1 -1
  284. package/dist/pagination.d.ts +36 -12
  285. package/dist/pagination.d.ts.map +1 -1
  286. package/dist/pagination.js +208 -281
  287. package/dist/popover.cjs +1 -1
  288. package/dist/popover.d.ts +1 -1
  289. package/dist/popover.d.ts.map +1 -1
  290. package/dist/popover.js +34 -45
  291. package/dist/progress.cjs +1 -1
  292. package/dist/progress.d.ts +139 -17
  293. package/dist/progress.d.ts.map +1 -1
  294. package/dist/progress.js +116 -148
  295. package/dist/radio-group.cjs +1 -1
  296. package/dist/radio-group.js +90 -146
  297. package/dist/rating.cjs +1 -1
  298. package/dist/rating.d.ts +80 -13
  299. package/dist/rating.d.ts.map +1 -1
  300. package/dist/rating.js +70 -65
  301. package/dist/relative-date.cjs +1 -0
  302. package/dist/relative-date.d.ts +65 -0
  303. package/dist/relative-date.d.ts.map +1 -0
  304. package/dist/relative-date.js +112 -0
  305. package/dist/resizable.cjs +1 -1
  306. package/dist/resizable.d.ts +39 -23
  307. package/dist/resizable.d.ts.map +1 -1
  308. package/dist/resizable.js +42 -44
  309. package/dist/result-count.cjs +1 -0
  310. package/dist/result-count.d.ts +110 -0
  311. package/dist/result-count.d.ts.map +1 -0
  312. package/dist/result-count.js +49 -0
  313. package/dist/route-progress.cjs +1 -1
  314. package/dist/route-progress.js +58 -102
  315. package/dist/scroll-area.cjs +1 -1
  316. package/dist/scroll-area.d.ts +9 -1
  317. package/dist/scroll-area.d.ts.map +1 -1
  318. package/dist/scroll-area.js +44 -79
  319. package/dist/select.cjs +2 -2
  320. package/dist/select.d.ts +20 -10
  321. package/dist/select.d.ts.map +1 -1
  322. package/dist/select.js +132 -236
  323. package/dist/separator.cjs +1 -1
  324. package/dist/separator.js +90 -78
  325. package/dist/sheet.cjs +1 -1
  326. package/dist/sheet.d.ts +86 -7
  327. package/dist/sheet.d.ts.map +1 -1
  328. package/dist/sheet.js +275 -235
  329. package/dist/single-select-filter.cjs +1 -0
  330. package/dist/single-select-filter.d.ts +113 -0
  331. package/dist/single-select-filter.d.ts.map +1 -0
  332. package/dist/single-select-filter.js +224 -0
  333. package/dist/skeleton.cjs +1 -1
  334. package/dist/skeleton.js +24 -38
  335. package/dist/slider.cjs +1 -1
  336. package/dist/slider.js +51 -81
  337. package/dist/sonner.cjs +1 -1
  338. package/dist/sonner.d.ts +1 -1
  339. package/dist/sonner.d.ts.map +1 -1
  340. package/dist/sonner.js +113 -137
  341. package/dist/spinner.cjs +1 -1
  342. package/dist/spinner.js +22 -31
  343. package/dist/split-layout.cjs +1 -1
  344. package/dist/split-layout.d.ts +1 -1
  345. package/dist/split-layout.js +53 -102
  346. package/dist/status.cjs +1 -0
  347. package/dist/status.d.ts +51 -0
  348. package/dist/status.d.ts.map +1 -0
  349. package/dist/status.js +60 -0
  350. package/dist/stepper.cjs +1 -1
  351. package/dist/stepper.js +184 -316
  352. package/dist/switch.cjs +1 -1
  353. package/dist/switch.js +17 -32
  354. package/dist/table.cjs +1 -1
  355. package/dist/table.d.ts +127 -13
  356. package/dist/table.d.ts.map +1 -1
  357. package/dist/table.js +170 -192
  358. package/dist/tabs.cjs +1 -1
  359. package/dist/tabs.d.ts +12 -1
  360. package/dist/tabs.d.ts.map +1 -1
  361. package/dist/tabs.js +123 -146
  362. package/dist/text-reveal-motion.cjs +1 -1
  363. package/dist/text-reveal-motion.js +307 -363
  364. package/dist/textarea.cjs +1 -1
  365. package/dist/textarea.d.ts.map +1 -1
  366. package/dist/textarea.js +23 -36
  367. package/dist/toggle-group.cjs +1 -1
  368. package/dist/toggle-group.js +43 -62
  369. package/dist/toggle.cjs +1 -1
  370. package/dist/toggle.js +34 -46
  371. package/dist/tooltip.cjs +1 -1
  372. package/dist/tooltip.d.ts +38 -36
  373. package/dist/tooltip.d.ts.map +1 -1
  374. package/dist/tooltip.js +175 -78
  375. package/dist/typography-heading.cjs +1 -1
  376. package/dist/typography-heading.js +25 -61
  377. package/dist/typography-text.cjs +1 -1
  378. package/dist/typography-text.d.ts +1 -2
  379. package/dist/typography-text.d.ts.map +1 -1
  380. package/dist/typography-text.js +27 -57
  381. package/dist/typography.cjs +1 -1
  382. package/dist/typography.d.ts +1 -1
  383. package/dist/typography.js +132 -340
  384. package/package.json +45 -46
  385. package/src/blocks/empty-state.tsx +42 -21
  386. package/src/blocks/progress-state.tsx +2 -2
  387. package/src/blocks/sidebar.tsx +111 -32
  388. package/src/components/accordion.tsx +1 -1
  389. package/src/components/alert-dialog.tsx +52 -5
  390. package/src/components/alert.tsx +16 -8
  391. package/src/components/badge.tsx +152 -3
  392. package/src/components/banner.tsx +288 -0
  393. package/src/components/brand-illustration-motif.tsx +1 -1
  394. package/src/components/breadcrumb.tsx +1 -1
  395. package/src/components/button.tsx +8 -6
  396. package/src/components/calendar.tsx +155 -9
  397. package/src/components/card.tsx +266 -26
  398. package/src/components/carousel.tsx +4 -1
  399. package/src/components/chart.tsx +664 -42
  400. package/src/components/checkbox.tsx +2 -2
  401. package/src/components/collapsible.tsx +4 -1
  402. package/src/components/combobox.tsx +42 -9
  403. package/src/components/command.tsx +10 -11
  404. package/src/components/context-menu.tsx +4 -4
  405. package/src/components/data-table.tsx +1363 -398
  406. package/src/components/date-picker.tsx +31 -4
  407. package/src/components/delta.tsx +217 -0
  408. package/src/components/drawer.tsx +5 -5
  409. package/src/components/dropdown-menu.tsx +4 -4
  410. package/src/components/field.tsx +36 -15
  411. package/src/components/global-layout.tsx +1 -1
  412. package/src/components/grid.tsx +32 -1
  413. package/src/components/info-tooltip.tsx +94 -0
  414. package/src/components/input-chip.tsx +52 -8
  415. package/src/components/input-group.tsx +247 -12
  416. package/src/components/input-otp.tsx +1 -1
  417. package/src/components/input-password.tsx +29 -11
  418. package/src/components/input.tsx +11 -2
  419. package/src/components/list.tsx +15 -3
  420. package/src/components/logo-mark.tsx +345 -0
  421. package/src/components/map.tsx +18 -20
  422. package/src/components/media-viewer.tsx +908 -0
  423. package/src/components/multi-select-filter.tsx +1046 -0
  424. package/src/components/navigation-menu.tsx +2 -2
  425. package/src/components/pagination.tsx +86 -26
  426. package/src/components/progress.tsx +281 -54
  427. package/src/components/rating.tsx +200 -74
  428. package/src/components/relative-date.tsx +238 -0
  429. package/src/components/resizable.tsx +86 -33
  430. package/src/components/result-count.tsx +253 -0
  431. package/src/components/scroll-area.tsx +31 -5
  432. package/src/components/select.tsx +37 -7
  433. package/src/components/sheet.tsx +252 -6
  434. package/src/components/single-select-filter.tsx +538 -0
  435. package/src/components/slider.tsx +2 -2
  436. package/src/components/sonner.tsx +16 -5
  437. package/src/components/split-layout.tsx +2 -2
  438. package/src/components/status.tsx +162 -0
  439. package/src/components/switch.tsx +1 -1
  440. package/src/components/table.tsx +305 -73
  441. package/src/components/tabs.tsx +94 -46
  442. package/src/components/textarea.tsx +21 -3
  443. package/src/components/toggle.tsx +2 -2
  444. package/src/components/tooltip.tsx +431 -68
  445. package/src/components/typography-text.tsx +1 -2
  446. package/src/components/typography.tsx +1 -1
  447. package/src/hooks/use-breakpoint.ts +2 -1
  448. package/src/hooks/use-filter-search-params.ts +302 -0
  449. package/src/index.ts +11 -0
  450. package/src/lib/block-illustration.tsx +5 -1
  451. package/src/lib/compose-event-handlers.ts +14 -0
  452. package/src/lib/download-file.ts +61 -0
  453. package/src/lib/empty-chip.tsx +52 -0
  454. package/src/lib/field-aria.tsx +97 -0
  455. package/src/lib/image-file-info.ts +102 -0
  456. package/src/lib/media-viewer-content.tsx +1587 -0
  457. package/src/lib/media-viewer-internal.tsx +191 -0
  458. package/src/lib/media-viewer-motion.ts +120 -0
  459. package/src/lib/motion.ts +9 -0
  460. package/src/lib/table-internal.ts +74 -0
  461. package/src/lib/use-controllable.ts +43 -0
  462. package/src/lib/utils.ts +1 -0
  463. package/src/lib/empty-chip.ts +0 -24
@@ -0,0 +1,1046 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+
6
+ import { Check, ChevronDown, SearchX } from "@brightlocal/icons";
7
+ import { Button } from "@brightlocal/ui-components/button";
8
+ import {
9
+ Checkbox,
10
+ checkboxVariants,
11
+ } from "@brightlocal/ui-components/checkbox";
12
+ import {
13
+ Command,
14
+ CommandEmpty,
15
+ CommandGroup,
16
+ CommandInput,
17
+ CommandItem,
18
+ CommandList,
19
+ } from "@brightlocal/ui-components/command";
20
+ import {
21
+ Drawer,
22
+ DrawerBody,
23
+ DrawerClose,
24
+ DrawerContent,
25
+ DrawerDescription,
26
+ DrawerFooter,
27
+ DrawerHeader,
28
+ DrawerTitle,
29
+ DrawerTrigger,
30
+ } from "@brightlocal/ui-components/drawer";
31
+ import { useIsBelowBreakpoint } from "@brightlocal/ui-components/hooks/use-breakpoint";
32
+ import {
33
+ InputGroup,
34
+ InputGroupClear,
35
+ InputGroupInput,
36
+ } from "@brightlocal/ui-components/input-group";
37
+ import { Label } from "@brightlocal/ui-components/label";
38
+ import { cn } from "@brightlocal/ui-components/lib/utils";
39
+ import {
40
+ Popover,
41
+ PopoverContent,
42
+ PopoverTrigger,
43
+ } from "@brightlocal/ui-components/popover";
44
+ import { EmptyChip } from "../lib/empty-chip";
45
+
46
+ /* MultiSelectFilter — the Filtering pattern's several-at-once filter
47
+ (Patterns/Filtering → Which filter → Several at once): several values
48
+ from one dimension, combining as OR.
49
+
50
+ Trigger. The trigger hugs its label in a toolbar and wears the field look
51
+ (SelectTrigger's border, radius, focus ring and chevron), because a filter
52
+ trigger holds a value rather than performing an action — which is also why
53
+ it is a native button, not the DS Button. Stacked in a panel, it takes the
54
+ row's width from a `w-full` layout class. The trigger reads its
55
+ picks like a Select shows its value: the All label (or the dimension's
56
+ name, muted, as a placeholder) at zero, then the picked labels in pick
57
+ order, collapsing past `maxVisibleLabels` into `summaryLabel` ("Google
58
+ +2"). The accessible name is computed here with every pick spelled out.
59
+ Glyphs are the consumer's: a pinned `icon`, or the selection's own —
60
+ `allIcon` at zero, then the first pick's `option.icon`; every option's
61
+ glyph sits before its label in the menu and the drawer.
62
+
63
+ Menu. The menu stays open across picks; selected values pin to the top on
64
+ reopen (never mid-pick); a zero-count option is disabled, never hidden,
65
+ and stays enabled while picked so it can be unticked; Clear filters lives
66
+ inside the menu. Past `searchThreshold` options (or with `searchable`) an
67
+ autofocused search input narrows the options by a case-insensitive
68
+ substring match on label and value — never on the count. While a query
69
+ is typed the All row and Clear step aside; a query that matches nothing
70
+ shows the compact empty form (muted chip, `emptyLabel`,
71
+ `emptyDescription`).
72
+
73
+ All. The optional All row is a reset, not a select-all: an empty
74
+ selection narrows nothing (the API's own rule for an omitted filter), so
75
+ the row is checked when nothing is picked and picking it clears. For the
76
+ same reason a pick that completes the set collapses to `[]`
77
+ (`collapseFullSelection`, default on) — every pickable option ticked is
78
+ "All", and must not read "Google +3".
79
+
80
+ Presentations. `presentation="menu"` is the Popover + Command menu;
81
+ `presentation="drawer"` is the phone form — the same trigger opens a
82
+ bottom Drawer titled with the dimension, with the All row, the options as
83
+ Checkboxes in two columns, the search field past the threshold, Clear
84
+ while something is picked, and a Done button that only closes (every tick
85
+ applies at once; an Apply button on a per-filter surface reads as "nothing
86
+ happened"). `presentation="auto"` switches at the `md` breakpoint. Both
87
+ render from one state, so the rules above cannot drift between them.
88
+
89
+ Groups. An option's `group` files it under a heading (Facebook's
90
+ Recommended / Not recommended after the star ratings). Groups keep the
91
+ order their first option has in `options`; options without a group form
92
+ the leading, heading-less group with the All row. Picks pin to the top of
93
+ their own group, search narrows within each group and hides a group with
94
+ no match, and the All row, counts, full-set collapse and the trigger
95
+ reading run across every group exactly as on a flat list (DS-1241).
96
+
97
+ Commit model is per filter: `onValueChange` fires on every pick so client
98
+ data can reflect immediately; defer an expensive refetch to
99
+ `onOpenChange(false)`. */
100
+
101
+ /* ------------------------------------------------------------------------ */
102
+ /* Trigger styles */
103
+ /* ------------------------------------------------------------------------ */
104
+
105
+ /* The field look of SelectTrigger — the same border, radius, focus ring and
106
+ open state, written in the semantic tokens the Figma Select is bound to
107
+ (`background` / `input/30` fill, `input` border, `ring` focus). The
108
+ differences are structural, not decorative: the trigger hugs its label
109
+ where a form field fills its row, there is no `data-[placeholder]` state
110
+ because a trigger always has text to show, and there is no error state
111
+ because a filter does not validate. Exported as the trigger's style
112
+ helper (SingleSelectFilter's drawer trigger wears it too). */
113
+ const multiSelectFilterTriggerVariants = cva(
114
+ [
115
+ // Base layout
116
+ "relative inline-flex cursor-pointer items-center justify-between gap-2 py-2",
117
+
118
+ // Base appearance — the Figma Select's surface: background (input/30 in
119
+ // dark) fill and the input border
120
+ "border border-input rounded-sm outline-none transition-[border-color,box-shadow,background-color] duration-fast ease-out",
121
+ "bg-background dark:bg-input/30",
122
+ "text-foreground",
123
+
124
+ // Focus state (keyboard navigation only — not on click)
125
+ "focus-visible:outline-none focus-visible:border-ring focus-visible:bg-background",
126
+ "focus-visible:shadow-default",
127
+
128
+ // Open state — the surface this trigger owns is showing
129
+ "data-[state=open]:border-ring",
130
+
131
+ // Disabled state
132
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
133
+
134
+ // Icon styles (chevron and leading icons)
135
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
136
+ ],
137
+ {
138
+ variants: {
139
+ size: {
140
+ /* A filter trigger is a field-like control holding a value, so it
141
+ wears the field's type role, exactly like SelectTrigger (DS-992):
142
+ 14px/20 on desktop, 16px/24 on touch devices so it never differs
143
+ from the Select beside it in a toolbar. */
144
+ default: "h-9 px-3 text-field",
145
+ /* The DS Button's `sm` height (h-8) with text-label (14px everywhere),
146
+ so the same trigger sits in a phone card header without the desktop
147
+ height or the touch bump crowding the row. Icons stay 16px unless
148
+ the consumer's glyph sizes itself. */
149
+ sm: "h-8 px-2.5 text-label [&_svg:not([class*='size-'])]:size-4",
150
+ },
151
+ },
152
+ defaultVariants: {
153
+ size: "default",
154
+ },
155
+ }
156
+ );
157
+
158
+ /* ------------------------------------------------------------------------ */
159
+ /* Types */
160
+ /* ------------------------------------------------------------------------ */
161
+
162
+ /** One selectable option of a multi-select filter. */
163
+ interface MultiSelectFilterOption {
164
+ /** Unique value of the option. */
165
+ value: string;
166
+ /** Visible label of the option. */
167
+ label: string;
168
+ /**
169
+ * Result count for this option, shown beside the label in the menu (the
170
+ * drawer's two-column rows carry only the All total). A count of 0
171
+ * disables the option in both — disabled, never hidden, so the dimension
172
+ * keeps its full shape.
173
+ */
174
+ count?: number;
175
+ /** Disables the option explicitly. */
176
+ disabled?: boolean;
177
+ /**
178
+ * The option's own glyph (a search-engine logo, a rating star), 16px.
179
+ * Shown before the label in the menu and the drawer; the trigger shows the
180
+ * first pick's glyph when no `icon` is set.
181
+ */
182
+ icon?: React.ReactNode;
183
+ /**
184
+ * Heading this option is listed under, e.g. "Facebook". Options sharing a
185
+ * `group` render together under it, in the order the group first appears
186
+ * in `options`; options without one lead the list with no heading. Only
187
+ * the menu and the drawer show it — the trigger, counts, the All row and
188
+ * the full-set collapse treat every option alike.
189
+ */
190
+ group?: string;
191
+ }
192
+
193
+ interface MultiSelectFilterProps
194
+ extends
195
+ Omit<
196
+ React.ComponentPropsWithoutRef<"button">,
197
+ "value" | "defaultValue" | "onChange" | "children"
198
+ >,
199
+ VariantProps<typeof multiSelectFilterTriggerVariants> {
200
+ /**
201
+ * Data hook for automated testing (REQUIRED). Every part of the menu
202
+ * derives its own hook from it (`-popover`, `-search`, `-option-all`,
203
+ * `-option-<value>`, `-group-<heading>`, `-clear`, `-summary`, `-icon`).
204
+ * @example "locations-status-filter"
205
+ */
206
+ dataHook: string;
207
+ /**
208
+ * The dimension's name — use the product's words ("Status", "Source"),
209
+ * never an internal field name. Always the start of the accessible name;
210
+ * also the trigger's muted placeholder at zero when there is no `allLabel`.
211
+ */
212
+ label: string;
213
+ /** The selectable options, in the dimension's own order. */
214
+ options: readonly MultiSelectFilterOption[];
215
+ /** Controlled selected values. Values combine as OR. */
216
+ value?: readonly string[];
217
+ /**
218
+ * Initial selection for uncontrolled mode.
219
+ * @default []
220
+ */
221
+ defaultValue?: readonly string[];
222
+ /**
223
+ * Callback on every pick (the per-filter commit model: reflect
224
+ * immediately on client data; defer expensive refetches to
225
+ * `onOpenChange(false)`).
226
+ * @param value - The full selection after the pick
227
+ */
228
+ onValueChange?: (value: string[]) => void;
229
+ /** Controlled open state of the menu. */
230
+ open?: boolean;
231
+ /**
232
+ * Callback when the menu opens or closes — `false` is the moment to run
233
+ * an expensive refetch for everything picked while it was open.
234
+ */
235
+ onOpenChange?: (open: boolean) => void;
236
+ /**
237
+ * Fixed glyph leading the trigger — the dimension's own icon (a funnel, a
238
+ * calendar), 16px. Without it the trigger follows the selection: `allIcon`
239
+ * at zero, then the first pick's `option.icon`. Hidden from assistive
240
+ * tech; the accessible name comes from `label` and the picks.
241
+ */
242
+ icon?: React.ReactNode;
243
+ /**
244
+ * How many picked labels to spell out before collapsing into
245
+ * `summaryLabel` ("Google +2" at 1, "London, Brighton +1" at 2). Values
246
+ * below 1 are treated as 1.
247
+ * @default 1
248
+ */
249
+ maxVisibleLabels?: number;
250
+ /**
251
+ * Label of the leading reset row, e.g. "All sources". Omit to hide the
252
+ * row. Checked when nothing is picked; picking it clears the selection.
253
+ * Also the trigger's text at zero.
254
+ */
255
+ allLabel?: string;
256
+ /**
257
+ * Glyph of the All row, and of the trigger while nothing is picked (when
258
+ * no `icon` is set) — the dimension's "everything" mark, e.g. a globe.
259
+ */
260
+ allIcon?: React.ReactNode;
261
+ /**
262
+ * Total beside the All row. Defaults to the sum of the options' counts
263
+ * when every option has one — per-option counts leave out their own
264
+ * filter, so together they are the unfiltered total.
265
+ */
266
+ allCount?: number;
267
+ /**
268
+ * Show a search input inside the menu once the option list grows past
269
+ * this many options. Scanning stops working past ~10–15.
270
+ * @default 10
271
+ */
272
+ searchThreshold?: number;
273
+ /** Force the search input on or off, overriding `searchThreshold`. */
274
+ searchable?: boolean;
275
+ /**
276
+ * When a pick completes the set — every option that can be picked (not
277
+ * disabled, count not 0) is ticked — the selection collapses to `[]`,
278
+ * i.e. "All": the same records, read as no filter instead of "Google +3".
279
+ * @default true
280
+ */
281
+ collapseFullSelection?: boolean;
282
+ /** Disables the trigger. */
283
+ disabled?: boolean;
284
+ /**
285
+ * Label of the clear action inside the menu.
286
+ * @default "Clear filters"
287
+ */
288
+ clearLabel?: string;
289
+ /**
290
+ * Trigger summary once more values are picked than `maxVisibleLabels`.
291
+ * Placeholders: `{labels}` — the first `maxVisibleLabels` labels,
292
+ * `{rest}` — the picks beyond them, `{count}` — every pick.
293
+ * `"{count} selected"` reads "3 selected" instead.
294
+ * @default "{labels} +{rest}"
295
+ */
296
+ summaryLabel?: string;
297
+ /**
298
+ * Placeholder of the search input inside the menu.
299
+ * @default "Search options..."
300
+ */
301
+ searchPlaceholder?: string;
302
+ /**
303
+ * Message when the search matches no options.
304
+ * @default "No options found."
305
+ */
306
+ emptyLabel?: string;
307
+ /**
308
+ * The quiet hint under the no-match message.
309
+ * @default "Try another search."
310
+ */
311
+ emptyDescription?: string;
312
+ /**
313
+ * Accessible label of the menu search input's clear button (the drawer's
314
+ * search field is a plain Input without one).
315
+ * @default "Clear search"
316
+ */
317
+ clearSearchAriaLabel?: string;
318
+ /**
319
+ * How the options open: the Popover + Command `menu`, a bottom `drawer`
320
+ * (the phone form: Checkbox rows in two columns, Clear, Done), or `auto`
321
+ * — the menu from the `md` breakpoint up and the drawer below it.
322
+ * @default "menu"
323
+ */
324
+ presentation?: "menu" | "drawer" | "auto";
325
+ /**
326
+ * Label of the drawer's Done button — it only closes; picks apply at once.
327
+ * @default "Done"
328
+ */
329
+ doneLabel?: string;
330
+ /**
331
+ * Screen-reader description of the drawer (the Drawer contract needs a
332
+ * title and a description; the title is `label`).
333
+ * @default "Picks apply as you make them."
334
+ */
335
+ drawerDescription?: string;
336
+ /** Analytics element identifier. @default "multi-select-filter" */
337
+ trackingEl?: string;
338
+ /** Analytics label */
339
+ trackingLabel?: string;
340
+ }
341
+
342
+ /* ------------------------------------------------------------------------ */
343
+ /* Engine */
344
+ /* ------------------------------------------------------------------------ */
345
+
346
+ interface UseMultiSelectFilterStateOptions {
347
+ value?: readonly string[];
348
+ defaultValue: readonly string[];
349
+ onValueChange?: (value: string[]) => void;
350
+ open?: boolean;
351
+ onOpenChange?: (open: boolean) => void;
352
+ options: readonly MultiSelectFilterOption[];
353
+ collapseFullSelection: boolean;
354
+ }
355
+
356
+ /* The shared multi-select state: value, open state, pinned order and the
357
+ toggle-accumulate handler. Private — the component is the only consumer. */
358
+ function useMultiSelectFilterState({
359
+ value: controlledValue,
360
+ defaultValue,
361
+ onValueChange,
362
+ open: controlledOpen,
363
+ onOpenChange,
364
+ options,
365
+ collapseFullSelection,
366
+ }: UseMultiSelectFilterStateOptions) {
367
+ const [uncontrolledValue, setUncontrolledValue] =
368
+ React.useState<readonly string[]>(defaultValue);
369
+ const isControlled = controlledValue !== undefined;
370
+ const value = isControlled ? controlledValue : uncontrolledValue;
371
+ const selectedSet = React.useMemo(() => new Set(value), [value]);
372
+
373
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
374
+ const isOpenControlled = controlledOpen !== undefined;
375
+ const open = isOpenControlled ? controlledOpen : uncontrolledOpen;
376
+
377
+ /* Pinned order snapshots when the menu opens — selected values pin to the
378
+ top on reopen, never mid-pick, so the list doesn't reshuffle under the
379
+ pointer. Keyed on `open` itself (not the handler) so a parent flipping a
380
+ controlled `open` pins too; the value is read through a ref so a pick
381
+ while open never re-snapshots. */
382
+ const [pinned, setPinned] = React.useState<Set<string>>(new Set());
383
+ const wasOpen = React.useRef(open);
384
+ React.useEffect(() => {
385
+ if (open && !wasOpen.current) setPinned(new Set(value));
386
+ wasOpen.current = open;
387
+ }, [open, value]);
388
+
389
+ const setValue = (next: string[]) => {
390
+ if (!isControlled) setUncontrolledValue(next);
391
+ onValueChange?.(next);
392
+ };
393
+
394
+ const toggleOption = (optionValue: string) => {
395
+ if (selectedSet.has(optionValue)) {
396
+ setValue(value.filter((item) => item !== optionValue));
397
+ return;
398
+ }
399
+ const next = [...value, optionValue];
400
+ if (collapseFullSelection) {
401
+ /* Every pickable option ticked means "All" — the empty selection. */
402
+ const pickable = options.filter(
403
+ (option) => !option.disabled && option.count !== 0
404
+ );
405
+ const nextSet = new Set(next);
406
+ if (
407
+ pickable.length > 0 &&
408
+ pickable.every((option) => nextSet.has(option.value))
409
+ ) {
410
+ setValue([]);
411
+ return;
412
+ }
413
+ }
414
+ setValue(next);
415
+ };
416
+
417
+ const handleOpenChange = (next: boolean) => {
418
+ if (!isOpenControlled) setUncontrolledOpen(next);
419
+ onOpenChange?.(next);
420
+ };
421
+
422
+ const orderedOptions = React.useMemo(
423
+ () => [
424
+ ...options.filter((option) => pinned.has(option.value)),
425
+ ...options.filter((option) => !pinned.has(option.value)),
426
+ ],
427
+ [options, pinned]
428
+ );
429
+
430
+ return {
431
+ clear: () => setValue([]),
432
+ onOpenChange: handleOpenChange,
433
+ open,
434
+ orderedOptions,
435
+ selectedSet,
436
+ toggleOption,
437
+ value,
438
+ };
439
+ }
440
+
441
+ /* ------------------------------------------------------------------------ */
442
+ /* Pieces */
443
+ /* ------------------------------------------------------------------------ */
444
+
445
+ /* The option's check mark wears the DS Checkbox look without being a
446
+ Checkbox: the CommandItem owns the click and carries aria-checked, so a
447
+ nested button would be a second control inside an option. `data-state`
448
+ drives checkboxVariants' checked treatment exactly as Radix does. */
449
+ function OptionCheck({ checked }: { checked: boolean }) {
450
+ return (
451
+ <span
452
+ aria-hidden="true"
453
+ className={cn(
454
+ checkboxVariants(),
455
+ "mt-0 flex items-center justify-center self-center"
456
+ )}
457
+ data-state={checked ? "checked" : "unchecked"}
458
+ >
459
+ {checked ? <Check /> : null}
460
+ </span>
461
+ );
462
+ }
463
+
464
+ function OptionCount({ count }: { count: number }) {
465
+ return (
466
+ <span className="text-muted-foreground text-label-sm ml-auto tabular-nums">
467
+ {count}
468
+ </span>
469
+ );
470
+ }
471
+
472
+ /* One heading's worth of options. `group` undefined is the leading,
473
+ heading-less run. */
474
+ interface OptionSection {
475
+ group?: string;
476
+ options: MultiSelectFilterOption[];
477
+ }
478
+
479
+ /* Split the shown options into their groups: the heading-less run first,
480
+ then named groups in the order of their first option in `options` (not
481
+ the shown list), so pinning a pick
482
+ never moves its whole group up; within a group the shown order (picks
483
+ pinned first) is kept. Empty groups (all filtered out) are dropped. */
484
+ function groupOptions(
485
+ options: readonly MultiSelectFilterOption[],
486
+ shown: readonly MultiSelectFilterOption[]
487
+ ): OptionSection[] {
488
+ /* Ungrouped options always lead, wherever they sit in `options`; the
489
+ empty-section filter drops that run when every option has a group. */
490
+ const order: (string | undefined)[] = [undefined];
491
+ for (const option of options) {
492
+ if (!order.includes(option.group)) order.push(option.group);
493
+ }
494
+ return order
495
+ .map((group) => ({
496
+ group,
497
+ options: shown.filter((option) => option.group === group),
498
+ }))
499
+ .filter((section) => section.options.length > 0);
500
+ }
501
+
502
+ /* `<dataHook>-group-<heading>`, the heading lower-cased with spaces as
503
+ dashes ("Not recommended" → "-group-not-recommended"). */
504
+ function groupHook(dataHook: string, group: string): string {
505
+ return `${dataHook}-group-${group.trim().toLowerCase().replace(/\s+/g, "-")}`;
506
+ }
507
+
508
+ /* cmdk values for the two rows that are not options — unique, so an option
509
+ labelled "All" or "Clear" never shares a value with them. */
510
+ const ALL_ROW_VALUE = "__all__";
511
+ const CLEAR_ROW_VALUE = "__clear__";
512
+
513
+ /* ------------------------------------------------------------------------ */
514
+ /* Component */
515
+ /* ------------------------------------------------------------------------ */
516
+
517
+ /**
518
+ * Multi-select filter for one dimension: a field-look trigger that reads its
519
+ * picks, over a Popover + Command menu that stays open across picks. Values
520
+ * combine as OR.
521
+ */
522
+ const MultiSelectFilter = React.forwardRef<
523
+ HTMLButtonElement,
524
+ MultiSelectFilterProps
525
+ >(
526
+ (
527
+ {
528
+ className,
529
+ dataHook,
530
+ label,
531
+ options,
532
+ value: controlledValue,
533
+ defaultValue = [],
534
+ onValueChange,
535
+ open: controlledOpen,
536
+ onOpenChange,
537
+ size = "default",
538
+ icon,
539
+ maxVisibleLabels = 1,
540
+ allLabel,
541
+ allIcon,
542
+ allCount,
543
+ searchThreshold = 10,
544
+ searchable,
545
+ collapseFullSelection = true,
546
+ disabled = false,
547
+ clearLabel,
548
+ summaryLabel,
549
+ searchPlaceholder,
550
+ emptyLabel,
551
+ emptyDescription,
552
+ clearSearchAriaLabel,
553
+ presentation = "menu",
554
+ doneLabel,
555
+ drawerDescription,
556
+ trackingEl,
557
+ trackingLabel,
558
+ "aria-label": ariaLabelProp,
559
+ "aria-describedby": describedByProp,
560
+ ...props
561
+ },
562
+ ref
563
+ ) => {
564
+ const state = useMultiSelectFilterState({
565
+ collapseFullSelection,
566
+ defaultValue,
567
+ onOpenChange,
568
+ onValueChange,
569
+ open: controlledOpen,
570
+ options,
571
+ value: controlledValue,
572
+ });
573
+
574
+ const belowMd = useIsBelowBreakpoint("md");
575
+ const useDrawer =
576
+ presentation === "drawer" || (presentation === "auto" && belowMd);
577
+ const idPrefix = React.useId();
578
+
579
+ /* The search query, so the All row and Clear can step aside while the
580
+ person types. It resets with every open. */
581
+ const [query, setQuery] = React.useState("");
582
+ const normalizedQuery = query.trim().toLowerCase();
583
+ const commandRef = React.useRef<HTMLDivElement>(null);
584
+ const showSearch = searchable ?? options.length > searchThreshold;
585
+ const searching = showSearch && normalizedQuery.length > 0;
586
+ /* Case-insensitive substring match on label and value — predictable for
587
+ a list of names, unlike a fuzzy score. */
588
+ const visibleOptions = searching
589
+ ? state.orderedOptions.filter(
590
+ (option) =>
591
+ option.label.toLowerCase().includes(normalizedQuery) ||
592
+ option.value.toLowerCase().includes(normalizedQuery)
593
+ )
594
+ : state.orderedOptions;
595
+ const sections = groupOptions(options, visibleOptions);
596
+
597
+ /* The trigger's own record of the selection, in pick order — the first
598
+ label stays put while more are added. A value with no option (stale
599
+ after the options changed) is not a pick — it neither reads on the
600
+ trigger nor counts. */
601
+ const labelByValue = new Map(
602
+ options.map((option) => [option.value, option.label])
603
+ );
604
+ const pickedLabels = state.value.flatMap((picked) => {
605
+ const pickedLabel = labelByValue.get(picked);
606
+ return pickedLabel === undefined ? [] : [pickedLabel];
607
+ });
608
+ const count = pickedLabels.length;
609
+ /* "All" means no narrowing, which is an empty selection — so the row is
610
+ checked when nothing is picked, not when everything is. */
611
+ const allSelected = state.value.length === 0;
612
+ const resolvedAllCount =
613
+ allCount ??
614
+ (options.length > 0 &&
615
+ options.every((option) => option.count !== undefined)
616
+ ? options.reduce((sum, option) => sum + (option.count ?? 0), 0)
617
+ : undefined);
618
+ const visibleLabels = Math.max(1, maxVisibleLabels);
619
+
620
+ let triggerText: string;
621
+ let mutedText = false;
622
+ if (count === 0) {
623
+ triggerText = allLabel ?? label;
624
+ /* Without an All label the dimension name stands in as a placeholder —
625
+ muted, like a Select with nothing chosen. With one, "All sources" is
626
+ a real state and reads at full strength. */
627
+ mutedText = allLabel === undefined;
628
+ } else if (count <= visibleLabels) {
629
+ triggerText = pickedLabels.join(", ");
630
+ } else {
631
+ /* One pass with a function replacer: a label containing "$&" or a
632
+ placeholder is inserted verbatim, never re-expanded. */
633
+ const fills: Record<string, string> = {
634
+ "{count}": String(count),
635
+ "{labels}": pickedLabels.slice(0, visibleLabels).join(", "),
636
+ "{rest}": String(count - visibleLabels),
637
+ };
638
+ triggerText = (summaryLabel ?? "{labels} +{rest}").replace(
639
+ /\{(count|labels|rest)\}/g,
640
+ (token) => fills[token] ?? token
641
+ );
642
+ }
643
+
644
+ /* The accessible name starts with the dimension and then reads the text
645
+ the trigger shows (WCAG 2.5.3 Label in Name). The summary may hide
646
+ picks ("Google +2"), so when it does every pick is spelled out in the
647
+ description instead of the name. */
648
+ const computedAriaLabel =
649
+ count > 0
650
+ ? `${label}: ${triggerText}`
651
+ : allLabel !== undefined
652
+ ? `${label}: ${allLabel}`
653
+ : label;
654
+ const picksDescription =
655
+ count > visibleLabels ? pickedLabels.join(", ") : undefined;
656
+ const picksId = `${idPrefix}-picks`;
657
+ /* The consumer's description ids ride along with the picks, never replace
658
+ them. */
659
+ const describedBy =
660
+ [describedByProp, picksDescription ? picksId : undefined]
661
+ .filter(Boolean)
662
+ .join(" ") || undefined;
663
+
664
+ /* The glyph follows the selection unless the consumer pins one: the All
665
+ mark at zero, then the first pick's own. */
666
+ const firstPicked = state.value
667
+ .map((picked) => options.find((option) => option.value === picked))
668
+ .find((option) => option !== undefined);
669
+ const resolvedIcon =
670
+ icon ?? (count > 0 ? firstPicked?.icon : allIcon) ?? undefined;
671
+
672
+ const handleOpenChange = (next: boolean) => {
673
+ if (next) setQuery("");
674
+ state.onOpenChange(next);
675
+ };
676
+
677
+ const triggerNode = (
678
+ <button
679
+ ref={ref}
680
+ aria-describedby={describedBy}
681
+ aria-label={ariaLabelProp ?? computedAriaLabel}
682
+ className={cn(multiSelectFilterTriggerVariants({ size }), className)}
683
+ data-hook={dataHook}
684
+ data-slot="multi-select-filter"
685
+ data-tracking-el={trackingEl ?? "multi-select-filter"}
686
+ data-tracking-label={trackingLabel}
687
+ disabled={disabled}
688
+ type="button"
689
+ {...props}
690
+ >
691
+ {resolvedIcon ? (
692
+ <span
693
+ aria-hidden="true"
694
+ className="flex shrink-0 items-center"
695
+ data-hook={`${dataHook}-icon`}
696
+ >
697
+ {resolvedIcon}
698
+ </span>
699
+ ) : null}
700
+ <span
701
+ className={cn(mutedText && "text-muted-foreground")}
702
+ data-hook={`${dataHook}-summary`}
703
+ >
704
+ {triggerText}
705
+ </span>
706
+ {picksDescription ? (
707
+ <span hidden id={picksId}>
708
+ {picksDescription}
709
+ </span>
710
+ ) : null}
711
+ {/* The affordance the field look promises: a menu opens here. */}
712
+ <ChevronDown aria-hidden="true" className="text-muted-foreground" />
713
+ </button>
714
+ );
715
+
716
+ if (useDrawer) {
717
+ const allId = `${idPrefix}-all`;
718
+ return (
719
+ <Drawer open={state.open} onOpenChange={handleOpenChange}>
720
+ <DrawerTrigger asChild>{triggerNode}</DrawerTrigger>
721
+ <DrawerContent dataHook={`${dataHook}-drawer`}>
722
+ <DrawerHeader>
723
+ <DrawerTitle>{label}</DrawerTitle>
724
+ <DrawerDescription className="sr-only">
725
+ {drawerDescription ?? "Picks apply as you make them."}
726
+ </DrawerDescription>
727
+ </DrawerHeader>
728
+ {/* The search field sits outside the scroll area: an overflow
729
+ container clips the input's 3px focus ring, and the field
730
+ stays in reach while the list scrolls. */}
731
+ {showSearch ? (
732
+ <DrawerBody className="shrink-0 pb-4">
733
+ <InputGroup dataHook={`${dataHook}-search`}>
734
+ <InputGroupInput
735
+ aria-label={searchPlaceholder ?? "Search options..."}
736
+ placeholder={searchPlaceholder ?? "Search options..."}
737
+ value={query}
738
+ onChange={(event) => setQuery(event.target.value)}
739
+ />
740
+ <InputGroupClear
741
+ clearSearchAriaLabel={clearSearchAriaLabel}
742
+ dataHook={`${dataHook}-search-clear`}
743
+ />
744
+ </InputGroup>
745
+ </DrawerBody>
746
+ ) : null}
747
+ {/* min-h-0 + overflow: the list scrolls inside the drawer's
748
+ height cap; pt-1 keeps the first row's focus ring inside the
749
+ clip. The All row and Clear scroll with the list. */}
750
+ <DrawerBody className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pt-1 pb-2">
751
+ {searching && visibleOptions.length === 0 ? (
752
+ /* The compact no-match form of Patterns → Empty States: the
753
+ muted chip, the message line, one quiet hint — the same
754
+ form CommandEmpty draws in the menu. */
755
+ <div
756
+ className="text-body-sm flex flex-col items-center gap-1 py-6 text-center"
757
+ data-hook={`${dataHook}-empty`}
758
+ >
759
+ <EmptyChip
760
+ className="mb-1"
761
+ dataHook={`${dataHook}-empty-icon`}
762
+ icon={<SearchX />}
763
+ slot="multi-select-filter-empty-icon"
764
+ />
765
+ <p>{emptyLabel ?? "No options found."}</p>
766
+ <p className="text-muted-foreground">
767
+ {emptyDescription ?? "Try another search."}
768
+ </p>
769
+ </div>
770
+ ) : (
771
+ <>
772
+ {allLabel !== undefined && !searching ? (
773
+ <div className="flex items-center gap-2">
774
+ <Checkbox
775
+ checked={allSelected}
776
+ dataHook={`${dataHook}-option-all`}
777
+ id={allId}
778
+ onCheckedChange={state.clear}
779
+ />
780
+ <Label className="flex-1 gap-2" htmlFor={allId}>
781
+ {allIcon ? (
782
+ <span
783
+ aria-hidden="true"
784
+ className="flex shrink-0 items-center [&_svg]:size-4"
785
+ >
786
+ {allIcon}
787
+ </span>
788
+ ) : null}
789
+ {allLabel}
790
+ </Label>
791
+ {resolvedAllCount !== undefined ? (
792
+ <OptionCount count={resolvedAllCount} />
793
+ ) : null}
794
+ </div>
795
+ ) : null}
796
+ {sections.map((section, sectionIndex) => {
797
+ const grid = (
798
+ <div className="grid grid-cols-2 gap-x-4 gap-y-3">
799
+ {section.options.map((option) => {
800
+ const index = visibleOptions.indexOf(option);
801
+ const active = state.selectedSet.has(option.value);
802
+ const optionDisabled =
803
+ option.disabled || (option.count === 0 && !active);
804
+ /* Keyed on the index, not the value — an id may not
805
+ contain whitespace, and a value may. */
806
+ const optionId = `${idPrefix}-${index}`;
807
+ return (
808
+ <div
809
+ key={option.value}
810
+ className="flex items-center gap-2"
811
+ >
812
+ <Checkbox
813
+ checked={active}
814
+ dataHook={`${dataHook}-option-${option.value}`}
815
+ disabled={optionDisabled}
816
+ id={optionId}
817
+ onCheckedChange={() =>
818
+ state.toggleOption(option.value)
819
+ }
820
+ />
821
+ <Label
822
+ className="flex-1 gap-2"
823
+ htmlFor={optionId}
824
+ >
825
+ {option.icon ? (
826
+ <span
827
+ aria-hidden="true"
828
+ className="flex shrink-0 items-center [&_svg]:size-4"
829
+ data-hook={`${dataHook}-option-${option.value}-icon`}
830
+ >
831
+ {option.icon}
832
+ </span>
833
+ ) : null}
834
+ {option.label}
835
+ </Label>
836
+ </div>
837
+ );
838
+ })}
839
+ </div>
840
+ );
841
+ if (!section.group) {
842
+ return (
843
+ <React.Fragment key="__ungrouped__">
844
+ {grid}
845
+ </React.Fragment>
846
+ );
847
+ }
848
+ const headingId = `${idPrefix}-group-${sectionIndex}`;
849
+ return (
850
+ <div
851
+ key={section.group}
852
+ aria-labelledby={headingId}
853
+ className="flex flex-col gap-3"
854
+ data-hook={groupHook(dataHook, section.group)}
855
+ role="group"
856
+ >
857
+ <p
858
+ className="text-muted-foreground text-label-sm"
859
+ id={headingId}
860
+ >
861
+ {section.group}
862
+ </p>
863
+ {grid}
864
+ </div>
865
+ );
866
+ })}
867
+ </>
868
+ )}
869
+ {state.value.length > 0 && !searching ? (
870
+ <Button
871
+ dataHook={`${dataHook}-clear`}
872
+ variant="ghost"
873
+ onClick={state.clear}
874
+ >
875
+ {clearLabel ?? "Clear filters"}
876
+ </Button>
877
+ ) : null}
878
+ </DrawerBody>
879
+ <DrawerFooter>
880
+ <DrawerClose asChild>
881
+ <Button dataHook={`${dataHook}-done`}>
882
+ {doneLabel ?? "Done"}
883
+ </Button>
884
+ </DrawerClose>
885
+ </DrawerFooter>
886
+ </DrawerContent>
887
+ </Drawer>
888
+ );
889
+ }
890
+
891
+ const showAllRow = allLabel !== undefined && !searching;
892
+ /* The All row rides in the leading heading-less group; when every option
893
+ has a group (or there are none) it gets a group of its own. */
894
+ const allInLead =
895
+ showAllRow && sections[0]?.group === undefined && sections.length > 0;
896
+ const allRow = showAllRow ? (
897
+ <CommandItem
898
+ aria-checked={allSelected}
899
+ dataHook={`${dataHook}-option-all`}
900
+ value={ALL_ROW_VALUE}
901
+ onSelect={state.clear}
902
+ >
903
+ <OptionCheck checked={allSelected} />
904
+ {allIcon ? (
905
+ <span
906
+ aria-hidden="true"
907
+ className="flex shrink-0 items-center [&_svg]:size-4"
908
+ >
909
+ {allIcon}
910
+ </span>
911
+ ) : null}
912
+ {allLabel}
913
+ {resolvedAllCount !== undefined ? (
914
+ <OptionCount count={resolvedAllCount} />
915
+ ) : null}
916
+ </CommandItem>
917
+ ) : null;
918
+
919
+ return (
920
+ <Popover open={state.open} onOpenChange={handleOpenChange}>
921
+ <PopoverTrigger asChild>{triggerNode}</PopoverTrigger>
922
+ {/* p-0: the Command surface owns the popover's inner spacing. The
923
+ menu hugs its widest option between a floor and a ceiling rather
924
+ than following the trigger, whose width is only its text. */}
925
+ <PopoverContent
926
+ align="start"
927
+ aria-label={label}
928
+ className="w-max max-w-80 min-w-60 p-0"
929
+ dataHook={`${dataHook}-popover`}
930
+ /* cmdk listens for the arrow keys on its root, so without a search
931
+ input to take focus the root itself must — otherwise the menu
932
+ opens but the keyboard goes nowhere. */
933
+ onOpenAutoFocus={(event) => {
934
+ if (showSearch) return;
935
+ event.preventDefault();
936
+ commandRef.current?.focus();
937
+ }}
938
+ >
939
+ {/* shouldFilter off: the list is narrowed above, so cmdk only
940
+ provides the roving highlight and the keyboard. */}
941
+ <Command
942
+ ref={commandRef}
943
+ className="border-0 shadow-none"
944
+ dataHook={`${dataHook}-command`}
945
+ shouldFilter={false}
946
+ >
947
+ {showSearch ? (
948
+ /* Autofocused on open — the person came to type, not scroll;
949
+ focus moves into a menu they deliberately opened. */
950
+ <CommandInput
951
+ // eslint-disable-next-line jsx-a11y/no-autofocus
952
+ autoFocus
953
+ clearSearchAriaLabel={clearSearchAriaLabel ?? "Clear search"}
954
+ dataHook={`${dataHook}-search`}
955
+ placeholder={searchPlaceholder ?? "Search options..."}
956
+ onValueChange={setQuery}
957
+ />
958
+ ) : null}
959
+ {/* aria-multiselectable + per-option aria-checked: cmdk's
960
+ aria-selected tracks the highlight, so checkedness needs its
961
+ own attribute for assistive tech. */}
962
+ <CommandList aria-multiselectable="true">
963
+ <CommandEmpty
964
+ description={emptyDescription ?? "Try another search."}
965
+ icon={<SearchX />}
966
+ >
967
+ {emptyLabel ?? "No options found."}
968
+ </CommandEmpty>
969
+ {/* The All row shares the leading group with the heading-less
970
+ options; every named group follows under its heading. */}
971
+ {showAllRow && !allInLead ? (
972
+ <CommandGroup>{allRow}</CommandGroup>
973
+ ) : null}
974
+ {sections.map((section, sectionIndex) => (
975
+ <CommandGroup
976
+ key={section.group ?? "__ungrouped__"}
977
+ dataHook={
978
+ section.group
979
+ ? groupHook(dataHook, section.group)
980
+ : undefined
981
+ }
982
+ heading={section.group}
983
+ >
984
+ {sectionIndex === 0 && allInLead ? allRow : null}
985
+ {section.options.map((option) => {
986
+ const active = state.selectedSet.has(option.value);
987
+ /* A zero-count option disables, never hides — the dimension
988
+ keeps its full shape on screen. A pick whose count dropped
989
+ to zero under another filter stays enabled, so it can
990
+ still be unticked. */
991
+ const optionDisabled =
992
+ option.disabled || (option.count === 0 && !active);
993
+ return (
994
+ <CommandItem
995
+ key={option.value}
996
+ aria-checked={active}
997
+ dataHook={`${dataHook}-option-${option.value}`}
998
+ disabled={optionDisabled}
999
+ value={option.value}
1000
+ onSelect={() => state.toggleOption(option.value)}
1001
+ >
1002
+ <OptionCheck checked={active} />
1003
+ {option.icon ? (
1004
+ <span
1005
+ aria-hidden="true"
1006
+ className="flex shrink-0 items-center [&_svg]:size-4"
1007
+ data-hook={`${dataHook}-option-${option.value}-icon`}
1008
+ >
1009
+ {option.icon}
1010
+ </span>
1011
+ ) : null}
1012
+ {option.label}
1013
+ {option.count !== undefined ? (
1014
+ <OptionCount count={option.count} />
1015
+ ) : null}
1016
+ </CommandItem>
1017
+ );
1018
+ })}
1019
+ </CommandGroup>
1020
+ ))}
1021
+ {state.value.length > 0 && !searching ? (
1022
+ /* A bordered group, not CommandSeparator — role="separator"
1023
+ is not a permitted child of the cmdk listbox. */
1024
+ <CommandGroup className="border-border border-t">
1025
+ <CommandItem
1026
+ className="justify-center"
1027
+ dataHook={`${dataHook}-clear`}
1028
+ value={CLEAR_ROW_VALUE}
1029
+ onSelect={state.clear}
1030
+ >
1031
+ {clearLabel ?? "Clear filters"}
1032
+ </CommandItem>
1033
+ </CommandGroup>
1034
+ ) : null}
1035
+ </CommandList>
1036
+ </Command>
1037
+ </PopoverContent>
1038
+ </Popover>
1039
+ );
1040
+ }
1041
+ );
1042
+
1043
+ MultiSelectFilter.displayName = "MultiSelectFilter";
1044
+
1045
+ export { MultiSelectFilter, multiSelectFilterTriggerVariants };
1046
+ export type { MultiSelectFilterOption, MultiSelectFilterProps };