@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,95 @@
1
+ const CHART_PALETTES = {
2
+ magenta: [
3
+ "#e90060",
4
+ "#ff7eb6",
5
+ "#9b5de5",
6
+ "#5b8def",
7
+ "#36c5f0",
8
+ "#6eece7",
9
+ "#d98a3d",
10
+ "#2bb6a3"
11
+ ],
12
+ cyan: [
13
+ "#17b8cf",
14
+ "#41ddc9",
15
+ "#3f8ff0",
16
+ "#8b6cf0",
17
+ "#c46bf0",
18
+ "#ff7eb6",
19
+ "#e90060",
20
+ "#c98be0"
21
+ ]
22
+ };
23
+ const heatRampMagenta = (empty) => [
24
+ empty,
25
+ "#5b0a31",
26
+ "#a3034a",
27
+ "#e90060",
28
+ "#ff7eb6"
29
+ ];
30
+ const heatRampMint = (empty) => [
31
+ empty,
32
+ "#0c4a52",
33
+ "#17b8cf",
34
+ "#41ddc9",
35
+ "#6eece7"
36
+ ];
37
+ const HEAT_EMPTY = {
38
+ light: "#eef3f3",
39
+ dark: "#102222"
40
+ };
41
+ const HEAT_RAMPS = {
42
+ magenta: heatRampMagenta,
43
+ cyan: heatRampMint
44
+ };
45
+ const heatRamp = (palette, empty) => HEAT_RAMPS[palette](empty);
46
+ const hexToRgb = (hex) => {
47
+ const value = Number.parseInt(hex.slice(1), 16);
48
+ return [
49
+ value >> 16 & 255,
50
+ value >> 8 & 255,
51
+ value & 255
52
+ ];
53
+ };
54
+ const luminance = (hex) => {
55
+ const linear = hexToRgb(hex).map((channel) => {
56
+ const normalized = channel / 255;
57
+ return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
58
+ });
59
+ return .2126 * linear[0] + .7152 * linear[1] + .0722 * linear[2];
60
+ };
61
+ const paletteColor = (palette, index) => {
62
+ return palette[(index % palette.length + palette.length) % palette.length];
63
+ };
64
+ const RAMP_ENDS = {
65
+ magenta: ["#e90060", "#ff7eb6"],
66
+ cyan: ["#17b8cf", "#6eece7"]
67
+ };
68
+ const mixHex = (from, to, fraction) => {
69
+ const [fromR, fromG, fromB] = hexToRgb(from);
70
+ const [toR, toG, toB] = hexToRgb(to);
71
+ const ratio = Math.min(1, Math.max(0, fraction));
72
+ const channel = (start, end) => Math.round(start + (end - start) * ratio);
73
+ return `#${[
74
+ channel(fromR, toR),
75
+ channel(fromG, toG),
76
+ channel(fromB, toB)
77
+ ].map((value) => value.toString(16).padStart(2, "0")).join("")}`;
78
+ };
79
+ const rampColor = (palette, fraction) => {
80
+ const [from, to] = RAMP_ENDS[palette];
81
+ return mixHex(from, to, fraction);
82
+ };
83
+ /**
84
+ * Interpolate continuously across a multi-stop heat ramp (e.g. `heatRampMagenta`),
85
+ * so a normalized 0..1 value reads as a smooth single-hue gradient rather than
86
+ * the five discrete bands.
87
+ */
88
+ const heatColor = (stops, fraction) => {
89
+ const clamped = Math.min(1, Math.max(0, fraction));
90
+ const segment = (stops.length - 1) * clamped;
91
+ const lowerIndex = Math.min(stops.length - 2, Math.floor(segment));
92
+ return mixHex(stops[lowerIndex], stops[lowerIndex + 1], segment - lowerIndex);
93
+ };
94
+ //#endregion
95
+ export { CHART_PALETTES, HEAT_EMPTY, heatColor, heatRamp, luminance, paletteColor, rampColor };
@@ -0,0 +1,14 @@
1
+ //#region src/lib/chart.d.ts
2
+ /**
3
+ * Declarative description of one plotted series. The same shape drives area,
4
+ * line and bar charts — what differs is how each chart renders it.
5
+ */
6
+ interface ChartSeries {
7
+ key: string;
8
+ name?: string;
9
+ color?: string;
10
+ semantic?: "error" | "warning" | "success";
11
+ dashed?: boolean;
12
+ }
13
+ //#endregion
14
+ export { ChartSeries };
@@ -0,0 +1,42 @@
1
+ import { luminance, paletteColor } from "./chart-palette.mjs";
2
+ import * as React$1 from "react";
3
+ //#region src/lib/chart.ts
4
+ const formatShare = (fraction) => `${(fraction * 100).toFixed(fraction >= .1 ? 0 : 1)}%`;
5
+ const semanticColor = (theme, semantic) => {
6
+ if (semantic === "error") return theme.destructive;
7
+ if (semantic === "warning") return theme.warning;
8
+ return theme.success;
9
+ };
10
+ /**
11
+ * Resolve each series to a concrete color and name. Color precedence:
12
+ * explicit `color` → `semantic` token → palette slot by declared index (so the
13
+ * lead series keeps the lead color even after the bands are reordered).
14
+ */
15
+ const resolveSeries = (series, palette, theme) => series.map((entry, index) => ({
16
+ ...entry,
17
+ name: entry.name ?? entry.key,
18
+ color: entry.color ?? (entry.semantic ? semanticColor(theme, entry.semantic) : paletteColor(palette, index))
19
+ }));
20
+ /**
21
+ * Stacked bands read cleanest as a vertical gradient: darkest at the baseline,
22
+ * lightest at the top edge. Sorting by luminance enforces that for any palette
23
+ * (this is what fixed the "muddy cyan" stack in the lab). Render order maps to
24
+ * stack order in Recharts — first entry sits at the bottom.
25
+ */
26
+ const orderByLuminance = (series) => [...series].sort((lower, upper) => luminance(lower.color) - luminance(upper.color));
27
+ const makeXAxisTick = (theme) => ({ x, y, payload, index, visibleTicksCount }) => {
28
+ const isFirst = index === 0;
29
+ const isLast = visibleTicksCount != null && index === visibleTicksCount - 1;
30
+ const anchor = isFirst ? "start" : isLast ? "end" : "middle";
31
+ return React$1.createElement("text", {
32
+ x: Number(x ?? 0),
33
+ y: Number(y ?? 0),
34
+ dy: 12,
35
+ textAnchor: anchor,
36
+ fill: theme.axisForeground,
37
+ fontFamily: theme.fontMono,
38
+ fontSize: 10
39
+ }, String(payload?.value ?? ""));
40
+ };
41
+ //#endregion
42
+ export { formatShare, makeXAxisTick, orderByLuminance, resolveSeries };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpic-ai/ui",
3
- "version": "0.0.0-dev.g19c2d9f",
3
+ "version": "0.0.0-dev.g1a5d5ed",
4
4
  "description": "Alpic design system — shared UI components",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,48 +23,49 @@
23
23
  "src"
24
24
  ],
25
25
  "peerDependencies": {
26
- "lucide-react": "^1.14.0",
27
- "react": "^19.2.6",
28
- "react-dom": "^19.2.6",
29
- "react-hook-form": "^7.75.0",
26
+ "lucide-react": "^1.21.0",
27
+ "react": "^19.2.7",
28
+ "react-dom": "^19.2.7",
29
+ "react-hook-form": "^7.80.0",
30
30
  "sonner": "^2.0.7",
31
- "tailwindcss": "^4.3.0",
31
+ "tailwindcss": "^4.3.1",
32
32
  "tw-animate-css": "^1.4.0"
33
33
  },
34
34
  "dependencies": {
35
- "@radix-ui/react-accordion": "^1.2.12",
36
- "@radix-ui/react-avatar": "^1.1.11",
37
- "@radix-ui/react-checkbox": "^1.3.3",
38
- "@radix-ui/react-collapsible": "^1.1.12",
39
- "@radix-ui/react-dialog": "^1.1.15",
40
- "@radix-ui/react-dropdown-menu": "^2.1.16",
41
- "@radix-ui/react-label": "^2.1.8",
42
- "@radix-ui/react-popover": "^1.1.15",
43
- "@radix-ui/react-radio-group": "^1.3.8",
44
- "@radix-ui/react-scroll-area": "^1.2.10",
45
- "@radix-ui/react-select": "^2.2.6",
46
- "@radix-ui/react-separator": "^1.1.8",
47
- "@radix-ui/react-slot": "^1.2.4",
48
- "@radix-ui/react-switch": "^1.2.6",
49
- "@radix-ui/react-tabs": "^1.1.13",
50
- "@radix-ui/react-toggle-group": "^1.1.11",
51
- "@radix-ui/react-tooltip": "^1.2.8",
35
+ "@radix-ui/react-accordion": "^1.2.14",
36
+ "@radix-ui/react-avatar": "^1.2.0",
37
+ "@radix-ui/react-checkbox": "^1.3.5",
38
+ "@radix-ui/react-collapsible": "^1.1.14",
39
+ "@radix-ui/react-dialog": "^1.1.17",
40
+ "@radix-ui/react-dropdown-menu": "^2.1.18",
41
+ "@radix-ui/react-label": "^2.1.10",
42
+ "@radix-ui/react-popover": "^1.1.17",
43
+ "@radix-ui/react-radio-group": "^1.4.1",
44
+ "@radix-ui/react-scroll-area": "^1.2.12",
45
+ "@radix-ui/react-select": "^2.3.1",
46
+ "@radix-ui/react-separator": "^1.1.10",
47
+ "@radix-ui/react-slot": "^1.3.0",
48
+ "@radix-ui/react-switch": "^1.3.1",
49
+ "@radix-ui/react-tabs": "^1.1.15",
50
+ "@radix-ui/react-toggle-group": "^1.1.13",
51
+ "@radix-ui/react-tooltip": "^1.2.10",
52
52
  "class-variance-authority": "^0.7.1",
53
53
  "clsx": "^2.1.1",
54
54
  "cmdk": "^1.1.1",
55
+ "recharts": "^3.8.1",
55
56
  "tailwind-merge": "^3.6.0"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@ladle/react": "^5.1.1",
59
- "@tailwindcss/postcss": "^4.3.0",
60
- "@types/react": "19.2.14",
60
+ "@tailwindcss/postcss": "^4.3.1",
61
+ "@types/react": "19.2.17",
61
62
  "@types/react-dom": "19.2.3",
62
- "lucide-react": "^1.14.0",
63
- "react-hook-form": "^7.75.0",
63
+ "lucide-react": "^1.21.0",
64
+ "react-hook-form": "^7.80.0",
64
65
  "shx": "^0.4.0",
65
66
  "sonner": "^2.0.7",
66
- "tailwindcss": "^4.3.0",
67
- "tsdown": "^0.22.0",
67
+ "tailwindcss": "^4.3.1",
68
+ "tsdown": "^0.22.3",
68
69
  "tw-animate-css": "^1.4.0",
69
70
  "typescript": "^6.0.3"
70
71
  },
@@ -0,0 +1,347 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ Area,
6
+ CartesianGrid,
7
+ LabelList,
8
+ AreaChart as RechartsAreaChart,
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, orderByLuminance, resolveSeries } from "../lib/chart";
20
+ import type { ChartPaletteName } from "../lib/chart-palette";
21
+ import { cn } from "../lib/cn";
22
+ import { useChartContext } from "./chart-container";
23
+ import { ChartLegend } from "./chart-legend";
24
+ import { ChartTooltipContent } from "./chart-tooltip";
25
+
26
+ const CURVE_TYPE = { monotone: "monotone", linear: "linear", step: "stepAfter" } as const;
27
+
28
+ export interface ChartMarker {
29
+ x: string | number;
30
+ y: number;
31
+ label?: string;
32
+ color?: string;
33
+ }
34
+
35
+ export interface AreaChartProps {
36
+ data: ReadonlyArray<Record<string, string | number | null | undefined>>;
37
+ index: string;
38
+ series: ChartSeries[];
39
+ variant?: "stacked" | "grouped" | "expand";
40
+ curve?: keyof typeof CURVE_TYPE;
41
+ legend?: boolean;
42
+ legendAlign?: "left" | "center" | "right";
43
+ valueFlags?: boolean;
44
+ height?: number;
45
+ yAxisWidth?: number;
46
+ palette?: ChartPaletteName;
47
+ referenceLine?: { y: number; label?: string; band?: boolean };
48
+ markers?: ChartMarker[];
49
+ lastValueLabel?: boolean;
50
+ texture?: boolean;
51
+ loading?: boolean;
52
+ valueFormatter?: (value: number) => string;
53
+ labelFormatter?: (label: string | number) => string;
54
+ className?: string;
55
+ }
56
+
57
+ function AreaChart({
58
+ data,
59
+ index,
60
+ series,
61
+ variant = "stacked",
62
+ curve = "monotone",
63
+ legend = false,
64
+ legendAlign = "left",
65
+ valueFlags = false,
66
+ height = 200,
67
+ yAxisWidth = 48,
68
+ palette,
69
+ referenceLine,
70
+ markers,
71
+ lastValueLabel = false,
72
+ texture = false,
73
+ loading = false,
74
+ valueFormatter = (value) => value.toLocaleString("en-US"),
75
+ labelFormatter,
76
+ className,
77
+ }: AreaChartProps) {
78
+ const { palette: paletteColors, theme } = useChartContext(palette);
79
+ const reactId = React.useId().replace(/:/g, "");
80
+ const reducedMotion = useReducedMotion();
81
+ const animated = !reducedMotion;
82
+
83
+ const resolved = resolveSeries(series, paletteColors, theme);
84
+ const stacked = variant === "stacked" || variant === "expand";
85
+ const rendered = stacked ? orderByLuminance(resolved) : resolved;
86
+
87
+ const strokeOnly = variant === "grouped" && rendered.length > 1;
88
+ const filled = !strokeOnly;
89
+ const lead = resolved[0];
90
+ const withTotal = stacked && rendered.length > 1;
91
+
92
+ // Stacked bands must reach the stack height (sum per x-point), not the tallest
93
+ // single series, or the reference band stops short of the chart top.
94
+ const numericMax = React.useMemo(() => {
95
+ let max = 0;
96
+ for (const row of data) {
97
+ let rowTotal = 0;
98
+ for (const entry of series) {
99
+ const value = Number(row[entry.key]);
100
+ if (Number.isFinite(value)) {
101
+ rowTotal += value;
102
+ if (!stacked && value > max) {
103
+ max = value;
104
+ }
105
+ }
106
+ }
107
+ if (stacked && rowTotal > max) {
108
+ max = rowTotal;
109
+ }
110
+ }
111
+ return max;
112
+ }, [data, series, stacked]);
113
+
114
+ const curveType = CURVE_TYPE[curve];
115
+ const margin = { top: markers?.length ? 18 : 8, right: lastValueLabel ? 56 : 8, bottom: 2, left: 0 };
116
+
117
+ const axis = {
118
+ stroke: theme.border,
119
+ tick: { fill: theme.axisForeground, fontSize: 10, fontFamily: theme.fontMono },
120
+ tickLine: false as const,
121
+ axisLine: { stroke: theme.border, strokeOpacity: 0.6 },
122
+ };
123
+
124
+ const legendItems = resolved.map((entry) => ({ name: entry.name, color: entry.color, dashed: entry.dashed }));
125
+
126
+ const activeDotFor = (entry: (typeof rendered)[number]) =>
127
+ valueFlags
128
+ ? (dotProps: { cx?: number; cy?: number; value?: number | string }) => {
129
+ if (dotProps.cx == null || dotProps.cy == null) {
130
+ return <g />;
131
+ }
132
+ return (
133
+ <g>
134
+ <circle
135
+ cx={dotProps.cx}
136
+ cy={dotProps.cy}
137
+ r={3.5}
138
+ fill={entry.color}
139
+ stroke={theme.card}
140
+ strokeWidth={2}
141
+ />
142
+ <text
143
+ x={dotProps.cx}
144
+ y={dotProps.cy - 8}
145
+ textAnchor="middle"
146
+ fill={entry.color}
147
+ fontFamily={theme.fontMono}
148
+ fontSize={10}
149
+ style={{ fontVariantNumeric: "tabular-nums" }}
150
+ >
151
+ {valueFormatter(Number(dotProps.value ?? 0))}
152
+ </text>
153
+ </g>
154
+ );
155
+ }
156
+ : { r: 3.5, fill: entry.color, stroke: theme.card, strokeWidth: 2 };
157
+
158
+ const fillFor = (entry: (typeof rendered)[number], slot: number) => {
159
+ if (!filled) {
160
+ return "none";
161
+ }
162
+ if (texture && lead && entry.key === lead.key) {
163
+ return `url(#hatch-${reactId})`;
164
+ }
165
+ return `url(#area-${reactId}-${slot})`;
166
+ };
167
+
168
+ const renderLastLabel =
169
+ (color: string) =>
170
+ (props: {
171
+ x?: string | number;
172
+ y?: string | number;
173
+ value?: string | number | boolean | Array<string | number | boolean> | null;
174
+ index?: number;
175
+ }) => {
176
+ if (props.index !== data.length - 1 || props.x == null || props.y == null) {
177
+ return null;
178
+ }
179
+ return (
180
+ <text
181
+ x={Number(props.x) + 6}
182
+ y={Number(props.y)}
183
+ dy={3}
184
+ fill={color}
185
+ fontFamily={theme.fontMono}
186
+ fontSize={10}
187
+ textAnchor="start"
188
+ style={{ fontVariantNumeric: "tabular-nums" }}
189
+ >
190
+ {valueFormatter(Number(props.value ?? 0))}
191
+ </text>
192
+ );
193
+ };
194
+
195
+ const isEmpty = data.length === 0 || rendered.length === 0;
196
+
197
+ return (
198
+ <div data-slot="area-chart" className={cn("flex w-full flex-col gap-3", className)}>
199
+ <div className="w-full" style={{ height }}>
200
+ {loading ? (
201
+ <div className="flex h-full items-center justify-center gap-2.5 font-mono text-quaternary-foreground text-text-xs">
202
+ <span className="size-4 animate-spin rounded-full border-2 border-border border-t-foreground" />
203
+ loading…
204
+ </div>
205
+ ) : isEmpty ? (
206
+ <div className="flex h-full items-center justify-center rounded-lg border border-border border-dashed font-mono text-quaternary-foreground text-text-xs">
207
+ no data in range
208
+ </div>
209
+ ) : (
210
+ <ResponsiveContainer width="100%" height="100%" initialDimension={{ width: 0, height }}>
211
+ <RechartsAreaChart
212
+ data={data as Record<string, string | number>[]}
213
+ stackOffset={variant === "expand" ? "expand" : "none"}
214
+ margin={margin}
215
+ >
216
+ <defs>
217
+ {filled &&
218
+ rendered.map((entry, slot) => (
219
+ <linearGradient key={entry.key} id={`area-${reactId}-${slot}`} x1="0" y1="0" x2="0" y2="1">
220
+ <stop offset="0%" stopColor={entry.color} stopOpacity={stacked ? 0.78 : 0.5} />
221
+ <stop offset="100%" stopColor={entry.color} stopOpacity={stacked ? 0.32 : 0.04} />
222
+ </linearGradient>
223
+ ))}
224
+ {texture && filled && lead && (
225
+ <pattern
226
+ id={`hatch-${reactId}`}
227
+ patternUnits="userSpaceOnUse"
228
+ width={6}
229
+ height={6}
230
+ patternTransform="rotate(45)"
231
+ >
232
+ <rect width={6} height={6} fill={lead.color} fillOpacity={0.18} />
233
+ <line x1={0} y1={0} x2={0} y2={6} stroke={lead.color} strokeWidth={1.2} strokeOpacity={0.6} />
234
+ </pattern>
235
+ )}
236
+ </defs>
237
+
238
+ <CartesianGrid vertical={false} stroke={theme.grid} strokeDasharray="2 4" />
239
+ <XAxis
240
+ dataKey={index}
241
+ {...axis}
242
+ tick={makeXAxisTick(theme)}
243
+ interval="preserveStartEnd"
244
+ minTickGap={44}
245
+ />
246
+ <YAxis
247
+ {...axis}
248
+ width={yAxisWidth}
249
+ tickFormatter={(value: number) =>
250
+ variant === "expand" ? `${Math.round(value * 100)}%` : valueFormatter(value)
251
+ }
252
+ />
253
+ <Tooltip
254
+ offset={12}
255
+ allowEscapeViewBox={{ x: false, y: false }}
256
+ cursor={{ stroke: theme.axisForeground, strokeWidth: 1, strokeDasharray: "3 3" }}
257
+ content={
258
+ <ChartTooltipContent
259
+ valueFormatter={valueFormatter}
260
+ labelFormatter={labelFormatter}
261
+ showTotal={withTotal}
262
+ />
263
+ }
264
+ />
265
+ {referenceLine?.band && (
266
+ <ReferenceArea
267
+ y1={referenceLine.y}
268
+ y2={numericMax}
269
+ fill={theme.warning}
270
+ fillOpacity={0.06}
271
+ ifOverflow="extendDomain"
272
+ />
273
+ )}
274
+ {referenceLine && (
275
+ <ReferenceLine
276
+ y={referenceLine.y}
277
+ stroke={theme.warning}
278
+ strokeDasharray="4 4"
279
+ strokeOpacity={0.6}
280
+ label={
281
+ referenceLine.label
282
+ ? {
283
+ value: referenceLine.label,
284
+ fill: theme.warning,
285
+ fontSize: 9,
286
+ fontFamily: theme.fontMono,
287
+ position: "insideBottomRight",
288
+ }
289
+ : undefined
290
+ }
291
+ />
292
+ )}
293
+
294
+ {rendered.map((entry, slot) => (
295
+ <Area
296
+ key={entry.key}
297
+ type={curveType}
298
+ dataKey={entry.key}
299
+ name={entry.name}
300
+ stackId={stacked ? "stack" : undefined}
301
+ stroke={entry.color}
302
+ strokeWidth={entry.dashed ? 2 : 1.6}
303
+ strokeDasharray={entry.dashed ? "5 3" : undefined}
304
+ fill={fillFor(entry, slot)}
305
+ dot={false}
306
+ activeDot={activeDotFor(entry)}
307
+ isAnimationActive={animated}
308
+ animationDuration={650}
309
+ animationEasing="ease-out"
310
+ >
311
+ {lastValueLabel && <LabelList dataKey={entry.key} content={renderLastLabel(entry.color)} />}
312
+ </Area>
313
+ ))}
314
+
315
+ {markers?.map((marker) => (
316
+ <ReferenceDot
317
+ key={`${marker.x}-${marker.y}`}
318
+ x={marker.x}
319
+ y={marker.y}
320
+ r={3.5}
321
+ fill={marker.color ?? theme.foreground}
322
+ stroke={theme.card}
323
+ strokeWidth={2}
324
+ label={
325
+ marker.label
326
+ ? {
327
+ value: marker.label,
328
+ fill: marker.color ?? theme.foreground,
329
+ fontSize: 9,
330
+ fontFamily: theme.fontMono,
331
+ position: "top",
332
+ }
333
+ : undefined
334
+ }
335
+ />
336
+ ))}
337
+ </RechartsAreaChart>
338
+ </ResponsiveContainer>
339
+ )}
340
+ </div>
341
+
342
+ {legend && !isEmpty && <ChartLegend items={legendItems} align={legendAlign} insetLeft={yAxisWidth} />}
343
+ </div>
344
+ );
345
+ }
346
+
347
+ export { AreaChart };