@brdgapp/ui 1.1.1 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  Every release of `@brdgapp/ui`. Versions follow the rules in README.md → Versions.
4
4
 
5
+ ## 1.2.1
6
+
7
+ 2026-11-10. A small addition that changes nothing an app relies on.
8
+
9
+ - Chart: Home and End jump to the first or last point, and Esc hides the tooltip (← → and Enter already worked).
10
+
11
+ ## 1.2.0
12
+
13
+ 2026-11-06. A new component and new tokens. Nothing changes for apps already on 1.1, so they can update
14
+ without changes.
15
+
16
+ - New: Chart (`components/chart`), for line, bar and area charts with Recharts. `ChartContainer` with
17
+ `ChartGrid`, `ChartXAxis`, `ChartYAxis`, `ChartTooltip`, `ChartLegend`, `ChartSkeleton` and `useChartMotion`.
18
+ Recharts (3.8 or newer) is an optional peer dependency: install it only in an app that draws charts.
19
+ - New tokens: `--chart-1` to `--chart-5`, the chart colours in order (Royal, Teal, Amber, Purple, Slate), for
20
+ light and dark.
21
+
5
22
  ## 1.1.1
6
23
 
7
24
  2026-11-06. A fix that changes nothing an app relies on.
package/README.md CHANGED
@@ -8,6 +8,7 @@ Bridge's shared components, tokens and styles. How and when to use each part is
8
8
  - React 19
9
9
  - Tailwind CSS 4 (apps still on Tailwind 3 upgrade first)
10
10
  - The Mulish font, loaded by the app. Every Bridge app uses Mulish, and only Mulish (rule "One typeface").
11
+ - Recharts 3.8 or newer, only if the app draws charts (`npm install recharts`). Chart is the one part that needs it.
11
12
 
12
13
  ## Set up
13
14
 
@@ -0,0 +1,55 @@
1
+ import * as React from "react";
2
+ import * as Recharts from "recharts";
3
+ /** A chart colour: the five come in order, and a chart with one series uses the first. */
4
+ export type ChartColor = "var(--chart-1)" | "var(--chart-2)" | "var(--chart-3)" | "var(--chart-4)" | "var(--chart-5)";
5
+ /** One entry per series. Keys match the series `dataKey`. */
6
+ export type ChartConfig = Record<string, {
7
+ label: string;
8
+ color: ChartColor;
9
+ }>;
10
+ type ChartContainerProps = {
11
+ /** One entry per series: its label and chart colour. */
12
+ config: ChartConfig;
13
+ /** What the chart shows, in one sentence, for screen readers: "Intros per week, 12 weeks, 148 in all." */
14
+ summary: string;
15
+ /** Height in px. Width always fills the space. */
16
+ height?: number;
17
+ /** One Recharts chart: `BarChart`, `LineChart` or `AreaChart`. */
18
+ children: React.ReactElement;
19
+ /** Layout only (margins, grid placement). */
20
+ className?: string;
21
+ };
22
+ /** Wraps one Recharts chart: colours, sizing, the screen-reader summary and the keyboard read-out. */
23
+ declare function ChartContainer({ config, summary, height, children, className }: ChartContainerProps): React.JSX.Element;
24
+ /** Horizontal rules only. */
25
+ declare function ChartGrid(props: React.ComponentProps<typeof Recharts.CartesianGrid>): React.JSX.Element;
26
+ /** The category axis along the base: no tick or axis lines, labels thinned so they never collide. */
27
+ declare function ChartXAxis(props: React.ComponentProps<typeof Recharts.XAxis>): React.JSX.Element;
28
+ /** The value axis: no tick or axis lines, a fixed width so charts in a row line up. */
29
+ declare function ChartYAxis(props: React.ComponentProps<typeof Recharts.YAxis>): React.JSX.Element;
30
+ type ChartTooltipContentProps = {
31
+ /** Rewrites the category label: `(label) => \`Week of ${label}\``. */
32
+ labelFormatter?: (label: string) => string;
33
+ /** Formats each value. Defaults to the full number with commas (1,284). Use `formatMoney` for money. */
34
+ valueFormatter?: (value: number) => string;
35
+ /** Hides the category label (when the series names say it all). */
36
+ hideLabel?: boolean;
37
+ };
38
+ /** The tooltip, on hover and as the arrow keys move through the chart. */
39
+ declare function ChartTooltip({ labelFormatter, valueFormatter, hideLabel, ...props }: ChartTooltipContentProps & Omit<React.ComponentProps<typeof Recharts.Tooltip>, "content" | "labelFormatter">): React.JSX.Element;
40
+ /** Names each series under the chart. Leave it out when there's one series: the title names it. */
41
+ declare function ChartLegend(props: Omit<React.ComponentProps<typeof Recharts.Legend>, "content">): React.JSX.Element;
42
+ /**
43
+ * Spread onto each series: `<Bar {...motion} />`. Series grow in over 300ms, once, and not at all under
44
+ * reduced motion. Recharts' own default is 1.5s on every series.
45
+ */
46
+ declare function useChartMotion(): {
47
+ isAnimationActive: boolean;
48
+ animationDuration: number;
49
+ animationEasing: "ease-out";
50
+ };
51
+ /** The loading chart: one grey block, the same height as the chart, so nothing jumps when data arrives. */
52
+ declare function ChartSkeleton({ height }: {
53
+ height?: number;
54
+ }): React.JSX.Element;
55
+ export { ChartContainer, ChartGrid, ChartXAxis, ChartYAxis, ChartTooltip, ChartLegend, ChartSkeleton, useChartMotion };
@@ -0,0 +1,156 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Line, bar and area charts, drawn with Recharts in Bridge's look. Seven apps already draw charts with
4
+ // Recharts, each with its own hex colours; this is the one way now (decision 2026-11-06).
5
+ //
6
+ // `ChartContainer` names each series and gives it a chart colour, in order: Royal, Teal, Amber, Purple,
7
+ // Slate (`--chart-1` … `--chart-5`). It writes `--color-<key>` for lines and bars and `--fade-<key>` for
8
+ // the soft fade under an area. Its styles set the grid, ticks, line width and dots, so Recharts' defaults
9
+ // never show. The parts below (`ChartGrid`, `ChartXAxis`, `ChartYAxis`, `ChartTooltip`, `ChartLegend`)
10
+ // come set up; pass Recharts props to change data, not the look.
11
+ //
12
+ // Recharts is an optional peer dependency: install it (`npm install recharts`) only if the app draws charts.
13
+ import * as React from "react";
14
+ import * as Recharts from "recharts";
15
+ import { skeletonVariants } from "@brdgapp/ui/components/skeleton";
16
+ import { cn } from "@brdgapp/ui/lib/utils";
17
+ const ChartContext = React.createContext(null);
18
+ function useChart() {
19
+ const ctx = React.useContext(ChartContext);
20
+ if (!ctx)
21
+ throw new Error("Chart parts must sit inside <ChartContainer>.");
22
+ return ctx;
23
+ }
24
+ // Keys become CSS variable names and SVG ids, so keep only safe characters.
25
+ const safe = (key) => key.replace(/[^a-zA-Z0-9_-]/g, "_");
26
+ // The most points Home and End step across: far more than a readable chart has.
27
+ const MAX_POINTS = 500;
28
+ // Where a series sits in `config`; anything not in it goes last.
29
+ const rankIn = (config, key) => {
30
+ const i = Object.keys(config).indexOf(key);
31
+ return i === -1 ? Number.MAX_SAFE_INTEGER : i;
32
+ };
33
+ // The container's styles: Bridge's grid, ticks, cursor, line width and dots, whatever props a chart passes.
34
+ const CHART_STYLES = [
35
+ "relative w-full text-12 tabular-nums",
36
+ "[&_.recharts-cartesian-axis-tick-value]:fill-[var(--text-muted)]",
37
+ "[&_.recharts-cartesian-grid_line]:stroke-[var(--border-default)]",
38
+ "[&_.recharts-reference-line_line]:stroke-[var(--text-muted)]",
39
+ "[&_.recharts-reference-line_text]:fill-[var(--text-muted)]",
40
+ "[&_.recharts-curve.recharts-tooltip-cursor]:stroke-[var(--border-hover)]",
41
+ "[&_.recharts-rectangle.recharts-tooltip-cursor]:fill-[var(--surface-tertiary)]",
42
+ // Lines are 2px with no dots; the hovered point still shows its dot.
43
+ "[&_.recharts-line-curve]:stroke-2 [&_.recharts-area-curve]:stroke-2 [&_.recharts-line-dots]:hidden [&_.recharts-area-dots]:hidden",
44
+ "[&_.recharts-active-dot_.recharts-dot]:stroke-[var(--surface-elevated)] [&_.recharts-active-dot_.recharts-dot]:stroke-2",
45
+ "[&_.recharts-area-area]:[fill-opacity:1]",
46
+ // Recharts makes the chart a tab stop. Show where focus is, as every control does.
47
+ "[&_.recharts-wrapper]:outline-none [&_.recharts-surface]:outline-none [&_.recharts-layer]:outline-none [&_.recharts-sector]:outline-none",
48
+ "[&_.recharts-surface:focus-visible]:outline-2 [&_.recharts-surface:focus-visible]:outline-offset-2 [&_.recharts-surface:focus-visible]:outline-solid [&_.recharts-surface:focus-visible]:outline-[var(--primary)] [&_.recharts-surface]:rounded-sm",
49
+ ].join(" ");
50
+ /** Wraps one Recharts chart: colours, sizing, the screen-reader summary and the keyboard read-out. */
51
+ function ChartContainer({ config, summary, height = 240, children, className }) {
52
+ const id = `chart-${React.useId().replace(/[^a-zA-Z0-9]/g, "")}`;
53
+ const root = React.useRef(null);
54
+ const [announcement, setAnnouncement] = React.useState("");
55
+ const value = React.useMemo(() => ({ config, announce: setAnnouncement, root }), [config]);
56
+ const keys = Object.keys(config);
57
+ const css = keys.map((key) => `--color-${safe(key)}: ${config[key].color}; --fade-${safe(key)}: url(#${id}-fade-${safe(key)});`).join(" ");
58
+ // Recharts moves the tooltip with ← → and shows or hides it with Enter. Home and End jump to the first or
59
+ // last point by pressing ← or → until it stops (Recharts ignores a press past the end); Esc hides the tooltip.
60
+ const onKeyDown = (e) => {
61
+ const surface = e.target;
62
+ if (!surface.classList?.contains("recharts-surface"))
63
+ return;
64
+ const press = (key) => surface.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true }));
65
+ if (e.key === "Home" || e.key === "End") {
66
+ e.preventDefault();
67
+ for (let i = 0; i < MAX_POINTS; i++)
68
+ press(e.key === "Home" ? "ArrowLeft" : "ArrowRight");
69
+ }
70
+ else if (e.key === "Escape" && announcement) {
71
+ e.stopPropagation();
72
+ press("Enter");
73
+ }
74
+ };
75
+ return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { ref: root, "data-slot": "chart", "data-chart": id, role: "figure", "aria-label": summary, className: cn(CHART_STYLES, className), style: { height }, onKeyDown: onKeyDown, children: [_jsx("style", { children: `[data-chart="${id}"] { ${css} }` }), _jsx("svg", { "aria-hidden": "true", width: "0", height: "0", className: "absolute", children: _jsx("defs", { children: keys.map((key) => (_jsxs("linearGradient", { id: `${id}-fade-${safe(key)}`, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: `var(--color-${safe(key)})`, stopOpacity: 0.3 }), _jsx("stop", { offset: "100%", stopColor: `var(--color-${safe(key)})`, stopOpacity: 0 })] }, key))) }) }), _jsx(Recharts.ResponsiveContainer, { width: "100%", height: "100%", initialDimension: { width: 320, height }, children: children }), _jsx("div", { "aria-live": "polite", className: "sr-only", children: announcement })] }) }));
76
+ }
77
+ /** Horizontal rules only. */
78
+ function ChartGrid(props) {
79
+ return _jsx(Recharts.CartesianGrid, { vertical: false, ...props });
80
+ }
81
+ /** The category axis along the base: no tick or axis lines, labels thinned so they never collide. */
82
+ function ChartXAxis(props) {
83
+ return _jsx(Recharts.XAxis, { tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 24, ...props });
84
+ }
85
+ /** The value axis: no tick or axis lines, a fixed width so charts in a row line up. */
86
+ function ChartYAxis(props) {
87
+ return _jsx(Recharts.YAxis, { tickLine: false, axisLine: false, tickMargin: 4, width: 40, ...props });
88
+ }
89
+ function ChartTooltipContent({ active, payload, label, labelFormatter, valueFormatter = (v) => v.toLocaleString("en-US"), hideLabel = false, }) {
90
+ const { config, announce, root } = useChart();
91
+ const heading = label == null ? "" : labelFormatter ? labelFormatter(String(label)) : String(label);
92
+ const rows = (payload ?? [])
93
+ .filter((item) => item.type !== "none" && item.value != null)
94
+ .map((item) => {
95
+ const key = String(item.dataKey ?? item.name ?? "value");
96
+ const entry = config[key];
97
+ const raw = Array.isArray(item.value) ? item.value[1] : item.value;
98
+ return {
99
+ key,
100
+ label: entry?.label ?? String(item.name ?? key),
101
+ color: entry ? `var(--color-${safe(key)})` : String(item.color ?? "currentColor"),
102
+ value: typeof raw === "number" ? valueFormatter(raw) : String(raw),
103
+ };
104
+ })
105
+ // In the order of `config`, like the legend.
106
+ .sort((a, b) => rankIn(config, a.key) - rankIn(config, b.key));
107
+ const text = active && rows.length ? [hideLabel ? "" : heading, rows.map((r) => `${r.label} ${r.value}`).join(", ")].filter(Boolean).join(": ") : "";
108
+ // Keyboard users step through the chart with the arrow keys; read each point out as it shows.
109
+ React.useEffect(() => {
110
+ if (root.current?.contains(document.activeElement))
111
+ announce(text);
112
+ }, [text, announce, root]);
113
+ if (!active || !rows.length)
114
+ return null;
115
+ return (_jsxs("div", { className: "grid min-w-32 gap-1.5 rounded-lg border border-[var(--border-default)] bg-[var(--surface-elevated)] px-2.5 py-2 text-12 shadow-[var(--shadow-menu)]", children: [!hideLabel && heading ? _jsx("div", { className: "font-semibold text-[var(--text-primary)]", children: heading }) : null, rows.map((row) => (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { "aria-hidden": "true", className: "size-2 shrink-0 rounded-[2px]", style: { background: row.color } }), _jsx("span", { className: "flex-1 text-[var(--text-secondary)]", children: row.label }), _jsx("span", { className: "font-semibold text-[var(--text-primary)] tabular-nums", children: row.value })] }, row.key)))] }));
116
+ }
117
+ /** The tooltip, on hover and as the arrow keys move through the chart. */
118
+ function ChartTooltip({ labelFormatter, valueFormatter, hideLabel, ...props }) {
119
+ return (_jsx(Recharts.Tooltip, { cursor: true, isAnimationActive: false, ...props, content: (p) => (_jsx(ChartTooltipContent, { active: p.active, payload: p.payload, label: p.label, labelFormatter: labelFormatter, valueFormatter: valueFormatter, hideLabel: hideLabel })) }));
120
+ }
121
+ function ChartLegendContent({ payload }) {
122
+ const { config } = useChart();
123
+ if (!payload?.length)
124
+ return null;
125
+ // In the order of `config`, which is the order of the series and of a stack.
126
+ const rank = (item) => rankIn(config, String(item.dataKey ?? item.value));
127
+ return (_jsx("ul", { className: "flex flex-wrap items-center justify-center gap-x-4 gap-y-1 pt-3 text-12 text-[var(--text-secondary)]", children: [...payload]
128
+ .filter((item) => item.type !== "none")
129
+ .sort((a, b) => rank(a) - rank(b))
130
+ .map((item) => {
131
+ const key = String(item.dataKey ?? item.value);
132
+ return (_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("span", { "aria-hidden": "true", className: "size-2 shrink-0 rounded-[2px]", style: { background: config[key] ? `var(--color-${safe(key)})` : item.color } }), config[key]?.label ?? String(item.value)] }, key));
133
+ }) }));
134
+ }
135
+ /** Names each series under the chart. Leave it out when there's one series: the title names it. */
136
+ function ChartLegend(props) {
137
+ return _jsx(Recharts.Legend, { verticalAlign: "bottom", itemSorter: null, ...props, content: (p) => _jsx(ChartLegendContent, { payload: p.payload }) });
138
+ }
139
+ const subscribeToMotion = (onChange) => {
140
+ const query = window.matchMedia("(prefers-reduced-motion: reduce)");
141
+ query.addEventListener("change", onChange);
142
+ return () => query.removeEventListener("change", onChange);
143
+ };
144
+ /**
145
+ * Spread onto each series: `<Bar {...motion} />`. Series grow in over 300ms, once, and not at all under
146
+ * reduced motion. Recharts' own default is 1.5s on every series.
147
+ */
148
+ function useChartMotion() {
149
+ const reduced = React.useSyncExternalStore(subscribeToMotion, () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, () => true);
150
+ return { isAnimationActive: !reduced, animationDuration: 300, animationEasing: "ease-out" };
151
+ }
152
+ /** The loading chart: one grey block, the same height as the chart, so nothing jumps when data arrives. */
153
+ function ChartSkeleton({ height = 240 }) {
154
+ return _jsx("span", { "aria-hidden": "true", className: cn(skeletonVariants({ shape: "block" }), "w-full"), style: { height } });
155
+ }
156
+ export { ChartContainer, ChartGrid, ChartXAxis, ChartYAxis, ChartTooltip, ChartLegend, ChartSkeleton, useChartMotion };
package/lib/motion.d.ts CHANGED
@@ -11,6 +11,6 @@ export declare const DURATION: {
11
11
  export declare const EASE: readonly [0.23, 1, 0.32, 1];
12
12
  /** A ready-made transition for Framer Motion: `transition={transition("base")}`. */
13
13
  export declare function transition(speed?: keyof typeof DURATION): {
14
- duration: 0.15 | 0.2 | 0.3;
14
+ duration: 0.3 | 0.15 | 0.2;
15
15
  ease: readonly [0.23, 1, 0.32, 1];
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brdgapp/ui",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Bridge's shared components, tokens and styles. Documented at handbook.brdg.app.",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://handbook.brdg.app",
@@ -39,6 +39,12 @@
39
39
  "peerDependencies": {
40
40
  "react": ">=19",
41
41
  "react-dom": ">=19",
42
- "tailwindcss": ">=4"
42
+ "tailwindcss": ">=4",
43
+ "recharts": ">=3.8"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "recharts": {
47
+ "optional": true
48
+ }
43
49
  }
44
50
  }
@@ -95,6 +95,14 @@
95
95
  --honey: #E19500;
96
96
  --honey-text: #9A6B00; /* Honey for text on light surfaces: 4.7:1 on white (honey itself is 2.5). Decision 2026-11-04. */
97
97
 
98
+ /* Chart series — used in this order, Royal first (decision 2026-11-06). Each passes 3:1 on white and
99
+ --surface-secondary, and every pair stays apart under protan, deutan and tritan simulation. */
100
+ --chart-1: #0038FF; /* Royal */
101
+ --chart-2: #0E9384; /* Teal */
102
+ --chart-3: #C27A00; /* Amber */
103
+ --chart-4: #A855F7; /* Purple */
104
+ --chart-5: #4B5267; /* Slate */
105
+
98
106
  /* Avatar badges — the same in both themes: they mark the person, not the page. The white mark
99
107
  on each passes 3:1 (super connector 3.3–6.0, warning 3.6). */
100
108
  --super-connector-from: #6A3AF3;
@@ -210,6 +218,13 @@
210
218
  --honey: #F5C451;
211
219
  --honey-text: #F5C451;
212
220
 
221
+ /* Chart series — lightened for dark surfaces: each passes 3:1 on --surface-primary and --surface-secondary. */
222
+ --chart-1: #4D7AFF;
223
+ --chart-2: #2DD4BF;
224
+ --chart-3: #F5C451;
225
+ --chart-4: #C4A1FF;
226
+ --chart-5: #6B7189;
227
+
213
228
  /* Avatar badges — the same in both themes: they mark the person, not the page. The white mark
214
229
  on each passes 3:1 (super connector 3.3–6.0, warning 3.6). */
215
230
  --super-connector-from: #6A3AF3;