@alpic-ai/ui 0.0.0-dev.g19c2d9f → 0.0.0-dev.g1a5d5ed

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 (116) hide show
  1. package/dist/components/accordion-card.d.mts +5 -6
  2. package/dist/components/accordion.d.mts +5 -6
  3. package/dist/components/alert.d.mts +9 -11
  4. package/dist/components/area-chart.d.mts +64 -0
  5. package/dist/components/area-chart.mjs +275 -0
  6. package/dist/components/attachment-tile.d.mts +1 -3
  7. package/dist/components/avatar.d.mts +8 -10
  8. package/dist/components/badge.d.mts +2 -4
  9. package/dist/components/bar-chart.d.mts +50 -0
  10. package/dist/components/bar-chart.mjs +262 -0
  11. package/dist/components/bar-list.d.mts +31 -0
  12. package/dist/components/bar-list.mjs +111 -0
  13. package/dist/components/breadcrumb.d.mts +10 -11
  14. package/dist/components/button.d.mts +6 -8
  15. package/dist/components/card.d.mts +9 -10
  16. package/dist/components/chart-card.d.mts +25 -0
  17. package/dist/components/chart-card.mjs +48 -0
  18. package/dist/components/chart-container.d.mts +20 -0
  19. package/dist/components/chart-container.mjs +37 -0
  20. package/dist/components/chart-legend.d.mts +21 -0
  21. package/dist/components/chart-legend.mjs +35 -0
  22. package/dist/components/chart-tooltip.d.mts +33 -0
  23. package/dist/components/chart-tooltip.mjs +52 -0
  24. package/dist/components/checkbox.d.mts +2 -3
  25. package/dist/components/collapsible.d.mts +4 -5
  26. package/dist/components/combobox.d.mts +12 -11
  27. package/dist/components/combobox.mjs +7 -4
  28. package/dist/components/command.d.mts +9 -10
  29. package/dist/components/copyable.d.mts +2 -3
  30. package/dist/components/description-list.d.mts +5 -6
  31. package/dist/components/dialog.d.mts +15 -17
  32. package/dist/components/donut-chart.d.mts +46 -0
  33. package/dist/components/donut-chart.mjs +189 -0
  34. package/dist/components/dropdown-menu.d.mts +18 -20
  35. package/dist/components/form.d.mts +38 -21
  36. package/dist/components/form.mjs +7 -7
  37. package/dist/components/github-button.d.mts +1 -2
  38. package/dist/components/heatmap-chart.d.mts +48 -0
  39. package/dist/components/heatmap-chart.mjs +229 -0
  40. package/dist/components/input-group.d.mts +5 -7
  41. package/dist/components/input.d.mts +4 -5
  42. package/dist/components/input.mjs +2 -2
  43. package/dist/components/label.d.mts +2 -3
  44. package/dist/components/line-chart.d.mts +57 -0
  45. package/dist/components/line-chart.mjs +218 -0
  46. package/dist/components/page-loader.d.mts +1 -3
  47. package/dist/components/pagination.d.mts +3 -4
  48. package/dist/components/popover.d.mts +5 -6
  49. package/dist/components/radio-group.d.mts +3 -4
  50. package/dist/components/scroll-area.d.mts +3 -4
  51. package/dist/components/select-trigger-variants.d.mts +1 -3
  52. package/dist/components/select.d.mts +9 -10
  53. package/dist/components/separator.d.mts +2 -3
  54. package/dist/components/sheet.d.mts +11 -12
  55. package/dist/components/shimmer-text.d.mts +2 -2
  56. package/dist/components/sidebar.d.mts +34 -36
  57. package/dist/components/sidebar.mjs +10 -10
  58. package/dist/components/skeleton.d.mts +2 -4
  59. package/dist/components/sonner.d.mts +5 -6
  60. package/dist/components/spinner.d.mts +3 -5
  61. package/dist/components/stat.d.mts +32 -0
  62. package/dist/components/stat.mjs +117 -0
  63. package/dist/components/status-dot.d.mts +2 -4
  64. package/dist/components/switch.d.mts +2 -3
  65. package/dist/components/table.d.mts +10 -11
  66. package/dist/components/tabs.d.mts +12 -14
  67. package/dist/components/tag.d.mts +3 -5
  68. package/dist/components/task-progress.d.mts +1 -3
  69. package/dist/components/textarea.d.mts +3 -4
  70. package/dist/components/textarea.mjs +3 -3
  71. package/dist/components/toggle-group.d.mts +4 -6
  72. package/dist/components/toggle-group.mjs +3 -3
  73. package/dist/components/tooltip-icon-button.d.mts +1 -2
  74. package/dist/components/tooltip.d.mts +5 -6
  75. package/dist/components/typography.d.mts +4 -5
  76. package/dist/components/wizard.d.mts +4 -23
  77. package/dist/components/wizard.mjs +1 -19
  78. package/dist/hooks/use-chart-theme.d.mts +18 -0
  79. package/dist/hooks/use-chart-theme.mjs +57 -0
  80. package/dist/hooks/use-mobile.mjs +3 -3
  81. package/dist/hooks/use-reduced-motion.d.mts +4 -0
  82. package/dist/hooks/use-reduced-motion.mjs +16 -0
  83. package/dist/lib/chart-palette.d.mts +4 -0
  84. package/dist/lib/chart-palette.mjs +95 -0
  85. package/dist/lib/chart.d.mts +14 -0
  86. package/dist/lib/chart.mjs +42 -0
  87. package/package.json +30 -29
  88. package/src/components/area-chart.tsx +347 -0
  89. package/src/components/bar-chart.tsx +317 -0
  90. package/src/components/bar-list.tsx +166 -0
  91. package/src/components/chart-card.tsx +65 -0
  92. package/src/components/chart-container.tsx +51 -0
  93. package/src/components/chart-legend.tsx +49 -0
  94. package/src/components/chart-tooltip.tsx +93 -0
  95. package/src/components/combobox.tsx +9 -2
  96. package/src/components/donut-chart.tsx +217 -0
  97. package/src/components/form.tsx +1 -1
  98. package/src/components/heatmap-chart.tsx +331 -0
  99. package/src/components/line-chart.tsx +277 -0
  100. package/src/components/stat.tsx +113 -0
  101. package/src/components/textarea.tsx +1 -1
  102. package/src/components/wizard.tsx +1 -35
  103. package/src/hooks/use-chart-theme.ts +75 -0
  104. package/src/hooks/use-reduced-motion.ts +17 -0
  105. package/src/lib/chart-palette.ts +110 -0
  106. package/src/lib/chart.ts +90 -0
  107. package/src/stories/area-chart.stories.tsx +198 -0
  108. package/src/stories/bar-chart.stories.tsx +167 -0
  109. package/src/stories/bar-list.stories.tsx +83 -0
  110. package/src/stories/donut-chart.stories.tsx +110 -0
  111. package/src/stories/heatmap-chart.stories.tsx +105 -0
  112. package/src/stories/line-chart.stories.tsx +144 -0
  113. package/src/stories/stat.stories.tsx +64 -0
  114. package/src/stories/textarea.stories.tsx +7 -0
  115. package/src/stories/wizard.stories.tsx +23 -5
  116. package/src/styles/tokens.css +18 -0
@@ -0,0 +1,331 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { createPortal } from "react-dom";
5
+
6
+ import type { ChartPaletteName } from "../lib/chart-palette";
7
+ import { HEAT_EMPTY, heatColor, heatRamp } from "../lib/chart-palette";
8
+ import { cn } from "../lib/cn";
9
+ import { useChartContext } from "./chart-container";
10
+
11
+ export interface HeatmapChartProps {
12
+ data: ReadonlyArray<Record<string, string | number | null | undefined>>;
13
+ xKey: string;
14
+ yKey: string;
15
+ dataKey?: string;
16
+ variant?: "square" | "dot";
17
+ palette?: ChartPaletteName;
18
+ xLabels?: readonly string[];
19
+ yLabels?: readonly string[];
20
+ showAllXLabels?: boolean;
21
+ highlightPeak?: boolean;
22
+ loading?: boolean;
23
+ valueFormatter?: (value: number) => string;
24
+ xTickFormatter?: (label: string) => string;
25
+ yTickFormatter?: (label: string) => string;
26
+ tooltipMetrics?: ReadonlyArray<{ key: string; label: string; format?: (value: number) => string }>;
27
+ ariaLabel?: string;
28
+ className?: string;
29
+ }
30
+
31
+ type CellRecord = Record<string, string | number | null | undefined>;
32
+
33
+ interface HoverState {
34
+ x: number;
35
+ y: number;
36
+ rowLabel: string;
37
+ colLabel: string;
38
+ value: number;
39
+ record: CellRecord | null;
40
+ }
41
+
42
+ const PLACEHOLDER_HEIGHT = 168;
43
+ // viewBox units — the SVG scales to the container width, so these stay squares.
44
+ const CELL = 22;
45
+ const GAP = 3;
46
+ const PAD = { left: 36, top: 18, right: 6, bottom: 6 };
47
+ const MAX_X_TICKS = 13;
48
+ // Dots never fully vanish at zero and never quite touch their neighbours at peak.
49
+ const DOT_MIN = 0.42;
50
+ const DOT_RANGE = 0.52;
51
+ const TOOLTIP_OFFSET = 14;
52
+ const TOOLTIP_WIDTH = 150;
53
+ const TOOLTIP_HEIGHT = 64;
54
+
55
+ // Unambiguous composite key — labels may themselves contain hyphens, spaces, etc.
56
+ const pairKey = (rowLabel: string, colLabel: string) => JSON.stringify([rowLabel, colLabel]);
57
+
58
+ const uniqueInOrder = (values: readonly string[]) => {
59
+ const seen = new Set<string>();
60
+ const ordered: string[] = [];
61
+ for (const value of values) {
62
+ if (!seen.has(value)) {
63
+ seen.add(value);
64
+ ordered.push(value);
65
+ }
66
+ }
67
+ return ordered;
68
+ };
69
+
70
+ function HeatmapChart({
71
+ data,
72
+ xKey,
73
+ yKey,
74
+ dataKey = "value",
75
+ variant = "square",
76
+ palette,
77
+ xLabels,
78
+ yLabels,
79
+ showAllXLabels = false,
80
+ highlightPeak = true,
81
+ loading = false,
82
+ valueFormatter = (value) => value.toLocaleString("en-US"),
83
+ xTickFormatter,
84
+ yTickFormatter,
85
+ tooltipMetrics,
86
+ ariaLabel = "Activity heatmap",
87
+ className,
88
+ }: HeatmapChartProps) {
89
+ const { paletteName, theme } = useChartContext(palette);
90
+ const [hovered, setHovered] = React.useState<HoverState | null>(null);
91
+ const [mounted, setMounted] = React.useState(false);
92
+
93
+ React.useEffect(() => {
94
+ setMounted(true);
95
+ }, []);
96
+
97
+ const layout = React.useMemo(() => {
98
+ const columns = xLabels ? [...xLabels] : uniqueInOrder(data.map((row) => String(row[xKey] ?? "")));
99
+ const rows = yLabels ? [...yLabels] : uniqueInOrder(data.map((row) => String(row[yKey] ?? "")));
100
+ const valueAt = new Map<string, number>();
101
+ const recordAt = new Map<string, CellRecord>();
102
+ for (const row of data) {
103
+ const key = pairKey(String(row[yKey] ?? ""), String(row[xKey] ?? ""));
104
+ valueAt.set(key, Number(row[dataKey]) || 0);
105
+ recordAt.set(key, row);
106
+ }
107
+ let maxValue = 0;
108
+ let peakKey = "";
109
+ const cells = rows.flatMap((rowLabel, rowIndex) =>
110
+ columns.map((colLabel, colIndex) => {
111
+ const key = pairKey(rowLabel, colLabel);
112
+ const value = valueAt.get(key) ?? 0;
113
+ if (value > maxValue) {
114
+ maxValue = value;
115
+ peakKey = key;
116
+ }
117
+ return { rowLabel, colLabel, rowIndex, colIndex, value, record: recordAt.get(key) ?? null };
118
+ }),
119
+ );
120
+ return { columns, rows, cells, maxValue, peakKey };
121
+ }, [data, xKey, yKey, dataKey, xLabels, yLabels]);
122
+
123
+ const { columns, rows, cells, maxValue, peakKey } = layout;
124
+ const isEmpty = columns.length === 0 || rows.length === 0 || maxValue <= 0;
125
+
126
+ if (loading) {
127
+ return (
128
+ <div
129
+ className={cn(
130
+ "flex items-center justify-center gap-2.5 font-mono text-quaternary-foreground text-text-xs",
131
+ className,
132
+ )}
133
+ style={{ minHeight: PLACEHOLDER_HEIGHT }}
134
+ >
135
+ <span className="size-4 animate-spin rounded-full border-2 border-border border-t-foreground" />
136
+ loading…
137
+ </div>
138
+ );
139
+ }
140
+
141
+ if (isEmpty) {
142
+ return (
143
+ <div
144
+ className={cn(
145
+ "flex items-center justify-center rounded-lg border border-border border-dashed font-mono text-quaternary-foreground text-text-xs",
146
+ className,
147
+ )}
148
+ style={{ minHeight: PLACEHOLDER_HEIGHT }}
149
+ >
150
+ no data in range
151
+ </div>
152
+ );
153
+ }
154
+
155
+ const ramp = heatRamp(paletteName, theme.isDark ? HEAT_EMPTY.dark : HEAT_EMPTY.light);
156
+ const totalWidth = PAD.left + columns.length * CELL + (columns.length - 1) * GAP + PAD.right;
157
+ const totalHeight = PAD.top + rows.length * CELL + (rows.length - 1) * GAP + PAD.bottom;
158
+ const xStride = showAllXLabels ? 1 : Math.ceil(columns.length / MAX_X_TICKS);
159
+ const cellX = (col: number) => PAD.left + col * (CELL + GAP);
160
+ const cellY = (row: number) => PAD.top + row * (CELL + GAP);
161
+ const formatX = (label: string) => (xTickFormatter ? xTickFormatter(label) : label);
162
+ const formatY = (label: string) => (yTickFormatter ? yTickFormatter(label) : label);
163
+
164
+ // The tooltip follows the cursor; rendered through a portal so a transformed/
165
+ // clipped ancestor (e.g. the card's mount animation + overflow-hidden) can't
166
+ // shift or trim it. Flip near the viewport edges.
167
+ const tooltipLeft =
168
+ hovered && hovered.x + TOOLTIP_OFFSET + TOOLTIP_WIDTH > window.innerWidth
169
+ ? hovered.x - TOOLTIP_OFFSET - TOOLTIP_WIDTH
170
+ : (hovered?.x ?? 0) + TOOLTIP_OFFSET;
171
+ const tooltipTop =
172
+ hovered && hovered.y + TOOLTIP_OFFSET + TOOLTIP_HEIGHT > window.innerHeight
173
+ ? hovered.y - TOOLTIP_OFFSET - TOOLTIP_HEIGHT
174
+ : (hovered?.y ?? 0) + TOOLTIP_OFFSET;
175
+
176
+ return (
177
+ <div data-slot="heatmap-chart" className={cn("w-full", className)}>
178
+ <div className="overflow-x-auto">
179
+ <svg
180
+ viewBox={`0 0 ${totalWidth} ${totalHeight}`}
181
+ className="block min-w-[480px]"
182
+ style={{ width: "100%", height: "auto" }}
183
+ role="img"
184
+ aria-label={ariaLabel}
185
+ onMouseLeave={() => setHovered(null)}
186
+ >
187
+ {columns.map((label, col) =>
188
+ col % xStride === 0 ? (
189
+ <text
190
+ key={`x-${label}`}
191
+ x={cellX(col) + CELL / 2}
192
+ y={PAD.top - 7}
193
+ textAnchor="middle"
194
+ className="fill-quaternary-foreground font-mono text-[8.5px]"
195
+ >
196
+ {formatX(label)}
197
+ </text>
198
+ ) : null,
199
+ )}
200
+ {rows.map((label, row) => (
201
+ <text
202
+ key={`y-${label}`}
203
+ x={PAD.left - 8}
204
+ y={cellY(row) + CELL / 2 + 3}
205
+ textAnchor="end"
206
+ className="fill-quaternary-foreground font-mono text-[8.5px]"
207
+ >
208
+ {formatY(label)}
209
+ </text>
210
+ ))}
211
+ {cells.map((cell) => {
212
+ const fraction = cell.value / maxValue;
213
+ const fill = heatColor(ramp, fraction);
214
+ const key = pairKey(cell.rowLabel, cell.colLabel);
215
+ const isPeak = highlightPeak && key === peakKey;
216
+ if (variant === "dot") {
217
+ return (
218
+ <circle
219
+ key={key}
220
+ cx={cellX(cell.colIndex) + CELL / 2}
221
+ cy={cellY(cell.rowIndex) + CELL / 2}
222
+ r={(CELL / 2) * (DOT_MIN + DOT_RANGE * fraction)}
223
+ fill={fill}
224
+ stroke={isPeak ? theme.foreground : undefined}
225
+ strokeWidth={isPeak ? 1.4 : undefined}
226
+ />
227
+ );
228
+ }
229
+ return (
230
+ <rect
231
+ key={key}
232
+ x={cellX(cell.colIndex)}
233
+ y={cellY(cell.rowIndex)}
234
+ width={CELL}
235
+ height={CELL}
236
+ rx={2.5}
237
+ fill={fill}
238
+ stroke={isPeak ? theme.foreground : undefined}
239
+ strokeWidth={isPeak ? 1.4 : undefined}
240
+ />
241
+ );
242
+ })}
243
+ {/* Transparent hit layer over the full pitch so every cell — and the gaps
244
+ between dots — registers hover uniformly. */}
245
+ {cells.map((cell) => (
246
+ // biome-ignore lint/a11y/noStaticElementInteractions: decorative hover tooltip; all values are visible on the cells
247
+ <rect
248
+ key={`hit-${pairKey(cell.rowLabel, cell.colLabel)}`}
249
+ x={cellX(cell.colIndex)}
250
+ y={cellY(cell.rowIndex)}
251
+ width={CELL + GAP}
252
+ height={CELL + GAP}
253
+ fill="transparent"
254
+ onMouseMove={(event) =>
255
+ setHovered({
256
+ x: event.clientX,
257
+ y: event.clientY,
258
+ rowLabel: cell.rowLabel,
259
+ colLabel: cell.colLabel,
260
+ value: cell.value,
261
+ record: cell.record,
262
+ })
263
+ }
264
+ />
265
+ ))}
266
+ </svg>
267
+ </div>
268
+
269
+ {mounted &&
270
+ hovered &&
271
+ createPortal(
272
+ <div
273
+ className="pointer-events-none fixed z-50 min-w-[130px] rounded-lg border border-border bg-popover px-3 py-2.5 text-popover-foreground shadow-lg"
274
+ style={{ left: tooltipLeft, top: tooltipTop }}
275
+ >
276
+ <p className="mb-1.5 font-mono text-[10px] text-quaternary-foreground uppercase tracking-wider">
277
+ {formatY(hovered.rowLabel)} · {formatX(hovered.colLabel)}
278
+ </p>
279
+ {tooltipMetrics && tooltipMetrics.length > 0 ? (
280
+ <div className="flex flex-col gap-1">
281
+ {tooltipMetrics.map((metric) => {
282
+ const raw = hovered.record ? Number(hovered.record[metric.key]) || 0 : 0;
283
+ const isActive = metric.key === dataKey;
284
+ return (
285
+ <div key={metric.key} className="flex items-center justify-between gap-4 text-text-xs">
286
+ <span className="inline-flex items-center gap-2 text-muted-foreground">
287
+ <span
288
+ aria-hidden
289
+ className="size-2 shrink-0 rounded-[2px]"
290
+ style={{
291
+ background: isActive ? heatColor(ramp, hovered.value / maxValue) : theme.mutedForeground,
292
+ opacity: isActive ? 1 : 0.35,
293
+ }}
294
+ />
295
+ {metric.label}
296
+ </span>
297
+ <span
298
+ className={cn(
299
+ "font-mono tabular-nums",
300
+ isActive ? "font-semibold text-foreground" : "text-muted-foreground",
301
+ )}
302
+ >
303
+ {(metric.format ?? valueFormatter)(raw)}
304
+ </span>
305
+ </div>
306
+ );
307
+ })}
308
+ </div>
309
+ ) : (
310
+ <div className="flex items-center justify-between gap-4 text-text-xs">
311
+ <span className="inline-flex items-center gap-2 text-muted-foreground">
312
+ <span
313
+ aria-hidden
314
+ className="size-2 shrink-0 rounded-[2px]"
315
+ style={{ background: heatColor(ramp, hovered.value / maxValue) }}
316
+ />
317
+ activity
318
+ </span>
319
+ <span className="font-mono font-semibold tabular-nums text-foreground">
320
+ {valueFormatter(hovered.value)}
321
+ </span>
322
+ </div>
323
+ )}
324
+ </div>,
325
+ document.body,
326
+ )}
327
+ </div>
328
+ );
329
+ }
330
+
331
+ export { HeatmapChart };
@@ -0,0 +1,277 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ CartesianGrid,
6
+ LabelList,
7
+ Line,
8
+ LineChart as RechartsLineChart,
9
+ ReferenceArea,
10
+ ReferenceDot,
11
+ ReferenceLine,
12
+ ResponsiveContainer,
13
+ Tooltip,
14
+ XAxis,
15
+ YAxis,
16
+ } from "recharts";
17
+
18
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
19
+ import { type ChartSeries, makeXAxisTick, resolveSeries } from "../lib/chart";
20
+ import type { ChartPaletteName } from "../lib/chart-palette";
21
+ import { cn } from "../lib/cn";
22
+ import type { ChartMarker } from "./area-chart";
23
+ import { useChartContext } from "./chart-container";
24
+ import { ChartLegend } from "./chart-legend";
25
+ import { ChartTooltipContent } from "./chart-tooltip";
26
+
27
+ const CURVE_TYPE = { monotone: "monotone", linear: "linear", step: "stepAfter" } as const;
28
+
29
+ export interface LineChartProps {
30
+ data: ReadonlyArray<Record<string, string | number | null | undefined>>;
31
+ index: string;
32
+ series: ChartSeries[];
33
+ curve?: keyof typeof CURVE_TYPE;
34
+ legend?: boolean;
35
+ legendAlign?: "left" | "center" | "right";
36
+ valueFlags?: boolean;
37
+ dots?: boolean;
38
+ height?: number;
39
+ yAxisWidth?: number;
40
+ palette?: ChartPaletteName;
41
+ referenceLine?: { y: number; label?: string; band?: boolean };
42
+ markers?: ChartMarker[];
43
+ lastValueLabel?: boolean;
44
+ loading?: boolean;
45
+ valueFormatter?: (value: number) => string;
46
+ labelFormatter?: (label: string | number) => string;
47
+ className?: string;
48
+ }
49
+
50
+ function LineChart({
51
+ data,
52
+ index,
53
+ series,
54
+ curve = "monotone",
55
+ legend = false,
56
+ legendAlign = "left",
57
+ valueFlags = false,
58
+ dots = false,
59
+ height = 200,
60
+ yAxisWidth = 48,
61
+ palette,
62
+ referenceLine,
63
+ markers,
64
+ lastValueLabel = false,
65
+ loading = false,
66
+ valueFormatter = (value) => value.toLocaleString("en-US"),
67
+ labelFormatter,
68
+ className,
69
+ }: LineChartProps) {
70
+ const { palette: paletteColors, theme } = useChartContext(palette);
71
+ const reducedMotion = useReducedMotion();
72
+ const animated = !reducedMotion;
73
+
74
+ const resolved = resolveSeries(series, paletteColors, theme);
75
+
76
+ const numericMax = React.useMemo(() => {
77
+ let max = 0;
78
+ for (const row of data) {
79
+ for (const entry of series) {
80
+ const value = Number(row[entry.key]);
81
+ if (Number.isFinite(value) && value > max) {
82
+ max = value;
83
+ }
84
+ }
85
+ }
86
+ return max;
87
+ }, [data, series]);
88
+
89
+ const curveType = CURVE_TYPE[curve];
90
+ const margin = { top: markers?.length ? 18 : 8, right: lastValueLabel ? 56 : 8, bottom: 2, left: 0 };
91
+
92
+ const axis = {
93
+ stroke: theme.border,
94
+ tick: { fill: theme.axisForeground, fontSize: 10, fontFamily: theme.fontMono },
95
+ tickLine: false as const,
96
+ axisLine: { stroke: theme.border, strokeOpacity: 0.6 },
97
+ };
98
+
99
+ const legendItems = resolved.map((entry) => ({ name: entry.name, color: entry.color, dashed: entry.dashed }));
100
+
101
+ const activeDotFor = (entry: (typeof resolved)[number]) =>
102
+ valueFlags
103
+ ? (dotProps: { cx?: number; cy?: number; value?: number | string }) => {
104
+ if (dotProps.cx == null || dotProps.cy == null) {
105
+ return <g />;
106
+ }
107
+ return (
108
+ <g>
109
+ <circle
110
+ cx={dotProps.cx}
111
+ cy={dotProps.cy}
112
+ r={3.5}
113
+ fill={entry.color}
114
+ stroke={theme.card}
115
+ strokeWidth={2}
116
+ />
117
+ <text
118
+ x={dotProps.cx}
119
+ y={dotProps.cy - 8}
120
+ textAnchor="middle"
121
+ fill={entry.color}
122
+ fontFamily={theme.fontMono}
123
+ fontSize={10}
124
+ style={{ fontVariantNumeric: "tabular-nums" }}
125
+ >
126
+ {valueFormatter(Number(dotProps.value ?? 0))}
127
+ </text>
128
+ </g>
129
+ );
130
+ }
131
+ : { r: 3.5, fill: entry.color, stroke: theme.card, strokeWidth: 2 };
132
+
133
+ const renderLastLabel =
134
+ (color: string) =>
135
+ (props: {
136
+ x?: string | number;
137
+ y?: string | number;
138
+ value?: string | number | boolean | Array<string | number | boolean> | null;
139
+ index?: number;
140
+ }) => {
141
+ if (props.index !== data.length - 1 || props.x == null || props.y == null) {
142
+ return null;
143
+ }
144
+ return (
145
+ <text
146
+ x={Number(props.x) + 6}
147
+ y={Number(props.y)}
148
+ dy={3}
149
+ fill={color}
150
+ fontFamily={theme.fontMono}
151
+ fontSize={10}
152
+ textAnchor="start"
153
+ style={{ fontVariantNumeric: "tabular-nums" }}
154
+ >
155
+ {valueFormatter(Number(props.value ?? 0))}
156
+ </text>
157
+ );
158
+ };
159
+
160
+ const isEmpty = data.length === 0 || resolved.length === 0;
161
+
162
+ return (
163
+ <div data-slot="line-chart" className={cn("flex w-full flex-col gap-3", className)}>
164
+ <div className="w-full" style={{ height }}>
165
+ {loading ? (
166
+ <div className="flex h-full items-center justify-center gap-2.5 font-mono text-quaternary-foreground text-text-xs">
167
+ <span className="size-4 animate-spin rounded-full border-2 border-border border-t-foreground" />
168
+ loading…
169
+ </div>
170
+ ) : isEmpty ? (
171
+ <div className="flex h-full items-center justify-center rounded-lg border border-border border-dashed font-mono text-quaternary-foreground text-text-xs">
172
+ no data in range
173
+ </div>
174
+ ) : (
175
+ <ResponsiveContainer width="100%" height="100%" initialDimension={{ width: 0, height }}>
176
+ <RechartsLineChart data={data as Record<string, string | number>[]} margin={margin}>
177
+ <CartesianGrid vertical={false} stroke={theme.grid} strokeDasharray="2 4" />
178
+ <XAxis
179
+ dataKey={index}
180
+ {...axis}
181
+ tick={makeXAxisTick(theme)}
182
+ interval="preserveStartEnd"
183
+ minTickGap={44}
184
+ />
185
+ <YAxis
186
+ {...axis}
187
+ width={yAxisWidth}
188
+ domain={["auto", "auto"]}
189
+ tickFormatter={(value: number) => valueFormatter(value)}
190
+ />
191
+ <Tooltip
192
+ offset={12}
193
+ allowEscapeViewBox={{ x: false, y: false }}
194
+ cursor={{ stroke: theme.axisForeground, strokeWidth: 1, strokeDasharray: "3 3" }}
195
+ content={<ChartTooltipContent valueFormatter={valueFormatter} labelFormatter={labelFormatter} />}
196
+ />
197
+ {referenceLine?.band && (
198
+ <ReferenceArea
199
+ y1={referenceLine.y}
200
+ y2={numericMax}
201
+ fill={theme.warning}
202
+ fillOpacity={0.06}
203
+ ifOverflow="extendDomain"
204
+ />
205
+ )}
206
+ {referenceLine && (
207
+ <ReferenceLine
208
+ y={referenceLine.y}
209
+ stroke={theme.warning}
210
+ strokeDasharray="4 4"
211
+ strokeOpacity={0.6}
212
+ label={
213
+ referenceLine.label
214
+ ? {
215
+ value: referenceLine.label,
216
+ fill: theme.warning,
217
+ fontSize: 9,
218
+ fontFamily: theme.fontMono,
219
+ position: "insideBottomRight",
220
+ }
221
+ : undefined
222
+ }
223
+ />
224
+ )}
225
+
226
+ {resolved.map((entry) => (
227
+ <Line
228
+ key={entry.key}
229
+ type={curveType}
230
+ dataKey={entry.key}
231
+ name={entry.name}
232
+ stroke={entry.color}
233
+ strokeWidth={entry.dashed ? 2 : 1.8}
234
+ strokeDasharray={entry.dashed ? "5 3" : undefined}
235
+ dot={dots ? { r: 2.5, fill: entry.color, strokeWidth: 0 } : false}
236
+ activeDot={activeDotFor(entry)}
237
+ isAnimationActive={animated}
238
+ animationDuration={650}
239
+ animationEasing="ease-out"
240
+ >
241
+ {lastValueLabel && <LabelList dataKey={entry.key} content={renderLastLabel(entry.color)} />}
242
+ </Line>
243
+ ))}
244
+
245
+ {markers?.map((marker) => (
246
+ <ReferenceDot
247
+ key={`${marker.x}-${marker.y}`}
248
+ x={marker.x}
249
+ y={marker.y}
250
+ r={3.5}
251
+ fill={marker.color ?? theme.foreground}
252
+ stroke={theme.card}
253
+ strokeWidth={2}
254
+ label={
255
+ marker.label
256
+ ? {
257
+ value: marker.label,
258
+ fill: marker.color ?? theme.foreground,
259
+ fontSize: 9,
260
+ fontFamily: theme.fontMono,
261
+ position: "top",
262
+ }
263
+ : undefined
264
+ }
265
+ />
266
+ ))}
267
+ </RechartsLineChart>
268
+ </ResponsiveContainer>
269
+ )}
270
+ </div>
271
+
272
+ {legend && !isEmpty && <ChartLegend items={legendItems} align={legendAlign} insetLeft={yAxisWidth} />}
273
+ </div>
274
+ );
275
+ }
276
+
277
+ export { LineChart };