@alpic-ai/ui 0.0.0-dev.g1d699ea → 0.0.0-dev.g1d80e15

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 (112) hide show
  1. package/dist/components/accordion-card.d.mts +5 -5
  2. package/dist/components/accordion.d.mts +5 -5
  3. package/dist/components/alert.d.mts +8 -8
  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 -1
  7. package/dist/components/avatar.d.mts +7 -7
  8. package/dist/components/badge.d.mts +1 -1
  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 -10
  14. package/dist/components/button.d.mts +5 -5
  15. package/dist/components/card.d.mts +9 -9
  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 -2
  25. package/dist/components/collapsible.d.mts +4 -4
  26. package/dist/components/combobox.d.mts +10 -10
  27. package/dist/components/command.d.mts +9 -9
  28. package/dist/components/copyable.d.mts +2 -2
  29. package/dist/components/description-list.d.mts +5 -5
  30. package/dist/components/dialog.d.mts +13 -13
  31. package/dist/components/donut-chart.d.mts +46 -0
  32. package/dist/components/donut-chart.mjs +189 -0
  33. package/dist/components/dropdown-menu.d.mts +17 -17
  34. package/dist/components/form.d.mts +18 -18
  35. package/dist/components/form.mjs +7 -7
  36. package/dist/components/github-button.d.mts +1 -1
  37. package/dist/components/heatmap-chart.d.mts +48 -0
  38. package/dist/components/heatmap-chart.mjs +229 -0
  39. package/dist/components/input-group.d.mts +4 -4
  40. package/dist/components/input.d.mts +4 -4
  41. package/dist/components/input.mjs +2 -2
  42. package/dist/components/label.d.mts +2 -2
  43. package/dist/components/line-chart.d.mts +57 -0
  44. package/dist/components/line-chart.mjs +218 -0
  45. package/dist/components/page-loader.d.mts +1 -1
  46. package/dist/components/pagination.d.mts +3 -3
  47. package/dist/components/popover.d.mts +5 -5
  48. package/dist/components/radio-group.d.mts +3 -3
  49. package/dist/components/scroll-area.d.mts +3 -3
  50. package/dist/components/select.d.mts +9 -9
  51. package/dist/components/separator.d.mts +2 -2
  52. package/dist/components/sheet.d.mts +11 -11
  53. package/dist/components/shimmer-text.d.mts +3 -1
  54. package/dist/components/sidebar.d.mts +33 -33
  55. package/dist/components/sidebar.mjs +10 -10
  56. package/dist/components/skeleton.d.mts +1 -1
  57. package/dist/components/sonner.d.mts +5 -5
  58. package/dist/components/spinner.d.mts +2 -2
  59. package/dist/components/stat.d.mts +32 -0
  60. package/dist/components/stat.mjs +117 -0
  61. package/dist/components/status-dot.d.mts +1 -1
  62. package/dist/components/switch.d.mts +2 -2
  63. package/dist/components/table.d.mts +10 -10
  64. package/dist/components/tabs.d.mts +10 -10
  65. package/dist/components/tag.d.mts +3 -3
  66. package/dist/components/task-progress.d.mts +1 -1
  67. package/dist/components/textarea.d.mts +3 -3
  68. package/dist/components/textarea.mjs +3 -3
  69. package/dist/components/toggle-group.d.mts +3 -3
  70. package/dist/components/toggle-group.mjs +3 -3
  71. package/dist/components/tooltip.d.mts +5 -5
  72. package/dist/components/typography.d.mts +4 -4
  73. package/dist/components/wizard.d.mts +4 -22
  74. package/dist/components/wizard.mjs +1 -19
  75. package/dist/hooks/use-chart-theme.d.mts +18 -0
  76. package/dist/hooks/use-chart-theme.mjs +57 -0
  77. package/dist/hooks/use-mobile.mjs +3 -3
  78. package/dist/hooks/use-reduced-motion.d.mts +4 -0
  79. package/dist/hooks/use-reduced-motion.mjs +16 -0
  80. package/dist/lib/chart-palette.d.mts +4 -0
  81. package/dist/lib/chart-palette.mjs +95 -0
  82. package/dist/lib/chart.d.mts +14 -0
  83. package/dist/lib/chart.mjs +42 -0
  84. package/package.json +30 -29
  85. package/src/components/area-chart.tsx +347 -0
  86. package/src/components/bar-chart.tsx +317 -0
  87. package/src/components/bar-list.tsx +166 -0
  88. package/src/components/chart-card.tsx +65 -0
  89. package/src/components/chart-container.tsx +51 -0
  90. package/src/components/chart-legend.tsx +49 -0
  91. package/src/components/chart-tooltip.tsx +93 -0
  92. package/src/components/donut-chart.tsx +217 -0
  93. package/src/components/form.tsx +1 -1
  94. package/src/components/heatmap-chart.tsx +331 -0
  95. package/src/components/line-chart.tsx +277 -0
  96. package/src/components/stat.tsx +113 -0
  97. package/src/components/textarea.tsx +1 -1
  98. package/src/components/wizard.tsx +1 -35
  99. package/src/hooks/use-chart-theme.ts +75 -0
  100. package/src/hooks/use-reduced-motion.ts +17 -0
  101. package/src/lib/chart-palette.ts +110 -0
  102. package/src/lib/chart.ts +90 -0
  103. package/src/stories/area-chart.stories.tsx +198 -0
  104. package/src/stories/bar-chart.stories.tsx +167 -0
  105. package/src/stories/bar-list.stories.tsx +83 -0
  106. package/src/stories/donut-chart.stories.tsx +110 -0
  107. package/src/stories/heatmap-chart.stories.tsx +105 -0
  108. package/src/stories/line-chart.stories.tsx +144 -0
  109. package/src/stories/stat.stories.tsx +64 -0
  110. package/src/stories/textarea.stories.tsx +7 -0
  111. package/src/stories/wizard.stories.tsx +23 -5
  112. package/src/styles/tokens.css +18 -0
@@ -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 };
@@ -0,0 +1,317 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ Bar,
6
+ CartesianGrid,
7
+ LabelList,
8
+ BarChart as RechartsBarChart,
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 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 BAR_RADIUS = 4;
28
+ const MAX_BAR_SIZE = 48;
29
+
30
+ export interface BarChartProps {
31
+ data: ReadonlyArray<Record<string, string | number | null | undefined>>;
32
+ index: string;
33
+ series: ChartSeries[];
34
+ variant?: "stacked" | "grouped" | "expand";
35
+ legend?: boolean;
36
+ legendAlign?: "left" | "center" | "right";
37
+ valueLabels?: boolean;
38
+ height?: number;
39
+ yAxisWidth?: number;
40
+ palette?: ChartPaletteName;
41
+ referenceLine?: { y: number; label?: string; band?: boolean };
42
+ markers?: ChartMarker[];
43
+ texture?: boolean;
44
+ loading?: boolean;
45
+ valueFormatter?: (value: number) => string;
46
+ labelFormatter?: (label: string | number) => string;
47
+ className?: string;
48
+ }
49
+
50
+ function BarChart({
51
+ data,
52
+ index,
53
+ series,
54
+ variant = "stacked",
55
+ legend = false,
56
+ legendAlign = "left",
57
+ valueLabels = false,
58
+ height = 200,
59
+ yAxisWidth = 48,
60
+ palette,
61
+ referenceLine,
62
+ markers,
63
+ texture = false,
64
+ loading = false,
65
+ valueFormatter = (value) => value.toLocaleString("en-US"),
66
+ labelFormatter,
67
+ className,
68
+ }: BarChartProps) {
69
+ const { palette: paletteColors, theme } = useChartContext(palette);
70
+ const reactId = React.useId().replace(/:/g, "");
71
+ const reducedMotion = useReducedMotion();
72
+ const animated = !reducedMotion;
73
+
74
+ const resolved = resolveSeries(series, paletteColors, theme);
75
+ const stacked = variant === "stacked" || variant === "expand";
76
+ const rendered = stacked ? orderByLuminance(resolved) : resolved;
77
+ const lead = resolved[0];
78
+ const withTotal = stacked && rendered.length > 1;
79
+
80
+ // Stacked bars reach the stack height (sum per x-point), not the tallest single
81
+ // series, so the explicit YAxis domain must not clip a tall stack short.
82
+ const numericMax = React.useMemo(() => {
83
+ let max = 0;
84
+ for (const row of data) {
85
+ let rowTotal = 0;
86
+ for (const entry of series) {
87
+ const value = Number(row[entry.key]);
88
+ if (Number.isFinite(value)) {
89
+ rowTotal += value;
90
+ if (!stacked && value > max) {
91
+ max = value;
92
+ }
93
+ }
94
+ }
95
+ if (stacked && rowTotal > max) {
96
+ max = rowTotal;
97
+ }
98
+ }
99
+ return max;
100
+ }, [data, series, stacked]);
101
+
102
+ const margin = { top: markers?.length || valueLabels ? 18 : 8, right: 8, bottom: 2, left: 0 };
103
+
104
+ const axis = {
105
+ stroke: theme.border,
106
+ tick: { fill: theme.axisForeground, fontSize: 10, fontFamily: theme.fontMono },
107
+ tickLine: false as const,
108
+ axisLine: { stroke: theme.border, strokeOpacity: 0.6 },
109
+ };
110
+
111
+ const legendItems = resolved.map((entry) => ({ name: entry.name, color: entry.color, dashed: entry.dashed }));
112
+
113
+ const radiusFor = (slot: number): [number, number, number, number] => {
114
+ if (!stacked || slot === rendered.length - 1) {
115
+ return [BAR_RADIUS, BAR_RADIUS, 0, 0];
116
+ }
117
+ return [0, 0, 0, 0];
118
+ };
119
+
120
+ const fillFor = (entry: (typeof rendered)[number], slot: number) => {
121
+ if (texture && lead && entry.key === lead.key) {
122
+ return `url(#bar-hatch-${reactId})`;
123
+ }
124
+ // Stacked segments read cleanest as flat solids — a per-segment gradient
125
+ // banding looks like a drop shadow between bands. Grouped bars keep the fade.
126
+ if (stacked) {
127
+ return entry.color;
128
+ }
129
+ return `url(#bar-${reactId}-${slot})`;
130
+ };
131
+
132
+ const renderValueLabel =
133
+ (color: string) =>
134
+ (props: {
135
+ x?: string | number;
136
+ y?: string | number;
137
+ width?: string | number;
138
+ value?: string | number | boolean | Array<string | number | boolean> | null;
139
+ }) => {
140
+ if (props.x == null || props.y == null) {
141
+ return null;
142
+ }
143
+ return (
144
+ <text
145
+ x={Number(props.x) + Number(props.width ?? 0) / 2}
146
+ y={Number(props.y) - 5}
147
+ textAnchor="middle"
148
+ fill={color}
149
+ fontFamily={theme.fontMono}
150
+ fontSize={10}
151
+ style={{ fontVariantNumeric: "tabular-nums" }}
152
+ >
153
+ {valueFormatter(Number(props.value ?? 0))}
154
+ </text>
155
+ );
156
+ };
157
+
158
+ const isEmpty = data.length === 0 || rendered.length === 0;
159
+
160
+ return (
161
+ <div data-slot="bar-chart" className={cn("flex w-full flex-col gap-3", className)}>
162
+ <div className="w-full" style={{ height }}>
163
+ {loading ? (
164
+ <div className="flex h-full items-center justify-center gap-2.5 font-mono text-quaternary-foreground text-text-xs">
165
+ <span className="size-4 animate-spin rounded-full border-2 border-border border-t-foreground" />
166
+ loading…
167
+ </div>
168
+ ) : isEmpty ? (
169
+ <div className="flex h-full items-center justify-center rounded-lg border border-border border-dashed font-mono text-quaternary-foreground text-text-xs">
170
+ no data in range
171
+ </div>
172
+ ) : (
173
+ <ResponsiveContainer width="100%" height="100%" initialDimension={{ width: 0, height }}>
174
+ <RechartsBarChart
175
+ data={data as Record<string, string | number>[]}
176
+ stackOffset={variant === "expand" ? "expand" : "none"}
177
+ margin={margin}
178
+ barCategoryGap={stacked ? "20%" : "16%"}
179
+ >
180
+ <defs>
181
+ {!stacked &&
182
+ rendered.map((entry, slot) => (
183
+ <linearGradient key={entry.key} id={`bar-${reactId}-${slot}`} x1="0" y1="0" x2="0" y2="1">
184
+ <stop offset="0%" stopColor={entry.color} stopOpacity={0.95} />
185
+ <stop offset="100%" stopColor={entry.color} stopOpacity={0.5} />
186
+ </linearGradient>
187
+ ))}
188
+ {texture && lead && (
189
+ <pattern
190
+ id={`bar-hatch-${reactId}`}
191
+ patternUnits="userSpaceOnUse"
192
+ width={6}
193
+ height={6}
194
+ patternTransform="rotate(45)"
195
+ >
196
+ <rect width={6} height={6} fill={lead.color} fillOpacity={0.22} />
197
+ <line x1={0} y1={0} x2={0} y2={6} stroke={lead.color} strokeWidth={1.2} strokeOpacity={0.65} />
198
+ </pattern>
199
+ )}
200
+ </defs>
201
+
202
+ <CartesianGrid vertical={false} stroke={theme.grid} strokeDasharray="2 4" />
203
+ <XAxis
204
+ dataKey={index}
205
+ {...axis}
206
+ tick={makeXAxisTick(theme)}
207
+ interval="preserveStartEnd"
208
+ minTickGap={44}
209
+ />
210
+ <YAxis
211
+ {...axis}
212
+ width={yAxisWidth}
213
+ domain={
214
+ referenceLine && variant !== "expand"
215
+ ? [0, Math.ceil(Math.max(numericMax, referenceLine.y) * 1.15)]
216
+ : undefined
217
+ }
218
+ tickFormatter={(value: number) =>
219
+ variant === "expand" ? `${Math.round(value * 100)}%` : valueFormatter(value)
220
+ }
221
+ />
222
+ <Tooltip
223
+ offset={12}
224
+ allowEscapeViewBox={{ x: false, y: false }}
225
+ cursor={{ fill: lead?.color ?? theme.mutedForeground, fillOpacity: theme.isDark ? 0.1 : 0.06 }}
226
+ content={
227
+ <ChartTooltipContent
228
+ valueFormatter={valueFormatter}
229
+ labelFormatter={labelFormatter}
230
+ showTotal={withTotal}
231
+ />
232
+ }
233
+ />
234
+ {referenceLine?.band && (
235
+ <ReferenceArea
236
+ y1={referenceLine.y}
237
+ y2={numericMax}
238
+ fill={theme.warning}
239
+ fillOpacity={0.06}
240
+ ifOverflow="extendDomain"
241
+ />
242
+ )}
243
+ {referenceLine && (
244
+ <ReferenceLine
245
+ y={referenceLine.y}
246
+ stroke={theme.warning}
247
+ strokeDasharray="4 4"
248
+ strokeOpacity={0.6}
249
+ label={
250
+ referenceLine.label
251
+ ? {
252
+ value: referenceLine.label,
253
+ fill: theme.warning,
254
+ fontSize: 9,
255
+ fontFamily: theme.fontMono,
256
+ position: "insideBottomRight",
257
+ }
258
+ : undefined
259
+ }
260
+ />
261
+ )}
262
+
263
+ {rendered.map((entry, slot) => (
264
+ <Bar
265
+ key={entry.key}
266
+ dataKey={entry.key}
267
+ name={entry.name}
268
+ stackId={stacked ? "stack" : undefined}
269
+ fill={fillFor(entry, slot)}
270
+ stroke={entry.color}
271
+ strokeWidth={0}
272
+ radius={radiusFor(slot)}
273
+ maxBarSize={MAX_BAR_SIZE}
274
+ activeBar={{ fillOpacity: 1, stroke: theme.card, strokeWidth: 1 }}
275
+ isAnimationActive={animated}
276
+ animationDuration={650}
277
+ animationEasing="ease-out"
278
+ >
279
+ {valueLabels && (!stacked || rendered.length === 1) && (
280
+ <LabelList dataKey={entry.key} content={renderValueLabel(entry.color)} />
281
+ )}
282
+ </Bar>
283
+ ))}
284
+
285
+ {markers?.map((marker) => (
286
+ <ReferenceDot
287
+ key={`${marker.x}-${marker.y}`}
288
+ x={marker.x}
289
+ y={marker.y}
290
+ r={3.5}
291
+ fill={marker.color ?? theme.foreground}
292
+ stroke={theme.card}
293
+ strokeWidth={2}
294
+ label={
295
+ marker.label
296
+ ? {
297
+ value: marker.label,
298
+ fill: marker.color ?? theme.foreground,
299
+ fontSize: 9,
300
+ fontFamily: theme.fontMono,
301
+ position: "top",
302
+ }
303
+ : undefined
304
+ }
305
+ />
306
+ ))}
307
+ </RechartsBarChart>
308
+ </ResponsiveContainer>
309
+ )}
310
+ </div>
311
+
312
+ {legend && !isEmpty && <ChartLegend items={legendItems} align={legendAlign} insetLeft={yAxisWidth} />}
313
+ </div>
314
+ );
315
+ }
316
+
317
+ export { BarChart };