orbital-ds 0.9.0 → 0.10.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 (71) hide show
  1. package/AGENTS.md +22 -2
  2. package/components.manifest.json +388 -1
  3. package/contract.json +5 -0
  4. package/dist/hooks/use-ds-messages.d.ts +59 -1
  5. package/dist/hooks/use-ds-messages.js +6 -0
  6. package/dist/lib/echarts-presets.d.ts +153 -0
  7. package/dist/lib/echarts-presets.js +311 -0
  8. package/dist/lib/echarts-server.d.ts +15 -0
  9. package/dist/lib/echarts-server.js +15 -0
  10. package/dist/lib/echarts-setup.d.ts +8 -0
  11. package/dist/lib/echarts-setup.js +68 -0
  12. package/dist/lib/echarts-theme.d.ts +36 -0
  13. package/dist/lib/echarts-theme.js +142 -0
  14. package/dist/lib/i18n.d.ts +57 -1
  15. package/dist/lib/i18n.js +169 -3
  16. package/dist/styles.css +43 -5
  17. package/dist/themes/friendly.css +3 -1
  18. package/dist/themes/friendly.scoped.css +3 -1
  19. package/dist/themes/friendly.tokens.json +45 -0
  20. package/dist/themes/qratia.tokens.json +49 -0
  21. package/dist/themes/tactile.css +3 -1
  22. package/dist/themes/tactile.scoped.css +3 -1
  23. package/dist/themes/tactile.tokens.json +42 -0
  24. package/dist/themes/twitter.css +3 -1
  25. package/dist/themes/twitter.scoped.css +3 -1
  26. package/dist/themes/twitter.tokens.json +45 -0
  27. package/dist/themes/zyro.css +3 -1
  28. package/dist/themes/zyro.scoped.css +3 -1
  29. package/dist/themes/zyro.tokens.json +46 -0
  30. package/dist/ui/calendar.js +4 -0
  31. package/dist/ui/code-block.d.ts +14 -0
  32. package/dist/ui/code-block.js +106 -0
  33. package/dist/ui/data-table.d.ts +185 -0
  34. package/dist/ui/data-table.js +714 -0
  35. package/dist/ui/date-picker.d.ts +65 -0
  36. package/dist/ui/date-picker.js +362 -0
  37. package/dist/ui/dropzone.d.ts +42 -0
  38. package/dist/ui/dropzone.js +220 -0
  39. package/dist/ui/echart.d.ts +31 -0
  40. package/dist/ui/echart.js +88 -0
  41. package/dist/ui/eyebrow.d.ts +7 -0
  42. package/dist/ui/eyebrow.js +16 -0
  43. package/dist/ui/filter-bar.d.ts +36 -0
  44. package/dist/ui/filter-bar.js +193 -0
  45. package/dist/ui/heatmap-grid.d.ts +39 -0
  46. package/dist/ui/heatmap-grid.js +195 -0
  47. package/dist/ui/i18n-provider.js +3 -3
  48. package/dist/ui/legend.d.ts +30 -0
  49. package/dist/ui/legend.js +124 -0
  50. package/dist/ui/notifications.d.ts +69 -0
  51. package/dist/ui/notifications.js +335 -0
  52. package/dist/ui/page-header.d.ts +19 -0
  53. package/dist/ui/page-header.js +132 -0
  54. package/dist/ui/panel.d.ts +12 -0
  55. package/dist/ui/panel.js +41 -0
  56. package/dist/ui/proportion-bar.d.ts +27 -0
  57. package/dist/ui/proportion-bar.js +92 -0
  58. package/dist/ui/sparkline.d.ts +26 -0
  59. package/dist/ui/sparkline.js +97 -0
  60. package/dist/ui/stat.d.ts +61 -0
  61. package/dist/ui/stat.js +238 -0
  62. package/dist/ui/status-badge.d.ts +38 -0
  63. package/dist/ui/status-badge.js +153 -0
  64. package/dist/ui/stepper.d.ts +20 -0
  65. package/dist/ui/stepper.js +152 -0
  66. package/dist/ui/timeline.d.ts +29 -0
  67. package/dist/ui/timeline.js +157 -0
  68. package/docs/GRAFICOS.md +125 -0
  69. package/docs/adr/0001-rtl-clases-logicas.md +78 -0
  70. package/package.json +17 -4
  71. package/scripts/init.mjs +1 -0
@@ -0,0 +1,41 @@
1
+ import { mergeProps } from "@base-ui/react/merge-props";
2
+ import { useRender } from "@base-ui/react/use-render";
3
+ import { cva } from "class-variance-authority";
4
+ import { cn } from "../lib/utils";
5
+ const panelVariants = cva("group/panel min-w-0 rounded-card text-sm", {
6
+ variants: {
7
+ variant: {
8
+ default: "border border-border bg-card text-card-foreground shadow-card",
9
+ muted: "bg-inset text-inset-foreground",
10
+ outline: "border border-border",
11
+ ghost: ""
12
+ },
13
+ size: {
14
+ sm: "p-(--ds-panel-p-sm)",
15
+ md: "p-(--ds-panel-p)",
16
+ lg: "p-(--ds-panel-p-lg)"
17
+ }
18
+ },
19
+ defaultVariants: {
20
+ variant: "default",
21
+ size: "md"
22
+ }
23
+ });
24
+ function Panel({
25
+ className,
26
+ variant = "default",
27
+ size = "md",
28
+ render,
29
+ ...props
30
+ }) {
31
+ return useRender({
32
+ defaultTagName: "div",
33
+ props: mergeProps({ className: cn(panelVariants({ variant, size }), className) }, props),
34
+ render,
35
+ state: { slot: "panel", variant, size }
36
+ });
37
+ }
38
+ export {
39
+ Panel,
40
+ panelVariants
41
+ };
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { DsDataTone } from './legend.js';
3
+
4
+ interface ProportionSegment {
5
+ value: number;
6
+ tone?: DsDataTone;
7
+ /** Nombre del segmento (para el texto accesible y el tooltip nativo). */
8
+ label?: string;
9
+ }
10
+ declare function ProportionBar({ className, value, max, segments, tone, label, showValue, unknown, formatValue, ...props }: Omit<React.ComponentProps<"div">, "children"> & {
11
+ /** Parte del total (sin `segments`). `null`/`undefined` sin segmentos = sin dato. */
12
+ value?: number | null;
13
+ /** Total (por defecto 100). */
14
+ max?: number;
15
+ segments?: ProportionSegment[];
16
+ tone?: DsDataTone;
17
+ /** Etiqueta visible sobre la barra (y nombre accesible). */
18
+ label?: React.ReactNode;
19
+ /** Muestra el valor formateado junto a la etiqueta. */
20
+ showValue?: boolean;
21
+ /** Sin dato: rayado neutro, nunca una barra a 0. */
22
+ unknown?: boolean;
23
+ /** Formato del valor (por defecto, porcentaje en el idioma activo). */
24
+ formatValue?: (value: number, max: number) => string;
25
+ }): React.JSX.Element;
26
+
27
+ export { ProportionBar, type ProportionSegment };
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { useDsLocale, useDsMessages } from "../hooks/use-ds-messages";
5
+ import { cn } from "../lib/utils";
6
+ import { dataToneBg } from "./legend";
7
+ const HATCH = "var(--ds-hatch)";
8
+ function ProportionBar({
9
+ className,
10
+ value,
11
+ max = 100,
12
+ segments,
13
+ tone = "primary",
14
+ label,
15
+ showValue = false,
16
+ unknown = false,
17
+ formatValue,
18
+ ...props
19
+ }) {
20
+ const t = useDsMessages();
21
+ const locale = useDsLocale();
22
+ const labelId = React.useId();
23
+ const total = segments ? segments.reduce((s, x) => s + Math.max(0, x.value), 0) : value;
24
+ const isUnknown = unknown || total == null || !Number.isFinite(total) || max <= 0;
25
+ const safeMax = max > 0 ? max : 1;
26
+ const now = isUnknown ? null : Math.min(Math.max(total, 0), safeMax);
27
+ const percent = React.useMemo(() => new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 1 }), [locale]);
28
+ const format = (v) => formatValue ? formatValue(v, safeMax) : percent.format(v / safeMax);
29
+ const valueText = now == null ? t.statNoData : segments?.length ? segments.map((s) => s.label ? `${s.label}: ${format(s.value)}` : format(s.value)).join(", ") : format(now);
30
+ const pct = (v) => `${Math.min(Math.max(v, 0), safeMax) / safeMax * 100}%`;
31
+ return /* @__PURE__ */ jsxs(
32
+ "div",
33
+ {
34
+ "data-slot": "proportion-bar",
35
+ "data-state": isUnknown ? "unknown" : "known",
36
+ "data-tone": segments ? void 0 : tone,
37
+ className: cn("flex min-w-0 flex-col gap-1.5", className),
38
+ ...props,
39
+ children: [
40
+ (label || showValue) && /* @__PURE__ */ jsxs("div", { "data-slot": "proportion-bar-header", className: "flex items-baseline justify-between gap-2 text-sm", children: [
41
+ label && /* @__PURE__ */ jsx("span", { id: labelId, "data-slot": "proportion-bar-label", className: "min-w-0 truncate text-muted-foreground", children: label }),
42
+ showValue && /* @__PURE__ */ jsx("span", { "data-slot": "proportion-bar-value", className: "ms-auto font-medium text-foreground tabular-nums", children: now == null ? t.statNoData : format(now) })
43
+ ] }),
44
+ /* @__PURE__ */ jsx(
45
+ "div",
46
+ {
47
+ role: "meter",
48
+ "aria-labelledby": label ? labelId : void 0,
49
+ "aria-valuemin": 0,
50
+ "aria-valuemax": safeMax,
51
+ "aria-valuenow": now ?? void 0,
52
+ "aria-valuetext": valueText,
53
+ "data-slot": "proportion-bar-track",
54
+ className: "flex h-(--ds-proportion-h) w-full overflow-hidden rounded-track bg-muted",
55
+ style: isUnknown ? { backgroundImage: HATCH } : void 0,
56
+ children: !isUnknown && (segments?.length ? segments.map((s, i) => {
57
+ const segTone = s.tone ?? `chart-${i % 5 + 1}`;
58
+ return /* @__PURE__ */ jsx(
59
+ "div",
60
+ {
61
+ "data-slot": "proportion-bar-segment",
62
+ "data-tone": segTone,
63
+ title: s.label,
64
+ className: cn(
65
+ "h-full transition-[width] duration-(--ds-motion-base) ease-(--ds-ease-standard) motion-reduce:transition-none",
66
+ dataToneBg[segTone]
67
+ ),
68
+ style: { width: pct(s.value) }
69
+ },
70
+ i
71
+ );
72
+ }) : /* @__PURE__ */ jsx(
73
+ "div",
74
+ {
75
+ "data-slot": "proportion-bar-indicator",
76
+ "data-tone": tone,
77
+ className: cn(
78
+ "h-full rounded-track transition-[width] duration-(--ds-motion-base) ease-(--ds-ease-standard) motion-reduce:transition-none",
79
+ dataToneBg[tone]
80
+ ),
81
+ style: { width: pct(now) }
82
+ }
83
+ ))
84
+ }
85
+ )
86
+ ]
87
+ }
88
+ );
89
+ }
90
+ export {
91
+ ProportionBar
92
+ };
@@ -0,0 +1,26 @@
1
+ import * as class_variance_authority_types from 'class-variance-authority/types';
2
+ import * as React from 'react';
3
+
4
+ type SparklineSeries = 1 | 2 | 3 | 4 | 5;
5
+ type SparklineTone = "info" | "success" | "warning" | "danger" | "neutral";
6
+ declare const sparklineVariants: (props?: ({
7
+ color?: "current" | "info" | "success" | "warning" | "danger" | "neutral" | "series-1" | "series-2" | "series-3" | "series-4" | "series-5" | null | undefined;
8
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
9
+ type SparklineProps = Omit<React.ComponentProps<"svg">, "children" | "color"> & {
10
+ /** Serie de valores; `null` = sin dato (hueco), nunca cero. */
11
+ data: ReadonlyArray<number | null | undefined>;
12
+ /** Color de serie del tema (--chart-1..5). */
13
+ series?: SparklineSeries;
14
+ /** Color de un estado. Si no hay `series` ni `tone`, usa el color del texto. */
15
+ tone?: SparklineTone;
16
+ /** Rellena el área bajo la línea con el mismo color, atenuado. */
17
+ area?: boolean;
18
+ /** Límites del eje vertical (por defecto, mínimo y máximo de los datos). */
19
+ min?: number;
20
+ max?: number;
21
+ /** Descripción accesible. Sin ella la línea es decorativa (aria-hidden). */
22
+ label?: string;
23
+ };
24
+ declare function Sparkline({ data, series, tone, area, min, max, label, className, ...props }: SparklineProps): React.JSX.Element;
25
+
26
+ export { Sparkline, type SparklineProps, type SparklineSeries, type SparklineTone, sparklineVariants };
@@ -0,0 +1,97 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { cva } from "class-variance-authority";
3
+ import { cn } from "../lib/utils";
4
+ const sparklineVariants = cva(
5
+ "block h-(--ds-sparkline-h) w-full overflow-visible fill-none stroke-current stroke-(length:--ds-sparkline-w)",
6
+ {
7
+ variants: {
8
+ color: {
9
+ current: "",
10
+ "series-1": "text-chart-1",
11
+ "series-2": "text-chart-2",
12
+ "series-3": "text-chart-3",
13
+ "series-4": "text-chart-4",
14
+ "series-5": "text-chart-5",
15
+ info: "text-info",
16
+ success: "text-success",
17
+ warning: "text-warning",
18
+ danger: "text-danger",
19
+ neutral: "text-neutral"
20
+ }
21
+ },
22
+ defaultVariants: { color: "current" }
23
+ }
24
+ );
25
+ const VIEW_W = 100;
26
+ const VIEW_H = 100;
27
+ function segments(data, min, max) {
28
+ const out = [];
29
+ let current = [];
30
+ const span = max - min;
31
+ const step = data.length > 1 ? VIEW_W / (data.length - 1) : 0;
32
+ data.forEach((v, i) => {
33
+ if (v == null || !Number.isFinite(v)) {
34
+ if (current.length) out.push(current);
35
+ current = [];
36
+ return;
37
+ }
38
+ const x = data.length > 1 ? i * step : VIEW_W / 2;
39
+ const y = span === 0 ? VIEW_H / 2 : VIEW_H - (v - min) / span * VIEW_H;
40
+ current.push({ x, y });
41
+ });
42
+ if (current.length) out.push(current);
43
+ return out;
44
+ }
45
+ function linePath(seg) {
46
+ const [first, ...rest] = seg;
47
+ if (!rest.length) return `M${first.x} ${first.y}l0 0`;
48
+ return `M${first.x} ${first.y}` + rest.map((p) => `L${p.x} ${p.y}`).join("");
49
+ }
50
+ function areaPath(seg) {
51
+ if (seg.length < 2) return null;
52
+ const first = seg[0];
53
+ const last = seg[seg.length - 1];
54
+ return `${linePath(seg)}L${last.x} ${VIEW_H}L${first.x} ${VIEW_H}Z`;
55
+ }
56
+ function Sparkline({ data, series, tone, area = false, min, max, label, className, ...props }) {
57
+ const finite = data.filter((v) => v != null && Number.isFinite(v));
58
+ const lo = min ?? (finite.length ? Math.min(...finite) : 0);
59
+ const hi = max ?? (finite.length ? Math.max(...finite) : 0);
60
+ const segs = segments(data, lo, hi);
61
+ const color = series ? `series-${series}` : tone ?? "current";
62
+ return /* @__PURE__ */ jsxs(
63
+ "svg",
64
+ {
65
+ "data-slot": "sparkline",
66
+ "data-state": finite.length ? "filled" : "empty",
67
+ "data-tone": tone,
68
+ "data-series": series,
69
+ viewBox: `0 0 ${VIEW_W} ${VIEW_H}`,
70
+ preserveAspectRatio: "none",
71
+ ...label ? { role: "img", "aria-label": label } : { "aria-hidden": true, focusable: false },
72
+ className: cn(sparklineVariants({ color }), className),
73
+ ...props,
74
+ children: [
75
+ area && segs.map((seg, i) => {
76
+ const d = areaPath(seg);
77
+ return d ? /* @__PURE__ */ jsx("path", { "data-slot": "sparkline-area", d, className: "fill-current/15 stroke-none" }, `a${i}`) : null;
78
+ }),
79
+ segs.map((seg, i) => /* @__PURE__ */ jsx(
80
+ "path",
81
+ {
82
+ "data-slot": "sparkline-line",
83
+ d: linePath(seg),
84
+ vectorEffect: "non-scaling-stroke",
85
+ strokeLinecap: "round",
86
+ strokeLinejoin: "round"
87
+ },
88
+ `l${i}`
89
+ ))
90
+ ]
91
+ }
92
+ );
93
+ }
94
+ export {
95
+ Sparkline,
96
+ sparklineVariants
97
+ };
@@ -0,0 +1,61 @@
1
+ import * as class_variance_authority_types from 'class-variance-authority/types';
2
+ import * as React from 'react';
3
+
4
+ type StatVariant = "card" | "inline";
5
+ type StatSize = "sm" | "md" | "lg";
6
+ type StatTone = "neutral" | "good" | "warn" | "bad";
7
+ declare const statVariants: (props?: ({
8
+ variant?: "inline" | "card" | null | undefined;
9
+ tone?: "neutral" | "good" | "warn" | "bad" | null | undefined;
10
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
11
+ type StatProps = Omit<React.ComponentProps<"div">, "ref"> & {
12
+ variant?: StatVariant;
13
+ /** Tamaño fijo de la cifra; sin él, se adapta al ancho del contenedor. */
14
+ size?: StatSize;
15
+ tone?: StatTone;
16
+ };
17
+ declare function Stat({ className, variant, size, tone, children, ...props }: StatProps): React.JSX.Element;
18
+ declare function StatLabel({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
19
+ type StatValueProps = Omit<React.ComponentProps<"div">, "children"> & {
20
+ /** Número (se formatea con Intl en el idioma activo), texto ya formateado o null = sin dato. */
21
+ value: number | string | null | undefined;
22
+ /** Unidad o sufijo pegado a la cifra («min», «%», «llamadas»). */
23
+ unit?: React.ReactNode;
24
+ /** Texto antes de la cifra (p. ej. «≈»). */
25
+ prefix?: React.ReactNode;
26
+ /** Opciones de Intl.NumberFormat (moneda, compacto, porcentaje sobre 1…). */
27
+ format?: Intl.NumberFormatOptions;
28
+ /** Decimales fijos (atajo de minimum/maximumFractionDigits). */
29
+ fractionDigits?: number;
30
+ /** Motivo de que no haya dato; se muestra en un tooltip y se lee con «Sin dato». */
31
+ reason?: React.ReactNode;
32
+ /** Cargando: esqueleto en lugar de la cifra. */
33
+ loading?: boolean;
34
+ /** Signo que sustituye a la cifra cuando no hay dato. */
35
+ placeholder?: React.ReactNode;
36
+ };
37
+ declare function StatValue({ value, unit, prefix, format, fractionDigits, reason, loading, placeholder, className, ...props }: StatValueProps): React.JSX.Element;
38
+ type StatDeltaPolarity = "higher-is-better" | "lower-is-better" | "neutral";
39
+ type StatDeltaProps = Omit<React.ComponentProps<"div">, "children"> & {
40
+ /** Variación en PUNTOS PORCENTUALES (4.2 = +4,2 %). null = sin dato (nunca 0). */
41
+ value: number | null | undefined;
42
+ /** Qué dirección es buena: decide el tono (éxito, peligro o neutro). */
43
+ polarity?: StatDeltaPolarity;
44
+ fractionDigits?: number;
45
+ /** Texto propio en lugar de la cifra formateada (p. ej. «+12 llamadas»). */
46
+ children?: React.ReactNode;
47
+ };
48
+ declare function StatDelta({ value, polarity, fractionDigits, className, children, ...props }: StatDeltaProps): React.JSX.Element;
49
+ declare function StatDescription({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
50
+ /** Hueco para una Sparkline u otro gráfico mínimo bajo la cifra. */
51
+ declare function StatChart({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
52
+ type StatSwatchProps = React.ComponentProps<"span"> & {
53
+ /** Color de serie del tema (--chart-1..5). */
54
+ series?: 1 | 2 | 3 | 4 | 5;
55
+ /** O el color de un estado. */
56
+ tone?: "info" | "success" | "warning" | "danger" | "neutral";
57
+ };
58
+ /** Muestra de color que liga el KPI con su serie en un gráfico. Decorativa. */
59
+ declare function StatSwatch({ series, tone, className, ...props }: StatSwatchProps): React.JSX.Element;
60
+
61
+ export { Stat, StatChart, StatDelta, type StatDeltaPolarity, type StatDeltaProps, StatDescription, StatLabel, type StatProps, type StatSize, StatSwatch, type StatSwatchProps, type StatTone, StatValue, type StatValueProps, type StatVariant, statVariants };
@@ -0,0 +1,238 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { cva } from "class-variance-authority";
5
+ import { ArrowDownIcon, ArrowUpIcon, MinusIcon } from "lucide-react";
6
+ import { useDsLocale, useDsMessages } from "../hooks/use-ds-messages";
7
+ import { cn } from "../lib/utils";
8
+ import { eyebrowClassName } from "./eyebrow";
9
+ import { Panel } from "./panel";
10
+ import { Skeleton } from "./skeleton";
11
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
12
+ const StatContext = React.createContext({ variant: "card", size: "auto", labelId: "" });
13
+ const statVariants = cva("group/stat @container/stat min-w-0", {
14
+ variants: {
15
+ variant: {
16
+ card: "flex flex-col gap-1.5",
17
+ inline: "inline-flex flex-wrap items-baseline gap-x-2 gap-y-1"
18
+ },
19
+ tone: {
20
+ neutral: "",
21
+ good: "",
22
+ warn: "",
23
+ bad: ""
24
+ }
25
+ },
26
+ compoundVariants: [
27
+ // Tarjeta: el filete toma el color del estado y se engrosa en el borde de inicio.
28
+ {
29
+ variant: "card",
30
+ tone: ["good", "warn", "bad"],
31
+ className: "[border-inline-start-width:var(--ds-stat-accent-w)]"
32
+ },
33
+ { variant: "card", tone: "good", className: "border-success/40 border-s-success" },
34
+ { variant: "card", tone: "warn", className: "border-warning/40 border-s-warning" },
35
+ { variant: "card", tone: "bad", className: "border-danger/40 border-s-danger" },
36
+ // En línea: el estado colorea la cifra (pares de texto AA comprobados por check:ds).
37
+ { variant: "inline", tone: "good", className: "**:data-[slot=stat-value]:text-success" },
38
+ { variant: "inline", tone: "warn", className: "**:data-[slot=stat-value]:text-warning" },
39
+ { variant: "inline", tone: "bad", className: "**:data-[slot=stat-value]:text-danger" }
40
+ ],
41
+ defaultVariants: { variant: "card", tone: "neutral" }
42
+ });
43
+ const statValueSize = {
44
+ sm: "text-xl",
45
+ md: "text-3xl",
46
+ lg: "text-4xl",
47
+ auto: "text-2xl @3xs/stat:text-3xl @xs/stat:text-4xl"
48
+ };
49
+ function Stat({ className, variant = "card", size, tone = "neutral", children, ...props }) {
50
+ const labelId = React.useId();
51
+ const ctx = React.useMemo(() => ({ variant, size: size ?? "auto", labelId }), [variant, size, labelId]);
52
+ const shared = {
53
+ "data-slot": "stat",
54
+ "data-variant": variant,
55
+ "data-size": size ?? "auto",
56
+ "data-tone": tone,
57
+ className: cn(statVariants({ variant, tone }), className)
58
+ };
59
+ return /* @__PURE__ */ jsx(StatContext.Provider, { value: ctx, children: variant === "card" ? /* @__PURE__ */ jsx(Panel, { role: "group", "aria-labelledby": labelId, ...shared, ...props, children }) : /* @__PURE__ */ jsx("dl", { ...shared, ...props, children }) });
60
+ }
61
+ function StatPart({
62
+ term = false,
63
+ ...props
64
+ }) {
65
+ const { variant } = React.useContext(StatContext);
66
+ if (variant === "inline") {
67
+ const Tag = term ? "dt" : "dd";
68
+ return /* @__PURE__ */ jsx(Tag, { ...props });
69
+ }
70
+ return /* @__PURE__ */ jsx("div", { ...props });
71
+ }
72
+ function StatLabel({ className, ...props }) {
73
+ const { labelId } = React.useContext(StatContext);
74
+ return /* @__PURE__ */ jsx(StatPart, { term: true, id: labelId, "data-slot": "stat-label", className: cn(eyebrowClassName, className), ...props });
75
+ }
76
+ function StatValue({
77
+ value,
78
+ unit,
79
+ prefix,
80
+ format,
81
+ fractionDigits,
82
+ reason,
83
+ loading = false,
84
+ placeholder = "\u2014",
85
+ className,
86
+ ...props
87
+ }) {
88
+ const t = useDsMessages();
89
+ const locale = useDsLocale();
90
+ const stat = React.useContext(StatContext);
91
+ const formatted = React.useMemo(() => {
92
+ if (typeof value !== "number" || !Number.isFinite(value)) return typeof value === "string" ? value : null;
93
+ const digits = fractionDigits == null ? {} : { minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits };
94
+ return new Intl.NumberFormat(locale, { ...format, ...digits }).format(value);
95
+ }, [value, format, fractionDigits, locale]);
96
+ const state = loading ? "loading" : formatted == null ? "empty" : "filled";
97
+ const base = cn(
98
+ "flex items-baseline gap-1 leading-none font-(--ds-stat-value-weight) text-foreground tabular-nums",
99
+ stat.variant === "inline" ? "text-base" : statValueSize[stat.size],
100
+ className
101
+ );
102
+ if (loading) {
103
+ return /* @__PURE__ */ jsxs(StatPart, { "data-slot": "stat-value", "data-state": state, "aria-busy": "true", className: base, ...props, children: [
104
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-lh w-16" }),
105
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: t.loading })
106
+ ] });
107
+ }
108
+ if (formatted == null) {
109
+ const spoken = reason ? /* @__PURE__ */ jsxs(Fragment, { children: [
110
+ t.statNoData,
111
+ ": ",
112
+ reason
113
+ ] }) : t.statNoData;
114
+ const mark = /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: placeholder });
115
+ return /* @__PURE__ */ jsx(StatPart, { "data-slot": "stat-value", "data-state": state, className: base, ...props, children: reason ? /* @__PURE__ */ jsxs(Tooltip, { children: [
116
+ /* @__PURE__ */ jsxs(
117
+ TooltipTrigger,
118
+ {
119
+ render: /* @__PURE__ */ jsx("span", { tabIndex: 0 }),
120
+ "data-slot": "stat-value-reason",
121
+ className: "cursor-help rounded-control underline decoration-dotted decoration-muted-foreground underline-offset-4 outline-none focus-visible:ring-(length:--ds-ring-width) focus-visible:ring-(--ds-ring-color)",
122
+ children: [
123
+ mark,
124
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: spoken })
125
+ ]
126
+ }
127
+ ),
128
+ /* @__PURE__ */ jsx(TooltipContent, { children: reason })
129
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
130
+ mark,
131
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: spoken })
132
+ ] }) });
133
+ }
134
+ return /* @__PURE__ */ jsxs(StatPart, { "data-slot": "stat-value", "data-state": state, className: base, ...props, children: [
135
+ prefix != null && /* @__PURE__ */ jsx("span", { "data-slot": "stat-value-prefix", className: "text-sm text-muted-foreground", children: prefix }),
136
+ /* @__PURE__ */ jsx("span", { "data-slot": "stat-value-number", children: formatted }),
137
+ unit != null && /* @__PURE__ */ jsx("span", { "data-slot": "stat-value-unit", className: "text-sm font-(--ds-label-weight) text-muted-foreground", children: unit })
138
+ ] });
139
+ }
140
+ function StatDelta({
141
+ value,
142
+ polarity = "higher-is-better",
143
+ fractionDigits = 1,
144
+ className,
145
+ children,
146
+ ...props
147
+ }) {
148
+ const t = useDsMessages();
149
+ const locale = useDsLocale();
150
+ const empty = value == null || !Number.isFinite(value);
151
+ const direction = empty ? "empty" : value > 0 ? "increase" : value < 0 ? "decrease" : "unchanged";
152
+ const good = polarity === "higher-is-better" ? "increase" : polarity === "lower-is-better" ? "decrease" : null;
153
+ const tone = direction === "empty" || direction === "unchanged" || good == null ? "neutral" : direction === good ? "success" : "danger";
154
+ const text = empty ? null : new Intl.NumberFormat(locale, {
155
+ style: "percent",
156
+ signDisplay: "exceptZero",
157
+ minimumFractionDigits: fractionDigits,
158
+ maximumFractionDigits: fractionDigits
159
+ }).format(value / 100);
160
+ const spoken = direction === "increase" ? t.statIncrease : direction === "decrease" ? t.statDecrease : direction === "unchanged" ? t.statNoChange : t.statNoData;
161
+ const Icon = direction === "increase" ? ArrowUpIcon : direction === "decrease" ? ArrowDownIcon : MinusIcon;
162
+ return /* @__PURE__ */ jsxs(
163
+ StatPart,
164
+ {
165
+ "data-slot": "stat-delta",
166
+ "data-state": direction,
167
+ "data-tone": tone,
168
+ className: cn(
169
+ "inline-flex w-fit items-center gap-0.5 rounded-badge px-(--ds-badge-px) py-(--ds-badge-py) text-xs font-(--ds-label-weight) tabular-nums [&>svg]:size-3 [&>svg]:shrink-0",
170
+ tone === "success" && "bg-success-soft text-success",
171
+ tone === "danger" && "bg-danger-soft text-danger",
172
+ tone === "neutral" && "bg-neutral-soft text-neutral",
173
+ className
174
+ ),
175
+ ...props,
176
+ children: [
177
+ /* @__PURE__ */ jsx(Icon, { "aria-hidden": "true" }),
178
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
179
+ spoken,
180
+ " "
181
+ ] }),
182
+ empty ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2014" }) : children ?? text
183
+ ]
184
+ }
185
+ );
186
+ }
187
+ function StatDescription({ className, ...props }) {
188
+ return /* @__PURE__ */ jsx(
189
+ StatPart,
190
+ {
191
+ "data-slot": "stat-description",
192
+ className: cn("text-xs text-muted-foreground", className),
193
+ ...props
194
+ }
195
+ );
196
+ }
197
+ function StatChart({ className, ...props }) {
198
+ return /* @__PURE__ */ jsx(StatPart, { "data-slot": "stat-chart", className: cn("mt-1 min-w-0", className), ...props });
199
+ }
200
+ const swatchColor = {
201
+ 1: "bg-chart-1",
202
+ 2: "bg-chart-2",
203
+ 3: "bg-chart-3",
204
+ 4: "bg-chart-4",
205
+ 5: "bg-chart-5",
206
+ info: "bg-info",
207
+ success: "bg-success",
208
+ warning: "bg-warning",
209
+ danger: "bg-danger",
210
+ neutral: "bg-neutral"
211
+ };
212
+ function StatSwatch({ series, tone, className, ...props }) {
213
+ return /* @__PURE__ */ jsx(
214
+ "span",
215
+ {
216
+ "data-slot": "stat-swatch",
217
+ "data-series": series,
218
+ "data-tone": tone,
219
+ "aria-hidden": "true",
220
+ className: cn(
221
+ "inline-block size-(--ds-legend-swatch) shrink-0 rounded-xs align-middle",
222
+ swatchColor[series ?? tone ?? 1],
223
+ className
224
+ ),
225
+ ...props
226
+ }
227
+ );
228
+ }
229
+ export {
230
+ Stat,
231
+ StatChart,
232
+ StatDelta,
233
+ StatDescription,
234
+ StatLabel,
235
+ StatSwatch,
236
+ StatValue,
237
+ statVariants
238
+ };
@@ -0,0 +1,38 @@
1
+ import * as class_variance_authority_types from 'class-variance-authority/types';
2
+ import * as React from 'react';
3
+
4
+ type StatusLevel = "critical" | "warning" | "ok" | "info" | "neutral" | "none";
5
+ type StatusBadgeVariant = "soft" | "dot" | "outline";
6
+ declare const statusDotVariants: (props?: ({
7
+ level?: "none" | "info" | "warning" | "neutral" | "critical" | "ok" | null | undefined;
8
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
9
+ type StatusDotProps = Omit<React.ComponentProps<"span">, "children"> & {
10
+ level?: StatusLevel;
11
+ pulse?: boolean;
12
+ /** Texto accesible. Sin él el punto es decorativo: acompáñalo de texto visible. */
13
+ label?: string;
14
+ };
15
+ /** Punto de estado suelto. Sin `label` es decorativo: pon el texto al lado. */
16
+ declare function StatusDot({ level, pulse, label, className, ...props }: StatusDotProps): React.JSX.Element;
17
+ declare const statusBadgeVariants: (props?: ({
18
+ variant?: "outline" | "dot" | "soft" | null | undefined;
19
+ level?: "none" | "info" | "warning" | "neutral" | "critical" | "ok" | null | undefined;
20
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
21
+ type StatusBadgeProps = Omit<React.ComponentProps<"span">, "children"> & {
22
+ level?: StatusLevel;
23
+ variant?: StatusBadgeVariant;
24
+ /** Latido del punto (para lo que está pasando ahora). Respeta el movimiento reducido. */
25
+ pulse?: boolean;
26
+ /** Texto del estado. Obligatorio salvo en `level="none"` (por defecto, «Sin dato»). */
27
+ children?: React.ReactNode;
28
+ /** Explicación en un popover al pulsar: usa StatusExplanation (qué significa / por qué / qué hacer). */
29
+ explanation?: React.ReactNode;
30
+ };
31
+ declare function StatusBadge({ level, variant, pulse, explanation, className, children, ...props }: StatusBadgeProps): React.JSX.Element;
32
+ /** Cuerpo estructurado de la explicación: pares término / detalle. */
33
+ declare function StatusExplanation({ className, ...props }: React.ComponentProps<"dl">): React.JSX.Element;
34
+ /** Encabezado de un bloque («Qué significa», «Por qué», «Qué hacer»): el texto lo pone la app. */
35
+ declare function StatusExplanationTerm({ className, ...props }: React.ComponentProps<"dt">): React.JSX.Element;
36
+ declare function StatusExplanationDetail({ className, ...props }: React.ComponentProps<"dd">): React.JSX.Element;
37
+
38
+ export { StatusBadge, type StatusBadgeProps, type StatusBadgeVariant, StatusDot, type StatusDotProps, StatusExplanation, StatusExplanationDetail, StatusExplanationTerm, type StatusLevel, statusBadgeVariants, statusDotVariants };