@arolariu/components 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (451) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/EXAMPLES.md +2510 -0
  3. package/dist/components/ui/accordion.js +3 -3
  4. package/dist/components/ui/accordion.js.map +1 -1
  5. package/dist/components/ui/accordion_module.css.map +1 -1
  6. package/dist/components/ui/alert-dialog.d.ts +4 -16
  7. package/dist/components/ui/alert-dialog.d.ts.map +1 -1
  8. package/dist/components/ui/alert-dialog.js +21 -17
  9. package/dist/components/ui/alert-dialog.js.map +1 -1
  10. package/dist/components/ui/alert-dialog_module.css +1 -1
  11. package/dist/components/ui/alert-dialog_module.css.map +1 -1
  12. package/dist/components/ui/alert.js +4 -4
  13. package/dist/components/ui/alert.js.map +1 -1
  14. package/dist/components/ui/alert_module.css.map +1 -1
  15. package/dist/components/ui/aspect-ratio.js +2 -2
  16. package/dist/components/ui/aspect-ratio.js.map +1 -1
  17. package/dist/components/ui/aspect-ratio_module.css.map +1 -1
  18. package/dist/components/ui/async-boundary.js +2 -2
  19. package/dist/components/ui/async-boundary.js.map +1 -1
  20. package/dist/components/ui/avatar.d.ts +3 -12
  21. package/dist/components/ui/avatar.d.ts.map +1 -1
  22. package/dist/components/ui/avatar.js +18 -15
  23. package/dist/components/ui/avatar.js.map +1 -1
  24. package/dist/components/ui/avatar_module.css.map +1 -1
  25. package/dist/components/ui/background-beams.js +3 -3
  26. package/dist/components/ui/background-beams.js.map +1 -1
  27. package/dist/components/ui/background-beams_module.css.map +1 -1
  28. package/dist/components/ui/badge.js +2 -2
  29. package/dist/components/ui/badge.js.map +1 -1
  30. package/dist/components/ui/badge_module.css.map +1 -1
  31. package/dist/components/ui/breadcrumb.js +10 -10
  32. package/dist/components/ui/breadcrumb.js.map +1 -1
  33. package/dist/components/ui/breadcrumb_module.css.map +1 -1
  34. package/dist/components/ui/bubble-background.js +5 -5
  35. package/dist/components/ui/bubble-background.js.map +1 -1
  36. package/dist/components/ui/bubble-background_module.css.map +1 -1
  37. package/dist/components/ui/button-group.d.ts +1 -1
  38. package/dist/components/ui/button-group.d.ts.map +1 -1
  39. package/dist/components/ui/button-group.js +6 -6
  40. package/dist/components/ui/button-group.js.map +1 -1
  41. package/dist/components/ui/button-group_module.css.map +1 -1
  42. package/dist/components/ui/button.js +4 -4
  43. package/dist/components/ui/button.js.map +1 -1
  44. package/dist/components/ui/button_module.css.map +1 -1
  45. package/dist/components/ui/calendar.d.ts +3 -5
  46. package/dist/components/ui/calendar.d.ts.map +1 -1
  47. package/dist/components/ui/calendar.js +9 -9
  48. package/dist/components/ui/calendar.js.map +1 -1
  49. package/dist/components/ui/calendar_module.css.map +1 -1
  50. package/dist/components/ui/card-skeleton.js +2 -2
  51. package/dist/components/ui/card-skeleton.js.map +1 -1
  52. package/dist/components/ui/card-skeleton_module.css.map +1 -1
  53. package/dist/components/ui/card.js +8 -8
  54. package/dist/components/ui/card.js.map +1 -1
  55. package/dist/components/ui/card_module.css.map +1 -1
  56. package/dist/components/ui/carousel.d.ts.map +1 -1
  57. package/dist/components/ui/carousel.js +16 -16
  58. package/dist/components/ui/carousel.js.map +1 -1
  59. package/dist/components/ui/carousel_module.css +1 -1
  60. package/dist/components/ui/carousel_module.css.map +1 -1
  61. package/dist/components/ui/chart.d.ts +6 -3
  62. package/dist/components/ui/chart.d.ts.map +1 -1
  63. package/dist/components/ui/chart.js +70 -70
  64. package/dist/components/ui/chart.js.map +1 -1
  65. package/dist/components/ui/chart_module.css.map +1 -1
  66. package/dist/components/ui/checkbox-group.d.ts +2 -6
  67. package/dist/components/ui/checkbox-group.d.ts.map +1 -1
  68. package/dist/components/ui/checkbox-group.js +8 -7
  69. package/dist/components/ui/checkbox-group.js.map +1 -1
  70. package/dist/components/ui/checkbox-group_module.css.map +1 -1
  71. package/dist/components/ui/checkbox.d.ts +3 -1
  72. package/dist/components/ui/checkbox.d.ts.map +1 -1
  73. package/dist/components/ui/checkbox.js +6 -3
  74. package/dist/components/ui/checkbox.js.map +1 -1
  75. package/dist/components/ui/checkbox_module.css.map +1 -1
  76. package/dist/components/ui/collapsible.d.ts.map +1 -1
  77. package/dist/components/ui/collapsible.js +4 -4
  78. package/dist/components/ui/collapsible.js.map +1 -1
  79. package/dist/components/ui/collapsible_module.css.map +1 -1
  80. package/dist/components/ui/combobox.d.ts +335 -0
  81. package/dist/components/ui/combobox.d.ts.map +1 -0
  82. package/dist/components/ui/combobox.js +206 -0
  83. package/dist/components/ui/combobox.js.map +1 -0
  84. package/dist/components/ui/combobox.module.js +23 -0
  85. package/dist/components/ui/combobox.module.js.map +1 -0
  86. package/dist/components/ui/combobox_module.css +142 -0
  87. package/dist/components/ui/combobox_module.css.map +1 -0
  88. package/dist/components/ui/command.d.ts.map +1 -1
  89. package/dist/components/ui/command.js +62 -53
  90. package/dist/components/ui/command.js.map +1 -1
  91. package/dist/components/ui/command_module.css +1 -1
  92. package/dist/components/ui/command_module.css.map +1 -1
  93. package/dist/components/ui/context-menu.d.ts.map +1 -1
  94. package/dist/components/ui/context-menu.js +6 -6
  95. package/dist/components/ui/context-menu.js.map +1 -1
  96. package/dist/components/ui/context-menu_module.css.map +1 -1
  97. package/dist/components/ui/copy-button.js +6 -6
  98. package/dist/components/ui/copy-button.js.map +1 -1
  99. package/dist/components/ui/copy-button_module.css.map +1 -1
  100. package/dist/components/ui/counting-number.js +6 -6
  101. package/dist/components/ui/counting-number.js.map +1 -1
  102. package/dist/components/ui/counting-number_module.css.map +1 -1
  103. package/dist/components/ui/dialog.js +6 -6
  104. package/dist/components/ui/dialog.js.map +1 -1
  105. package/dist/components/ui/dialog_module.css +1 -1
  106. package/dist/components/ui/dialog_module.css.map +1 -1
  107. package/dist/components/ui/dot-background_module.css.map +1 -1
  108. package/dist/components/ui/drawer.d.ts.map +1 -1
  109. package/dist/components/ui/drawer.js +5 -5
  110. package/dist/components/ui/drawer.js.map +1 -1
  111. package/dist/components/ui/drawer_module.css.map +1 -1
  112. package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
  113. package/dist/components/ui/dropdown-menu.js +6 -6
  114. package/dist/components/ui/dropdown-menu.js.map +1 -1
  115. package/dist/components/ui/dropdown-menu_module.css.map +1 -1
  116. package/dist/components/ui/dropdrawer.d.ts +10 -16
  117. package/dist/components/ui/dropdrawer.d.ts.map +1 -1
  118. package/dist/components/ui/dropdrawer.js +73 -65
  119. package/dist/components/ui/dropdrawer.js.map +1 -1
  120. package/dist/components/ui/dropdrawer_module.css.map +1 -1
  121. package/dist/components/ui/empty.js +7 -7
  122. package/dist/components/ui/empty.js.map +1 -1
  123. package/dist/components/ui/empty_module.css.map +1 -1
  124. package/dist/components/ui/error-boundary.js +2 -2
  125. package/dist/components/ui/error-boundary.js.map +1 -1
  126. package/dist/components/ui/error-boundary_module.css.map +1 -1
  127. package/dist/components/ui/field.js +12 -12
  128. package/dist/components/ui/field.js.map +1 -1
  129. package/dist/components/ui/field_module.css.map +1 -1
  130. package/dist/components/ui/fireworks-background.js +6 -6
  131. package/dist/components/ui/fireworks-background.js.map +1 -1
  132. package/dist/components/ui/fireworks-background_module.css.map +1 -1
  133. package/dist/components/ui/flip-button.js +5 -5
  134. package/dist/components/ui/flip-button.js.map +1 -1
  135. package/dist/components/ui/flip-button_module.css.map +1 -1
  136. package/dist/components/ui/focus-scope.js +6 -6
  137. package/dist/components/ui/focus-scope.js.map +1 -1
  138. package/dist/components/ui/focus-scope_module.css.map +1 -1
  139. package/dist/components/ui/form-skeleton.js +2 -2
  140. package/dist/components/ui/form-skeleton.js.map +1 -1
  141. package/dist/components/ui/form-skeleton_module.css.map +1 -1
  142. package/dist/components/ui/form.d.ts +3 -3
  143. package/dist/components/ui/form.d.ts.map +1 -1
  144. package/dist/components/ui/form.js +13 -13
  145. package/dist/components/ui/form.js.map +1 -1
  146. package/dist/components/ui/form_module.css.map +1 -1
  147. package/dist/components/ui/gradient-background.js +2 -2
  148. package/dist/components/ui/gradient-background.js.map +1 -1
  149. package/dist/components/ui/gradient-background_module.css.map +1 -1
  150. package/dist/components/ui/gradient-text.js +2 -2
  151. package/dist/components/ui/gradient-text.js.map +1 -1
  152. package/dist/components/ui/gradient-text_module.css.map +1 -1
  153. package/dist/components/ui/highlight-text.js +4 -4
  154. package/dist/components/ui/highlight-text.js.map +1 -1
  155. package/dist/components/ui/highlight-text_module.css.map +1 -1
  156. package/dist/components/ui/hole-background.js +21 -21
  157. package/dist/components/ui/hole-background.js.map +1 -1
  158. package/dist/components/ui/hole-background_module.css.map +1 -1
  159. package/dist/components/ui/hover-card.js +3 -3
  160. package/dist/components/ui/hover-card.js.map +1 -1
  161. package/dist/components/ui/hover-card_module.css.map +1 -1
  162. package/dist/components/ui/input-group.js +7 -7
  163. package/dist/components/ui/input-group.js.map +1 -1
  164. package/dist/components/ui/input-group_module.css.map +1 -1
  165. package/dist/components/ui/input-otp.d.ts +3 -3
  166. package/dist/components/ui/input-otp.d.ts.map +1 -1
  167. package/dist/components/ui/input-otp.js +6 -6
  168. package/dist/components/ui/input-otp.js.map +1 -1
  169. package/dist/components/ui/input-otp_module.css.map +1 -1
  170. package/dist/components/ui/input.js +2 -2
  171. package/dist/components/ui/input.js.map +1 -1
  172. package/dist/components/ui/input_module.css.map +1 -1
  173. package/dist/components/ui/item.d.ts +1 -1
  174. package/dist/components/ui/item.d.ts.map +1 -1
  175. package/dist/components/ui/item.js +13 -13
  176. package/dist/components/ui/item.js.map +1 -1
  177. package/dist/components/ui/item_module.css.map +1 -1
  178. package/dist/components/ui/kbd.js +3 -3
  179. package/dist/components/ui/kbd.js.map +1 -1
  180. package/dist/components/ui/kbd_module.css.map +1 -1
  181. package/dist/components/ui/label.js +2 -2
  182. package/dist/components/ui/label.js.map +1 -1
  183. package/dist/components/ui/label_module.css.map +1 -1
  184. package/dist/components/ui/list-skeleton.js +2 -2
  185. package/dist/components/ui/list-skeleton.js.map +1 -1
  186. package/dist/components/ui/list-skeleton_module.css.map +1 -1
  187. package/dist/components/ui/loading-overlay.js +2 -2
  188. package/dist/components/ui/loading-overlay.js.map +1 -1
  189. package/dist/components/ui/loading-overlay_module.css.map +1 -1
  190. package/dist/components/ui/menubar.d.ts +11 -13
  191. package/dist/components/ui/menubar.d.ts.map +1 -1
  192. package/dist/components/ui/menubar.js +4 -4
  193. package/dist/components/ui/menubar.js.map +1 -1
  194. package/dist/components/ui/menubar_module.css.map +1 -1
  195. package/dist/components/ui/meter.d.ts +8 -24
  196. package/dist/components/ui/meter.d.ts.map +1 -1
  197. package/dist/components/ui/meter.js +23 -19
  198. package/dist/components/ui/meter.js.map +1 -1
  199. package/dist/components/ui/meter_module.css.map +1 -1
  200. package/dist/components/ui/navigation-menu.d.ts +3 -12
  201. package/dist/components/ui/navigation-menu.d.ts.map +1 -1
  202. package/dist/components/ui/navigation-menu.js +15 -12
  203. package/dist/components/ui/navigation-menu.js.map +1 -1
  204. package/dist/components/ui/navigation-menu_module.css +1 -1
  205. package/dist/components/ui/navigation-menu_module.css.map +1 -1
  206. package/dist/components/ui/number-field.d.ts +6 -12
  207. package/dist/components/ui/number-field.d.ts.map +1 -1
  208. package/dist/components/ui/number-field.js +3 -3
  209. package/dist/components/ui/number-field.js.map +1 -1
  210. package/dist/components/ui/number-field_module.css.map +1 -1
  211. package/dist/components/ui/pagination.js +8 -8
  212. package/dist/components/ui/pagination.js.map +1 -1
  213. package/dist/components/ui/pagination_module.css.map +1 -1
  214. package/dist/components/ui/popover.js +5 -5
  215. package/dist/components/ui/popover.js.map +1 -1
  216. package/dist/components/ui/popover_module.css.map +1 -1
  217. package/dist/components/ui/progress.d.ts +1 -4
  218. package/dist/components/ui/progress.d.ts.map +1 -1
  219. package/dist/components/ui/progress.js +10 -9
  220. package/dist/components/ui/progress.js.map +1 -1
  221. package/dist/components/ui/progress_module.css.map +1 -1
  222. package/dist/components/ui/radio-group.d.ts +2 -4
  223. package/dist/components/ui/radio-group.d.ts.map +1 -1
  224. package/dist/components/ui/radio-group.js +3 -3
  225. package/dist/components/ui/radio-group.js.map +1 -1
  226. package/dist/components/ui/radio-group_module.css.map +1 -1
  227. package/dist/components/ui/resizable.d.ts +13 -29
  228. package/dist/components/ui/resizable.d.ts.map +1 -1
  229. package/dist/components/ui/resizable.js +8 -7
  230. package/dist/components/ui/resizable.js.map +1 -1
  231. package/dist/components/ui/resizable_module.css.map +1 -1
  232. package/dist/components/ui/ripple-button.js +9 -9
  233. package/dist/components/ui/ripple-button.js.map +1 -1
  234. package/dist/components/ui/ripple-button_module.css.map +1 -1
  235. package/dist/components/ui/scratcher.d.ts +1 -1
  236. package/dist/components/ui/scratcher.d.ts.map +1 -1
  237. package/dist/components/ui/scratcher.js +5 -4
  238. package/dist/components/ui/scratcher.js.map +1 -1
  239. package/dist/components/ui/scratcher_module.css.map +1 -1
  240. package/dist/components/ui/scroll-area.d.ts +2 -4
  241. package/dist/components/ui/scroll-area.d.ts.map +1 -1
  242. package/dist/components/ui/scroll-area.js +2 -2
  243. package/dist/components/ui/scroll-area.js.map +1 -1
  244. package/dist/components/ui/scroll-area_module.css.map +1 -1
  245. package/dist/components/ui/select.js +4 -4
  246. package/dist/components/ui/select.js.map +1 -1
  247. package/dist/components/ui/select_module.css.map +1 -1
  248. package/dist/components/ui/separator.d.ts +1 -4
  249. package/dist/components/ui/separator.d.ts.map +1 -1
  250. package/dist/components/ui/separator.js +9 -8
  251. package/dist/components/ui/separator.js.map +1 -1
  252. package/dist/components/ui/separator_module.css.map +1 -1
  253. package/dist/components/ui/sheet.d.ts.map +1 -1
  254. package/dist/components/ui/sheet.js +6 -6
  255. package/dist/components/ui/sheet.js.map +1 -1
  256. package/dist/components/ui/sheet_module.css.map +1 -1
  257. package/dist/components/ui/sidebar.d.ts +1 -1
  258. package/dist/components/ui/sidebar.d.ts.map +1 -1
  259. package/dist/components/ui/sidebar.js +36 -36
  260. package/dist/components/ui/sidebar.js.map +1 -1
  261. package/dist/components/ui/sidebar_module.css.map +1 -1
  262. package/dist/components/ui/skeleton.js +2 -2
  263. package/dist/components/ui/skeleton.js.map +1 -1
  264. package/dist/components/ui/skeleton_module.css.map +1 -1
  265. package/dist/components/ui/slider.js +2 -2
  266. package/dist/components/ui/slider.js.map +1 -1
  267. package/dist/components/ui/slider_module.css.map +1 -1
  268. package/dist/components/ui/spinner.js +2 -2
  269. package/dist/components/ui/spinner.js.map +1 -1
  270. package/dist/components/ui/spinner_module.css.map +1 -1
  271. package/dist/components/ui/stepper.js +2 -2
  272. package/dist/components/ui/stepper.js.map +1 -1
  273. package/dist/components/ui/stepper_module.css.map +1 -1
  274. package/dist/components/ui/switch.js +2 -2
  275. package/dist/components/ui/switch.js.map +1 -1
  276. package/dist/components/ui/switch_module.css.map +1 -1
  277. package/dist/components/ui/table-skeleton.js +2 -2
  278. package/dist/components/ui/table-skeleton.js.map +1 -1
  279. package/dist/components/ui/table-skeleton_module.css.map +1 -1
  280. package/dist/components/ui/table.js +9 -9
  281. package/dist/components/ui/table.js.map +1 -1
  282. package/dist/components/ui/table_module.css.map +1 -1
  283. package/dist/components/ui/tabs.js +3 -3
  284. package/dist/components/ui/tabs.js.map +1 -1
  285. package/dist/components/ui/tabs_module.css.map +1 -1
  286. package/dist/components/ui/textarea.js +2 -2
  287. package/dist/components/ui/textarea.js.map +1 -1
  288. package/dist/components/ui/textarea_module.css.map +1 -1
  289. package/dist/components/ui/timeline.js +5 -5
  290. package/dist/components/ui/timeline.js.map +1 -1
  291. package/dist/components/ui/timeline_module.css.map +1 -1
  292. package/dist/components/ui/{sonner.d.ts → toast.d.ts} +15 -6
  293. package/dist/components/ui/toast.d.ts.map +1 -0
  294. package/dist/components/ui/{sonner.js → toast.js} +43 -42
  295. package/dist/components/ui/toast.js.map +1 -0
  296. package/dist/components/ui/toast.module.js +34 -0
  297. package/dist/components/ui/toast.module.js.map +1 -0
  298. package/dist/components/ui/{sonner_module.css → toast_module.css} +35 -35
  299. package/dist/components/ui/toast_module.css.map +1 -0
  300. package/dist/components/ui/toggle-group.d.ts +2 -8
  301. package/dist/components/ui/toggle-group.d.ts.map +1 -1
  302. package/dist/components/ui/toggle-group.js +14 -12
  303. package/dist/components/ui/toggle-group.js.map +1 -1
  304. package/dist/components/ui/toggle-group_module.css.map +1 -1
  305. package/dist/components/ui/toggle.js +2 -2
  306. package/dist/components/ui/toggle.js.map +1 -1
  307. package/dist/components/ui/toggle_module.css.map +1 -1
  308. package/dist/components/ui/toolbar.d.ts +10 -30
  309. package/dist/components/ui/toolbar.d.ts.map +1 -1
  310. package/dist/components/ui/toolbar.js +28 -23
  311. package/dist/components/ui/toolbar.js.map +1 -1
  312. package/dist/components/ui/toolbar_module.css.map +1 -1
  313. package/dist/components/ui/tooltip.js +4 -4
  314. package/dist/components/ui/tooltip.js.map +1 -1
  315. package/dist/components/ui/tooltip_module.css.map +1 -1
  316. package/dist/components/ui/typewriter.js +4 -4
  317. package/dist/components/ui/typewriter.js.map +1 -1
  318. package/dist/components/ui/typewriter_module.css.map +1 -1
  319. package/dist/components/ui/visually-hidden.js +2 -2
  320. package/dist/components/ui/visually-hidden.js.map +1 -1
  321. package/dist/components/ui/visually-hidden_module.css.map +1 -1
  322. package/dist/hooks/useAnnounce.js +5 -5
  323. package/dist/hooks/useAnnounce.js.map +1 -1
  324. package/dist/hooks/useClipboard.d.ts +77 -0
  325. package/dist/hooks/useClipboard.d.ts.map +1 -0
  326. package/dist/hooks/useClipboard.js +42 -0
  327. package/dist/hooks/useClipboard.js.map +1 -0
  328. package/dist/hooks/useControllableState.d.ts +54 -0
  329. package/dist/hooks/useControllableState.d.ts.map +1 -0
  330. package/dist/hooks/useControllableState.js +29 -0
  331. package/dist/hooks/useControllableState.js.map +1 -0
  332. package/dist/hooks/useDebounce.d.ts +33 -0
  333. package/dist/hooks/useDebounce.d.ts.map +1 -0
  334. package/dist/hooks/useDebounce.js +20 -0
  335. package/dist/hooks/useDebounce.js.map +1 -0
  336. package/dist/hooks/useEventCallback.d.ts +34 -0
  337. package/dist/hooks/useEventCallback.d.ts.map +1 -0
  338. package/dist/hooks/useEventCallback.js +12 -0
  339. package/dist/hooks/useEventCallback.js.map +1 -0
  340. package/dist/hooks/useFocusManager.js +6 -6
  341. package/dist/hooks/useFocusManager.js.map +1 -1
  342. package/dist/hooks/useFocusVisible.js +5 -5
  343. package/dist/hooks/useFocusVisible.js.map +1 -1
  344. package/dist/hooks/useId.d.ts +30 -0
  345. package/dist/hooks/useId.d.ts.map +1 -0
  346. package/dist/hooks/useId.js +9 -0
  347. package/dist/hooks/useId.js.map +1 -0
  348. package/dist/hooks/useIntersectionObserver.d.ts +51 -0
  349. package/dist/hooks/useIntersectionObserver.d.ts.map +1 -0
  350. package/dist/hooks/useIntersectionObserver.js +25 -0
  351. package/dist/hooks/useIntersectionObserver.js.map +1 -0
  352. package/dist/hooks/useInterval.d.ts +55 -0
  353. package/dist/hooks/useInterval.d.ts.map +1 -0
  354. package/dist/hooks/useInterval.js +24 -0
  355. package/dist/hooks/useInterval.js.map +1 -0
  356. package/dist/hooks/useLocalStorage.d.ts +43 -0
  357. package/dist/hooks/useLocalStorage.d.ts.map +1 -0
  358. package/dist/hooks/useLocalStorage.js +53 -0
  359. package/dist/hooks/useLocalStorage.js.map +1 -0
  360. package/dist/hooks/useMediaQuery.js +3 -3
  361. package/dist/hooks/useMediaQuery.js.map +1 -1
  362. package/dist/hooks/useMergedRefs.d.ts +27 -0
  363. package/dist/hooks/useMergedRefs.d.ts.map +1 -0
  364. package/dist/hooks/useMergedRefs.js +11 -0
  365. package/dist/hooks/useMergedRefs.js.map +1 -0
  366. package/dist/hooks/useOnClickOutside.d.ts +32 -0
  367. package/dist/hooks/useOnClickOutside.d.ts.map +1 -0
  368. package/dist/hooks/useOnClickOutside.js +23 -0
  369. package/dist/hooks/useOnClickOutside.js.map +1 -0
  370. package/dist/hooks/usePrevious.d.ts +33 -0
  371. package/dist/hooks/usePrevious.d.ts.map +1 -0
  372. package/dist/hooks/usePrevious.js +14 -0
  373. package/dist/hooks/usePrevious.js.map +1 -0
  374. package/dist/hooks/useThrottle.d.ts +37 -0
  375. package/dist/hooks/useThrottle.d.ts.map +1 -0
  376. package/dist/hooks/useThrottle.js +34 -0
  377. package/dist/hooks/useThrottle.js.map +1 -0
  378. package/dist/hooks/useTimeout.d.ts +28 -0
  379. package/dist/hooks/useTimeout.d.ts.map +1 -0
  380. package/dist/hooks/useTimeout.js +24 -0
  381. package/dist/hooks/useTimeout.js.map +1 -0
  382. package/dist/index.css.map +1 -1
  383. package/dist/index.d.ts +17 -3
  384. package/dist/index.d.ts.map +1 -1
  385. package/dist/index.js +15 -1
  386. package/dist/lib/utilities.d.ts +2 -3
  387. package/dist/lib/utilities.d.ts.map +1 -1
  388. package/dist/lib/utilities.js.map +1 -1
  389. package/dist/motion/Collapse.js +2 -2
  390. package/dist/motion/Collapse.js.map +1 -1
  391. package/dist/motion/Collapse_module.css.map +1 -1
  392. package/dist/motion/tokens.js +5 -5
  393. package/dist/motion/tokens.js.map +1 -1
  394. package/package.json +88 -10
  395. package/src/components/ui/alert-dialog.tsx +15 -8
  396. package/src/components/ui/avatar.tsx +9 -6
  397. package/src/components/ui/calendar.tsx +9 -14
  398. package/src/components/ui/carousel.tsx +2 -0
  399. package/src/components/ui/chart.tsx +65 -62
  400. package/src/components/ui/checkbox-group.tsx +4 -5
  401. package/src/components/ui/checkbox.tsx +10 -2
  402. package/src/components/ui/collapsible.tsx +1 -0
  403. package/src/components/ui/combobox.module.css +158 -0
  404. package/src/components/ui/combobox.tsx +569 -0
  405. package/src/components/ui/command.tsx +31 -15
  406. package/src/components/ui/context-menu.tsx +3 -0
  407. package/src/components/ui/drawer.tsx +2 -0
  408. package/src/components/ui/dropdown-menu.tsx +3 -0
  409. package/src/components/ui/dropdrawer.tsx +80 -62
  410. package/src/components/ui/form.tsx +28 -3
  411. package/src/components/ui/input-otp.tsx +3 -3
  412. package/src/components/ui/menubar.tsx +9 -10
  413. package/src/components/ui/meter.tsx +16 -17
  414. package/src/components/ui/navigation-menu.tsx +41 -33
  415. package/src/components/ui/number-field.tsx +6 -13
  416. package/src/components/ui/progress.tsx +3 -2
  417. package/src/components/ui/radio-group.tsx +2 -5
  418. package/src/components/ui/resizable.tsx +15 -18
  419. package/src/components/ui/scratcher.tsx +6 -10
  420. package/src/components/ui/scroll-area.tsx +2 -5
  421. package/src/components/ui/separator.tsx +4 -3
  422. package/src/components/ui/sheet.tsx +3 -0
  423. package/src/components/ui/sidebar.tsx +1 -0
  424. package/src/components/ui/{sonner.module.css → toast.module.css} +1 -1
  425. package/src/components/ui/{sonner.tsx → toast.tsx} +22 -14
  426. package/src/components/ui/toggle-group.tsx +6 -4
  427. package/src/components/ui/toolbar.tsx +20 -21
  428. package/src/hooks/useClipboard.tsx +137 -0
  429. package/src/hooks/useControllableState.tsx +81 -0
  430. package/src/hooks/useDebounce.tsx +50 -0
  431. package/src/hooks/useEventCallback.tsx +47 -0
  432. package/src/hooks/useId.tsx +36 -0
  433. package/src/hooks/useIntersectionObserver.tsx +81 -0
  434. package/src/hooks/useInterval.tsx +80 -0
  435. package/src/hooks/useLocalStorage.tsx +111 -0
  436. package/src/hooks/useMergedRefs.tsx +48 -0
  437. package/src/hooks/useOnClickOutside.tsx +55 -0
  438. package/src/hooks/usePrevious.tsx +44 -0
  439. package/src/hooks/useThrottle.tsx +78 -0
  440. package/src/hooks/useTimeout.tsx +51 -0
  441. package/src/index.ts +27 -4
  442. package/src/lib/utilities.ts +4 -4
  443. package/src/motion/tokens.ts +4 -4
  444. package/src/stories/DesignPrinciples.mdx +48 -0
  445. package/src/stories/GettingStarted.mdx +92 -0
  446. package/src/stories/Welcome.mdx +44 -0
  447. package/dist/components/ui/sonner.d.ts.map +0 -1
  448. package/dist/components/ui/sonner.js.map +0 -1
  449. package/dist/components/ui/sonner.module.js +0 -34
  450. package/dist/components/ui/sonner.module.js.map +0 -1
  451. package/dist/components/ui/sonner_module.css.map +0 -1
@@ -0,0 +1,137 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Options for the `useClipboard` hook.
7
+ */
8
+ export interface UseClipboardOptions {
9
+ /**
10
+ * The duration in milliseconds after which the `copied` state resets to `false`.
11
+ *
12
+ * @defaultValue 2000
13
+ */
14
+ timeout?: number;
15
+ }
16
+
17
+ /**
18
+ * Return type for the `useClipboard` hook.
19
+ */
20
+ export interface UseClipboardReturn {
21
+ /**
22
+ * Whether the text was successfully copied to the clipboard.
23
+ */
24
+ copied: boolean;
25
+
26
+ /**
27
+ * Copies the provided text to the clipboard.
28
+ *
29
+ * @param text - The text to copy.
30
+ * @returns A promise that resolves when the copy operation completes.
31
+ */
32
+ copy: (text: string) => Promise<void>;
33
+
34
+ /**
35
+ * The error that occurred during the copy operation, or `null` if no error occurred.
36
+ */
37
+ error: Error | null;
38
+ }
39
+
40
+ /**
41
+ * Copies text to the clipboard with success/error state management.
42
+ *
43
+ * @remarks
44
+ * This hook provides a simple interface for copying text to the clipboard using
45
+ * the Clipboard API. It manages the `copied` state that automatically resets
46
+ * after a configurable timeout, and handles errors gracefully when the Clipboard
47
+ * API is unavailable or the operation fails.
48
+ *
49
+ * The hook is SSR-safe and will handle the case where `navigator.clipboard` is
50
+ * not available (e.g., in non-secure contexts or older browsers).
51
+ *
52
+ * @param options - Configuration options for the hook.
53
+ * @returns An object containing the copied state, copy function, and any error.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * function CopyButton({textToCopy}: {textToCopy: string}) {
58
+ * const {copied, copy, error} = useClipboard({timeout: 3000});
59
+ *
60
+ * return (
61
+ * <div>
62
+ * <button onClick={() => copy(textToCopy)}>
63
+ * {copied ? "Copied!" : "Copy to clipboard"}
64
+ * </button>
65
+ * {error && <span>Failed to copy: {error.message}</span>}
66
+ * </div>
67
+ * );
68
+ * }
69
+ * ```
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * function ShareLink({url}: {url: string}) {
74
+ * const {copied, copy} = useClipboard();
75
+ *
76
+ * return (
77
+ * <button onClick={() => copy(url)} disabled={copied}>
78
+ * {copied ? "✓ Copied" : "Share link"}
79
+ * </button>
80
+ * );
81
+ * }
82
+ * ```
83
+ */
84
+ export function useClipboard(options: UseClipboardOptions = {}): UseClipboardReturn {
85
+ const {timeout = 2000} = options;
86
+
87
+ const [copied, setCopied] = React.useState(false);
88
+ const [error, setError] = React.useState<Error | null>(null);
89
+ const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
90
+
91
+ const copy = React.useCallback(
92
+ async (text: string): Promise<void> => {
93
+ // Clear any existing timeout
94
+ if (timeoutRef.current !== null) {
95
+ clearTimeout(timeoutRef.current);
96
+ timeoutRef.current = null;
97
+ }
98
+
99
+ // Reset error state
100
+ setError(null);
101
+
102
+ try {
103
+ // Check if Clipboard API is available
104
+ if (typeof globalThis.navigator === "undefined" || !globalThis.navigator.clipboard) {
105
+ throw new Error("Clipboard API is not available");
106
+ }
107
+
108
+ await globalThis.navigator.clipboard.writeText(text);
109
+ setCopied(true);
110
+
111
+ // Reset copied state after timeout
112
+ timeoutRef.current = setTimeout(() => {
113
+ setCopied(false);
114
+ timeoutRef.current = null;
115
+ }, timeout);
116
+ } catch (err) {
117
+ const errorMessage = err instanceof Error ? err : new Error("Failed to copy to clipboard");
118
+
119
+ setError(errorMessage);
120
+ setCopied(false);
121
+ console.error("Copy to clipboard failed:", errorMessage);
122
+ }
123
+ },
124
+ [timeout],
125
+ );
126
+
127
+ // Cleanup timeout on unmount
128
+ React.useEffect(() => {
129
+ return () => {
130
+ if (timeoutRef.current !== null) {
131
+ clearTimeout(timeoutRef.current);
132
+ }
133
+ };
134
+ }, []);
135
+
136
+ return {copied, copy, error};
137
+ }
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Options for configuring controllable state behavior.
7
+ *
8
+ * @typeParam T - The type of the state value.
9
+ */
10
+ export interface UseControllableStateOptions<T> {
11
+ /**
12
+ * The controlled value from props. When provided, the component operates in controlled mode.
13
+ */
14
+ controlled?: T;
15
+ /**
16
+ * The default value used when the component is uncontrolled.
17
+ */
18
+ defaultValue: T;
19
+ /**
20
+ * Callback fired when the internal state changes in controlled mode.
21
+ *
22
+ * @param value - The new state value.
23
+ */
24
+ onChange?: (value: T) => void;
25
+ }
26
+
27
+ /**
28
+ * Manages state that can be either controlled or uncontrolled.
29
+ *
30
+ * @remarks
31
+ * This hook enables components to support both controlled and uncontrolled patterns
32
+ * seamlessly. When a `controlled` value is provided, it takes precedence; otherwise,
33
+ * the hook manages internal state initialized with `defaultValue`.
34
+ *
35
+ * @typeParam T - The type of the state value.
36
+ * @param options - Configuration object for controllable state.
37
+ * @returns A tuple containing the current state value and a setter function.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * function CustomInput({value, defaultValue = "", onChange}) {
42
+ * const [internalValue, setValue] = useControllableState({
43
+ * controlled: value,
44
+ * defaultValue,
45
+ * onChange,
46
+ * });
47
+ *
48
+ * return (
49
+ * <input
50
+ * type="text"
51
+ * value={internalValue}
52
+ * onChange={(e) => setValue(e.target.value)}
53
+ * />
54
+ * );
55
+ * }
56
+ * ```
57
+ */
58
+ export function useControllableState<T>(options: UseControllableStateOptions<T>): [T, (value: T | ((prev: T) => T)) => void] {
59
+ const {controlled, defaultValue, onChange} = options;
60
+ const [uncontrolledState, setUncontrolledState] = React.useState<T>(defaultValue);
61
+ const isControlled = controlled !== undefined;
62
+ const value = isControlled ? controlled : uncontrolledState;
63
+
64
+ const setValue = React.useCallback(
65
+ (nextValue: T | ((prev: T) => T)) => {
66
+ if (!isControlled) {
67
+ setUncontrolledState((currentValue) => {
68
+ const resolvedValue = typeof nextValue === "function" ? (nextValue as (prev: T) => T)(currentValue) : nextValue;
69
+ onChange?.(resolvedValue);
70
+ return resolvedValue;
71
+ });
72
+ } else {
73
+ const resolvedValue = typeof nextValue === "function" ? (nextValue as (prev: T) => T)(controlled as T) : nextValue;
74
+ onChange?.(resolvedValue);
75
+ }
76
+ },
77
+ [isControlled, onChange, controlled],
78
+ );
79
+
80
+ return [value, setValue];
81
+ }
@@ -0,0 +1,50 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Debounces a value, delaying updates until after the specified delay has elapsed.
7
+ *
8
+ * @remarks
9
+ * This hook returns a debounced version of the provided value that only updates
10
+ * after the value has stopped changing for the specified delay. Useful for optimizing
11
+ * performance in scenarios like search inputs, where you want to avoid triggering
12
+ * expensive operations on every keystroke.
13
+ *
14
+ * The debounce timer resets on every value change and cleans up automatically on unmount.
15
+ *
16
+ * @typeParam T - The type of the value being debounced.
17
+ * @param value - The value to debounce.
18
+ * @param delay - The delay in milliseconds before the debounced value updates.
19
+ * @returns The debounced value.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * function SearchInput() {
24
+ * const [searchTerm, setSearchTerm] = useState("");
25
+ * const debouncedSearchTerm = useDebounce(searchTerm, 500);
26
+ *
27
+ * useEffect(() => {
28
+ * // Expensive search operation
29
+ * performSearch(debouncedSearchTerm);
30
+ * }, [debouncedSearchTerm]);
31
+ *
32
+ * return <input value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} />;
33
+ * }
34
+ * ```
35
+ */
36
+ export function useDebounce<T>(value: T, delay: number): T {
37
+ const [debouncedValue, setDebouncedValue] = React.useState<T>(value);
38
+
39
+ React.useEffect(() => {
40
+ const timeoutId = globalThis.setTimeout(() => {
41
+ setDebouncedValue(value);
42
+ }, delay);
43
+
44
+ return () => {
45
+ globalThis.clearTimeout(timeoutId);
46
+ };
47
+ }, [value, delay]);
48
+
49
+ return debouncedValue;
50
+ }
@@ -0,0 +1,47 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Creates a stable callback reference that always calls the latest version of the provided function.
7
+ *
8
+ * @remarks
9
+ * Unlike `useCallback`, this hook returns a stable function reference that never changes,
10
+ * but always invokes the most recent version of the callback. This is useful when you need
11
+ * to pass callbacks to optimized child components or effects without triggering re-renders
12
+ * when dependencies change.
13
+ *
14
+ * The returned function is safe to use in dependency arrays because its identity never changes.
15
+ *
16
+ * @typeParam Args - The tuple type of the callback's arguments.
17
+ * @typeParam Return - The return type of the callback.
18
+ * @param callback - The function to wrap with a stable reference.
19
+ * @returns A stable function reference that invokes the latest callback.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * function SearchInput({onSearch}) {
24
+ * const [query, setQuery] = useState("");
25
+ * // stableOnSearch never changes identity, but always calls the latest onSearch
26
+ * const stableOnSearch = useEventCallback(onSearch);
27
+ *
28
+ * useEffect(() => {
29
+ * const timer = setTimeout(() => stableOnSearch(query), 500);
30
+ * return () => clearTimeout(timer);
31
+ * }, [query, stableOnSearch]); // Safe to include in deps
32
+ *
33
+ * return <input value={query} onChange={(e) => setQuery(e.target.value)} />;
34
+ * }
35
+ * ```
36
+ */
37
+ export function useEventCallback<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return {
38
+ const callbackRef = React.useRef(callback);
39
+
40
+ React.useLayoutEffect(() => {
41
+ callbackRef.current = callback;
42
+ });
43
+
44
+ return React.useCallback((...args: Args) => {
45
+ return callbackRef.current(...args);
46
+ }, []);
47
+ }
@@ -0,0 +1,36 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Generates a unique, stable identifier that is safe for server-side rendering.
7
+ *
8
+ * @remarks
9
+ * This hook wraps React's `useId` and optionally prepends a custom prefix.
10
+ * The generated ID remains stable across re-renders and matches between server
11
+ * and client, making it ideal for associating form labels with inputs or
12
+ * managing accessible ARIA relationships.
13
+ *
14
+ * @param prefix - Optional string to prepend to the generated ID.
15
+ * @returns A unique identifier string.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function FormField({label}) {
20
+ * const id = useId("field");
21
+ *
22
+ * return (
23
+ * <div>
24
+ * <label htmlFor={id}>{label}</label>
25
+ * <input id={id} type="text" />
26
+ * </div>
27
+ * );
28
+ * }
29
+ * ```
30
+ *
31
+ * @see {@link https://react.dev/reference/react/useId | React useId}
32
+ */
33
+ export function useId(prefix?: string): string {
34
+ const reactId = React.useId();
35
+ return prefix ? `${prefix}-${reactId}` : reactId;
36
+ }
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Observes element visibility using the Intersection Observer API.
7
+ *
8
+ * @remarks
9
+ * This hook creates an IntersectionObserver that watches the provided element
10
+ * reference and returns the latest `IntersectionObserverEntry`. It's useful
11
+ * for implementing lazy loading, infinite scroll, animations on scroll, and
12
+ * tracking element visibility.
13
+ *
14
+ * The observer automatically disconnects when the component unmounts or when
15
+ * the element reference changes. The hook is SSR-safe and returns `null` when
16
+ * running on the server or when the observer is not yet initialized.
17
+ *
18
+ * @param ref - A React ref object pointing to the element to observe.
19
+ * @param options - Optional IntersectionObserver configuration (threshold, root, rootMargin).
20
+ * @returns The latest IntersectionObserverEntry or null if not intersecting yet.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * function LazyImage({src, alt}: {src: string; alt: string}) {
25
+ * const imageRef = useRef<HTMLImageElement>(null);
26
+ * const entry = useIntersectionObserver(imageRef, {threshold: 0.1});
27
+ *
28
+ * return (
29
+ * <img
30
+ * ref={imageRef}
31
+ * src={entry?.isIntersecting ? src : undefined}
32
+ * alt={alt}
33
+ * />
34
+ * );
35
+ * }
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * function AnimateOnScroll({children}: {children: React.ReactNode}) {
41
+ * const ref = useRef<HTMLDivElement>(null);
42
+ * const entry = useIntersectionObserver(ref, {threshold: 0.5});
43
+ * const isVisible = entry?.isIntersecting ?? false;
44
+ *
45
+ * return (
46
+ * <div ref={ref} className={isVisible ? "fade-in" : "hidden"}>
47
+ * {children}
48
+ * </div>
49
+ * );
50
+ * }
51
+ * ```
52
+ */
53
+ export function useIntersectionObserver(
54
+ ref: React.RefObject<Element | null>,
55
+ options?: IntersectionObserverInit,
56
+ ): IntersectionObserverEntry | null {
57
+ const [entry, setEntry] = React.useState<IntersectionObserverEntry | null>(null);
58
+
59
+ React.useEffect(() => {
60
+ const element = ref.current;
61
+
62
+ // SSR safety: IntersectionObserver is not available on server
63
+ if (typeof globalThis.IntersectionObserver === "undefined" || !element) {
64
+ return;
65
+ }
66
+
67
+ const observer = new globalThis.IntersectionObserver(([observerEntry]) => {
68
+ if (observerEntry) {
69
+ setEntry(observerEntry);
70
+ }
71
+ }, options);
72
+
73
+ observer.observe(element);
74
+
75
+ return () => {
76
+ observer.disconnect();
77
+ };
78
+ }, [ref, options?.threshold, options?.root, options?.rootMargin]);
79
+
80
+ return entry;
81
+ }
@@ -0,0 +1,80 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Executes a callback function at specified intervals with automatic cleanup.
7
+ *
8
+ * @remarks
9
+ * This hook provides a declarative interface for `setInterval` that automatically
10
+ * handles cleanup on unmount and ensures the latest callback is always invoked
11
+ * (preventing stale closures). Setting the delay to `null` pauses the interval,
12
+ * which is useful for implementing play/pause functionality.
13
+ *
14
+ * Unlike raw `setInterval`, this hook guarantees that the interval is cleared
15
+ * when the component unmounts or when the delay changes, preventing memory leaks
16
+ * and unexpected behavior.
17
+ *
18
+ * @param callback - The function to execute at each interval.
19
+ * @param delay - The interval delay in milliseconds, or `null` to pause the interval.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * function Timer() {
24
+ * const [count, setCount] = useState(0);
25
+ *
26
+ * useInterval(() => {
27
+ * setCount((c) => c + 1);
28
+ * }, 1000);
29
+ *
30
+ * return <div>Count: {count}</div>;
31
+ * }
32
+ * ```
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * function PausableTimer() {
37
+ * const [count, setCount] = useState(0);
38
+ * const [isRunning, setIsRunning] = useState(true);
39
+ *
40
+ * useInterval(
41
+ * () => {
42
+ * setCount((c) => c + 1);
43
+ * },
44
+ * isRunning ? 1000 : null,
45
+ * );
46
+ *
47
+ * return (
48
+ * <div>
49
+ * <div>Count: {count}</div>
50
+ * <button onClick={() => setIsRunning(!isRunning)}>
51
+ * {isRunning ? "Pause" : "Resume"}
52
+ * </button>
53
+ * </div>
54
+ * );
55
+ * }
56
+ * ```
57
+ */
58
+ export function useInterval(callback: () => void, delay: number | null): void {
59
+ const savedCallback = React.useRef(callback);
60
+
61
+ // Update ref to latest callback on every render to avoid stale closures
62
+ React.useEffect(() => {
63
+ savedCallback.current = callback;
64
+ }, [callback]);
65
+
66
+ React.useEffect(() => {
67
+ // Don't schedule if delay is null
68
+ if (delay === null) {
69
+ return;
70
+ }
71
+
72
+ const intervalId = globalThis.setInterval(() => {
73
+ savedCallback.current();
74
+ }, delay);
75
+
76
+ return () => {
77
+ globalThis.clearInterval(intervalId);
78
+ };
79
+ }, [delay]);
80
+ }
@@ -0,0 +1,111 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Persists state to localStorage with SSR safety and JSON serialization.
7
+ *
8
+ * @remarks
9
+ * This hook synchronizes state with localStorage, allowing data to persist
10
+ * across page refreshes and browser sessions. It is SSR-safe and returns the
11
+ * initial value on the server until hydration completes. The hook also syncs
12
+ * state across tabs/windows via the `storage` event and handles JSON parse
13
+ * errors gracefully by falling back to the initial value.
14
+ *
15
+ * @typeParam T - The type of the value being stored.
16
+ * @param key - The localStorage key to store the value under.
17
+ * @param initialValue - The default value to use if no value is found in localStorage.
18
+ * @returns A tuple containing the current value and a setter function.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * function UserSettings() {
23
+ * const [theme, setTheme] = useLocalStorage("theme", "light");
24
+ *
25
+ * return (
26
+ * <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>
27
+ * Toggle theme (current: {theme})
28
+ * </button>
29
+ * );
30
+ * }
31
+ * ```
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * function ShoppingCart() {
36
+ * const [cart, setCart] = useLocalStorage<Product[]>("cart", []);
37
+ *
38
+ * return (
39
+ * <button onClick={() => setCart((prev) => [...prev, newProduct])}>
40
+ * Add to cart ({cart.length} items)
41
+ * </button>
42
+ * );
43
+ * }
44
+ * ```
45
+ */
46
+ export function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T | ((prev: T) => T)) => void] {
47
+ const [storedValue, setStoredValue] = React.useState<T>(() => {
48
+ // SSR safety: return initial value on server
49
+ if (typeof globalThis.window === "undefined") {
50
+ return initialValue;
51
+ }
52
+
53
+ try {
54
+ const item = globalThis.window.localStorage.getItem(key);
55
+
56
+ return item !== null ? (JSON.parse(item) as T) : initialValue;
57
+ } catch (error) {
58
+ console.error(`Error reading localStorage key "${key}":`, error);
59
+
60
+ return initialValue;
61
+ }
62
+ });
63
+
64
+ const setValue = React.useCallback(
65
+ (value: T | ((prev: T) => T)) => {
66
+ try {
67
+ setStoredValue((currentValue) => {
68
+ const valueToStore = value instanceof Function ? value(currentValue) : value;
69
+
70
+ if (typeof globalThis.window !== "undefined") {
71
+ globalThis.window.localStorage.setItem(key, JSON.stringify(valueToStore));
72
+ }
73
+
74
+ return valueToStore;
75
+ });
76
+ } catch (error) {
77
+ console.error(`Error setting localStorage key "${key}":`, error);
78
+ }
79
+ },
80
+ [key],
81
+ );
82
+
83
+ React.useEffect(() => {
84
+ // SSR safety: window is not available on server
85
+ if (typeof globalThis.window === "undefined") {
86
+ return;
87
+ }
88
+
89
+ const handleStorageChange = (event: StorageEvent) => {
90
+ if (event.key !== key || event.storageArea !== globalThis.window.localStorage) {
91
+ return;
92
+ }
93
+
94
+ try {
95
+ const newValue = event.newValue !== null ? (JSON.parse(event.newValue) as T) : initialValue;
96
+
97
+ setStoredValue(newValue);
98
+ } catch (error) {
99
+ console.error(`Error parsing storage event for key "${key}":`, error);
100
+ }
101
+ };
102
+
103
+ globalThis.window.addEventListener("storage", handleStorageChange);
104
+
105
+ return () => {
106
+ globalThis.window.removeEventListener("storage", handleStorageChange);
107
+ };
108
+ }, [key, initialValue]);
109
+
110
+ return [storedValue, setValue];
111
+ }
@@ -0,0 +1,48 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Merges multiple refs into a single callback ref.
7
+ *
8
+ * @remarks
9
+ * This hook is essential when you need to attach multiple refs to the same element,
10
+ * such as combining a forwarded ref with an internal ref for measurements or
11
+ * imperative operations. All provided refs will receive the same element instance.
12
+ *
13
+ * Supports all ref types: callback refs, mutable ref objects, and `null`/`undefined`.
14
+ *
15
+ * @typeParam T - The type of the element being referenced.
16
+ * @param refs - An array of refs to merge. Can include callback refs, ref objects, or undefined.
17
+ * @returns A callback ref that updates all provided refs.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * const MyComponent = React.forwardRef<HTMLDivElement, Props>((props, forwardedRef) => {
22
+ * const internalRef = useRef<HTMLDivElement>(null);
23
+ * const mergedRef = useMergedRefs(forwardedRef, internalRef);
24
+ *
25
+ * return <div ref={mergedRef}>Content</div>;
26
+ * });
27
+ * ```
28
+ */
29
+ export function useMergedRefs<T>(...refs: Array<React.Ref<T> | undefined>): React.RefCallback<T> {
30
+ return React.useCallback(
31
+ (element: T | null) => {
32
+ for (const ref of refs) {
33
+ if (!ref) {
34
+ continue;
35
+ }
36
+
37
+ if (typeof ref === "function") {
38
+ ref(element);
39
+ } else {
40
+ // Mutable ref object
41
+ (ref as React.MutableRefObject<T | null>).current = element;
42
+ }
43
+ }
44
+ },
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ refs,
47
+ );
48
+ }