@alpic-ai/ui 0.0.0-dev.g16d80c2 → 0.0.0-dev.g172fb9f

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 (60) hide show
  1. package/dist/components/area-chart.d.mts +62 -0
  2. package/dist/components/area-chart.mjs +269 -0
  3. package/dist/components/badge.d.mts +1 -1
  4. package/dist/components/bar-chart.d.mts +48 -0
  5. package/dist/components/bar-chart.mjs +256 -0
  6. package/dist/components/bar-list.d.mts +28 -0
  7. package/dist/components/bar-list.mjs +98 -0
  8. package/dist/components/button.d.mts +1 -1
  9. package/dist/components/chart-card.d.mts +25 -0
  10. package/dist/components/chart-card.mjs +48 -0
  11. package/dist/components/chart-container.d.mts +20 -0
  12. package/dist/components/chart-container.mjs +37 -0
  13. package/dist/components/chart-legend.d.mts +16 -0
  14. package/dist/components/chart-legend.mjs +26 -0
  15. package/dist/components/chart-tooltip.d.mts +33 -0
  16. package/dist/components/chart-tooltip.mjs +52 -0
  17. package/dist/components/donut-chart.d.mts +46 -0
  18. package/dist/components/donut-chart.mjs +185 -0
  19. package/dist/components/grid-fx.d.mts +13 -0
  20. package/dist/components/grid-fx.mjs +188 -0
  21. package/dist/components/heatmap-chart.d.mts +40 -0
  22. package/dist/components/heatmap-chart.mjs +198 -0
  23. package/dist/components/line-chart.d.mts +55 -0
  24. package/dist/components/line-chart.mjs +211 -0
  25. package/dist/components/spinner.d.mts +1 -1
  26. package/dist/components/stat.d.mts +30 -0
  27. package/dist/components/stat.mjs +107 -0
  28. package/dist/hooks/use-chart-theme.d.mts +18 -0
  29. package/dist/hooks/use-chart-theme.mjs +57 -0
  30. package/dist/hooks/use-reduced-motion.d.mts +4 -0
  31. package/dist/hooks/use-reduced-motion.mjs +16 -0
  32. package/dist/lib/chart-palette.d.mts +4 -0
  33. package/dist/lib/chart-palette.mjs +95 -0
  34. package/dist/lib/chart.d.mts +14 -0
  35. package/dist/lib/chart.mjs +27 -0
  36. package/package.json +2 -1
  37. package/src/components/area-chart.tsx +339 -0
  38. package/src/components/bar-chart.tsx +309 -0
  39. package/src/components/bar-list.tsx +150 -0
  40. package/src/components/chart-card.tsx +63 -0
  41. package/src/components/chart-container.tsx +49 -0
  42. package/src/components/chart-legend.tsx +41 -0
  43. package/src/components/chart-tooltip.tsx +93 -0
  44. package/src/components/donut-chart.tsx +217 -0
  45. package/src/components/grid-fx.tsx +238 -0
  46. package/src/components/heatmap-chart.tsx +287 -0
  47. package/src/components/line-chart.tsx +264 -0
  48. package/src/components/stat.tsx +109 -0
  49. package/src/hooks/use-chart-theme.ts +75 -0
  50. package/src/hooks/use-reduced-motion.ts +17 -0
  51. package/src/lib/chart-palette.ts +110 -0
  52. package/src/lib/chart.ts +56 -0
  53. package/src/stories/area-chart.stories.tsx +200 -0
  54. package/src/stories/bar-chart.stories.tsx +169 -0
  55. package/src/stories/bar-list.stories.tsx +85 -0
  56. package/src/stories/donut-chart.stories.tsx +112 -0
  57. package/src/stories/heatmap-chart.stories.tsx +107 -0
  58. package/src/stories/line-chart.stories.tsx +146 -0
  59. package/src/stories/stat.stories.tsx +64 -0
  60. package/src/styles/tokens.css +63 -0
@@ -0,0 +1,30 @@
1
+ import * as React$1 from "react";
2
+
3
+ //#region src/components/stat.d.ts
4
+ declare const statDeltaVariants: (props?: ({
5
+ sentiment?: "positive" | "negative" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ interface StatDelta {
8
+ value: number;
9
+ direction: "up" | "down";
10
+ invert?: boolean;
11
+ label?: React$1.ReactNode;
12
+ }
13
+ interface StatProps extends React$1.ComponentProps<"div"> {
14
+ value: React$1.ReactNode;
15
+ unit?: string;
16
+ delta?: StatDelta;
17
+ sparkline?: number[] | Array<{
18
+ value: number;
19
+ }>;
20
+ }
21
+ declare function Stat({
22
+ value,
23
+ unit,
24
+ delta,
25
+ sparkline,
26
+ className,
27
+ ...props
28
+ }: StatProps): React$1.JSX.Element;
29
+ //#endregion
30
+ export { Stat, StatDelta, StatProps, statDeltaVariants };
@@ -0,0 +1,107 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.mjs";
3
+ import { useChartContext } from "./chart-container.mjs";
4
+ import { ArrowDown, ArrowUp } from "lucide-react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { cva } from "class-variance-authority";
7
+ import * as React$1 from "react";
8
+ import { Area, AreaChart, ResponsiveContainer } from "recharts";
9
+ //#region src/components/stat.tsx
10
+ const statDeltaVariants = cva("inline-flex items-center gap-0.5 rounded-md px-1.5 py-0.5 font-mono text-[11px] font-medium leading-none", {
11
+ variants: { sentiment: {
12
+ positive: "text-success bg-success/12",
13
+ negative: "text-destructive bg-destructive/12"
14
+ } },
15
+ defaultVariants: { sentiment: "positive" }
16
+ });
17
+ const toSparkData = (sparkline) => (sparkline ?? []).map((point, index) => typeof point === "number" ? {
18
+ index,
19
+ value: point
20
+ } : {
21
+ index,
22
+ value: point.value
23
+ });
24
+ function Stat({ value, unit, delta, sparkline, className, ...props }) {
25
+ const { palette } = useChartContext();
26
+ const gradientId = React$1.useId().replace(/:/g, "");
27
+ const sparkData = React$1.useMemo(() => toSparkData(sparkline), [sparkline]);
28
+ const sparkColor = palette[0];
29
+ const sentiment = delta && (delta.invert ? delta.direction === "down" : delta.direction === "up") ? "positive" : "negative";
30
+ return /* @__PURE__ */ jsxs("div", {
31
+ "data-slot": "stat",
32
+ className: cn("flex flex-col gap-2.5", className),
33
+ ...props,
34
+ children: [/* @__PURE__ */ jsxs("div", {
35
+ className: "flex items-baseline gap-3",
36
+ children: [
37
+ /* @__PURE__ */ jsx("span", {
38
+ className: "type-display-sm font-bold leading-none tracking-tight tabular-nums text-foreground",
39
+ children: value
40
+ }),
41
+ unit && /* @__PURE__ */ jsx("span", {
42
+ className: "font-mono text-[11px] leading-none text-quaternary-foreground mb-0.5",
43
+ children: unit
44
+ }),
45
+ delta && /* @__PURE__ */ jsxs(DeltaPill, {
46
+ sentiment,
47
+ className: "mb-0.5",
48
+ children: [delta.direction === "up" ? /* @__PURE__ */ jsx(ArrowUp, { className: "size-3" }) : /* @__PURE__ */ jsx(ArrowDown, { className: "size-3" }), delta.label ?? `${delta.value}%`]
49
+ })
50
+ ]
51
+ }), sparkData.length > 0 && /* @__PURE__ */ jsx("div", {
52
+ className: "h-9 w-full",
53
+ children: /* @__PURE__ */ jsx(ResponsiveContainer, {
54
+ width: "100%",
55
+ height: "100%",
56
+ children: /* @__PURE__ */ jsxs(AreaChart, {
57
+ data: sparkData,
58
+ margin: {
59
+ top: 4,
60
+ right: 2,
61
+ bottom: 0,
62
+ left: 2
63
+ },
64
+ children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
65
+ id: gradientId,
66
+ x1: "0",
67
+ y1: "0",
68
+ x2: "0",
69
+ y2: "1",
70
+ children: [/* @__PURE__ */ jsx("stop", {
71
+ offset: "0%",
72
+ stopColor: sparkColor,
73
+ stopOpacity: .4
74
+ }), /* @__PURE__ */ jsx("stop", {
75
+ offset: "100%",
76
+ stopColor: sparkColor,
77
+ stopOpacity: 0
78
+ })]
79
+ }) }), /* @__PURE__ */ jsx(Area, {
80
+ type: "monotone",
81
+ dataKey: "value",
82
+ stroke: sparkColor,
83
+ strokeWidth: 1.6,
84
+ fill: `url(#${gradientId})`,
85
+ isAnimationActive: false,
86
+ dot: ({ cx, cy, index }) => {
87
+ return index === sparkData.length - 1 && cx != null && cy != null ? /* @__PURE__ */ jsx("circle", {
88
+ cx,
89
+ cy,
90
+ r: 2.5,
91
+ fill: sparkColor
92
+ }, index) : /* @__PURE__ */ jsx("g", {}, index);
93
+ }
94
+ })]
95
+ })
96
+ })
97
+ })]
98
+ });
99
+ }
100
+ function DeltaPill({ sentiment, className, ...props }) {
101
+ return /* @__PURE__ */ jsx("span", {
102
+ className: cn(statDeltaVariants({ sentiment }), className),
103
+ ...props
104
+ });
105
+ }
106
+ //#endregion
107
+ export { Stat, statDeltaVariants };
@@ -0,0 +1,18 @@
1
+ //#region src/hooks/use-chart-theme.d.ts
2
+ interface ChartTheme {
3
+ foreground: string;
4
+ mutedForeground: string;
5
+ axisForeground: string;
6
+ grid: string;
7
+ border: string;
8
+ card: string;
9
+ popover: string;
10
+ destructive: string;
11
+ warning: string;
12
+ success: string;
13
+ fontMono: string;
14
+ isDark: boolean;
15
+ }
16
+ declare function useChartTheme(): ChartTheme;
17
+ //#endregion
18
+ export { ChartTheme, useChartTheme };
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import * as React$1 from "react";
3
+ //#region src/hooks/use-chart-theme.ts
4
+ const TOKEN_MAP = {
5
+ foreground: "--color-foreground",
6
+ mutedForeground: "--color-muted-foreground",
7
+ axisForeground: "--color-quaternary-foreground",
8
+ grid: "--color-sidebar-border",
9
+ border: "--color-border",
10
+ card: "--color-card",
11
+ popover: "--color-popover",
12
+ destructive: "--color-destructive",
13
+ warning: "--color-warning",
14
+ success: "--color-success",
15
+ fontMono: "--font-mono"
16
+ };
17
+ const FALLBACK = {
18
+ foreground: "#121e1e",
19
+ mutedForeground: "#3a4848",
20
+ axisForeground: "#6f7f7f",
21
+ grid: "#e3eaea",
22
+ border: "#acb8b8",
23
+ card: "#f8fafa",
24
+ popover: "#ffffff",
25
+ destructive: "#d92d20",
26
+ warning: "#dc6803",
27
+ success: "#079455",
28
+ fontMono: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
29
+ isDark: false
30
+ };
31
+ const readTheme = () => {
32
+ if (typeof window === "undefined") return FALLBACK;
33
+ const styles = window.getComputedStyle(document.documentElement);
34
+ const entries = Object.entries(TOKEN_MAP).map(([key, token]) => {
35
+ return [key, styles.getPropertyValue(token).trim() || FALLBACK[key]];
36
+ });
37
+ return {
38
+ ...Object.fromEntries(entries),
39
+ isDark: document.documentElement.classList.contains("dark")
40
+ };
41
+ };
42
+ function useChartTheme() {
43
+ const [theme, setTheme] = React$1.useState(readTheme);
44
+ React$1.useEffect(() => {
45
+ const update = () => setTheme(readTheme());
46
+ update();
47
+ const observer = new MutationObserver(update);
48
+ observer.observe(document.documentElement, {
49
+ attributes: true,
50
+ attributeFilter: ["class"]
51
+ });
52
+ return () => observer.disconnect();
53
+ }, []);
54
+ return theme;
55
+ }
56
+ //#endregion
57
+ export { useChartTheme };
@@ -0,0 +1,4 @@
1
+ //#region src/hooks/use-reduced-motion.d.ts
2
+ declare function useReducedMotion(): boolean;
3
+ //#endregion
4
+ export { useReducedMotion };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import * as React$1 from "react";
3
+ //#region src/hooks/use-reduced-motion.ts
4
+ function useReducedMotion() {
5
+ const [reduced, setReduced] = React$1.useState(false);
6
+ React$1.useEffect(() => {
7
+ const query = window.matchMedia("(prefers-reduced-motion: reduce)");
8
+ const update = () => setReduced(query.matches);
9
+ update();
10
+ query.addEventListener("change", update);
11
+ return () => query.removeEventListener("change", update);
12
+ }, []);
13
+ return reduced;
14
+ }
15
+ //#endregion
16
+ export { useReducedMotion };
@@ -0,0 +1,4 @@
1
+ //#region src/lib/chart-palette.d.ts
2
+ type ChartPaletteName = "magenta" | "cyan";
3
+ //#endregion
4
+ export { ChartPaletteName };
@@ -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,27 @@
1
+ import { luminance, paletteColor } from "./chart-palette.mjs";
2
+ //#region src/lib/chart.ts
3
+ const formatShare = (fraction) => `${(fraction * 100).toFixed(fraction >= .1 ? 0 : 1)}%`;
4
+ const semanticColor = (theme, semantic) => {
5
+ if (semantic === "error") return theme.destructive;
6
+ if (semantic === "warning") return theme.warning;
7
+ return theme.success;
8
+ };
9
+ /**
10
+ * Resolve each series to a concrete color and name. Color precedence:
11
+ * explicit `color` → `semantic` token → palette slot by declared index (so the
12
+ * lead series keeps the lead color even after the bands are reordered).
13
+ */
14
+ const resolveSeries = (series, palette, theme) => series.map((entry, index) => ({
15
+ ...entry,
16
+ name: entry.name ?? entry.key,
17
+ color: entry.color ?? (entry.semantic ? semanticColor(theme, entry.semantic) : paletteColor(palette, index))
18
+ }));
19
+ /**
20
+ * Stacked bands read cleanest as a vertical gradient: darkest at the baseline,
21
+ * lightest at the top edge. Sorting by luminance enforces that for any palette
22
+ * (this is what fixed the "muddy cyan" stack in the lab). Render order maps to
23
+ * stack order in Recharts — first entry sits at the bottom.
24
+ */
25
+ const orderByLuminance = (series) => [...series].sort((lower, upper) => luminance(lower.color) - luminance(upper.color));
26
+ //#endregion
27
+ export { formatShare, orderByLuminance, resolveSeries };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpic-ai/ui",
3
- "version": "0.0.0-dev.g16d80c2",
3
+ "version": "0.0.0-dev.g172fb9f",
4
4
  "description": "Alpic design system — shared UI components",
5
5
  "type": "module",
6
6
  "exports": {
@@ -52,6 +52,7 @@
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": {