@appica/ui-react 1.0.0 → 1.1.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 (473) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +47 -5
  3. package/agent-rules.md +41 -0
  4. package/appica.css +7 -0
  5. package/dist/components/accordion/accordion.d.ts +24 -0
  6. package/dist/components/accordion/accordion.d.ts.map +1 -1
  7. package/dist/components/accordion/accordion.js +1 -1
  8. package/dist/components/accordion/accordion.js.map +1 -1
  9. package/dist/components/alert/alert.d.ts +29 -1
  10. package/dist/components/alert/alert.d.ts.map +1 -1
  11. package/dist/components/alert/alert.js +1 -1
  12. package/dist/components/alert/alert.js.map +1 -1
  13. package/dist/components/alert-dialog/alert-dialog.d.ts +12 -2
  14. package/dist/components/alert-dialog/alert-dialog.d.ts.map +1 -1
  15. package/dist/components/alert-dialog/alert-dialog.js +9 -5
  16. package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
  17. package/dist/components/autocomplete/autocomplete.d.ts +21 -1
  18. package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
  19. package/dist/components/autocomplete/autocomplete.js +2 -2
  20. package/dist/components/autocomplete/autocomplete.js.map +1 -1
  21. package/dist/components/avatar/avatar.d.ts +16 -0
  22. package/dist/components/avatar/avatar.d.ts.map +1 -1
  23. package/dist/components/avatar/avatar.js +1 -1
  24. package/dist/components/avatar/avatar.js.map +1 -1
  25. package/dist/components/background-pattern/background-pattern-interactive.js +1 -1
  26. package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
  27. package/dist/components/background-pattern/background-pattern-shared.js +1 -1
  28. package/dist/components/background-pattern/background-pattern-shared.js.map +1 -1
  29. package/dist/components/background-pattern/background-pattern.d.ts +13 -5
  30. package/dist/components/background-pattern/background-pattern.d.ts.map +1 -1
  31. package/dist/components/background-pattern/background-pattern.js +1 -1
  32. package/dist/components/background-pattern/background-pattern.js.map +1 -1
  33. package/dist/components/badge/badge.d.ts +11 -1
  34. package/dist/components/badge/badge.d.ts.map +1 -1
  35. package/dist/components/badge/badge.js +1 -1
  36. package/dist/components/badge/badge.js.map +1 -1
  37. package/dist/components/border-beam/border-beam.d.ts +52 -0
  38. package/dist/components/border-beam/border-beam.d.ts.map +1 -0
  39. package/dist/components/border-beam/border-beam.js +67 -0
  40. package/dist/components/border-beam/border-beam.js.map +1 -0
  41. package/dist/components/breadcrumb/breadcrumb.d.ts +8 -0
  42. package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -1
  43. package/dist/components/breadcrumb/breadcrumb.js +1 -1
  44. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  45. package/dist/components/button/button-variants.js +1 -1
  46. package/dist/components/button/button-variants.js.map +1 -1
  47. package/dist/components/button/button.d.ts +11 -1
  48. package/dist/components/button/button.d.ts.map +1 -1
  49. package/dist/components/button/button.js +1 -1
  50. package/dist/components/button/button.js.map +1 -1
  51. package/dist/components/button-group/button-group.d.ts +10 -0
  52. package/dist/components/button-group/button-group.d.ts.map +1 -1
  53. package/dist/components/button-group/button-group.js +1 -1
  54. package/dist/components/button-group/button-group.js.map +1 -1
  55. package/dist/components/calendar/calendar.d.ts +5 -0
  56. package/dist/components/calendar/calendar.d.ts.map +1 -1
  57. package/dist/components/calendar/calendar.js +1 -1
  58. package/dist/components/calendar/calendar.js.map +1 -1
  59. package/dist/components/card/card.d.ts +43 -0
  60. package/dist/components/card/card.d.ts.map +1 -0
  61. package/dist/components/card/card.js +103 -0
  62. package/dist/components/card/card.js.map +1 -0
  63. package/dist/components/carousel/carousel.d.ts +105 -5
  64. package/dist/components/carousel/carousel.d.ts.map +1 -1
  65. package/dist/components/carousel/carousel.js +157 -5
  66. package/dist/components/carousel/carousel.js.map +1 -1
  67. package/dist/components/checkbox/checkbox.js +1 -1
  68. package/dist/components/checkbox/checkbox.js.map +1 -1
  69. package/dist/components/checkbox-group/checkbox-group.d.ts +4 -0
  70. package/dist/components/checkbox-group/checkbox-group.d.ts.map +1 -1
  71. package/dist/components/checkbox-group/checkbox-group.js +1 -1
  72. package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
  73. package/dist/components/chip/chip.d.ts +32 -0
  74. package/dist/components/chip/chip.d.ts.map +1 -1
  75. package/dist/components/chip/chip.js +1 -1
  76. package/dist/components/chip/chip.js.map +1 -1
  77. package/dist/components/collapsible/collapsible.js +1 -1
  78. package/dist/components/collapsible/collapsible.js.map +1 -1
  79. package/dist/components/color-area/color-area.d.ts +53 -0
  80. package/dist/components/color-area/color-area.d.ts.map +1 -0
  81. package/dist/components/color-area/color-area.js +245 -0
  82. package/dist/components/color-area/color-area.js.map +1 -0
  83. package/dist/components/color-picker/color-picker.d.ts +152 -0
  84. package/dist/components/color-picker/color-picker.d.ts.map +1 -0
  85. package/dist/components/color-picker/color-picker.js +327 -0
  86. package/dist/components/color-picker/color-picker.js.map +1 -0
  87. package/dist/components/color-slider/color-slider.d.ts +48 -0
  88. package/dist/components/color-slider/color-slider.d.ts.map +1 -0
  89. package/dist/components/color-slider/color-slider.js +216 -0
  90. package/dist/components/color-slider/color-slider.js.map +1 -0
  91. package/dist/components/color-swatch/color-swatch.d.ts +47 -0
  92. package/dist/components/color-swatch/color-swatch.d.ts.map +1 -0
  93. package/dist/components/color-swatch/color-swatch.js +66 -0
  94. package/dist/components/color-swatch/color-swatch.js.map +1 -0
  95. package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +62 -0
  96. package/dist/components/color-swatch-picker/color-swatch-picker.d.ts.map +1 -0
  97. package/dist/components/color-swatch-picker/color-swatch-picker.js +202 -0
  98. package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -0
  99. package/dist/components/combobox/combobox.d.ts +25 -1
  100. package/dist/components/combobox/combobox.d.ts.map +1 -1
  101. package/dist/components/combobox/combobox.js +2 -2
  102. package/dist/components/combobox/combobox.js.map +1 -1
  103. package/dist/components/context-menu/context-menu.d.ts +7 -1
  104. package/dist/components/context-menu/context-menu.d.ts.map +1 -1
  105. package/dist/components/context-menu/context-menu.js +5 -5
  106. package/dist/components/context-menu/context-menu.js.map +1 -1
  107. package/dist/components/copy-button/copy-button.d.ts +15 -0
  108. package/dist/components/copy-button/copy-button.d.ts.map +1 -1
  109. package/dist/components/copy-button/copy-button.js +1 -1
  110. package/dist/components/copy-button/copy-button.js.map +1 -1
  111. package/dist/components/countdown/countdown.d.ts +14 -0
  112. package/dist/components/countdown/countdown.d.ts.map +1 -1
  113. package/dist/components/countdown/countdown.js +1 -1
  114. package/dist/components/countdown/countdown.js.map +1 -1
  115. package/dist/components/date-field/date-field.d.ts +35 -0
  116. package/dist/components/date-field/date-field.d.ts.map +1 -1
  117. package/dist/components/date-field/date-field.js +1 -1
  118. package/dist/components/date-field/date-field.js.map +1 -1
  119. package/dist/components/date-picker/date-picker.d.ts +94 -0
  120. package/dist/components/date-picker/date-picker.d.ts.map +1 -1
  121. package/dist/components/date-picker/date-picker.js +1 -1
  122. package/dist/components/date-picker/date-picker.js.map +1 -1
  123. package/dist/components/dialog/dialog.d.ts +20 -2
  124. package/dist/components/dialog/dialog.d.ts.map +1 -1
  125. package/dist/components/dialog/dialog.js +8 -4
  126. package/dist/components/dialog/dialog.js.map +1 -1
  127. package/dist/components/drawer/drawer.d.ts +22 -2
  128. package/dist/components/drawer/drawer.d.ts.map +1 -1
  129. package/dist/components/drawer/drawer.js +13 -7
  130. package/dist/components/drawer/drawer.js.map +1 -1
  131. package/dist/components/dropdown-menu/dropdown-menu.d.ts +7 -1
  132. package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
  133. package/dist/components/dropdown-menu/dropdown-menu.js +5 -5
  134. package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
  135. package/dist/components/field/field.js +1 -1
  136. package/dist/components/field/field.js.map +1 -1
  137. package/dist/components/fieldset/fieldset.js +1 -1
  138. package/dist/components/fieldset/fieldset.js.map +1 -1
  139. package/dist/components/gradient-glow/gradient-glow.d.ts +45 -0
  140. package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
  141. package/dist/components/gradient-glow/gradient-glow.js +1 -1
  142. package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
  143. package/dist/components/input/input-variants.js +1 -1
  144. package/dist/components/input/input-variants.js.map +1 -1
  145. package/dist/components/input/input.d.ts +21 -1
  146. package/dist/components/input/input.d.ts.map +1 -1
  147. package/dist/components/input/input.js +3 -3
  148. package/dist/components/input/input.js.map +1 -1
  149. package/dist/components/kbd/kbd.d.ts +8 -0
  150. package/dist/components/kbd/kbd.d.ts.map +1 -1
  151. package/dist/components/kbd/kbd.js +1 -1
  152. package/dist/components/kbd/kbd.js.map +1 -1
  153. package/dist/components/loader/loader.d.ts +8 -0
  154. package/dist/components/loader/loader.d.ts.map +1 -1
  155. package/dist/components/loader/loader.js +1 -1
  156. package/dist/components/loader/loader.js.map +1 -1
  157. package/dist/components/menubar/menubar.d.ts +8 -0
  158. package/dist/components/menubar/menubar.d.ts.map +1 -1
  159. package/dist/components/menubar/menubar.js +1 -1
  160. package/dist/components/menubar/menubar.js.map +1 -1
  161. package/dist/components/meter/meter.d.ts +4 -0
  162. package/dist/components/meter/meter.d.ts.map +1 -1
  163. package/dist/components/meter/meter.js +1 -1
  164. package/dist/components/meter/meter.js.map +1 -1
  165. package/dist/components/navigation/navigation-link-variants.d.ts +1 -1
  166. package/dist/components/navigation/navigation-link-variants.js +1 -1
  167. package/dist/components/navigation/navigation-link-variants.js.map +1 -1
  168. package/dist/components/navigation/navigation-link.d.ts +22 -0
  169. package/dist/components/navigation/navigation-link.d.ts.map +1 -1
  170. package/dist/components/navigation/navigation-link.js +1 -1
  171. package/dist/components/navigation/navigation-link.js.map +1 -1
  172. package/dist/components/navigation/navigation.d.ts +12 -0
  173. package/dist/components/navigation/navigation.d.ts.map +1 -1
  174. package/dist/components/navigation/navigation.js +1 -1
  175. package/dist/components/navigation/navigation.js.map +1 -1
  176. package/dist/components/navigation-menu/navigation-menu.d.ts +33 -0
  177. package/dist/components/navigation-menu/navigation-menu.d.ts.map +1 -1
  178. package/dist/components/navigation-menu/navigation-menu.js +1 -1
  179. package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
  180. package/dist/components/number-field/number-field.d.ts +14 -0
  181. package/dist/components/number-field/number-field.d.ts.map +1 -1
  182. package/dist/components/number-field/number-field.js +1 -1
  183. package/dist/components/number-field/number-field.js.map +1 -1
  184. package/dist/components/otp-field/otp-field.d.ts +9 -0
  185. package/dist/components/otp-field/otp-field.d.ts.map +1 -1
  186. package/dist/components/otp-field/otp-field.js +1 -1
  187. package/dist/components/otp-field/otp-field.js.map +1 -1
  188. package/dist/components/pagination/pagination.d.ts +16 -0
  189. package/dist/components/pagination/pagination.d.ts.map +1 -1
  190. package/dist/components/pagination/pagination.js +1 -1
  191. package/dist/components/pagination/pagination.js.map +1 -1
  192. package/dist/components/popover/popover.d.ts +5 -1
  193. package/dist/components/popover/popover.d.ts.map +1 -1
  194. package/dist/components/popover/popover.js +2 -2
  195. package/dist/components/popover/popover.js.map +1 -1
  196. package/dist/components/preview-card/preview-card.d.ts +5 -1
  197. package/dist/components/preview-card/preview-card.d.ts.map +1 -1
  198. package/dist/components/preview-card/preview-card.js +2 -2
  199. package/dist/components/preview-card/preview-card.js.map +1 -1
  200. package/dist/components/progress/progress.d.ts +17 -0
  201. package/dist/components/progress/progress.d.ts.map +1 -1
  202. package/dist/components/progress/progress.js +1 -1
  203. package/dist/components/progress/progress.js.map +1 -1
  204. package/dist/components/radio/radio.js +1 -1
  205. package/dist/components/radio/radio.js.map +1 -1
  206. package/dist/components/radio-group/radio-group.d.ts +4 -0
  207. package/dist/components/radio-group/radio-group.d.ts.map +1 -1
  208. package/dist/components/radio-group/radio-group.js +1 -1
  209. package/dist/components/radio-group/radio-group.js.map +1 -1
  210. package/dist/components/rating/rating.d.ts +79 -0
  211. package/dist/components/rating/rating.d.ts.map +1 -0
  212. package/dist/components/rating/rating.js +301 -0
  213. package/dist/components/rating/rating.js.map +1 -0
  214. package/dist/components/scroll-area/scroll-area.d.ts +13 -0
  215. package/dist/components/scroll-area/scroll-area.d.ts.map +1 -1
  216. package/dist/components/scroll-area/scroll-area.js +1 -1
  217. package/dist/components/scroll-area/scroll-area.js.map +1 -1
  218. package/dist/components/select/select.d.ts +20 -1
  219. package/dist/components/select/select.d.ts.map +1 -1
  220. package/dist/components/select/select.js +2 -2
  221. package/dist/components/select/select.js.map +1 -1
  222. package/dist/components/separator/separator.d.ts +4 -0
  223. package/dist/components/separator/separator.d.ts.map +1 -1
  224. package/dist/components/separator/separator.js +1 -1
  225. package/dist/components/separator/separator.js.map +1 -1
  226. package/dist/components/skeleton/skeleton.d.ts +4 -0
  227. package/dist/components/skeleton/skeleton.d.ts.map +1 -1
  228. package/dist/components/skeleton/skeleton.js +1 -1
  229. package/dist/components/skeleton/skeleton.js.map +1 -1
  230. package/dist/components/slider/slider.d.ts +5 -0
  231. package/dist/components/slider/slider.d.ts.map +1 -1
  232. package/dist/components/slider/slider.js +1 -1
  233. package/dist/components/slider/slider.js.map +1 -1
  234. package/dist/components/sparkline/sparkline.d.ts +44 -0
  235. package/dist/components/sparkline/sparkline.d.ts.map +1 -1
  236. package/dist/components/sparkline/sparkline.js +1 -1
  237. package/dist/components/sparkline/sparkline.js.map +1 -1
  238. package/dist/components/spinner/spinner.d.ts +8 -0
  239. package/dist/components/spinner/spinner.d.ts.map +1 -1
  240. package/dist/components/spinner/spinner.js +1 -1
  241. package/dist/components/spinner/spinner.js.map +1 -1
  242. package/dist/components/switch/switch.d.ts +4 -0
  243. package/dist/components/switch/switch.d.ts.map +1 -1
  244. package/dist/components/switch/switch.js +1 -1
  245. package/dist/components/switch/switch.js.map +1 -1
  246. package/dist/components/table/table.d.ts +28 -0
  247. package/dist/components/table/table.d.ts.map +1 -1
  248. package/dist/components/table/table.js +1 -1
  249. package/dist/components/table/table.js.map +1 -1
  250. package/dist/components/tabs/tabs.d.ts +31 -1
  251. package/dist/components/tabs/tabs.d.ts.map +1 -1
  252. package/dist/components/tabs/tabs.js +1 -1
  253. package/dist/components/tabs/tabs.js.map +1 -1
  254. package/dist/components/text-animate/text-animate.d.ts +31 -0
  255. package/dist/components/text-animate/text-animate.d.ts.map +1 -1
  256. package/dist/components/text-animate/text-animate.js +26 -9
  257. package/dist/components/text-animate/text-animate.js.map +1 -1
  258. package/dist/components/textarea/textarea.d.ts +15 -0
  259. package/dist/components/textarea/textarea.d.ts.map +1 -1
  260. package/dist/components/textarea/textarea.js +1 -1
  261. package/dist/components/textarea/textarea.js.map +1 -1
  262. package/dist/components/thumbnail/thumbnail.d.ts +20 -0
  263. package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
  264. package/dist/components/thumbnail/thumbnail.js +1 -1
  265. package/dist/components/thumbnail/thumbnail.js.map +1 -1
  266. package/dist/components/time-field/time-field.d.ts +35 -0
  267. package/dist/components/time-field/time-field.d.ts.map +1 -1
  268. package/dist/components/time-field/time-field.js +1 -1
  269. package/dist/components/time-field/time-field.js.map +1 -1
  270. package/dist/components/toast/toast.d.ts +18 -0
  271. package/dist/components/toast/toast.d.ts.map +1 -1
  272. package/dist/components/toast/toast.js +1 -1
  273. package/dist/components/toast/toast.js.map +1 -1
  274. package/dist/components/toc/toc.d.ts +10 -0
  275. package/dist/components/toc/toc.d.ts.map +1 -1
  276. package/dist/components/toc/toc.js +1 -1
  277. package/dist/components/toc/toc.js.map +1 -1
  278. package/dist/components/toggle-group/toggle-group.js +1 -1
  279. package/dist/components/toggle-group/toggle-group.js.map +1 -1
  280. package/dist/components/toolbar/toolbar.js +1 -1
  281. package/dist/components/toolbar/toolbar.js.map +1 -1
  282. package/dist/components/tooltip/tooltip.d.ts +5 -1
  283. package/dist/components/tooltip/tooltip.d.ts.map +1 -1
  284. package/dist/components/tooltip/tooltip.js +2 -2
  285. package/dist/components/tooltip/tooltip.js.map +1 -1
  286. package/dist/hooks/use-dismissible.d.ts +4 -0
  287. package/dist/hooks/use-dismissible.d.ts.map +1 -1
  288. package/dist/hooks/use-dismissible.js.map +1 -1
  289. package/dist/hooks/use-local-storage.js.map +1 -1
  290. package/dist/hooks/use-reduced-motion.d.ts +1 -1
  291. package/dist/hooks/use-reduced-motion.js.map +1 -1
  292. package/dist/hooks/use-theme.d.ts +1 -1
  293. package/dist/hooks/use-theme.js.map +1 -1
  294. package/dist/index.d.ts +9 -0
  295. package/dist/index.d.ts.map +1 -1
  296. package/dist/index.js +10 -1
  297. package/dist/index.js.map +1 -1
  298. package/dist/internal/color-control.d.ts +75 -0
  299. package/dist/internal/color-control.d.ts.map +1 -0
  300. package/dist/internal/color-control.js +78 -0
  301. package/dist/internal/color-control.js.map +1 -0
  302. package/dist/internal/color-math.d.ts +9 -0
  303. package/dist/internal/color-math.d.ts.map +1 -0
  304. package/dist/internal/color-math.js +34 -0
  305. package/dist/internal/color-math.js.map +1 -0
  306. package/dist/internal/color-picker-context.d.ts +34 -0
  307. package/dist/internal/color-picker-context.d.ts.map +1 -0
  308. package/dist/internal/color-picker-context.js +41 -0
  309. package/dist/internal/color-picker-context.js.map +1 -0
  310. package/dist/{floating.d.ts → internal/floating.d.ts} +1 -1
  311. package/dist/internal/floating.d.ts.map +1 -0
  312. package/dist/internal/floating.js.map +1 -0
  313. package/dist/{modal.d.ts → internal/modal.d.ts} +1 -1
  314. package/dist/internal/modal.d.ts.map +1 -0
  315. package/dist/internal/modal.js.map +1 -0
  316. package/dist/internal/utils.d.ts.map +1 -0
  317. package/dist/internal/utils.js.map +1 -0
  318. package/dist/lib/color.d.ts +95 -0
  319. package/dist/lib/color.d.ts.map +1 -0
  320. package/dist/lib/color.js +328 -0
  321. package/dist/lib/color.js.map +1 -0
  322. package/dist/providers/direction-provider.d.ts +4 -4
  323. package/dist/providers/direction-provider.d.ts.map +1 -1
  324. package/dist/providers/direction-provider.js.map +1 -1
  325. package/dist/providers/reduced-motion-provider.d.ts +4 -8
  326. package/dist/providers/reduced-motion-provider.d.ts.map +1 -1
  327. package/dist/providers/reduced-motion-provider.js.map +1 -1
  328. package/dist/providers/theme-provider/theme-provider.d.ts +28 -12
  329. package/dist/providers/theme-provider/theme-provider.d.ts.map +1 -1
  330. package/dist/providers/theme-provider/theme-provider.js.map +1 -1
  331. package/dist/providers/theme-provider/theme-script.js.map +1 -1
  332. package/package.json +75 -17
  333. package/src/components/accordion/accordion.tsx +25 -1
  334. package/src/components/alert/alert.tsx +30 -2
  335. package/src/components/alert-dialog/alert-dialog.test.tsx +34 -2
  336. package/src/components/alert-dialog/alert-dialog.tsx +21 -5
  337. package/src/components/autocomplete/autocomplete.test.tsx +1 -1
  338. package/src/components/autocomplete/autocomplete.tsx +22 -2
  339. package/src/components/avatar/avatar.test.tsx +2 -2
  340. package/src/components/avatar/avatar.tsx +17 -1
  341. package/src/components/background-pattern/background-pattern-interactive.tsx +1 -1
  342. package/src/components/background-pattern/background-pattern-shared.tsx +1 -1
  343. package/src/components/background-pattern/background-pattern.test.tsx +1 -1
  344. package/src/components/background-pattern/background-pattern.tsx +14 -6
  345. package/src/components/badge/badge.tsx +14 -2
  346. package/src/components/border-beam/border-beam.test.tsx +91 -0
  347. package/src/components/border-beam/border-beam.tsx +131 -0
  348. package/src/components/breadcrumb/breadcrumb.tsx +9 -1
  349. package/src/components/button/button-variants.ts +1 -1
  350. package/src/components/button/button.tsx +13 -2
  351. package/src/components/button-group/button-group.tsx +11 -1
  352. package/src/components/calendar/calendar.tsx +6 -1
  353. package/src/components/card/card.test.tsx +98 -0
  354. package/src/components/card/card.tsx +154 -0
  355. package/src/components/carousel/carousel.test.tsx +155 -0
  356. package/src/components/carousel/carousel.tsx +305 -5
  357. package/src/components/checkbox/checkbox.test.tsx +2 -2
  358. package/src/components/checkbox/checkbox.tsx +1 -1
  359. package/src/components/checkbox-group/checkbox-group.tsx +5 -1
  360. package/src/components/chip/chip.tsx +33 -1
  361. package/src/components/collapsible/collapsible.tsx +1 -1
  362. package/src/components/color-area/color-area.test.tsx +242 -0
  363. package/src/components/color-area/color-area.tsx +356 -0
  364. package/src/components/color-picker/color-picker.test.tsx +286 -0
  365. package/src/components/color-picker/color-picker.tsx +546 -0
  366. package/src/components/color-slider/color-slider.test.tsx +222 -0
  367. package/src/components/color-slider/color-slider.tsx +330 -0
  368. package/src/components/color-swatch/color-swatch.test.tsx +117 -0
  369. package/src/components/color-swatch/color-swatch.tsx +119 -0
  370. package/src/components/color-swatch-picker/color-swatch-picker.test.tsx +287 -0
  371. package/src/components/color-swatch-picker/color-swatch-picker.tsx +327 -0
  372. package/src/components/combobox/combobox.test.tsx +1 -1
  373. package/src/components/combobox/combobox.tsx +26 -2
  374. package/src/components/context-menu/context-menu.tsx +11 -5
  375. package/src/components/copy-button/copy-button.test.tsx +1 -1
  376. package/src/components/copy-button/copy-button.tsx +16 -1
  377. package/src/components/countdown/countdown.tsx +15 -1
  378. package/src/components/date-field/date-field.tsx +36 -1
  379. package/src/components/date-picker/date-picker.test.tsx +1 -1
  380. package/src/components/date-picker/date-picker.tsx +95 -1
  381. package/src/components/dialog/dialog.test.tsx +30 -1
  382. package/src/components/dialog/dialog.tsx +28 -6
  383. package/src/components/drawer/drawer.test.tsx +32 -1
  384. package/src/components/drawer/drawer.tsx +37 -7
  385. package/src/components/dropdown-menu/dropdown-menu.tsx +11 -5
  386. package/src/components/field/field.tsx +1 -1
  387. package/src/components/fieldset/fieldset.tsx +1 -1
  388. package/src/components/gradient-glow/gradient-glow.test.tsx +1 -1
  389. package/src/components/gradient-glow/gradient-glow.tsx +46 -1
  390. package/src/components/input/input-variants.ts +1 -1
  391. package/src/components/input/input.tsx +24 -4
  392. package/src/components/kbd/kbd.tsx +9 -1
  393. package/src/components/loader/loader.tsx +9 -1
  394. package/src/components/menubar/menubar.tsx +9 -1
  395. package/src/components/meter/meter.tsx +5 -1
  396. package/src/components/navigation/navigation-link-variants.ts +1 -1
  397. package/src/components/navigation/navigation-link.tsx +23 -1
  398. package/src/components/navigation/navigation.tsx +23 -3
  399. package/src/components/navigation-menu/navigation-menu.tsx +34 -1
  400. package/src/components/number-field/number-field.tsx +15 -1
  401. package/src/components/otp-field/otp-field.tsx +10 -1
  402. package/src/components/pagination/pagination.tsx +17 -1
  403. package/src/components/popover/popover.test.tsx +1 -1
  404. package/src/components/popover/popover.tsx +6 -2
  405. package/src/components/preview-card/preview-card.tsx +6 -2
  406. package/src/components/progress/progress.tsx +18 -1
  407. package/src/components/radio/radio.test.tsx +1 -1
  408. package/src/components/radio/radio.tsx +1 -1
  409. package/src/components/radio-group/radio-group.test.tsx +1 -1
  410. package/src/components/radio-group/radio-group.tsx +5 -1
  411. package/src/components/rating/rating.test.tsx +246 -0
  412. package/src/components/rating/rating.tsx +457 -0
  413. package/src/components/scroll-area/scroll-area.test.tsx +1 -1
  414. package/src/components/scroll-area/scroll-area.tsx +14 -1
  415. package/src/components/select/select.tsx +21 -2
  416. package/src/components/separator/separator.tsx +5 -1
  417. package/src/components/skeleton/skeleton.tsx +5 -1
  418. package/src/components/slider/slider.test.tsx +1 -1
  419. package/src/components/slider/slider.tsx +6 -1
  420. package/src/components/sparkline/sparkline.test.tsx +1 -1
  421. package/src/components/sparkline/sparkline.tsx +45 -1
  422. package/src/components/spinner/spinner.tsx +9 -1
  423. package/src/components/switch/switch.test.tsx +1 -1
  424. package/src/components/switch/switch.tsx +5 -1
  425. package/src/components/table/table.tsx +29 -1
  426. package/src/components/tabs/tabs.test.tsx +1 -1
  427. package/src/components/tabs/tabs.tsx +33 -2
  428. package/src/components/text-animate/text-animate.test.tsx +62 -0
  429. package/src/components/text-animate/text-animate.tsx +77 -9
  430. package/src/components/textarea/textarea.tsx +16 -1
  431. package/src/components/thumbnail/thumbnail.test.tsx +1 -1
  432. package/src/components/thumbnail/thumbnail.tsx +21 -1
  433. package/src/components/time-field/time-field.tsx +36 -1
  434. package/src/components/toast/toast.test.tsx +1 -1
  435. package/src/components/toast/toast.tsx +19 -1
  436. package/src/components/toc/toc.tsx +11 -1
  437. package/src/components/toggle/toggle.test.tsx +1 -1
  438. package/src/components/toggle-group/toggle-group.tsx +1 -1
  439. package/src/components/toolbar/toolbar.tsx +1 -1
  440. package/src/components/tooltip/tooltip.test.tsx +1 -1
  441. package/src/components/tooltip/tooltip.tsx +6 -2
  442. package/src/hooks/use-dismissible.ts +4 -0
  443. package/src/hooks/use-local-storage.ts +3 -3
  444. package/src/hooks/use-reduced-motion.ts +1 -1
  445. package/src/hooks/use-theme.ts +1 -1
  446. package/src/index.ts +11 -2
  447. package/src/internal/color-control.ts +178 -0
  448. package/src/internal/color-math.ts +44 -0
  449. package/src/internal/color-picker-context.ts +80 -0
  450. package/src/{floating.ts → internal/floating.ts} +3 -3
  451. package/src/{modal.ts → internal/modal.ts} +3 -3
  452. package/src/lib/color.test.ts +178 -0
  453. package/src/lib/color.ts +471 -0
  454. package/src/providers/direction-provider.tsx +4 -4
  455. package/src/providers/reduced-motion-provider.tsx +4 -8
  456. package/src/providers/theme-provider/theme-provider.tsx +28 -12
  457. package/src/providers/theme-provider/theme-script.tsx +2 -2
  458. package/src/test/setup.ts +1 -1
  459. package/styles.css +28 -4
  460. package/dist/floating.d.ts.map +0 -1
  461. package/dist/floating.js.map +0 -1
  462. package/dist/modal.d.ts.map +0 -1
  463. package/dist/modal.js.map +0 -1
  464. package/dist/utils.d.ts.map +0 -1
  465. package/dist/utils.js.map +0 -1
  466. /package/dist/{floating.js → internal/floating.js} +0 -0
  467. /package/dist/{modal.js → internal/modal.js} +0 -0
  468. /package/dist/{utils.d.ts → internal/utils.d.ts} +0 -0
  469. /package/dist/{utils.js → internal/utils.js} +0 -0
  470. /package/src/{floating.test.ts → internal/floating.test.ts} +0 -0
  471. /package/src/{modal.test.ts → internal/modal.test.ts} +0 -0
  472. /package/src/{utils.test.tsx → internal/utils.test.tsx} +0 -0
  473. /package/src/{utils.ts → internal/utils.ts} +0 -0
@@ -0,0 +1,222 @@
1
+ import * as React from 'react'
2
+ import { render, screen } from '@testing-library/react'
3
+ import userEvent from '@testing-library/user-event'
4
+ import { describe, it, expect, vi, afterEach } from 'vitest'
5
+ import { axe } from 'vitest-axe'
6
+ import { ColorSlider, type ColorSliderProps } from './color-slider'
7
+ import { ColorArea } from '../color-area/color-area'
8
+ import { type Color, getChannelValue, parseColor } from '../../lib/color'
9
+ import { DirectionProvider } from '../../providers/direction-provider'
10
+
11
+ const RECT = { x: 0, y: 0, top: 0, left: 0, right: 200, bottom: 200, width: 200, height: 200 }
12
+
13
+ function stubSize() {
14
+ vi.spyOn(HTMLDivElement.prototype, 'getBoundingClientRect').mockImplementation(
15
+ () => ({ ...RECT, toJSON: () => RECT }) as DOMRect,
16
+ )
17
+ }
18
+
19
+ /** jsdom lays nothing out, so stand in a track thickness and a thumb size. */
20
+ function stubGeometry(track: number, thumb: number) {
21
+ const extent = (element: HTMLElement) => (element.dataset.slot === 'color-slider-thumb' ? thumb : track)
22
+ for (const property of ['offsetWidth', 'offsetHeight'] as const) {
23
+ vi.spyOn(HTMLElement.prototype, property, 'get').mockImplementation(function (this: HTMLElement) {
24
+ return extent(this)
25
+ })
26
+ }
27
+ }
28
+
29
+ function renderSlider(props: ColorSliderProps) {
30
+ return render(<ColorSlider data-testid="track" {...props} />)
31
+ }
32
+
33
+ const slider = () => screen.getByRole('slider') as HTMLInputElement
34
+ const track = () => screen.getByTestId('track')
35
+ const thumb = () => document.querySelector('[data-slot="color-slider-thumb"]') as HTMLElement
36
+ const stopCount = () => (track().style.backgroundImage.match(/rgba?\(/g) ?? []).length
37
+
38
+ describe('ColorSlider', () => {
39
+ it('exposes the channel as a labeled range input', () => {
40
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(120, 50%, 50%)' })
41
+ expect(slider()).toHaveAttribute('aria-label', 'Hue')
42
+ expect(slider()).toHaveAttribute('min', '0')
43
+ expect(slider()).toHaveAttribute('max', '360')
44
+ expect(slider()).toHaveValue('120')
45
+ })
46
+
47
+ it('reads a channel the value space lacks from that channel home space', () => {
48
+ // A hex value is RGB, which has no hue, so hue comes from HSB.
49
+ renderSlider({ channel: 'hue', defaultValue: '#ff0000' })
50
+ expect(slider()).toHaveValue('0')
51
+ })
52
+
53
+ it('keeps the value space when it already carries the channel', () => {
54
+ renderSlider({ channel: 'lightness', defaultValue: 'hsl(200, 50%, 40%)' })
55
+ expect(slider()).toHaveValue('40')
56
+ })
57
+
58
+ it('leaves the space alone for alpha, which every space carries', async () => {
59
+ const user = userEvent.setup()
60
+ const onValueChange = vi.fn<(value: Color) => void>()
61
+ renderSlider({ channel: 'alpha', defaultValue: 'hsb(217, 76%, 96%)', onValueChange })
62
+
63
+ slider().focus()
64
+ await user.keyboard('{ArrowLeft}')
65
+ // Converting to RGB here would strip the channels a sibling area reads.
66
+ expect(onValueChange.mock.lastCall![0].space).toBe('hsb')
67
+ })
68
+
69
+ it('moves by step, by page step with shift, and jumps with Home and End', async () => {
70
+ const user = userEvent.setup()
71
+ const onValueChange = vi.fn<(value: Color) => void>()
72
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(120, 50%, 50%)', onValueChange })
73
+
74
+ slider().focus()
75
+ await user.keyboard('{ArrowRight}')
76
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(121)
77
+
78
+ await user.keyboard('{Shift>}{ArrowRight}{/Shift}')
79
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(136)
80
+
81
+ await user.keyboard('{End}')
82
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(360)
83
+
84
+ await user.keyboard('{Home}')
85
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(0)
86
+ })
87
+
88
+ it('reverses the horizontal arrow keys in RTL', async () => {
89
+ const user = userEvent.setup()
90
+ const onValueChange = vi.fn<(value: Color) => void>()
91
+ render(
92
+ <DirectionProvider dir="rtl">
93
+ <ColorSlider channel="hue" defaultValue="hsb(120, 50%, 50%)" onValueChange={onValueChange} />
94
+ </DirectionProvider>,
95
+ )
96
+
97
+ slider().focus()
98
+ await user.keyboard('{ArrowRight}')
99
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(119)
100
+ })
101
+
102
+ it('leaves the vertical arrow keys alone in RTL', async () => {
103
+ const user = userEvent.setup()
104
+ const onValueChange = vi.fn<(value: Color) => void>()
105
+ render(
106
+ <DirectionProvider dir="rtl">
107
+ <ColorSlider
108
+ channel="hue"
109
+ orientation="vertical"
110
+ defaultValue="hsb(120, 50%, 50%)"
111
+ onValueChange={onValueChange}
112
+ />
113
+ </DirectionProvider>,
114
+ )
115
+
116
+ slider().focus()
117
+ await user.keyboard('{ArrowUp}')
118
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(121)
119
+ })
120
+
121
+ it('sets the channel from a pointer press along the track', async () => {
122
+ stubSize()
123
+ const user = userEvent.setup()
124
+ const onValueChange = vi.fn<(value: Color) => void>()
125
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', onValueChange })
126
+
127
+ await user.pointer({ target: track(), coords: { clientX: 50, clientY: 10 }, keys: '[MouseLeft]' })
128
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(90)
129
+ })
130
+
131
+ it('fills a vertical track from the bottom', async () => {
132
+ stubSize()
133
+ const user = userEvent.setup()
134
+ const onValueChange = vi.fn<(value: Color) => void>()
135
+ renderSlider({ channel: 'hue', orientation: 'vertical', defaultValue: 'hsb(0, 50%, 50%)', onValueChange })
136
+
137
+ // A quarter down from the top is three quarters up the track.
138
+ await user.pointer({ target: track(), coords: { clientX: 10, clientY: 50 }, keys: '[MouseLeft]' })
139
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(270)
140
+ })
141
+
142
+ it('fires onValueCommitted once per gesture', async () => {
143
+ stubSize()
144
+ const user = userEvent.setup()
145
+ const onValueCommitted = vi.fn<(value: Color) => void>()
146
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', onValueCommitted })
147
+
148
+ await user.pointer({ target: track(), coords: { clientX: 50, clientY: 10 }, keys: '[MouseLeft]' })
149
+ expect(onValueCommitted).toHaveBeenCalledTimes(1)
150
+ })
151
+
152
+ it('ignores interaction when disabled', async () => {
153
+ const user = userEvent.setup()
154
+ const onValueChange = vi.fn<(value: Color) => void>()
155
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', disabled: true, onValueChange })
156
+
157
+ expect(track()).toHaveAttribute('data-disabled')
158
+ expect(slider()).toBeDisabled()
159
+ await user.click(track())
160
+ expect(onValueChange).not.toHaveBeenCalled()
161
+ })
162
+
163
+ it('drops the gradient when disabled, so the flat fill can show', () => {
164
+ renderSlider({ channel: 'alpha', defaultValue: 'rgba(255, 0, 0, 0.5)', disabled: true })
165
+ // An inline background-image would paint straight over the disabled class.
166
+ expect(track().style.backgroundImage).toBe('')
167
+ expect(track().style.backgroundSize).toBe('')
168
+ expect(thumb().style.backgroundColor).toBe('')
169
+ })
170
+
171
+ it('names the hidden input for form submission', () => {
172
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', name: 'hue' })
173
+ expect(slider()).toHaveAttribute('name', 'hue')
174
+ })
175
+
176
+ it('has no accessibility violations', async () => {
177
+ const { container } = renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', 'aria-label': 'Hue' })
178
+ expect(await axe(container)).toHaveNoViolations()
179
+ })
180
+ })
181
+
182
+ describe('ColorSlider thumb inset', () => {
183
+ // The geometry stubs sit on HTMLElement.prototype, so they have to come back off.
184
+ afterEach(() => vi.restoreAllMocks())
185
+
186
+ it('holds the thumb inside the track at both ends', () => {
187
+ stubGeometry(20, 18)
188
+ const { rerender } = renderSlider({ channel: 'saturation', value: 'hsb(200, 0%, 100%)' })
189
+ // Half a thumb (9) plus the 1px of track it already clears, at each end.
190
+ expect(thumb().style.insetInlineStart).toBe('10px')
191
+
192
+ rerender(<ColorSlider data-testid="track" channel="saturation" value="hsb(200, 100%, 100%)" />)
193
+ expect(thumb().style.insetInlineStart).toBe('calc(100% - 10px)')
194
+ })
195
+
196
+ it('insets a vertical track along its own axis', () => {
197
+ stubGeometry(20, 18)
198
+ renderSlider({ channel: 'saturation', orientation: 'vertical', value: 'hsb(200, 100%, 100%)' })
199
+ expect(thumb().style.top).toBe('10px')
200
+ expect(thumb().style.insetInlineStart).toBe('50%')
201
+ })
202
+
203
+ it('maps a press against the inset track, not the full width', async () => {
204
+ stubGeometry(20, 18)
205
+ stubSize()
206
+ const user = userEvent.setup()
207
+ const onValueChange = vi.fn<(value: Color) => void>()
208
+ renderSlider({ channel: 'hue', defaultValue: 'hsb(0, 50%, 50%)', onValueChange })
209
+
210
+ // 200px wide with 10px off each end, so the middle of the travel is x = 100.
211
+ await user.pointer({ target: track(), coords: { clientX: 100, clientY: 10 }, keys: '[MouseLeft]' })
212
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(180)
213
+
214
+ // The very edge still reaches the minimum rather than stopping short of it.
215
+ await user.pointer({ target: track(), coords: { clientX: 0, clientY: 10 }, keys: '[MouseLeft]' })
216
+ expect(getChannelValue(onValueChange.mock.lastCall![0], 'hue')).toBe(0)
217
+ })
218
+
219
+ // The ramp's matching inset has no test here: jsdom's CSS parser rejects any
220
+ // `calc()` inside a gradient color stop and drops the whole declaration, so
221
+ // `style.backgroundImage` never sees it. Verified in the browser instead.
222
+ })
@@ -0,0 +1,330 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { cn } from '../../internal/utils'
5
+ import { useDirection } from '../../hooks/use-direction'
6
+ import {
7
+ COLOR_CONTROL_GROUP,
8
+ type ColorControlSpace,
9
+ colorControlCheckerboard,
10
+ colorControlCheckerboardSize,
11
+ colorControlRootClasses,
12
+ colorControlSurfaceClasses,
13
+ colorControlThumbClasses,
14
+ resolveControlSpace,
15
+ snapToStep,
16
+ } from '../../internal/color-control'
17
+ import { useColorControl } from '../../internal/color-picker-context'
18
+ import {
19
+ type Color,
20
+ type ColorChannel,
21
+ convertColor,
22
+ formatChannelValue,
23
+ formatColor,
24
+ getChannelName,
25
+ getChannelRange,
26
+ getChannelValue,
27
+ parseColor,
28
+ withChannelValue,
29
+ } from '../../lib/color'
30
+
31
+ const DEFAULT_VALUE = '#ffffff'
32
+
33
+ type ColorSliderOrientation = 'horizontal' | 'vertical'
34
+
35
+ /**
36
+ * The color the track ramps through, which is not always the value. Hue reads best
37
+ * at full saturation rather than as a ramp through whatever the current color is,
38
+ * and alpha is the one channel that keeps its own transparency.
39
+ */
40
+ function trackColor(color: Color, channel: ColorChannel): Color {
41
+ if (channel === 'hue') return parseColor(`hsl(${getChannelValue(color, 'hue')}, 100%, 50%)`)
42
+ return channel === 'alpha' ? color : withChannelValue(color, 'alpha', 1)
43
+ }
44
+
45
+ /** A point along the track, `inset` in from each end - the range the thumb reaches. */
46
+ function offsetAt(fraction: number, inset: number): string {
47
+ if (inset === 0) return `${fraction * 100}%`
48
+ if (fraction === 0) return `${inset}px`
49
+ if (fraction === 1) return `calc(100% - ${inset}px)`
50
+ return `calc(${inset}px + (100% - ${inset * 2}px) * ${fraction})`
51
+ }
52
+
53
+ /**
54
+ * Lays the stops across the thumb's travel rather than the track's full width, so the
55
+ * color under the thumb is the color the slider reports. CSS extends the first and
56
+ * last stop to the ends on its own, which caps the pill in the channel's min and max -
57
+ * the same result HeroUI draws with a pseudo-element at each end.
58
+ */
59
+ function ramp(colors: string[], to: string, inset: number): string {
60
+ const last = colors.length - 1
61
+ const stops = colors.map((color, index) => (inset === 0 ? color : `${color} ${offsetAt(index / last, inset)}`))
62
+ return `linear-gradient(to ${to}, ${stops.join(', ')})`
63
+ }
64
+
65
+ function trackBackground(color: Color, channel: ColorChannel, to: string, inset: number): string {
66
+ const base = trackColor(color, channel)
67
+ const at = (value: number) => formatColor(withChannelValue(base, channel, value))
68
+
69
+ if (channel === 'hue') {
70
+ const hues = [0, 60, 120, 180, 240, 300, 360].map((hue) => formatColor(withChannelValue(base, 'hue', hue)))
71
+ return ramp(hues, to, inset)
72
+ }
73
+
74
+ const { minValue, maxValue } = getChannelRange(base.space, channel)
75
+ // Lightness needs the midpoint stop, or the hue drops out and the ramp is just
76
+ // black to white.
77
+ const colors =
78
+ channel === 'lightness' ? [at(minValue), at((minValue + maxValue) / 2), at(maxValue)] : [at(minValue), at(maxValue)]
79
+ return ramp(colors, to, inset)
80
+ }
81
+
82
+ const rootClasses = `${COLOR_CONTROL_GROUP} ${colorControlRootClasses} rounded-full data-[orientation=horizontal]:h-5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-40 data-[orientation=vertical]:w-5`
83
+
84
+ interface ColorSliderProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'color' | 'defaultValue' | 'onChange'> {
85
+ /** Channel the track ramps through, and the one the slider changes. */
86
+ channel: ColorChannel
87
+ /**
88
+ * Selected color. Pass a `Color` or any CSS color string to control the component.
89
+ * Inside a `ColorPicker` it can be left off: the control then reads and writes the
90
+ * picker's color.
91
+ */
92
+ value?: Color | string
93
+ /**
94
+ * Color selected before any interaction, when the component is uncontrolled.
95
+ * @default '#ffffff'
96
+ */
97
+ defaultValue?: Color | string
98
+ /** Fires on every change, including each frame of a drag. */
99
+ onValueChange?: (value: Color) => void
100
+ /** Fires once a drag ends or a key press settles, with the color that was landed on. */
101
+ onValueCommitted?: (value: Color) => void
102
+ /**
103
+ * Color space the channel is read from. Defaults to the space of the value when it
104
+ * carries `channel`, so a slider shares a color with an area without converting it.
105
+ */
106
+ colorSpace?: ColorControlSpace
107
+ /**
108
+ * Axis the track runs along. A vertical track fills from the bottom.
109
+ * @default 'horizontal'
110
+ */
111
+ orientation?: ColorSliderOrientation
112
+ /**
113
+ * Prevent interaction and dim the track.
114
+ * @default false
115
+ */
116
+ disabled?: boolean
117
+ /** Name of the hidden input, used when submitting an HTML form. */
118
+ name?: string
119
+ /** `id` of the `<form>` the hidden input belongs to, when it sits outside it. */
120
+ form?: string
121
+ /** Props for the thumb element, for styling or a test id. */
122
+ thumbProps?: React.ComponentPropsWithoutRef<'span'>
123
+ }
124
+
125
+ function ColorSlider({
126
+ channel,
127
+ value,
128
+ defaultValue = DEFAULT_VALUE,
129
+ onValueChange,
130
+ onValueCommitted,
131
+ colorSpace,
132
+ orientation = 'horizontal',
133
+ disabled: disabledProp,
134
+ name,
135
+ form,
136
+ thumbProps,
137
+ className,
138
+ children,
139
+ 'aria-label': ariaLabel,
140
+ ...props
141
+ }: ColorSliderProps) {
142
+ const mirrored = useDirection() === 'rtl'
143
+ const vertical = orientation === 'vertical'
144
+ const alpha = channel === 'alpha'
145
+
146
+ const containerRef = React.useRef<HTMLDivElement>(null)
147
+ const inputRef = React.useRef<HTMLInputElement>(null)
148
+ const thumbRef = React.useRef<HTMLSpanElement>(null)
149
+
150
+ const [dragging, setDragging] = React.useState(false)
151
+ const [inset, setInset] = React.useState(0)
152
+
153
+ const control = useColorControl({ value, defaultValue, onValueChange, onValueCommitted, disabled: disabledProp })
154
+ const disabled = control.disabled
155
+ const space = resolveControlSpace(control.color.space, channel, colorSpace)
156
+ const color = convertColor(control.color, space)
157
+
158
+ const range = getChannelRange(space, channel)
159
+ const channelValue = getChannelValue(color, channel)
160
+ const ratio = (channelValue - range.minValue) / (range.maxValue - range.minValue)
161
+
162
+ const latestRef = React.useRef<Color>(color)
163
+ latestRef.current = color
164
+
165
+ // How far the thumb's center stays off each end: half a thumb, plus the clearance
166
+ // it already has across the track, so it sits inside by the same margin all round.
167
+ // Measured rather than assumed, since `thumbProps` can resize it.
168
+ React.useEffect(() => {
169
+ const track = containerRef.current
170
+ const thumb = thumbRef.current
171
+ if (!track || !thumb) return
172
+
173
+ const measure = () => {
174
+ // Layout sizes, not a bounding rect: the thumb scales while pressed, and a
175
+ // rect would feed that transform back into the geometry.
176
+ const along = vertical ? thumb.offsetHeight : thumb.offsetWidth
177
+ const across = vertical ? thumb.offsetWidth : thumb.offsetHeight
178
+ const thickness = vertical ? track.offsetWidth : track.offsetHeight
179
+ setInset((along + thickness - across) / 2)
180
+ }
181
+
182
+ measure()
183
+ if (typeof ResizeObserver === 'undefined') return
184
+ const observer = new ResizeObserver(measure)
185
+ observer.observe(track)
186
+ observer.observe(thumb)
187
+ return () => observer.disconnect()
188
+ }, [vertical])
189
+
190
+ const setChannel = (next: number) => {
191
+ const snapped = snapToStep(next, range.minValue, range.maxValue, range.step)
192
+ if (snapped === getChannelValue(latestRef.current, channel)) return
193
+ const updated = withChannelValue(latestRef.current, channel, snapped)
194
+ latestRef.current = updated
195
+ control.setColor(updated)
196
+ }
197
+
198
+ const setFromPoint = (clientX: number, clientY: number) => {
199
+ const rect = containerRef.current?.getBoundingClientRect()
200
+ if (!rect?.width || !rect.height) return
201
+ const extent = (vertical ? rect.height : rect.width) - inset * 2
202
+ if (extent <= 0) return
203
+ const along = vertical ? 1 - (clientY - rect.top - inset) / extent : (clientX - rect.left - inset) / extent
204
+ const fraction = Math.min(Math.max(mirrored && !vertical ? 1 - along : along, 0), 1)
205
+ setChannel(range.minValue + fraction * (range.maxValue - range.minValue))
206
+ }
207
+
208
+ const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
209
+ if (disabled || event.button !== 0) return
210
+ setDragging(true)
211
+ setFromPoint(event.clientX, event.clientY)
212
+ inputRef.current?.focus({ preventScroll: true })
213
+ try {
214
+ // Capture last: it throws when the pointer is already gone, by which point the
215
+ // press has been applied and a failure only costs tracking outside the element.
216
+ event.currentTarget.setPointerCapture(event.pointerId)
217
+ } catch {}
218
+ }
219
+
220
+ const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {
221
+ if (dragging) setFromPoint(event.clientX, event.clientY)
222
+ }
223
+
224
+ const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {
225
+ if (!dragging) return
226
+ if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
227
+ event.currentTarget.releasePointerCapture(event.pointerId)
228
+ }
229
+ setDragging(false)
230
+ control.commitColor(latestRef.current)
231
+ }
232
+
233
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
234
+ if (disabled) return
235
+ const step = event.shiftKey ? range.pageSize : range.step
236
+ const sign = mirrored && !vertical ? -1 : 1
237
+
238
+ const deltas: Record<string, number | undefined> = {
239
+ ArrowLeft: -sign * step,
240
+ ArrowRight: sign * step,
241
+ ArrowDown: -step,
242
+ ArrowUp: step,
243
+ PageDown: -range.pageSize,
244
+ PageUp: range.pageSize,
245
+ }
246
+
247
+ const current = getChannelValue(latestRef.current, channel)
248
+ const next =
249
+ event.key === 'Home'
250
+ ? range.minValue
251
+ : event.key === 'End'
252
+ ? range.maxValue
253
+ : current + (deltas[event.key] ?? NaN)
254
+ if (Number.isNaN(next)) return
255
+
256
+ event.preventDefault()
257
+ setChannel(next)
258
+ control.commitColor(latestRef.current)
259
+ }
260
+
261
+ const to = vertical ? 'top' : mirrored ? 'left' : 'right'
262
+ const background = React.useMemo(() => trackBackground(color, channel, to, inset), [color, channel, to, inset])
263
+
264
+ const offset = (fraction: number) => offsetAt(fraction, inset)
265
+
266
+ const state = {
267
+ 'data-disabled': disabled ? '' : undefined,
268
+ 'data-dragging': dragging ? '' : undefined,
269
+ }
270
+
271
+ return (
272
+ <div
273
+ ref={containerRef}
274
+ {...props}
275
+ data-slot="color-slider"
276
+ data-orientation={orientation}
277
+ data-channel={channel}
278
+ {...state}
279
+ className={cn(rootClasses, className)}
280
+ style={{
281
+ backgroundImage: disabled ? undefined : alpha ? `${background}, ${colorControlCheckerboard}` : background,
282
+ backgroundSize: !disabled && alpha ? `auto, ${colorControlCheckerboardSize}` : undefined,
283
+ ...props.style,
284
+ }}
285
+ onPointerDown={handlePointerDown}
286
+ onPointerMove={handlePointerMove}
287
+ onPointerUp={endDrag}
288
+ onPointerCancel={endDrag}
289
+ >
290
+ <span data-slot="color-slider-surface" aria-hidden="true" className={colorControlSurfaceClasses} />
291
+
292
+ <input
293
+ ref={inputRef}
294
+ type="range"
295
+ className="sr-only"
296
+ form={form}
297
+ name={name}
298
+ disabled={disabled}
299
+ min={range.minValue}
300
+ max={range.maxValue}
301
+ step={range.step}
302
+ value={channelValue}
303
+ aria-label={ariaLabel ?? getChannelName(channel)}
304
+ aria-orientation={orientation}
305
+ aria-valuetext={`${formatChannelValue(color, channel)}, ${formatColor(withChannelValue(color, 'alpha', 1), 'hex')}`}
306
+ onKeyDown={handleKeyDown}
307
+ onChange={(event) => setChannel(Number.parseFloat(event.target.value))}
308
+ />
309
+
310
+ <span
311
+ ref={thumbRef}
312
+ data-slot="color-slider-thumb"
313
+ {...state}
314
+ {...thumbProps}
315
+ className={cn(colorControlThumbClasses, thumbProps?.className)}
316
+ style={{
317
+ insetInlineStart: vertical ? '50%' : offset(ratio),
318
+ top: vertical ? offset(1 - ratio) : '50%',
319
+ backgroundColor: disabled ? undefined : formatColor(trackColor(color, channel)),
320
+ ...thumbProps?.style,
321
+ }}
322
+ />
323
+
324
+ {children}
325
+ </div>
326
+ )
327
+ }
328
+
329
+ export { ColorSlider }
330
+ export type { ColorSliderProps }
@@ -0,0 +1,117 @@
1
+ import * as React from 'react'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { describe, it, expect } from 'vitest'
4
+ import { axe } from 'vitest-axe'
5
+ import { ColorSwatch, type ColorSwatchProps } from './color-swatch'
6
+ import { parseColor } from '../../lib/color'
7
+
8
+ function renderSwatch(props: ColorSwatchProps) {
9
+ return render(<ColorSwatch data-testid="swatch" {...props} />)
10
+ }
11
+
12
+ const swatch = () => screen.getByTestId('swatch')
13
+
14
+ describe('ColorSwatch', () => {
15
+ it('paints an opaque color as a flat fill, with no checkerboard behind it', () => {
16
+ renderSwatch({ color: '#3b82f6' })
17
+ expect(swatch().style.backgroundColor).toBe('rgb(59, 130, 246)')
18
+ expect(swatch().style.backgroundImage).toBe('')
19
+ })
20
+
21
+ it('accepts a Color object as well as a string', () => {
22
+ renderSwatch({ color: parseColor('hsl(217, 91%, 60%)') })
23
+ expect(swatch().style.backgroundColor).toBe('rgb(60, 131, 246)')
24
+ })
25
+
26
+ it('draws a translucent color over a checkerboard so the transparency reads', () => {
27
+ renderSwatch({ color: 'rgba(59, 130, 246, 0.5)' })
28
+ expect(swatch().style.backgroundImage).toContain('linear-gradient(rgba(59, 130, 246, 0.5)')
29
+ expect(swatch().style.backgroundImage).toContain('repeating-conic-gradient')
30
+ // The tile size has to be its own declaration: `background-image` rejects the
31
+ // `0 0 / size` shorthand and drops the whole rule.
32
+ expect(swatch().style.backgroundSize).toBe('auto, 0.3em 0.3em')
33
+ })
34
+
35
+ it('drops the checkerboard so a translucent color can blend into the surface', () => {
36
+ renderSwatch({ color: 'rgba(59, 130, 246, 0.5)', checkerboard: false })
37
+ expect(swatch().style.backgroundImage).toBe('')
38
+ expect(swatch().style.backgroundColor).toBe('rgba(59, 130, 246, 0.5)')
39
+ })
40
+
41
+ it('names the color for assistive technology', () => {
42
+ renderSwatch({ color: '#3b82f6' })
43
+ expect(screen.getByRole('img')).toHaveAccessibleName('vivid blue')
44
+ })
45
+
46
+ it('describes grays and the extremes without reaching for a hue', () => {
47
+ const { rerender } = renderSwatch({ color: '#000000' })
48
+ expect(swatch()).toHaveAccessibleName('black')
49
+
50
+ rerender(<ColorSwatch data-testid="swatch" color="#ffffff" />)
51
+ expect(swatch()).toHaveAccessibleName('white')
52
+
53
+ rerender(<ColorSwatch data-testid="swatch" color="#808080" />)
54
+ expect(swatch()).toHaveAccessibleName('gray')
55
+
56
+ rerender(<ColorSwatch data-testid="swatch" color="rgba(0, 0, 0, 0)" />)
57
+ expect(swatch()).toHaveAccessibleName('transparent')
58
+ })
59
+
60
+ it('reports the opacity as part of the name', () => {
61
+ renderSwatch({ color: 'rgba(59, 130, 246, 0.5)' })
62
+ expect(swatch()).toHaveAccessibleName('vivid blue, 50% opacity')
63
+ })
64
+
65
+ it('lets colorName replace the description and aria-label add context', () => {
66
+ renderSwatch({ color: '#ff0000', colorName: 'Fire truck red', 'aria-label': 'Background color' })
67
+ expect(swatch()).toHaveAccessibleName('Fire truck red, Background color')
68
+ })
69
+
70
+ it('sizes from a preset or an exact pixel number', () => {
71
+ const { rerender } = renderSwatch({ color: '#3b82f6' })
72
+ // The box is 1em, so the preset scale and a number both land on font-size.
73
+ expect(swatch()).toHaveClass('text-[2.5rem]')
74
+ expect(swatch()).toHaveClass('size-[1em]')
75
+
76
+ rerender(<ColorSwatch data-testid="swatch" color="#3b82f6" size={20} />)
77
+ expect(swatch().style.fontSize).toBe('20px')
78
+ expect(swatch()).not.toHaveClass('text-[2.5rem]')
79
+ })
80
+
81
+ it('takes a size class override on the root', () => {
82
+ renderSwatch({ color: '#3b82f6', className: 'size-10' })
83
+ expect(swatch()).toHaveClass('size-10')
84
+ expect(swatch()).not.toHaveClass('size-[1em]')
85
+ })
86
+
87
+ it('rounds the corners by default and goes fully round on request', () => {
88
+ const { rerender } = renderSwatch({ color: '#3b82f6' })
89
+ expect(swatch().className).toContain('rounded-[calc(tan(atan2(var(--radius-md),2.5rem))*100%)]')
90
+
91
+ rerender(<ColorSwatch data-testid="swatch" color="#3b82f6" shape="circle" />)
92
+ expect(swatch()).toHaveClass('rounded-full')
93
+ })
94
+
95
+ it('drops the color when disabled, so the flat fill can show', () => {
96
+ renderSwatch({ color: 'rgba(59, 130, 246, 0.5)', disabled: true })
97
+ // An inline background would paint straight over the disabled class.
98
+ expect(swatch()).toHaveAttribute('data-disabled')
99
+ expect(swatch().style.backgroundImage).toBe('')
100
+ expect(swatch().style.backgroundColor).toBe('')
101
+ })
102
+
103
+ it('carries the shared border overlay', () => {
104
+ renderSwatch({ color: '#3b82f6' })
105
+ expect(swatch().querySelector('[data-slot="color-swatch-surface"]')).toBeInTheDocument()
106
+ })
107
+
108
+ it('renders children over the color', () => {
109
+ renderSwatch({ color: '#3b82f6', children: <span data-testid="check">✓</span> })
110
+ expect(screen.getByTestId('check')).toBeInTheDocument()
111
+ })
112
+
113
+ it('has no accessibility violations', async () => {
114
+ const { container } = renderSwatch({ color: 'rgba(59, 130, 246, 0.5)' })
115
+ expect(await axe(container)).toHaveNoViolations()
116
+ })
117
+ })