@alpic-ai/ui 1.144.0 → 1.145.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/components/accordion-card.d.mts +1 -1
  2. package/dist/components/accordion.d.mts +1 -1
  3. package/dist/components/alert.d.mts +1 -1
  4. package/dist/components/area-chart.mjs +5 -7
  5. package/dist/components/attachment-tile.mjs +1 -1
  6. package/dist/components/avatar.d.mts +1 -1
  7. package/dist/components/bar-chart.mjs +6 -12
  8. package/dist/components/bar-list.mjs +1 -1
  9. package/dist/components/button.d.mts +1 -1
  10. package/dist/components/chart-container.mjs +2 -2
  11. package/dist/components/chart-tooltip.mjs +52 -27
  12. package/dist/components/combobox.d.mts +1 -1
  13. package/dist/components/combobox.mjs +1 -1
  14. package/dist/components/copyable.mjs +1 -1
  15. package/dist/components/dialog.d.mts +1 -1
  16. package/dist/components/donut-chart.mjs +1 -1
  17. package/dist/components/dropdown-menu.d.mts +1 -1
  18. package/dist/components/form.mjs +1 -1
  19. package/dist/components/heatmap-chart.d.mts +6 -0
  20. package/dist/components/heatmap-chart.mjs +147 -117
  21. package/dist/components/input-group.d.mts +1 -1
  22. package/dist/components/input.mjs +1 -1
  23. package/dist/components/line-chart.mjs +5 -7
  24. package/dist/components/select.d.mts +1 -1
  25. package/dist/components/sidebar.d.mts +1 -1
  26. package/dist/components/sidebar.mjs +3 -3
  27. package/dist/components/skeleton.mjs +1 -1
  28. package/dist/components/stat.mjs +5 -5
  29. package/dist/components/tabs.d.mts +1 -1
  30. package/dist/components/tabs.mjs +1 -1
  31. package/dist/components/textarea.mjs +1 -1
  32. package/dist/components/toggle-group.d.mts +1 -1
  33. package/dist/components/toggle-group.mjs +1 -1
  34. package/dist/components/tooltip-icon-button.mjs +1 -1
  35. package/dist/lib/chart-palette.mjs +4 -1
  36. package/package.json +2 -2
  37. package/src/components/area-chart.tsx +11 -6
  38. package/src/components/bar-chart.tsx +12 -7
  39. package/src/components/chart-tooltip.tsx +17 -1
  40. package/src/components/heatmap-chart.tsx +49 -5
  41. package/src/components/line-chart.tsx +11 -6
  42. package/src/components/skeleton.tsx +1 -1
  43. package/src/components/stat.tsx +4 -4
  44. package/src/lib/chart-palette.ts +4 -1
@@ -3,6 +3,8 @@
3
3
  import { cn } from "../lib/cn";
4
4
  import { useChartContext } from "./chart-container";
5
5
 
6
+ const MAX_TOOLTIP_ROWS = 8;
7
+
6
8
  export interface ChartTooltipItem {
7
9
  name?: string | number;
8
10
  value?: number | string;
@@ -44,7 +46,11 @@ function ChartTooltipContent({
44
46
  const toNumber = (value: ChartTooltipItem["value"]) => (typeof value === "number" ? value : Number(value ?? 0));
45
47
  const total = payload.reduce((sum, item) => sum + toNumber(item.value), 0);
46
48
 
47
- const rows = [...payload].sort((lower, upper) => toNumber(upper.value) - toNumber(lower.value));
49
+ const sorted = [...payload].sort((lower, upper) => toNumber(upper.value) - toNumber(lower.value));
50
+
51
+ const rows = sorted.slice(0, MAX_TOOLTIP_ROWS);
52
+ const overflow = sorted.slice(MAX_TOOLTIP_ROWS);
53
+ const overflowTotal = overflow.reduce((sum, item) => sum + toNumber(item.value), 0);
48
54
 
49
55
  return (
50
56
  <div
@@ -77,6 +83,16 @@ function ChartTooltipContent({
77
83
  </div>
78
84
  );
79
85
  })}
86
+ {overflow.length > 0 && (
87
+ <div className="flex items-center justify-between gap-4 text-text-xs">
88
+ <span className="inline-flex items-center gap-2 text-quaternary-foreground">
89
+ <span aria-hidden className="size-2 shrink-0" />+{overflow.length} more
90
+ </span>
91
+ <span className="font-mono font-semibold tabular-nums text-quaternary-foreground">
92
+ {valueFormatter(overflowTotal)}
93
+ </span>
94
+ </div>
95
+ )}
80
96
  {showTotal && (
81
97
  <div className="mt-1 flex items-center justify-between gap-4 border-border border-t pt-1.5 text-text-xs">
82
98
  <span className="font-mono text-quaternary-foreground uppercase tracking-wider text-[10px]">
@@ -24,6 +24,9 @@ export interface HeatmapChartProps {
24
24
  xTickFormatter?: (label: string) => string;
25
25
  yTickFormatter?: (label: string) => string;
26
26
  tooltipMetrics?: ReadonlyArray<{ key: string; label: string; format?: (value: number) => string }>;
27
+ tooltipTitleKey?: string;
28
+ colorScale?: "linear" | "rank";
29
+ showLegend?: boolean;
27
30
  ariaLabel?: string;
28
31
  className?: string;
29
32
  }
@@ -83,6 +86,9 @@ function HeatmapChart({
83
86
  xTickFormatter,
84
87
  yTickFormatter,
85
88
  tooltipMetrics,
89
+ tooltipTitleKey,
90
+ colorScale = "linear",
91
+ showLegend = false,
86
92
  ariaLabel = "Activity heatmap",
87
93
  className,
88
94
  }: HeatmapChartProps) {
@@ -123,6 +129,28 @@ function HeatmapChart({
123
129
  const { columns, rows, cells, maxValue, peakKey } = layout;
124
130
  const isEmpty = columns.length === 0 || rows.length === 0 || maxValue <= 0;
125
131
 
132
+ // "rank" spreads clustered values across the whole ramp by colouring each cell
133
+ // by its position among the distinct non-zero values rather than its raw ratio
134
+ // to the max — the right read for skewed activity counts (à la GitHub).
135
+ const colorFractionOf = React.useMemo(() => {
136
+ if (colorScale === "rank") {
137
+ const sorted = [...new Set(cells.map((cell) => cell.value).filter((value) => value > 0))].sort(
138
+ (lower, upper) => lower - upper,
139
+ );
140
+ // Floor non-zero ranks above the empty colour so the quietest active day
141
+ // still reads as coloured, never mistaken for no data.
142
+ const RANK_FLOOR = 0.18;
143
+ const fractionByValue = new Map(
144
+ sorted.map((value, index) => [
145
+ value,
146
+ sorted.length > 1 ? RANK_FLOOR + (1 - RANK_FLOOR) * (index / (sorted.length - 1)) : 1,
147
+ ]),
148
+ );
149
+ return (value: number) => (value > 0 ? (fractionByValue.get(value) ?? 0) : 0);
150
+ }
151
+ return (value: number) => (maxValue > 0 ? value / maxValue : 0);
152
+ }, [cells, colorScale, maxValue]);
153
+
126
154
  if (loading) {
127
155
  return (
128
156
  <div
@@ -152,7 +180,7 @@ function HeatmapChart({
152
180
  );
153
181
  }
154
182
 
155
- const ramp = heatRamp(paletteName, theme.isDark ? HEAT_EMPTY.dark : HEAT_EMPTY.light);
183
+ const ramp = heatRamp(paletteName, theme.isDark ? HEAT_EMPTY.dark : HEAT_EMPTY.light, theme.isDark);
156
184
  const totalWidth = PAD.left + columns.length * CELL + (columns.length - 1) * GAP + PAD.right;
157
185
  const totalHeight = PAD.top + rows.length * CELL + (rows.length - 1) * GAP + PAD.bottom;
158
186
  const xStride = showAllXLabels ? 1 : Math.ceil(columns.length / MAX_X_TICKS);
@@ -209,7 +237,7 @@ function HeatmapChart({
209
237
  </text>
210
238
  ))}
211
239
  {cells.map((cell) => {
212
- const fraction = cell.value / maxValue;
240
+ const fraction = colorFractionOf(cell.value);
213
241
  const fill = heatColor(ramp, fraction);
214
242
  const key = pairKey(cell.rowLabel, cell.colLabel);
215
243
  const isPeak = highlightPeak && key === peakKey;
@@ -266,6 +294,18 @@ function HeatmapChart({
266
294
  </svg>
267
295
  </div>
268
296
 
297
+ {showLegend && (
298
+ <div className="mt-3 flex items-center justify-end gap-2">
299
+ <span className="font-mono text-[9px] text-quaternary-foreground uppercase tracking-[0.14em]">Less</span>
300
+ <span
301
+ aria-hidden
302
+ className="h-2 w-24 rounded-full border border-border"
303
+ style={{ background: `linear-gradient(90deg, ${ramp.join(", ")})` }}
304
+ />
305
+ <span className="font-mono text-[9px] text-quaternary-foreground uppercase tracking-[0.14em]">More</span>
306
+ </div>
307
+ )}
308
+
269
309
  {mounted &&
270
310
  hovered &&
271
311
  createPortal(
@@ -274,7 +314,9 @@ function HeatmapChart({
274
314
  style={{ left: tooltipLeft, top: tooltipTop }}
275
315
  >
276
316
  <p className="mb-1.5 font-mono text-[10px] text-quaternary-foreground uppercase tracking-wider">
277
- {formatY(hovered.rowLabel)} · {formatX(hovered.colLabel)}
317
+ {tooltipTitleKey && typeof hovered.record?.[tooltipTitleKey] === "string"
318
+ ? hovered.record[tooltipTitleKey]
319
+ : `${formatY(hovered.rowLabel)} · ${formatX(hovered.colLabel)}`}
278
320
  </p>
279
321
  {tooltipMetrics && tooltipMetrics.length > 0 ? (
280
322
  <div className="flex flex-col gap-1">
@@ -288,7 +330,9 @@ function HeatmapChart({
288
330
  aria-hidden
289
331
  className="size-2 shrink-0 rounded-[2px]"
290
332
  style={{
291
- background: isActive ? heatColor(ramp, hovered.value / maxValue) : theme.mutedForeground,
333
+ background: isActive
334
+ ? heatColor(ramp, colorFractionOf(hovered.value))
335
+ : theme.mutedForeground,
292
336
  opacity: isActive ? 1 : 0.35,
293
337
  }}
294
338
  />
@@ -312,7 +356,7 @@ function HeatmapChart({
312
356
  <span
313
357
  aria-hidden
314
358
  className="size-2 shrink-0 rounded-[2px]"
315
- style={{ background: heatColor(ramp, hovered.value / maxValue) }}
359
+ style={{ background: heatColor(ramp, colorFractionOf(hovered.value)) }}
316
360
  />
317
361
  activity
318
362
  </span>
@@ -22,6 +22,7 @@ import type { ChartMarker } from "./area-chart";
22
22
  import { useChartContext } from "./chart-container";
23
23
  import { ChartLegend } from "./chart-legend";
24
24
  import { ChartTooltipContent } from "./chart-tooltip";
25
+ import { Skeleton } from "./skeleton";
25
26
 
26
27
  const CURVE_TYPE = { monotone: "monotone", linear: "linear", step: "stepAfter" } as const;
27
28
 
@@ -157,13 +158,17 @@ function LineChart({
157
158
  const isEmpty = data.length === 0 || resolved.length === 0;
158
159
 
159
160
  return (
160
- <div data-slot="line-chart" className={cn("flex w-full flex-col gap-3", className)}>
161
+ <div
162
+ data-slot="line-chart"
163
+ className={cn(
164
+ "flex w-full flex-col gap-3",
165
+ "[&_.recharts-surface]:outline-none [&_.recharts-wrapper]:outline-none",
166
+ className,
167
+ )}
168
+ >
161
169
  <div className="w-full" style={{ height }}>
162
170
  {loading ? (
163
- <div className="flex h-full items-center justify-center gap-2.5 font-mono text-quaternary-foreground text-text-xs">
164
- <span className="size-4 animate-spin rounded-full border-2 border-border border-t-foreground" />
165
- loading…
166
- </div>
171
+ <Skeleton className="h-full w-full rounded-lg" />
167
172
  ) : isEmpty ? (
168
173
  <div className="flex h-full items-center justify-center rounded-lg border border-border border-dashed font-mono text-quaternary-foreground text-text-xs">
169
174
  no data in range
@@ -177,7 +182,7 @@ function LineChart({
177
182
  {...axis}
178
183
  tick={makeXAxisTick(theme)}
179
184
  interval="preserveStartEnd"
180
- minTickGap={44}
185
+ minTickGap={56}
181
186
  />
182
187
  <YAxis
183
188
  {...axis}
@@ -3,7 +3,7 @@
3
3
  import { cn } from "@alpic-ai/ui/lib/cn";
4
4
  import { cva, type VariantProps } from "class-variance-authority";
5
5
 
6
- const skeletonVariants = cva("bg-accent motion-safe:animate-pulse", {
6
+ const skeletonVariants = cva("bg-foreground/10 motion-safe:animate-pulse", {
7
7
  variants: {
8
8
  shape: {
9
9
  rectangle: "rounded-md",
@@ -55,9 +55,9 @@ function Stat({ value, unit, delta, sparkline, semantic, className, ...props }:
55
55
  delta && (delta.invert ? delta.direction === "down" : delta.direction === "up") ? "positive" : "negative";
56
56
 
57
57
  return (
58
- <div data-slot="stat" className={cn("flex flex-col gap-2.5", className)} {...props}>
59
- <div className="flex items-baseline gap-3">
60
- <span className="type-display-sm font-bold leading-none tracking-tight tabular-nums text-foreground">
58
+ <div data-slot="stat" className={cn("flex min-w-0 flex-col gap-2.5", className)} {...props}>
59
+ <div className="flex min-w-0 items-baseline gap-x-2.5">
60
+ <span className="type-display-sm min-w-0 truncate font-bold leading-none tracking-tight tabular-nums text-foreground">
61
61
  {value}
62
62
  </span>
63
63
  {unit && <span className="font-mono text-[11px] leading-none text-quaternary-foreground mb-0.5">{unit}</span>}
@@ -69,7 +69,7 @@ function Stat({ value, unit, delta, sparkline, semantic, className, ...props }:
69
69
  )}
70
70
  </div>
71
71
  {hasSpark && (
72
- <div className="h-9 w-full">
72
+ <div className="pointer-events-none h-9 w-full">
73
73
  <ResponsiveContainer width="100%" height="100%" initialDimension={{ width: 0, height: 36 }}>
74
74
  <AreaChart data={sparkData} margin={{ top: 4, right: 2, bottom: 0, left: 2 }}>
75
75
  <defs>
@@ -55,7 +55,10 @@ const HEAT_RAMPS: Record<ChartPaletteName, (empty: string) => string[]> = {
55
55
  cyan: heatRampMint,
56
56
  };
57
57
 
58
- export const heatRamp = (palette: ChartPaletteName, empty: string) => HEAT_RAMPS[palette](empty);
58
+ export const heatRamp = (palette: ChartPaletteName, empty: string, isDark = true) => {
59
+ const [, ...colored] = HEAT_RAMPS[palette](empty);
60
+ return [empty, ...(isDark ? colored : colored.reverse())];
61
+ };
59
62
 
60
63
  const hexToRgb = (hex: string) => {
61
64
  const value = Number.parseInt(hex.slice(1), 16);