@wealthx/shadcn 1.0.2 → 1.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 (300) hide show
  1. package/.turbo/turbo-build.log +235 -138
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +82 -0
  4. package/dist/{chunk-6OJF6XRN.mjs → chunk-24FUO7TD.mjs} +4 -8
  5. package/dist/{chunk-4AJ5HWHD.mjs → chunk-2I5S2AMY.mjs} +3 -3
  6. package/dist/chunk-2SF672SZ.mjs +161 -0
  7. package/dist/{chunk-GPRJQ24C.mjs → chunk-34NWQURD.mjs} +2 -2
  8. package/dist/{chunk-MQ72DIBH.mjs → chunk-3GF7OVTP.mjs} +14 -5
  9. package/dist/chunk-3WMX6KWS.mjs +245 -0
  10. package/dist/{chunk-PMKODV6M.mjs → chunk-462HMNO4.mjs} +6 -10
  11. package/dist/chunk-4CX4SBRO.mjs +153 -0
  12. package/dist/chunk-4MN6UQHG.mjs +443 -0
  13. package/dist/chunk-5QQVZTVZ.mjs +233 -0
  14. package/dist/{chunk-BGP2N52Z.mjs → chunk-66MI7Q4B.mjs} +5 -5
  15. package/dist/chunk-6FCGKSZX.mjs +268 -0
  16. package/dist/{chunk-CGOKTPXU.mjs → chunk-6JQFUE5I.mjs} +20 -23
  17. package/dist/{chunk-Z3MK2KKZ.mjs → chunk-7DHU4VGG.mjs} +7 -3
  18. package/dist/{chunk-VZ2NR7L3.mjs → chunk-7PYJD5JI.mjs} +35 -27
  19. package/dist/{chunk-JU2RUWHF.mjs → chunk-7XJHLGUV.mjs} +1 -1
  20. package/dist/{chunk-BMFN37JH.mjs → chunk-7YAU5CY6.mjs} +1 -1
  21. package/dist/chunk-A56YQQHG.mjs +402 -0
  22. package/dist/chunk-AH52LG6N.mjs +315 -0
  23. package/dist/{chunk-SLWCCURD.mjs → chunk-CLIN5525.mjs} +8 -4
  24. package/dist/{chunk-3VQNJ235.mjs → chunk-CSDO6VBW.mjs} +7 -0
  25. package/dist/chunk-D4ILTPOG.mjs +293 -0
  26. package/dist/{chunk-HS7TFG7V.mjs → chunk-D6ID6M4V.mjs} +1 -1
  27. package/dist/chunk-DOH3EHX7.mjs +378 -0
  28. package/dist/{chunk-MJIEMGRD.mjs → chunk-EFRENWEJ.mjs} +9 -17
  29. package/dist/chunk-ERGGHC2V.mjs +185 -0
  30. package/dist/{chunk-OXQQNQZI.mjs → chunk-FEZKMUCF.mjs} +10 -1
  31. package/dist/{chunk-55CEW76V.mjs → chunk-FH6QVUVZ.mjs} +1 -1
  32. package/dist/chunk-FMAXJ2SI.mjs +71 -0
  33. package/dist/chunk-FZIXGLMV.mjs +173 -0
  34. package/dist/{chunk-DS2AMHN2.mjs → chunk-GYMYRIZP.mjs} +2 -2
  35. package/dist/{chunk-KQDD5MU3.mjs → chunk-H45TKD34.mjs} +5 -5
  36. package/dist/{chunk-BBJBJSXQ.mjs → chunk-J5UICVJS.mjs} +1 -1
  37. package/dist/{chunk-RL772EH7.mjs → chunk-JHJHG4GO.mjs} +4 -12
  38. package/dist/chunk-KMCGSZTX.mjs +177 -0
  39. package/dist/{chunk-FHNT55I5.mjs → chunk-KUDCQ4FI.mjs} +4 -4
  40. package/dist/chunk-LE6YFY6D.mjs +209 -0
  41. package/dist/{chunk-HUVTPUV2.mjs → chunk-LLVQKSU3.mjs} +23 -19
  42. package/dist/{chunk-KKHTJNMM.mjs → chunk-MARPPFOJ.mjs} +8 -4
  43. package/dist/{chunk-6AFMNC42.mjs → chunk-N2PT566P.mjs} +15 -11
  44. package/dist/chunk-NLCKVHWB.mjs +161 -0
  45. package/dist/{chunk-YN5SYTOO.mjs → chunk-NQPOYKAQ.mjs} +9 -5
  46. package/dist/{chunk-ZZV5JVNW.mjs → chunk-NSLMILBT.mjs} +3 -7
  47. package/dist/chunk-NXA3CZ7A.mjs +248 -0
  48. package/dist/chunk-OGOYQ7BG.mjs +150 -0
  49. package/dist/{chunk-3NQGYJEZ.mjs → chunk-P6AM5V7O.mjs} +10 -18
  50. package/dist/{chunk-CZ3BW5GL.mjs → chunk-P76HMUI6.mjs} +5 -11
  51. package/dist/chunk-PCPLO5HT.mjs +671 -0
  52. package/dist/chunk-PG6K5XEC.mjs +475 -0
  53. package/dist/chunk-PJHPSRYD.mjs +234 -0
  54. package/dist/{chunk-DDPA2XXS.mjs → chunk-PMB3A7V3.mjs} +2 -2
  55. package/dist/chunk-PR6V5XKM.mjs +209 -0
  56. package/dist/{chunk-46OFHMQA.mjs → chunk-Q76O3RIQ.mjs} +10 -6
  57. package/dist/chunk-QVKWW6KE.mjs +272 -0
  58. package/dist/chunk-RGU7HOEC.mjs +140 -0
  59. package/dist/{chunk-JF4PHPD5.mjs → chunk-RGVKLTLH.mjs} +4 -4
  60. package/dist/{chunk-VG6UF6UT.mjs → chunk-RP3SQYA3.mjs} +2 -2
  61. package/dist/chunk-RRBS6D63.mjs +163 -0
  62. package/dist/chunk-SMQ3DG25.mjs +285 -0
  63. package/dist/chunk-SPJ5KXW7.mjs +199 -0
  64. package/dist/chunk-SYOD63OZ.mjs +225 -0
  65. package/dist/chunk-UFYSFDER.mjs +42 -0
  66. package/dist/chunk-VACKZOMY.mjs +190 -0
  67. package/dist/chunk-VLQZANBF.mjs +42 -0
  68. package/dist/chunk-WA6O6EUR.mjs +1885 -0
  69. package/dist/{chunk-E3K6O4FZ.mjs → chunk-WAZD7NFU.mjs} +5 -2
  70. package/dist/chunk-WG6JGJXB.mjs +165 -0
  71. package/dist/{chunk-I64K754C.mjs → chunk-WNGWBVLV.mjs} +2 -2
  72. package/dist/{chunk-3U7SD3MS.mjs → chunk-WOEHFRGB.mjs} +3 -3
  73. package/dist/{chunk-DKZRJOMF.mjs → chunk-XIRTEFKH.mjs} +12 -12
  74. package/dist/chunk-Y6DWJSKZ.mjs +79 -0
  75. package/dist/chunk-YKPROFLB.mjs +161 -0
  76. package/dist/{chunk-K76E2TQU.mjs → chunk-ZRO5JO3H.mjs} +107 -67
  77. package/dist/{chunk-VYMHBV6D.mjs → chunk-ZU4NV6RG.mjs} +5 -3
  78. package/dist/components/ui/accordion.js +40 -4
  79. package/dist/components/ui/accordion.mjs +2 -2
  80. package/dist/components/ui/add-column-modal.js +789 -0
  81. package/dist/components/ui/add-column-modal.mjs +17 -0
  82. package/dist/components/ui/add-lead-modal.js +647 -0
  83. package/dist/components/ui/add-lead-modal.mjs +16 -0
  84. package/dist/components/ui/ai-assistant-drawer.js +686 -0
  85. package/dist/components/ui/ai-assistant-drawer.mjs +16 -0
  86. package/dist/components/ui/alert-dialog.js +37 -5
  87. package/dist/components/ui/alert-dialog.mjs +4 -4
  88. package/dist/components/ui/alert.js +37 -11
  89. package/dist/components/ui/alert.mjs +2 -2
  90. package/dist/components/ui/avatar.js +36 -8
  91. package/dist/components/ui/avatar.mjs +2 -2
  92. package/dist/components/ui/backoffice-alert-history-chart.js +624 -0
  93. package/dist/components/ui/backoffice-alert-history-chart.mjs +16 -0
  94. package/dist/components/ui/backoffice-contact-history-chart.js +687 -0
  95. package/dist/components/ui/backoffice-contact-history-chart.mjs +16 -0
  96. package/dist/components/ui/badge.js +37 -2
  97. package/dist/components/ui/badge.mjs +2 -2
  98. package/dist/components/ui/borrowing-capacity-line-chart.js +639 -0
  99. package/dist/components/ui/borrowing-capacity-line-chart.mjs +16 -0
  100. package/dist/components/ui/button.js +35 -3
  101. package/dist/components/ui/button.mjs +2 -2
  102. package/dist/components/ui/calendar.js +43 -19
  103. package/dist/components/ui/calendar.mjs +3 -3
  104. package/dist/components/ui/card.js +40 -4
  105. package/dist/components/ui/card.mjs +2 -2
  106. package/dist/components/ui/cash-balance-line-chart.js +627 -0
  107. package/dist/components/ui/cash-balance-line-chart.mjs +16 -0
  108. package/dist/components/ui/cashflow-bar-chart.js +650 -0
  109. package/dist/components/ui/cashflow-bar-chart.mjs +16 -0
  110. package/dist/components/ui/checkbox.js +36 -5
  111. package/dist/components/ui/checkbox.mjs +2 -3
  112. package/dist/components/ui/chip.js +37 -2
  113. package/dist/components/ui/chip.mjs +3 -3
  114. package/dist/components/ui/combobox.js +280 -0
  115. package/dist/components/ui/combobox.mjs +28 -0
  116. package/dist/components/ui/data-table.js +160 -88
  117. package/dist/components/ui/data-table.mjs +10 -11
  118. package/dist/components/ui/date-picker.js +44 -20
  119. package/dist/components/ui/date-picker.mjs +6 -7
  120. package/dist/components/ui/dialog.js +44 -12
  121. package/dist/components/ui/dialog.mjs +4 -4
  122. package/dist/components/ui/drawer.js +46 -10
  123. package/dist/components/ui/drawer.mjs +3 -3
  124. package/dist/components/ui/dropdown-menu.js +40 -16
  125. package/dist/components/ui/dropdown-menu.mjs +3 -3
  126. package/dist/components/ui/empty.js +41 -5
  127. package/dist/components/ui/empty.mjs +2 -2
  128. package/dist/components/ui/expense-bar-chart.js +642 -0
  129. package/dist/components/ui/expense-bar-chart.mjs +16 -0
  130. package/dist/components/ui/field.js +53 -21
  131. package/dist/components/ui/field.mjs +4 -4
  132. package/dist/components/ui/financial-cards.js +1002 -0
  133. package/dist/components/ui/financial-cards.mjs +24 -0
  134. package/dist/components/ui/financial-drawers.js +637 -0
  135. package/dist/components/ui/financial-drawers.mjs +17 -0
  136. package/dist/components/ui/financial-primitives.js +218 -0
  137. package/dist/components/ui/financial-primitives.mjs +22 -0
  138. package/dist/components/ui/financial-sections.js +1422 -0
  139. package/dist/components/ui/financial-sections.mjs +30 -0
  140. package/dist/components/ui/form-primitives.js +682 -0
  141. package/dist/components/ui/form-primitives.mjs +19 -0
  142. package/dist/components/ui/income-bar-chart.js +641 -0
  143. package/dist/components/ui/income-bar-chart.mjs +16 -0
  144. package/dist/components/ui/input-group.js +43 -7
  145. package/dist/components/ui/input-group.mjs +5 -5
  146. package/dist/components/ui/input-otp.js +39 -3
  147. package/dist/components/ui/input-otp.mjs +2 -2
  148. package/dist/components/ui/input.js +34 -2
  149. package/dist/components/ui/input.mjs +2 -2
  150. package/dist/components/ui/kanban-column.js +1143 -0
  151. package/dist/components/ui/kanban-column.mjs +20 -0
  152. package/dist/components/ui/label.js +35 -7
  153. package/dist/components/ui/label.mjs +2 -2
  154. package/dist/components/ui/opportunity-card.js +960 -0
  155. package/dist/components/ui/opportunity-card.mjs +20 -0
  156. package/dist/components/ui/opportunity-edit-modals.js +3360 -0
  157. package/dist/components/ui/opportunity-edit-modals.mjs +37 -0
  158. package/dist/components/ui/opportunity-summary-tab.js +4365 -0
  159. package/dist/components/ui/opportunity-summary-tab.mjs +34 -0
  160. package/dist/components/ui/pagination.js +35 -3
  161. package/dist/components/ui/pagination.mjs +3 -3
  162. package/dist/components/ui/pipeline-alerts.js +103 -0
  163. package/dist/components/ui/pipeline-alerts.mjs +8 -0
  164. package/dist/components/ui/pipeline-board.js +1408 -0
  165. package/dist/components/ui/pipeline-board.mjs +24 -0
  166. package/dist/components/ui/pipeline-chart.js +216 -0
  167. package/dist/components/ui/pipeline-chart.mjs +10 -0
  168. package/dist/components/ui/pipeline-dialogs.js +1183 -0
  169. package/dist/components/ui/pipeline-dialogs.mjs +23 -0
  170. package/dist/components/ui/pipeline-primitives.js +300 -0
  171. package/dist/components/ui/pipeline-primitives.mjs +11 -0
  172. package/dist/components/ui/popover.js +45 -4
  173. package/dist/components/ui/popover.mjs +3 -3
  174. package/dist/components/ui/progress.js +33 -1
  175. package/dist/components/ui/progress.mjs +2 -2
  176. package/dist/components/ui/property-cashflow-doughnut-chart.js +523 -0
  177. package/dist/components/ui/property-cashflow-doughnut-chart.mjs +16 -0
  178. package/dist/components/ui/property-debt-equity-doughnut-chart.js +521 -0
  179. package/dist/components/ui/property-debt-equity-doughnut-chart.mjs +16 -0
  180. package/dist/components/ui/property-mobile-estimate-line-chart.js +682 -0
  181. package/dist/components/ui/property-mobile-estimate-line-chart.mjs +16 -0
  182. package/dist/components/ui/radio-group.js +33 -1
  183. package/dist/components/ui/radio-group.mjs +2 -2
  184. package/dist/components/ui/select.js +66 -26
  185. package/dist/components/ui/select.mjs +3 -3
  186. package/dist/components/ui/separator.js +33 -1
  187. package/dist/components/ui/separator.mjs +2 -2
  188. package/dist/components/ui/sheet.js +37 -9
  189. package/dist/components/ui/sheet.mjs +3 -3
  190. package/dist/components/ui/skeleton.js +33 -1
  191. package/dist/components/ui/skeleton.mjs +2 -2
  192. package/dist/components/ui/slider.js +86 -102
  193. package/dist/components/ui/slider.mjs +2 -2
  194. package/dist/components/ui/spinner.js +33 -1
  195. package/dist/components/ui/spinner.mjs +2 -2
  196. package/dist/components/ui/stage-timeline.js +579 -0
  197. package/dist/components/ui/stage-timeline.mjs +15 -0
  198. package/dist/components/ui/switch.js +37 -4
  199. package/dist/components/ui/switch.mjs +2 -3
  200. package/dist/components/ui/table.js +37 -5
  201. package/dist/components/ui/table.mjs +2 -2
  202. package/dist/components/ui/tabs.js +36 -12
  203. package/dist/components/ui/tabs.mjs +2 -2
  204. package/dist/components/ui/textarea.js +34 -2
  205. package/dist/components/ui/textarea.mjs +2 -2
  206. package/dist/components/ui/toggle-group.js +35 -4
  207. package/dist/components/ui/toggle-group.mjs +3 -4
  208. package/dist/components/ui/toggle.js +35 -4
  209. package/dist/components/ui/toggle.mjs +2 -3
  210. package/dist/components/ui/tooltip.js +51 -22
  211. package/dist/components/ui/tooltip.mjs +3 -3
  212. package/dist/components/ui/transactions-expense-categories-doughnut-chart.js +528 -0
  213. package/dist/components/ui/transactions-expense-categories-doughnut-chart.mjs +16 -0
  214. package/dist/components/ui/transactions-income-expense-bar-chart.js +516 -0
  215. package/dist/components/ui/transactions-income-expense-bar-chart.mjs +16 -0
  216. package/dist/components/ui/transactions-liabilities-breakdown-doughnut-chart.js +528 -0
  217. package/dist/components/ui/transactions-liabilities-breakdown-doughnut-chart.mjs +16 -0
  218. package/dist/index.js +11613 -2868
  219. package/dist/index.mjs +377 -164
  220. package/dist/lib/theme-provider.js +10 -1
  221. package/dist/lib/theme-provider.mjs +1 -1
  222. package/dist/lib/typography.js +8 -0
  223. package/dist/lib/typography.mjs +3 -1
  224. package/dist/lib/utils.js +33 -1
  225. package/dist/lib/utils.mjs +1 -1
  226. package/dist/styles.css +1 -1
  227. package/package.json +169 -6
  228. package/src/components/index.tsx +323 -13
  229. package/src/components/ui/accordion.tsx +6 -3
  230. package/src/components/ui/add-column-modal.tsx +339 -0
  231. package/src/components/ui/add-lead-modal.tsx +290 -0
  232. package/src/components/ui/ai-assistant-drawer.tsx +408 -0
  233. package/src/components/ui/alert-dialog.tsx +80 -54
  234. package/src/components/ui/alert.tsx +28 -28
  235. package/src/components/ui/avatar.tsx +30 -29
  236. package/src/components/ui/backoffice-alert-history-chart.tsx +260 -0
  237. package/src/components/ui/backoffice-contact-history-chart.tsx +325 -0
  238. package/src/components/ui/badge.tsx +17 -15
  239. package/src/components/ui/borrowing-capacity-line-chart.tsx +357 -0
  240. package/src/components/ui/button.tsx +30 -27
  241. package/src/components/ui/calendar.tsx +53 -67
  242. package/src/components/ui/card.tsx +27 -24
  243. package/src/components/ui/cash-balance-line-chart.tsx +302 -0
  244. package/src/components/ui/cashflow-bar-chart.tsx +363 -0
  245. package/src/components/ui/chart-shared.tsx +261 -0
  246. package/src/components/ui/checkbox.tsx +30 -26
  247. package/src/components/ui/combobox.tsx +223 -0
  248. package/src/components/ui/data-table.tsx +160 -99
  249. package/src/components/ui/date-picker.tsx +0 -2
  250. package/src/components/ui/dialog.tsx +70 -60
  251. package/src/components/ui/drawer.tsx +57 -48
  252. package/src/components/ui/dropdown-menu.tsx +90 -82
  253. package/src/components/ui/empty.tsx +31 -27
  254. package/src/components/ui/expense-bar-chart.tsx +296 -0
  255. package/src/components/ui/field.tsx +70 -62
  256. package/src/components/ui/financial-cards.tsx +830 -0
  257. package/src/components/ui/financial-drawers.tsx +339 -0
  258. package/src/components/ui/financial-primitives.tsx +331 -0
  259. package/src/components/ui/financial-sections.tsx +672 -0
  260. package/src/components/ui/form-primitives.tsx +536 -0
  261. package/src/components/ui/income-bar-chart.tsx +297 -0
  262. package/src/components/ui/input-group.tsx +41 -34
  263. package/src/components/ui/input-otp.tsx +29 -24
  264. package/src/components/ui/input.tsx +8 -8
  265. package/src/components/ui/kanban-column.tsx +333 -0
  266. package/src/components/ui/label.tsx +9 -12
  267. package/src/components/ui/opportunity-card.tsx +616 -0
  268. package/src/components/ui/opportunity-edit-modals.tsx +2528 -0
  269. package/src/components/ui/opportunity-summary-tab.tsx +579 -0
  270. package/src/components/ui/pipeline-alerts.tsx +74 -0
  271. package/src/components/ui/pipeline-board.tsx +268 -0
  272. package/src/components/ui/pipeline-chart.tsx +173 -0
  273. package/src/components/ui/pipeline-dialogs.tsx +303 -0
  274. package/src/components/ui/pipeline-primitives.tsx +108 -0
  275. package/src/components/ui/popover.tsx +41 -36
  276. package/src/components/ui/property-cashflow-doughnut-chart.tsx +188 -0
  277. package/src/components/ui/property-debt-equity-doughnut-chart.tsx +185 -0
  278. package/src/components/ui/property-mobile-estimate-line-chart.tsx +393 -0
  279. package/src/components/ui/select.tsx +65 -52
  280. package/src/components/ui/sheet.tsx +55 -52
  281. package/src/components/ui/slider.tsx +54 -77
  282. package/src/components/ui/stage-timeline.tsx +205 -0
  283. package/src/components/ui/switch.tsx +42 -29
  284. package/src/components/ui/table.tsx +28 -28
  285. package/src/components/ui/tabs.tsx +22 -28
  286. package/src/components/ui/textarea.tsx +8 -8
  287. package/src/components/ui/toggle-group.tsx +0 -2
  288. package/src/components/ui/toggle.tsx +13 -15
  289. package/src/components/ui/tooltip.tsx +30 -28
  290. package/src/components/ui/transactions-expense-categories-doughnut-chart.tsx +191 -0
  291. package/src/components/ui/transactions-income-expense-bar-chart.tsx +205 -0
  292. package/src/components/ui/transactions-liabilities-breakdown-doughnut-chart.tsx +191 -0
  293. package/src/lib/theme-provider.tsx +10 -0
  294. package/src/lib/typography.ts +9 -0
  295. package/src/lib/utils.ts +41 -3
  296. package/src/styles/globals.css +371 -124
  297. package/src/styles/styles-css.ts +1 -1
  298. package/tsup.config.ts +32 -0
  299. package/dist/chunk-K74JRTJR.mjs +0 -105
  300. package/dist/chunk-V7CNWJT3.mjs +0 -10
@@ -0,0 +1,302 @@
1
+ import React, { useMemo } from "react";
2
+ import {
3
+ Chart as ChartJS,
4
+ CategoryScale,
5
+ LinearScale,
6
+ LineElement,
7
+ PointElement,
8
+ Tooltip,
9
+ type ChartOptions,
10
+ type ChartData,
11
+ } from "chart.js";
12
+ import { Chart } from "react-chartjs-2";
13
+ import { useThemeVars } from "@/lib/theme-provider";
14
+ import { Card, CardContent, CardHeader, CardTitle } from "./card";
15
+ import { Empty, EmptyDescription } from "./empty";
16
+ import { Spinner } from "./spinner";
17
+ import { cn } from "@/lib/utils";
18
+ import {
19
+ FALLBACK_TICK,
20
+ FALLBACK_PRIMARY,
21
+ FALLBACK_BG,
22
+ ChartLegendItem,
23
+ } from "./chart-shared";
24
+
25
+ ChartJS.register(
26
+ CategoryScale,
27
+ LinearScale,
28
+ LineElement,
29
+ PointElement,
30
+ Tooltip,
31
+ );
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // Helpers
35
+ // ---------------------------------------------------------------------------
36
+
37
+ /** Abbreviate a dollar value: $1.2K, $4.5M, $1.1B */
38
+ function formatAbbrev(value: number): string {
39
+ const abs = Math.abs(value);
40
+ const sign = value < 0 ? "-" : "";
41
+ if (abs >= 1_000_000_000)
42
+ return `${sign}$${(abs / 1_000_000_000).toFixed(1)}B`;
43
+ if (abs >= 1_000_000) return `${sign}$${(abs / 1_000_000).toFixed(1)}M`;
44
+ if (abs >= 1_000) return `${sign}$${(abs / 1_000).toFixed(1)}K`;
45
+ return `${sign}$${abs.toFixed(0)}`;
46
+ }
47
+
48
+ /** Format a balance value for prominent display: $12,345.67 */
49
+ function formatBalanceFull(value: number): string {
50
+ const abs = Math.abs(value);
51
+ const sign = value < 0 ? "-" : "";
52
+ return `${sign}$${abs.toLocaleString(undefined, {
53
+ minimumFractionDigits: 2,
54
+ maximumFractionDigits: 2,
55
+ })}`;
56
+ }
57
+
58
+ /** Format ISO date string to "MMM dd" label e.g. "Jan 15" */
59
+ function formatDateLabel(iso: string): string {
60
+ const d = new Date(iso);
61
+ return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
62
+ }
63
+
64
+ /** Format ISO date string for tooltip e.g. "Jan 15, 2024" */
65
+ function formatDateTooltip(iso: string): string {
66
+ const d = new Date(iso);
67
+ return d.toLocaleDateString("en-US", {
68
+ month: "short",
69
+ day: "numeric",
70
+ year: "numeric",
71
+ });
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Types
76
+ // ---------------------------------------------------------------------------
77
+
78
+ export interface CashBalanceDataPoint {
79
+ /** ISO date string e.g. "2024-01-15" */
80
+ x: string;
81
+ y: number;
82
+ }
83
+
84
+ export interface CashBalanceLineChartProps {
85
+ chartData?: CashBalanceDataPoint[] | null;
86
+ title?: string;
87
+ /** Chart canvas height in pixels */
88
+ height?: number;
89
+ /** Width of the card */
90
+ width?: number | string;
91
+ className?: string;
92
+ /** Show skeleton loading state instead of the chart */
93
+ isLoading?: boolean;
94
+ /** Show or hide X axis labels */
95
+ showXAxis?: boolean;
96
+ /** Show or hide Y axis labels */
97
+ showYAxis?: boolean;
98
+ /** Show the latest balance value prominently below the title */
99
+ showBalanceValue?: boolean;
100
+ /** Show or hide the chart legend */
101
+ showLegend?: boolean;
102
+ /** Legend placement relative to the chart */
103
+ legendPosition?: "top" | "bottom";
104
+ }
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Component
108
+ // ---------------------------------------------------------------------------
109
+
110
+ export function CashBalanceLineChart({
111
+ chartData,
112
+ title = "Cash Balance",
113
+ height = 200,
114
+ width = "100%",
115
+ className,
116
+ isLoading = false,
117
+ showXAxis = true,
118
+ showYAxis = true,
119
+ showBalanceValue = false,
120
+ showLegend = false,
121
+ legendPosition = "bottom",
122
+ }: CashBalanceLineChartProps) {
123
+ const themeVars = useThemeVars();
124
+ const brandPrimary =
125
+ (themeVars["--theme-primary"] as string | undefined) || FALLBACK_PRIMARY;
126
+ const fontFamily =
127
+ (themeVars["--font-sans"] as string | undefined) || "Figtree, sans-serif";
128
+
129
+ const hasData = Array.isArray(chartData) && chartData.length > 0;
130
+
131
+ // Indices to show on x-axis (max ~6 ticks)
132
+ const tickIndices = useMemo<Set<number>>(() => {
133
+ if (!hasData) return new Set();
134
+ const count = chartData!.length;
135
+ const step = Math.max(1, Math.floor(count / 6));
136
+ const indices = new Set<number>();
137
+ for (let i = 0; i < count; i += step) indices.add(i);
138
+ indices.add(count - 1);
139
+ return indices;
140
+ }, [hasData, chartData]);
141
+
142
+ const data = useMemo<ChartData<"line">>(() => {
143
+ if (!hasData) return { labels: [], datasets: [] };
144
+ return {
145
+ labels: chartData!.map((p) => p.x), // raw ISO — used for tooltip + tick lookup
146
+ datasets: [
147
+ {
148
+ label: title,
149
+ data: chartData!.map((p) => p.y),
150
+ fill: false,
151
+ borderColor: brandPrimary,
152
+ backgroundColor: "transparent",
153
+ borderWidth: 2.5,
154
+ tension: 0.4,
155
+ pointRadius: 0,
156
+ pointHoverRadius: 6,
157
+ pointHoverBackgroundColor: FALLBACK_BG,
158
+ pointHoverBorderColor: brandPrimary,
159
+ pointHoverBorderWidth: 3,
160
+ pointHitRadius: 10,
161
+ },
162
+ ],
163
+ };
164
+ }, [hasData, chartData, brandPrimary, title]);
165
+
166
+ const options = useMemo<ChartOptions<"line">>(
167
+ () => ({
168
+ responsive: true,
169
+ maintainAspectRatio: false,
170
+ animation: { duration: 1200, easing: "easeOutQuart" },
171
+ plugins: {
172
+ legend: { display: false },
173
+ tooltip: {
174
+ enabled: true,
175
+ mode: "index",
176
+ intersect: false,
177
+ displayColors: false,
178
+ padding: 12,
179
+ cornerRadius: 0,
180
+ titleFont: { size: 11, weight: "600", family: fontFamily },
181
+ bodyFont: { size: 13, weight: "700", family: fontFamily },
182
+ callbacks: {
183
+ title: (items) => {
184
+ const iso = items[0]?.label;
185
+ return iso ? formatDateTooltip(iso) : "";
186
+ },
187
+ label: (ctx) => {
188
+ const val = ctx.parsed.y;
189
+ const formatted = Math.abs(val).toLocaleString(undefined, {
190
+ minimumFractionDigits: 2,
191
+ maximumFractionDigits: 2,
192
+ });
193
+ return `$ ${formatted}`;
194
+ },
195
+ },
196
+ },
197
+ },
198
+ interaction: { mode: "index", intersect: false },
199
+ scales: {
200
+ x: {
201
+ type: "category",
202
+ display: showXAxis,
203
+ grid: { display: false },
204
+ border: { display: false },
205
+ ticks: {
206
+ autoSkip: false,
207
+ maxRotation: 0,
208
+ minRotation: 0,
209
+ color: FALLBACK_TICK,
210
+ font: { size: 10, family: fontFamily },
211
+ callback: function (_, index) {
212
+ if (!tickIndices.has(index) || !chartData) return "";
213
+ return formatDateLabel(chartData[index].x);
214
+ },
215
+ },
216
+ },
217
+ y: {
218
+ display: showYAxis,
219
+ position: "left",
220
+ grid: { display: false },
221
+ border: { display: false },
222
+ ticks: {
223
+ beginAtZero: false,
224
+ maxTicksLimit: 5,
225
+ padding: 8,
226
+ color: FALLBACK_TICK,
227
+ font: { size: 10, family: fontFamily },
228
+ callback: (v) => formatAbbrev(Number(v)),
229
+ },
230
+ },
231
+ },
232
+ }),
233
+ [tickIndices, chartData, showXAxis, showYAxis, fontFamily],
234
+ );
235
+
236
+ const latestValue = hasData ? chartData![chartData!.length - 1].y : null;
237
+
238
+ return (
239
+ <Card
240
+ className={cn("w-full py-4 sm:py-6 gap-2", className)}
241
+ style={{ maxWidth: width, fontFamily }}
242
+ >
243
+ <CardHeader className="px-3 sm:px-6">
244
+ <div className="flex flex-col gap-0.5">
245
+ <CardTitle className="text-sm sm:text-base uppercase tracking-wider">
246
+ {title}
247
+ </CardTitle>
248
+ {showBalanceValue && latestValue !== null && (
249
+ <p className="text-2xl font-bold tabular-nums leading-tight">
250
+ {formatBalanceFull(latestValue)}
251
+ </p>
252
+ )}
253
+ </div>
254
+ </CardHeader>
255
+
256
+ <CardContent className="px-3 sm:px-6">
257
+ {isLoading ? (
258
+ <div
259
+ className="flex items-center justify-center text-muted-foreground"
260
+ style={{ height, width: "100%" }}
261
+ >
262
+ <Spinner size="lg" />
263
+ </div>
264
+ ) : !hasData ? (
265
+ <Empty className="flex-none p-4" style={{ height }}>
266
+ <EmptyDescription>No data available</EmptyDescription>
267
+ </Empty>
268
+ ) : (
269
+ <div className="flex flex-col gap-2">
270
+ {showLegend && legendPosition === "top" && (
271
+ <div className="flex flex-wrap items-center gap-x-4 gap-y-1.5">
272
+ <ChartLegendItem
273
+ label={title}
274
+ color={brandPrimary}
275
+ lineStyle="solid"
276
+ />
277
+ </div>
278
+ )}
279
+ <div style={{ height, width: "100%", position: "relative" }}>
280
+ <Chart
281
+ key={brandPrimary}
282
+ type="line"
283
+ data={data}
284
+ options={options}
285
+ aria-label={title}
286
+ />
287
+ </div>
288
+ {showLegend && legendPosition === "bottom" && (
289
+ <div className="flex flex-wrap items-center gap-x-4 gap-y-1.5">
290
+ <ChartLegendItem
291
+ label={title}
292
+ color={brandPrimary}
293
+ lineStyle="solid"
294
+ />
295
+ </div>
296
+ )}
297
+ </div>
298
+ )}
299
+ </CardContent>
300
+ </Card>
301
+ );
302
+ }
@@ -0,0 +1,363 @@
1
+ import React, { useMemo, useState } from "react";
2
+ import {
3
+ Chart as ChartJS,
4
+ CategoryScale,
5
+ LinearScale,
6
+ BarElement,
7
+ Tooltip,
8
+ Legend,
9
+ type ChartOptions,
10
+ type ChartData,
11
+ } from "chart.js";
12
+ import { Chart } from "react-chartjs-2";
13
+ import { useThemeVars } from "@/lib/theme-provider";
14
+ import { Card, CardContent, CardHeader, CardTitle, CardAction } from "./card";
15
+ import { Empty, EmptyDescription } from "./empty";
16
+ import { Skeleton } from "./skeleton";
17
+ import { cn } from "@/lib/utils";
18
+ import {
19
+ hexToRgba,
20
+ FALLBACK_TICK,
21
+ FALLBACK_PRIMARY,
22
+ FALLBACK_SECONDARY,
23
+ formatTooltipDate,
24
+ ChartPeriodButton,
25
+ } from "./chart-shared";
26
+
27
+ ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Types
31
+ // ---------------------------------------------------------------------------
32
+
33
+ export interface CashflowDataPoint {
34
+ /** ISO date string e.g. "2024-01-01" */
35
+ date: string;
36
+ income: number;
37
+ expenses: number;
38
+ /** Positive value — ignored when overspending > 0 */
39
+ surplus: number;
40
+ /** Positive value — ignored when surplus > 0 */
41
+ overspending: number;
42
+ }
43
+
44
+ export interface CashflowChartData {
45
+ months: string[];
46
+ data: CashflowDataPoint[];
47
+ }
48
+
49
+ export type CashflowPeriod = 3 | 6 | 12;
50
+
51
+ export interface CashflowBarChartProps {
52
+ /** Full dataset — sliced to the selected period */
53
+ cashflowData: CashflowChartData | null;
54
+ title?: string;
55
+ /** Show or hide the chart legend */
56
+ showLegend?: boolean;
57
+ /** Show or hide X axis labels */
58
+ showXAxis?: boolean;
59
+ /** Show or hide Y axis labels */
60
+ showYAxis?: boolean;
61
+ /** Legend placement relative to chart */
62
+ legendPosition?: "top" | "bottom";
63
+ /** Default period selector value */
64
+ defaultPeriod?: CashflowPeriod;
65
+ /** Show or hide the period selector buttons (3M / 6M / 12M) */
66
+ showPeriodSelector?: boolean;
67
+ /** Chart canvas height in pixels */
68
+ height?: number;
69
+ /** Width of the card in pixels */
70
+ width?: number | string;
71
+ className?: string;
72
+ /** Show skeleton loading state instead of the chart */
73
+ isLoading?: boolean;
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // HTML legend (outside canvas — full spacing control)
78
+ // ---------------------------------------------------------------------------
79
+
80
+ interface LegendItemProps {
81
+ label: string;
82
+ fillColor: string;
83
+ strokeColor: string;
84
+ strokeWidth?: number;
85
+ }
86
+
87
+ function LegendItem({
88
+ label,
89
+ fillColor,
90
+ strokeColor,
91
+ strokeWidth = 1.5,
92
+ }: LegendItemProps) {
93
+ return (
94
+ <div className="flex items-center gap-1.5">
95
+ <div
96
+ style={{
97
+ width: 10,
98
+ height: 10,
99
+ backgroundColor: fillColor,
100
+ border:
101
+ strokeWidth > 0 ? `${strokeWidth}px solid ${strokeColor}` : "none",
102
+ flexShrink: 0,
103
+ }}
104
+ />
105
+ <span className="text-[11px] text-muted-foreground leading-none">
106
+ {label}
107
+ </span>
108
+ </div>
109
+ );
110
+ }
111
+
112
+ function ChartLegend({
113
+ primary,
114
+ secondary,
115
+ }: {
116
+ primary: string;
117
+ secondary: string;
118
+ }) {
119
+ return (
120
+ <div className="flex flex-wrap gap-x-3 gap-y-1.5 pb-2">
121
+ <LegendItem
122
+ label="Income"
123
+ fillColor={hexToRgba(primary, 0.2)}
124
+ strokeColor={primary}
125
+ />
126
+ <LegendItem
127
+ label="Expenses and Liabilities"
128
+ fillColor={hexToRgba(secondary, 0.2)}
129
+ strokeColor={secondary}
130
+ />
131
+ <LegendItem
132
+ label="Surplus Income"
133
+ fillColor={primary}
134
+ strokeColor={primary}
135
+ strokeWidth={0}
136
+ />
137
+ <LegendItem
138
+ label="Over Spending"
139
+ fillColor={secondary}
140
+ strokeColor={secondary}
141
+ strokeWidth={0}
142
+ />
143
+ </div>
144
+ );
145
+ }
146
+
147
+ // ---------------------------------------------------------------------------
148
+ // Constants
149
+ // ---------------------------------------------------------------------------
150
+
151
+ const PERIODS: CashflowPeriod[] = [3, 6, 12];
152
+
153
+ // ---------------------------------------------------------------------------
154
+ // Component
155
+ // ---------------------------------------------------------------------------
156
+
157
+ export function CashflowBarChart({
158
+ cashflowData,
159
+ title = "Cashflow",
160
+ showLegend = true,
161
+ showXAxis = true,
162
+ showYAxis = true,
163
+ legendPosition = "top",
164
+ defaultPeriod = 6,
165
+ showPeriodSelector = true,
166
+ height = 280,
167
+ width = "100%",
168
+ className,
169
+ isLoading = false,
170
+ }: CashflowBarChartProps) {
171
+ const [period, setPeriod] = useState<CashflowPeriod>(defaultPeriod);
172
+
173
+ // Read theme colors from ThemeProvider context.
174
+ // Falls back to WealthX defaults when no ThemeProvider is present.
175
+ const themeVars = useThemeVars();
176
+ const brandPrimary: string =
177
+ (themeVars["--theme-primary"] as string | undefined) || FALLBACK_PRIMARY;
178
+ const brandSecondary: string =
179
+ (themeVars["--theme-secondary"] as string | undefined) ||
180
+ FALLBACK_SECONDARY;
181
+ const fontFamily: string =
182
+ (themeVars["--font-sans"] as string | undefined) || "Figtree, sans-serif";
183
+
184
+ const sliced = useMemo<CashflowChartData | null>(() => {
185
+ if (!cashflowData?.data?.length) return null;
186
+ const count = Math.min(period, cashflowData.data.length);
187
+ const start = cashflowData.data.length - count;
188
+ return {
189
+ months: cashflowData.months.slice(start),
190
+ data: cashflowData.data.slice(start),
191
+ };
192
+ }, [cashflowData, period]);
193
+
194
+ const chartData = useMemo<ChartData<"bar">>(() => {
195
+ if (!sliced) return { labels: [], datasets: [] };
196
+
197
+ return {
198
+ labels: sliced.months,
199
+ datasets: [
200
+ {
201
+ label: "Income",
202
+ data: sliced.data.map((d) => d.income),
203
+ backgroundColor: hexToRgba(brandPrimary, 0.2),
204
+ hoverBackgroundColor: hexToRgba(brandPrimary, 0.35),
205
+ borderColor: brandPrimary,
206
+ borderWidth: 1.5,
207
+ borderRadius: 0,
208
+ borderSkipped: false,
209
+ barPercentage: 0.75,
210
+ categoryPercentage: 0.7,
211
+ },
212
+ {
213
+ label: "Expenses and Liabilities",
214
+ data: sliced.data.map((d) => d.expenses),
215
+ backgroundColor: hexToRgba(brandSecondary, 0.2),
216
+ hoverBackgroundColor: hexToRgba(brandSecondary, 0.35),
217
+ borderColor: brandSecondary,
218
+ borderWidth: 1.5,
219
+ borderRadius: 0,
220
+ borderSkipped: false,
221
+ barPercentage: 0.75,
222
+ categoryPercentage: 0.7,
223
+ },
224
+ {
225
+ label: "_thirdBar",
226
+ data: sliced.data.map((d) =>
227
+ d.overspending > 0 ? d.overspending : d.surplus,
228
+ ),
229
+ backgroundColor: sliced.data.map((d) =>
230
+ d.overspending > 0 ? brandSecondary : brandPrimary,
231
+ ),
232
+ hoverBackgroundColor: sliced.data.map((d) =>
233
+ d.overspending > 0
234
+ ? hexToRgba(brandSecondary, 0.8)
235
+ : hexToRgba(brandPrimary, 0.8),
236
+ ),
237
+ borderWidth: 0,
238
+ borderRadius: 0,
239
+ borderSkipped: false,
240
+ barPercentage: 0.75,
241
+ categoryPercentage: 0.7,
242
+ },
243
+ ],
244
+ };
245
+ }, [sliced, brandPrimary, brandSecondary]);
246
+
247
+ const options = useMemo<ChartOptions<"bar">>(
248
+ () => ({
249
+ responsive: true,
250
+ maintainAspectRatio: false,
251
+ animation: { duration: 800, easing: "easeOutQuart" },
252
+ layout: { padding: 0 },
253
+ plugins: {
254
+ legend: { display: false },
255
+ tooltip: {
256
+ mode: "index",
257
+ intersect: false,
258
+ padding: 12,
259
+ cornerRadius: 0,
260
+ titleFont: { size: 11, weight: 600 },
261
+ bodyFont: { size: 12, weight: 500 },
262
+ callbacks: {
263
+ title: (tooltipItems) => {
264
+ const idx = tooltipItems[0]?.dataIndex;
265
+ if (idx != null && sliced?.data[idx]?.date) {
266
+ return formatTooltipDate(sliced.data[idx].date, "monthly");
267
+ }
268
+ return tooltipItems[0]?.label ?? "";
269
+ },
270
+ label: (ctx) => {
271
+ const val = ctx.raw as number;
272
+ if (val === 0) return;
273
+ if (ctx.datasetIndex === 2) {
274
+ const d = sliced?.data[ctx.dataIndex];
275
+ if (!d) return;
276
+ const lbl =
277
+ d.overspending > 0 ? "Over Spending" : "Surplus Income";
278
+ return ` ${lbl}: $${val.toLocaleString()}`;
279
+ }
280
+ return ` ${ctx.dataset.label}: $${val.toLocaleString()}`;
281
+ },
282
+ },
283
+ },
284
+ },
285
+ scales: {
286
+ x: {
287
+ display: showXAxis,
288
+ grid: { display: false },
289
+ border: { display: false },
290
+ ticks: { font: { size: 10 }, color: FALLBACK_TICK },
291
+ },
292
+ y: {
293
+ display: showYAxis,
294
+ grid: { display: false },
295
+ border: { display: false },
296
+ ticks: {
297
+ font: { size: 10 },
298
+ color: FALLBACK_TICK,
299
+ maxTicksLimit: 5,
300
+ padding: 8,
301
+ callback: (v) => `$${Number(v).toLocaleString()}`,
302
+ },
303
+ },
304
+ },
305
+ }),
306
+ [showXAxis, showYAxis, sliced],
307
+ );
308
+
309
+ return (
310
+ <Card
311
+ className={cn("w-full py-4 sm:py-6 gap-2", className)}
312
+ style={{ maxWidth: width, fontFamily }}
313
+ >
314
+ <CardHeader className="px-3 sm:px-6">
315
+ <CardTitle className="text-sm sm:text-base uppercase tracking-wider">
316
+ {title}
317
+ </CardTitle>
318
+ {showPeriodSelector && (
319
+ <CardAction>
320
+ <div className="flex gap-0.5 sm:gap-1">
321
+ {PERIODS.map((p) => (
322
+ <ChartPeriodButton
323
+ key={p}
324
+ period={p}
325
+ active={period === p}
326
+ onClick={() => setPeriod(p)}
327
+ />
328
+ ))}
329
+ </div>
330
+ </CardAction>
331
+ )}
332
+ </CardHeader>
333
+
334
+ <CardContent className="px-3 sm:px-6">
335
+ {isLoading ? (
336
+ <Skeleton style={{ height, width: "100%" }} />
337
+ ) : !sliced ? (
338
+ <Empty className="flex-none p-4" style={{ height }}>
339
+ <EmptyDescription>No data available</EmptyDescription>
340
+ </Empty>
341
+ ) : (
342
+ <div className="flex flex-col gap-2">
343
+ {showLegend && legendPosition === "top" && (
344
+ <ChartLegend primary={brandPrimary} secondary={brandSecondary} />
345
+ )}
346
+ <div style={{ height, width: "100%", position: "relative" }}>
347
+ <Chart
348
+ key={`${brandPrimary}__${brandSecondary}`}
349
+ type="bar"
350
+ data={chartData}
351
+ options={options}
352
+ aria-label={title}
353
+ />
354
+ </div>
355
+ {showLegend && legendPosition === "bottom" && (
356
+ <ChartLegend primary={brandPrimary} secondary={brandSecondary} />
357
+ )}
358
+ </div>
359
+ )}
360
+ </CardContent>
361
+ </Card>
362
+ );
363
+ }