@meetreeve/ui 0.27.0 → 0.30.0

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/README.md CHANGED
@@ -657,6 +657,10 @@ chart in a tenant's brand colours, set those variables. Hosts that don't import
657
657
  (`BAR_CATEGORY_GAP = "8.33%"` per side), no y-axis, the value above each bar.
658
658
  An all-negative series tops out at 0 (DEV-16977). Hand-rolled Recharts bar
659
659
  charts spread `BAR_STANDARD` and render `<LabelList content={barValueLabel(fmt)} />`.
660
+ - **Funnels:** `<BarChart funnel />` adds a faint silhouette behind the bars
661
+ that slopes from each bar's top to the next (DEV-19691). Single series
662
+ only (ignored otherwise); no tooltip or legend entry. Use it only when the
663
+ steps are a real funnel, each a subset of the one before.
660
664
  - **Reduced motion:** entry animations are off under `prefers-reduced-motion`.
661
665
  - **`KpiCard`:** `delta` is a fraction (0.12 = +12%). `polarity` decides
662
666
  whether a rise is green or red. `state="empty" | "setup"` replaces raw errors;
@@ -63,6 +63,8 @@ interface TooltipPayloadItem {
63
63
  name: string;
64
64
  value: number;
65
65
  color: string;
66
+ /** The item's `tooltipType`; "none" keeps it out of the tooltip, as in Recharts' default content. */
67
+ type?: string;
66
68
  }
67
69
  interface ChartTooltipContentProps {
68
70
  active?: boolean;
@@ -178,9 +180,18 @@ interface BarChartProps {
178
180
  * (e.g. it is read against a scale rather than per-bar values).
179
181
  */
180
182
  showYAxis?: boolean;
183
+ /**
184
+ * Funnel silhouette (DEV-19691, GA4-style): a soft, low-alpha shape behind
185
+ * the bars that slopes from each bar's top to the next bar's top, so the
186
+ * drop-off between steps reads without the numbers. The bars, value labels,
187
+ * tooltip and cursor are unchanged, and the shape has no tooltip or legend
188
+ * entry. Single series only: with more than one series it is ignored.
189
+ * Default false.
190
+ */
191
+ funnel?: boolean;
181
192
  loading?: boolean;
182
193
  }
183
- declare function BarChart({ data, xKey, series, height, showGrid, showLegend, tooltipFormatter, labelFormatter, showValueLabels, showYAxis, loading, }: BarChartProps): react.JSX.Element;
194
+ declare function BarChart({ data, xKey, series, height, showGrid, showLegend, tooltipFormatter, labelFormatter, showValueLabels, showYAxis, funnel, loading, }: BarChartProps): react.JSX.Element;
184
195
 
185
196
  interface DonutDataItem {
186
197
  name: string;
@@ -63,6 +63,8 @@ interface TooltipPayloadItem {
63
63
  name: string;
64
64
  value: number;
65
65
  color: string;
66
+ /** The item's `tooltipType`; "none" keeps it out of the tooltip, as in Recharts' default content. */
67
+ type?: string;
66
68
  }
67
69
  interface ChartTooltipContentProps {
68
70
  active?: boolean;
@@ -178,9 +180,18 @@ interface BarChartProps {
178
180
  * (e.g. it is read against a scale rather than per-bar values).
179
181
  */
180
182
  showYAxis?: boolean;
183
+ /**
184
+ * Funnel silhouette (DEV-19691, GA4-style): a soft, low-alpha shape behind
185
+ * the bars that slopes from each bar's top to the next bar's top, so the
186
+ * drop-off between steps reads without the numbers. The bars, value labels,
187
+ * tooltip and cursor are unchanged, and the shape has no tooltip or legend
188
+ * entry. Single series only: with more than one series it is ignored.
189
+ * Default false.
190
+ */
191
+ funnel?: boolean;
181
192
  loading?: boolean;
182
193
  }
183
- declare function BarChart({ data, xKey, series, height, showGrid, showLegend, tooltipFormatter, labelFormatter, showValueLabels, showYAxis, loading, }: BarChartProps): react.JSX.Element;
194
+ declare function BarChart({ data, xKey, series, height, showGrid, showLegend, tooltipFormatter, labelFormatter, showValueLabels, showYAxis, funnel, loading, }: BarChartProps): react.JSX.Element;
184
195
 
185
196
  interface DonutDataItem {
186
197
  name: string;
@@ -161,7 +161,8 @@ function ChartSkeleton({ height = 300 }) {
161
161
  );
162
162
  }
163
163
  function ChartTooltipContent({ active, payload, label, formatter }) {
164
- if (!active || !payload?.length) return null;
164
+ const entries = payload?.filter((entry) => entry.type !== "none");
165
+ if (!active || !entries?.length) return null;
165
166
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
166
167
  "div",
167
168
  {
@@ -169,7 +170,7 @@ function ChartTooltipContent({ active, payload, label, formatter }) {
169
170
  style: { background: chartConfig.tooltip.background, border: `1px solid ${chartConfig.tooltip.border}` },
170
171
  children: [
171
172
  label != null && label !== "" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mb-1 font-medium", style: { color: chartConfig.tooltip.label }, children: label }),
172
- payload.map((entry, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "flex items-center gap-2", style: { color: chartConfig.tooltip.text }, children: [
173
+ entries.map((entry, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "flex items-center gap-2", style: { color: chartConfig.tooltip.text }, children: [
173
174
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "inline-block h-2 w-2 rounded-full", style: { backgroundColor: entry.color } }),
174
175
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { color: chartConfig.tooltip.label }, children: [
175
176
  entry.name,
@@ -385,6 +386,7 @@ function LineChart({
385
386
 
386
387
  // src/charts/bar-chart.tsx
387
388
  var import_recharts4 = require("recharts");
389
+ var import_react5 = require("react");
388
390
  var import_jsx_runtime5 = require("react/jsx-runtime");
389
391
  var BAR_CATEGORY_GAP = "8.33%";
390
392
  var BAR_LABEL_FONT_SIZE = chartConfig.axis.fontSize;
@@ -428,6 +430,89 @@ function barValueLabel(format = (v) => v.toLocaleString(), {
428
430
  return BarValueLabel;
429
431
  }
430
432
  var GROUPED_BAR_GAP = 4;
433
+ var FUNNEL_ALPHA = 12;
434
+ var BAR_ANIMATION_MS = 400;
435
+ var BAR_GAP_FRACTION = parseFloat(BAR_CATEGORY_GAP) / 100;
436
+ function barEdges(band) {
437
+ const inset = band * BAR_GAP_FRACTION;
438
+ const raw = band - 2 * inset;
439
+ const width = raw > 1 ? Math.floor(raw) : raw;
440
+ return { right: inset + width - band / 2, left: band / 2 - inset };
441
+ }
442
+ var funnelCurve = (context) => {
443
+ let line = NaN;
444
+ let count = 0;
445
+ let prev = [0, 0];
446
+ return {
447
+ areaStart() {
448
+ line = 0;
449
+ },
450
+ areaEnd() {
451
+ line = NaN;
452
+ },
453
+ lineStart() {
454
+ count = 0;
455
+ },
456
+ lineEnd() {
457
+ if (line || line !== 0 && count === 1) context.closePath();
458
+ line = 1 - line;
459
+ },
460
+ point(x, y) {
461
+ if (count++ === 0) {
462
+ if (line) context.lineTo(x, y);
463
+ else context.moveTo(x, y);
464
+ } else {
465
+ const [px, py] = prev;
466
+ const dir = Math.sign(x - px);
467
+ const { right, left } = barEdges(Math.abs(x - px));
468
+ context.lineTo(px + dir * right, py);
469
+ context.lineTo(x - dir * left, y);
470
+ context.lineTo(x, y);
471
+ }
472
+ prev = [x, y];
473
+ }
474
+ };
475
+ };
476
+ function BandCursor({ bands, fill, points, top = 0, width = 0, height = 0, className }) {
477
+ const x = points?.[0]?.x;
478
+ if (x == null || bands < 1) return null;
479
+ const band = width / bands;
480
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts4.ZIndexLayer, { zIndex: import_recharts4.DefaultZIndexes.cursorRectangle, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
481
+ import_recharts4.Rectangle,
482
+ {
483
+ x: x - band / 2,
484
+ y: top + 0.5,
485
+ width: band,
486
+ height: height - 1,
487
+ fill,
488
+ stroke: "none",
489
+ pointerEvents: "none",
490
+ className
491
+ }
492
+ ) });
493
+ }
494
+ function FunnelSilhouette({ series, animate }) {
495
+ const [entered, setEntered] = (0, import_react5.useState)(false);
496
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
497
+ import_recharts4.Area,
498
+ {
499
+ dataKey: series.dataKey,
500
+ name: series.name,
501
+ type: funnelCurve,
502
+ fill: withAlpha(series.color ?? chartColor(0), FUNNEL_ALPHA),
503
+ fillOpacity: 1,
504
+ stroke: "none",
505
+ dot: false,
506
+ activeDot: false,
507
+ tooltipType: "none",
508
+ legendType: "none",
509
+ isAnimationActive: animate,
510
+ animationBegin: entered ? 0 : BAR_ANIMATION_MS,
511
+ animationDuration: BAR_ANIMATION_MS,
512
+ onAnimationEnd: () => setEntered(true)
513
+ }
514
+ );
515
+ }
431
516
  function BarChart({
432
517
  data,
433
518
  xKey,
@@ -439,13 +524,17 @@ function BarChart({
439
524
  labelFormatter,
440
525
  showValueLabels = true,
441
526
  showYAxis = false,
527
+ funnel = false,
442
528
  loading = false
443
529
  }) {
444
530
  const animate = !usePrefersReducedMotion();
445
531
  const grouped = series.length > 1;
532
+ const silhouette = funnel && series.length === 1;
446
533
  const formatLabel = labelFormatter ?? tooltipFormatter ?? ((v) => v.toLocaleString());
534
+ const cursorFill = withAlpha(chartColor(0), 6);
535
+ const Chart = silhouette ? import_recharts4.ComposedChart : import_recharts4.BarChart;
447
536
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartContainer, { height, loading, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
448
- import_recharts4.BarChart,
537
+ Chart,
449
538
  {
450
539
  data,
451
540
  barCategoryGap: BAR_CATEGORY_GAP,
@@ -489,10 +578,11 @@ function BarChart({
489
578
  import_recharts4.Tooltip,
490
579
  {
491
580
  content: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartTooltipContent, { formatter: tooltipFormatter }),
492
- cursor: { fill: withAlpha(chartColor(0), 6) }
581
+ cursor: silhouette ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BandCursor, { bands: data.length, fill: cursorFill }) : { fill: cursorFill }
493
582
  }
494
583
  ),
495
584
  showLegend && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts4.Legend, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } }),
585
+ silhouette && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FunnelSilhouette, { series: series[0], animate }),
496
586
  series.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
497
587
  import_recharts4.Bar,
498
588
  {
@@ -594,11 +684,11 @@ function RadialChart({ data, max = 100, height = 220, centerValue, centerLabel,
594
684
  }
595
685
 
596
686
  // src/charts/sparkline.tsx
597
- var import_react5 = require("react");
687
+ var import_react6 = require("react");
598
688
  var import_recharts7 = require("recharts");
599
689
  var import_jsx_runtime8 = require("react/jsx-runtime");
600
690
  function Sparkline({ values, color = chartColor(0), height = 32, filled = true }) {
601
- const chartId = `spark-${(0, import_react5.useId)().replace(/:/g, "")}`;
691
+ const chartId = `spark-${(0, import_react6.useId)().replace(/:/g, "")}`;
602
692
  const data = values.filter(Number.isFinite).map((v, i) => ({ i, v }));
603
693
  if (data.length < 2) return null;
604
694
  const id = fillId(chartId, "v", "gradient");
@@ -109,7 +109,8 @@ function ChartSkeleton({ height = 300 }) {
109
109
  );
110
110
  }
111
111
  function ChartTooltipContent({ active, payload, label, formatter }) {
112
- if (!active || !payload?.length) return null;
112
+ const entries = payload?.filter((entry) => entry.type !== "none");
113
+ if (!active || !entries?.length) return null;
113
114
  return /* @__PURE__ */ jsxs(
114
115
  "div",
115
116
  {
@@ -117,7 +118,7 @@ function ChartTooltipContent({ active, payload, label, formatter }) {
117
118
  style: { background: chartConfig.tooltip.background, border: `1px solid ${chartConfig.tooltip.border}` },
118
119
  children: [
119
120
  label != null && label !== "" && /* @__PURE__ */ jsx("p", { className: "mb-1 font-medium", style: { color: chartConfig.tooltip.label }, children: label }),
120
- payload.map((entry, i) => /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2", style: { color: chartConfig.tooltip.text }, children: [
121
+ entries.map((entry, i) => /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2", style: { color: chartConfig.tooltip.text }, children: [
121
122
  /* @__PURE__ */ jsx("span", { className: "inline-block h-2 w-2 rounded-full", style: { backgroundColor: entry.color } }),
122
123
  /* @__PURE__ */ jsxs("span", { style: { color: chartConfig.tooltip.label }, children: [
123
124
  entry.name,
@@ -332,7 +333,22 @@ function LineChart({
332
333
  }
333
334
 
334
335
  // src/charts/bar-chart.tsx
335
- import { Bar, BarChart as RechartsBarChart, CartesianGrid as CartesianGrid3, LabelList, Legend as Legend3, Tooltip as Tooltip4, XAxis as XAxis3, YAxis as YAxis3 } from "recharts";
336
+ import {
337
+ Area as Area2,
338
+ Bar,
339
+ BarChart as RechartsBarChart,
340
+ CartesianGrid as CartesianGrid3,
341
+ ComposedChart,
342
+ DefaultZIndexes,
343
+ LabelList,
344
+ Legend as Legend3,
345
+ Rectangle,
346
+ Tooltip as Tooltip4,
347
+ XAxis as XAxis3,
348
+ YAxis as YAxis3,
349
+ ZIndexLayer
350
+ } from "recharts";
351
+ import { useState } from "react";
336
352
  import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
337
353
  var BAR_CATEGORY_GAP = "8.33%";
338
354
  var BAR_LABEL_FONT_SIZE = chartConfig.axis.fontSize;
@@ -376,6 +392,89 @@ function barValueLabel(format = (v) => v.toLocaleString(), {
376
392
  return BarValueLabel;
377
393
  }
378
394
  var GROUPED_BAR_GAP = 4;
395
+ var FUNNEL_ALPHA = 12;
396
+ var BAR_ANIMATION_MS = 400;
397
+ var BAR_GAP_FRACTION = parseFloat(BAR_CATEGORY_GAP) / 100;
398
+ function barEdges(band) {
399
+ const inset = band * BAR_GAP_FRACTION;
400
+ const raw = band - 2 * inset;
401
+ const width = raw > 1 ? Math.floor(raw) : raw;
402
+ return { right: inset + width - band / 2, left: band / 2 - inset };
403
+ }
404
+ var funnelCurve = (context) => {
405
+ let line = NaN;
406
+ let count = 0;
407
+ let prev = [0, 0];
408
+ return {
409
+ areaStart() {
410
+ line = 0;
411
+ },
412
+ areaEnd() {
413
+ line = NaN;
414
+ },
415
+ lineStart() {
416
+ count = 0;
417
+ },
418
+ lineEnd() {
419
+ if (line || line !== 0 && count === 1) context.closePath();
420
+ line = 1 - line;
421
+ },
422
+ point(x, y) {
423
+ if (count++ === 0) {
424
+ if (line) context.lineTo(x, y);
425
+ else context.moveTo(x, y);
426
+ } else {
427
+ const [px, py] = prev;
428
+ const dir = Math.sign(x - px);
429
+ const { right, left } = barEdges(Math.abs(x - px));
430
+ context.lineTo(px + dir * right, py);
431
+ context.lineTo(x - dir * left, y);
432
+ context.lineTo(x, y);
433
+ }
434
+ prev = [x, y];
435
+ }
436
+ };
437
+ };
438
+ function BandCursor({ bands, fill, points, top = 0, width = 0, height = 0, className }) {
439
+ const x = points?.[0]?.x;
440
+ if (x == null || bands < 1) return null;
441
+ const band = width / bands;
442
+ return /* @__PURE__ */ jsx5(ZIndexLayer, { zIndex: DefaultZIndexes.cursorRectangle, children: /* @__PURE__ */ jsx5(
443
+ Rectangle,
444
+ {
445
+ x: x - band / 2,
446
+ y: top + 0.5,
447
+ width: band,
448
+ height: height - 1,
449
+ fill,
450
+ stroke: "none",
451
+ pointerEvents: "none",
452
+ className
453
+ }
454
+ ) });
455
+ }
456
+ function FunnelSilhouette({ series, animate }) {
457
+ const [entered, setEntered] = useState(false);
458
+ return /* @__PURE__ */ jsx5(
459
+ Area2,
460
+ {
461
+ dataKey: series.dataKey,
462
+ name: series.name,
463
+ type: funnelCurve,
464
+ fill: withAlpha(series.color ?? chartColor(0), FUNNEL_ALPHA),
465
+ fillOpacity: 1,
466
+ stroke: "none",
467
+ dot: false,
468
+ activeDot: false,
469
+ tooltipType: "none",
470
+ legendType: "none",
471
+ isAnimationActive: animate,
472
+ animationBegin: entered ? 0 : BAR_ANIMATION_MS,
473
+ animationDuration: BAR_ANIMATION_MS,
474
+ onAnimationEnd: () => setEntered(true)
475
+ }
476
+ );
477
+ }
379
478
  function BarChart({
380
479
  data,
381
480
  xKey,
@@ -387,13 +486,17 @@ function BarChart({
387
486
  labelFormatter,
388
487
  showValueLabels = true,
389
488
  showYAxis = false,
489
+ funnel = false,
390
490
  loading = false
391
491
  }) {
392
492
  const animate = !usePrefersReducedMotion();
393
493
  const grouped = series.length > 1;
494
+ const silhouette = funnel && series.length === 1;
394
495
  const formatLabel = labelFormatter ?? tooltipFormatter ?? ((v) => v.toLocaleString());
496
+ const cursorFill = withAlpha(chartColor(0), 6);
497
+ const Chart = silhouette ? ComposedChart : RechartsBarChart;
395
498
  return /* @__PURE__ */ jsx5(ChartContainer, { height, loading, children: /* @__PURE__ */ jsxs5(
396
- RechartsBarChart,
499
+ Chart,
397
500
  {
398
501
  data,
399
502
  barCategoryGap: BAR_CATEGORY_GAP,
@@ -437,10 +540,11 @@ function BarChart({
437
540
  Tooltip4,
438
541
  {
439
542
  content: /* @__PURE__ */ jsx5(ChartTooltipContent, { formatter: tooltipFormatter }),
440
- cursor: { fill: withAlpha(chartColor(0), 6) }
543
+ cursor: silhouette ? /* @__PURE__ */ jsx5(BandCursor, { bands: data.length, fill: cursorFill }) : { fill: cursorFill }
441
544
  }
442
545
  ),
443
546
  showLegend && /* @__PURE__ */ jsx5(Legend3, { wrapperStyle: { fontSize: 12, color: chartTokens.muted, paddingTop: 8 } }),
547
+ silhouette && /* @__PURE__ */ jsx5(FunnelSilhouette, { series: series[0], animate }),
444
548
  series.map((s, i) => /* @__PURE__ */ jsx5(
445
549
  Bar,
446
550
  {
@@ -543,7 +647,7 @@ function RadialChart({ data, max = 100, height = 220, centerValue, centerLabel,
543
647
 
544
648
  // src/charts/sparkline.tsx
545
649
  import { useId as useId4 } from "react";
546
- import { Area as Area2, AreaChart as RechartsAreaChart2, YAxis as YAxis4 } from "recharts";
650
+ import { Area as Area3, AreaChart as RechartsAreaChart2, YAxis as YAxis4 } from "recharts";
547
651
  import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
548
652
  function Sparkline({ values, color = chartColor(0), height = 32, filled = true }) {
549
653
  const chartId = `spark-${useId4().replace(/:/g, "")}`;
@@ -554,7 +658,7 @@ function Sparkline({ values, color = chartColor(0), height = 32, filled = true }
554
658
  /* @__PURE__ */ jsx8("defs", { children: /* @__PURE__ */ jsx8(AreaFill, { id, variant: "gradient", color }) }),
555
659
  /* @__PURE__ */ jsx8(YAxis4, { hide: true, domain: ["dataMin", "dataMax"] }),
556
660
  /* @__PURE__ */ jsx8(
557
- Area2,
661
+ Area3,
558
662
  {
559
663
  type: "monotone",
560
664
  dataKey: "v",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetreeve/ui",
3
- "version": "0.27.0",
3
+ "version": "0.30.0",
4
4
  "description": "Shared brand-adaptive UI primitives for MindFortress frontends — min-size tokens, a favicon→logo→monogram BrandGlyph, a responsive header that keeps the search bar usable on mobile, AppSidebar's viewport-driven auto-collapse ladder, the StageRail flow-of-cards primitives, the tenant SiteFooter, the LockedValue/LockedBlock/UnlockCta paywall primitives, the @meetreeve/ui/charts dashboard kit (token-driven charts, KpiCard, ChartCard, DashboardGrid), and @meetreeve/ui/theme (brandTheme: one brand's inputs to contrast-checked light and dark semantic tokens, with the Reeve preset).",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",