@arolariu/components 0.1.2 → 0.2.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 (323) hide show
  1. package/DEBUGGING.md +396 -396
  2. package/LICENSE.md +21 -21
  3. package/changelog.md +109 -118
  4. package/dist/components/ui/accordion.d.ts +2 -2
  5. package/dist/components/ui/accordion.d.ts.map +1 -1
  6. package/dist/components/ui/accordion.js +4 -4
  7. package/dist/components/ui/accordion.js.map +1 -1
  8. package/dist/components/ui/alert-dialog.d.ts +13 -13
  9. package/dist/components/ui/alert-dialog.d.ts.map +1 -1
  10. package/dist/components/ui/alert-dialog.js +4 -4
  11. package/dist/components/ui/alert-dialog.js.map +1 -1
  12. package/dist/components/ui/alert.d.ts +5 -5
  13. package/dist/components/ui/alert.d.ts.map +1 -1
  14. package/dist/components/ui/alert.js +3 -3
  15. package/dist/components/ui/alert.js.map +1 -1
  16. package/dist/components/ui/aspect-ratio.d.ts +1 -1
  17. package/dist/components/ui/aspect-ratio.d.ts.map +1 -1
  18. package/dist/components/ui/aspect-ratio.js +1 -1
  19. package/dist/components/ui/aspect-ratio.js.map +1 -1
  20. package/dist/components/ui/avatar.d.ts +2 -2
  21. package/dist/components/ui/avatar.d.ts.map +1 -1
  22. package/dist/components/ui/avatar.js +3 -3
  23. package/dist/components/ui/avatar.js.map +1 -1
  24. package/dist/components/ui/background-beams.d.ts.map +1 -1
  25. package/dist/components/ui/background-beams.js +6 -6
  26. package/dist/components/ui/background-beams.js.map +1 -1
  27. package/dist/components/ui/badge.d.ts +4 -4
  28. package/dist/components/ui/badge.d.ts.map +1 -1
  29. package/dist/components/ui/badge.js +2 -2
  30. package/dist/components/ui/badge.js.map +1 -1
  31. package/dist/components/ui/breadcrumb.d.ts +6 -6
  32. package/dist/components/ui/breadcrumb.d.ts.map +1 -1
  33. package/dist/components/ui/breadcrumb.js +5 -5
  34. package/dist/components/ui/breadcrumb.js.map +1 -1
  35. package/dist/components/ui/bubble-background.d.ts +1 -1
  36. package/dist/components/ui/bubble-background.d.ts.map +1 -1
  37. package/dist/components/ui/bubble-background.js +13 -13
  38. package/dist/components/ui/bubble-background.js.map +1 -1
  39. package/dist/components/ui/button.d.ts +5 -5
  40. package/dist/components/ui/button.d.ts.map +1 -1
  41. package/dist/components/ui/button.js +2 -2
  42. package/dist/components/ui/button.js.map +1 -1
  43. package/dist/components/ui/calendar.d.ts.map +1 -1
  44. package/dist/components/ui/calendar.js +4 -4
  45. package/dist/components/ui/calendar.js.map +1 -1
  46. package/dist/components/ui/card.d.ts +1 -1
  47. package/dist/components/ui/card.d.ts.map +1 -1
  48. package/dist/components/ui/card.js +3 -3
  49. package/dist/components/ui/card.js.map +1 -1
  50. package/dist/components/ui/carousel.d.ts +2 -2
  51. package/dist/components/ui/carousel.d.ts.map +1 -1
  52. package/dist/components/ui/carousel.js +3 -3
  53. package/dist/components/ui/carousel.js.map +1 -1
  54. package/dist/components/ui/chart.d.ts +4 -4
  55. package/dist/components/ui/chart.d.ts.map +1 -1
  56. package/dist/components/ui/chart.js +1 -1
  57. package/dist/components/ui/chart.js.map +1 -1
  58. package/dist/components/ui/checkbox.d.ts +1 -1
  59. package/dist/components/ui/checkbox.d.ts.map +1 -1
  60. package/dist/components/ui/checkbox.js +3 -3
  61. package/dist/components/ui/checkbox.js.map +1 -1
  62. package/dist/components/ui/collapsible.d.ts +2 -2
  63. package/dist/components/ui/collapsible.d.ts.map +1 -1
  64. package/dist/components/ui/collapsible.js +1 -1
  65. package/dist/components/ui/collapsible.js.map +1 -1
  66. package/dist/components/ui/command.d.ts +2 -2
  67. package/dist/components/ui/command.d.ts.map +1 -1
  68. package/dist/components/ui/command.js +9 -9
  69. package/dist/components/ui/command.js.map +1 -1
  70. package/dist/components/ui/context-menu.d.ts +2 -2
  71. package/dist/components/ui/context-menu.d.ts.map +1 -1
  72. package/dist/components/ui/context-menu.js +11 -11
  73. package/dist/components/ui/context-menu.js.map +1 -1
  74. package/dist/components/ui/counting-number.d.ts +1 -1
  75. package/dist/components/ui/counting-number.d.ts.map +1 -1
  76. package/dist/components/ui/counting-number.js +4 -3
  77. package/dist/components/ui/counting-number.js.map +1 -1
  78. package/dist/components/ui/dialog.d.ts +1 -1
  79. package/dist/components/ui/dialog.d.ts.map +1 -1
  80. package/dist/components/ui/dialog.js +6 -6
  81. package/dist/components/ui/dialog.js.map +1 -1
  82. package/dist/components/ui/dot-background.d.ts +10 -17
  83. package/dist/components/ui/dot-background.d.ts.map +1 -1
  84. package/dist/components/ui/dot-background.js +2 -2
  85. package/dist/components/ui/dot-background.js.map +1 -1
  86. package/dist/components/ui/drawer.d.ts +1 -1
  87. package/dist/components/ui/drawer.d.ts.map +1 -1
  88. package/dist/components/ui/drawer.js +5 -5
  89. package/dist/components/ui/drawer.js.map +1 -1
  90. package/dist/components/ui/dropdown-menu.d.ts +2 -2
  91. package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
  92. package/dist/components/ui/dropdown-menu.js +10 -10
  93. package/dist/components/ui/dropdown-menu.js.map +1 -1
  94. package/dist/components/ui/dropdrawer.d.ts +2 -2
  95. package/dist/components/ui/dropdrawer.d.ts.map +1 -1
  96. package/dist/components/ui/dropdrawer.js +12 -12
  97. package/dist/components/ui/dropdrawer.js.map +1 -1
  98. package/dist/components/ui/fireworks-background.d.ts.map +1 -1
  99. package/dist/components/ui/fireworks-background.js +1 -1
  100. package/dist/components/ui/fireworks-background.js.map +1 -1
  101. package/dist/components/ui/flip-button.d.ts +1 -1
  102. package/dist/components/ui/flip-button.d.ts.map +1 -1
  103. package/dist/components/ui/flip-button.js +3 -3
  104. package/dist/components/ui/flip-button.js.map +1 -1
  105. package/dist/components/ui/form.d.ts +3 -3
  106. package/dist/components/ui/form.d.ts.map +1 -1
  107. package/dist/components/ui/form.js +4 -4
  108. package/dist/components/ui/form.js.map +1 -1
  109. package/dist/components/ui/gradient-background.d.ts +1 -1
  110. package/dist/components/ui/gradient-background.d.ts.map +1 -1
  111. package/dist/components/ui/gradient-background.js +2 -2
  112. package/dist/components/ui/gradient-background.js.map +1 -1
  113. package/dist/components/ui/gradient-text.d.ts +1 -1
  114. package/dist/components/ui/gradient-text.d.ts.map +1 -1
  115. package/dist/components/ui/gradient-text.js +5 -5
  116. package/dist/components/ui/gradient-text.js.map +1 -1
  117. package/dist/components/ui/highlight-text.d.ts +1 -1
  118. package/dist/components/ui/highlight-text.d.ts.map +1 -1
  119. package/dist/components/ui/highlight-text.js +3 -3
  120. package/dist/components/ui/highlight-text.js.map +1 -1
  121. package/dist/components/ui/hole-background.d.ts.map +1 -1
  122. package/dist/components/ui/hole-background.js +11 -10
  123. package/dist/components/ui/hole-background.js.map +1 -1
  124. package/dist/components/ui/hover-card.d.ts +2 -2
  125. package/dist/components/ui/hover-card.d.ts.map +1 -1
  126. package/dist/components/ui/hover-card.js +3 -3
  127. package/dist/components/ui/hover-card.js.map +1 -1
  128. package/dist/components/ui/input-otp.d.ts +2 -2
  129. package/dist/components/ui/input-otp.d.ts.map +1 -1
  130. package/dist/components/ui/input-otp.js +5 -5
  131. package/dist/components/ui/input-otp.js.map +1 -1
  132. package/dist/components/ui/input.d.ts.map +1 -1
  133. package/dist/components/ui/input.js +2 -2
  134. package/dist/components/ui/input.js.map +1 -1
  135. package/dist/components/ui/label.d.ts +1 -1
  136. package/dist/components/ui/label.d.ts.map +1 -1
  137. package/dist/components/ui/label.js +2 -2
  138. package/dist/components/ui/label.js.map +1 -1
  139. package/dist/components/ui/menubar.d.ts +2 -2
  140. package/dist/components/ui/menubar.d.ts.map +1 -1
  141. package/dist/components/ui/menubar.js +12 -12
  142. package/dist/components/ui/menubar.js.map +1 -1
  143. package/dist/components/ui/navigation-menu.d.ts +3 -3
  144. package/dist/components/ui/navigation-menu.d.ts.map +1 -1
  145. package/dist/components/ui/navigation-menu.js +6 -7
  146. package/dist/components/ui/navigation-menu.js.map +1 -1
  147. package/dist/components/ui/pagination.d.ts +2 -2
  148. package/dist/components/ui/pagination.d.ts.map +1 -1
  149. package/dist/components/ui/pagination.js +8 -4
  150. package/dist/components/ui/pagination.js.map +1 -1
  151. package/dist/components/ui/popover.d.ts +2 -2
  152. package/dist/components/ui/popover.d.ts.map +1 -1
  153. package/dist/components/ui/popover.js +3 -3
  154. package/dist/components/ui/popover.js.map +1 -1
  155. package/dist/components/ui/progress.d.ts +1 -1
  156. package/dist/components/ui/progress.d.ts.map +1 -1
  157. package/dist/components/ui/progress.js +4 -4
  158. package/dist/components/ui/progress.js.map +1 -1
  159. package/dist/components/ui/radio-group.d.ts +1 -1
  160. package/dist/components/ui/radio-group.d.ts.map +1 -1
  161. package/dist/components/ui/radio-group.js +3 -3
  162. package/dist/components/ui/radio-group.js.map +1 -1
  163. package/dist/components/ui/resizable.d.ts +1 -1
  164. package/dist/components/ui/resizable.d.ts.map +1 -1
  165. package/dist/components/ui/resizable.js +5 -5
  166. package/dist/components/ui/resizable.js.map +1 -1
  167. package/dist/components/ui/ripple-button.d.ts +1 -1
  168. package/dist/components/ui/ripple-button.d.ts.map +1 -1
  169. package/dist/components/ui/ripple-button.js +4 -4
  170. package/dist/components/ui/ripple-button.js.map +1 -1
  171. package/dist/components/ui/scratcher.d.ts.map +1 -1
  172. package/dist/components/ui/scratcher.js +7 -5
  173. package/dist/components/ui/scratcher.js.map +1 -1
  174. package/dist/components/ui/scroll-area.d.ts +1 -1
  175. package/dist/components/ui/scroll-area.d.ts.map +1 -1
  176. package/dist/components/ui/scroll-area.js +4 -4
  177. package/dist/components/ui/scroll-area.js.map +1 -1
  178. package/dist/components/ui/select.d.ts +1 -1
  179. package/dist/components/ui/select.d.ts.map +1 -1
  180. package/dist/components/ui/select.js +7 -7
  181. package/dist/components/ui/select.js.map +1 -1
  182. package/dist/components/ui/separator.d.ts +1 -1
  183. package/dist/components/ui/separator.d.ts.map +1 -1
  184. package/dist/components/ui/separator.js +3 -3
  185. package/dist/components/ui/separator.js.map +1 -1
  186. package/dist/components/ui/sheet.d.ts +2 -2
  187. package/dist/components/ui/sheet.d.ts.map +1 -1
  188. package/dist/components/ui/sheet.js +6 -6
  189. package/dist/components/ui/sheet.js.map +1 -1
  190. package/dist/components/ui/sidebar.d.ts +5 -5
  191. package/dist/components/ui/sidebar.d.ts.map +1 -1
  192. package/dist/components/ui/sidebar.js +5 -5
  193. package/dist/components/ui/sidebar.js.map +1 -1
  194. package/dist/components/ui/skeleton.d.ts.map +1 -1
  195. package/dist/components/ui/skeleton.js +2 -2
  196. package/dist/components/ui/skeleton.js.map +1 -1
  197. package/dist/components/ui/slider.d.ts +1 -1
  198. package/dist/components/ui/slider.d.ts.map +1 -1
  199. package/dist/components/ui/slider.js +5 -5
  200. package/dist/components/ui/slider.js.map +1 -1
  201. package/dist/components/ui/sonner.d.ts +1 -1
  202. package/dist/components/ui/sonner.d.ts.map +1 -1
  203. package/dist/components/ui/sonner.js +1 -1
  204. package/dist/components/ui/sonner.js.map +1 -1
  205. package/dist/components/ui/switch.d.ts +1 -1
  206. package/dist/components/ui/switch.d.ts.map +1 -1
  207. package/dist/components/ui/switch.js +4 -4
  208. package/dist/components/ui/switch.js.map +1 -1
  209. package/dist/components/ui/table.d.ts +1 -1
  210. package/dist/components/ui/table.d.ts.map +1 -1
  211. package/dist/components/ui/table.js +5 -5
  212. package/dist/components/ui/table.js.map +1 -1
  213. package/dist/components/ui/tabs.d.ts +2 -2
  214. package/dist/components/ui/tabs.d.ts.map +1 -1
  215. package/dist/components/ui/tabs.js +4 -4
  216. package/dist/components/ui/tabs.js.map +1 -1
  217. package/dist/components/ui/textarea.d.ts +1 -1
  218. package/dist/components/ui/textarea.d.ts.map +1 -1
  219. package/dist/components/ui/textarea.js +2 -2
  220. package/dist/components/ui/textarea.js.map +1 -1
  221. package/dist/components/ui/toggle-group.d.ts +3 -3
  222. package/dist/components/ui/toggle-group.d.ts.map +1 -1
  223. package/dist/components/ui/toggle-group.js +2 -2
  224. package/dist/components/ui/toggle-group.js.map +1 -1
  225. package/dist/components/ui/toggle.d.ts +6 -6
  226. package/dist/components/ui/toggle.d.ts.map +1 -1
  227. package/dist/components/ui/toggle.js +2 -2
  228. package/dist/components/ui/toggle.js.map +1 -1
  229. package/dist/components/ui/tooltip.d.ts +6 -6
  230. package/dist/components/ui/tooltip.d.ts.map +1 -1
  231. package/dist/components/ui/tooltip.js +4 -4
  232. package/dist/components/ui/tooltip.js.map +1 -1
  233. package/dist/components/ui/typewriter.d.ts.map +1 -1
  234. package/dist/components/ui/typewriter.js +15 -11
  235. package/dist/components/ui/typewriter.js.map +1 -1
  236. package/dist/hooks/useIsMobile.d.ts +2 -5
  237. package/dist/hooks/useIsMobile.d.ts.map +1 -1
  238. package/dist/hooks/useIsMobile.js +1 -1
  239. package/dist/hooks/useIsMobile.js.map +1 -1
  240. package/dist/hooks/useWindowSize.d.ts +0 -1
  241. package/dist/hooks/useWindowSize.d.ts.map +1 -1
  242. package/dist/hooks/useWindowSize.js +1 -1
  243. package/dist/hooks/useWindowSize.js.map +1 -1
  244. package/dist/index.css +2 -2
  245. package/dist/index.css.map +1 -1
  246. package/dist/index.d.ts +37 -37
  247. package/dist/index.d.ts.map +1 -1
  248. package/dist/index.js +2 -2
  249. package/dist/lib/utilities.d.ts +9 -0
  250. package/dist/lib/utilities.d.ts.map +1 -0
  251. package/dist/lib/{utils.js → utilities.js} +1 -1
  252. package/dist/lib/utilities.js.map +1 -0
  253. package/package.json +85 -89
  254. package/{README.md → readme.md} +627 -627
  255. package/src/components/ui/accordion.tsx +56 -66
  256. package/src/components/ui/alert-dialog.tsx +135 -160
  257. package/src/components/ui/alert.tsx +58 -69
  258. package/src/components/ui/aspect-ratio.tsx +15 -12
  259. package/src/components/ui/avatar.tsx +38 -53
  260. package/src/components/ui/background-beams.tsx +145 -142
  261. package/src/components/ui/badge.tsx +47 -48
  262. package/src/components/ui/breadcrumb.tsx +97 -117
  263. package/src/components/ui/bubble-background.tsx +170 -189
  264. package/src/components/ui/button.tsx +61 -61
  265. package/src/components/ui/calendar.tsx +177 -216
  266. package/src/components/ui/card.tsx +83 -97
  267. package/src/components/ui/carousel.tsx +204 -241
  268. package/src/components/ui/chart.tsx +303 -385
  269. package/src/components/ui/checkbox.tsx +27 -32
  270. package/src/components/ui/collapsible.tsx +33 -34
  271. package/src/components/ui/command.tsx +137 -184
  272. package/src/components/ui/context-menu.tsx +229 -255
  273. package/src/components/ui/counting-number.tsx +92 -108
  274. package/src/components/ui/dialog.tsx +141 -146
  275. package/src/components/ui/dot-background.tsx +153 -158
  276. package/src/components/ui/drawer.tsx +133 -141
  277. package/src/components/ui/dropdown-menu.tsx +235 -260
  278. package/src/components/ui/dropdrawer.tsx +870 -973
  279. package/src/components/ui/fireworks-background.tsx +325 -378
  280. package/src/components/ui/flip-button.tsx +89 -110
  281. package/src/components/ui/form.tsx +145 -174
  282. package/src/components/ui/gradient-background.tsx +30 -43
  283. package/src/components/ui/gradient-text.tsx +62 -65
  284. package/src/components/ui/highlight-text.tsx +54 -71
  285. package/src/components/ui/hole-background.tsx +326 -361
  286. package/src/components/ui/hover-card.tsx +48 -44
  287. package/src/components/ui/input-otp.tsx +76 -77
  288. package/src/components/ui/input.tsx +22 -22
  289. package/src/components/ui/label.tsx +21 -24
  290. package/src/components/ui/menubar.tsx +256 -279
  291. package/src/components/ui/navigation-menu.tsx +135 -171
  292. package/src/components/ui/pagination.tsx +103 -129
  293. package/src/components/ui/popover.tsx +52 -48
  294. package/src/components/ui/progress.tsx +23 -31
  295. package/src/components/ui/radio-group.tsx +37 -45
  296. package/src/components/ui/resizable.tsx +52 -56
  297. package/src/components/ui/ripple-button.tsx +90 -111
  298. package/src/components/ui/scratcher.tsx +167 -171
  299. package/src/components/ui/scroll-area.tsx +45 -58
  300. package/src/components/ui/select.tsx +160 -191
  301. package/src/components/ui/separator.tsx +28 -28
  302. package/src/components/ui/sheet.tsx +133 -145
  303. package/src/components/ui/sidebar.tsx +673 -729
  304. package/src/components/ui/skeleton.tsx +16 -19
  305. package/src/components/ui/slider.tsx +49 -63
  306. package/src/components/ui/sonner.tsx +30 -26
  307. package/src/components/ui/switch.tsx +27 -31
  308. package/src/components/ui/table.tsx +98 -119
  309. package/src/components/ui/tabs.tsx +54 -66
  310. package/src/components/ui/textarea.tsx +20 -20
  311. package/src/components/ui/toggle-group.tsx +66 -73
  312. package/src/components/ui/toggle.tsx +46 -47
  313. package/src/components/ui/tooltip.tsx +56 -61
  314. package/src/components/ui/typewriter.tsx +174 -188
  315. package/src/hooks/useIsMobile.tsx +42 -45
  316. package/src/hooks/useWindowSize.tsx +66 -72
  317. package/src/index.css +73 -73
  318. package/src/index.ts +303 -408
  319. package/src/lib/utilities.ts +12 -0
  320. package/dist/lib/utils.d.ts +0 -7
  321. package/dist/lib/utils.d.ts.map +0 -1
  322. package/dist/lib/utils.js.map +0 -1
  323. package/src/lib/utils.ts +0 -10
@@ -1,108 +1,92 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import {
5
- type SpringOptions,
6
- type UseInViewOptions,
7
- useInView,
8
- useMotionValue,
9
- useSpring,
10
- } from "motion/react";
11
-
12
- interface CountingNumberProps extends React.HTMLAttributes<HTMLSpanElement> {
13
- number: number;
14
- fromNumber?: number;
15
- padStart?: boolean;
16
- inView?: boolean;
17
- inViewMargin?: UseInViewOptions["margin"];
18
- inViewOnce?: boolean;
19
- decimalSeparator?: string;
20
- transition?: SpringOptions;
21
- decimalPlaces?: number;
22
- }
23
-
24
- const CountingNumber = React.forwardRef<HTMLSpanElement, CountingNumberProps>(
25
- (
26
- {
27
- number,
28
- fromNumber = 0,
29
- padStart = false,
30
- inView = false,
31
- inViewMargin = "0px",
32
- inViewOnce = true,
33
- decimalSeparator = ".",
34
- transition = { stiffness: 90, damping: 50 },
35
- decimalPlaces = 0,
36
- className,
37
- ...props
38
- },
39
- ref,
40
- ) => {
41
- const localRef = React.useRef<HTMLSpanElement>(null);
42
- React.useImperativeHandle(ref, () => localRef.current as HTMLSpanElement);
43
-
44
- const numberStr = number.toString();
45
- const decimals =
46
- typeof decimalPlaces === "number"
47
- ? decimalPlaces
48
- : numberStr.includes(".")
49
- ? numberStr.split(".")[1].length
50
- : 0;
51
-
52
- const motionVal = useMotionValue(fromNumber);
53
- const springVal = useSpring(motionVal, transition);
54
- const inViewResult = useInView(localRef, {
55
- once: inViewOnce,
56
- margin: inViewMargin,
57
- });
58
- const isInView = !inView || inViewResult;
59
-
60
- React.useEffect(() => {
61
- if (isInView) motionVal.set(number);
62
- }, [isInView, number, motionVal]);
63
-
64
- React.useEffect(() => {
65
- const unsubscribe = springVal.on("change", (latest) => {
66
- if (localRef.current) {
67
- let formatted =
68
- decimals > 0
69
- ? latest.toFixed(decimals)
70
- : Math.round(latest).toString();
71
-
72
- if (decimals > 0) {
73
- formatted = formatted.replace(".", decimalSeparator);
74
- }
75
-
76
- if (padStart) {
77
- const finalIntLength = Math.floor(Math.abs(number)).toString()
78
- .length;
79
- const [intPart, fracPart] = formatted.split(decimalSeparator);
80
- const paddedInt = intPart.padStart(finalIntLength, "0");
81
- formatted = fracPart
82
- ? `${paddedInt}${decimalSeparator}${fracPart}`
83
- : paddedInt;
84
- }
85
-
86
- localRef.current.textContent = formatted;
87
- }
88
- });
89
- return () => unsubscribe();
90
- }, [springVal, decimals, padStart, number, decimalSeparator]);
91
-
92
- const finalIntLength = Math.floor(Math.abs(number)).toString().length;
93
- const initialText = padStart
94
- ? "0".padStart(finalIntLength, "0") +
95
- (decimals > 0 ? decimalSeparator + "0".repeat(decimals) : "")
96
- : "0" + (decimals > 0 ? decimalSeparator + "0".repeat(decimals) : "");
97
-
98
- return (
99
- <span ref={localRef} className={className} {...props}>
100
- {initialText}
101
- </span>
102
- );
103
- },
104
- );
105
-
106
- CountingNumber.displayName = "CountingNumber";
107
-
108
- export { CountingNumber, type CountingNumberProps };
1
+ "use client";
2
+
3
+ import {type SpringOptions, type UseInViewOptions, useInView, useMotionValue, useSpring} from "motion/react";
4
+ import * as React from "react";
5
+
6
+ interface CountingNumberProps extends React.HTMLAttributes<HTMLSpanElement> {
7
+ number: number;
8
+ fromNumber?: number;
9
+ padStart?: boolean;
10
+ inView?: boolean;
11
+ inViewMargin?: UseInViewOptions["margin"];
12
+ inViewOnce?: boolean;
13
+ decimalSeparator?: string;
14
+ transition?: SpringOptions;
15
+ decimalPlaces?: number;
16
+ }
17
+
18
+ const CountingNumber = React.forwardRef<HTMLSpanElement, CountingNumberProps>(
19
+ (
20
+ {
21
+ number,
22
+ fromNumber = 0,
23
+ padStart = false,
24
+ inView = false,
25
+ inViewMargin = "0px",
26
+ inViewOnce = true,
27
+ decimalSeparator = ".",
28
+ transition = {stiffness: 90, damping: 50},
29
+ decimalPlaces = 0,
30
+ className,
31
+ ...props
32
+ },
33
+ ref,
34
+ ) => {
35
+ const localRef = React.useRef<HTMLSpanElement>(null);
36
+ React.useImperativeHandle(ref, () => localRef.current as HTMLSpanElement);
37
+
38
+ const numberStr = number.toString();
39
+ const decimals = typeof decimalPlaces === "number" ? decimalPlaces : numberStr.includes(".") ? numberStr?.split(".")[1].length : 0;
40
+
41
+ const motionVal = useMotionValue(fromNumber);
42
+ const springVal = useSpring(motionVal, transition);
43
+ const inViewResult = useInView(localRef, {
44
+ once: inViewOnce,
45
+ margin: inViewMargin,
46
+ });
47
+ const isInView = !inView || inViewResult;
48
+
49
+ React.useEffect(() => {
50
+ if (isInView) motionVal.set(number);
51
+ }, [isInView, number, motionVal]);
52
+
53
+ React.useEffect(() => {
54
+ const unsubscribe = springVal.on("change", (latest) => {
55
+ if (localRef.current) {
56
+ let formatted = decimals > 0 ? latest.toFixed(decimals) : Math.round(latest).toString();
57
+
58
+ if (decimals > 0) {
59
+ formatted = formatted.replace(".", decimalSeparator);
60
+ }
61
+
62
+ if (padStart) {
63
+ const finalIntLength = Math.floor(Math.abs(number)).toString().length;
64
+ const [intPart, fracPart] = formatted.split(decimalSeparator);
65
+ const paddedInt = intPart.padStart(finalIntLength, "0");
66
+ formatted = fracPart ? `${paddedInt}${decimalSeparator}${fracPart}` : paddedInt;
67
+ }
68
+
69
+ localRef.current.textContent = formatted;
70
+ }
71
+ });
72
+ return () => unsubscribe();
73
+ }, [springVal, decimals, padStart, number, decimalSeparator]);
74
+
75
+ const finalIntLength = Math.floor(Math.abs(number)).toString().length;
76
+ const suffix = decimals > 0 ? `${decimalSeparator}${"0".repeat(decimals)}` : "";
77
+ const initialText = padStart ? `${"0".padStart(finalIntLength, "0")}${suffix}` : `0${suffix}`;
78
+
79
+ return (
80
+ <span
81
+ ref={localRef}
82
+ className={className}
83
+ {...props}>
84
+ {initialText}
85
+ </span>
86
+ );
87
+ },
88
+ );
89
+
90
+ CountingNumber.displayName = "CountingNumber";
91
+
92
+ export {CountingNumber, type CountingNumberProps};
@@ -1,146 +1,141 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import * as DialogPrimitive from "@radix-ui/react-dialog";
5
- import { XIcon } from "lucide-react";
6
-
7
- import { cn } from "@/lib/utils";
8
-
9
- function Dialog({
10
- ...props
11
- }: React.ComponentProps<typeof DialogPrimitive.Root>) {
12
- return <DialogPrimitive.Root data-slot="dialog" {...props} />;
13
- }
14
-
15
- function DialogTrigger({
16
- ...props
17
- }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
18
- return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
19
- }
20
-
21
- function DialogPortal({
22
- ...props
23
- }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
24
- return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
25
- }
26
-
27
- function DialogClose({
28
- ...props
29
- }: React.ComponentProps<typeof DialogPrimitive.Close>) {
30
- return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
31
- }
32
-
33
- function DialogOverlay({
34
- className,
35
- ...props
36
- }: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
37
- return (
38
- <DialogPrimitive.Overlay
39
- data-slot="dialog-overlay"
40
- className={cn(
41
- "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
42
- className,
43
- )}
44
- {...props}
45
- />
46
- );
47
- }
48
-
49
- function DialogContent({
50
- className,
51
- children,
52
- showCloseButton = true,
53
- ...props
54
- }: React.ComponentProps<typeof DialogPrimitive.Content> & {
55
- showCloseButton?: boolean;
56
- }) {
57
- return (
58
- <DialogPortal data-slot="dialog-portal">
59
- <DialogOverlay />
60
- <DialogPrimitive.Content
61
- data-slot="dialog-content"
62
- className={cn(
63
- "bg-white data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-neutral-200 p-6 shadow-lg duration-200 sm:max-w-lg dark:bg-neutral-950 dark:border-neutral-800",
64
- className,
65
- )}
66
- {...props}
67
- >
68
- {children}
69
- {showCloseButton && (
70
- <DialogPrimitive.Close
71
- data-slot="dialog-close"
72
- className="ring-offset-white focus:ring-neutral-950 data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400"
73
- >
74
- <XIcon />
75
- <span className="sr-only">Close</span>
76
- </DialogPrimitive.Close>
77
- )}
78
- </DialogPrimitive.Content>
79
- </DialogPortal>
80
- );
81
- }
82
-
83
- function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
84
- return (
85
- <div
86
- data-slot="dialog-header"
87
- className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
88
- {...props}
89
- />
90
- );
91
- }
92
-
93
- function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
94
- return (
95
- <div
96
- data-slot="dialog-footer"
97
- className={cn(
98
- "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
99
- className,
100
- )}
101
- {...props}
102
- />
103
- );
104
- }
105
-
106
- function DialogTitle({
107
- className,
108
- ...props
109
- }: React.ComponentProps<typeof DialogPrimitive.Title>) {
110
- return (
111
- <DialogPrimitive.Title
112
- data-slot="dialog-title"
113
- className={cn("text-lg leading-none font-semibold", className)}
114
- {...props}
115
- />
116
- );
117
- }
118
-
119
- function DialogDescription({
120
- className,
121
- ...props
122
- }: React.ComponentProps<typeof DialogPrimitive.Description>) {
123
- return (
124
- <DialogPrimitive.Description
125
- data-slot="dialog-description"
126
- className={cn(
127
- "text-neutral-500 text-sm dark:text-neutral-400",
128
- className,
129
- )}
130
- {...props}
131
- />
132
- );
133
- }
134
-
135
- export {
136
- Dialog,
137
- DialogClose,
138
- DialogContent,
139
- DialogDescription,
140
- DialogFooter,
141
- DialogHeader,
142
- DialogOverlay,
143
- DialogPortal,
144
- DialogTitle,
145
- DialogTrigger,
146
- };
1
+ "use client";
2
+
3
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
4
+ import {XIcon} from "lucide-react";
5
+ import * as React from "react";
6
+
7
+ import {cn} from "@/lib/utilities";
8
+
9
+ function Dialog({...props}: React.ComponentProps<typeof DialogPrimitive.Root>) {
10
+ return (
11
+ <DialogPrimitive.Root
12
+ data-slot='dialog'
13
+ {...props}
14
+ />
15
+ );
16
+ }
17
+
18
+ function DialogTrigger({...props}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
19
+ return (
20
+ <DialogPrimitive.Trigger
21
+ data-slot='dialog-trigger'
22
+ {...props}
23
+ />
24
+ );
25
+ }
26
+
27
+ function DialogPortal({...props}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
28
+ return (
29
+ <DialogPrimitive.Portal
30
+ data-slot='dialog-portal'
31
+ {...props}
32
+ />
33
+ );
34
+ }
35
+
36
+ function DialogClose({...props}: React.ComponentProps<typeof DialogPrimitive.Close>) {
37
+ return (
38
+ <DialogPrimitive.Close
39
+ data-slot='dialog-close'
40
+ {...props}
41
+ />
42
+ );
43
+ }
44
+
45
+ function DialogOverlay({className, ...props}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
46
+ return (
47
+ <DialogPrimitive.Overlay
48
+ data-slot='dialog-overlay'
49
+ className={cn(
50
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
51
+ className,
52
+ )}
53
+ {...props}
54
+ />
55
+ );
56
+ }
57
+
58
+ function DialogContent({
59
+ className,
60
+ children,
61
+ showCloseButton = true,
62
+ ...props
63
+ }: React.ComponentProps<typeof DialogPrimitive.Content> & {
64
+ showCloseButton?: boolean;
65
+ }) {
66
+ return (
67
+ <DialogPortal data-slot='dialog-portal'>
68
+ <DialogOverlay />
69
+ <DialogPrimitive.Content
70
+ data-slot='dialog-content'
71
+ className={cn(
72
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-neutral-200 bg-white p-6 shadow-lg duration-200 sm:max-w-lg dark:border-neutral-800 dark:bg-neutral-950",
73
+ className,
74
+ )}
75
+ {...props}>
76
+ {children}
77
+ {Boolean(showCloseButton) && (
78
+ <DialogPrimitive.Close
79
+ data-slot='dialog-close'
80
+ className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
81
+ <XIcon />
82
+ <span className='sr-only'>Close</span>
83
+ </DialogPrimitive.Close>
84
+ )}
85
+ </DialogPrimitive.Content>
86
+ </DialogPortal>
87
+ );
88
+ }
89
+
90
+ function DialogHeader({className, ...props}: React.ComponentProps<"div">) {
91
+ return (
92
+ <div
93
+ data-slot='dialog-header'
94
+ className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
95
+ {...props}
96
+ />
97
+ );
98
+ }
99
+
100
+ function DialogFooter({className, ...props}: React.ComponentProps<"div">) {
101
+ return (
102
+ <div
103
+ data-slot='dialog-footer'
104
+ className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)}
105
+ {...props}
106
+ />
107
+ );
108
+ }
109
+
110
+ function DialogTitle({className, ...props}: React.ComponentProps<typeof DialogPrimitive.Title>) {
111
+ return (
112
+ <DialogPrimitive.Title
113
+ data-slot='dialog-title'
114
+ className={cn("text-lg leading-none font-semibold", className)}
115
+ {...props}
116
+ />
117
+ );
118
+ }
119
+
120
+ function DialogDescription({className, ...props}: React.ComponentProps<typeof DialogPrimitive.Description>) {
121
+ return (
122
+ <DialogPrimitive.Description
123
+ data-slot='dialog-description'
124
+ className={cn("text-sm text-neutral-500 dark:text-neutral-400", className)}
125
+ {...props}
126
+ />
127
+ );
128
+ }
129
+
130
+ export {
131
+ Dialog,
132
+ DialogClose,
133
+ DialogContent,
134
+ DialogDescription,
135
+ DialogFooter,
136
+ DialogHeader,
137
+ DialogOverlay,
138
+ DialogPortal,
139
+ DialogTitle,
140
+ DialogTrigger,
141
+ };