@justanarthur/modo-ui 0.5.0 → 0.6.0-canary.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 (461) hide show
  1. package/DESIGN.md +608 -0
  2. package/README.md +61 -39
  3. package/blocks/sidebar-app/examples.mdx +33 -0
  4. package/blocks/sidebar-app/index.tsx +218 -0
  5. package/blocks/sidebar-app/inset-topbar.tsx +25 -0
  6. package/blocks/sidebar-app/menu-grid.ts +26 -0
  7. package/blocks/sidebar-app/nav-data.ts +36 -0
  8. package/blocks/sidebar-app/search-field.tsx +48 -0
  9. package/blocks/sidebar-app/user-footer.tsx +67 -0
  10. package/blocks/sidebar-app/workspace-header.tsx +129 -0
  11. package/components/AI/input-message/examples.mdx +124 -0
  12. package/components/AI/input-message/file-thumbnail.tsx +173 -0
  13. package/components/AI/input-message/index.tsx +1383 -0
  14. package/components/AI/thinking-indicator/examples.mdx +27 -0
  15. package/components/AI/thinking-indicator/index.tsx +210 -0
  16. package/components/accordion/examples.mdx +148 -0
  17. package/components/accordion/index.tsx +1034 -0
  18. package/components/avatar/examples.mdx +95 -0
  19. package/components/avatar/index.tsx +129 -0
  20. package/components/badge/change-demo.tsx +29 -0
  21. package/components/badge/examples.mdx +120 -0
  22. package/components/badge/index.tsx +225 -0
  23. package/components/badge/variants.ts +73 -0
  24. package/components/button/examples.mdx +164 -0
  25. package/components/button/index.tsx +416 -0
  26. package/components/button/loading-demo.tsx +25 -0
  27. package/components/button/variants.ts +166 -0
  28. package/components/card/examples.mdx +212 -0
  29. package/components/card/index.tsx +1037 -0
  30. package/components/copy/examples.mdx +87 -0
  31. package/components/copy/index.tsx +482 -0
  32. package/components/inputs/checkbox/examples.mdx +83 -0
  33. package/components/inputs/checkbox/index.tsx +611 -0
  34. package/components/inputs/checkbox/select-all-demo.tsx +48 -0
  35. package/components/inputs/color-picker/examples.mdx +72 -0
  36. package/components/inputs/color-picker/index.tsx +1955 -0
  37. package/components/inputs/color-picker/variants.ts +401 -0
  38. package/components/inputs/combobox/examples.mdx +273 -0
  39. package/components/inputs/combobox/index.tsx +1436 -0
  40. package/components/inputs/combobox/remote-demo.tsx +101 -0
  41. package/components/inputs/date-time/calendar/examples.mdx +34 -0
  42. package/components/inputs/date-time/calendar/index.tsx +351 -0
  43. package/components/inputs/date-time/calendar/use-month-window.ts +163 -0
  44. package/components/inputs/date-time/date-picker/examples.mdx +166 -0
  45. package/components/inputs/date-time/date-picker/index.tsx +385 -0
  46. package/components/inputs/date-time/date-picker/masked-date-input.tsx +336 -0
  47. package/components/inputs/date-time/date-range-picker/examples.mdx +29 -0
  48. package/components/inputs/date-time/date-range-picker/index.tsx +217 -0
  49. package/components/inputs/date-time/duration-picker/examples.mdx +16 -0
  50. package/components/inputs/date-time/duration-picker/index.tsx +189 -0
  51. package/components/inputs/date-time/month-picker/examples.mdx +16 -0
  52. package/components/inputs/date-time/month-picker/index.tsx +190 -0
  53. package/components/inputs/date-time/picker-shell.tsx +395 -0
  54. package/components/inputs/date-time/time-columns.tsx +91 -0
  55. package/components/inputs/date-time/time-picker/examples.mdx +26 -0
  56. package/components/inputs/date-time/time-picker/index.tsx +166 -0
  57. package/components/inputs/field/examples.mdx +113 -0
  58. package/components/inputs/field/index.tsx +267 -0
  59. package/components/inputs/file-dropzone/examples.mdx +73 -0
  60. package/components/inputs/file-dropzone/file-row.tsx +201 -0
  61. package/components/inputs/file-dropzone/index.tsx +296 -0
  62. package/components/inputs/file-dropzone/upload-demo.tsx +67 -0
  63. package/components/inputs/file-dropzone/variants.ts +94 -0
  64. package/components/inputs/input/examples.mdx +135 -0
  65. package/components/inputs/input/index.tsx +494 -0
  66. package/components/inputs/input/password-demo.tsx +30 -0
  67. package/components/inputs/label/examples.mdx +67 -0
  68. package/components/inputs/label/index.tsx +85 -0
  69. package/components/inputs/number-input/examples.mdx +56 -0
  70. package/components/inputs/number-input/index.tsx +214 -0
  71. package/components/inputs/radio/examples.mdx +77 -0
  72. package/components/inputs/radio/index.tsx +636 -0
  73. package/components/inputs/search/examples.mdx +74 -0
  74. package/components/inputs/search/index.tsx +333 -0
  75. package/components/inputs/select/examples.mdx +218 -0
  76. package/components/inputs/select/index.tsx +862 -0
  77. package/components/inputs/select/variants.ts +32 -0
  78. package/components/inputs/slider/examples.mdx +127 -0
  79. package/components/inputs/slider/index.tsx +1725 -0
  80. package/components/inputs/switch/examples.mdx +94 -0
  81. package/components/inputs/switch/index.tsx +504 -0
  82. package/components/inputs/textarea/examples.mdx +88 -0
  83. package/components/inputs/textarea/index.tsx +161 -0
  84. package/components/navigation/navigation-menu/examples.mdx +109 -0
  85. package/components/navigation/navigation-menu/index.tsx +613 -0
  86. package/components/navigation/pagination/examples.mdx +64 -0
  87. package/components/navigation/pagination/index.tsx +395 -0
  88. package/components/navigation/sidebar/examples.mdx +319 -0
  89. package/components/navigation/sidebar/index.tsx +453 -0
  90. package/components/navigation/sidebar/sidebar-core.tsx +1408 -0
  91. package/components/navigation/sidebar/sidebar-menu.tsx +1495 -0
  92. package/components/navigation/sidebar/sidebar.css +74 -0
  93. package/components/navigation/sidebar/variants.ts +55 -0
  94. package/components/navigation/tabs/examples.mdx +89 -0
  95. package/components/navigation/tabs/index.tsx +494 -0
  96. package/components/navigation/tabs-subtle/examples.mdx +49 -0
  97. package/components/navigation/tabs-subtle/index.tsx +512 -0
  98. package/components/overlays/alert-dialog/examples.mdx +123 -0
  99. package/components/overlays/alert-dialog/index.tsx +258 -0
  100. package/components/overlays/alert-dialog/pending-demo.tsx +36 -0
  101. package/components/overlays/command/examples.mdx +113 -0
  102. package/components/overlays/command/index.tsx +416 -0
  103. package/components/overlays/context-menu/examples.mdx +56 -0
  104. package/components/overlays/context-menu/index.tsx +279 -0
  105. package/components/overlays/dialog/examples.mdx +144 -0
  106. package/components/overlays/dialog/index.tsx +366 -0
  107. package/components/overlays/dropdown/dropdown-search.tsx +395 -0
  108. package/components/overlays/dropdown/examples.mdx +294 -0
  109. package/components/overlays/dropdown/index.tsx +1168 -0
  110. package/components/overlays/dropdown/menu-item.tsx +464 -0
  111. package/components/overlays/dropdown/menu-parts.tsx +660 -0
  112. package/components/overlays/popover/anchored-demo.tsx +59 -0
  113. package/components/overlays/popover/examples.mdx +180 -0
  114. package/components/overlays/popover/index.tsx +315 -0
  115. package/components/overlays/preview-card/examples.mdx +61 -0
  116. package/components/overlays/preview-card/index.tsx +204 -0
  117. package/components/overlays/sheet/examples.mdx +89 -0
  118. package/components/overlays/sheet/index.tsx +247 -0
  119. package/components/overlays/toast/examples.mdx +68 -0
  120. package/components/overlays/toast/global-demo.tsx +72 -0
  121. package/components/overlays/toast/index.tsx +474 -0
  122. package/components/overlays/toast/manager.ts +193 -0
  123. package/components/overlays/tooltip/examples.mdx +106 -0
  124. package/components/overlays/tooltip/index.tsx +519 -0
  125. package/components/progress/examples.mdx +59 -0
  126. package/components/progress/index.tsx +174 -0
  127. package/components/progress/progress.css +49 -0
  128. package/components/progress/step-demo.tsx +27 -0
  129. package/components/table/examples.mdx +184 -0
  130. package/components/table/index.tsx +510 -0
  131. package/components/table/sort-demo.tsx +61 -0
  132. package/dist/base.css +100 -0
  133. package/dist/blocks/sidebar-app/index.js +39 -26
  134. package/dist/components/AI/input-message/index.js +22 -16
  135. package/dist/components/AI/thinking-indicator/index.js +9 -6
  136. package/dist/components/accordion/index.js +16 -13
  137. package/dist/components/avatar/index.d.ts +46 -0
  138. package/dist/components/avatar/index.js +18 -0
  139. package/dist/components/badge/index.d.ts +18 -11
  140. package/dist/components/badge/index.js +11 -7
  141. package/dist/components/badge/variants.d.ts +33 -0
  142. package/dist/components/badge/variants.js +10 -0
  143. package/dist/components/button/index.d.ts +53 -17
  144. package/dist/components/button/index.js +10 -6
  145. package/dist/components/button/variants.d.ts +39 -0
  146. package/dist/components/button/variants.js +8 -0
  147. package/dist/components/card/index.d.ts +16 -3
  148. package/dist/components/card/index.js +16 -11
  149. package/dist/components/copy/index.js +13 -9
  150. package/dist/components/inputs/checkbox/index.d.ts +28 -9
  151. package/dist/components/inputs/checkbox/index.js +17 -13
  152. package/dist/components/inputs/color-picker/index.d.ts +13 -13
  153. package/dist/components/inputs/color-picker/index.js +25 -18
  154. package/dist/components/inputs/color-picker/variants.d.ts +61 -0
  155. package/dist/components/inputs/color-picker/variants.js +28 -0
  156. package/dist/components/inputs/combobox/index.d.ts +60 -17
  157. package/dist/components/inputs/combobox/index.js +26 -18
  158. package/dist/components/inputs/date-time/calendar/index.js +14 -11
  159. package/dist/components/inputs/date-time/date-picker/index.d.ts +53 -11
  160. package/dist/components/inputs/date-time/date-picker/index.js +33 -25
  161. package/dist/components/inputs/date-time/date-range-picker/index.d.ts +3 -3
  162. package/dist/components/inputs/date-time/date-range-picker/index.js +32 -24
  163. package/dist/components/inputs/date-time/duration-picker/index.d.ts +3 -3
  164. package/dist/components/inputs/date-time/duration-picker/index.js +32 -24
  165. package/dist/components/inputs/date-time/month-picker/index.d.ts +3 -3
  166. package/dist/components/inputs/date-time/month-picker/index.js +31 -23
  167. package/dist/components/inputs/date-time/time-picker/index.d.ts +3 -3
  168. package/dist/components/inputs/date-time/time-picker/index.js +32 -24
  169. package/dist/components/inputs/field/index.d.ts +116 -0
  170. package/dist/components/inputs/field/index.js +28 -0
  171. package/dist/components/inputs/file-dropzone/index.d.ts +165 -0
  172. package/dist/components/inputs/file-dropzone/index.js +32 -0
  173. package/dist/components/inputs/file-dropzone/variants.d.ts +35 -0
  174. package/dist/components/inputs/file-dropzone/variants.js +12 -0
  175. package/dist/components/inputs/input/index.d.ts +95 -13
  176. package/dist/components/inputs/input/index.js +17 -9
  177. package/dist/components/inputs/label/index.d.ts +32 -0
  178. package/dist/components/inputs/label/index.js +11 -0
  179. package/dist/components/inputs/number-input/index.d.ts +84 -0
  180. package/dist/components/inputs/number-input/index.js +20 -0
  181. package/dist/components/inputs/radio/index.d.ts +20 -5
  182. package/dist/components/inputs/radio/index.js +15 -12
  183. package/dist/components/inputs/search/index.js +25 -18
  184. package/dist/components/inputs/select/index.d.ts +41 -11
  185. package/dist/components/inputs/select/index.js +27 -14
  186. package/dist/components/inputs/select/variants.d.ts +5 -0
  187. package/dist/components/inputs/select/variants.js +6 -0
  188. package/dist/components/inputs/slider/index.js +7 -5
  189. package/dist/components/inputs/switch/index.d.ts +8 -2
  190. package/dist/components/inputs/switch/index.js +14 -12
  191. package/dist/components/inputs/textarea/index.d.ts +4 -0
  192. package/dist/components/inputs/textarea/index.js +8 -6
  193. package/dist/components/navigation/navigation-menu/index.d.ts +114 -0
  194. package/dist/components/navigation/navigation-menu/index.js +40 -0
  195. package/dist/components/navigation/pagination/index.d.ts +73 -0
  196. package/dist/components/navigation/pagination/index.js +39 -0
  197. package/dist/components/navigation/sidebar/index.d.ts +44 -21
  198. package/dist/components/navigation/sidebar/index.js +41 -31
  199. package/dist/components/navigation/sidebar/variants.d.ts +25 -0
  200. package/dist/components/navigation/sidebar/variants.js +28 -0
  201. package/dist/components/navigation/tabs/index.d.ts +8 -2
  202. package/dist/components/navigation/tabs/index.js +14 -10
  203. package/dist/components/navigation/tabs-subtle/index.js +12 -10
  204. package/dist/components/overlays/alert-dialog/index.d.ts +121 -15
  205. package/dist/components/overlays/alert-dialog/index.js +22 -13
  206. package/dist/components/overlays/command/index.js +24 -17
  207. package/dist/components/overlays/context-menu/index.d.ts +33 -17
  208. package/dist/components/overlays/context-menu/index.js +27 -18
  209. package/dist/components/overlays/dialog/index.js +17 -12
  210. package/dist/components/overlays/dropdown/index.d.ts +257 -31
  211. package/dist/components/overlays/dropdown/index.js +42 -17
  212. package/dist/components/overlays/popover/index.d.ts +31 -9
  213. package/dist/components/overlays/popover/index.js +12 -9
  214. package/dist/components/overlays/preview-card/index.js +11 -8
  215. package/dist/components/overlays/sheet/index.js +18 -13
  216. package/dist/components/overlays/toast/index.d.ts +123 -47
  217. package/dist/components/overlays/toast/index.js +18 -10
  218. package/dist/components/overlays/tooltip/index.d.ts +113 -21
  219. package/dist/components/overlays/tooltip/index.js +15 -6
  220. package/dist/components/progress/index.d.ts +56 -0
  221. package/dist/components/progress/index.js +15 -0
  222. package/dist/components/table/index.d.ts +63 -8
  223. package/dist/components/table/index.js +19 -9
  224. package/dist/index.d.ts +2201 -736
  225. package/dist/index.js +223 -82
  226. package/dist/lib/date-locale.d.ts +14 -0
  227. package/dist/lib/date-locale.js +16 -0
  228. package/dist/lib/field-classes.d.ts +144 -0
  229. package/dist/lib/field-classes.js +40 -0
  230. package/dist/lib/field-variants.d.ts +47 -0
  231. package/dist/lib/field-variants.js +26 -0
  232. package/dist/lib/fluid-hover-highlight.d.ts +112 -0
  233. package/dist/lib/fluid-hover-highlight.js +17 -0
  234. package/dist/lib/focus-ring.d.ts +18 -0
  235. package/dist/lib/focus-ring.js +10 -0
  236. package/dist/lib/goo-indicator.d.ts +46 -0
  237. package/dist/lib/goo-indicator.js +14 -0
  238. package/dist/lib/icon-context.d.ts +30 -0
  239. package/dist/lib/icon-context.js +12 -0
  240. package/dist/lib/inert.d.ts +9 -0
  241. package/dist/lib/inert.js +8 -0
  242. package/dist/lib/morph-layers.d.ts +93 -0
  243. package/dist/lib/morph-layers.js +13 -0
  244. package/dist/lib/morph-part.d.ts +21 -0
  245. package/dist/lib/morph-part.js +12 -0
  246. package/dist/lib/popup.d.ts +20 -0
  247. package/dist/lib/popup.js +12 -0
  248. package/dist/lib/reduced-motion.d.ts +9 -0
  249. package/dist/lib/reduced-motion.js +6 -0
  250. package/dist/lib/row-index.d.ts +10 -0
  251. package/dist/lib/row-index.js +8 -0
  252. package/dist/lib/row-order.d.ts +28 -0
  253. package/dist/lib/row-order.js +10 -0
  254. package/dist/lib/scroll-column.d.ts +27 -0
  255. package/dist/lib/scroll-column.js +18 -0
  256. package/dist/lib/shape-context.d.ts +30 -0
  257. package/dist/lib/shape-context.js +12 -0
  258. package/dist/lib/size-context.d.ts +94 -0
  259. package/dist/lib/size-context.js +20 -0
  260. package/dist/lib/size-scale.d.ts +79 -0
  261. package/dist/lib/size-scale.js +8 -0
  262. package/dist/lib/slot.d.ts +12 -0
  263. package/dist/lib/slot.js +6 -0
  264. package/dist/lib/springs.d.ts +44 -0
  265. package/dist/lib/springs.js +8 -0
  266. package/dist/lib/surface-classes.d.ts +19 -0
  267. package/dist/lib/surface-classes.js +10 -0
  268. package/dist/lib/surface-context.d.ts +9 -0
  269. package/dist/lib/surface-context.js +8 -0
  270. package/dist/lib/use-controllable-state.d.ts +2 -0
  271. package/dist/lib/use-controllable-state.js +6 -0
  272. package/dist/lib/use-fluid-hover.d.ts +138 -0
  273. package/dist/lib/use-fluid-hover.js +14 -0
  274. package/dist/lib/use-is-mobile.d.ts +2 -0
  275. package/dist/lib/use-is-mobile.js +6 -0
  276. package/dist/lib/use-keyboard-nav-gate.d.ts +20 -0
  277. package/dist/lib/use-keyboard-nav-gate.js +7 -0
  278. package/dist/lib/use-merge-split.d.ts +47 -0
  279. package/dist/lib/use-merge-split.js +15 -0
  280. package/dist/lib/use-morph.d.ts +101 -0
  281. package/dist/lib/use-morph.js +20 -0
  282. package/dist/lib/use-touch-primary.d.ts +2 -0
  283. package/dist/lib/use-touch-primary.js +6 -0
  284. package/dist/lib/utils.d.ts +3 -0
  285. package/dist/lib/utils.js +6 -0
  286. package/dist/preset.d.ts +17 -0
  287. package/dist/preset.js +22 -2
  288. package/dist/primitives/code/index.js +7 -5
  289. package/dist/primitives/craft/index.js +9 -6
  290. package/dist/primitives/fluid-hover/index.js +9 -8
  291. package/dist/primitives/morph/index.js +15 -10
  292. package/dist/primitives/motion/index.js +10 -8
  293. package/dist/primitives/scroll-area/index.js +4 -3
  294. package/dist/primitives/separator/index.d.ts +25 -0
  295. package/dist/primitives/separator/index.js +9 -0
  296. package/dist/primitives/sizes/index.js +6 -4
  297. package/dist/primitives/skeleton/index.d.ts +35 -0
  298. package/dist/primitives/skeleton/index.js +12 -0
  299. package/dist/primitives/surface/index.js +6 -4
  300. package/dist/shared/{components-3mkepka5.js → components-0jmqhx2k.js} +28 -25
  301. package/dist/shared/components-124epb7f.js +53 -0
  302. package/dist/shared/{components-gz8zf3ec.js → components-1k0wv53d.js} +15 -43
  303. package/dist/shared/components-26snnbs9.js +322 -0
  304. package/dist/shared/{components-2dxkv6zm.js → components-2c0qcfx4.js} +8 -7
  305. package/dist/shared/{components-473g814w.js → components-2mt9te6d.js} +243 -137
  306. package/dist/shared/{components-hawvy2qz.js → components-2z48g4fp.js} +9 -30
  307. package/dist/shared/components-34txk9rj.js +35 -0
  308. package/dist/shared/components-3h92d94m.js +23 -0
  309. package/dist/shared/{components-zfnmn5d4.js → components-3sp623ae.js} +36 -31
  310. package/dist/shared/{components-jwst3vtj.js → components-3wxkjgqn.js} +186 -76
  311. package/dist/shared/{components-s2bz1xpk.js → components-49bsynbw.js} +8 -5
  312. package/dist/shared/components-4bwsd46w.js +71 -0
  313. package/dist/shared/components-4n4f5m3e.js +297 -0
  314. package/dist/shared/{components-0q0sqfh4.js → components-4y816hwp.js} +27 -49
  315. package/dist/shared/components-52ngsgca.js +399 -0
  316. package/dist/shared/{components-y9y0g8er.js → components-52r5763g.js} +22 -19
  317. package/dist/shared/components-559tf7yb.js +28 -0
  318. package/dist/shared/components-5mkga9hj.js +440 -0
  319. package/dist/shared/{components-kwa6mrf9.js → components-5s0nfqvw.js} +14 -9
  320. package/dist/shared/{components-dk0gjr5a.js → components-60atskhp.js} +19 -18
  321. package/dist/shared/{components-rr7a6ja9.js → components-658b26nb.js} +21 -18
  322. package/dist/shared/{components-xxvdw7k1.js → components-65vwfjs6.js} +37 -34
  323. package/dist/shared/{components-frw34b65.js → components-6j2fh74k.js} +114 -123
  324. package/dist/shared/components-6zg1yft7.js +167 -0
  325. package/dist/shared/components-6zng858q.js +53 -0
  326. package/dist/shared/components-72w4ge68.js +64 -0
  327. package/dist/shared/{components-cv16mryv.js → components-78x40gee.js} +13 -7
  328. package/dist/shared/{components-b2wyq2cq.js → components-7d4r7hh1.js} +39 -57
  329. package/dist/shared/components-7ntvvegr.js +316 -0
  330. package/dist/shared/components-8nwsqjn8.js +34 -0
  331. package/dist/shared/{components-5xc2j8jz.js → components-8tt3xbb5.js} +19 -18
  332. package/dist/shared/{components-vc7vq5nz.js → components-9as3rf68.js} +6 -3
  333. package/dist/shared/components-9mys9jna.js +255 -0
  334. package/dist/shared/components-adkarj8n.js +35 -0
  335. package/dist/shared/{components-b3c5et5b.js → components-ae9fncz4.js} +32 -31
  336. package/dist/shared/{components-hqeq3w9q.js → components-awra5sff.js} +24 -16
  337. package/dist/shared/components-b1e239g3.js +28 -0
  338. package/dist/shared/{components-q5xj5c16.js → components-b1f2bjf1.js} +9 -8
  339. package/dist/shared/{components-qmmjx1qw.js → components-bn42vq6d.js} +71 -72
  340. package/dist/shared/components-c96g82th.js +1444 -0
  341. package/dist/shared/components-c9yr4ed1.js +44 -0
  342. package/dist/shared/components-d3shbwqq.js +95 -0
  343. package/dist/shared/{components-jjw69c4c.js → components-dcc02hs2.js} +7 -4
  344. package/dist/shared/{components-men63rwj.js → components-de99ykt7.js} +3 -2
  345. package/dist/shared/components-dhgk6mbt.js +16 -0
  346. package/dist/shared/components-drxrtnp2.js +25 -0
  347. package/dist/shared/{components-6p8tfcd6.js → components-ds9fqat9.js} +21 -18
  348. package/dist/shared/{components-mjthm1kf.js → components-egy4tyjt.js} +11 -8
  349. package/dist/shared/components-f0xfpkhh.js +82 -0
  350. package/dist/shared/components-f7h57m6t.js +59 -0
  351. package/dist/shared/{components-d6xtjht3.js → components-fjkpbg6n.js} +33 -30
  352. package/dist/shared/{components-gc5vtq2f.js → components-gh0qeey3.js} +63 -29
  353. package/dist/shared/{components-39jq9va1.js → components-gvbapfen.js} +29 -24
  354. package/dist/shared/{components-5vgpnxgy.js → components-gzesg7hy.js} +19 -16
  355. package/dist/shared/components-h6p86be3.js +19 -0
  356. package/dist/shared/components-h83az0bz.js +33 -0
  357. package/dist/shared/components-jjrj6ymn.js +104 -0
  358. package/dist/shared/{components-wvp1m52g.js → components-jp5v0m0f.js} +15 -14
  359. package/dist/shared/{components-zrkzcayz.js → components-jqpefjsn.js} +54 -6
  360. package/dist/shared/{components-1z6tdadk.js → components-k74j4hwh.js} +20 -17
  361. package/dist/shared/components-kswxnm3h.js +24 -0
  362. package/dist/shared/{components-jbbmdr74.js → components-mkkbbgb7.js} +36 -17
  363. package/dist/shared/{components-pbmqctfa.js → components-mpw667rb.js} +169 -65
  364. package/dist/shared/{components-s5ngg32c.js → components-paa08427.js} +121 -47
  365. package/dist/shared/{components-vfbhxf5r.js → components-pd42emw3.js} +6 -5
  366. package/dist/shared/{components-hw9yk32z.js → components-pmfszv7a.js} +35 -23
  367. package/dist/shared/{components-chacnk61.js → components-pw06rbxq.js} +19 -19
  368. package/dist/shared/components-q03cktx8.js +246 -0
  369. package/dist/shared/{components-kvr7f9hy.js → components-qdm3yh26.js} +19 -10
  370. package/dist/shared/{components-27nnvrwe.js → components-qs4rkqsj.js} +15 -14
  371. package/dist/shared/{components-s083f38z.js → components-r6gbmkew.js} +22 -21
  372. package/dist/shared/{components-ta7shw28.js → components-r8eqs7gz.js} +4 -4
  373. package/dist/shared/{components-sn1rxx1d.js → components-rm02h9nt.js} +12 -11
  374. package/dist/shared/{components-c6s6b43g.js → components-rrbpmfx4.js} +3 -2
  375. package/dist/shared/{components-n7mjr357.js → components-tz1fv35x.js} +3 -2
  376. package/dist/shared/components-tz4gaf1v.js +23 -0
  377. package/dist/shared/{components-zx6b6yby.js → components-vf45j12c.js} +4 -18
  378. package/dist/shared/{components-3ky44908.js → components-vfjc9jzz.js} +2 -3
  379. package/dist/shared/{components-39vmfq9s.js → components-vsa625vk.js} +21 -20
  380. package/dist/shared/components-wawnmkph.js +500 -0
  381. package/dist/shared/components-wktrrb4m.js +38 -0
  382. package/dist/shared/{components-8snj490h.js → components-wwd363me.js} +78 -32
  383. package/dist/shared/{components-5pnw8183.js → components-xcwvgcrd.js} +23 -22
  384. package/dist/shared/components-xdqmt6ed.js +20 -0
  385. package/dist/shared/{components-h2ajmhwn.js → components-y1w3a6wx.js} +107 -35
  386. package/dist/shared/{components-ar66gnt0.js → components-y6578b8h.js} +37 -34
  387. package/dist/shared/{components-59efxjd9.js → components-yhgq0qxx.js} +13 -12
  388. package/dist/shared/{components-jthe1pwb.js → components-yz84gpkq.js} +101 -404
  389. package/dist/shared/components-z3v0n0de.js +11 -0
  390. package/dist/shared/{components-7r3etddy.js → components-z9n19fyk.js} +19 -54
  391. package/dist/shared/components-zbvjzh1p.js +141 -0
  392. package/dist/styles.css +241 -16
  393. package/dist/tailwind.css +13 -0
  394. package/dist/tokens.css +34 -0
  395. package/index.ts +60 -0
  396. package/lib/date-locale.ts +50 -0
  397. package/lib/field-classes.ts +115 -0
  398. package/lib/field-variants.ts +117 -0
  399. package/lib/fluid-hover-highlight.tsx +139 -0
  400. package/lib/focus-ring.tsx +46 -0
  401. package/lib/goo-indicator.tsx +261 -0
  402. package/lib/icon-context.tsx +310 -0
  403. package/lib/inert.ts +22 -0
  404. package/lib/morph-layers.tsx +102 -0
  405. package/lib/morph-part.tsx +49 -0
  406. package/lib/popup.ts +52 -0
  407. package/lib/reduced-motion.ts +19 -0
  408. package/lib/row-index.tsx +29 -0
  409. package/lib/row-order.tsx +115 -0
  410. package/lib/scroll-column.tsx +244 -0
  411. package/lib/shape-context.tsx +124 -0
  412. package/lib/size-context.tsx +66 -0
  413. package/lib/size-scale.ts +115 -0
  414. package/lib/slot.ts +25 -0
  415. package/lib/springs.ts +62 -0
  416. package/lib/surface-classes.ts +58 -0
  417. package/lib/surface-context.tsx +21 -0
  418. package/lib/use-controllable-state.ts +44 -0
  419. package/lib/use-fluid-hover.ts +541 -0
  420. package/lib/use-is-mobile.ts +25 -0
  421. package/lib/use-keyboard-nav-gate.ts +45 -0
  422. package/lib/use-merge-split.tsx +209 -0
  423. package/lib/use-morph.ts +557 -0
  424. package/lib/use-touch-primary.tsx +43 -0
  425. package/lib/utils.ts +37 -0
  426. package/package.json +177 -4
  427. package/preset.ts +196 -0
  428. package/primitives/code/examples.mdx +27 -0
  429. package/primitives/code/index.tsx +80 -0
  430. package/primitives/craft/demos.tsx +173 -0
  431. package/primitives/craft/examples.mdx +138 -0
  432. package/primitives/craft/index.tsx +76 -0
  433. package/primitives/fluid-hover/examples.mdx +84 -0
  434. package/primitives/fluid-hover/index.tsx +316 -0
  435. package/primitives/morph/examples.mdx +135 -0
  436. package/primitives/morph/index.tsx +192 -0
  437. package/primitives/motion/examples.mdx +100 -0
  438. package/primitives/motion/index.tsx +160 -0
  439. package/primitives/scroll-area/examples.mdx +58 -0
  440. package/primitives/scroll-area/index.tsx +200 -0
  441. package/primitives/separator/examples.mdx +30 -0
  442. package/primitives/separator/index.tsx +53 -0
  443. package/primitives/sizes/examples.mdx +167 -0
  444. package/primitives/sizes/index.tsx +89 -0
  445. package/primitives/skeleton/examples.mdx +51 -0
  446. package/primitives/skeleton/index.tsx +72 -0
  447. package/primitives/skeleton/skeleton.css +15 -0
  448. package/primitives/surface/examples.mdx +173 -0
  449. package/primitives/surface/index.tsx +109 -0
  450. package/primitives/surface/surface.css +176 -0
  451. package/dist/shared/components-0sn7ypjw.js +0 -61
  452. package/dist/shared/components-1434p1mh.js +0 -123
  453. package/dist/shared/components-a86dytt0.js +0 -986
  454. package/dist/shared/components-gf5s6ap9.js +0 -42
  455. package/dist/shared/components-hyq23phv.js +0 -310
  456. package/dist/shared/components-ng72k97e.js +0 -128
  457. package/dist/shared/components-raknhppb.js +0 -64
  458. package/dist/shared/components-vynjtrk6.js +0 -19
  459. package/dist/shared/components-wy9jpqny.js +0 -146
  460. /package/dist/shared/{components-1v7rxytx.js → components-3ey0hzpb.js} +0 -0
  461. /package/dist/shared/{components-ezxhrmer.js → components-jcnjay5g.js} +0 -0
@@ -0,0 +1,1955 @@
1
+ // biome-ignore-all lint: vendored upstream code keeps its own patterns (see the header)
2
+ /*
3
+ * Ported from Fluid Functionalism — github.com/mickadesign/fluid-functionalism
4
+ * `registry/default/color-picker.tsx` @ b3587bdbd83fc66c2a6aae3817ffb856cb09260b
5
+ * MIT License © 2026 Micka Touillaud — fluidfunctionalism.com (notice: LICENSE.fluid-functionalism)
6
+ * Local modifications:
7
+ * - `"use client"` dropped; `@/lib/*`, `@/hooks/*` and
8
+ * `@/components/ui/fluid-hover-highlight` → `../../../lib/*` (`SizeProvider`
9
+ * → `../../../primitives/sizes`), `@/lib/elevated` → `../../../primitives/surface`,
10
+ * `framer-motion` → `motion/react`.
11
+ * - `@/registry/radix/{slider,tooltip}` → the Base-flavor siblings `../slider`
12
+ * and `../../overlays/tooltip` (same `value`/`onChange`/`trackStyle`/`hideFill`/
13
+ * `thumbColor` and `content`/`delayDuration` APIs).
14
+ * - `noUncheckedIndexedAccess` guards: regex capture groups and the numeric
15
+ * parts of `rgb()`/`hsl()`/`oklch()` read through non-null assertions or a
16
+ * local (the alpha part), `itemRects[i]` reads fall back to `null`, and the
17
+ * Slider's array value reads `v[0] ?? 0`.
18
+ * - Prop JSDoc on `ColorPickerProps` / `ColorPickerPopoverProps` rewritten from
19
+ * the FF docs API tables; `className` re-declared so it is documented (modo's
20
+ * parser lists only members declared in the interface body).
21
+ * - modo item: TSDoc and examples on `ColorPicker`, the compound static
22
+ * `ColorPicker.Popover` attached with `Object.assign` and typed through a
23
+ * `ColorPickerComponent` cast on the forwardRef, plus a default export.
24
+ * Upstream's named exports and exported types are kept.
25
+ * - Styling reads DS tokens (AGENTS.md styling): `text-[Npx]` →
26
+ * `text-<role>[-compact]`; inline `fontVariationSettings` → `weight-*`; the
27
+ * hex focus-ring fallback → `ring-focus-ring` / `border-focus-ring`;
28
+ * literal colors → color tokens; `duration-80|120|160` and tier-length JS
29
+ * durations → `duration-<tier>` / `spring.*`.
30
+ * - The white and black thumb rings, shadows and scrub cursor → `--picker-*`
31
+ * tokens. Colors the picker shows (values, swatches, the S/V and hue
32
+ * gradients) and the canvas parse sentinels stay literal: they are color
33
+ * data, not styling.
34
+ * - `ColorPicker.Popover` and the format menu morph out of their triggers
35
+ * through the shared morph layer (`lib/use-morph.ts` + `MorphSurface`, goo
36
+ * by default on `spring.goo`; the popover takes `from` / `effect` /
37
+ * `hideSource` / `tier`, the menu's plain morph is on `spring.moderate`), the origin captured
38
+ * from each Base UI root's `onOpenChange`. Their `actionsRef` deferred
39
+ * unmounts, fallback timers and motion wrappers are gone: Popover and Menu
40
+ * ignore `actionsRef`, and the wrappers animated outside the popup, so Base
41
+ * UI unmounted both on the first frame of a close. The popover's panel
42
+ * paints no surface of its own (a private `PanelSurfaceContext`): the
43
+ * morph's surface layers paint its level; the menu's do the same in place of
44
+ * `render={<Elevated/>}`.
45
+ * - `effect="morph"` with `hideSource` opens the popover in place over its
46
+ * trigger: the positioner's `sideOffset` becomes the engine's `inPlaceOffset`.
47
+ * - The color types and math (`parseColor`, `buildParsed`, conversions) moved
48
+ * to `variants.ts` (server-callable, no JSX or hooks) and re-exported here.
49
+ */
50
+
51
+ import { Menu } from '@base-ui/react/menu'
52
+ import { NumberField } from '@base-ui/react/number-field'
53
+ import { Popover } from '@base-ui/react/popover'
54
+ import { AnimatePresence, motion } from 'motion/react'
55
+ import {
56
+ type CSSProperties,
57
+ createContext,
58
+ type ForwardRefExoticComponent,
59
+ forwardRef,
60
+ type HTMLAttributes,
61
+ type ReactNode,
62
+ type RefAttributes,
63
+ type RefObject,
64
+ useCallback,
65
+ useContext,
66
+ useEffect,
67
+ useMemo,
68
+ useRef,
69
+ useState,
70
+ } from 'react'
71
+ import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
72
+ import { useIcon } from '../../../lib/icon-context'
73
+ import { MorphSurface } from '../../../lib/morph-layers'
74
+ import { shapeMap, useShape } from '../../../lib/shape-context'
75
+ import { type SizeVariant, useSize } from '../../../lib/size-context'
76
+ import { spring } from '../../../lib/springs'
77
+ import { SURFACE_BG, SURFACE_SHADOW, surfaceClasses } from '../../../lib/surface-classes'
78
+ import { SurfaceProvider, useSurface } from '../../../lib/surface-context'
79
+ import { useFluidHover, useRegisterFluidHoverItem } from '../../../lib/use-fluid-hover'
80
+ import { inPlaceOffset, opensInPlace, useMorph, useMorphOrigin } from '../../../lib/use-morph'
81
+ import { cn } from '../../../lib/utils'
82
+ import { SizeProvider } from '../../../primitives/sizes'
83
+ import { Tooltip } from '../../overlays/tooltip'
84
+ import { Slider } from '../slider'
85
+ import {
86
+ buildParsed,
87
+ type ColorFormat,
88
+ clamp01,
89
+ formatValueByFormat,
90
+ hslToRgb,
91
+ hsvToRgb,
92
+ oklchToRgb,
93
+ type ParsedColor,
94
+ parseColor,
95
+ resolveCssColor,
96
+ rgbToHexStr,
97
+ rgbToHsl,
98
+ rgbToHsv,
99
+ rgbToOklch,
100
+ } from './variants'
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // Types
104
+ // ---------------------------------------------------------------------------
105
+
106
+ // Allows consumers (e.g. the /demo carousel) to portal popups inside a
107
+ // CSS-scaled ancestor so menu/popover layers visually scale with the picker.
108
+ const ColorPickerPortalContainerContext = createContext<HTMLElement | null>(null)
109
+
110
+ function ColorPickerPortalContainer({ value, children }: { value: HTMLElement | null; children: ReactNode }) {
111
+ return (
112
+ <ColorPickerPortalContainerContext.Provider value={value}>{children}</ColorPickerPortalContainerContext.Provider>
113
+ )
114
+ }
115
+
116
+ // False inside ColorPicker.Popover, whose morph layers paint the panel's
117
+ // surface; the panel then paints none of its own.
118
+ const PanelSurfaceContext = createContext(true)
119
+
120
+ interface ColorPickerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
121
+ /** Controlled color value, in any of the supported formats. Omit it to let the picker keep its own state, seeded from `defaultValue`. */
122
+ value?: string
123
+ /** Initial color when uncontrolled — any CSS color string, named colors included. Defaults to `"#6B97FF"`. */
124
+ defaultValue?: string
125
+ /** Fired on every change. Receives the formatted string and a parsed color object carrying every format. */
126
+ onValueChange?: (value: string, parsed: ParsedColor) => void
127
+ /** Controlled format selection. */
128
+ format?: ColorFormat
129
+ /** Initial format when uncontrolled. Defaults to `"hex"`. */
130
+ defaultFormat?: ColorFormat
131
+ /** Fired when the user switches format. */
132
+ onFormatChange?: (format: ColorFormat) => void
133
+ /** Optional preset swatches. When omitted, the strip is hidden. */
134
+ swatches?: string[]
135
+ /** Force-hide the eyedropper button — it is hidden automatically in browsers that do not support it. Defaults to `false`. */
136
+ hideEyedropper?: boolean
137
+ /** Controls the format dropdown's open state. When provided, the dropdown is fully controlled and ignores user toggles. */
138
+ formatOpen?: boolean
139
+ /** Initial open state for the format dropdown (uncontrolled). Defaults to `false`. */
140
+ defaultFormatOpen?: boolean
141
+ /** Pins trigger and popover to one step of the size ladder (default 36px, compact 28px — see Sizes). Omitted, they follow the surrounding SizeProvider. */
142
+ size?: SizeVariant
143
+ /** Merged after the panel's surface, radius and padding classes. */
144
+ className?: string
145
+ }
146
+
147
+ interface ColorPickerPopoverProps extends ColorPickerProps {
148
+ /** Optional label rendered alongside the color tile. */
149
+ triggerLabel?: string
150
+ /** Position of the label relative to the color tile. Defaults to `"left"`. */
151
+ triggerLabelPosition?: 'left' | 'right'
152
+ /** Show the hex value (without alpha) next to the tile. Defaults to `true`. */
153
+ triggerShowValue?: boolean
154
+ /** Render an X button on the trigger; pairs with `onTriggerRemove`. Defaults to `false`. */
155
+ triggerShowRemove?: boolean
156
+ /** Fired when the X button is clicked. */
157
+ onTriggerRemove?: () => void
158
+ /** Custom classes on the trigger button. */
159
+ triggerClassName?: string
160
+ /** Controls the popover's open state. When provided, the popover is fully
161
+ * controlled and ignores trigger clicks. */
162
+ open?: boolean
163
+ /** Initial open state for the popover (uncontrolled). Defaults to `false`. */
164
+ defaultOpen?: boolean
165
+ /** Called when the open state would change (fires even when controlled). */
166
+ onOpenChange?: (open: boolean) => void
167
+ /** Where the panel grows from (see Morph): the trigger, the press point, its own center, a viewport edge, or a ref to any element. Defaults to `'trigger'`. */
168
+ from?: 'trigger' | 'pointer' | 'center' | 'top' | 'right' | 'bottom' | 'left' | RefObject<HTMLElement | null>
169
+ /** How it grows (see Morph): with the liquid goo neck, a plain morph, a slide or a fade. Defaults to `'goo'`. */
170
+ effect?: 'goo' | 'morph' | 'slide' | 'fade'
171
+ /** Hide the trigger while open, so it reads as turning into the panel. Defaults to `false`. */
172
+ hideSource?: boolean
173
+ /** Spring tier of a plain morph, slide or fade; goo runs on its own `spring.goo`. Defaults to `'slow'`. */
174
+ tier?: 'moderate' | 'slow'
175
+ }
176
+
177
+ interface ColorSwatchProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'color'> {
178
+ /** The swatch color — any CSS color string. */
179
+ color: string
180
+ /** Edge length in pixels. Defaults to `28`. */
181
+ size?: number
182
+ /** Draws the selection ring. */
183
+ selected?: boolean
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // Constants
188
+ // ---------------------------------------------------------------------------
189
+
190
+ const PANEL_WIDTH = 280
191
+ const SQUARE_HEIGHT = 156
192
+ const CHECKER_BG: CSSProperties = {
193
+ backgroundImage:
194
+ 'conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%, var(--checker-a) 0 75%, var(--checker-b) 0)',
195
+ backgroundSize: '8px 8px',
196
+ }
197
+
198
+ // ---------------------------------------------------------------------------
199
+ // SaturationSquare
200
+ // ---------------------------------------------------------------------------
201
+
202
+ interface SaturationSquareProps {
203
+ h: number
204
+ s: number
205
+ v: number
206
+ onChange: (s: number, v: number) => void
207
+ }
208
+
209
+ function SaturationSquare({ h, s, v, onChange }: SaturationSquareProps) {
210
+ const ref = useRef<HTMLDivElement>(null)
211
+ // State (not a ref): this gates the ghost hover cursor during render, and a
212
+ // ref mutation wouldn't re-render, letting the ghost stick around.
213
+ const [dragging, setDragging] = useState(false)
214
+ const hasMoved = useRef(false)
215
+ const [focused, setFocused] = useState(false)
216
+ const [hovered, setHovered] = useState(false)
217
+ const [cursorPos, setCursorPos] = useState<{ x: number; y: number } | null>(null)
218
+ const shape = useShape()
219
+
220
+ const updateFromPointer = useCallback(
221
+ (clientX: number, clientY: number) => {
222
+ const rect = ref.current?.getBoundingClientRect()
223
+ if (!rect) return
224
+ const x = clamp01((clientX - rect.left) / rect.width)
225
+ const y = clamp01((clientY - rect.top) / rect.height)
226
+ onChange(x, 1 - y)
227
+ },
228
+ [onChange],
229
+ )
230
+
231
+ const updateCursorPos = useCallback((clientX: number, clientY: number) => {
232
+ const rect = ref.current?.getBoundingClientRect()
233
+ if (!rect) return
234
+ setCursorPos({
235
+ x: clamp01((clientX - rect.left) / rect.width) * 100,
236
+ y: clamp01((clientY - rect.top) / rect.height) * 100,
237
+ })
238
+ }, [])
239
+
240
+ const onPointerDown = useCallback(
241
+ (e: React.PointerEvent<HTMLDivElement>) => {
242
+ if (e.pointerType === 'mouse' && e.button !== 0) return
243
+ e.preventDefault()
244
+ setDragging(true)
245
+ hasMoved.current = false
246
+ ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
247
+ updateFromPointer(e.clientX, e.clientY)
248
+ },
249
+ [updateFromPointer],
250
+ )
251
+
252
+ const onPointerMove = useCallback(
253
+ (e: React.PointerEvent<HTMLDivElement>) => {
254
+ updateCursorPos(e.clientX, e.clientY)
255
+ if (!dragging) return
256
+ hasMoved.current = true
257
+ updateFromPointer(e.clientX, e.clientY)
258
+ },
259
+ [dragging, updateFromPointer, updateCursorPos],
260
+ )
261
+
262
+ const onPointerUp = useCallback(() => {
263
+ setDragging(false)
264
+ hasMoved.current = false
265
+ }, [])
266
+
267
+ const onKeyDown = useCallback(
268
+ (e: React.KeyboardEvent<HTMLDivElement>) => {
269
+ const step = e.shiftKey ? 0.1 : 0.01
270
+ let nextS = s,
271
+ nextV = v,
272
+ handled = true
273
+ if (e.key === 'ArrowLeft') nextS = clamp01(s - step)
274
+ else if (e.key === 'ArrowRight') nextS = clamp01(s + step)
275
+ else if (e.key === 'ArrowUp') nextV = clamp01(v + step)
276
+ else if (e.key === 'ArrowDown') nextV = clamp01(v - step)
277
+ else handled = false
278
+ if (handled) {
279
+ e.preventDefault()
280
+ onChange(nextS, nextV)
281
+ }
282
+ },
283
+ [onChange, s, v],
284
+ )
285
+
286
+ const { r, g, b } = hsvToRgb(h, s, v)
287
+ const thumbColor = `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`
288
+
289
+ return (
290
+ <div
291
+ ref={ref}
292
+ role="application"
293
+ aria-label="Saturation and brightness"
294
+ tabIndex={0}
295
+ onFocus={e => {
296
+ if (e.currentTarget.matches(':focus-visible')) setFocused(true)
297
+ }}
298
+ onBlur={() => setFocused(false)}
299
+ onPointerEnter={() => setHovered(true)}
300
+ onPointerLeave={() => {
301
+ setHovered(false)
302
+ setCursorPos(null)
303
+ }}
304
+ onPointerDown={onPointerDown}
305
+ onPointerMove={onPointerMove}
306
+ onPointerUp={onPointerUp}
307
+ onKeyDown={onKeyDown}
308
+ className={cn(
309
+ 'relative w-full select-none touch-none cursor-none outline-none',
310
+ focused && 'ring-2 ring-focus-ring',
311
+ shape.bg,
312
+ )}
313
+ style={{
314
+ height: SQUARE_HEIGHT,
315
+ }}
316
+ >
317
+ <div
318
+ className={cn('absolute inset-0 overflow-hidden', shape.bg === 'rounded-[20px]' ? 'rounded-2xl' : shape.bg)}
319
+ style={{
320
+ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${h}, 100%, 50%))`,
321
+ }}
322
+ />
323
+ <motion.div
324
+ className="absolute pointer-events-none rounded-full border border-thumb shadow-picker-thumb"
325
+ initial={false}
326
+ animate={{
327
+ left: `${s * 100}%`,
328
+ top: `${(1 - v) * 100}%`,
329
+ width: 18,
330
+ height: 18,
331
+ }}
332
+ transition={{ duration: 0 }}
333
+ style={{
334
+ transform: 'translate(-50%, -50%)',
335
+ backgroundColor: thumbColor,
336
+ }}
337
+ />
338
+ {hovered && !dragging && cursorPos && (
339
+ <div
340
+ className="absolute pointer-events-none rounded-full border-2 border-picker-ring shadow-picker-cursor"
341
+ style={{
342
+ left: `${cursorPos.x}%`,
343
+ top: `${cursorPos.y}%`,
344
+ width: 18,
345
+ height: 18,
346
+ transform: 'translate(-50%, -50%)',
347
+ }}
348
+ />
349
+ )}
350
+ </div>
351
+ )
352
+ }
353
+
354
+ // ---------------------------------------------------------------------------
355
+ // HueSlider
356
+ // ---------------------------------------------------------------------------
357
+
358
+ function HueSlider({ h, onChange }: { h: number; onChange: (h: number) => void }) {
359
+ const hueColor = `hsl(${h}, 100%, 50%)`
360
+ return (
361
+ <Slider
362
+ value={h}
363
+ onChange={v => onChange(typeof v === 'number' ? v : (v[0] ?? 0))}
364
+ min={0}
365
+ max={360}
366
+ step={1}
367
+ showValue={false}
368
+ hideFill
369
+ thumbColor={hueColor}
370
+ thumbBorderColor="var(--picker-thumb-border)"
371
+ trackStyle={{
372
+ background:
373
+ 'linear-gradient(to right, hsl(0,100%,50%), hsl(60,100%,50%), hsl(120,100%,50%), hsl(180,100%,50%), hsl(240,100%,50%), hsl(300,100%,50%), hsl(360,100%,50%))',
374
+ borderColor: 'transparent',
375
+ }}
376
+ aria-label="Hue"
377
+ />
378
+ )
379
+ }
380
+
381
+ // ---------------------------------------------------------------------------
382
+ // AlphaSlider
383
+ // ---------------------------------------------------------------------------
384
+
385
+ function AlphaSlider({
386
+ a,
387
+ solidColor,
388
+ solidR,
389
+ solidG,
390
+ solidB,
391
+ onChange,
392
+ }: {
393
+ a: number
394
+ solidColor: string
395
+ solidR: number
396
+ solidG: number
397
+ solidB: number
398
+ onChange: (a: number) => void
399
+ }) {
400
+ // Use color-aware transparent stop (same hue, alpha 0) so the gradient stays
401
+ // chromatically consistent and reaches fully opaque at 100% with no edge gap.
402
+ const transparentColor = `rgba(${solidR}, ${solidG}, ${solidB}, 0)`
403
+ return (
404
+ <Slider
405
+ value={Math.round(a * 100)}
406
+ onChange={v => onChange((typeof v === 'number' ? v : (v[0] ?? 0)) / 100)}
407
+ min={0}
408
+ max={100}
409
+ step={1}
410
+ showValue={false}
411
+ hideFill
412
+ thumbColor={solidColor}
413
+ thumbBorderColor="var(--picker-thumb-border)"
414
+ trackStyle={{
415
+ backgroundImage: `linear-gradient(to right, ${transparentColor} 0%, ${solidColor} 98%), conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%, var(--checker-a) 0 75%, var(--checker-b) 0)`,
416
+ backgroundSize: '100% 100%, 8px 8px',
417
+ borderWidth: 0,
418
+ }}
419
+ aria-label="Alpha"
420
+ />
421
+ )
422
+ }
423
+
424
+ // ---------------------------------------------------------------------------
425
+ // FormatDropdown
426
+ //
427
+ // Built on Base UI's Menu primitive, which owns trigger wiring, positioning
428
+ // (anchor tracking + collision flipping — the old hand-rolled version computed
429
+ // coordinates once on open and detached from the trigger on scroll),
430
+ // dismissal, roving highlight, and typeahead. Menu.RadioGroup/RadioItem carry
431
+ // the radio semantics. This layer keeps the fluid-hover
432
+ // overlays and the morph open/close (lib/use-morph.ts) — the same pattern as
433
+ // select.tsx / dropdown.tsx.
434
+ // ---------------------------------------------------------------------------
435
+
436
+ const FORMAT_LABELS: Record<ColorFormat, string> = {
437
+ hex: 'HEX',
438
+ rgb: 'RGB',
439
+ hsl: 'HSL',
440
+ oklch: 'OKLCH',
441
+ }
442
+
443
+ const FORMATS = ['hex', 'rgb', 'hsl', 'oklch'] as const
444
+
445
+ // Popup surfaces opt out of the global pill/rounded shape — same rationale as
446
+ // the Dropdown component (pill radii distort perceived padding at this scale).
447
+ const menuShape = shapeMap.rounded
448
+
449
+ interface FormatMenuContextValue {
450
+ registerItem: (index: number, element: HTMLElement | null) => void
451
+ activeIndex: number | null
452
+ checkedIndex?: number
453
+ }
454
+
455
+ const FormatMenuContext = createContext<FormatMenuContextValue | null>(null)
456
+
457
+ function FormatItem({
458
+ index,
459
+ value,
460
+ label,
461
+ checked,
462
+ }: {
463
+ index: number
464
+ value: ColorFormat
465
+ label: string
466
+ checked: boolean
467
+ }) {
468
+ const ref = useRef<HTMLDivElement>(null)
469
+ const menuCtx = useContext(FormatMenuContext)
470
+ const shape = useShape()
471
+ const sizeClasses = useSize()
472
+ const compact = sizeClasses.variant === 'compact'
473
+
474
+ useRegisterFluidHoverItem(menuCtx?.registerItem, index, ref)
475
+
476
+ const isActive = menuCtx?.activeIndex === index
477
+
478
+ return (
479
+ <Menu.RadioItem
480
+ value={value}
481
+ label={label}
482
+ closeOnClick
483
+ render={
484
+ <div
485
+ ref={ref}
486
+ data-fluid-hover-index={index}
487
+ className={cn(
488
+ 'relative z-10 flex items-center cursor-pointer outline-none',
489
+ compact ? 'px-2.5 py-1.5' : 'px-3 py-2',
490
+ sizeClasses.text,
491
+ shape.item,
492
+ )}
493
+ />
494
+ }
495
+ >
496
+ <span className="inline-grid">
497
+ <span className="col-start-1 row-start-1 invisible weight-semibold" aria-hidden="true">
498
+ {label}
499
+ </span>
500
+ <span
501
+ className={cn(
502
+ 'col-start-1 row-start-1 transition-[color,font-variation-settings] duration-fast',
503
+ isActive || checked ? 'text-foreground' : 'text-muted-foreground',
504
+ checked ? 'weight-semibold' : 'weight-normal',
505
+ )}
506
+ >
507
+ {label}
508
+ </span>
509
+ </span>
510
+ </Menu.RadioItem>
511
+ )
512
+ }
513
+
514
+ function FormatDropdown({
515
+ value,
516
+ onChange,
517
+ open: openProp,
518
+ defaultOpen = false,
519
+ }: {
520
+ value: ColorFormat
521
+ onChange: (f: ColorFormat) => void
522
+ open?: boolean
523
+ defaultOpen?: boolean
524
+ }) {
525
+ const [internalOpen, setInternalOpen] = useState(defaultOpen)
526
+ const isControlled = openProp !== undefined
527
+ const open = isControlled ? openProp : internalOpen
528
+ const { origin, capture } = useMorphOrigin()
529
+ const morph = useMorph(open, origin, { tier: 'moderate' })
530
+ // Lifts 2 levels off the panel with a fixed shadow (see Elevated).
531
+ const level = Math.min(useSurface() + 2, 8)
532
+ const shape = useShape()
533
+ const sizeClasses = useSize()
534
+ const portalContainer = useContext(ColorPickerPortalContainerContext)
535
+ const containerRef = useRef<HTMLDivElement>(null)
536
+ const ChevronDownIcon = useIcon('chevron-down')
537
+
538
+ const hover = useFluidHover(containerRef)
539
+ const { activeIndex, setActiveIndex, itemRects, handlers, registerItem, remeasure } = hover
540
+
541
+ const [focusedIndex, setFocusedIndex] = useState<number | null>(null)
542
+
543
+ // The popup keeps its rows registered between opens, so their rects
544
+ // were taken while it was hidden: re-measure once it is open and laid out.
545
+ useEffect(() => {
546
+ if (!open) return
547
+ remeasure()
548
+ }, [open, remeasure])
549
+
550
+ const checkedIndex = FORMATS.indexOf(value)
551
+ const checkedRect = checkedIndex !== -1 ? (itemRects[checkedIndex] ?? null) : null
552
+ const focusRect = focusedIndex !== null ? (itemRects[focusedIndex] ?? null) : null
553
+ const menuCtx = useMemo(
554
+ () => ({ registerItem, activeIndex, checkedIndex }),
555
+ [registerItem, activeIndex, checkedIndex],
556
+ )
557
+
558
+ return (
559
+ <Menu.Root
560
+ open={open}
561
+ onOpenChange={(next, details) => {
562
+ if (next) capture(details)
563
+ if (!isControlled) setInternalOpen(next)
564
+ }}
565
+ // Non-modal: the page keeps scrolling and the Positioner tracks the
566
+ // anchor, so the popup follows its trigger instead of detaching.
567
+ modal={false}
568
+ >
569
+ <Menu.Trigger
570
+ className={cn(
571
+ 'flex items-center justify-between bg-transparent hover:bg-hover hover:text-foreground transition-colors duration-fast outline-none focus-visible:ring-1 focus-visible:ring-focus-ring cursor-pointer',
572
+ sizeClasses.gap,
573
+ sizeClasses.control,
574
+ sizeClasses.px,
575
+ sizeClasses.text,
576
+ open ? 'bg-active text-foreground' : 'text-muted-foreground active:bg-active',
577
+ shape.input,
578
+ 'weight-medium',
579
+ )}
580
+ >
581
+ <span>{FORMAT_LABELS[value]}</span>
582
+ <ChevronDownIcon
583
+ size={14}
584
+ strokeWidth={1.5}
585
+ className={cn('text-muted-foreground transition-transform duration-150', open && 'rotate-180')}
586
+ />
587
+ </Menu.Trigger>
588
+ <Menu.Portal container={portalContainer ?? undefined}>
589
+ <Menu.Positioner side="bottom" align="start" sideOffset={6} className="z-[60] outline-none">
590
+ <FormatMenuContext.Provider value={menuCtx}>
591
+ <Menu.Popup
592
+ ref={morph.popupRef}
593
+ onMouseEnter={() => {
594
+ handlers.onMouseEnter()
595
+ setFocusedIndex(null)
596
+ }}
597
+ onMouseMove={handlers.onMouseMove}
598
+ onMouseLeave={handlers.onMouseLeave}
599
+ onClick={handlers.onClick}
600
+ onFocus={e => {
601
+ const indexAttr = (e.target as HTMLElement)
602
+ .closest('[data-fluid-hover-index]')
603
+ ?.getAttribute('data-fluid-hover-index')
604
+ if (indexAttr != null) {
605
+ const idx = Number(indexAttr)
606
+ setActiveIndex(idx)
607
+ setFocusedIndex((e.target as HTMLElement).matches(':focus-visible') ? idx : null)
608
+ }
609
+ }}
610
+ onBlur={e => {
611
+ // The popup itself takes focus when the pointer leaves a row.
612
+ if (e.currentTarget.contains(e.relatedTarget as Node)) return
613
+ setFocusedIndex(null)
614
+ setActiveIndex(null)
615
+ }}
616
+ className="relative select-none outline-none"
617
+ >
618
+ <SurfaceProvider value={level}>
619
+ <MorphSurface
620
+ morph={morph}
621
+ bg={SURFACE_BG[level]}
622
+ shadow={SURFACE_SHADOW[3]}
623
+ radius={menuShape.container}
624
+ className="min-w-[var(--anchor-width)]"
625
+ >
626
+ <div ref={containerRef} className="relative flex flex-col p-1">
627
+ {/* Selected background */}
628
+ <AnimatePresence>
629
+ {checkedRect && (
630
+ <motion.div
631
+ className={`absolute ${menuShape.bg} bg-active pointer-events-none`}
632
+ initial={false}
633
+ animate={{
634
+ top: checkedRect.top,
635
+ left: checkedRect.left,
636
+ width: checkedRect.width,
637
+ height: checkedRect.height,
638
+ opacity: 1,
639
+ }}
640
+ exit={{ opacity: 0, transition: spring.moderate.exit }}
641
+ transition={{
642
+ ...spring.moderate,
643
+ opacity: { duration: spring.fast.duration },
644
+ }}
645
+ />
646
+ )}
647
+ </AnimatePresence>
648
+
649
+ {/* Hover background */}
650
+ <FluidHoverHighlight hover={hover} from={checkedRect} className={menuShape.bg} />
651
+
652
+ {/* Focus ring */}
653
+ <AnimatePresence>
654
+ {focusRect && (
655
+ <motion.div
656
+ className={`absolute ${menuShape.focusRing} pointer-events-none z-20 border border-focus-ring`}
657
+ initial={false}
658
+ animate={{
659
+ left: focusRect.left - 2,
660
+ top: focusRect.top - 2,
661
+ width: focusRect.width + 4,
662
+ height: focusRect.height + 4,
663
+ }}
664
+ exit={{ opacity: 0, transition: spring.fast.exit }}
665
+ transition={{
666
+ ...spring.fast,
667
+ opacity: { duration: spring.fast.duration },
668
+ }}
669
+ />
670
+ )}
671
+ </AnimatePresence>
672
+
673
+ {/* display: contents keeps items direct flex children of the
674
+ wrapper so fluid hover measurement and gap layout still work,
675
+ while the group provides the radio value context. */}
676
+ <Menu.RadioGroup
677
+ value={value}
678
+ onValueChange={next => onChange(next as ColorFormat)}
679
+ className="contents"
680
+ >
681
+ {FORMATS.map((fmt, i) => (
682
+ <FormatItem
683
+ key={fmt}
684
+ index={i}
685
+ value={fmt}
686
+ label={FORMAT_LABELS[fmt]}
687
+ checked={value === fmt}
688
+ />
689
+ ))}
690
+ </Menu.RadioGroup>
691
+ </div>
692
+ </MorphSurface>
693
+ </SurfaceProvider>
694
+ </Menu.Popup>
695
+ </FormatMenuContext.Provider>
696
+ </Menu.Positioner>
697
+ </Menu.Portal>
698
+ </Menu.Root>
699
+ )
700
+ }
701
+
702
+ // ---------------------------------------------------------------------------
703
+ // ColorInput
704
+ //
705
+ // Two internal variants behind one API:
706
+ // - TextColorInput: draft-based text input (hex).
707
+ // - ScrubColorInput: numeric channels, built on Base UI's NumberField whose
708
+ // ScrubArea provides pointer-lock scrubbing with a virtual cursor,
709
+ // replacing the old hand-rolled pointer-capture logic.
710
+ // ---------------------------------------------------------------------------
711
+
712
+ interface ColorInputProps {
713
+ value: string
714
+ onCommit: (next: string) => void
715
+ ariaLabel: string
716
+ width?: string
717
+ className?: string
718
+ inputClassName?: string
719
+ align?: 'left' | 'center' | 'right'
720
+ prefix?: ReactNode
721
+ inputMode?: 'numeric' | 'decimal' | 'text'
722
+ nudgeStep?: number
723
+ nudgeShiftStep?: number
724
+ hasPercent?: boolean
725
+ decimals?: number
726
+ scrubbable?: boolean
727
+ min?: number
728
+ max?: number
729
+ /** When true with min and max, wrap (modulo) instead of clamping. Used for angular values like hue. */
730
+ wrap?: boolean
731
+ }
732
+
733
+ const TextColorInput = forwardRef<HTMLInputElement, ColorInputProps>(
734
+ (
735
+ {
736
+ value,
737
+ onCommit,
738
+ ariaLabel,
739
+ width,
740
+ className,
741
+ inputClassName,
742
+ align = 'left',
743
+ prefix,
744
+ inputMode = 'text',
745
+ nudgeStep,
746
+ nudgeShiftStep,
747
+ hasPercent = false,
748
+ decimals,
749
+ min,
750
+ max,
751
+ wrap = false,
752
+ },
753
+ ref,
754
+ ) => {
755
+ const [draft, setDraft] = useState(value)
756
+ const interactingRef = useRef(false)
757
+ const shape = useShape()
758
+ const sizeClasses = useSize()
759
+ const compact = sizeClasses.variant === 'compact'
760
+
761
+ useEffect(() => {
762
+ if (!interactingRef.current) setDraft(value)
763
+ }, [value])
764
+
765
+ const formatNumber = (n: number) => (decimals != null ? n.toFixed(decimals) : String(Math.round(n)))
766
+
767
+ const commitNumber = (n: number) => {
768
+ let bounded = n
769
+ if (wrap && min != null && max != null) {
770
+ const range = max - min
771
+ bounded = ((((bounded - min) % range) + range) % range) + min
772
+ } else {
773
+ if (min != null) bounded = Math.max(min, bounded)
774
+ if (max != null) bounded = Math.min(max, bounded)
775
+ }
776
+ const formatted = formatNumber(bounded)
777
+ const withSuffix = hasPercent ? `${formatted}%` : formatted
778
+ setDraft(withSuffix)
779
+ onCommit(withSuffix)
780
+ }
781
+
782
+ const nudge = (direction: 1 | -1, shift: boolean) => {
783
+ const baseStep = shift ? (nudgeShiftStep ?? 10) : (nudgeStep ?? 1)
784
+ const cur = parseFloat(draft.replace('%', ''))
785
+ if (Number.isNaN(cur)) return
786
+ commitNumber(cur + direction * baseStep)
787
+ }
788
+
789
+ return (
790
+ <div
791
+ className={cn(
792
+ 'flex items-center px-2 bg-transparent hover:bg-hover active:bg-active transition-colors duration-fast focus-within:ring-1 focus-within:ring-focus-ring select-none',
793
+ sizeClasses.control,
794
+ shape.input,
795
+ className,
796
+ )}
797
+ style={{ width }}
798
+ >
799
+ {prefix && (
800
+ <span
801
+ className={cn('text-muted-foreground mr-1 select-none', compact ? 'text-caption-compact' : 'text-caption')}
802
+ >
803
+ {prefix}
804
+ </span>
805
+ )}
806
+ <input
807
+ ref={ref}
808
+ value={draft}
809
+ onChange={e => setDraft(e.target.value)}
810
+ onFocus={e => {
811
+ interactingRef.current = true
812
+ e.currentTarget.select()
813
+ }}
814
+ onBlur={() => {
815
+ interactingRef.current = false
816
+ if (draft !== value) {
817
+ const numeric = parseFloat(draft.replace('%', ''))
818
+ if (!Number.isNaN(numeric) && (min != null || max != null)) {
819
+ commitNumber(numeric)
820
+ } else {
821
+ onCommit(draft)
822
+ }
823
+ } else setDraft(value)
824
+ }}
825
+ onKeyDown={e => {
826
+ if (e.key === 'Enter') {
827
+ ;(e.currentTarget as HTMLInputElement).blur()
828
+ } else if (e.key === 'Escape') {
829
+ setDraft(value)
830
+ ;(e.currentTarget as HTMLInputElement).blur()
831
+ } else if (
832
+ (nudgeStep != null || nudgeShiftStep != null) &&
833
+ (e.key === 'ArrowUp' || e.key === 'ArrowDown')
834
+ ) {
835
+ e.preventDefault()
836
+ nudge(e.key === 'ArrowUp' ? 1 : -1, e.shiftKey)
837
+ }
838
+ }}
839
+ inputMode={inputMode}
840
+ aria-label={ariaLabel}
841
+ className={cn(
842
+ 'flex-1 min-w-0 bg-transparent text-foreground outline-none tabular-nums',
843
+ sizeClasses.text,
844
+ align === 'center' && 'text-center',
845
+ align === 'right' && 'text-right',
846
+ 'weight-medium',
847
+ inputClassName,
848
+ )}
849
+ />
850
+ </div>
851
+ )
852
+ },
853
+ )
854
+
855
+ TextColorInput.displayName = 'TextColorInput'
856
+
857
+ const ScrubColorInput = forwardRef<HTMLInputElement, ColorInputProps>(
858
+ (
859
+ {
860
+ value,
861
+ onCommit,
862
+ ariaLabel,
863
+ width,
864
+ className,
865
+ inputClassName,
866
+ align = 'left',
867
+ prefix,
868
+ inputMode = 'numeric',
869
+ nudgeStep,
870
+ nudgeShiftStep,
871
+ hasPercent = false,
872
+ decimals,
873
+ min,
874
+ max,
875
+ wrap = false,
876
+ },
877
+ ref,
878
+ ) => {
879
+ const shape = useShape()
880
+ const sizeClasses = useSize()
881
+ const compact = sizeClasses.variant === 'compact'
882
+ const inputRef = useRef<HTMLInputElement | null>(null)
883
+ const [editing, setEditing] = useState(false)
884
+ // Set on pointerdown inside the scrub area (capture phase, before Base UI
885
+ // focuses the input for scrubbing) so onFocus can tell scrub-focus apart
886
+ // from keyboard/programmatic focus.
887
+ const pointerDownRef = useRef(false)
888
+
889
+ const numeric = parseFloat(String(value).replace('%', ''))
890
+ const fieldValue = Number.isNaN(numeric) ? null : numeric
891
+
892
+ const format = useMemo(() => {
893
+ const f: Intl.NumberFormatOptions = { useGrouping: false }
894
+ if (decimals != null) {
895
+ f.minimumFractionDigits = decimals
896
+ f.maximumFractionDigits = decimals
897
+ } else {
898
+ f.maximumFractionDigits = 0
899
+ }
900
+ if (hasPercent) {
901
+ // style "unit" + unit "percent" renders "50%" while keeping the
902
+ // numeric value on the 0..100 scale (unlike style "percent").
903
+ f.style = 'unit'
904
+ f.unit = 'percent'
905
+ }
906
+ return f
907
+ }, [decimals, hasPercent])
908
+
909
+ const setInputRef = useCallback(
910
+ (node: HTMLInputElement | null) => {
911
+ inputRef.current = node
912
+ if (typeof ref === 'function') ref(node)
913
+ else if (ref) (ref as React.MutableRefObject<HTMLInputElement | null>).current = node
914
+ },
915
+ [ref],
916
+ )
917
+
918
+ const commit = useCallback(
919
+ (n: number) => {
920
+ let bounded = n
921
+ if (wrap && min != null && max != null) {
922
+ // Hue-style wrap: NumberField won't wrap natively, so shim it here
923
+ // (361 → 1, -1 → 359; exactly `max` stays put).
924
+ if (bounded < min || bounded > max) {
925
+ const range = max - min
926
+ bounded = ((((bounded - min) % range) + range) % range) + min
927
+ }
928
+ } else {
929
+ if (min != null) bounded = Math.max(min, bounded)
930
+ if (max != null) bounded = Math.min(max, bounded)
931
+ }
932
+ const formatted = decimals != null ? bounded.toFixed(decimals) : String(Math.round(bounded))
933
+ onCommit(hasPercent ? `${formatted}%` : formatted)
934
+ },
935
+ [wrap, min, max, decimals, hasPercent, onCommit],
936
+ )
937
+
938
+ return (
939
+ <NumberField.Root
940
+ value={fieldValue}
941
+ onValueChange={(next, eventDetails) => {
942
+ if (next == null) return
943
+ const reason = eventDetails.reason
944
+ // Preserve the old commit-on-blur typing semantics: ignore the
945
+ // per-keystroke parses and let the input-blur change land the final
946
+ // value. Keyboard nudges, scrubbing, and wheel commit immediately.
947
+ if (reason === 'input-change' || reason === 'input-paste' || reason === 'input-clear') {
948
+ return
949
+ }
950
+ commit(next)
951
+ }}
952
+ onValueCommitted={(_, eventDetails) => {
953
+ // After a scrub gesture ends, drop the focus Base UI placed on the
954
+ // input so the field returns to its rest state (matching the old
955
+ // behavior). For a no-drag press, ScrubArea dispatches a synthetic
956
+ // click right after this, which re-enters edit mode below.
957
+ if (eventDetails.reason === 'scrub') {
958
+ pointerDownRef.current = false
959
+ inputRef.current?.blur()
960
+ }
961
+ }}
962
+ min={wrap ? undefined : min}
963
+ max={wrap ? undefined : max}
964
+ step={nudgeStep ?? 1}
965
+ largeStep={nudgeShiftStep ?? 10}
966
+ format={format}
967
+ className={cn(
968
+ 'flex items-center bg-transparent hover:bg-hover active:bg-active transition-colors duration-fast focus-within:ring-1 focus-within:ring-focus-ring select-none',
969
+ sizeClasses.control,
970
+ shape.input,
971
+ className,
972
+ )}
973
+ style={{ width }}
974
+ >
975
+ <NumberField.ScrubArea
976
+ direction="horizontal"
977
+ pixelSensitivity={1}
978
+ onPointerDownCapture={() => {
979
+ pointerDownRef.current = true
980
+ }}
981
+ onClick={() => {
982
+ // Real clicks and the synthetic click ScrubArea dispatches after a
983
+ // no-drag press both land here → enter edit mode (focus + select),
984
+ // like the old click-to-edit behavior.
985
+ pointerDownRef.current = false
986
+ setEditing(true)
987
+ inputRef.current?.focus()
988
+ inputRef.current?.select()
989
+ }}
990
+ className={cn('flex flex-1 min-w-0 items-center self-stretch px-2', !editing && 'cursor-ew-resize')}
991
+ >
992
+ <NumberField.ScrubAreaCursor className="drop-shadow-picker-cursor">
993
+ <svg
994
+ width={24}
995
+ height={14}
996
+ viewBox="0 0 24 14"
997
+ className="fill-picker-edge stroke-thumb"
998
+ strokeWidth={1}
999
+ aria-hidden="true"
1000
+ >
1001
+ <path d="M0.5 7l5-5v3.5h13V2l5 5-5 5V8.5h-13V12l-5-5z" />
1002
+ </svg>
1003
+ </NumberField.ScrubAreaCursor>
1004
+ {prefix && (
1005
+ <span
1006
+ className={cn(
1007
+ 'text-muted-foreground mr-1 select-none',
1008
+ compact ? 'text-caption-compact' : 'text-caption',
1009
+ )}
1010
+ >
1011
+ {prefix}
1012
+ </span>
1013
+ )}
1014
+ <NumberField.Input
1015
+ ref={setInputRef}
1016
+ aria-label={ariaLabel}
1017
+ inputMode={inputMode}
1018
+ onPointerDown={e => {
1019
+ // While editing, let the input handle caret placement and text
1020
+ // selection itself instead of starting a scrub gesture.
1021
+ if (editing) e.stopPropagation()
1022
+ }}
1023
+ onFocus={e => {
1024
+ if (pointerDownRef.current) return // scrub-initiated focus
1025
+ setEditing(true)
1026
+ e.currentTarget.select()
1027
+ }}
1028
+ onBlur={() => {
1029
+ setEditing(false)
1030
+ }}
1031
+ onKeyDown={e => {
1032
+ if (e.key === 'Enter') {
1033
+ e.currentTarget.blur()
1034
+ } else if (e.key === 'Escape') {
1035
+ // Revert the draft like the old input: restore the committed
1036
+ // value's text before blurring so the input-blur commit is a
1037
+ // no-op.
1038
+ const input = e.currentTarget
1039
+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set
1040
+ if (setter && fieldValue != null) {
1041
+ const restored = decimals != null ? fieldValue.toFixed(decimals) : String(Math.round(fieldValue))
1042
+ setter.call(input, hasPercent ? `${restored}%` : restored)
1043
+ input.dispatchEvent(new Event('input', { bubbles: true }))
1044
+ }
1045
+ input.blur()
1046
+ }
1047
+ }}
1048
+ className={cn(
1049
+ 'flex-1 min-w-0 bg-transparent text-foreground outline-none tabular-nums',
1050
+ sizeClasses.text,
1051
+ align === 'center' && 'text-center',
1052
+ align === 'right' && 'text-right',
1053
+ !editing && 'pointer-events-none',
1054
+ 'weight-medium',
1055
+ inputClassName,
1056
+ )}
1057
+ />
1058
+ </NumberField.ScrubArea>
1059
+ </NumberField.Root>
1060
+ )
1061
+ },
1062
+ )
1063
+
1064
+ ScrubColorInput.displayName = 'ScrubColorInput'
1065
+
1066
+ const ColorInput = forwardRef<HTMLInputElement, ColorInputProps>(({ scrubbable = false, ...props }, ref) =>
1067
+ scrubbable ? <ScrubColorInput ref={ref} {...props} /> : <TextColorInput ref={ref} {...props} />,
1068
+ )
1069
+
1070
+ ColorInput.displayName = 'ColorInput'
1071
+
1072
+ // ---------------------------------------------------------------------------
1073
+ // EyeDropperButton
1074
+ //
1075
+ // `window.EyeDropper` is not in TypeScript's DOM lib, so the constructor is
1076
+ // read through a cast (upstream does the same) rather than a global
1077
+ // declaration — feature detection stays a runtime `in` check.
1078
+ // ---------------------------------------------------------------------------
1079
+
1080
+ interface EyeDropperGlobal {
1081
+ open(): Promise<{ sRGBHex: string }>
1082
+ }
1083
+
1084
+ function EyeDropperButton({ onPick }: { onPick: (hex: string) => void }) {
1085
+ const [supported, setSupported] = useState(false)
1086
+ const shape = useShape()
1087
+ const sizeClasses = useSize()
1088
+ const PipetteIcon = useIcon('pipette')
1089
+
1090
+ useEffect(() => {
1091
+ setSupported(typeof window !== 'undefined' && 'EyeDropper' in window)
1092
+ }, [])
1093
+
1094
+ if (!supported) return null
1095
+
1096
+ const handleClick = async () => {
1097
+ try {
1098
+ const Ctor = (window as unknown as { EyeDropper: new () => EyeDropperGlobal }).EyeDropper
1099
+ const eye = new Ctor()
1100
+ const result = await eye.open()
1101
+ onPick(result.sRGBHex)
1102
+ } catch {
1103
+ // user cancelled
1104
+ }
1105
+ }
1106
+
1107
+ return (
1108
+ <button
1109
+ type="button"
1110
+ onClick={handleClick}
1111
+ aria-label="Pick color from screen"
1112
+ className={cn(
1113
+ 'flex items-center justify-center text-muted-foreground bg-transparent hover:bg-hover hover:text-foreground active:bg-active transition-colors duration-fast outline-none focus-visible:ring-1 focus-visible:ring-focus-ring cursor-pointer',
1114
+ sizeClasses.control,
1115
+ sizeClasses.px,
1116
+ shape.input,
1117
+ )}
1118
+ >
1119
+ <PipetteIcon size={sizeClasses.icon} strokeWidth={1.5} />
1120
+ </button>
1121
+ )
1122
+ }
1123
+
1124
+ // ---------------------------------------------------------------------------
1125
+ // ColorTile (small colored square — checker behind alpha)
1126
+ // ---------------------------------------------------------------------------
1127
+
1128
+ interface ColorTileProps {
1129
+ color: string
1130
+ size?: number
1131
+ className?: string
1132
+ style?: CSSProperties
1133
+ }
1134
+
1135
+ function ColorTile({ color, size = 24, className, style }: ColorTileProps) {
1136
+ const shape = useShape()
1137
+ return (
1138
+ <span
1139
+ className={cn('inline-block relative shrink-0 overflow-hidden shadow-swatch', shape.bg, className)}
1140
+ style={{
1141
+ width: size,
1142
+ height: size,
1143
+ ...CHECKER_BG,
1144
+ ...style,
1145
+ }}
1146
+ >
1147
+ <span className="absolute inset-0" style={{ backgroundColor: color }} />
1148
+ </span>
1149
+ )
1150
+ }
1151
+
1152
+ // ---------------------------------------------------------------------------
1153
+ // ColorSwatch (clickable strip swatch)
1154
+ // ---------------------------------------------------------------------------
1155
+
1156
+ const ColorSwatch = forwardRef<HTMLButtonElement, ColorSwatchProps>(
1157
+ ({ color, size = 28, selected, className, onMouseEnter, onMouseLeave, ...props }, ref) => {
1158
+ const shape = useShape()
1159
+ const [hovered, setHovered] = useState(false)
1160
+ const ring = selected ? 'shadow-swatch-selected' : hovered ? 'shadow-swatch-hover' : 'shadow-swatch'
1161
+ return (
1162
+ <button
1163
+ ref={ref}
1164
+ type="button"
1165
+ aria-label={`Select color ${color}`}
1166
+ className={cn(
1167
+ 'relative shrink-0 overflow-hidden cursor-pointer outline-none transition-shadow duration-100',
1168
+ shape.bg,
1169
+ ring,
1170
+ className,
1171
+ )}
1172
+ style={{
1173
+ width: size,
1174
+ height: size,
1175
+ ...CHECKER_BG,
1176
+ }}
1177
+ onMouseEnter={e => {
1178
+ setHovered(true)
1179
+ onMouseEnter?.(e)
1180
+ }}
1181
+ onMouseLeave={e => {
1182
+ setHovered(false)
1183
+ onMouseLeave?.(e)
1184
+ }}
1185
+ {...props}
1186
+ >
1187
+ <span className="absolute inset-0" style={{ backgroundColor: color }} />
1188
+ </button>
1189
+ )
1190
+ },
1191
+ )
1192
+
1193
+ ColorSwatch.displayName = 'ColorSwatch'
1194
+
1195
+ // ---------------------------------------------------------------------------
1196
+ // SwatchStrip
1197
+ // ---------------------------------------------------------------------------
1198
+
1199
+ function SwatchStrip({
1200
+ swatches,
1201
+ current,
1202
+ onPick,
1203
+ }: {
1204
+ swatches: string[]
1205
+ current: string
1206
+ onPick: (color: string) => void
1207
+ }) {
1208
+ const normalizedCurrent = useMemo(() => {
1209
+ const p = parseColor(current)
1210
+ return p ? rgbToHexStr(p.r, p.g, p.b, p.a).toLowerCase() : ''
1211
+ }, [current])
1212
+
1213
+ // Named CSS colors ("red", "tomato") need the browser to normalize before
1214
+ // the selected-state comparison can match. Resolve them in an effect so
1215
+ // render (and SSR) never touch the DOM.
1216
+ const [resolvedSwatches, setResolvedSwatches] = useState<Record<string, string>>({})
1217
+ useEffect(() => {
1218
+ const next: Record<string, string> = {}
1219
+ for (const sw of swatches) {
1220
+ if (!parseColor(sw)) {
1221
+ const p = resolveCssColor(sw)
1222
+ if (p) next[sw] = rgbToHexStr(p.r, p.g, p.b, p.a).toLowerCase()
1223
+ }
1224
+ }
1225
+ setResolvedSwatches(next)
1226
+ }, [swatches])
1227
+
1228
+ return (
1229
+ <div className="flex flex-wrap gap-2">
1230
+ {swatches.map((sw, i) => {
1231
+ const parsed = parseColor(sw)
1232
+ const normalized = parsed
1233
+ ? rgbToHexStr(parsed.r, parsed.g, parsed.b, parsed.a).toLowerCase()
1234
+ : (resolvedSwatches[sw] ?? sw.toLowerCase())
1235
+ const isSelected = normalized === normalizedCurrent
1236
+ return <ColorSwatch key={`${sw}-${i}`} color={sw} size={28} selected={isSelected} onClick={() => onPick(sw)} />
1237
+ })}
1238
+ </div>
1239
+ )
1240
+ }
1241
+
1242
+ // ---------------------------------------------------------------------------
1243
+ // ColorPicker (panel)
1244
+ // ---------------------------------------------------------------------------
1245
+
1246
+ type ColorPickerComponent = ForwardRefExoticComponent<ColorPickerProps & RefAttributes<HTMLDivElement>> & {
1247
+ /** `ColorPickerPopover` — the same panel behind a trigger button. */
1248
+ Popover: typeof ColorPickerPopover
1249
+ }
1250
+
1251
+ /**
1252
+ * Color picker with HEX, RGB, HSL, and OKLCH formats, an alpha channel,
1253
+ * optional swatches, and an eyedropper. Available as an inline panel or a
1254
+ * popover.
1255
+ *
1256
+ * The value is kept internally as HSV, so hue survives a pass through pure
1257
+ * black, pure white or full grey instead of collapsing to red. Every edit —
1258
+ * the saturation square, the hue and alpha sliders, the per-channel inputs,
1259
+ * a swatch, the eyedropper — writes to that one canonical color, which is
1260
+ * re-emitted in the active format together with a parsed object carrying all
1261
+ * four. Numeric channels scrub: drag sideways to sweep a value, click to type
1262
+ * it. Alpha reads against a checkerboard, swatches accept any CSS color string
1263
+ * (named colors included), and OKLCH edits keep the hue you typed across the
1264
+ * lossy trip back through sRGB. The panel paints itself on the surface ladder
1265
+ * and re-provides its level, so the format menu elevates above it however
1266
+ * deeply the picker is nested.
1267
+ *
1268
+ * Statics:
1269
+ * - `ColorPicker.Popover` — `ColorPickerPopover`: the same panel behind a
1270
+ * trigger button showing a color tile, an optional label and the hex value.
1271
+ * The panel oozes out of the trigger and back through the shared morph (see
1272
+ * Morph), with the morph options `from`, `effect`, `hideSource`, `tier`.
1273
+ *
1274
+ * Also exported: `ColorSwatch` and `ColorTile` (the swatch button and the
1275
+ * checkerboard tile), `ColorPickerPortalContainer` (portal the format menu
1276
+ * into a given element — e.g. inside a CSS-scaled ancestor), and the
1277
+ * `parseColor` / `buildParsed` color helpers.
1278
+ *
1279
+ * @example {@include ./examples.mdx}
1280
+ */
1281
+ const ColorPicker = forwardRef<HTMLDivElement, ColorPickerProps>(
1282
+ (
1283
+ {
1284
+ value,
1285
+ defaultValue = '#6B97FF',
1286
+ onValueChange,
1287
+ format,
1288
+ defaultFormat = 'hex',
1289
+ onFormatChange,
1290
+ swatches,
1291
+ hideEyedropper,
1292
+ formatOpen,
1293
+ defaultFormatOpen,
1294
+ size,
1295
+ className,
1296
+ ...props
1297
+ },
1298
+ ref,
1299
+ ) => {
1300
+ const isControlled = value !== undefined
1301
+ const [internalValue, setInternalValue] = useState(value ?? defaultValue)
1302
+ const currentRawValue = isControlled ? (value as string) : internalValue
1303
+
1304
+ const isFormatControlled = format !== undefined
1305
+ const [internalFormat, setInternalFormat] = useState<ColorFormat>(defaultFormat)
1306
+ const currentFormat = isFormatControlled ? (format as ColorFormat) : internalFormat
1307
+
1308
+ // Internal HSV state (canonical). H is preserved across S=0 / V=0
1309
+ // transitions. Deliberately computed once from the initial value only.
1310
+ const initialParsed = useMemo(() => {
1311
+ const p = parseColor(currentRawValue)
1312
+ if (!p) return { h: 0, s: 1, v: 1, a: 1 }
1313
+ const hsv = rgbToHsv(p.r, p.g, p.b)
1314
+ return { h: hsv.s === 0 ? 0 : hsv.h, s: hsv.s, v: hsv.v, a: p.a }
1315
+ }, [])
1316
+
1317
+ const [hsv, setHsv] = useState(initialParsed)
1318
+
1319
+ // Sticky OKLCH hue: preserves the user's stated OKLCH H across the lossy
1320
+ // RGB round-trip (so the displayed H doesn't drift after release) and
1321
+ // across achromatic colors (where RGB-derived H would collapse to 0).
1322
+ // Cleared whenever the color changes through a non-OKLCH-internal channel.
1323
+ const oklchHueRef = useRef<number | null>(null)
1324
+
1325
+ // External value sync — when controlled value changes from outside, sync HSV
1326
+ const lastEmittedRef = useRef<string>('')
1327
+ useEffect(() => {
1328
+ if (!isControlled) return
1329
+ const emitted = lastEmittedRef.current
1330
+ const cur = value as string
1331
+ if (cur === emitted) return
1332
+ const p = parseColor(cur)
1333
+ if (!p) return
1334
+ oklchHueRef.current = null
1335
+ const newHsv = rgbToHsv(p.r, p.g, p.b)
1336
+ setHsv(prev => ({
1337
+ h: newHsv.s === 0 ? prev.h : newHsv.h,
1338
+ s: newHsv.s,
1339
+ v: newHsv.v,
1340
+ a: p.a,
1341
+ }))
1342
+ }, [value, isControlled])
1343
+
1344
+ const parsed = useMemo(() => buildParsed(hsv.h, hsv.s, hsv.v, hsv.a), [hsv])
1345
+
1346
+ const updateHsv = useCallback(
1347
+ (next: { h?: number; s?: number; v?: number; a?: number }) => {
1348
+ const merged = { ...hsv, ...next }
1349
+ setHsv(merged)
1350
+ const p = buildParsed(merged.h, merged.s, merged.v, merged.a)
1351
+ const formatted = formatValueByFormat(p, currentFormat)
1352
+ lastEmittedRef.current = formatted
1353
+ if (!isControlled) setInternalValue(formatted)
1354
+ onValueChange?.(formatted, p)
1355
+ },
1356
+ [hsv, currentFormat, isControlled, onValueChange],
1357
+ )
1358
+
1359
+ const handleFormatChange = useCallback(
1360
+ (f: ColorFormat) => {
1361
+ if (!isFormatControlled) setInternalFormat(f)
1362
+ onFormatChange?.(f)
1363
+ // Re-emit value in new format
1364
+ const formatted = formatValueByFormat(parsed, f)
1365
+ lastEmittedRef.current = formatted
1366
+ if (!isControlled) setInternalValue(formatted)
1367
+ onValueChange?.(formatted, parsed)
1368
+ },
1369
+ [isFormatControlled, isControlled, onFormatChange, onValueChange, parsed],
1370
+ )
1371
+
1372
+ const handleHexCommit = useCallback(
1373
+ (input: string) => {
1374
+ // resolveCssColor falls back to browser normalization so named CSS
1375
+ // colors ("red", "tomato") from swatches or the hex field work too.
1376
+ // Safe here: this only ever runs inside event handlers.
1377
+ const p = resolveCssColor(input)
1378
+ if (!p) return
1379
+ oklchHueRef.current = null
1380
+ const newHsv = rgbToHsv(p.r, p.g, p.b)
1381
+ const merged = {
1382
+ h: newHsv.s === 0 ? hsv.h : newHsv.h,
1383
+ s: newHsv.s,
1384
+ v: newHsv.v,
1385
+ a: p.a,
1386
+ }
1387
+ setHsv(merged)
1388
+ const next = buildParsed(merged.h, merged.s, merged.v, merged.a)
1389
+ const formatted = formatValueByFormat(next, currentFormat)
1390
+ lastEmittedRef.current = formatted
1391
+ if (!isControlled) setInternalValue(formatted)
1392
+ onValueChange?.(formatted, next)
1393
+ },
1394
+ [hsv.h, currentFormat, isControlled, onValueChange],
1395
+ )
1396
+
1397
+ const handleSwatchPick = useCallback(
1398
+ (sw: string) => {
1399
+ handleHexCommit(sw)
1400
+ },
1401
+ [handleHexCommit],
1402
+ )
1403
+
1404
+ const handleEyedrop = useCallback(
1405
+ (hex: string) => {
1406
+ handleHexCommit(hex)
1407
+ },
1408
+ [handleHexCommit],
1409
+ )
1410
+
1411
+ const solidHueRgb = useMemo(() => hsvToRgb(hsv.h, hsv.s, hsv.v), [hsv.h, hsv.s, hsv.v])
1412
+ const solidR = Math.round(solidHueRgb.r)
1413
+ const solidG = Math.round(solidHueRgb.g)
1414
+ const solidB = Math.round(solidHueRgb.b)
1415
+ const solidColorString = `rgb(${solidR}, ${solidG}, ${solidB})`
1416
+ const shape = useShape()
1417
+ const substrate = useSurface()
1418
+ // The picker panel uses bg-card (surface-3) by default; when wrapped in
1419
+ // ColorPickerPopover the className override pushes it higher. Either way,
1420
+ // announce the panel's effective level so descendants (FormatDropdown,
1421
+ // etc.) elevate above it instead of colliding at the same surface.
1422
+ const pickerLevel = Math.max(substrate, 3)
1423
+ const paintsSurface = useContext(PanelSurfaceContext)
1424
+
1425
+ // A size prop pins the whole panel — format dropdown, inputs, eyedropper
1426
+ // (React context crosses portals) — to one step of the ladder.
1427
+ const root = (
1428
+ <SurfaceProvider value={pickerLevel}>
1429
+ <div
1430
+ ref={ref}
1431
+ className={cn(
1432
+ 'flex flex-col gap-2 p-3',
1433
+ paintsSurface && surfaceClasses(pickerLevel, 1),
1434
+ shape.container,
1435
+ className,
1436
+ )}
1437
+ style={{ width: PANEL_WIDTH }}
1438
+ {...props}
1439
+ >
1440
+ <SaturationSquare h={hsv.h} s={hsv.s} v={hsv.v} onChange={(s, v) => updateHsv({ s, v })} />
1441
+
1442
+ <div className="flex flex-col [&>*]:mb-0 [&>*+*]:-mt-px">
1443
+ <HueSlider
1444
+ h={hsv.h}
1445
+ onChange={h => {
1446
+ oklchHueRef.current = null
1447
+ updateHsv({ h })
1448
+ }}
1449
+ />
1450
+ <AlphaSlider
1451
+ a={hsv.a}
1452
+ solidColor={solidColorString}
1453
+ solidR={solidR}
1454
+ solidG={solidG}
1455
+ solidB={solidB}
1456
+ onChange={a => updateHsv({ a })}
1457
+ />
1458
+ </div>
1459
+
1460
+ <div className="grid grid-cols-2 gap-2">
1461
+ <FormatDropdown
1462
+ value={currentFormat}
1463
+ onChange={handleFormatChange}
1464
+ open={formatOpen}
1465
+ defaultOpen={defaultFormatOpen}
1466
+ />
1467
+ {!hideEyedropper && <EyeDropperButton onPick={handleEyedrop} />}
1468
+ </div>
1469
+
1470
+ <ColorInputsRow
1471
+ parsed={parsed}
1472
+ format={currentFormat}
1473
+ oklchHue={oklchHueRef.current}
1474
+ onChannelChange={(channel, value) => {
1475
+ const p = { ...parsed }
1476
+ switch (channel) {
1477
+ case 'hex':
1478
+ handleHexCommit(value as string)
1479
+ return
1480
+ case 'r':
1481
+ case 'g':
1482
+ case 'b': {
1483
+ oklchHueRef.current = null
1484
+ const r = channel === 'r' ? Number(value) : p.r
1485
+ const g = channel === 'g' ? Number(value) : p.g
1486
+ const b = channel === 'b' ? Number(value) : p.b
1487
+ const hsvVal = rgbToHsv(r, g, b)
1488
+ updateHsv({
1489
+ h: hsvVal.s === 0 ? hsv.h : hsvVal.h,
1490
+ s: hsvVal.s,
1491
+ v: hsvVal.v,
1492
+ })
1493
+ return
1494
+ }
1495
+ case 'hSL':
1496
+ case 'sSL':
1497
+ case 'lSL': {
1498
+ if (channel === 'hSL') oklchHueRef.current = null
1499
+ const hsl = rgbToHsl(p.r, p.g, p.b)
1500
+ const h2 = channel === 'hSL' ? Number(value) : hsl.h
1501
+ const s2 = channel === 'sSL' ? Number(value) / 100 : hsl.s
1502
+ const l2 = channel === 'lSL' ? Number(value) / 100 : hsl.l
1503
+ const rgb = hslToRgb(h2, clamp01(s2), clamp01(l2))
1504
+ const hsvVal = rgbToHsv(rgb.r, rgb.g, rgb.b)
1505
+ updateHsv({
1506
+ h: hsvVal.s === 0 ? h2 : hsvVal.h,
1507
+ s: hsvVal.s,
1508
+ v: hsvVal.v,
1509
+ })
1510
+ return
1511
+ }
1512
+ case 'L':
1513
+ case 'C':
1514
+ case 'H': {
1515
+ const cur = rgbToOklch(p.r, p.g, p.b)
1516
+ // For L/C edits, anchor on the user's last stated H so we
1517
+ // don't drift along with chroma changes.
1518
+ const baseH = oklchHueRef.current ?? cur.H
1519
+ const L = channel === 'L' ? Number(value) / 100 : cur.L
1520
+ const C = channel === 'C' ? Number(value) : cur.C
1521
+ const H = channel === 'H' ? Number(value) : baseH
1522
+ oklchHueRef.current = H
1523
+ const rgb = oklchToRgb(clamp01(L), Math.max(0, C), H)
1524
+ const hsvVal = rgbToHsv(rgb.r, rgb.g, rgb.b)
1525
+ updateHsv({
1526
+ h: hsvVal.s === 0 ? hsv.h : hsvVal.h,
1527
+ s: hsvVal.s,
1528
+ v: hsvVal.v,
1529
+ })
1530
+ return
1531
+ }
1532
+ case 'alphaPercent': {
1533
+ const a = clamp01(Number(value) / 100)
1534
+ updateHsv({ a })
1535
+ return
1536
+ }
1537
+ }
1538
+ }}
1539
+ />
1540
+
1541
+ {swatches && swatches.length > 0 && (
1542
+ <SwatchStrip swatches={swatches} current={parsed.hex} onPick={handleSwatchPick} />
1543
+ )}
1544
+ </div>
1545
+ </SurfaceProvider>
1546
+ )
1547
+
1548
+ return size ? <SizeProvider size={size}>{root}</SizeProvider> : root
1549
+ },
1550
+ ) as ColorPickerComponent
1551
+
1552
+ ColorPicker.displayName = 'ColorPicker'
1553
+
1554
+ // ---------------------------------------------------------------------------
1555
+ // ColorInputsRow — adapts inputs to format
1556
+ // ---------------------------------------------------------------------------
1557
+
1558
+ type ChannelKey = 'hex' | 'r' | 'g' | 'b' | 'hSL' | 'sSL' | 'lSL' | 'L' | 'C' | 'H' | 'alphaPercent'
1559
+
1560
+ function ColorInputsRow({
1561
+ parsed,
1562
+ format,
1563
+ oklchHue,
1564
+ onChannelChange,
1565
+ }: {
1566
+ parsed: ParsedColor
1567
+ format: ColorFormat
1568
+ /** Sticky OKLCH hue override for display (preserves user's stated H across round-trip drift). */
1569
+ oklchHue?: number | null
1570
+ onChannelChange: (key: ChannelKey, value: string) => void
1571
+ }) {
1572
+ const alphaPct = Math.round(parsed.a * 100)
1573
+
1574
+ if (format === 'hex') {
1575
+ const hexNoHash = parsed.hex.replace(/^#/, '').toUpperCase()
1576
+ return (
1577
+ <div className="grid grid-cols-2 gap-2">
1578
+ <ChannelTooltip label="Hex">
1579
+ <ColorInput
1580
+ value={hexNoHash}
1581
+ onCommit={next => onChannelChange('hex', next.startsWith('#') ? next : `#${next}`)}
1582
+ ariaLabel="Hex value"
1583
+ prefix="#"
1584
+ />
1585
+ </ChannelTooltip>
1586
+ <AlphaInput value={alphaPct} onCommit={n => onChannelChange('alphaPercent', String(n))} />
1587
+ </div>
1588
+ )
1589
+ }
1590
+
1591
+ if (format === 'rgb') {
1592
+ return (
1593
+ <div className="grid grid-cols-4 gap-1">
1594
+ <ChannelTooltip label="Red">
1595
+ <ColorInput
1596
+ value={String(parsed.r)}
1597
+ onCommit={n => onChannelChange('r', n)}
1598
+ ariaLabel="Red"
1599
+ align="center"
1600
+ inputMode="numeric"
1601
+ nudgeStep={1}
1602
+ nudgeShiftStep={10}
1603
+ scrubbable
1604
+ min={0}
1605
+ max={255}
1606
+ />
1607
+ </ChannelTooltip>
1608
+ <ChannelTooltip label="Green">
1609
+ <ColorInput
1610
+ value={String(parsed.g)}
1611
+ onCommit={n => onChannelChange('g', n)}
1612
+ ariaLabel="Green"
1613
+ align="center"
1614
+ inputMode="numeric"
1615
+ nudgeStep={1}
1616
+ nudgeShiftStep={10}
1617
+ scrubbable
1618
+ min={0}
1619
+ max={255}
1620
+ />
1621
+ </ChannelTooltip>
1622
+ <ChannelTooltip label="Blue">
1623
+ <ColorInput
1624
+ value={String(parsed.b)}
1625
+ onCommit={n => onChannelChange('b', n)}
1626
+ ariaLabel="Blue"
1627
+ align="center"
1628
+ inputMode="numeric"
1629
+ nudgeStep={1}
1630
+ nudgeShiftStep={10}
1631
+ scrubbable
1632
+ min={0}
1633
+ max={255}
1634
+ />
1635
+ </ChannelTooltip>
1636
+ <AlphaInput value={alphaPct} onCommit={n => onChannelChange('alphaPercent', String(n))} />
1637
+ </div>
1638
+ )
1639
+ }
1640
+
1641
+ if (format === 'hsl') {
1642
+ const hsl = rgbToHsl(parsed.r, parsed.g, parsed.b)
1643
+ return (
1644
+ <div className="grid grid-cols-4 gap-1">
1645
+ <ChannelTooltip label="Hue">
1646
+ <ColorInput
1647
+ value={String(Math.round(hsl.h))}
1648
+ onCommit={n => onChannelChange('hSL', n)}
1649
+ ariaLabel="Hue"
1650
+ align="center"
1651
+ inputMode="numeric"
1652
+ nudgeStep={1}
1653
+ nudgeShiftStep={10}
1654
+ scrubbable
1655
+ min={0}
1656
+ max={360}
1657
+ wrap
1658
+ />
1659
+ </ChannelTooltip>
1660
+ <ChannelTooltip label="Saturation">
1661
+ <ColorInput
1662
+ value={String(Math.round(hsl.s * 100))}
1663
+ onCommit={n => onChannelChange('sSL', n)}
1664
+ ariaLabel="Saturation"
1665
+ align="center"
1666
+ inputMode="numeric"
1667
+ nudgeStep={1}
1668
+ nudgeShiftStep={10}
1669
+ scrubbable
1670
+ min={0}
1671
+ max={100}
1672
+ />
1673
+ </ChannelTooltip>
1674
+ <ChannelTooltip label="Lightness">
1675
+ <ColorInput
1676
+ value={String(Math.round(hsl.l * 100))}
1677
+ onCommit={n => onChannelChange('lSL', n)}
1678
+ ariaLabel="Lightness"
1679
+ align="center"
1680
+ inputMode="numeric"
1681
+ nudgeStep={1}
1682
+ nudgeShiftStep={10}
1683
+ scrubbable
1684
+ min={0}
1685
+ max={100}
1686
+ />
1687
+ </ChannelTooltip>
1688
+ <AlphaInput value={alphaPct} onCommit={n => onChannelChange('alphaPercent', String(n))} />
1689
+ </div>
1690
+ )
1691
+ }
1692
+
1693
+ // oklch
1694
+ const oklch = rgbToOklch(parsed.r, parsed.g, parsed.b)
1695
+ const displayH = oklchHue ?? oklch.H
1696
+ return (
1697
+ <div className="grid grid-cols-4 gap-1">
1698
+ <ChannelTooltip label="Lightness">
1699
+ <ColorInput
1700
+ value={(oklch.L * 100).toFixed(0)}
1701
+ onCommit={n => onChannelChange('L', n)}
1702
+ ariaLabel="Lightness"
1703
+ align="center"
1704
+ inputMode="decimal"
1705
+ nudgeStep={1}
1706
+ nudgeShiftStep={10}
1707
+ scrubbable
1708
+ min={0}
1709
+ max={100}
1710
+ />
1711
+ </ChannelTooltip>
1712
+ <ChannelTooltip label="Chroma">
1713
+ <ColorInput
1714
+ value={oklch.C.toFixed(2)}
1715
+ onCommit={n => onChannelChange('C', n)}
1716
+ ariaLabel="Chroma"
1717
+ align="center"
1718
+ inputMode="decimal"
1719
+ nudgeStep={0.01}
1720
+ nudgeShiftStep={0.1}
1721
+ decimals={2}
1722
+ scrubbable
1723
+ min={0}
1724
+ max={0.4}
1725
+ />
1726
+ </ChannelTooltip>
1727
+ <ChannelTooltip label="Hue">
1728
+ <ColorInput
1729
+ value={displayH.toFixed(0)}
1730
+ onCommit={n => onChannelChange('H', n)}
1731
+ ariaLabel="Hue"
1732
+ align="center"
1733
+ inputMode="numeric"
1734
+ nudgeStep={1}
1735
+ nudgeShiftStep={10}
1736
+ scrubbable
1737
+ min={0}
1738
+ max={360}
1739
+ wrap
1740
+ />
1741
+ </ChannelTooltip>
1742
+ <AlphaInput value={alphaPct} onCommit={n => onChannelChange('alphaPercent', String(n))} />
1743
+ </div>
1744
+ )
1745
+ }
1746
+
1747
+ function ChannelTooltip({ label, children }: { label: string; children: ReactNode }) {
1748
+ return (
1749
+ <Tooltip content={label} delayDuration={300}>
1750
+ <div>{children}</div>
1751
+ </Tooltip>
1752
+ )
1753
+ }
1754
+
1755
+ function AlphaInput({ value, onCommit }: { value: number; onCommit: (n: number) => void }) {
1756
+ return (
1757
+ <ChannelTooltip label="Alpha">
1758
+ <ColorInput
1759
+ value={`${value}%`}
1760
+ onCommit={input => {
1761
+ const n = parseFloat(input.replace('%', ''))
1762
+ if (Number.isNaN(n)) return
1763
+ onCommit(Math.max(0, Math.min(100, Math.round(n))))
1764
+ }}
1765
+ ariaLabel="Alpha"
1766
+ align="center"
1767
+ inputMode="numeric"
1768
+ nudgeStep={1}
1769
+ nudgeShiftStep={10}
1770
+ hasPercent
1771
+ scrubbable
1772
+ min={0}
1773
+ max={100}
1774
+ />
1775
+ </ChannelTooltip>
1776
+ )
1777
+ }
1778
+
1779
+ // ---------------------------------------------------------------------------
1780
+ // ColorPickerPopover (trigger button + popover panel)
1781
+ //
1782
+ // Built on Base UI's Popover primitive, which owns positioning (anchor
1783
+ // tracking + collision flipping — the old version placed the panel at a
1784
+ // captured rect and could overflow the viewport bottom), dismissal (outside
1785
+ // press, focus-out, Escape only while focus is relevant), and focus
1786
+ // management (focus moves into the panel on open and restores to the trigger
1787
+ // on close). The panel morphs out of its trigger and back (lib/use-morph.ts),
1788
+ // the same pattern as popover.tsx.
1789
+ // ---------------------------------------------------------------------------
1790
+
1791
+ const ColorPickerPopover = forwardRef<HTMLDivElement, ColorPickerPopoverProps>(
1792
+ (
1793
+ {
1794
+ triggerLabel,
1795
+ triggerLabelPosition = 'left',
1796
+ triggerShowValue = true,
1797
+ triggerShowRemove = false,
1798
+ onTriggerRemove,
1799
+ triggerClassName,
1800
+ open: openProp,
1801
+ defaultOpen = false,
1802
+ onOpenChange,
1803
+ size,
1804
+ from,
1805
+ effect,
1806
+ hideSource,
1807
+ tier,
1808
+ ...pickerProps
1809
+ },
1810
+ ref,
1811
+ ) => {
1812
+ const isOpenControlled = openProp !== undefined
1813
+ const [internalOpen, setInternalOpen] = useState(defaultOpen)
1814
+ const open = isOpenControlled ? openProp : internalOpen
1815
+ const { origin, capture } = useMorphOrigin()
1816
+ const morph = useMorph(open, origin, { from, effect, hideSource, tier })
1817
+ const shape = useShape()
1818
+ // Resolved with the override directly: this component's own hooks run
1819
+ // outside the SizeProvider it renders, so the trigger can't read the pin
1820
+ // from context. The portalled panel inherits it from the provider below
1821
+ // (React context crosses portals).
1822
+ const sizeClasses = useSize(size)
1823
+ const compact = sizeClasses.variant === 'compact'
1824
+ const substrate = useSurface()
1825
+ const level = Math.min(substrate + 2, 8)
1826
+
1827
+ const handleOpenChange = useCallback(
1828
+ (next: boolean, details: { trigger?: Element; event?: Event }) => {
1829
+ if (next) capture(details)
1830
+ if (!isOpenControlled) setInternalOpen(next)
1831
+ onOpenChange?.(next)
1832
+ },
1833
+ [isOpenControlled, onOpenChange, capture],
1834
+ )
1835
+
1836
+ const isControlled = pickerProps.value !== undefined
1837
+ const [internalValue, setInternalValue] = useState(pickerProps.value ?? pickerProps.defaultValue ?? '#6B97FF')
1838
+ const currentValue = isControlled ? (pickerProps.value as string) : internalValue
1839
+
1840
+ const handleValueChange = useCallback(
1841
+ (v: string, parsed: ParsedColor) => {
1842
+ if (!isControlled) setInternalValue(v)
1843
+ pickerProps.onValueChange?.(v, parsed)
1844
+ },
1845
+ [isControlled, pickerProps],
1846
+ )
1847
+
1848
+ const XIcon = useIcon('x')
1849
+ const parsed = useMemo(() => parseColor(currentValue), [currentValue])
1850
+ const swatchColor = parsed ? rgbToHexStr(parsed.r, parsed.g, parsed.b, parsed.a) : currentValue
1851
+ const valueLabel = parsed
1852
+ ? rgbToHexStr(parsed.r, parsed.g, parsed.b, 1).replace(/^#/, '').toUpperCase()
1853
+ : currentValue
1854
+
1855
+ // A size prop pins the whole compound (trigger + portalled panel — React
1856
+ // context crosses portals) to one step of the ladder.
1857
+ const root = (
1858
+ <Popover.Root
1859
+ open={open}
1860
+ onOpenChange={handleOpenChange}
1861
+ // Non-modal: the page keeps scrolling and the Positioner tracks the
1862
+ // anchor, so the panel follows its trigger instead of detaching.
1863
+ modal={false}
1864
+ >
1865
+ <div ref={ref} className="inline-flex">
1866
+ <Popover.Trigger
1867
+ className={cn(
1868
+ 'flex items-center border border-border bg-transparent hover:bg-hover transition-colors duration-fast outline-none focus-visible:ring-1 focus-visible:ring-focus-ring cursor-pointer',
1869
+ sizeClasses.gap,
1870
+ sizeClasses.control,
1871
+ compact ? 'px-1.5' : 'px-2',
1872
+ shape.input,
1873
+ 'weight-medium',
1874
+ triggerClassName,
1875
+ )}
1876
+ >
1877
+ {triggerLabel && triggerLabelPosition === 'left' && (
1878
+ <span className={cn('text-muted-foreground px-1 select-none', sizeClasses.text)}>{triggerLabel}</span>
1879
+ )}
1880
+ <ColorTile color={swatchColor} size={compact ? 16 : 20} />
1881
+ {triggerShowValue && (
1882
+ <span className={cn('text-foreground tabular-nums', sizeClasses.text)}>{valueLabel}</span>
1883
+ )}
1884
+ {triggerLabel && triggerLabelPosition === 'right' && (
1885
+ <span className={cn('text-muted-foreground px-1 select-none', sizeClasses.text)}>{triggerLabel}</span>
1886
+ )}
1887
+ {triggerShowRemove && (
1888
+ <span
1889
+ role="button"
1890
+ aria-label="Remove color"
1891
+ tabIndex={0}
1892
+ onClick={e => {
1893
+ e.stopPropagation()
1894
+ onTriggerRemove?.()
1895
+ }}
1896
+ onKeyDown={e => {
1897
+ if (e.key === 'Enter' || e.key === ' ') {
1898
+ e.stopPropagation()
1899
+ e.preventDefault()
1900
+ onTriggerRemove?.()
1901
+ }
1902
+ }}
1903
+ className="ml-1 text-muted-foreground hover:text-foreground cursor-pointer flex items-center"
1904
+ >
1905
+ <XIcon size={14} strokeWidth={1.5} />
1906
+ </span>
1907
+ )}
1908
+ </Popover.Trigger>
1909
+ <Popover.Portal>
1910
+ <Popover.Positioner
1911
+ side="bottom"
1912
+ align="start"
1913
+ sideOffset={opensInPlace({ effect, hideSource }) ? inPlaceOffset : 6}
1914
+ className="z-50 outline-none"
1915
+ >
1916
+ <Popover.Popup ref={morph.popupRef} className="relative outline-none">
1917
+ <ColorPickerPortalContainer value={morph.popup}>
1918
+ <SurfaceProvider value={level}>
1919
+ <MorphSurface
1920
+ morph={morph}
1921
+ bg={SURFACE_BG[level]}
1922
+ shadow={SURFACE_SHADOW[3]}
1923
+ radius={shape.container}
1924
+ >
1925
+ <PanelSurfaceContext.Provider value={false}>
1926
+ <ColorPicker {...pickerProps} value={currentValue} onValueChange={handleValueChange} />
1927
+ </PanelSurfaceContext.Provider>
1928
+ </MorphSurface>
1929
+ </SurfaceProvider>
1930
+ </ColorPickerPortalContainer>
1931
+ </Popover.Popup>
1932
+ </Popover.Positioner>
1933
+ </Popover.Portal>
1934
+ </div>
1935
+ </Popover.Root>
1936
+ )
1937
+
1938
+ return size ? <SizeProvider size={size}>{root}</SizeProvider> : root
1939
+ },
1940
+ )
1941
+
1942
+ ColorPickerPopover.displayName = 'ColorPickerPopover'
1943
+
1944
+ // Compound static: `<ColorPicker.Popover>` (typed by the ColorPickerComponent
1945
+ // cast on the forwardRef above).
1946
+ Object.assign(ColorPicker, { Popover: ColorPickerPopover })
1947
+
1948
+ // ---------------------------------------------------------------------------
1949
+ // Exports
1950
+ // ---------------------------------------------------------------------------
1951
+
1952
+ export type { ColorFormat, ColorPickerPopoverProps, ColorPickerProps, ColorSwatchProps, ParsedColor }
1953
+ export { buildParsed, ColorPicker, ColorPickerPopover, ColorPickerPortalContainer, ColorSwatch, ColorTile, parseColor }
1954
+
1955
+ export default ColorPicker