@justanarthur/modo-ui 0.6.0-canary.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (619) hide show
  1. package/README.md +197 -643
  2. package/blocks/sidebar-app/examples.mdx +2 -2
  3. package/blocks/sidebar-app/index.tsx +20 -7
  4. package/blocks/sidebar-app/inset-topbar.tsx +3 -8
  5. package/blocks/sidebar-app/menu-grid.ts +8 -18
  6. package/blocks/sidebar-app/nav-data.ts +1 -1
  7. package/blocks/sidebar-app/search-field.tsx +8 -15
  8. package/blocks/sidebar-app/thread-page.tsx +58 -0
  9. package/blocks/sidebar-app/user-footer.tsx +8 -15
  10. package/blocks/sidebar-app/workspace-header.tsx +9 -28
  11. package/components/AI/input-message/examples.mdx +37 -33
  12. package/components/AI/input-message/file-preview-tile.tsx +59 -0
  13. package/components/AI/input-message/file-thumbnail.tsx +26 -53
  14. package/components/AI/input-message/index.tsx +362 -1122
  15. package/components/AI/input-message/input-message.css +25 -0
  16. package/components/AI/input-message/queued-row.tsx +102 -0
  17. package/components/AI/input-message/shared.ts +38 -0
  18. package/components/AI/input-message/suggestion-row.tsx +64 -0
  19. package/components/AI/input-message/use-composer-files.ts +142 -0
  20. package/components/AI/input-message/use-history-nav.ts +60 -0
  21. package/components/AI/input-message/use-message-queue.ts +108 -0
  22. package/components/AI/input-message/use-region-height.ts +34 -0
  23. package/components/AI/thinking-indicator/index.tsx +9 -31
  24. package/components/accordion/accordion-content.tsx +217 -0
  25. package/components/accordion/accordion-context.tsx +118 -0
  26. package/components/accordion/accordion-group.tsx +215 -0
  27. package/components/accordion/examples.mdx +64 -132
  28. package/components/accordion/index.tsx +127 -891
  29. package/components/avatar/examples.mdx +2 -2
  30. package/components/avatar/index.tsx +40 -34
  31. package/components/badge/change-demo.tsx +2 -0
  32. package/components/badge/examples.mdx +16 -34
  33. package/components/badge/index.tsx +31 -69
  34. package/components/badge/variants.ts +5 -30
  35. package/components/button/examples.mdx +79 -94
  36. package/components/button/index.tsx +97 -188
  37. package/components/button/loading-demo.tsx +2 -0
  38. package/components/button/variants.ts +12 -117
  39. package/components/card/card-group.tsx +184 -0
  40. package/components/card/card-media.tsx +207 -0
  41. package/components/card/card-parts.tsx +179 -0
  42. package/components/card/examples.mdx +91 -143
  43. package/components/card/index.tsx +190 -881
  44. package/components/copy/examples.mdx +29 -67
  45. package/components/copy/index.tsx +58 -285
  46. package/components/inputs/checkbox/examples.mdx +22 -39
  47. package/components/inputs/checkbox/index.tsx +103 -255
  48. package/components/inputs/checkbox/select-all-demo.tsx +8 -6
  49. package/components/inputs/color-picker/channel-sliders.tsx +70 -0
  50. package/components/inputs/color-picker/color-input.tsx +387 -0
  51. package/components/inputs/color-picker/{variants.ts → color-math.ts} +22 -57
  52. package/components/inputs/color-picker/context.ts +11 -0
  53. package/components/inputs/color-picker/examples.mdx +20 -59
  54. package/components/inputs/color-picker/format-menu.tsx +212 -0
  55. package/components/inputs/color-picker/index.tsx +190 -1776
  56. package/components/inputs/color-picker/inputs-row.tsx +196 -0
  57. package/components/inputs/color-picker/popover.tsx +161 -0
  58. package/components/inputs/color-picker/saturation-square.tsx +167 -0
  59. package/components/inputs/color-picker/swatches.tsx +178 -0
  60. package/components/inputs/combobox/context.ts +90 -0
  61. package/components/inputs/combobox/examples.mdx +103 -206
  62. package/components/inputs/combobox/fields.tsx +328 -0
  63. package/components/inputs/combobox/index.tsx +155 -1310
  64. package/components/inputs/combobox/list.tsx +415 -0
  65. package/components/inputs/combobox/remote-demo.tsx +70 -74
  66. package/components/inputs/date-time/calendar/examples.mdx +0 -11
  67. package/components/inputs/date-time/calendar/index.tsx +32 -59
  68. package/components/inputs/date-time/calendar/use-month-window.ts +35 -32
  69. package/components/inputs/date-time/date-picker/examples.mdx +59 -155
  70. package/components/inputs/date-time/date-picker/index.tsx +186 -370
  71. package/components/inputs/date-time/date-picker/masked-date-input.tsx +105 -247
  72. package/components/inputs/date-time/date-range-picker/examples.mdx +6 -62
  73. package/components/inputs/date-time/date-range-picker/index.tsx +105 -404
  74. package/components/inputs/date-time/date-value.ts +37 -0
  75. package/components/inputs/date-time/day-rules.ts +22 -0
  76. package/components/inputs/date-time/duration-picker/examples.mdx +0 -24
  77. package/components/inputs/date-time/duration-picker/index.tsx +50 -140
  78. package/components/inputs/date-time/month-picker/examples.mdx +0 -29
  79. package/components/inputs/date-time/month-picker/index.tsx +48 -132
  80. package/components/inputs/date-time/picker-shell.tsx +226 -347
  81. package/components/inputs/date-time/time-columns.tsx +11 -15
  82. package/components/inputs/date-time/time-picker/examples.mdx +0 -31
  83. package/components/inputs/date-time/time-picker/index.tsx +37 -118
  84. package/components/inputs/field/examples.mdx +81 -39
  85. package/components/inputs/field/index.tsx +113 -103
  86. package/components/inputs/file-dropzone/examples.mdx +23 -24
  87. package/components/inputs/file-dropzone/file-row.tsx +20 -21
  88. package/components/inputs/file-dropzone/index.tsx +130 -129
  89. package/components/inputs/file-dropzone/upload-demo.tsx +22 -18
  90. package/components/inputs/file-dropzone/variants.ts +3 -1
  91. package/components/inputs/input/examples.mdx +19 -74
  92. package/components/inputs/input/index.tsx +86 -149
  93. package/components/inputs/input/password-demo.tsx +5 -5
  94. package/components/inputs/label/examples.mdx +19 -26
  95. package/components/inputs/label/index.tsx +21 -34
  96. package/components/inputs/number-input/examples.mdx +63 -36
  97. package/components/inputs/number-input/index.tsx +62 -57
  98. package/components/inputs/radio/examples.mdx +24 -39
  99. package/components/inputs/radio/index.tsx +125 -328
  100. package/components/inputs/search/examples.mdx +3 -3
  101. package/components/inputs/search/index.tsx +46 -39
  102. package/components/inputs/select/examples.mdx +76 -167
  103. package/components/inputs/select/index.tsx +252 -776
  104. package/components/inputs/slider/comfortable.tsx +524 -0
  105. package/components/inputs/slider/compact.tsx +690 -0
  106. package/components/inputs/slider/examples.mdx +9 -35
  107. package/components/inputs/slider/geometry.ts +88 -0
  108. package/components/inputs/slider/index.tsx +65 -1796
  109. package/components/inputs/slider/value-display.tsx +184 -0
  110. package/components/inputs/switch/examples.mdx +31 -33
  111. package/components/inputs/switch/index.tsx +55 -107
  112. package/components/inputs/textarea/examples.mdx +23 -61
  113. package/components/inputs/textarea/index.tsx +21 -99
  114. package/components/navigation/navigation-menu/content.tsx +76 -0
  115. package/components/navigation/navigation-menu/context.ts +34 -0
  116. package/components/navigation/navigation-menu/examples.mdx +21 -84
  117. package/components/navigation/navigation-menu/index.tsx +139 -639
  118. package/components/navigation/navigation-menu/item.tsx +47 -0
  119. package/components/navigation/navigation-menu/link.tsx +104 -0
  120. package/components/navigation/navigation-menu/list.tsx +86 -0
  121. package/components/navigation/navigation-menu/trigger.tsx +78 -0
  122. package/components/navigation/navigation-menu/use-dom-rows.ts +56 -0
  123. package/components/navigation/pagination/examples.mdx +25 -34
  124. package/components/navigation/pagination/index.tsx +75 -153
  125. package/components/navigation/sidebar/examples.mdx +17 -23
  126. package/components/navigation/sidebar/index.tsx +59 -119
  127. package/components/navigation/sidebar/menu-scope.tsx +439 -0
  128. package/components/navigation/sidebar/row-label.tsx +61 -0
  129. package/components/navigation/sidebar/sidebar-context.tsx +71 -0
  130. package/components/navigation/sidebar/sidebar-group.tsx +299 -0
  131. package/components/navigation/sidebar/sidebar-menu-actions.tsx +209 -0
  132. package/components/navigation/sidebar/sidebar-menu-button.tsx +214 -0
  133. package/components/navigation/sidebar/sidebar-menu-item.tsx +207 -0
  134. package/components/navigation/sidebar/sidebar-menu-sub.tsx +180 -0
  135. package/components/navigation/sidebar/sidebar-parts.tsx +94 -0
  136. package/components/navigation/sidebar/sidebar-provider.tsx +248 -0
  137. package/components/navigation/sidebar/sidebar-rail.tsx +206 -0
  138. package/components/navigation/sidebar/sidebar-shell.tsx +180 -0
  139. package/components/navigation/sidebar/sidebar-shortcut.tsx +101 -0
  140. package/components/navigation/sidebar/sidebar.css +7 -11
  141. package/components/navigation/sidebar/use-measured-collapse.ts +62 -0
  142. package/components/navigation/tabs/context.ts +45 -0
  143. package/components/navigation/tabs/examples.mdx +63 -17
  144. package/components/navigation/tabs/index.tsx +82 -434
  145. package/components/navigation/tabs/item.tsx +161 -0
  146. package/components/navigation/tabs/list.tsx +143 -0
  147. package/components/overlays/alert-dialog/examples.mdx +2 -36
  148. package/components/overlays/alert-dialog/index.tsx +76 -90
  149. package/components/overlays/alert-dialog/pending-demo.tsx +3 -1
  150. package/components/overlays/command/index.tsx +28 -59
  151. package/components/overlays/context-menu/examples.mdx +58 -4
  152. package/components/overlays/context-menu/index.tsx +77 -221
  153. package/components/overlays/dialog/examples.mdx +8 -31
  154. package/components/overlays/dialog/index.tsx +81 -261
  155. package/components/overlays/dropdown/dropdown-search.tsx +33 -98
  156. package/components/overlays/dropdown/examples.mdx +77 -363
  157. package/components/overlays/dropdown/index.tsx +114 -1010
  158. package/components/overlays/dropdown/menu-item.tsx +98 -382
  159. package/components/overlays/dropdown/menu-popup.tsx +294 -0
  160. package/components/overlays/dropdown/panel-state.ts +176 -0
  161. package/components/overlays/dropdown/submenu.tsx +170 -0
  162. package/components/overlays/popover/anchored-demo.tsx +22 -13
  163. package/components/overlays/popover/examples.mdx +16 -65
  164. package/components/overlays/popover/index.tsx +93 -137
  165. package/components/overlays/preview-card/examples.mdx +4 -4
  166. package/components/overlays/preview-card/index.tsx +48 -103
  167. package/components/overlays/sheet/examples.mdx +0 -12
  168. package/components/overlays/sheet/index.tsx +44 -129
  169. package/components/overlays/toast/examples.mdx +33 -25
  170. package/components/overlays/toast/index.tsx +56 -203
  171. package/components/overlays/toast/manager.ts +63 -119
  172. package/components/overlays/tooltip/examples.mdx +6 -12
  173. package/components/overlays/tooltip/index.tsx +124 -264
  174. package/components/progress/index.tsx +24 -30
  175. package/components/progress/progress.css +6 -28
  176. package/components/progress/step-demo.tsx +2 -0
  177. package/components/table/context.ts +49 -0
  178. package/components/table/examples.mdx +40 -72
  179. package/components/table/head.tsx +105 -0
  180. package/components/table/index.tsx +73 -458
  181. package/components/table/parts.tsx +188 -0
  182. package/components/table/sort-demo.tsx +21 -30
  183. package/dist/base.css +141 -122
  184. package/dist/blocks/sidebar-app/index.d.ts +10 -2
  185. package/dist/blocks/sidebar-app/index.js +49 -40
  186. package/dist/components/AI/input-message/index.d.ts +22 -19
  187. package/dist/components/AI/input-message/index.js +30 -23
  188. package/dist/components/AI/thinking-indicator/index.d.ts +2 -0
  189. package/dist/components/AI/thinking-indicator/index.js +10 -9
  190. package/dist/components/accordion/index.d.ts +52 -85
  191. package/dist/components/accordion/index.js +25 -19
  192. package/dist/components/avatar/index.d.ts +10 -10
  193. package/dist/components/avatar/index.js +9 -8
  194. package/dist/components/badge/index.d.ts +11 -18
  195. package/dist/components/badge/index.js +9 -9
  196. package/dist/components/badge/variants.d.ts +2 -9
  197. package/dist/components/badge/variants.js +3 -5
  198. package/dist/components/button/index.d.ts +36 -60
  199. package/dist/components/button/index.js +12 -9
  200. package/dist/components/button/variants.d.ts +3 -34
  201. package/dist/components/button/variants.js +2 -4
  202. package/dist/components/card/index.d.ts +163 -108
  203. package/dist/components/card/index.js +30 -21
  204. package/dist/components/copy/index.d.ts +10 -41
  205. package/dist/components/copy/index.js +18 -15
  206. package/dist/components/inputs/checkbox/index.d.ts +25 -25
  207. package/dist/components/inputs/checkbox/index.js +22 -18
  208. package/dist/components/inputs/color-picker/index.d.ts +65 -53
  209. package/dist/components/inputs/color-picker/index.js +35 -29
  210. package/dist/components/inputs/combobox/index.d.ts +147 -152
  211. package/dist/components/inputs/combobox/index.js +31 -29
  212. package/dist/components/inputs/date-time/calendar/index.d.ts +18 -24
  213. package/dist/components/inputs/date-time/calendar/index.js +17 -15
  214. package/dist/components/inputs/date-time/date-picker/index.d.ts +52 -96
  215. package/dist/components/inputs/date-time/date-picker/index.js +42 -35
  216. package/dist/components/inputs/date-time/date-range-picker/index.d.ts +48 -108
  217. package/dist/components/inputs/date-time/date-range-picker/index.js +40 -35
  218. package/dist/components/inputs/date-time/duration-picker/index.d.ts +21 -67
  219. package/dist/components/inputs/date-time/duration-picker/index.js +39 -33
  220. package/dist/components/inputs/date-time/month-picker/index.d.ts +18 -61
  221. package/dist/components/inputs/date-time/month-picker/index.js +38 -32
  222. package/dist/components/inputs/date-time/time-picker/index.d.ts +18 -59
  223. package/dist/components/inputs/date-time/time-picker/index.js +39 -33
  224. package/dist/components/inputs/field/index.d.ts +37 -41
  225. package/dist/components/inputs/field/index.js +13 -14
  226. package/dist/components/inputs/file-dropzone/index.d.ts +32 -25
  227. package/dist/components/inputs/file-dropzone/index.js +18 -15
  228. package/dist/components/inputs/file-dropzone/variants.js +1 -1
  229. package/dist/components/inputs/input/index.d.ts +48 -50
  230. package/dist/components/inputs/input/index.js +14 -12
  231. package/dist/components/inputs/label/index.d.ts +12 -10
  232. package/dist/components/inputs/label/index.js +5 -4
  233. package/dist/components/inputs/number-input/index.d.ts +31 -23
  234. package/dist/components/inputs/number-input/index.js +16 -14
  235. package/dist/components/inputs/radio/index.d.ts +20 -16
  236. package/dist/components/inputs/radio/index.js +20 -16
  237. package/dist/components/inputs/search/index.d.ts +12 -5
  238. package/dist/components/inputs/search/index.js +33 -26
  239. package/dist/components/inputs/select/index.d.ts +88 -99
  240. package/dist/components/inputs/select/index.js +32 -29
  241. package/dist/components/inputs/slider/index.d.ts +26 -48
  242. package/dist/components/inputs/slider/index.js +9 -10
  243. package/dist/components/inputs/switch/index.d.ts +12 -6
  244. package/dist/components/inputs/switch/index.js +17 -15
  245. package/dist/components/inputs/textarea/index.d.ts +12 -22
  246. package/dist/components/inputs/textarea/index.js +12 -9
  247. package/dist/components/navigation/navigation-menu/index.d.ts +112 -83
  248. package/dist/components/navigation/navigation-menu/index.js +31 -27
  249. package/dist/components/navigation/pagination/index.d.ts +25 -38
  250. package/dist/components/navigation/pagination/index.js +27 -34
  251. package/dist/components/navigation/sidebar/index.d.ts +236 -230
  252. package/dist/components/navigation/sidebar/index.js +59 -55
  253. package/dist/components/navigation/tabs/index.d.ts +62 -45
  254. package/dist/components/navigation/tabs/index.js +23 -17
  255. package/dist/components/overlays/alert-dialog/index.d.ts +71 -106
  256. package/dist/components/overlays/alert-dialog/index.js +24 -19
  257. package/dist/components/overlays/command/index.d.ts +40 -31
  258. package/dist/components/overlays/command/index.js +31 -25
  259. package/dist/components/overlays/context-menu/index.d.ts +70 -84
  260. package/dist/components/overlays/context-menu/index.js +35 -31
  261. package/dist/components/overlays/dialog/index.d.ts +82 -98
  262. package/dist/components/overlays/dialog/index.js +23 -20
  263. package/dist/components/overlays/dropdown/index.d.ts +191 -357
  264. package/dist/components/overlays/dropdown/index.js +35 -41
  265. package/dist/components/overlays/popover/index.d.ts +81 -52
  266. package/dist/components/overlays/popover/index.js +17 -13
  267. package/dist/components/overlays/preview-card/index.d.ts +52 -26
  268. package/dist/components/overlays/preview-card/index.js +16 -12
  269. package/dist/components/overlays/sheet/index.d.ts +41 -45
  270. package/dist/components/overlays/sheet/index.js +24 -19
  271. package/dist/components/overlays/toast/index.d.ts +73 -183
  272. package/dist/components/overlays/toast/index.js +20 -21
  273. package/dist/components/overlays/tooltip/index.d.ts +80 -118
  274. package/dist/components/overlays/tooltip/index.js +14 -12
  275. package/dist/components/progress/index.d.ts +10 -11
  276. package/dist/components/progress/index.js +7 -6
  277. package/dist/components/table/index.d.ts +72 -71
  278. package/dist/components/table/index.js +18 -16
  279. package/dist/index.d.ts +2575 -3149
  280. package/dist/index.js +186 -202
  281. package/dist/lib/date-locale.d.ts +6 -13
  282. package/dist/lib/date-locale.js +5 -11
  283. package/dist/lib/date-mask.d.ts +41 -0
  284. package/dist/lib/date-mask.js +20 -0
  285. package/dist/lib/field-box.d.ts +114 -0
  286. package/dist/lib/field-box.js +18 -0
  287. package/dist/lib/field-classes.d.ts +15 -119
  288. package/dist/lib/field-classes.js +4 -21
  289. package/dist/lib/fluid-hover-highlight.d.ts +3 -25
  290. package/dist/lib/fluid-hover-highlight.js +8 -13
  291. package/dist/lib/focus-ring.d.ts +16 -10
  292. package/dist/lib/focus-ring.js +6 -6
  293. package/dist/lib/goo-indicator.js +6 -5
  294. package/dist/lib/icon-context.d.ts +2 -8
  295. package/dist/lib/icon-context.js +2 -6
  296. package/dist/lib/merge-refs.d.ts +10 -0
  297. package/dist/lib/merge-refs.js +8 -0
  298. package/dist/lib/morph-layers.d.ts +12 -6
  299. package/dist/lib/morph-layers.js +7 -6
  300. package/dist/lib/morph-part.js +3 -3
  301. package/dist/lib/overlay.d.ts +113 -0
  302. package/dist/lib/overlay.js +21 -0
  303. package/dist/lib/popup-rows.d.ts +101 -0
  304. package/dist/lib/popup-rows.js +25 -0
  305. package/dist/lib/popup-surface.d.ts +92 -0
  306. package/dist/lib/popup-surface.js +17 -0
  307. package/dist/lib/popup.d.ts +17 -1
  308. package/dist/lib/popup.js +4 -1
  309. package/dist/lib/rect.d.ts +16 -0
  310. package/dist/lib/rect.js +12 -0
  311. package/dist/lib/reduced-motion.js +1 -1
  312. package/dist/lib/row-group.d.ts +100 -0
  313. package/dist/lib/row-group.js +12 -0
  314. package/dist/lib/row-index.d.ts +12 -7
  315. package/dist/lib/row-index.js +4 -2
  316. package/dist/lib/scroll-column.d.ts +1 -5
  317. package/dist/lib/scroll-column.js +13 -12
  318. package/dist/lib/shape-classes.d.ts +16 -0
  319. package/dist/lib/shape-classes.js +6 -0
  320. package/dist/lib/shape-context.d.ts +2 -9
  321. package/dist/lib/shape-context.js +3 -7
  322. package/dist/lib/size-context.d.ts +1 -2
  323. package/dist/lib/size-context.js +2 -7
  324. package/dist/lib/size-scale.js +1 -1
  325. package/dist/lib/slot.d.ts +31 -26
  326. package/dist/lib/slot.js +9 -9
  327. package/dist/lib/spinner-glyph.d.ts +7 -0
  328. package/dist/lib/spinner-glyph.js +7 -0
  329. package/dist/lib/springs.d.ts +5 -1
  330. package/dist/lib/springs.js +4 -2
  331. package/dist/lib/surface-classes.js +1 -1
  332. package/dist/lib/surface-context.d.ts +3 -1
  333. package/dist/lib/surface-context.js +3 -1
  334. package/dist/lib/use-autosize-textarea.d.ts +16 -0
  335. package/dist/lib/use-autosize-textarea.js +7 -0
  336. package/dist/lib/use-controllable-state.d.ts +15 -1
  337. package/dist/lib/use-controllable-state.js +1 -1
  338. package/dist/lib/use-fluid-hover.d.ts +1 -49
  339. package/dist/lib/use-fluid-hover.js +1 -7
  340. package/dist/lib/use-is-mobile.js +1 -1
  341. package/dist/lib/use-iso-layout-effect.d.ts +7 -0
  342. package/dist/lib/use-iso-layout-effect.js +6 -0
  343. package/dist/lib/use-keyboard-nav-gate.js +3 -2
  344. package/dist/lib/use-merge-split.js +7 -6
  345. package/dist/lib/use-morph.d.ts +13 -7
  346. package/dist/lib/use-morph.js +4 -3
  347. package/dist/lib/use-touch-primary.js +1 -1
  348. package/dist/lib/utils.js +1 -1
  349. package/dist/lib/weight-label.d.ts +26 -0
  350. package/dist/lib/weight-label.js +7 -0
  351. package/dist/preset.d.ts +4 -8
  352. package/dist/preset.js +8 -8
  353. package/dist/primitives/code/index.js +8 -8
  354. package/dist/primitives/craft/index.d.ts +1 -1
  355. package/dist/primitives/craft/index.js +13 -12
  356. package/dist/primitives/fluid-hover/index.d.ts +13 -14
  357. package/dist/primitives/fluid-hover/index.js +13 -10
  358. package/dist/primitives/morph/index.d.ts +1 -1
  359. package/dist/primitives/morph/index.js +20 -16
  360. package/dist/primitives/motion/index.d.ts +2 -0
  361. package/dist/primitives/motion/index.js +14 -11
  362. package/dist/primitives/scroll-area/index.d.ts +5 -4
  363. package/dist/primitives/scroll-area/index.js +5 -5
  364. package/dist/primitives/separator/index.d.ts +12 -11
  365. package/dist/primitives/separator/index.js +2 -2
  366. package/dist/primitives/sizes/index.d.ts +17 -4
  367. package/dist/primitives/sizes/index.js +7 -4
  368. package/dist/primitives/skeleton/index.d.ts +8 -8
  369. package/dist/primitives/skeleton/index.js +7 -6
  370. package/dist/primitives/surface/index.d.ts +12 -25
  371. package/dist/primitives/surface/index.js +8 -6
  372. package/dist/shared/{components-yxmxn2jp.js → components-07g2gbjy.js} +30 -75
  373. package/dist/shared/components-099sdasz.js +552 -0
  374. package/dist/shared/{components-bsqynhaj.js → components-0h3f5jae.js} +49 -51
  375. package/dist/shared/{components-wbbckbw8.js → components-0mrhj88d.js} +13 -12
  376. package/dist/shared/{components-0h78g3b5.js → components-0p2na0cp.js} +19 -47
  377. package/dist/shared/components-1a7cr7vh.js +40 -0
  378. package/dist/shared/components-1axxc3tk.js +334 -0
  379. package/dist/shared/components-1hc3xv0y.js +381 -0
  380. package/dist/shared/{components-gyt7my41.js → components-1jxw899c.js} +94 -84
  381. package/dist/shared/{components-jqpefjsn.js → components-1nv9q3s8.js} +24 -44
  382. package/dist/shared/components-1p3k62x2.js +137 -0
  383. package/dist/shared/{components-kz5q11pp.js → components-2xmke84n.js} +12 -4
  384. package/dist/shared/{components-c7rwx0ap.js → components-346ged8v.js} +24 -3
  385. package/dist/shared/{components-4j3t39dd.js → components-34brwmgp.js} +12 -11
  386. package/dist/shared/components-38wa9nx5.js +19 -0
  387. package/dist/shared/components-3hgk57s0.js +27 -0
  388. package/dist/shared/{components-px2zm7dc.js → components-3js2vgds.js} +13 -6
  389. package/dist/shared/{components-ctqmge8t.js → components-3m4rqrqm.js} +10 -3
  390. package/dist/shared/{components-3ey0hzpb.js → components-45r18egt.js} +11 -1
  391. package/dist/shared/components-50rh4ggz.js +54 -0
  392. package/dist/shared/components-5atrr490.js +99 -0
  393. package/dist/shared/components-5f3tq4qb.js +70 -0
  394. package/dist/shared/{components-dc5q749x.js → components-5vyaexsj.js} +16 -17
  395. package/dist/shared/{components-pwayrkw9.js → components-5ynncdpn.js} +5 -4
  396. package/dist/shared/{components-1e64t8aj.js → components-62mg6pab.js} +232 -93
  397. package/dist/shared/{components-drxrtnp2.js → components-6f5pyzb2.js} +8 -0
  398. package/dist/shared/{components-868v7scv.js → components-6xfhc5qm.js} +104 -169
  399. package/dist/shared/{components-yhgq0qxx.js → components-7c4a0egq.js} +20 -12
  400. package/dist/shared/components-7fqnqbh0.js +79 -0
  401. package/dist/shared/components-7fsy0jxg.js +443 -0
  402. package/dist/shared/{components-p0fm0bab.js → components-7t3pz7v7.js} +496 -526
  403. package/dist/shared/components-85epgxwf.js +620 -0
  404. package/dist/shared/{components-wknae3m4.js → components-86vvx0c8.js} +75 -121
  405. package/dist/shared/{components-wgtjt2af.js → components-88ktjdg0.js} +30 -27
  406. package/dist/shared/{components-ft3zdc79.js → components-88r046aa.js} +6 -6
  407. package/dist/shared/{components-xd3emmy4.js → components-8hfrd2fk.js} +1462 -1464
  408. package/dist/shared/components-8sazy704.js +146 -0
  409. package/dist/shared/{components-rrbpmfx4.js → components-8wp8d8q1.js} +8 -0
  410. package/dist/shared/{components-rtadhd9j.js → components-9ybenn5v.js} +16 -16
  411. package/dist/shared/components-amsc86fb.js +293 -0
  412. package/dist/shared/{components-9as3rf68.js → components-az04rmng.js} +12 -6
  413. package/dist/shared/components-bdkm2jzy.js +34 -0
  414. package/dist/shared/{components-xjkdvnbg.js → components-be3wggg1.js} +54 -48
  415. package/dist/shared/components-bkwjvvkh.js +18 -0
  416. package/dist/shared/{components-vf45j12c.js → components-ceyn28cf.js} +7 -0
  417. package/dist/shared/{components-3h92d94m.js → components-cy5z8zxy.js} +1 -2
  418. package/dist/shared/components-dm86y7b3.js +105 -0
  419. package/dist/shared/{components-c9yr4ed1.js → components-ejn6tvbw.js} +8 -6
  420. package/dist/shared/{components-34txk9rj.js → components-ew4wq7mj.js} +7 -0
  421. package/dist/shared/{components-svkt577j.js → components-f75y4gn8.js} +53 -70
  422. package/dist/shared/components-f9adtfq8.js +34 -0
  423. package/dist/shared/{components-2a7hcand.js → components-gbsdhmrv.js} +48 -83
  424. package/dist/shared/{components-9sttq78t.js → components-gc5zky2w.js} +54 -59
  425. package/dist/shared/{components-bae8sbjx.js → components-gkdx1787.js} +12 -6
  426. package/dist/shared/{components-124epb7f.js → components-grxgqa75.js} +3 -7
  427. package/dist/shared/components-gw0wd7gd.js +986 -0
  428. package/dist/shared/components-j4z3rtw2.js +179 -0
  429. package/dist/shared/{components-t5pk5nmc.js → components-j8tcbm8y.js} +927 -953
  430. package/dist/shared/components-jm91mjm1.js +297 -0
  431. package/dist/shared/{components-b94t6qtj.js → components-jtfptckj.js} +44 -39
  432. package/dist/shared/components-jx9qb4z8.js +63 -0
  433. package/dist/shared/components-k785rge6.js +336 -0
  434. package/dist/shared/{components-r8eqs7gz.js → components-k81x1aea.js} +10 -6
  435. package/dist/shared/{components-qx27excf.js → components-kn5c7652.js} +11 -13
  436. package/dist/shared/components-mse06t0x.js +31 -0
  437. package/dist/shared/{components-cet3jpa0.js → components-n7e31ct4.js} +71 -49
  438. package/dist/shared/components-nskr4hwg.js +1008 -0
  439. package/dist/shared/components-nv5m3gcv.js +37 -0
  440. package/dist/shared/components-nwa2a9tq.js +27 -0
  441. package/dist/shared/{components-f7h57m6t.js → components-p0x8ren6.js} +3 -1
  442. package/dist/shared/{components-2krsc300.js → components-p0z99d5b.js} +67 -92
  443. package/dist/shared/{components-b1e239g3.js → components-pa43g2r2.js} +15 -4
  444. package/dist/shared/{components-m06yq8wk.js → components-pedbt2dc.js} +35 -49
  445. package/dist/shared/components-pva1wj1r.js +27 -0
  446. package/dist/shared/components-q4wyd06h.js +382 -0
  447. package/dist/shared/{components-71nbt03m.js → components-qrpdtvxa.js} +12 -45
  448. package/dist/shared/components-r33dxr5j.js +91 -0
  449. package/dist/shared/{components-005jt2nz.js → components-re8p99fj.js} +53 -179
  450. package/dist/shared/components-s217vq1n.js +35 -0
  451. package/dist/shared/{components-vc864c51.js → components-sesrjvcc.js} +7 -6
  452. package/dist/shared/{components-qh1cvj6p.js → components-skn189mp.js} +29 -36
  453. package/dist/shared/{components-tz4gaf1v.js → components-tcyz2tdn.js} +9 -1
  454. package/dist/shared/components-tjxy84s9.js +53 -0
  455. package/dist/shared/components-tnj6mkhg.js +89 -0
  456. package/dist/shared/{components-de99ykt7.js → components-tz0axc0f.js} +1 -0
  457. package/dist/shared/components-v2j3jx89.js +7 -0
  458. package/dist/shared/components-vcte8p75.js +71 -0
  459. package/dist/shared/{components-c74gf16d.js → components-vgzerqt0.js} +34 -47
  460. package/dist/shared/components-vp6vzsee.js +30 -0
  461. package/dist/shared/components-vpkh6j83.js +42 -0
  462. package/dist/shared/{components-4nck8acq.js → components-wgd1nebp.js} +21 -14
  463. package/dist/shared/{components-pt5ftm4p.js → components-wrbw67f6.js} +10 -3
  464. package/dist/shared/{components-tz1fv35x.js → components-wwd093xg.js} +1 -0
  465. package/dist/shared/components-wyfmhtw9.js +61 -0
  466. package/dist/shared/{components-d3shbwqq.js → components-xpw8dzb0.js} +16 -23
  467. package/dist/shared/{components-mattt5jp.js → components-xzcgr3gy.js} +62 -60
  468. package/dist/shared/{components-jcnjay5g.js → components-ycx2kxeq.js} +9 -1
  469. package/dist/shared/components-zbzx62pg.js +1771 -0
  470. package/dist/shared/{components-dtca4s6b.js → components-zf0nnvvg.js} +67 -147
  471. package/dist/shared/{components-h83az0bz.js → components-znspksk0.js} +9 -1
  472. package/dist/shared/components-zpatc9x3.js +78 -0
  473. package/dist/styles.css +218 -235
  474. package/dist/tailwind.css +20 -8
  475. package/dist/tokens.css +53 -68
  476. package/index.ts +16 -2
  477. package/lib/date-locale.ts +12 -149
  478. package/lib/date-mask.ts +146 -0
  479. package/lib/field-box.ts +117 -0
  480. package/lib/field-classes.ts +85 -100
  481. package/lib/fluid-hover-highlight.tsx +12 -57
  482. package/lib/focus-ring.tsx +25 -22
  483. package/lib/goo-indicator.tsx +2 -0
  484. package/lib/icon-context.tsx +23 -75
  485. package/lib/merge-refs.ts +29 -0
  486. package/lib/morph-layers.tsx +3 -1
  487. package/lib/morph-part.tsx +5 -3
  488. package/lib/overlay.tsx +118 -0
  489. package/lib/popup-rows.tsx +149 -0
  490. package/lib/popup-surface.tsx +52 -0
  491. package/lib/popup.ts +10 -9
  492. package/lib/rect.ts +48 -0
  493. package/lib/reduced-motion.ts +2 -0
  494. package/lib/row-group.tsx +113 -0
  495. package/lib/row-index.tsx +27 -10
  496. package/lib/scroll-column.tsx +26 -53
  497. package/lib/shape-classes.ts +56 -0
  498. package/lib/shape-context.tsx +10 -79
  499. package/lib/size-context.tsx +8 -21
  500. package/lib/size-scale.ts +3 -9
  501. package/lib/slot.tsx +124 -0
  502. package/lib/spinner-glyph.tsx +27 -0
  503. package/lib/springs.ts +8 -9
  504. package/lib/surface-classes.ts +3 -8
  505. package/lib/surface-context.tsx +10 -5
  506. package/lib/use-autosize-textarea.ts +64 -0
  507. package/lib/use-controllable-state.ts +30 -15
  508. package/lib/use-fluid-hover.ts +9 -11
  509. package/lib/use-is-mobile.ts +5 -5
  510. package/lib/use-iso-layout-effect.ts +14 -0
  511. package/lib/use-keyboard-nav-gate.ts +5 -6
  512. package/lib/use-merge-split.tsx +5 -15
  513. package/lib/use-morph.ts +34 -76
  514. package/lib/use-touch-primary.tsx +5 -5
  515. package/lib/utils.ts +4 -11
  516. package/lib/weight-label.tsx +69 -0
  517. package/package.json +57 -194
  518. package/primitives/code/index.tsx +4 -2
  519. package/primitives/craft/demos.tsx +4 -2
  520. package/primitives/craft/examples.mdx +32 -34
  521. package/primitives/craft/index.tsx +3 -0
  522. package/primitives/fluid-hover/examples.mdx +1 -1
  523. package/primitives/fluid-hover/index.tsx +33 -68
  524. package/primitives/morph/examples.mdx +16 -19
  525. package/primitives/morph/index.tsx +5 -3
  526. package/primitives/motion/examples.mdx +3 -3
  527. package/primitives/motion/index.tsx +6 -22
  528. package/primitives/scroll-area/examples.mdx +4 -4
  529. package/primitives/scroll-area/index.tsx +16 -41
  530. package/primitives/separator/examples.mdx +2 -2
  531. package/primitives/separator/index.tsx +15 -14
  532. package/primitives/sizes/examples.mdx +1 -1
  533. package/primitives/sizes/index.tsx +28 -42
  534. package/primitives/skeleton/examples.mdx +6 -6
  535. package/primitives/skeleton/index.tsx +24 -10
  536. package/primitives/skeleton/skeleton.css +8 -3
  537. package/primitives/surface/examples.mdx +11 -11
  538. package/primitives/surface/index.tsx +15 -40
  539. package/primitives/surface/surface.css +1 -1
  540. package/DESIGN.md +0 -623
  541. package/components/inputs/select/variants.ts +0 -32
  542. package/components/navigation/sidebar/sidebar-core.tsx +0 -1408
  543. package/components/navigation/sidebar/sidebar-menu.tsx +0 -1495
  544. package/components/navigation/sidebar/variants.ts +0 -55
  545. package/components/navigation/tabs-subtle/examples.mdx +0 -49
  546. package/components/navigation/tabs-subtle/index.tsx +0 -512
  547. package/components/overlays/dropdown/menu-parts.tsx +0 -725
  548. package/components/overlays/toast/global-demo.tsx +0 -72
  549. package/dist/components/inputs/color-picker/variants.d.ts +0 -61
  550. package/dist/components/inputs/color-picker/variants.js +0 -28
  551. package/dist/components/inputs/select/variants.d.ts +0 -5
  552. package/dist/components/inputs/select/variants.js +0 -6
  553. package/dist/components/navigation/sidebar/variants.d.ts +0 -25
  554. package/dist/components/navigation/sidebar/variants.js +0 -28
  555. package/dist/components/navigation/tabs-subtle/index.d.ts +0 -73
  556. package/dist/components/navigation/tabs-subtle/index.js +0 -24
  557. package/dist/docs/index.d.ts +0 -83
  558. package/dist/docs/index.js +0 -288
  559. package/dist/docs/vite.d.ts +0 -31
  560. package/dist/docs/vite.js +0 -45
  561. package/dist/lib/field-variants.d.ts +0 -47
  562. package/dist/lib/field-variants.js +0 -26
  563. package/dist/lib/inert.d.ts +0 -9
  564. package/dist/lib/inert.js +0 -8
  565. package/dist/lib/row-order.d.ts +0 -28
  566. package/dist/lib/row-order.js +0 -10
  567. package/dist/lib/shape-radius.d.ts +0 -19
  568. package/dist/lib/shape-radius.js +0 -6
  569. package/dist/shared/components-01w9qcfa.js +0 -277
  570. package/dist/shared/components-26snnbs9.js +0 -322
  571. package/dist/shared/components-2qbqqpgq.js +0 -1545
  572. package/dist/shared/components-303jf96s.js +0 -1478
  573. package/dist/shared/components-4vfm04wq.js +0 -82
  574. package/dist/shared/components-54nq988h.js +0 -123
  575. package/dist/shared/components-7qx17na9.js +0 -300
  576. package/dist/shared/components-7s7pykk5.js +0 -281
  577. package/dist/shared/components-8jrk5eye.js +0 -448
  578. package/dist/shared/components-91zw3d9f.js +0 -136
  579. package/dist/shared/components-9jmjnkqd.js +0 -503
  580. package/dist/shared/components-adkarj8n.js +0 -35
  581. package/dist/shared/components-c5w5zk0s.js +0 -218
  582. package/dist/shared/components-cnead5qm.js +0 -185
  583. package/dist/shared/components-czdvj1a8.js +0 -266
  584. package/dist/shared/components-dcc02hs2.js +0 -31
  585. package/dist/shared/components-dhgk6mbt.js +0 -16
  586. package/dist/shared/components-g3eafs70.js +0 -337
  587. package/dist/shared/components-gx4h5rbb.js +0 -40
  588. package/dist/shared/components-h6p86be3.js +0 -19
  589. package/dist/shared/components-hdzrqqpx.js +0 -55
  590. package/dist/shared/components-hgv6tygd.js +0 -986
  591. package/dist/shared/components-krtx3m5b.js +0 -84
  592. package/dist/shared/components-kswxnm3h.js +0 -24
  593. package/dist/shared/components-mhza2wdn.js +0 -482
  594. package/dist/shared/components-mrbaxt8q.js +0 -62
  595. package/dist/shared/components-pv1dyrtn.js +0 -678
  596. package/dist/shared/components-s8yqk2dc.js +0 -124
  597. package/dist/shared/components-syynwm1r.js +0 -114
  598. package/dist/shared/components-tv7b8tet.js +0 -271
  599. package/dist/shared/components-w2jqa6hx.js +0 -404
  600. package/dist/shared/components-xdqmt6ed.js +0 -20
  601. package/dist/shared/components-y0kfy2g4.js +0 -578
  602. package/dist/shared/components-z3v0n0de.js +0 -11
  603. package/dist/shared/components-z8fedth5.js +0 -305
  604. package/dist/shared/components-zkk3fmw8.js +0 -150
  605. package/dist/tokens/colors.css +0 -230
  606. package/dist/tokens/motion.css +0 -40
  607. package/dist/tokens/radius.css +0 -10
  608. package/dist/tokens/spacing.css +0 -9
  609. package/dist/tokens/typography.css +0 -119
  610. package/docs/chrome.css +0 -120
  611. package/docs/chrome.tsx +0 -283
  612. package/docs/index.ts +0 -9
  613. package/docs/vite.ts +0 -85
  614. package/lib/field-variants.ts +0 -117
  615. package/lib/inert.ts +0 -22
  616. package/lib/row-order.tsx +0 -126
  617. package/lib/shape-radius.ts +0 -67
  618. package/lib/slot.ts +0 -115
  619. package/preset.ts +0 -199
@@ -1,256 +1,59 @@
1
- // biome-ignore-all lint: vendored upstream code keeps its own patterns (see the header)
2
- /*
1
+ /*!
3
2
  * Ported from Fluid Functionalism — github.com/mickadesign/fluid-functionalism
4
3
  * `registry/base/combobox.tsx` @ b3587bdbd83fc66c2a6aae3817ffb856cb09260b
5
4
  * MIT License © 2026 Micka Touillaud — fluidfunctionalism.com (notice: LICENSE.fluid-functionalism)
6
- * Local modifications:
7
- * - `"use client"` dropped (no RSC here).
8
- * - Imports rewritten: `@/lib/*` → `../../../lib/*` (`SizeProvider` →
9
- * `../../../primitives/sizes`), `@/hooks/*` → `../../../lib/*`,
10
- * `@/lib/elevated` → `../../../primitives/surface`, `@/components/ui/scroll-area` →
11
- * `../../../primitives/scroll-area`, `@/components/ui/fluid-hover-highlight` →
12
- * `../../../lib/fluid-hover-highlight`, `framer-motion` → `motion/react`.
13
- * - `React.*` type references replaced with named type imports (no React namespace import).
14
- * - The root's generics (`<T extends ComboboxItemData, Multiple extends boolean>`) dropped:
15
- * modo's parser needs a plain (non-generic) function declaration for the root plus a
16
- * same-file `interface ComboboxProps`. Item objects gained an index signature so rows can still
17
- * carry extra fields (`icon`, …), `value`/`defaultValue` are `string | string[]`, and
18
- * `onValueChange` is a union of the two handler shapes so `setState` still assigns.
19
- * `ComboboxValue<Multiple>` is still exported for callers that spell the value out.
20
- * - Uncontrolled create mode added: `creatable` offers the create row with no callback and
21
- * the component keeps the items it makes (merged into `items`, deduped by value), so a
22
- * combobox can grow its own list. `onCreate` is unchanged and still wins when it returns
23
- * an item.
24
- * - `noUncheckedIndexedAccess`: the single-mode checked rect guards `checkedIndices[0]`.
25
- * - modo item: TSDoc (FF docs page + API tables), statics `Combobox.Input` / `.Chips` /
26
- * `.Content` / `.List` / `.Item` / `.Empty` assigned on the root, upstream named exports
27
- * kept, `export default Combobox`.
28
- * - Styling reads DS tokens (AGENTS.md styling): `text-[Npx]` →
29
- * `text-<role>[-compact]`; the hex focus-ring fallback →
30
- * `ring-focus-ring` / `border-focus-ring`; `duration-80|120|160` and
31
- * tier-length JS durations → `duration-<tier>` / `spring.*`.
32
- * - The popup morphs out of the field through the shared morph layer
33
- * (`lib/use-morph.ts` + `MorphSurface`, goo by default on
34
- * `spring.goo`; `Combobox.Content` takes `from` / `effect` /
35
- * `hideSource` / `tier`). Whatever opened it (typing, a press on the input
36
- * or the chevron), the source is the field the list anchors to. The
37
- * `scaleY` motion wrapper and the `actionsRef` deferred unmount (with its
38
- * fallback timer) are gone: the morph holds Base UI's unmount itself. The
39
- * popup paints its level through the morph's surface layers instead of
40
- * `render={<Elevated/>}`, re-providing it with `SurfaceProvider`.
41
- * - `effect="morph"` with `hideSource` opens the list in place over its
42
- * trigger: the positioner's `sideOffset` becomes the engine's `inPlaceOffset`.
43
- * - The fields' ladder is the shared `lib/field-classes.ts` recipe (the local
44
- * `fieldVariants` cva moved there, still exported here as
45
- * `comboboxFieldVariants`; its default is now `borderless`, the fields pass
46
- * `bordered`): `error` stamps `data-invalid` instead of overriding the ring
47
- * per state, so an invalid field also tints its lit fill; the leading icon
48
- * darkens and thickens on hover too, not only on focus. Both fields build
49
- * their box with the shared `useFieldBox` (ladder in the variant, state
50
- * attributes, radius, inset), as every text field does; `variant` is typed
51
- * `FieldVariant` (no `null`).
52
- * - Hooks for remote data (local): `loading` (the chevron turns into a
53
- * spinner, a status row under the list, the empty message held back),
54
- * a controlled query (`inputValue` / `defaultInputValue` /
55
- * `onInputValueChange`), `filter={null}` to keep every item the caller
56
- * hands in, `readOnly`, a controlled popup (`open` / `defaultOpen` /
57
- * `onOpenChange`), a `footer` under the list (`Combobox.Content`), and
58
- * object items whose `label` is any node with a `textValue` to filter and
59
- * fill the field by.
60
- * - Field parity (local): the fields read a surrounding Field's invalid state
61
- * (`error` still forces it; `invalid` is a prop too, and `aria-invalid`
62
- * follows the resolved state), `hideTrigger` drops the chevron button,
63
- * `labels` on the root translates the "Open" / "Clear" / "Remove …" button
64
- * names and the default "Search…" placeholder, and `onInputValueChange`
65
- * hears Base UI's change details (`reason`) as a second argument.
5
+ * Local changes: see PORTING.md.
66
6
  */
67
7
 
68
- import { Combobox as ComboboxPrimitive, type ComboboxRootChangeEventDetails } from '@base-ui/react/combobox'
69
- import { AnimatePresence, animate, motion, useMotionValue } from 'motion/react'
70
- import {
71
- createContext,
72
- forwardRef,
73
- type HTMLAttributes,
74
- type InputHTMLAttributes,
75
- type MutableRefObject,
76
- type ReactNode,
77
- type RefObject,
78
- useCallback,
79
- useContext,
80
- useEffect,
81
- useImperativeHandle,
82
- useMemo,
83
- useRef,
84
- useState,
85
- } from 'react'
86
- import { type FieldVariant, fieldIconClasses, fieldVariants, useFieldBox } from '../../../lib/field-classes'
87
- import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
88
- import { type IconComponent, useIcon } from '../../../lib/icon-context'
89
- import { MorphSurface } from '../../../lib/morph-layers'
90
- import { isDisabledRow, popupScrollAreaClass, popupViewportClass } from '../../../lib/popup'
91
- import { useReduceMotion } from '../../../lib/reduced-motion'
92
- import { shapeMap, useShape } from '../../../lib/shape-context'
93
- import { type SizeVariant, useSize } from '../../../lib/size-context'
94
- import { spring } from '../../../lib/springs'
95
- import { SURFACE_BG, SURFACE_SHADOW } from '../../../lib/surface-classes'
96
- import { SurfaceProvider, useSurface } from '../../../lib/surface-context'
97
- import { useControllableState } from '../../../lib/use-controllable-state'
98
- import { useFluidHover, useRegisterFluidHoverItem } from '../../../lib/use-fluid-hover'
99
- import { SelectionBackgrounds, useMergeSplitBlocks, useSelectionRuns } from '../../../lib/use-merge-split'
100
- import { inPlaceOffset, type MorphOrigin, opensInPlace, useMorph, useMorphOrigin } from '../../../lib/use-morph'
101
- import { cn } from '../../../lib/utils'
102
- import { ScrollArea } from '../../../primitives/scroll-area'
103
- import { SizeProvider } from '../../../primitives/sizes'
104
-
105
- // ---------------------------------------------------------------------------
106
- // Combobox
107
- //
108
- // A text field that filters a list as you type. Built on Base UI's Combobox
109
- // primitive, which owns the filtering, the combobox/listbox ARIA wiring
110
- // (aria-activedescendant — the input keeps focus while arrows move a
111
- // highlight through the rows), positioning, dismissal, and the hidden form
112
- // input. This layer keeps the fluid-hover overlays, the morph open/close
113
- // (lib/use-morph.ts), and the animated checkmark — the same visuals as
114
- // Select.
115
- //
116
- // Items are data: pass `items` to the root and render rows from the
117
- // ComboboxList function child. String items are their own value and label;
118
- // object items carry `{ value, label }` plus anything else you need.
119
- // ---------------------------------------------------------------------------
120
-
121
- /** An object item: `value` and `label`, plus whatever the rows need. */
122
- interface ComboboxItemObject {
123
- value: string
124
- /** What the row and the chip show: text, or any node with a `textValue`. */
125
- label: ReactNode
126
- /** The item as text: what the query filters and the field shows. Defaults to `label` when it is a string, else `value`. */
127
- textValue?: string
128
- [key: string]: unknown
129
- }
130
-
131
- type ComboboxItemData = string | ComboboxItemObject
132
-
133
- function itemValue(item: ComboboxItemData): string {
134
- return typeof item === 'string' ? item : item.value
135
- }
136
-
137
- /** The item as text: what filters, fills the field and names a chip. */
138
- function itemLabel(item: ComboboxItemData): string {
139
- if (typeof item === 'string') return item
140
- return item.textValue ?? (typeof item.label === 'string' ? item.label : item.value)
141
- }
8
+ 'use client'
142
9
 
143
- /** The item as shown: its label node. */
144
- function itemNode(item: ComboboxItemData): ReactNode {
145
- return typeof item === 'string' ? item : item.label
146
- }
147
-
148
- /** Every fixed word the field's buttons announce, for translating it. */
149
- interface ComboboxLabels {
150
- /** Names the chevron button. Defaults to `"Open"`. */
151
- open?: string
152
- /** Names the clear ✕ of a `clearable` field. Defaults to `"Clear"`. */
153
- clear?: string
154
- /** Names a chip's remove ✕ from the chip's text: `(label) => …`. Defaults to ``(label) => `Remove ${label}` ``. */
155
- remove?: (label: string) => string
156
- /** The fields' placeholder while nothing is typed or selected, unless a field sets its own. Defaults to `"Search…"`. */
157
- placeholder?: string
158
- }
159
-
160
- /** What `Combobox.Content`'s footer gets when it is a function. */
161
- interface ComboboxFooterContext {
162
- /** Closes the popup. */
163
- close: () => void
164
- /** The trimmed query. */
165
- query: string
166
- }
167
-
168
- /** A node, or a function of the popup's state, rendered under the list. */
169
- type ComboboxFooter = ReactNode | ((context: ComboboxFooterContext) => ReactNode)
170
-
171
- // The create row is one more item in the list the primitive filters and
172
- // highlights, so Enter and the arrows reach it like any row. Its value can't
173
- // collide with a consumer's; its label is the query it would create.
174
- const CREATE_VALUE = '\0create'
10
+ import { Combobox as ComboboxPrimitive } from '@base-ui/react/combobox'
11
+ import { type ReactNode, useCallback, useMemo, useRef, useState } from 'react'
12
+ import { useFieldState } from '../../../lib/field-box'
13
+ import { OverlayContext, useOverlayRoot } from '../../../lib/overlay'
14
+ import type { SizeVariant } from '../../../lib/size-context'
15
+ import { useControllableState } from '../../../lib/use-controllable-state'
16
+ import { SizeScope } from '../../../primitives/sizes'
17
+ import {
18
+ ComboboxContext,
19
+ ComboboxHighlightContext,
20
+ type ComboboxItemData,
21
+ type ComboboxItemObject,
22
+ type ComboboxValue,
23
+ CREATE_VALUE,
24
+ type Highlight,
25
+ isCreateItem,
26
+ itemLabel,
27
+ itemValue,
28
+ } from './context'
29
+ import { ComboboxChips, type ComboboxChipsProps, ComboboxInput, type ComboboxInputProps } from './fields'
30
+ import {
31
+ ComboboxContent,
32
+ type ComboboxContentProps,
33
+ ComboboxEmpty,
34
+ type ComboboxEmptyProps,
35
+ type ComboboxFooter,
36
+ type ComboboxFooterContext,
37
+ ComboboxItem,
38
+ type ComboboxItemProps,
39
+ ComboboxList,
40
+ type ComboboxListProps,
41
+ } from './list'
175
42
 
176
- function isCreateItem(item: ComboboxItemData): boolean {
177
- return itemValue(item) === CREATE_VALUE
178
- }
43
+ // The first row is highlighted on open and follows the query, so Enter always
44
+ // has a target. AriaCombobox accepts "always"; ComboboxRoot's prop type says boolean.
45
+ const ALWAYS_HIGHLIGHT = 'always' as unknown as boolean
179
46
 
180
47
  function defaultCreateLabel(query: string): ReactNode {
181
48
  return `Create “${query}”`
182
49
  }
183
50
 
184
- type ComboboxValue<Multiple extends boolean> = Multiple extends true ? string[] : string
185
-
186
- interface ComboboxContextValue {
187
- /** Selected values — one entry in single mode, any number in multiple. */
188
- values: string[]
189
- multiple: boolean
190
- inputValue: string
191
- open: boolean
192
- /** What opened the popup; its trigger is always the field (`anchorRef`). */
193
- origin: RefObject<MorphOrigin>
194
- /** The field (input group or chips container) the popup anchors to.
195
- * `RefObject<HTMLDivElement>` (not `… | null`) so the ref prop on Base UI's
196
- * InputGroup/Chips accepts it under @types/react 18. */
197
- anchorRef: RefObject<HTMLDivElement>
198
- disabled: boolean
199
- itemsByValue: Map<string, ComboboxItemData>
200
- /** The create row's label for the current query; null while no row is
201
- * offered. */
202
- createRow: ReactNode | null
203
- /** `hideSelected` has emptied the list with nothing typed: every item is
204
- * a chip already. */
205
- allSelected: boolean
206
- /** Local: items are on their way; the empty message waits. */
207
- loading: boolean
208
- /** Local: the loading row's text. */
209
- loadingLabel: ReactNode
210
- /** Local: shows the picks but takes no input. */
211
- readOnly: boolean
212
- /** Local: opens or closes the popup (the footer's `close`). */
213
- setOpen: (open: boolean) => void
214
- /** Local: the translated button names and default placeholder. */
215
- labels: ComboboxLabels
216
- }
217
-
218
- const NO_LABELS: ComboboxLabels = {}
219
-
220
- const ComboboxContext = createContext<ComboboxContextValue | null>(null)
221
-
222
- /** Highlighted row (the primitive's active index over the rendered rows)
223
- * and whether a keyboard/auto highlight put it there — pointer highlights
224
- * are left to fluid hover. Its own context so a per-pointer highlight
225
- * re-renders the list, not the field and every row. */
226
- interface Highlight {
227
- index: number
228
- keyboard: boolean
229
- }
230
- const ComboboxHighlightContext = createContext<Highlight | null>(null)
231
-
232
- function useComboboxContext() {
233
- const ctx = useContext(ComboboxContext)
234
- if (!ctx) throw new Error('Combobox compound components must be inside <Combobox>')
235
- return ctx
236
- }
237
-
238
- // Content context for fluid hover
239
- interface ComboboxContentContextValue {
240
- registerItem: (index: number, element: HTMLElement | null) => void
241
- activeIndex: number | null
51
+ function toValues(v: string | readonly string[] | undefined): string[] {
52
+ if (v === undefined) return []
53
+ if (Array.isArray(v)) return v as string[]
54
+ return v === '' ? [] : [v as string]
242
55
  }
243
56
 
244
- const ComboboxContentContext = createContext<ComboboxContentContextValue | null>(null)
245
-
246
- // Each rendered row learns its index from the list, so consumers never
247
- // number rows by hand.
248
- const ComboboxItemIndexContext = createContext<number>(0)
249
-
250
- // ---------------------------------------------------------------------------
251
- // Combobox (root)
252
- // ---------------------------------------------------------------------------
253
-
254
57
  interface ComboboxProps {
255
58
  /** `Combobox.Input` or `Combobox.Chips`, plus `Combobox.Content`. */
256
59
  children: ReactNode
@@ -264,31 +67,32 @@ interface ComboboxProps {
264
67
  defaultValue?: string | string[]
265
68
  /** Called with the pick, `""` when cleared, or the array when `multiple`. */
266
69
  onValueChange?: ((value: string) => void) | ((value: string[]) => void)
267
- /** Match an item against the query, or `null` to show every item as given (filtered elsewhere, e.g. on a server). Defaults to a case-insensitive "contains" on the item's text. */
70
+ /** Controlled open state. Pair with `onOpenChange`. */
71
+ open?: boolean
72
+ /** Initial open state, for an uncontrolled combobox. Defaults to `false`. */
73
+ defaultOpen?: boolean
74
+ /** Called when the list opens or closes. */
75
+ onOpenChange?: (open: boolean) => void
76
+ /** Match an item against the query, or `null` to show every item as given (filtered elsewhere, e.g. on a server). Defaults to a case-insensitive "contains" on the label. */
268
77
  filter?: ((item: ComboboxItemData, query: string) => boolean) | null
269
- /** Controlled query, the field's text. Pair it with `onInputValueChange`. */
270
- inputValue?: string
271
- /** Initial query, for an uncontrolled field. Defaults to the picked item's text in single mode, else `""`. */
272
- defaultInputValue?: string
273
- /** Called with the field's text on every keystroke, and when a pick or a close rewrites it. The second argument is Base UI's change details: `reason` tells typing (`"input-change"`) from a pick, a clear or a close rewriting the text (`"item-press"`, `"clear-press"`, `"none"`, …). */
274
- onInputValueChange?: (inputValue: string, details: ComboboxRootChangeEventDetails) => void
275
- /** Items are loading: the chevron turns into a spinner, a status row sits under the list and the empty message waits. Defaults to `false`. */
78
+ /** Controlled query, the field's text. Pair with `onQueryChange`. */
79
+ query?: string
80
+ /** Initial query, for an uncontrolled field. Defaults to `""`. */
81
+ defaultQuery?: string
82
+ /** Called with the field's text on every keystroke, and when a pick, a clear or a close rewrites it. */
83
+ onQueryChange?: (query: string) => void
84
+ /** Items are on their way: the chevron turns into a spinner, a status row is pinned under the scrolling rows (announced, in sight however long the list) and the empty message waits. Defaults to `false`. */
276
85
  loading?: boolean
277
86
  /** The loading row's text. Defaults to `"Loading…"`. */
278
87
  loadingLabel?: ReactNode
279
88
  /** Shows the picks but takes no input: the popup stays shut and the clear ✕ and chip ✕ go. Defaults to `false`. */
280
89
  readOnly?: boolean
281
- /** Controlled open state of the popup. Pair it with `onOpenChange`. */
282
- open?: boolean
283
- /** Initial open state, for an uncontrolled popup. Defaults to `false`. */
284
- defaultOpen?: boolean
285
- /** Called when the popup opens or closes. */
286
- onOpenChange?: (open: boolean) => void
287
90
  /** Adds a last row that creates the trimmed query whenever no label matches it exactly. Add the item to `items` and return it to select it. */
91
+ // biome-ignore lint/suspicious/noConfusingVoidType: upstream API; a callback may return nothing.
288
92
  onCreate?: (query: string) => ComboboxItemData | void
289
93
  /** The create row's label. Defaults to ``(query) => `Create “${query}”` ``. */
290
94
  createLabel?: (query: string) => ReactNode
291
- /** Local addition: offer the create row with no callback — the component keeps the items it makes, so nothing outside has to hold the list. Defaults to `false`. */
95
+ /** Offer the create row with no callback — the component keeps the items it makes, so nothing outside has to hold the list. Defaults to `false`. */
292
96
  creatable?: boolean
293
97
  /** Multiple only. Picked items leave the list, so it reads as what is left to add. Deselect from the chips. Defaults to `false`. */
294
98
  hideSelected?: boolean
@@ -300,14 +104,6 @@ interface ComboboxProps {
300
104
  required?: boolean
301
105
  /** Pins field and popup to one step of the size ladder (default 36px, compact 28px — see the Sizes primitive). Omitted, both follow the surrounding SizeProvider. */
302
106
  size?: SizeVariant
303
- /** Every fixed word the field's buttons announce (`open`, `clear`, `remove`, `placeholder`), for translating it. Defaults to English: `"Open"`, `"Clear"`, `"Remove …"`, `"Search…"`. */
304
- labels?: ComboboxLabels
305
- }
306
-
307
- function toValues(v: string | readonly string[] | undefined): string[] {
308
- if (v === undefined) return []
309
- if (Array.isArray(v)) return v as string[]
310
- return v === '' ? [] : [v as string]
311
107
  }
312
108
 
313
109
  /**
@@ -318,37 +114,39 @@ function toValues(v: string | readonly string[] | undefined): string[] {
318
114
  * renders one `Combobox.Item` per match, so the filtering, the ARIA wiring
319
115
  * (the input keeps focus while the arrows move a highlight through the rows),
320
116
  * the positioning and the hidden form input stay with Base UI. On top of that
321
- * sit the fluid-hover highlight, the merged selection background of
322
- * `Checkbox.Group`, and a list that oozes out of the field and back through the
323
- * shared morph (see Morph), goo by default. `multiple` turns the picks into a
324
- * `string[]` and pairs with `Combobox.Chips`: one chip per pick, Backspace in
325
- * an empty field drops the last one. Uncontrolled with `defaultValue`, or
326
- * controlled with `value` plus `onValueChange`.
117
+ * sit Select's rows — the fluid-hover highlight, a selected background that
118
+ * melts between rows, the drawn check — the merged selection background of
119
+ * `Checkbox.Group` in multiple mode, and a list that oozes out of the field and
120
+ * back through the shared morph (see Morph), goo by default. `multiple` turns
121
+ * the picks into a `string[]` and pairs with `Combobox.Chips`: one chip per
122
+ * pick, Backspace in an empty field drops the last one. Uncontrolled with
123
+ * `defaultValue` and `defaultOpen`, or controlled with `value` plus
124
+ * `onValueChange` and `open` plus `onOpenChange`.
327
125
  *
328
126
  * For items that come from elsewhere (a server, a paged API), own the query
329
- * with `inputValue` + `onInputValueChange`, pass `filter={null}` so the list
330
- * shows exactly the items you hand it, and set `loading` while they are on
331
- * their way: the chevron blurs into a spinner and a status row sits under
332
- * the list instead of the empty message. `Combobox.Content`'s `footer` pins
333
- * an action under the list ("Load more", "Add new…"). An object item's
334
- * `label` may be any node; its `textValue` is what filters, fills the field
335
- * and names its chip. `readOnly` shows the picks and takes no input. Inside a
336
- * Field the fields take its invalid state, like Input does, and `hideTrigger`
337
- * drops the chevron (and with it the loading spinner; the popup's status row is then the only loading signal) for a field that opens by typing. The words the buttons
338
- * announce ("Open", "Clear", "Remove …") and the default "Search…" placeholder
339
- * come from `labels`, for translating them.
127
+ * with `query` + `onQueryChange`, pass `filter={null}` so the list shows
128
+ * exactly the items you hand it, and set `loading` while they are on their
129
+ * way: the chevron blurs into a spinner and a status row, pinned under the
130
+ * scrolling rows so a long stale list can't hide it, stands in for the empty
131
+ * message. `Combobox.Content`'s `footer` pins an action under the list ("Load
132
+ * more", "Add new…"); a press on it leaves focus and the caret in the input,
133
+ * and Tab still reaches it from the keyboard. `readOnly` shows the picks and
134
+ * takes no input. A row's label may be any node (an avatar and a name); it
135
+ * keeps its own box, where text is trimmed and truncated.
340
136
  *
341
137
  * Statics:
342
- * - `Combobox.Input` — the single-pick field: icon, text input, clear ✕, chevron (`hideTrigger` drops it); `invalid` or `error` turn it destructive, as a surrounding Field's invalid state does.
343
- * - `Combobox.Chips` — the multiple field: one chip per pick ahead of the input, with the same `hideTrigger`, `invalid` and `error`.
138
+ * - `Combobox.Input` — the single-pick field: icon, text input, clear ✕, chevron.
139
+ * - `Combobox.Chips` — the multiple field: one chip per pick ahead of the input.
344
140
  * - `Combobox.Content` — the popup surface, holding `Combobox.Empty` and `Combobox.List`:
345
- * `side`, `align`, `sideOffset`, a `footer` under the list, and the morph options
141
+ * `side`, `align`, `sideOffset`, `container`, a `footer` under the list, and the morph options
346
142
  * `from`, `effect`, `hideSource`, `tier`.
347
143
  * - `Combobox.List` — a row per match, from a `(item, index) => ReactNode` child.
348
144
  * - `Combobox.Item` — one row: `value`, optional `icon` and `disabled`.
349
145
  * - `Combobox.Empty` — what shows when nothing matches.
350
146
  *
351
147
  * @example {@include ./examples.mdx}
148
+ * @source https://github.com/mickadesign/fluid-functionalism/blob/b3587bdbd83fc66c2a6aae3817ffb856cb09260b/registry/base/combobox.tsx Fluid Functionalism
149
+ * @license MIT © 2026 Micka Touillaud
352
150
  */
353
151
  function Combobox({
354
152
  children,
@@ -357,57 +155,49 @@ function Combobox({
357
155
  value,
358
156
  defaultValue,
359
157
  onValueChange,
158
+ open,
159
+ defaultOpen,
160
+ onOpenChange,
360
161
  filter,
162
+ query: queryProp,
163
+ defaultQuery = '',
164
+ onQueryChange,
165
+ loading = false,
166
+ loadingLabel = 'Loading…',
167
+ readOnly: readOnlyProp,
361
168
  onCreate,
362
169
  createLabel = defaultCreateLabel,
363
170
  creatable = false,
364
171
  hideSelected = false,
365
- disabled = false,
172
+ disabled: disabledProp,
366
173
  name,
367
- required,
368
- inputValue: inputValueProp,
369
- defaultInputValue,
370
- onInputValueChange,
371
- labels,
372
- loading = false,
373
- loadingLabel = 'Loading…',
374
- readOnly = false,
375
- open: openProp,
376
- defaultOpen = false,
377
- onOpenChange,
174
+ required: requiredProp,
378
175
  size,
379
176
  }: ComboboxProps) {
177
+ const { disabled, readOnly, required } = useFieldState({
178
+ disabled: disabledProp,
179
+ readOnly: readOnlyProp,
180
+ required: requiredProp,
181
+ })
380
182
  const isMultiple = !!multiple
381
- const [internalValues, setInternalValues] = useState<string[]>(() => toValues(defaultValue))
382
- // The primitive's change details ride along to the caller's handler: the setter below drops no-op
383
- // writes, so the details are parked in a ref the handler reads when the write goes through.
384
- const inputDetails = useRef<ComboboxRootChangeEventDetails | undefined>(undefined)
385
- const [inputValue, setInputValue] = useControllableState(inputValueProp, defaultInputValue ?? '', next =>
386
- onInputValueChange?.(next, inputDetails.current as ComboboxRootChangeEventDetails),
387
- )
388
- const [open, setOpen] = useControllableState(openProp, defaultOpen, onOpenChange)
183
+ // Memoized on the prop: a consumer's array is state, so everything keyed on it changes only with the selection.
184
+ const controlledValues = useMemo(() => (value === undefined ? undefined : toValues(value)), [value])
185
+ const [values, setValues] = useControllableState<string[]>(controlledValues, toValues(defaultValue))
186
+ // Base UI owns the field's text unless the caller does; this mirrors it either way.
187
+ const [inputValue, setInputValue] = useControllableState(queryProp, defaultQuery, onQueryChange)
389
188
  const [highlight, setHighlight] = useState<Highlight | null>(null)
390
189
  // Items the create row made while no consumer owns the list.
391
190
  const [createdItems, setCreatedItems] = useState<ComboboxItemData[]>([])
392
- const { origin, capture } = useMorphOrigin()
191
+ const root = useOverlayRoot({ open, defaultOpen, onOpenChange })
393
192
  const anchorRef = useRef<HTMLDivElement | null>(null)
394
- // Memoized on the prop identity: a string value is stable by nature and a
395
- // consumer's array is state, so the derived array (and everything keyed on
396
- // it) only changes when the selection does.
397
- const controlledValues = useMemo(() => toValues(value), [value])
398
- const values = value !== undefined ? controlledValues : internalValues
399
193
 
400
- // The consumer's items plus anything `creatable` made here. A consumer that
401
- // adds a created item to `items` itself wins — the internal copy is deduped
402
- // away, so the two modes never double a row.
194
+ // A consumer that adds a created item to `items` itself wins: the internal copy is deduped away.
403
195
  const allItems = useMemo<readonly ComboboxItemData[]>(() => {
404
196
  const own = createdItems.filter(made => !items.some(item => itemValue(item) === itemValue(made)))
405
197
  return own.length ? [...items, ...own] : items
406
198
  }, [items, createdItems])
407
199
 
408
- // The query the primitive filters on: the trimmed input. In single mode
409
- // the field shows the selected label on open, which is an exact match, so
410
- // no create row appears until the user types past it.
200
+ // A single field shows the picked label on open, an exact match, so no create row until the user types past it.
411
201
  const query = inputValue.trim()
412
202
  const canCreate = !!onCreate || creatable
413
203
  const createItem = useMemo<ComboboxItemData | null>(() => {
@@ -420,8 +210,6 @@ function Combobox({
420
210
  const itemsByValue = useMemo(() => {
421
211
  const map = new Map<string, ComboboxItemData>()
422
212
  for (const item of allItems) map.set(itemValue(item), item)
423
- // Rows hand the primitive the item they were rendered from; the create
424
- // row's carries the query it stands for.
425
213
  if (createItem) map.set(CREATE_VALUE, createItem)
426
214
  return map
427
215
  }, [allItems, createItem])
@@ -430,9 +218,7 @@ function Combobox({
430
218
  [values, itemsByValue],
431
219
  )
432
220
 
433
- // What the list shows: the items less the chips when `hideSelected`, plus
434
- // the create row last, so Enter picks a real match while one exists and
435
- // only creates once nothing matches.
221
+ // The create row goes last, so Enter picks a real match while one exists.
436
222
  const hideChecked = hideSelected && isMultiple
437
223
  const listItems = useMemo<readonly ComboboxItemData[]>(() => {
438
224
  const visible = hideChecked ? allItems.filter(item => !values.includes(itemValue(item))) : allItems
@@ -440,9 +226,7 @@ function Combobox({
440
226
  }, [allItems, hideChecked, values, createItem])
441
227
  const allSelected = hideChecked && query === '' && allItems.length > 0 && listItems.length === 0
442
228
 
443
- // Base UI hands back the item(s); the public API speaks in values. A pick
444
- // on the create row is not a selection: it asks the consumer for the item,
445
- // and selects whatever comes back.
229
+ // A pick on the create row is not a selection: it asks for the item and selects what comes back.
446
230
  const onCreateRef = useRef(onCreate)
447
231
  onCreateRef.current = onCreate
448
232
  const handleValueChange = useCallback(
@@ -456,29 +240,24 @@ function Combobox({
456
240
  if (made !== undefined) {
457
241
  nextValues = [...nextValues, itemValue(made)]
458
242
  } else if (creatable) {
459
- // No consumer owns the list, so the item is made and kept here: the
460
- // row it adds is indistinguishable from a real one.
461
243
  const own: ComboboxItemData = { value: madeQuery, label: madeQuery }
462
244
  setCreatedItems(prev => (prev.some(item => itemValue(item) === madeQuery) ? prev : [...prev, own]))
463
245
  nextValues = [...nextValues, madeQuery]
464
246
  } else if (!isMultiple) {
465
- // Nothing to select: a single field keeps its pick.
466
247
  return
467
248
  }
468
249
  }
469
- if (value === undefined) setInternalValues(nextValues)
250
+ setValues(nextValues)
470
251
  ;(onValueChange as ((value: string | string[]) => void) | undefined)?.(
471
252
  isMultiple ? nextValues : (nextValues[0] ?? ''),
472
253
  )
473
254
  },
474
- [value, onValueChange, isMultiple, creatable],
255
+ [onValueChange, isMultiple, creatable, setValues],
475
256
  )
476
257
 
477
- // The create row must survive the filter that hides every other miss.
478
- // Without a consumer filter the primitive's own collator match is kept.
258
+ // The create row survives the filter that hides every other miss.
479
259
  const { contains } = ComboboxPrimitive.useFilter()
480
260
  const filterFn = useMemo(() => {
481
- // `null`: the caller filters; the list shows what it is handed.
482
261
  if (filter === null) return null
483
262
  if (!filter && !createItem) return undefined
484
263
  const match = filter
@@ -488,13 +267,13 @@ function Combobox({
488
267
  }, [filter, createItem, contains])
489
268
 
490
269
  const createRow = createItem ? createLabel(query) : null
270
+ const { setOpen } = root
271
+ const close = useCallback(() => setOpen(false), [setOpen])
491
272
  const ctx = useMemo(
492
273
  () => ({
493
274
  values,
494
275
  multiple: isMultiple,
495
276
  inputValue,
496
- open,
497
- origin,
498
277
  anchorRef,
499
278
  disabled,
500
279
  itemsByValue,
@@ -503,15 +282,12 @@ function Combobox({
503
282
  loading,
504
283
  loadingLabel,
505
284
  readOnly,
506
- setOpen,
507
- labels: labels ?? NO_LABELS,
285
+ close,
508
286
  }),
509
287
  [
510
288
  values,
511
289
  isMultiple,
512
290
  inputValue,
513
- open,
514
- origin,
515
291
  disabled,
516
292
  itemsByValue,
517
293
  createRow,
@@ -519,973 +295,56 @@ function Combobox({
519
295
  loading,
520
296
  loadingLabel,
521
297
  readOnly,
522
- setOpen,
523
- labels,
298
+ close,
524
299
  ],
525
300
  )
526
301
 
527
- // A size prop pins the whole compound (field + portalled popup — React
528
- // context crosses portals) to one step of the ladder.
529
- const root = (
530
- <ComboboxContext.Provider value={ctx}>
531
- <ComboboxHighlightContext.Provider value={highlight}>
532
- <ComboboxPrimitive.Root
533
- items={listItems}
534
- multiple={isMultiple}
535
- // Always controlled; "" (no selection) maps to Base UI's null. The
536
- // value shape follows `multiple`, which the primitive's generics
537
- // can't express from a boolean prop — hence the cast.
538
- value={(isMultiple ? selectedItems : (selectedItems[0] ?? null)) as never}
539
- onValueChange={handleValueChange as never}
540
- isItemEqualToValue={(a: ComboboxItemData, b: ComboboxItemData) => itemValue(a) === itemValue(b)}
541
- itemToStringLabel={itemLabel}
542
- itemToStringValue={itemValue}
543
- filter={filterFn}
544
- open={open}
545
- onOpenChange={(next, details) => {
546
- // The list grows out of the field, whichever part opened it.
547
- if (next) capture({ event: details.event, trigger: anchorRef.current ?? undefined })
548
- setOpen(next)
549
- }}
550
- // Controlled only when the caller owns the query; otherwise Base UI
551
- // keeps it and this mirrors it.
552
- inputValue={inputValueProp}
553
- defaultInputValue={defaultInputValue}
554
- onInputValueChange={(next, details) => {
555
- inputDetails.current = details
556
- setInputValue(next)
557
- }}
558
- autoHighlight={ALWAYS_HIGHLIGHT}
559
- onItemHighlighted={(item, details) =>
560
- setHighlight(item === undefined ? null : { index: details.index, keyboard: details.reason !== 'pointer' })
561
- }
562
- disabled={disabled}
563
- readOnly={readOnly}
564
- name={name}
565
- required={required}
566
- // Non-modal: the page keeps scrolling and the Positioner tracks the
567
- // anchor, so the popup follows its field instead of detaching.
568
- modal={false}
569
- >
570
- {children}
571
- </ComboboxPrimitive.Root>
572
- </ComboboxHighlightContext.Provider>
573
- </ComboboxContext.Provider>
574
- )
575
-
576
- return size ? <SizeProvider size={size}>{root}</SizeProvider> : root
577
- }
578
-
579
- Combobox.displayName = 'Combobox'
580
-
581
- // ---------------------------------------------------------------------------
582
- // ComboboxInput — the field: leading icon, text input, clear ✕, chevron.
583
- // ---------------------------------------------------------------------------
584
-
585
- // The field follows the global pill/rounded shape; the popup does not. Like
586
- // Dropdown, the list keeps the smaller "rounded" radii whatever the rest of
587
- // the UI is shaped: pill corners on a popover distort its padding and break
588
- // the concentric fit of the rows' hover and selection backgrounds inside it.
589
- const popupShape = shapeMap.rounded
590
-
591
- // The first row is highlighted the moment the list opens and follows the
592
- // query as it filters, so Enter always has a target. AriaCombobox accepts
593
- // "always" for this; ComboboxRoot's prop type still says boolean.
594
- const ALWAYS_HIGHLIGHT = 'always' as unknown as boolean
595
-
596
- // The clear and chevron buttons share one quiet style; they sit inside the
597
- // field's ring so they need no frame of their own.
598
- const fieldButtonClass =
599
- 'flex shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors duration-fast hover:text-foreground focus-visible:ring-1 focus-visible:ring-focus-ring data-[disabled]:pointer-events-none'
600
- // The clear ✕ is a real icon button: the hover fill says "press me", where
601
- // the chevron beside it only decorates the field it belongs to.
602
- const clearButtonClass = cn(fieldButtonClass, 'hover:bg-hover active:bg-active transition-[color,background-color]')
603
- // A chip's ✕ sits on the chip's own hover-tinted fill, so it steps up a notch.
604
- const chipRemoveClass = cn(fieldButtonClass, 'rounded hover:bg-active')
605
-
606
- interface ComboboxFieldProps
607
- extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'value' | 'defaultValue' | 'onChange'> {
608
- /** Framed at rest, or invisible until hovered or focused. Defaults to `"bordered"`. */
609
- variant?: FieldVariant
610
- /** Leading icon inside the field. */
611
- icon?: IconComponent
612
- /** Shown while nothing is typed or selected. Defaults to `labels.placeholder` on the root, else `"Search…"`. */
613
- placeholder?: string
614
- /** Error message under the field; tints the ring and sets `aria-invalid`. */
615
- error?: string
616
- /** Marks the value invalid without a message: the field turns destructive and sets `aria-invalid`. Defaults to the surrounding Field's invalid state. */
617
- invalid?: boolean
618
- /** Hides the chevron button, for a field that opens by typing or arrow keys alone. It also drops the loading spinner, which lives in that button, so the popup's status row is the only loading signal. Defaults to `false`. */
619
- hideTrigger?: boolean
620
- /** Render a ✕ that clears the selection and query. Its slot is always
621
- * reserved so the field never changes width. Defaults to `false`. */
622
- clearable?: boolean
623
- /** Size override for the field alone. Prefer the `size` prop on <Combobox>
624
- * (or a surrounding SizeProvider) so the popup matches. */
625
- size?: SizeVariant
626
- }
627
-
628
- type ComboboxInputProps = ComboboxFieldProps
629
-
630
- // Icon swap (motion.md): the chevron and the spinner share one cell.
631
- const SHOWN = { opacity: 1, scale: 1, filter: 'blur(0px)' }
632
- const HIDDEN = { opacity: 0, scale: 0.6, filter: 'blur(4px)' }
633
- const swapEnter = { type: 'tween' as const, duration: spring.fast.duration, ease: 'easeOut' as const }
634
- const swapLeave = { type: 'tween' as const, ...spring.fast.exit, ease: 'easeIn' as const }
635
-
636
- /** The trailing clear ✕ and chevron, shared by both fields. */
637
- function FieldControls({
638
- clearable,
639
- hideTrigger,
640
- compact,
641
- iconSize,
642
- }: {
643
- clearable: boolean
644
- hideTrigger: boolean
645
- compact: boolean
646
- iconSize: number
647
- }) {
648
- const XIcon = useIcon('x')
649
- const Loader = useIcon('loader-circle')
650
- const pill = useShape().variant === 'pill'
651
- const { loading, readOnly, labels } = useComboboxContext()
652
- const reduced = useReduceMotion()
653
- const swap = (shown: boolean) => (reduced ? { opacity: shown ? 1 : 0 } : shown ? SHOWN : HIDDEN)
654
302
  return (
655
- <>
656
- {clearable && !readOnly && (
657
- // The primitive hides the button while there is nothing to clear; a
658
- // fixed slot keeps the field's width steady either way.
659
- <span className={cn('flex shrink-0 items-center justify-center', compact ? 'size-5' : 'size-6')}>
660
- <ComboboxPrimitive.Clear
661
- aria-label={labels.clear ?? 'Clear'}
662
- className={cn(clearButtonClass, pill && 'rounded-full', compact ? 'size-5' : 'size-6')}
663
- >
664
- <XIcon size={iconSize} strokeWidth={1.5} />
665
- </ComboboxPrimitive.Clear>
666
- </span>
667
- )}
668
- {/* Not a tab stop: the field itself opens on ArrowDown or typing. */}
669
- {!hideTrigger && (
670
- <ComboboxPrimitive.Trigger
671
- aria-label={labels.open ?? 'Open'}
672
- tabIndex={-1}
673
- className={cn(fieldButtonClass, compact ? 'size-5' : 'size-6')}
674
- >
675
- {/* While loading, the chevron blurs into a spinner in the same cell. */}
676
- <span className="grid" style={{ width: iconSize, height: iconSize }}>
677
- <motion.span
678
- className="col-start-1 row-start-1 flex"
679
- initial={false}
680
- animate={swap(!loading)}
681
- transition={loading ? swapLeave : swapEnter}
682
- >
683
- <svg
684
- width={iconSize}
685
- height={iconSize}
686
- viewBox="0 0 24 24"
687
- fill="none"
688
- stroke="currentColor"
689
- strokeWidth={2}
690
- strokeLinecap="round"
691
- strokeLinejoin="round"
692
- className={cn('transition-colors duration-fast', readOnly && 'invisible')}
693
- >
694
- <path d="M6 9l6 6 6-6" />
695
- </svg>
696
- </motion.span>
697
- <motion.span
698
- aria-hidden
699
- className="col-start-1 row-start-1 flex"
700
- initial={false}
701
- animate={swap(loading)}
702
- transition={loading ? swapEnter : swapLeave}
303
+ <SizeScope size={size}>
304
+ <ComboboxContext.Provider value={ctx}>
305
+ <OverlayContext.Provider value={root.state}>
306
+ <ComboboxHighlightContext.Provider value={highlight}>
307
+ {/* Non-modal: the page keeps scrolling and the popup follows its field. */}
308
+ <ComboboxPrimitive.Root
309
+ items={listItems}
310
+ multiple={isMultiple}
311
+ // "" maps to Base UI's null. The value's shape follows `multiple`, which the generics can't express.
312
+ value={(isMultiple ? selectedItems : (selectedItems[0] ?? null)) as never}
313
+ onValueChange={handleValueChange as never}
314
+ isItemEqualToValue={(a: ComboboxItemData, b: ComboboxItemData) => itemValue(a) === itemValue(b)}
315
+ itemToStringLabel={itemLabel}
316
+ itemToStringValue={itemValue}
317
+ filter={filterFn}
318
+ open={root.open}
319
+ // The list grows out of the field, whichever part opened it.
320
+ onOpenChange={(next, details) =>
321
+ root.onOpenChange(next, { event: details.event, trigger: anchorRef.current ?? undefined })
322
+ }
323
+ inputValue={queryProp}
324
+ defaultInputValue={defaultQuery}
325
+ onInputValueChange={next => setInputValue(next)}
326
+ autoHighlight={ALWAYS_HIGHLIGHT}
327
+ onItemHighlighted={(item, details) =>
328
+ setHighlight(
329
+ item === undefined ? null : { index: details.index, keyboard: details.reason !== 'pointer' },
330
+ )
331
+ }
332
+ disabled={disabled}
333
+ readOnly={readOnly}
334
+ name={name}
335
+ required={required}
336
+ modal={false}
703
337
  >
704
- <Loader size={iconSize} strokeWidth={1.5} className="animate-spin motion-reduce:animate-none" />
705
- </motion.span>
706
- </span>
707
- </ComboboxPrimitive.Trigger>
708
- )}
709
- </>
710
- )
711
- }
712
-
713
- const ComboboxInput = forwardRef<HTMLInputElement, ComboboxInputProps>(
714
- (
715
- {
716
- className,
717
- variant = 'bordered',
718
- icon: Icon,
719
- placeholder,
720
- error,
721
- invalid,
722
- hideTrigger = false,
723
- clearable = false,
724
- size,
725
- ...props
726
- },
727
- ref,
728
- ) => {
729
- const { anchorRef, readOnly, labels } = useComboboxContext()
730
- // `error` forces the destructive state; otherwise the prop, then a surrounding Field's.
731
- const box = useFieldBox({ variant, invalid: error ? true : invalid, readOnly, size })
732
- const { size: sizeClasses, props: boxProps } = box
733
- const compact = sizeClasses.variant === 'compact'
734
-
735
- return (
736
- <div className="flex flex-col gap-1">
737
- {/* The group is the popup's anchor, so the list spans the whole
738
- field (icon to chevron), not just the text input. */}
739
- <ComboboxPrimitive.InputGroup
740
- ref={anchorRef}
741
- {...boxProps}
742
- className={cn(
743
- boxProps.className,
744
- 'flex items-center',
745
- sizeClasses.control,
746
- sizeClasses.gap,
747
- compact ? 'min-w-[128px]' : 'min-w-[160px]',
748
- className,
749
- )}
750
- >
751
- {Icon && <Icon size={sizeClasses.icon} strokeWidth={1.5} className={fieldIconClasses} />}
752
- <ComboboxPrimitive.Input
753
- ref={ref}
754
- placeholder={placeholder ?? labels.placeholder ?? 'Search…'}
755
- aria-invalid={box.invalid || undefined}
756
- className={cn(
757
- 'min-w-0 flex-1 rounded-none bg-transparent text-foreground placeholder:text-muted-foreground outline-none font-[inherit]',
758
- sizeClasses.text,
759
- // The caret is as tall as the line box (Chrome, Safari); the
760
- // ladder's leading keeps it in proportion to the field.
761
- compact ? 'leading-5' : 'leading-6',
762
- )}
763
- {...props}
764
- />
765
- <FieldControls
766
- clearable={clearable}
767
- hideTrigger={hideTrigger}
768
- compact={compact}
769
- iconSize={sizeClasses.icon}
770
- />
771
- </ComboboxPrimitive.InputGroup>
772
- {error && <span className="text-caption text-destructive pl-3">{error}</span>}
773
- </div>
774
- )
775
- },
776
- )
777
-
778
- ComboboxInput.displayName = 'ComboboxInput'
779
-
780
- // ---------------------------------------------------------------------------
781
- // ComboboxChips — the multiple-selection field: one chip per selected item
782
- // ahead of the text input, wrapping onto new lines as they accumulate.
783
- // Backspace in an empty input removes the last chip; ArrowLeft walks into
784
- // the chips, where Backspace/Delete removes the focused one.
785
- // ---------------------------------------------------------------------------
786
-
787
- type ComboboxChipsProps = ComboboxFieldProps
788
-
789
- /** Springs the chips field's height to the measured chip row stack (plus
790
- * `padY`, the field's vertical padding) as chips wrap and unwrap. The
791
- * height lives in a MotionValue driving an inline style, and for a reason:
792
- * the field must stay pinned at its old height through the reflow that
793
- * wraps a chip, or its auto height lands on the new row before any spring
794
- * can start and the growth snaps. First measure sets the pin; every later
795
- * one springs it. Measured (offsetHeight + ResizeObserver), never
796
- * `height: "auto"`: framer resolves "auto" from the element's *visual*
797
- * (transformed) size, so under a scaled ancestor (the /demo card) the
798
- * spring would overshoot. Layout metrics are transform-immune. */
799
- function useChipRowHeight(padY: number) {
800
- const height = useMotionValue<number | 'auto'>('auto')
801
- const roRef = useRef<ResizeObserver | null>(null)
802
- const padRef = useRef(padY)
803
- padRef.current = padY
804
- const ref = useCallback(
805
- (el: HTMLDivElement | null) => {
806
- roRef.current?.disconnect()
807
- roRef.current = null
808
- if (!el) return
809
- const measure = () => {
810
- if (el.offsetHeight <= 0) return
811
- const target = el.offsetHeight + padRef.current
812
- if (height.get() === 'auto') height.set(target)
813
- else if (height.get() !== target) animate(height, target, spring.fast)
814
- }
815
- measure()
816
- const ro = new ResizeObserver(measure)
817
- ro.observe(el)
818
- roRef.current = ro
819
- },
820
- [height],
821
- )
822
- return { ref, height }
823
- }
824
-
825
- const ComboboxChips = forwardRef<HTMLInputElement, ComboboxChipsProps>(
826
- (
827
- {
828
- className,
829
- variant = 'bordered',
830
- icon: Icon,
831
- placeholder,
832
- error,
833
- invalid,
834
- hideTrigger = false,
835
- clearable = false,
836
- size,
837
- ...props
838
- },
839
- ref,
840
- ) => {
841
- const XIcon = useIcon('x')
842
- const shape = useShape()
843
- const { anchorRef, open, disabled, inputValue, values, readOnly, labels } = useComboboxContext()
844
- const box = useFieldBox({ variant, invalid: error ? true : invalid, disabled, readOnly, size })
845
- const { size: sizeClasses, props: boxProps } = box
846
- const compact = sizeClasses.variant === 'compact'
847
- const rowHeight = useChipRowHeight(compact ? 8 : 12)
848
-
849
- return (
850
- <div className="flex flex-col gap-1">
851
- <ComboboxPrimitive.Chips
852
- ref={anchorRef}
853
- // The field springs to the chip rows' measured height as they
854
- // wrap and unwrap, instead of snapping a row taller or shorter.
855
- render={<motion.div style={{ height: rowHeight.height }} />}
856
- // Chips stamps no state attributes of its own (InputGroup does);
857
- // the field ladder (`lib/field-classes.ts`) and the chevron read these.
858
- {...boxProps}
859
- data-popup-open={open || undefined}
860
- className={cn(
861
- boxProps.className,
862
- 'flex items-center',
863
- // The spring above owns the height; leaving it in transition-all
864
- // would have the 80ms CSS ease drag behind every spring frame.
865
- 'transition-[color,background-color,border-radius,box-shadow,opacity]',
866
- // Grows with its chips. Rows top-align (`items-start`) so the
867
- // icon and controls hold the first line while chips wrap; the
868
- // vertical padding is exactly what centers one 24px (20px
869
- // compact) row inside the ladder height.
870
- '!items-start',
871
- compact ? 'min-h-7 py-1' : 'min-h-9 py-1.5',
872
- sizeClasses.gap,
873
- compact ? 'min-w-[128px]' : 'min-w-[160px]',
874
- className,
875
- )}
876
- >
877
- {Icon && (
878
- // A row-height box keeps the icon centered on the first line.
879
- <span className={cn('flex shrink-0 items-center', compact ? 'h-5' : 'h-6')}>
880
- <Icon size={sizeClasses.icon} strokeWidth={1.5} className={fieldIconClasses} />
881
- </span>
882
- )}
883
- <div
884
- ref={rowHeight.ref}
885
- className={cn(
886
- 'relative flex min-w-0 flex-1 flex-wrap items-center gap-1',
887
- // A chip leads the field: the row pulls left so the chip sits
888
- // an even distance from every edge. The offset lives here, not
889
- // on the container's padding — the container's transition-all
890
- // would ease a padding change against the chip's spring and
891
- // drag the caret with it; the row snaps instead, in the same
892
- // frame as the chip. An icon keeps the full inset — it leads,
893
- // not the chip.
894
- !Icon && values.length > 0 && '-ml-1',
895
- )}
896
- >
897
- <ComboboxPrimitive.Value>
898
- {(selected: ComboboxItemData[] | null) => (
899
- <>
900
- {/* Chips pop in and out on the fast tier and slide into
901
- their new slots; an exiting chip is inert while it
902
- fades, since the primitive has already dropped it.
903
- popLayout lifts the exiting chip out of the flow at
904
- once, so the field reflows immediately rather than
905
- after the fade. */}
906
- <AnimatePresence initial={false} mode="popLayout">
907
- {(selected ?? []).map(item => {
908
- const label = itemLabel(item)
909
- return (
910
- <motion.span
911
- key={itemValue(item)}
912
- layout
913
- initial={{ opacity: 0, scale: 0.9 }}
914
- animate={{ opacity: 1, scale: 1 }}
915
- exit={{
916
- opacity: 0,
917
- scale: 0.9,
918
- pointerEvents: 'none',
919
- transition: spring.fast.exit,
920
- }}
921
- transition={spring.fast}
922
- // Grow from the left edge, where the typed text
923
- // just was — not from the middle of the chip.
924
- style={{ originX: 0 }}
925
- className="inline-flex max-w-full shrink-0"
926
- >
927
- <ComboboxPrimitive.Chip
928
- aria-label={label}
929
- className={cn(
930
- 'inline-flex max-w-full shrink-0 items-center gap-0.5 bg-hover pl-2 pr-0.5 text-foreground outline-none',
931
- shape.variant === 'pill' ? 'rounded-full' : 'rounded-md',
932
- 'focus-visible:ring-1 focus-visible:ring-focus-ring',
933
- compact ? 'h-5 text-caption-compact' : 'h-6 text-caption',
934
- )}
935
- >
936
- <span
937
- className={cn(
938
- typeof itemNode(item) === 'string' ? 'truncate' : 'flex min-w-0 items-center',
939
- readOnly && 'pr-1.5',
940
- )}
941
- >
942
- {itemNode(item)}
943
- </span>
944
- {!readOnly && (
945
- <ComboboxPrimitive.ChipRemove
946
- aria-label={labels.remove ? labels.remove(label) : `Remove ${label}`}
947
- className={cn(
948
- chipRemoveClass,
949
- shape.variant === 'pill' && 'rounded-full',
950
- compact ? 'size-4' : 'size-5',
951
- )}
952
- >
953
- <XIcon size={compact ? 10 : 12} strokeWidth={2} />
954
- </ComboboxPrimitive.ChipRemove>
955
- )}
956
- </ComboboxPrimitive.Chip>
957
- </motion.span>
958
- )
959
- })}
960
- </AnimatePresence>
961
- {/* The field sizes to what is typed (`size` is the
962
- intrinsic width; flex-auto grows it across the rest
963
- of its row) so it stays beside the chips while it
964
- fits and wraps only once the text no longer does.
965
- It never animates: chips slide, the field snaps.
966
- Animating it read as the placeholder sliding in from
967
- the right when the last chip went. */}
968
- <span className="flex min-w-6 flex-auto">
969
- <ComboboxPrimitive.Input
970
- ref={ref}
971
- size={Math.max(1, inputValue.length + 1)}
972
- placeholder={selected?.length ? undefined : (placeholder ?? labels.placeholder ?? 'Search…')}
973
- aria-invalid={box.invalid || undefined}
974
- className={cn(
975
- 'w-full min-w-0 rounded-none bg-transparent text-foreground placeholder:text-muted-foreground outline-none font-[inherit]',
976
- // Line box = row height, so the caret spans the chip row.
977
- compact ? 'h-5 leading-5' : 'h-6 leading-6',
978
- sizeClasses.text,
979
- )}
980
- {...props}
981
- />
982
- </span>
983
- </>
984
- )}
985
- </ComboboxPrimitive.Value>
986
- </div>
987
- <FieldControls
988
- clearable={clearable}
989
- hideTrigger={hideTrigger}
990
- compact={compact}
991
- iconSize={sizeClasses.icon}
992
- />
993
- </ComboboxPrimitive.Chips>
994
- {error && <span className="text-caption text-destructive pl-3">{error}</span>}
995
- </div>
996
- )
997
- },
998
- )
999
-
1000
- ComboboxChips.displayName = 'ComboboxChips'
1001
-
1002
- // ---------------------------------------------------------------------------
1003
- // ComboboxContent — the popup surface. Holds ComboboxEmpty and ComboboxList.
1004
- // ---------------------------------------------------------------------------
1005
-
1006
- interface ComboboxContentProps {
1007
- /** Classes for the popup surface — merged after the radius and max-height. */
1008
- className?: string
1009
- /** `Combobox.Empty` and `Combobox.List`. */
1010
- children: ReactNode
1011
- /** Side of the field the popup prefers. Defaults to `"bottom"`. */
1012
- side?: 'top' | 'bottom' | 'left' | 'right'
1013
- /** Alignment against the field. Defaults to `"start"`. */
1014
- align?: 'start' | 'center' | 'end'
1015
- /** Gap to the field, in px. Ignored when the list opens in place over the field (`effect="morph"` with `hideSource`). Defaults to `6`. */
1016
- sideOffset?: number
1017
- /** Where the list grows from (see Morph): the field, the press point, its own center, a viewport edge, or a ref to any element. Defaults to `'trigger'` (the field). */
1018
- from?: 'trigger' | 'pointer' | 'center' | 'top' | 'right' | 'bottom' | 'left' | RefObject<HTMLElement | null>
1019
- /** How it grows (see Morph): with the liquid goo neck, a plain morph, a slide or a fade. Defaults to `'goo'`. */
1020
- effect?: 'goo' | 'morph' | 'slide' | 'fade'
1021
- /** Hide the field while open, so it reads as turning into the list. Defaults to `false`. */
1022
- hideSource?: boolean
1023
- /** Spring tier of a plain morph, slide or fade; goo runs on its own `spring.goo`. Defaults to `'moderate'`. */
1024
- tier?: 'moderate' | 'slow'
1025
- /** Pinned under the list, past a hairline: a "load more" or "add new" action. A function gets `{ close, query }`. */
1026
- footer?: ComboboxFooter
1027
- }
1028
-
1029
- const ComboboxContent = forwardRef<HTMLDivElement, ComboboxContentProps>(
1030
- (
1031
- {
1032
- className,
1033
- children,
1034
- side = 'bottom',
1035
- align = 'start',
1036
- sideOffset = 6,
1037
- from,
1038
- effect,
1039
- hideSource,
1040
- tier = 'moderate',
1041
- footer,
1042
- },
1043
- ref,
1044
- ) => {
1045
- const { open, origin, anchorRef, setOpen, inputValue } = useComboboxContext()
1046
- const morph = useMorph(open, origin, { from, effect, hideSource, tier })
1047
- useImperativeHandle(ref, () => morph.popup as HTMLDivElement, [morph.popup])
1048
- // Lifts 2 levels off its substrate with a fixed shadow (see Elevated).
1049
- const level = Math.min(useSurface() + 2, 8)
1050
- const shape = popupShape
1051
-
1052
- return (
1053
- <ComboboxPrimitive.Portal>
1054
- <ComboboxPrimitive.Positioner
1055
- // The whole field (input group or chips container) is the anchor,
1056
- // so the list spans it edge to edge.
1057
- anchor={anchorRef}
1058
- side={side}
1059
- align={align}
1060
- sideOffset={opensInPlace({ effect, hideSource }) ? inPlaceOffset : sideOffset}
1061
- className="z-50 outline-none"
1062
- >
1063
- <ComboboxPrimitive.Popup ref={morph.popupRef} className="relative select-none outline-none">
1064
- <SurfaceProvider value={level}>
1065
- <MorphSurface
1066
- morph={morph}
1067
- bg={SURFACE_BG[level]}
1068
- shadow={SURFACE_SHADOW[3]}
1069
- radius={shape.container}
1070
- className={cn(
1071
- // min-w tracks the field via the Positioner's --anchor-width
1072
- // var; the list inside owns padding and scrolling.
1073
- `flex flex-col min-w-[var(--anchor-width)] max-h-[min(300px,var(--available-height))] overflow-hidden ${shape.container}`,
1074
- className,
1075
- )}
1076
- >
1077
- {children}
1078
- {footer !== undefined && (
1079
- // Outside the scrolling list, so it stays put while the rows scroll.
1080
- <div className="shrink-0 border-t border-border p-1">
1081
- {typeof footer === 'function'
1082
- ? footer({ close: () => setOpen(false), query: inputValue.trim() })
1083
- : footer}
1084
- </div>
1085
- )}
1086
- </MorphSurface>
1087
- </SurfaceProvider>
1088
- </ComboboxPrimitive.Popup>
1089
- </ComboboxPrimitive.Positioner>
1090
- </ComboboxPrimitive.Portal>
1091
- )
1092
- },
1093
- )
1094
-
1095
- ComboboxContent.displayName = 'ComboboxContent'
1096
-
1097
- // ---------------------------------------------------------------------------
1098
- // ComboboxList — renders a row per matching item, carrying the fluid hover
1099
- // hover overlays and the animated selected background / focus ring.
1100
- // ---------------------------------------------------------------------------
1101
-
1102
- interface ComboboxListProps {
1103
- /** Classes for the rows' container. */
1104
- className?: string
1105
- /** Render one row per matching item: `(item, index) => <Combobox.Item …/>`. Rows get their index from the list. */
1106
- children: (item: ComboboxItemData, index: number) => ReactNode
1107
- }
1108
-
1109
- const ComboboxList = forwardRef<HTMLDivElement, ComboboxListProps>(({ className, children }, ref) => {
1110
- const { open, values, multiple, inputValue, createRow, loading, loadingLabel } = useComboboxContext()
1111
- const Loader = useIcon('loader-circle')
1112
- const sizeClasses = useSize()
1113
- const highlight = useContext(ComboboxHighlightContext)
1114
- const PlusIcon = useIcon('plus')
1115
- const shape = popupShape
1116
- const containerRef = useRef<HTMLDivElement>(null)
1117
-
1118
- const hover = useFluidHover(containerRef, { isItemDisabled: isDisabledRow })
1119
- const { activeIndex, setActiveIndex, itemRects, isMeasured, handlers, registerItem, remeasure } = hover
1120
-
1121
- // Checked rows by index — one in single mode, any number in multiple.
1122
- const [checkedIndices, setCheckedIndices] = useState<number[]>([])
1123
-
1124
- // Fresh rects once per open — the popup keeps its rows registered while
1125
- // it sits hidden between opens, so registration alone never triggers a
1126
- // pass on reopen. Filtering re-registers rows, which the hook coalesces
1127
- // into its own measurement.
1128
- useEffect(() => {
1129
- if (!open) return
1130
- remeasure()
1131
- }, [open, remeasure])
1132
-
1133
- // Typing re-filters the rows underneath the overlays, and those frames
1134
- // must snap, not glide — an overlay springing to wherever its row LANDED
1135
- // reads as the list smearing on every keystroke. The primitive filters
1136
- // internally, so the query is the reflow signal (picks don't change it,
1137
- // keeping multiple mode's merge/split glide). The flag arms on the
1138
- // query's render and holds until the rects measured from the new row
1139
- // set land — measurement coalesces on a rAF, one render behind.
1140
- const reflowRef = useRef(false)
1141
- const prevQueryRef = useRef(inputValue)
1142
- const armedRectsRef = useRef(itemRects)
1143
- if (prevQueryRef.current !== inputValue) {
1144
- prevQueryRef.current = inputValue
1145
- armedRectsRef.current = itemRects
1146
- reflowRef.current = true
1147
- }
1148
- const reflowSnap = reflowRef.current
1149
- useEffect(() => {
1150
- if (reflowRef.current && itemRects !== armedRectsRef.current) reflowRef.current = false
1151
- })
1152
-
1153
- // Detect the checked rows. Their indices shift as the query filters the
1154
- // list, so the typed value is a dependency too.
1155
- useEffect(() => {
1156
- if (!open) return
1157
- // Double rAF: first waits for React commit, second for layout
1158
- let inner: number
1159
- const outer = requestAnimationFrame(() => {
1160
- inner = requestAnimationFrame(() => {
1161
- const container = containerRef.current
1162
- if (container) {
1163
- const rows = Array.from(container.querySelectorAll('[data-fluid-hover-index]')) as HTMLElement[]
1164
- const next: number[] = []
1165
- rows.forEach((el, i) => {
1166
- if (values.includes(el.getAttribute('data-value') ?? '')) next.push(i)
1167
- })
1168
- setCheckedIndices(next)
1169
- }
1170
- })
1171
- })
1172
- return () => {
1173
- cancelAnimationFrame(outer)
1174
- cancelAnimationFrame(inner)
1175
- }
1176
- }, [open, values, inputValue])
1177
-
1178
- // A keyboard (or auto) highlight drives the hover background — the only
1179
- // indicator: the row Enter would pick reads like the row the pointer
1180
- // would pick, with no ring.
1181
- useEffect(() => {
1182
- // A dropped highlight (the input is the stop again) takes the hover
1183
- // background with it — otherwise it would linger on the last row.
1184
- if (!highlight) setActiveIndex(null)
1185
- else if (highlight.keyboard) setActiveIndex(highlight.index)
1186
- }, [highlight, setActiveIndex])
1187
-
1188
- // Reset every overlay index as the close begins, so the reopen doesn't
1189
- // spring an overlay from a stale row.
1190
- useEffect(() => {
1191
- if (open) return
1192
- setCheckedIndices([])
1193
- setActiveIndex(null)
1194
- }, [open, setActiveIndex])
1195
-
1196
- // Overlays read rects only once the hook reports the row set fully
1197
- // measured — positioning one from an incomplete pass mounts it at the
1198
- // wrong row, and the correcting pass then springs it across the list.
1199
- // Single mode glides ONE marker between rows (a value change springs it
1200
- // to the picked row). Multiple mode paints one block per contiguous run
1201
- // of checked rows — merging and splitting like Checkbox.Group as picks
1202
- // bridge or break a run.
1203
- const firstChecked = checkedIndices[0]
1204
- const checkedRect = isMeasured && !multiple && firstChecked !== undefined ? (itemRects[firstChecked] ?? null) : null
1205
- const runs = useSelectionRuns(multiple ? checkedIndices : [])
1206
- const blocks = useMergeSplitBlocks(runs, isMeasured && open ? itemRects : [], shape.bgRadius)
1207
-
1208
- const contentCtx = useMemo(() => ({ registerItem, activeIndex }), [registerItem, activeIndex])
1209
-
1210
- return (
1211
- <ComboboxContentContext.Provider value={contentCtx}>
1212
- <ScrollArea className={popupScrollAreaClass} viewportClassName={cn(popupViewportClass, 'scroll-fade')}>
1213
- <ComboboxPrimitive.List
1214
- ref={(node: HTMLDivElement | null) => {
1215
- ;(containerRef as MutableRefObject<HTMLDivElement | null>).current = node
1216
- if (typeof ref === 'function') ref(node)
1217
- else if (ref) (ref as MutableRefObject<HTMLDivElement | null>).current = node
1218
- }}
1219
- onMouseEnter={handlers.onMouseEnter}
1220
- onMouseMove={handlers.onMouseMove}
1221
- onMouseLeave={handlers.onMouseLeave}
1222
- onClick={handlers.onClick}
1223
- className={cn(
1224
- // The list is the overlays' offsetParent, so rows and overlays
1225
- // scroll together inside the ScrollArea. Padding collapses when
1226
- // the list is empty (ComboboxEmpty takes over).
1227
- 'relative flex flex-col p-1 outline-none data-[empty]:p-0',
1228
- className,
1229
- )}
1230
- >
1231
- {/* The three overlays are torn down as the close begins rather
1232
- than exit-animated: an overlay still mounted when the popup
1233
- reopens is one AnimatePresence re-adopts under its old key and
1234
- animates from the row it had before. */}
1235
- {/* Selected background */}
1236
- {open && multiple && (
1237
- <SelectionBackgrounds blocks={reflowSnap ? blocks.map(b => ({ ...b, instant: true })) : blocks} />
1238
- )}
1239
- {open && !multiple && (
1240
- <AnimatePresence>
1241
- {checkedRect && (
1242
- <motion.div
1243
- key="checked"
1244
- aria-hidden
1245
- className={`absolute ${shape.bg} bg-active pointer-events-none`}
1246
- initial={false}
1247
- animate={{
1248
- top: checkedRect.top,
1249
- left: checkedRect.left,
1250
- width: checkedRect.width,
1251
- height: checkedRect.height,
1252
- opacity: 1,
1253
- }}
1254
- exit={{ opacity: 0, transition: spring.moderate.exit }}
1255
- transition={
1256
- reflowSnap ? { duration: 0 } : { ...spring.moderate, opacity: { duration: spring.fast.duration } }
1257
- }
1258
- />
1259
- )}
1260
- </AnimatePresence>
1261
- )}
1262
-
1263
- {/* Hover background. Snaps (no travel) while a filter reflow is
1264
- moving the rows underneath. */}
1265
- {open && (
1266
- <FluidHoverHighlight hover={hover} className={shape.bg} transition={reflowSnap ? false : undefined} />
1267
- )}
1268
-
1269
- {/* The overlays above are plain children, so the rows come from
1270
- an explicit Collection (a function child on List would have
1271
- to be its only child). */}
1272
- <ComboboxPrimitive.Collection>
1273
- {(item: ComboboxItemData, index: number) => (
1274
- <ComboboxItemIndexContext.Provider key={itemValue(item)} value={index}>
1275
- {/* The create row is the list's, not the consumer's: it
1276
- reads the label from the root and picks like any row. */}
1277
- {isCreateItem(item) ? (
1278
- <ComboboxItem value={CREATE_VALUE} icon={PlusIcon}>
1279
- {createRow}
1280
- </ComboboxItem>
1281
- ) : (
1282
- children(item, index)
1283
- )}
1284
- </ComboboxItemIndexContext.Provider>
1285
- )}
1286
- </ComboboxPrimitive.Collection>
1287
- </ComboboxPrimitive.List>
1288
- {loading && (
1289
- // Not a row: no hover, no pick. Under the rows, so items already
1290
- // here stay where they are while more arrive.
1291
- <div
1292
- role="status"
1293
- className={cn(
1294
- 'flex shrink-0 items-center justify-center text-muted-foreground',
1295
- sizeClasses.control,
1296
- sizeClasses.itemPx,
1297
- sizeClasses.gap,
1298
- sizeClasses.text,
1299
- )}
1300
- >
1301
- <Loader
1302
- size={sizeClasses.icon}
1303
- strokeWidth={1.5}
1304
- className="shrink-0 animate-spin motion-reduce:animate-none"
1305
- />
1306
- <span className="truncate [text-box:trim-both_cap_alphabetic]">{loadingLabel}</span>
1307
- </div>
1308
- )}
1309
- </ScrollArea>
1310
- </ComboboxContentContext.Provider>
338
+ {children}
339
+ </ComboboxPrimitive.Root>
340
+ </ComboboxHighlightContext.Provider>
341
+ </OverlayContext.Provider>
342
+ </ComboboxContext.Provider>
343
+ </SizeScope>
1311
344
  )
1312
- })
1313
-
1314
- ComboboxList.displayName = 'ComboboxList'
1315
-
1316
- // ---------------------------------------------------------------------------
1317
- // ComboboxItem
1318
- // ---------------------------------------------------------------------------
1319
-
1320
- interface ComboboxItemProps extends HTMLAttributes<HTMLDivElement> {
1321
- /** Leading icon in the row. */
1322
- icon?: IconComponent
1323
- /** The item's value — a string item itself, or an object item's `value`. */
1324
- value: string
1325
- /** Disables the row. Defaults to `false`. */
1326
- disabled?: boolean
1327
- /** The row label. */
1328
- children?: ReactNode
1329
345
  }
1330
346
 
1331
- const ComboboxItem = forwardRef<HTMLDivElement, ComboboxItemProps>(
1332
- ({ className, children, icon: Icon, value, disabled = false, ...props }, ref) => {
1333
- const comboboxCtx = useComboboxContext()
1334
- const contentCtx = useContext(ComboboxContentContext)
1335
- const index = useContext(ComboboxItemIndexContext)
1336
- const internalRef = useRef<HTMLDivElement>(null)
1337
- const shape = popupShape
1338
- const sizeClasses = useSize()
1339
- const compact = sizeClasses.variant === 'compact'
1340
- const hasMounted = useRef(false)
1341
-
1342
- useEffect(() => {
1343
- hasMounted.current = true
1344
- }, [])
1345
-
1346
- // Register with fluid hover. Depends on the (stable) registerItem
1347
- // rather than the content context, which is rebuilt on every activeIndex
1348
- // change.
1349
- const registerItem = contentCtx?.registerItem
1350
- useRegisterFluidHoverItem(registerItem, index, internalRef)
1351
-
1352
- const isActive = contentCtx?.activeIndex === index
1353
- const isChecked = comboboxCtx.values.includes(value)
1354
- const skipAnimation = !hasMounted.current
1355
- // Base UI matches rows to `items` by value, so the row hands back the
1356
- // item it was rendered from.
1357
- const item = comboboxCtx.itemsByValue.get(value) ?? value
1358
-
1359
- return (
1360
- <ComboboxPrimitive.Item
1361
- value={item}
1362
- index={index}
1363
- disabled={disabled}
1364
- render={
1365
- <div
1366
- ref={(node: HTMLDivElement | null) => {
1367
- ;(internalRef as MutableRefObject<HTMLDivElement | null>).current = node
1368
- if (typeof ref === 'function') ref(node)
1369
- else if (ref) (ref as MutableRefObject<HTMLDivElement | null>).current = node
1370
- }}
1371
- data-fluid-hover-index={index}
1372
- data-value={value}
1373
- className={cn(
1374
- // Fixed height so the text-box trim on the label doesn't
1375
- // shrink the row; shrink-0 because the list is a max-height
1376
- // flex column.
1377
- `relative z-10 flex ${sizeClasses.control} shrink-0 items-center ${sizeClasses.gap} ${shape.item} ${sizeClasses.itemPx} ${sizeClasses.text} cursor-pointer outline-none select-none`,
1378
- 'transition-[color] duration-fast',
1379
- isActive || isChecked ? 'text-foreground' : 'text-muted-foreground',
1380
- disabled && 'opacity-50 pointer-events-none',
1381
- className,
1382
- )}
1383
- {...props}
1384
- />
1385
- }
1386
- >
1387
- {Icon && (
1388
- <Icon
1389
- size={sizeClasses.icon}
1390
- strokeWidth={isActive || isChecked ? 2 : 1.5}
1391
- className="shrink-0 transition-[color,stroke-width] duration-fast"
1392
- />
1393
- )}
1394
-
1395
- {/* py-1/-my-1 keeps truncate's overflow:hidden from clipping
1396
- ascenders/descenders outside the trimmed box. */}
1397
- {/* Nodes keep their own box; only text is trimmed and truncated. */}
1398
- <span
1399
- className={cn(
1400
- 'flex-1 min-w-0',
1401
- typeof children === 'string' || typeof children === 'number'
1402
- ? 'truncate [text-box:trim-both_cap_alphabetic] py-1 -my-1'
1403
- : 'flex items-center',
1404
- )}
1405
- >
1406
- {children}
1407
- </span>
1408
-
1409
- {/* Always-rendered fixed slot so the check appearing/disappearing
1410
- never changes the row's intrinsic width. */}
1411
- <span aria-hidden className={cn('shrink-0', compact ? 'w-3.5 h-3.5' : 'w-4 h-4')}>
1412
- <AnimatePresence>
1413
- {isChecked && (
1414
- <motion.svg
1415
- key="check"
1416
- width={sizeClasses.icon}
1417
- height={sizeClasses.icon}
1418
- viewBox="0 0 24 24"
1419
- fill="none"
1420
- stroke="currentColor"
1421
- strokeWidth={2}
1422
- strokeLinecap="round"
1423
- strokeLinejoin="round"
1424
- className="text-foreground"
1425
- initial={{ opacity: 1 }}
1426
- animate={{ opacity: 1 }}
1427
- exit={{ opacity: 1 }}
1428
- >
1429
- <motion.path
1430
- d="M4 12L9 17L20 6"
1431
- initial={{ pathLength: skipAnimation ? 1 : 0 }}
1432
- animate={{
1433
- pathLength: 1,
1434
- transition: { duration: spring.fast.duration, ease: 'easeOut' },
1435
- }}
1436
- exit={{
1437
- pathLength: 0,
1438
- transition: { duration: 0.04, ease: 'easeIn' },
1439
- }}
1440
- />
1441
- </motion.svg>
1442
- )}
1443
- </AnimatePresence>
1444
- </span>
1445
- </ComboboxPrimitive.Item>
1446
- )
1447
- },
1448
- )
1449
-
1450
- ComboboxItem.displayName = 'ComboboxItem'
1451
-
1452
- // ---------------------------------------------------------------------------
1453
- // ComboboxEmpty — shown in place of the list when nothing matches.
1454
- // ---------------------------------------------------------------------------
1455
-
1456
- interface ComboboxEmptyProps extends HTMLAttributes<HTMLDivElement> {
1457
- /** Shown instead of the children when `hideSelected` has emptied the
1458
- * list with nothing typed: every item is a chip already. */
1459
- allSelected?: ReactNode
1460
- /** Shown when nothing matches the query. */
1461
- children?: ReactNode
1462
- }
1463
-
1464
- const ComboboxEmpty = forwardRef<HTMLDivElement, ComboboxEmptyProps>(
1465
- ({ className, children, allSelected, ...props }, ref) => {
1466
- const sizeClasses = useSize()
1467
- const ctx = useComboboxContext()
1468
- return (
1469
- // Base UI keeps this element mounted (it is a live region) and only
1470
- // renders the children while the list is empty — so the padding is
1471
- // gated on having content.
1472
- <ComboboxPrimitive.Empty
1473
- ref={ref}
1474
- className={cn('px-3 text-center text-muted-foreground [&:not(:empty)]:py-6', sizeClasses.text, className)}
1475
- {...props}
1476
- >
1477
- {ctx.loading ? null : ctx.allSelected && allSelected !== undefined ? allSelected : children}
1478
- </ComboboxPrimitive.Empty>
1479
- )
1480
- },
1481
- )
1482
-
1483
- ComboboxEmpty.displayName = 'ComboboxEmpty'
1484
-
1485
- // ---------------------------------------------------------------------------
1486
- // Statics — the compound API, typed by assignment so `<Combobox.Item>` and
1487
- // the named exports stay the same component.
1488
- // ---------------------------------------------------------------------------
347
+ Combobox.displayName = 'Combobox'
1489
348
 
1490
349
  Combobox.Input = ComboboxInput
1491
350
  Combobox.Chips = ComboboxChips
@@ -1494,10 +353,6 @@ Combobox.List = ComboboxList
1494
353
  Combobox.Item = ComboboxItem
1495
354
  Combobox.Empty = ComboboxEmpty
1496
355
 
1497
- // ---------------------------------------------------------------------------
1498
- // Exports
1499
- // ---------------------------------------------------------------------------
1500
-
1501
356
  export type {
1502
357
  ComboboxChipsProps,
1503
358
  ComboboxContentProps,
@@ -1508,20 +363,10 @@ export type {
1508
363
  ComboboxItemData,
1509
364
  ComboboxItemObject,
1510
365
  ComboboxItemProps,
1511
- ComboboxLabels,
1512
366
  ComboboxListProps,
1513
367
  ComboboxProps,
1514
368
  ComboboxValue,
1515
369
  }
1516
- export {
1517
- Combobox,
1518
- ComboboxChips,
1519
- ComboboxContent,
1520
- ComboboxEmpty,
1521
- ComboboxInput,
1522
- ComboboxItem,
1523
- ComboboxList,
1524
- fieldVariants as comboboxFieldVariants,
1525
- }
370
+ export { Combobox, ComboboxChips, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList }
1526
371
 
1527
372
  export default Combobox