@umituz/web-dashboard 8.11.0 → 9.0.1

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 (46) hide show
  1. package/README.md +54 -7
  2. package/package.json +6 -2
  3. package/src/config/DashboardConfig.ts +4 -8
  4. package/src/domains/analytics/components/AnalyticsLayout.test.tsx +85 -0
  5. package/src/domains/analytics/components/AnalyticsLayout.tsx +103 -105
  6. package/src/domains/analytics/components/index.ts +0 -3
  7. package/src/domains/analytics/hooks/index.ts +1 -1
  8. package/src/domains/analytics/hooks/useAnalytics.test.tsx +125 -0
  9. package/src/domains/analytics/hooks/useAnalytics.ts +37 -56
  10. package/src/domains/analytics/index.ts +9 -26
  11. package/src/domains/analytics/services/index.ts +0 -1
  12. package/src/domains/analytics/types/analytics.ts +32 -149
  13. package/src/domains/analytics/types/index.ts +3 -15
  14. package/src/domains/analytics/utils/analytics.test.ts +82 -13
  15. package/src/domains/analytics/utils/analytics.ts +54 -77
  16. package/src/domains/analytics/utils/index.ts +5 -8
  17. package/src/domains/charts/charts.css +455 -0
  18. package/src/domains/charts/components/ActivityHeatmap.test.tsx +48 -0
  19. package/src/domains/charts/components/ActivityHeatmap.tsx +58 -0
  20. package/src/domains/charts/components/BarChart.test.tsx +91 -0
  21. package/src/domains/charts/components/BarChart.tsx +143 -0
  22. package/src/domains/charts/components/ChartCard.tsx +39 -0
  23. package/src/domains/charts/components/ChartPrimitives.test.tsx +90 -0
  24. package/src/domains/charts/components/ChartTip.tsx +18 -0
  25. package/src/domains/charts/components/Donut.test.tsx +51 -0
  26. package/src/domains/charts/components/Donut.tsx +97 -0
  27. package/src/domains/charts/components/HBars.tsx +31 -0
  28. package/src/domains/charts/components/Legend.tsx +21 -0
  29. package/src/domains/charts/components/LineChart.test.tsx +81 -0
  30. package/src/domains/charts/components/LineChart.tsx +244 -0
  31. package/src/domains/charts/components/Sparkline.tsx +35 -0
  32. package/src/domains/charts/components/index.ts +16 -0
  33. package/src/domains/charts/index.ts +16 -2
  34. package/src/domains/charts/ssr.test.tsx +35 -0
  35. package/src/domains/charts/types/index.ts +8 -0
  36. package/src/domains/charts/utils.ts +15 -0
  37. package/src/index.ts +6 -23
  38. package/src/styles/chrome.css +10 -490
  39. package/src/styles/dashboard.contract.test.ts +20 -5
  40. package/src/styles/dashboard.css +1 -0
  41. package/src/domains/analytics/components/AnalyticsCard.tsx +0 -87
  42. package/src/domains/analytics/components/AnalyticsChart.tsx +0 -387
  43. package/src/domains/analytics/components/MetricCard.tsx +0 -42
  44. package/src/domains/analytics/services/AnalyticsEngineService.ts +0 -300
  45. package/src/domains/charts/components.test.tsx +0 -141
  46. package/src/domains/charts/components.tsx +0 -683
@@ -1098,16 +1098,17 @@
1098
1098
  width: 16px;
1099
1099
  height: 16px;
1100
1100
  }
1101
- .udb-analytics__loading {
1102
- display: flex;
1103
- align-items: center;
1104
- justify-content: center;
1105
- padding: var(--udb-space-8) 0;
1101
+ .udb-analytics__kpi-skeleton {
1102
+ height: 108px;
1103
+ border-radius: var(--radius-lg);
1106
1104
  }
1107
- .udb-analytics__loading-spinner {
1108
- width: 48px;
1109
- height: 48px;
1110
- color: var(--color-muted-foreground);
1105
+ .udb-analytics__chart-skeleton {
1106
+ height: 280px;
1107
+ border-radius: var(--radius-lg);
1108
+ }
1109
+ .udb-analytics__error {
1110
+ border: 1px dashed var(--color-border);
1111
+ border-radius: var(--radius-lg);
1111
1112
  }
1112
1113
  .udb-analytics__metrics {
1113
1114
  display: grid;
@@ -1158,99 +1159,6 @@
1158
1159
  outline: none;
1159
1160
  cursor: pointer;
1160
1161
  }
1161
- .udb-analytics-card__status {
1162
- display: flex;
1163
- align-items: center;
1164
- justify-content: center;
1165
- gap: var(--udb-space-3);
1166
- min-height: 192px;
1167
- }
1168
- .udb-analytics-card__status--error {
1169
- color: var(--color-destructive);
1170
- }
1171
- .udb-analytics-card__spinner {
1172
- width: 32px;
1173
- height: 32px;
1174
- color: var(--color-muted-foreground);
1175
- }
1176
- .udb-analytics-card__error-icon {
1177
- width: 20px;
1178
- height: 20px;
1179
- flex-shrink: 0;
1180
- }
1181
- .udb-analytics-card__error-text {
1182
- margin: 0;
1183
- font-size: var(--udb-font-size-md);
1184
- }
1185
- .udb-analytics-card__header {
1186
- margin-bottom: var(--udb-space-6);
1187
- }
1188
- .udb-analytics-card__title {
1189
- margin: 0;
1190
- font-size: var(--udb-font-size-lg);
1191
- font-weight: 600;
1192
- color: var(--color-foreground);
1193
- }
1194
- .udb-analytics-card__description {
1195
- margin: var(--udb-space-1) 0 0;
1196
- font-size: var(--udb-font-size-sm);
1197
- color: var(--color-muted-foreground);
1198
- }
1199
- .udb-analytics-card__metrics {
1200
- display: grid;
1201
- grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
1202
- gap: var(--udb-space-4);
1203
- margin-top: var(--udb-space-4);
1204
- }
1205
- .udb-chart {
1206
- position: relative;
1207
- width: 100%;
1208
- }
1209
- .udb-chart__empty {
1210
- display: flex;
1211
- align-items: center;
1212
- justify-content: center;
1213
- height: 100%;
1214
- min-height: 192px;
1215
- padding: var(--udb-space-6);
1216
- text-align: center;
1217
- font-size: var(--udb-font-size-md);
1218
- color: var(--color-muted-foreground);
1219
- }
1220
- .udb-chart__axis {
1221
- font-size: var(--udb-font-size-sm);
1222
- fill: var(--color-muted-foreground);
1223
- }
1224
- .udb-chart__grid {
1225
- stroke: var(--color-border);
1226
- }
1227
- .udb-chart__svg {
1228
- display: block;
1229
- width: 100%;
1230
- height: 100%;
1231
- overflow: visible;
1232
- }
1233
- .udb-chart__legend {
1234
- display: flex;
1235
- align-items: center;
1236
- justify-content: center;
1237
- flex-wrap: wrap;
1238
- gap: var(--udb-space-3);
1239
- margin-top: var(--udb-space-3);
1240
- }
1241
- .udb-chart__chip {
1242
- display: inline-flex;
1243
- align-items: center;
1244
- gap: var(--udb-space-2);
1245
- font-size: var(--udb-font-size-sm);
1246
- color: var(--color-muted-foreground);
1247
- }
1248
- .udb-chart__chip-dot {
1249
- width: 8px;
1250
- height: 8px;
1251
- border-radius: 50%;
1252
- flex-shrink: 0;
1253
- }
1254
1162
  .udb-empty {
1255
1163
  display: flex;
1256
1164
  flex-direction: column;
@@ -1610,394 +1518,6 @@
1610
1518
  white-space: nowrap;
1611
1519
  color: var(--color-muted-foreground);
1612
1520
  }
1613
- .udb-chartcard {
1614
- display: flex;
1615
- flex-direction: column;
1616
- min-width: 0;
1617
- background: var(--color-card);
1618
- border: 1px solid var(--color-border);
1619
- border-radius: var(--radius-lg);
1620
- box-shadow: var(--shadow-sm);
1621
- }
1622
- .udb-chartcard__head {
1623
- display: flex;
1624
- align-items: flex-start;
1625
- justify-content: space-between;
1626
- gap: var(--udb-space-3);
1627
- padding: 14px 18px 4px;
1628
- flex-wrap: wrap;
1629
- }
1630
- .udb-chartcard__heading {
1631
- min-width: 0;
1632
- }
1633
- .udb-chartcard__title {
1634
- font-size: var(--udb-font-size-md);
1635
- font-weight: 600;
1636
- color: var(--color-foreground);
1637
- }
1638
- .udb-chartcard__sub {
1639
- font-size: var(--udb-font-size-sm);
1640
- color: var(--color-muted-foreground);
1641
- margin-top: 1px;
1642
- }
1643
- .udb-chartcard__tools {
1644
- display: flex;
1645
- align-items: center;
1646
- gap: 12px;
1647
- flex-wrap: wrap;
1648
- }
1649
- .udb-chartcard__body {
1650
- padding: 10px 14px 14px;
1651
- min-width: 0;
1652
- }
1653
- .udb-chartcard__body svg {
1654
- display: block;
1655
- width: 100%;
1656
- height: auto;
1657
- }
1658
- .udb-chartcard__plot {
1659
- position: relative;
1660
- }
1661
- .udb-chartlegend {
1662
- display: flex;
1663
- flex-wrap: wrap;
1664
- gap: 5px 14px;
1665
- }
1666
- .udb-chartlegend__item {
1667
- display: inline-flex;
1668
- align-items: center;
1669
- gap: 6px;
1670
- font-size: var(--udb-font-size-sm);
1671
- color: var(--color-foreground);
1672
- white-space: nowrap;
1673
- }
1674
- .udb-chartlegend__dot {
1675
- width: 8px;
1676
- height: 8px;
1677
- border-radius: 2.5px;
1678
- flex: none;
1679
- }
1680
- .udb-chartlegend__value {
1681
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1682
- color: var(--color-muted-foreground);
1683
- font-size: var(--udb-font-size-xs);
1684
- }
1685
- .udb-chartlegend__hint {
1686
- color: var(--color-muted-foreground);
1687
- font-size: var(--udb-font-size-xs);
1688
- }
1689
- .udb-charttip {
1690
- position: absolute;
1691
- pointer-events: none;
1692
- background: var(--color-foreground);
1693
- color: var(--color-background);
1694
- border-radius: var(--radius-md);
1695
- padding: 7px 10px;
1696
- font-size: var(--udb-font-size-sm);
1697
- box-shadow: var(--shadow-lg);
1698
- z-index: 30;
1699
- min-width: 120px;
1700
- transform: translate(-50%, calc(-100% - 10px));
1701
- }
1702
- .udb-charttip__title {
1703
- font-weight: 600;
1704
- margin-bottom: 2px;
1705
- white-space: nowrap;
1706
- }
1707
- .udb-charttip__row {
1708
- display: flex;
1709
- align-items: center;
1710
- gap: 6px;
1711
- justify-content: space-between;
1712
- font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1713
- font-size: var(--udb-font-size-xs);
1714
- }
1715
- .udb-charttip__row b {
1716
- font-weight: 600;
1717
- }
1718
- .udb-charttip__label {
1719
- display: inline-flex;
1720
- align-items: center;
1721
- gap: 5px;
1722
- }
1723
- .udb-hbars {
1724
- display: flex;
1725
- flex-direction: column;
1726
- gap: 10px;
1727
- }
1728
- .udb-hbars__row {
1729
- display: grid;
1730
- grid-template-columns: minmax(120px, 1.2fr) 2fr auto;
1731
- align-items: center;
1732
- gap: 12px;
1733
- }
1734
- .udb-hbars__label {
1735
- min-width: 0;
1736
- }
1737
- .udb-hbars__name {
1738
- font-weight: 600;
1739
- font-size: var(--udb-font-size-sm);
1740
- overflow: hidden;
1741
- text-overflow: ellipsis;
1742
- white-space: nowrap;
1743
- color: var(--color-foreground);
1744
- }
1745
- .udb-hbars__sub {
1746
- font-size: var(--udb-font-size-xs);
1747
- color: var(--color-muted-foreground);
1748
- }
1749
- .udb-hbars__track {
1750
- height: 8px;
1751
- background: var(--color-border);
1752
- border-radius: 999px;
1753
- overflow: hidden;
1754
- }
1755
- .udb-hbars__fill {
1756
- height: 100%;
1757
- background: var(--color-primary);
1758
- border-radius: 999px;
1759
- }
1760
- .udb-hbars__value {
1761
- font-size: var(--udb-font-size-sm);
1762
- color: var(--color-foreground);
1763
- text-align: right;
1764
- font-variant-numeric: tabular-nums;
1765
- }
1766
- .udb-barchart {
1767
- position: relative;
1768
- display: flex;
1769
- align-items: flex-end;
1770
- gap: 3px;
1771
- width: 100%;
1772
- }
1773
- .udb-barchart__goal {
1774
- position: absolute;
1775
- left: 0;
1776
- right: 0;
1777
- z-index: 5;
1778
- pointer-events: none;
1779
- border-top: 1.5px dashed var(--udb-chart-goal, #d97706);
1780
- }
1781
- .udb-barchart__goallabel {
1782
- position: absolute;
1783
- right: 0;
1784
- bottom: 2px;
1785
- padding: 0 4px;
1786
- border: 1px solid var(--udb-chart-goal, #d97706);
1787
- border-radius: var(--udb-radius-pill);
1788
- background: var(--color-card);
1789
- font-size: var(--udb-font-size-xs);
1790
- line-height: 16px;
1791
- color: var(--udb-chart-goal, #d97706);
1792
- }
1793
- .udb-barchart__col {
1794
- position: relative;
1795
- display: flex;
1796
- flex: 1;
1797
- align-items: flex-end;
1798
- min-width: 0;
1799
- height: 100%;
1800
- }
1801
- .udb-barchart__bars {
1802
- display: flex;
1803
- align-items: flex-end;
1804
- justify-content: center;
1805
- gap: 2px;
1806
- width: 100%;
1807
- height: 100%;
1808
- }
1809
- .udb-barchart__bars .udb-barchart__bar {
1810
- flex: 1;
1811
- width: auto;
1812
- }
1813
- .udb-barchart__bar {
1814
- width: 100%;
1815
- min-height: 2px;
1816
- border-radius: 3px 3px 0 0;
1817
- transition: opacity 150ms ease, height 300ms ease;
1818
- }
1819
- .udb-barchart__tip {
1820
- position: absolute;
1821
- bottom: calc(100% + 6px);
1822
- left: 50%;
1823
- z-index: 10;
1824
- padding: 4px 8px;
1825
- white-space: nowrap;
1826
- pointer-events: none;
1827
- border: 1px solid var(--color-border);
1828
- border-radius: var(--radius-sm);
1829
- background: var(--color-card);
1830
- box-shadow: var(--shadow-sm);
1831
- font-size: var(--udb-font-size-xs);
1832
- color: var(--color-muted-foreground);
1833
- }
1834
- .udb-barchart__tiptitle {
1835
- font-weight: var(--font-weight-medium);
1836
- color: var(--color-foreground);
1837
- }
1838
- .udb-barchart__tiprow {
1839
- display: flex;
1840
- align-items: center;
1841
- justify-content: space-between;
1842
- gap: 10px;
1843
- }
1844
- .udb-barchart__tiplabel {
1845
- display: inline-flex;
1846
- align-items: center;
1847
- gap: 5px;
1848
- }
1849
- .udb-barchart__tip b {
1850
- margin-right: 4px;
1851
- font-weight: var(--font-weight-medium);
1852
- color: var(--color-foreground);
1853
- }
1854
- .udb-donut {
1855
- display: flex;
1856
- align-items: center;
1857
- gap: 20px;
1858
- }
1859
- .udb-donut__wrap {
1860
- position: relative;
1861
- flex-shrink: 0;
1862
- }
1863
- .udb-donut__seg {
1864
- cursor: pointer;
1865
- transition: stroke-width 150ms ease, opacity 150ms ease;
1866
- }
1867
- .udb-donut__center {
1868
- position: absolute;
1869
- inset: 0;
1870
- display: flex;
1871
- flex-direction: column;
1872
- align-items: center;
1873
- justify-content: center;
1874
- }
1875
- .udb-donut__value {
1876
- font-size: var(--udb-font-size-lg);
1877
- font-weight: var(--font-weight-bold);
1878
- color: var(--color-foreground);
1879
- font-variant-numeric: tabular-nums;
1880
- }
1881
- .udb-donut__label {
1882
- margin-top: 2px;
1883
- font-size: var(--udb-font-size-xs);
1884
- color: var(--color-muted-foreground);
1885
- }
1886
- .udb-donut__list {
1887
- display: flex;
1888
- min-width: 0;
1889
- flex: 1;
1890
- flex-direction: column;
1891
- gap: 6px;
1892
- }
1893
- .udb-donut__item {
1894
- display: flex;
1895
- align-items: center;
1896
- justify-content: space-between;
1897
- gap: 8px;
1898
- padding: 4px 6px;
1899
- border-radius: var(--radius-sm);
1900
- }
1901
- .udb-donut__item:hover {
1902
- background: var(--color-muted);
1903
- }
1904
- .udb-donut__itemlabel {
1905
- display: flex;
1906
- min-width: 0;
1907
- align-items: center;
1908
- gap: 8px;
1909
- font-size: var(--udb-font-size-sm);
1910
- color: var(--color-foreground);
1911
- }
1912
- .udb-donut__dot {
1913
- width: 8px;
1914
- height: 8px;
1915
- flex-shrink: 0;
1916
- border-radius: 3px;
1917
- }
1918
- .udb-donut__itemvalue {
1919
- flex-shrink: 0;
1920
- font-size: var(--udb-font-size-sm);
1921
- font-weight: var(--font-weight-medium);
1922
- color: var(--color-foreground);
1923
- font-variant-numeric: tabular-nums;
1924
- }
1925
- .udb-donut__pct {
1926
- margin-left: 6px;
1927
- color: var(--color-muted-foreground);
1928
- }
1929
- .udb-linechart {
1930
- position: relative;
1931
- width: 100%;
1932
- user-select: none;
1933
- }
1934
- .udb-linechart__svg {
1935
- display: block;
1936
- width: 100%;
1937
- }
1938
- .udb-linechart__axis {
1939
- fill: var(--color-muted-foreground);
1940
- font-size: var(--udb-font-size-xs);
1941
- font-family: var(--font-sans);
1942
- }
1943
- .udb-linechart__grid {
1944
- stroke: var(--color-border);
1945
- stroke-width: 1;
1946
- }
1947
- .udb-linechart__band {
1948
- fill: var(--color-primary);
1949
- opacity: 0.08;
1950
- }
1951
- .udb-linechart__crosshair {
1952
- stroke: var(--udb-border-strong);
1953
- stroke-width: 1;
1954
- stroke-dasharray: 3 3;
1955
- }
1956
- .udb-linechart__tip {
1957
- position: absolute;
1958
- top: 8px;
1959
- z-index: 10;
1960
- min-width: 132px;
1961
- padding: 8px;
1962
- pointer-events: none;
1963
- border: 1px solid var(--color-border);
1964
- border-radius: var(--radius-md);
1965
- background: var(--color-card);
1966
- box-shadow: var(--shadow-md);
1967
- }
1968
- .udb-linechart__tiptitle {
1969
- margin-bottom: 4px;
1970
- font-size: var(--udb-font-size-xs);
1971
- color: var(--color-muted-foreground);
1972
- }
1973
- .udb-linechart__tiprow {
1974
- display: flex;
1975
- align-items: center;
1976
- justify-content: space-between;
1977
- gap: 12px;
1978
- font-size: var(--udb-font-size-sm);
1979
- }
1980
- .udb-linechart__tiprow span {
1981
- display: flex;
1982
- align-items: center;
1983
- gap: 6px;
1984
- color: var(--color-muted-foreground);
1985
- }
1986
- .udb-linechart__tiprow b {
1987
- font-weight: var(--font-weight-medium);
1988
- color: var(--color-foreground);
1989
- font-variant-numeric: tabular-nums;
1990
- }
1991
- .udb-linechart__swatch {
1992
- display: inline-block;
1993
- width: 12px;
1994
- height: 3px;
1995
- border-radius: 999px;
1996
- }
1997
- .udb-linechart__legendhost {
1998
- margin-top: 4px;
1999
- padding: 0 8px;
2000
- }
2001
1521
  .udb-pageheader__breadcrumbs .udb-pageheader__crumb + .udb-pageheader__crumb::before {
2002
1522
  content: "/";
2003
1523
  margin-right: 0.375rem;
@@ -4,26 +4,41 @@ import { describe, expect, it } from "vitest";
4
4
 
5
5
  const entry = readFileSync(new URL("./dashboard.css", import.meta.url), "utf8");
6
6
  const css = readFileSync(new URL("./chrome.css", import.meta.url), "utf8");
7
+ const chartsCss = readFileSync(new URL("../domains/charts/charts.css", import.meta.url), "utf8");
8
+ const sheet = css + chartsCss;
7
9
 
8
- const defined = new Set([...css.matchAll(/(--udb-[a-z0-9-]+)\s*:/g)].map((m) => m[1]));
9
- const used = new Set([...css.matchAll(/var\((--udb-[a-z0-9-]+)\)/g)].map((m) => m[1]));
10
+ const defined = new Set([...sheet.matchAll(/(--udb-[a-z0-9-]+)\s*:/g)].map((m) => m[1]));
11
+ const used = new Set([...sheet.matchAll(/var\((--udb-[a-z0-9-]+)\)/g)].map((m) => m[1]));
10
12
 
11
13
  describe("dashboard stylesheet contract", () => {
12
14
  it("defines every --udb variable it uses", () => {
13
15
  expect([...used].filter((v) => !defined.has(v))).toEqual([]);
14
16
  });
15
17
 
16
- it("entry chains the design-system stylesheet and the chrome rules", () => {
18
+ it("defines the eight chart series tokens", () => {
19
+ for (let i = 1; i <= 8; i += 1) {
20
+ expect(chartsCss).toContain(`--udb-chart-${i}:`);
21
+ }
22
+ });
23
+
24
+ it("entry chains the design-system stylesheet, the chrome rules and the chart rules", () => {
17
25
  expect(entry).toContain('@import "@umituz/web-design-system/styles.css";');
18
26
  expect(entry).toContain('@import "./chrome.css";');
27
+ expect(entry).toContain('@import "../domains/charts/charts.css";');
19
28
  });
20
29
 
21
30
  it("chrome carries no stylesheet imports (Tailwind hosts import it beside their own DS build)", () => {
22
31
  expect(css.match(/@import[^;]+;/g) ?? []).toEqual([]);
23
32
  });
24
33
 
34
+ it("chart selectors live in charts.css, not chrome.css", () => {
35
+ expect(
36
+ css.match(/udb-(chartcard|chartlegend|charttip|barchart|donut|linechart|hbars|heatmap)[a-z_-]*/g) ?? [],
37
+ ).toEqual([]);
38
+ });
39
+
25
40
  it("carries no legacy --u-* tokens", () => {
26
- expect(css.match(/--u-[a-z0-9-]+/g) ?? []).toEqual([]);
41
+ expect(sheet.match(/--u-[a-z0-9-]+/g) ?? []).toEqual([]);
27
42
  });
28
43
 
29
44
  it("reads only design-system variables that exist or are documented optional slots", () => {
@@ -40,7 +55,7 @@ describe("dashboard stylesheet contract", () => {
40
55
  "utf8",
41
56
  );
42
57
  const dsDefined = new Set([...dsCss.matchAll(/(--[a-z][a-z0-9-]*)\s*:/g)].map((m) => m[1]));
43
- const read = new Set([...css.matchAll(/var\((--[a-z][a-z0-9-]*)[,)]/g)].map((m) => m[1]));
58
+ const read = new Set([...sheet.matchAll(/var\((--[a-z][a-z0-9-]*)[,)]/g)].map((m) => m[1]));
44
59
  const missing = [...read].filter(
45
60
  (v) => !v.startsWith("--udb-") && !dsDefined.has(v) && !optional.has(v),
46
61
  );
@@ -1,2 +1,3 @@
1
1
  @import "@umituz/web-design-system/styles.css";
2
2
  @import "./chrome.css";
3
+ @import "../domains/charts/charts.css";
@@ -1,87 +0,0 @@
1
- import { Loader2, AlertCircle } from "lucide-react";
2
- import {
3
- Card,
4
- CardHeader,
5
- CardTitle,
6
- CardDescription,
7
- CardContent,
8
- } from "@umituz/web-design-system/organisms";
9
- import { cn } from "@umituz/web-design-system/utils/cn";
10
- import type { AnalyticsCardProps } from "../types/analytics";
11
- import { MetricCard } from "./MetricCard";
12
- import { AnalyticsChart } from "./AnalyticsChart";
13
-
14
- const SURFACE_CLASS = {
15
- sm: "udb-card--sm",
16
- md: undefined,
17
- lg: "udb-card--lg",
18
- full: undefined,
19
- } as const;
20
-
21
- export const AnalyticsCard = ({
22
- title,
23
- description,
24
- chart,
25
- metrics,
26
- size = "md",
27
- loading = false,
28
- error,
29
- className,
30
- children,
31
- }: AnalyticsCardProps) => {
32
- if (loading) {
33
- return (
34
- <Card className={cn(SURFACE_CLASS[size], className)}>
35
- <div className="udb-analytics-card__status" role="status">
36
- <Loader2 className="udb-spin udb-analytics-card__spinner" aria-hidden="true" />
37
- </div>
38
-
39
- </Card>
40
-
41
- );
42
- }
43
-
44
- if (error) {
45
- return (
46
- <Card className={cn(SURFACE_CLASS[size], className)}>
47
- <div className="udb-analytics-card__status udb-analytics-card__status--error" role="alert">
48
- <AlertCircle className="udb-analytics-card__error-icon" aria-hidden="true" />
49
- <p className="udb-analytics-card__error-text">{error}</p>
50
-
51
- </div>
52
-
53
- </Card>
54
-
55
- );
56
- }
57
-
58
- return (
59
- <Card className={cn(SURFACE_CLASS[size], className)}>
60
- {(title || description) && (
61
- <CardHeader>
62
- {title && <CardTitle>{title}</CardTitle>}
63
-
64
- {description && <CardDescription>{description}</CardDescription>}
65
-
66
- </CardHeader>
67
-
68
- )}
69
- <CardContent>
70
- {chart && <AnalyticsChart config={chart} />}
71
- {metrics && metrics.length > 0 && (
72
- <div className="udb-analytics-card__metrics">
73
- {metrics.map((metric) => (
74
- <MetricCard key={metric.id} metric={metric} size="sm" />
75
- ))}
76
- </div>
77
-
78
- )}
79
- {children}
80
- </CardContent>
81
-
82
- </Card>
83
-
84
- );
85
- };
86
-
87
- export default AnalyticsCard;