@siyahi/ui 0.1.9-next.3 → 0.1.9-next.31

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 (254) hide show
  1. package/DESIGN.md +251 -0
  2. package/README.md +94 -177
  3. package/THIRD_PARTY_NOTICES.md +11 -11
  4. package/agents/examples/accordion.tsx +39 -0
  5. package/agents/examples/alert.tsx +24 -0
  6. package/agents/examples/app-sidebar.tsx +40 -0
  7. package/agents/examples/avatar.tsx +24 -0
  8. package/agents/examples/badge.tsx +26 -0
  9. package/agents/examples/bar-list-labels.tsx +22 -0
  10. package/agents/examples/bar-list-sides.tsx +40 -0
  11. package/agents/examples/bar-list.tsx +24 -0
  12. package/agents/examples/breadcrumb.tsx +28 -0
  13. package/agents/examples/button-states.tsx +23 -0
  14. package/agents/examples/button.tsx +21 -0
  15. package/agents/examples/calendar.tsx +11 -0
  16. package/agents/examples/callout.tsx +33 -0
  17. package/agents/examples/card.tsx +36 -0
  18. package/agents/examples/change-bar.tsx +104 -0
  19. package/agents/examples/change-grid-money.tsx +36 -0
  20. package/agents/examples/change-grid.tsx +43 -0
  21. package/agents/examples/chart-area-log.tsx +45 -0
  22. package/agents/examples/chart-area.tsx +39 -0
  23. package/agents/examples/chart-bar-flows.tsx +32 -0
  24. package/agents/examples/chart-bar-hourly.tsx +28 -0
  25. package/agents/examples/chart-bar-losses.tsx +29 -0
  26. package/agents/examples/chart-bar-teams.tsx +72 -0
  27. package/agents/examples/chart-bar-years.tsx +42 -0
  28. package/agents/examples/chart-bar.tsx +56 -0
  29. package/agents/examples/chart-category-ticks.tsx +50 -0
  30. package/agents/examples/chart-line-events.tsx +47 -0
  31. package/agents/examples/chart-line-forecast.tsx +36 -0
  32. package/agents/examples/chart-line-log.tsx +39 -0
  33. package/agents/examples/chart-line-quiet.tsx +114 -0
  34. package/agents/examples/chart-line-timeline.tsx +41 -0
  35. package/agents/examples/chart-line.tsx +57 -0
  36. package/agents/examples/chart-panels.tsx +94 -0
  37. package/agents/examples/code-block.tsx +40 -0
  38. package/agents/examples/collapsible.tsx +18 -0
  39. package/agents/examples/command.tsx +29 -0
  40. package/agents/examples/context-menu.tsx +17 -0
  41. package/agents/examples/copy-button.tsx +8 -0
  42. package/agents/examples/data-bar.tsx +114 -0
  43. package/agents/examples/data-table-compact.tsx +93 -0
  44. package/agents/examples/data-table-filters.tsx +103 -0
  45. package/agents/examples/data-table.tsx +96 -0
  46. package/agents/examples/delta.tsx +18 -0
  47. package/agents/examples/dialog.tsx +28 -0
  48. package/agents/examples/distribution-bar-budget.tsx +30 -0
  49. package/agents/examples/distribution-bar-tug.tsx +74 -0
  50. package/agents/examples/drawdown-chart.tsx +35 -0
  51. package/agents/examples/dropdown-menu.tsx +31 -0
  52. package/agents/examples/field.tsx +108 -0
  53. package/agents/examples/formatters.tsx +42 -0
  54. package/agents/examples/heatmap-calendar-signed.tsx +67 -0
  55. package/agents/examples/heatmap-calendar.tsx +62 -0
  56. package/agents/examples/heatmap-status.tsx +61 -0
  57. package/agents/examples/heatmap-weekday.tsx +72 -0
  58. package/agents/examples/histogram-chart.tsx +28 -0
  59. package/agents/examples/input-states.tsx +23 -0
  60. package/agents/examples/input.tsx +17 -0
  61. package/agents/examples/local-time.tsx +14 -0
  62. package/agents/examples/metric-strip.tsx +46 -0
  63. package/agents/examples/overview-dashboard.tsx +180 -0
  64. package/agents/examples/page-hero.tsx +38 -0
  65. package/agents/examples/page-section.tsx +52 -0
  66. package/agents/examples/popover.tsx +23 -0
  67. package/agents/examples/price-chart.tsx +32 -0
  68. package/agents/examples/progress-tone.tsx +29 -0
  69. package/agents/examples/progress.tsx +10 -0
  70. package/agents/examples/range-position-table.tsx +113 -0
  71. package/agents/examples/range-position.tsx +55 -0
  72. package/agents/examples/scatter-chart-quadrants.tsx +63 -0
  73. package/agents/examples/scatter-chart-scales.tsx +46 -0
  74. package/agents/examples/scatter-chart.tsx +78 -0
  75. package/agents/examples/scroll-area.tsx +22 -0
  76. package/agents/examples/section-cards-select.tsx +28 -0
  77. package/agents/examples/section-cards-trend.tsx +32 -0
  78. package/agents/examples/section-cards.tsx +48 -0
  79. package/agents/examples/select.tsx +27 -0
  80. package/agents/examples/separator.tsx +13 -0
  81. package/agents/examples/sheet.tsx +15 -0
  82. package/agents/examples/skeleton.tsx +11 -0
  83. package/agents/examples/slider.tsx +5 -0
  84. package/agents/examples/slope-chart-market.tsx +33 -0
  85. package/agents/examples/slope-chart.tsx +26 -0
  86. package/agents/examples/stale-blocks.tsx +56 -0
  87. package/agents/examples/surfaces.tsx +116 -0
  88. package/agents/examples/table.tsx +60 -0
  89. package/agents/examples/tabs.tsx +16 -0
  90. package/agents/examples/target-rows.tsx +74 -0
  91. package/agents/examples/toggle-group.tsx +12 -0
  92. package/agents/examples/toggle.tsx +11 -0
  93. package/agents/examples/tooltip.tsx +13 -0
  94. package/agents/examples/treemap.tsx +93 -0
  95. package/agents/examples/waterfall-chart-stores.tsx +27 -0
  96. package/agents/examples/waterfall-chart.tsx +37 -0
  97. package/agents/manifest.json +1391 -0
  98. package/agents/report-rules.json +7 -0
  99. package/dist/components/registry/charts/area-chart-card.d.ts +7 -3
  100. package/dist/components/registry/charts/area-chart-card.js +56 -10
  101. package/dist/components/registry/charts/bar-chart-card.d.ts +1 -1
  102. package/dist/components/registry/charts/bar-chart-card.js +20 -22
  103. package/dist/components/registry/charts/line-chart-card.d.ts +3 -3
  104. package/dist/components/registry/charts/line-chart-card.js +44 -9
  105. package/dist/components/registry/dashboard-01/section-cards.d.ts +6 -0
  106. package/dist/components/registry/dashboard-01/section-cards.js +51 -35
  107. package/dist/components/registry/dashboardcn/bar-list.js +17 -10
  108. package/dist/components/registry/dashboardcn/distribution-bar.js +6 -4
  109. package/dist/components/registry/dashboardcn/kpi-row-card.d.ts +29 -0
  110. package/dist/components/registry/dashboardcn/kpi-row-card.js +81 -0
  111. package/dist/components/registry/dashboardcn/sparkline.d.ts +22 -0
  112. package/dist/components/registry/dashboardcn/sparkline.js +117 -0
  113. package/dist/components/registry/heatmap/calendar-heatmap.d.ts +11 -3
  114. package/dist/components/registry/heatmap/calendar-heatmap.js +164 -45
  115. package/dist/components/registry/heatmap/status-heatmap.d.ts +5 -3
  116. package/dist/components/registry/heatmap/status-heatmap.js +115 -54
  117. package/dist/components/registry/heatmap/weekday-heatmap.d.ts +9 -3
  118. package/dist/components/registry/heatmap/weekday-heatmap.js +83 -53
  119. package/dist/components/registry/niko-table/core/data-table-context.d.ts +18 -1
  120. package/dist/components/registry/niko-table/core/data-table-context.js +7 -1
  121. package/dist/components/registry/niko-table/core/data-table-grouped-row.js +3 -1
  122. package/dist/components/registry/niko-table/core/data-table-root.js +39 -4
  123. package/dist/components/registry/niko-table/core/data-table-structure.js +17 -12
  124. package/dist/components/registry/niko-table/core/data-table.d.ts +2 -2
  125. package/dist/components/registry/niko-table/core/data-table.js +5 -1
  126. package/dist/components/registry/niko-table/filters/table-faceted-filter.js +5 -5
  127. package/dist/components/registry/niko-table/filters/table-search-filter.js +1 -1
  128. package/dist/components/registry/niko-table/lib/flex-columns.d.ts +1 -1
  129. package/dist/components/registry/niko-table/lib/flex-columns.js +3 -3
  130. package/dist/components/registry/niko-table/lib/styles.d.ts +1 -1
  131. package/dist/components/registry/niko-table/lib/styles.js +3 -3
  132. package/dist/components/registry/niko-table/types/index.d.ts +9 -0
  133. package/dist/components/registry/niko-table/ui/table.js +2 -2
  134. package/dist/components/registry/sidebar-07/app-sidebar.d.ts +1 -1
  135. package/dist/components/registry/sidebar-07/app-sidebar.js +3 -1
  136. package/dist/components/registry/sidebar-07/nav-main.d.ts +2 -1
  137. package/dist/components/registry/sidebar-07/nav-main.js +16 -3
  138. package/dist/components/siyahi/callout.d.ts +17 -0
  139. package/dist/components/siyahi/callout.js +34 -0
  140. package/dist/components/siyahi/change-bar.d.ts +21 -0
  141. package/dist/components/siyahi/change-bar.js +35 -0
  142. package/dist/components/siyahi/change-grid.d.ts +31 -0
  143. package/dist/components/siyahi/change-grid.js +74 -0
  144. package/dist/components/siyahi/data-bar.d.ts +19 -0
  145. package/dist/components/siyahi/data-bar.js +29 -0
  146. package/dist/components/siyahi/data-table-compact-columns-toggle.d.ts +4 -0
  147. package/dist/components/siyahi/data-table-compact-columns-toggle.js +19 -0
  148. package/dist/components/siyahi/data-table-footnote.d.ts +12 -0
  149. package/dist/components/siyahi/data-table-footnote.js +35 -0
  150. package/dist/components/siyahi/default-sidebar-open.d.ts +8 -0
  151. package/dist/components/siyahi/default-sidebar-open.js +13 -0
  152. package/dist/components/siyahi/delta.d.ts +5 -1
  153. package/dist/components/siyahi/delta.js +14 -9
  154. package/dist/components/siyahi/drawdown-chart.d.ts +34 -0
  155. package/dist/components/siyahi/drawdown-chart.js +102 -0
  156. package/dist/components/siyahi/histogram-chart.d.ts +57 -0
  157. package/dist/components/siyahi/histogram-chart.js +134 -0
  158. package/dist/components/siyahi/page-hero.d.ts +23 -0
  159. package/dist/components/siyahi/page-hero.js +43 -0
  160. package/dist/components/siyahi/page-section.d.ts +4 -1
  161. package/dist/components/siyahi/page-section.js +6 -3
  162. package/dist/components/siyahi/page-toc.d.ts +20 -0
  163. package/dist/components/siyahi/page-toc.js +76 -0
  164. package/dist/components/siyahi/panel-grid.d.ts +24 -0
  165. package/dist/components/siyahi/panel-grid.js +37 -0
  166. package/dist/components/siyahi/quote.d.ts +12 -0
  167. package/dist/components/siyahi/quote.js +23 -0
  168. package/dist/components/siyahi/range-position.d.ts +24 -0
  169. package/dist/components/siyahi/range-position.js +105 -0
  170. package/dist/components/siyahi/scale-toggle.d.ts +32 -0
  171. package/dist/components/siyahi/scale-toggle.js +61 -0
  172. package/dist/components/siyahi/scatter-chart.d.ts +69 -0
  173. package/dist/components/siyahi/scatter-chart.js +395 -0
  174. package/dist/components/siyahi/siyahi-provider.d.ts +15 -2
  175. package/dist/components/siyahi/siyahi-provider.js +17 -4
  176. package/dist/components/siyahi/slope-chart.d.ts +35 -0
  177. package/dist/components/siyahi/slope-chart.js +159 -0
  178. package/dist/components/siyahi/stale-note.d.ts +9 -0
  179. package/dist/components/siyahi/stale-note.js +12 -0
  180. package/dist/components/siyahi/status-alert.d.ts +15 -0
  181. package/dist/components/siyahi/status-alert.js +29 -0
  182. package/dist/components/siyahi/status-badge.d.ts +15 -0
  183. package/dist/components/siyahi/status-badge.js +24 -0
  184. package/dist/components/siyahi/target-rows.d.ts +34 -0
  185. package/dist/components/siyahi/target-rows.js +97 -0
  186. package/dist/components/siyahi/tone-progress.d.ts +1 -1
  187. package/dist/components/siyahi/tone-progress.js +1 -1
  188. package/dist/components/siyahi/treemap.d.ts +8 -5
  189. package/dist/components/siyahi/treemap.js +80 -34
  190. package/dist/components/siyahi/waterfall-chart.d.ts +51 -0
  191. package/dist/components/siyahi/waterfall-chart.js +147 -0
  192. package/dist/components/ui/accordion.js +5 -5
  193. package/dist/components/ui/alert.js +2 -2
  194. package/dist/components/ui/badge.js +1 -1
  195. package/dist/components/ui/breadcrumb.js +2 -2
  196. package/dist/components/ui/button.js +10 -10
  197. package/dist/components/ui/calendar.js +1 -1
  198. package/dist/components/ui/card.js +4 -4
  199. package/dist/components/ui/chart.js +1 -1
  200. package/dist/components/ui/code-block.js +13 -12
  201. package/dist/components/ui/command.js +7 -6
  202. package/dist/components/ui/context-menu.js +7 -7
  203. package/dist/components/ui/dialog.js +5 -5
  204. package/dist/components/ui/dropdown-menu.js +8 -8
  205. package/dist/components/ui/field.d.ts +26 -0
  206. package/dist/components/ui/field.js +109 -0
  207. package/dist/components/ui/input-group.js +11 -11
  208. package/dist/components/ui/input.js +1 -1
  209. package/dist/components/ui/label.d.ts +5 -0
  210. package/dist/components/ui/label.js +13 -0
  211. package/dist/components/ui/popover.js +3 -3
  212. package/dist/components/ui/progress.js +1 -1
  213. package/dist/components/ui/select.js +6 -6
  214. package/dist/components/ui/sheet.js +5 -5
  215. package/dist/components/ui/sidebar.js +17 -18
  216. package/dist/components/ui/skeleton.js +1 -1
  217. package/dist/components/ui/slider.js +2 -2
  218. package/dist/components/ui/table.js +2 -2
  219. package/dist/components/ui/tabs.js +2 -2
  220. package/dist/components/ui/textarea.js +1 -1
  221. package/dist/components/ui/toggle-group.js +2 -2
  222. package/dist/components/ui/toggle.js +4 -4
  223. package/dist/components/ui/tooltip.js +2 -2
  224. package/dist/index.d.ts +35 -8
  225. package/dist/index.js +30 -4
  226. package/dist/lib/chart-frame.d.ts +51 -7
  227. package/dist/lib/chart-frame.js +390 -133
  228. package/dist/lib/chart-marks.d.ts +83 -0
  229. package/dist/lib/chart-marks.js +216 -0
  230. package/dist/lib/chart-series.d.ts +42 -10
  231. package/dist/lib/compact-columns.d.ts +19 -0
  232. package/dist/lib/compact-columns.js +55 -0
  233. package/dist/lib/fit-text.d.ts +6 -0
  234. package/dist/lib/fit-text.js +11 -0
  235. package/dist/lib/format.d.ts +8 -3
  236. package/dist/lib/format.js +55 -17
  237. package/dist/lib/heat.d.ts +7 -0
  238. package/dist/lib/heat.js +14 -0
  239. package/dist/lib/heatmap-navigation.d.ts +8 -0
  240. package/dist/lib/heatmap-navigation.js +49 -0
  241. package/dist/lib/scatter.d.ts +88 -0
  242. package/dist/lib/scatter.js +179 -0
  243. package/dist/lib/ticks.d.ts +27 -0
  244. package/dist/lib/ticks.js +67 -0
  245. package/dist/lib/tone.d.ts +36 -0
  246. package/dist/lib/tone.js +35 -0
  247. package/dist/lib/treemap.d.ts +0 -5
  248. package/dist/lib/treemap.js +1 -11
  249. package/dist/lib/use-element-width.d.ts +5 -0
  250. package/dist/lib/use-element-width.js +15 -0
  251. package/package.json +5 -1
  252. package/registry.lock.json +16 -0
  253. package/report.css +63 -47
  254. package/styles/siyahi.css +708 -55
@@ -0,0 +1,60 @@
1
+ import {
2
+ Card,
3
+ CardContent,
4
+ CardHeader,
5
+ CardTitle,
6
+ Table,
7
+ TableBody,
8
+ TableCell,
9
+ TableFooter,
10
+ TableHead,
11
+ TableHeader,
12
+ TableRow,
13
+ useFormat,
14
+ } from "@siyahi/ui";
15
+
16
+ const rows = [
17
+ { month: "July", in: 85000, out: 12000 },
18
+ { month: "August", in: 85000, out: 64000 },
19
+ { month: "September", in: 92000, out: 8000 },
20
+ ];
21
+
22
+ export default function TableExample() {
23
+ const { money } = useFormat();
24
+ const total = (key: "in" | "out") => rows.reduce((sum, row) => sum + row[key], 0);
25
+ return (
26
+ <Card>
27
+ <CardHeader>
28
+ <CardTitle>Cash flow</CardTitle>
29
+ </CardHeader>
30
+ <CardContent>
31
+ <Table>
32
+ <TableHeader>
33
+ <TableRow>
34
+ <TableHead>Month</TableHead>
35
+ <TableHead data-numeric>In</TableHead>
36
+ <TableHead data-numeric>Out</TableHead>
37
+ </TableRow>
38
+ </TableHeader>
39
+ <TableBody>
40
+ {rows.map((row) => (
41
+ // August's spending needs a look: the page marks the row, and the theme washes it amber.
42
+ <TableRow key={row.month} data-tone={row.out > 50000 ? "warning" : undefined}>
43
+ <TableCell>{row.month}</TableCell>
44
+ <TableCell data-numeric>{money(row.in)}</TableCell>
45
+ <TableCell data-numeric>{money(row.out)}</TableCell>
46
+ </TableRow>
47
+ ))}
48
+ </TableBody>
49
+ <TableFooter>
50
+ <TableRow>
51
+ <TableCell>Total</TableCell>
52
+ <TableCell data-numeric>{money(total("in"))}</TableCell>
53
+ <TableCell data-numeric>{money(total("out"))}</TableCell>
54
+ </TableRow>
55
+ </TableFooter>
56
+ </Table>
57
+ </CardContent>
58
+ </Card>
59
+ );
60
+ }
@@ -0,0 +1,16 @@
1
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@siyahi/ui";
2
+
3
+ export default function TabsExample() {
4
+ return (
5
+ <Tabs defaultValue="orders">
6
+ <TabsList>
7
+ <TabsTrigger value="orders">Orders</TabsTrigger>
8
+ <TabsTrigger value="returns">Returns</TabsTrigger>
9
+ <TabsTrigger value="payouts">Payouts</TabsTrigger>
10
+ </TabsList>
11
+ <TabsContent value="orders">Every order placed, newest first.</TabsContent>
12
+ <TabsContent value="returns">Items sent back and the refunds paid for them.</TabsContent>
13
+ <TabsContent value="payouts">Money paid out to sellers each week.</TabsContent>
14
+ </Tabs>
15
+ );
16
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ Card,
3
+ CardContent,
4
+ CardDescription,
5
+ CardHeader,
6
+ CardTitle,
7
+ TargetRows,
8
+ useFormat,
9
+ type TargetRow,
10
+ type TargetStatus,
11
+ } from "@siyahi/ui";
12
+
13
+ interface Team {
14
+ name: string;
15
+ costs: string;
16
+ /** The team's share of this year's spend so far and the budget's share, as fractions; made-up figures. */
17
+ weight: number;
18
+ target: number;
19
+ }
20
+
21
+ const teams: Team[] = [
22
+ { name: "Engineering", costs: "Cloud hosting, tools, contractors", weight: 0.426, target: 0.4 },
23
+ { name: "Marketing", costs: "Ads, events, design agency", weight: 0.189, target: 0.2 },
24
+ { name: "Sales", costs: "Travel, commissions, CRM seats", weight: 0.194, target: 0.25 },
25
+ { name: "Support", costs: "Help desk seats, training", weight: 0.093, target: 0.1 },
26
+ { name: "Operations", costs: "Office rent, facilities", weight: 0.098, target: 0.05 },
27
+ ];
28
+
29
+ // Within two points of the budget is on target; past five is far enough to review it.
30
+ const NEAR = 0.02;
31
+ const FAR = 0.05;
32
+
33
+ const points = (value: number) => `${(value * 100).toFixed(1)} points`;
34
+
35
+ function statusOf({ weight, target }: Team): TargetStatus {
36
+ const gap = weight - target;
37
+ const size = `${points(Math.abs(gap))} ${gap > 0 ? "over" : "under"}`;
38
+ if (Math.abs(gap) <= NEAR) return { kind: "met", label: "On target" };
39
+ if (Math.abs(gap) <= FAR) return { kind: "missed", label: size };
40
+ return { kind: "warning", label: `${size}, needs review` };
41
+ }
42
+
43
+ export default function TargetRowsExample() {
44
+ const f = useFormat();
45
+ const rows: TargetRow[] = teams.map((team) => ({
46
+ label: team.name,
47
+ detail: team.costs,
48
+ value: team.weight,
49
+ target: team.target,
50
+ bands: [
51
+ [team.target - FAR, team.target + FAR],
52
+ [team.target - NEAR, team.target + NEAR],
53
+ ],
54
+ status: statusOf(team),
55
+ }));
56
+ return (
57
+ <Card>
58
+ <CardHeader>
59
+ <CardTitle>Sales is 5.6 points under its budget</CardTitle>
60
+ <CardDescription>
61
+ Each team's share of spend against its share of the budget, on one 0–50% scale
62
+ </CardDescription>
63
+ </CardHeader>
64
+ <CardContent>
65
+ <div className="grid gap-2">
66
+ <p className="text-sm text-muted-foreground">
67
+ Bar: the share spent so far. Tall tick: the budgeted share. Shading: within 5 points of it, darker within 2.
68
+ </p>
69
+ <TargetRows rows={rows} domain={[0, 0.5]} valueFormatter={(value) => f.pct(value)} />
70
+ </div>
71
+ </CardContent>
72
+ </Card>
73
+ );
74
+ }
@@ -0,0 +1,12 @@
1
+ import { ToggleGroup, ToggleGroupItem } from "@siyahi/ui";
2
+
3
+ export default function ToggleGroupExample() {
4
+ return (
5
+ <ToggleGroup defaultValue={["1Y"]} variant="outline" size="sm" aria-label="Range">
6
+ <ToggleGroupItem value="1M">1M</ToggleGroupItem>
7
+ <ToggleGroupItem value="6M">6M</ToggleGroupItem>
8
+ <ToggleGroupItem value="1Y">1Y</ToggleGroupItem>
9
+ <ToggleGroupItem value="All">All</ToggleGroupItem>
10
+ </ToggleGroup>
11
+ );
12
+ }
@@ -0,0 +1,11 @@
1
+ import { Toggle } from "@siyahi/ui";
2
+ import { EyeOffIcon } from "lucide-react";
3
+
4
+ export default function ToggleExample() {
5
+ return (
6
+ <Toggle variant="outline" aria-label="Hide amounts">
7
+ <EyeOffIcon />
8
+ Hide amounts
9
+ </Toggle>
10
+ );
11
+ }
@@ -0,0 +1,13 @@
1
+ import { Button, Tooltip, TooltipContent, TooltipTrigger } from "@siyahi/ui";
2
+ import { InfoIcon } from "lucide-react";
3
+
4
+ export default function TooltipExample() {
5
+ return (
6
+ <Tooltip>
7
+ <TooltipTrigger render={<Button variant="outline" size="icon" aria-label="About churn" />}>
8
+ <InfoIcon />
9
+ </TooltipTrigger>
10
+ <TooltipContent>Churn counts customers who did not renew this month.</TooltipContent>
11
+ </Tooltip>
12
+ );
13
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ Card,
3
+ CardContent,
4
+ CardDescription,
5
+ CardHeader,
6
+ CardTitle,
7
+ Tooltip,
8
+ TooltipContent,
9
+ TooltipTrigger,
10
+ Treemap,
11
+ TreemapLegend,
12
+ useFormat,
13
+ type TreemapItem,
14
+ } from "@siyahi/ui";
15
+ import { useState } from "react";
16
+
17
+ interface City extends TreemapItem {
18
+ channel: string;
19
+ }
20
+
21
+ // weight is the month's sales in ₹ and change their growth on the same month last year; Guwahati opened this year,
22
+ // so it has no last year to grow from. Mumbai sells online and in stores, so it draws two tiles under one name.
23
+ const cities: City[] = [
24
+ { name: "Mumbai", key: "mumbai-online", channel: "Online", group: "West", weight: 224400, change: 0.38 },
25
+ { name: "Mumbai", key: "mumbai-stores", channel: "Stores", group: "West", weight: 152000, change: 0.12 },
26
+ { name: "Pune", channel: "Stores", group: "West", weight: 166000, change: 0.09 },
27
+ { name: "Surat", channel: "Online", group: "West", weight: 98000, change: -0.21 },
28
+ { name: "Bengaluru", channel: "Stores", group: "South", weight: 262500, change: -0.06 },
29
+ { name: "Chennai", channel: "Stores", group: "South", weight: 258000, change: 0.44 },
30
+ { name: "Kochi", channel: "Online", group: "South", weight: 87000, change: 0.58 },
31
+ { name: "Delhi", channel: "Stores", group: "North", weight: 276000, change: 0.27 },
32
+ { name: "Jaipur", channel: "Online", group: "North", weight: 64000, change: -0.33 },
33
+ { name: "Kolkata", channel: "Stores", group: "East", weight: 255600, change: 0.16 },
34
+ { name: "Guwahati", channel: "Online", group: "Northeast", weight: 52000, change: null },
35
+ ];
36
+
37
+ export default function TreemapExample() {
38
+ const [hovered, setHovered] = useState<City | null>(null);
39
+ const [selected, setSelected] = useState<City | null>(null);
40
+ const { money, pct } = useFormat();
41
+ const figures = (c: City) =>
42
+ `${money(c.weight)} · ${c.change === null ? "new this year" : `${c.change < 0 ? "\u2212" : "+"}${pct(Math.abs(c.change))}`}`;
43
+ return (
44
+ <Card>
45
+ <CardHeader>
46
+ <CardTitle>Sales by region</CardTitle>
47
+ <CardDescription>
48
+ Area is the city's sales this month; colour is its growth on last year, deepest at ±60%
49
+ </CardDescription>
50
+ </CardHeader>
51
+ <CardContent>
52
+ <Tooltip open={hovered !== null} trackCursorAxis="both">
53
+ <TooltipTrigger render={<div />}>
54
+ <Treemap
55
+ items={cities}
56
+ height={320}
57
+ range={0.6}
58
+ onHover={setHovered}
59
+ selected={selected}
60
+ onSelect={setSelected}
61
+ />
62
+ </TooltipTrigger>
63
+ <TooltipContent side="bottom">
64
+ <div className="flex flex-col items-start">
65
+ {hovered && (
66
+ <>
67
+ <span className="font-medium">
68
+ {hovered.name} · {hovered.channel}
69
+ </span>
70
+ <span>{hovered.group}</span>
71
+ <span>{figures(hovered)}</span>
72
+ </>
73
+ )}
74
+ </div>
75
+ </TooltipContent>
76
+ </Tooltip>
77
+ <TreemapLegend range={0.6} className="mt-3 ml-auto" />
78
+ <p data-slot="treemap-selection" aria-live="polite" className="mt-3 text-sm tabular-nums">
79
+ {selected ? (
80
+ <>
81
+ <span className="font-medium">
82
+ {selected.name} · {selected.channel}
83
+ </span>{" "}
84
+ · {selected.group} · {figures(selected)}
85
+ </>
86
+ ) : (
87
+ <span className="text-muted-foreground">Tap a tile for its figures</span>
88
+ )}
89
+ </p>
90
+ </CardContent>
91
+ </Card>
92
+ );
93
+ }
@@ -0,0 +1,27 @@
1
+ import { WaterfallChartCard, useFormat, type WaterfallStep } from "@siyahi/ui";
2
+
3
+ // Revenue from last year to this, store by store; made-up figures.
4
+ const steps: WaterfallStep[] = [
5
+ { kind: "total", label: "Last year", value: 4_820_000 },
6
+ { kind: "change", label: "Koramangala flagship", value: 640_000 },
7
+ { kind: "change", label: "Indiranagar high street", value: 310_000 },
8
+ { kind: "change", label: "Whitefield mall kiosk", value: -420_000 },
9
+ { kind: "change", label: "Online orders and delivery", value: 880_000 },
10
+ { kind: "change", label: "Jayanagar (closed in June)", value: -560_000 },
11
+ { kind: "total", label: "This year" },
12
+ ];
13
+
14
+ export default function WaterfallChartStoresExample() {
15
+ const { money, moneyCompact } = useFormat();
16
+ return (
17
+ <WaterfallChartCard
18
+ title="Revenue, last year to this"
19
+ description="What each store added or lost on the way from last year's total to this year's"
20
+ steps={steps}
21
+ horizontal
22
+ valueFormatter={money}
23
+ yTickFormatter={moneyCompact}
24
+ height={steps.length * 48 + 64}
25
+ />
26
+ );
27
+ }
@@ -0,0 +1,37 @@
1
+ import { WaterfallChartCard, useFormat, type WaterfallStep } from "@siyahi/ui";
2
+
3
+ // A bakery's profit for the year, April to March, month by month; made-up figures.
4
+ const months: [string, number][] = [
5
+ ["Apr", 42000],
6
+ ["May", 38000],
7
+ ["Jun", -12000],
8
+ ["Jul", 26000],
9
+ ["Aug", 31000],
10
+ ["Sep", -8000],
11
+ ["Oct", 54000],
12
+ ["Nov", 61000],
13
+ ["Dec", 72000],
14
+ ["Jan", -21000],
15
+ ["Feb", 18000],
16
+ ["Mar", 35000],
17
+ ];
18
+ const steps: WaterfallStep[] = [
19
+ ...months.map(([label, value]): WaterfallStep => ({ kind: "change", label, value })),
20
+ // No value: the year's total is wherever the months left it.
21
+ { kind: "total", label: "Year" },
22
+ ];
23
+
24
+ export default function WaterfallChartExample() {
25
+ const { money, moneyCompact } = useFormat();
26
+ return (
27
+ <WaterfallChartCard
28
+ title="Profit for the year, month by month"
29
+ description="April to March, before tax. Each bar starts where the month before left off."
30
+ steps={steps}
31
+ labels={{ rise: "Profit", fall: "Loss", total: "Year to date" }}
32
+ valueFormatter={money}
33
+ yTickFormatter={moneyCompact}
34
+ height={300}
35
+ />
36
+ );
37
+ }