@kapiuara/ui 0.10.0 → 0.11.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 +10 -5
- package/dist/components/data/KapiBarChart.d.ts +84 -0
- package/dist/components/data/KapiBarChart.js +87 -0
- package/dist/components/data/KapiEventCalendar.d.ts +70 -0
- package/dist/components/data/KapiEventCalendar.js +225 -0
- package/dist/components/data/KapiHeatmap.d.ts +62 -0
- package/dist/components/data/KapiHeatmap.js +120 -0
- package/dist/components/data/KapiLineChart.d.ts +50 -0
- package/dist/components/data/KapiLineChart.js +105 -0
- package/dist/components/data/KapiPaginationFooter.js +1 -0
- package/dist/components/data/KapiSparkline.d.ts +41 -0
- package/dist/components/data/KapiSparkline.js +55 -0
- package/dist/components/data/KapiTable.js +371 -359
- package/dist/components/data/barChartLogic.d.ts +59 -0
- package/dist/components/data/barChartLogic.js +53 -0
- package/dist/components/data/chartFrame.d.ts +96 -0
- package/dist/components/data/chartFrame.js +89 -0
- package/dist/components/data/eventCalendarLogic.d.ts +70 -0
- package/dist/components/data/eventCalendarLogic.js +45 -0
- package/dist/components/data/heatmapLogic.d.ts +15 -0
- package/dist/components/data/heatmapLogic.js +15 -0
- package/dist/components/data/index.d.ts +19 -0
- package/dist/components/data/lineChartLogic.d.ts +30 -0
- package/dist/components/data/lineChartLogic.js +21 -0
- package/dist/components/data/sparklineLogic.d.ts +28 -0
- package/dist/components/data/sparklineLogic.js +18 -0
- package/dist/components/display/KapiStat.d.ts +1 -1
- package/dist/components/inputs/KapiDatePicker.d.ts +8 -2
- package/dist/components/inputs/KapiDatePicker.js +120 -106
- package/dist/components/inputs/KapiDateRangePicker.d.ts +26 -5
- package/dist/components/inputs/KapiDateRangePicker.js +146 -111
- package/dist/components/inputs/datePickerLogic.d.ts +9 -0
- package/dist/components/inputs/datePickerLogic.js +25 -25
- package/dist/components/inputs/dateRangeLogic.d.ts +23 -4
- package/dist/components/inputs/dateRangeLogic.js +48 -22
- package/dist/components/inputs/facetedSearchLogic.d.ts +1 -1
- package/dist/components/layout/KapiContextSlot.js +108 -88
- package/dist/components/layout/KapiMasonry.d.ts +30 -0
- package/dist/components/layout/KapiMasonry.js +33 -0
- package/dist/components/layout/KapiPageHeader.js +89 -71
- package/dist/components/layout/KapiRail.d.ts +8 -2
- package/dist/components/layout/KapiRail.js +118 -67
- package/dist/components/layout/KapiShell.js +67 -37
- package/dist/components/layout/index.d.ts +2 -0
- package/dist/components/layout/masonryLogic.d.ts +40 -0
- package/dist/components/layout/masonryLogic.js +8 -0
- package/dist/components/layout/railLogic.d.ts +41 -1
- package/dist/components/layout/railLogic.js +36 -4
- package/dist/components/layout/reopenBus.d.ts +53 -0
- package/dist/components/layout/reopenBus.js +6 -0
- package/dist/components/layout/useMasonrySpans.d.ts +32 -0
- package/dist/components/layout/useMasonrySpans.js +44 -0
- package/dist/components/layout/useRailOverflow.d.ts +17 -0
- package/dist/components/layout/useRailOverflow.js +41 -0
- package/dist/components/locale/labelRegistry.d.ts +10 -1
- package/dist/components/navigation/KapiFilterChips.js +1 -1
- package/dist/components/navigation/filterChipsLogic.d.ts +7 -1
- package/dist/components/navigation/filterChipsLogic.js +3 -3
- package/dist/components/overlays/KapiContextMenu.d.ts +3 -0
- package/dist/components/overlays/KapiContextMenu.js +2 -1
- package/dist/components/overlays/KapiDropdown.d.ts +3 -1
- package/dist/components/overlays/KapiDropdown.js +29 -26
- package/dist/components/overlays/KapiMenuButton.js +1 -0
- package/dist/components/overlays/KapiOffcanvasStack.d.ts +2 -2
- package/dist/hooks/breakpointOpenLogic.d.ts +20 -5
- package/dist/hooks/breakpointOpenLogic.js +2 -2
- package/dist/hooks/dataColorLogic.d.ts +23 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/numberFormatLogic.d.ts +7 -0
- package/dist/hooks/numberFormatLogic.js +5 -2
- package/dist/hooks/seriesPaletteLogic.d.ts +24 -0
- package/dist/hooks/themeContrastLogic.js +1 -0
- package/dist/hooks/themeDeriveLogic.d.ts +8 -0
- package/dist/hooks/themeDeriveLogic.js +4 -2
- package/dist/hooks/useKapiTheme.js +27 -27
- package/dist/hooks/useMediaQuery.d.ts +7 -0
- package/dist/hooks/useMediaQuery.js +4 -4
- package/dist/index.js +125 -114
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +2 -6
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
+
import { formatDataValue as t } from "../../hooks/numberFormatLogic.js";
|
|
4
|
+
import { KapiTooltip as n } from "../overlays/KapiTooltip.js";
|
|
5
|
+
import { KapiSegmented as r } from "../inputs/KapiSegmented.js";
|
|
6
|
+
import { useChartTitleId as i, useChartView as a } from "./chartFrame.js";
|
|
7
|
+
import { heatLegendRanges as o, heatMax as s, heatStep as c } from "./heatmapLogic.js";
|
|
8
|
+
/* empty css */
|
|
9
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
10
|
+
import { Fragment as f } from "react";
|
|
11
|
+
//#region src/components/data/KapiHeatmap.tsx
|
|
12
|
+
var p = {
|
|
13
|
+
chartView: "Mapa",
|
|
14
|
+
tableView: "Tabla",
|
|
15
|
+
view: "Vista de los datos",
|
|
16
|
+
rowHeader: "Fila",
|
|
17
|
+
empty: "Sin datos para mostrar",
|
|
18
|
+
noData: "sin dato",
|
|
19
|
+
legend: "Intensidad",
|
|
20
|
+
summary: "Mapa de calor de {rows} filas por {columns} columnas. Cambiá a la vista de tabla para leer los valores."
|
|
21
|
+
}, m = (e) => ({ "--kapi-chart-slot": e > 0 ? `var(--kapi-seq-${e})` : "transparent" });
|
|
22
|
+
function h({ rows: h, columns: g, values: _, title: v, max: y, view: b, defaultView: x = "chart", onViewChange: S, labels: C, className: w, ref: T, ...E }) {
|
|
23
|
+
let D = e("heatmap", p, C), O = i(), { current: k, setView: A } = a(b, x, S), j = y !== void 0 && y > 0 ? y : s(_), M = h.length === 0 || g.length === 0, N = (e, t) => _[e]?.[t], P = D.summary.replace("{rows}", String(h.length)).replace("{columns}", String(g.length));
|
|
24
|
+
return /* @__PURE__ */ d("div", {
|
|
25
|
+
...E,
|
|
26
|
+
ref: T,
|
|
27
|
+
className: ["kapi-heatmap", w].filter(Boolean).join(" "),
|
|
28
|
+
role: "group",
|
|
29
|
+
...v ? { "aria-labelledby": O } : {},
|
|
30
|
+
children: [/* @__PURE__ */ d("div", {
|
|
31
|
+
className: "kapi-heatmap__head",
|
|
32
|
+
children: [v ? /* @__PURE__ */ u("div", {
|
|
33
|
+
className: "kapi-heatmap__title",
|
|
34
|
+
id: O,
|
|
35
|
+
children: v
|
|
36
|
+
}) : null, /* @__PURE__ */ u(r, {
|
|
37
|
+
"aria-label": D.view,
|
|
38
|
+
items: [{
|
|
39
|
+
id: "chart",
|
|
40
|
+
label: D.chartView
|
|
41
|
+
}, {
|
|
42
|
+
id: "table",
|
|
43
|
+
label: D.tableView
|
|
44
|
+
}],
|
|
45
|
+
value: k,
|
|
46
|
+
onChange: A
|
|
47
|
+
})]
|
|
48
|
+
}), M ? /* @__PURE__ */ u("p", {
|
|
49
|
+
className: "kapi-heatmap__empty kapi-muted",
|
|
50
|
+
children: D.empty
|
|
51
|
+
}) : k === "table" ? /* @__PURE__ */ u("div", {
|
|
52
|
+
className: "kapi-heatmap__tablewrap",
|
|
53
|
+
children: /* @__PURE__ */ d("table", {
|
|
54
|
+
className: "kapi-heatmap__table",
|
|
55
|
+
children: [/* @__PURE__ */ u("thead", { children: /* @__PURE__ */ d("tr", { children: [/* @__PURE__ */ u("th", {
|
|
56
|
+
scope: "col",
|
|
57
|
+
children: D.rowHeader
|
|
58
|
+
}), g.map((e, t) => /* @__PURE__ */ u("th", {
|
|
59
|
+
scope: "col",
|
|
60
|
+
children: e
|
|
61
|
+
}, `${e}-${t}`))] }) }), /* @__PURE__ */ u("tbody", { children: h.map((e, n) => /* @__PURE__ */ d("tr", { children: [/* @__PURE__ */ u("th", {
|
|
62
|
+
scope: "row",
|
|
63
|
+
children: e
|
|
64
|
+
}), g.map((e, r) => {
|
|
65
|
+
let i = N(n, r);
|
|
66
|
+
return /* @__PURE__ */ u("td", { children: i === void 0 || !Number.isFinite(i) ? /* @__PURE__ */ u("span", {
|
|
67
|
+
className: "kapi-muted",
|
|
68
|
+
children: D.noData
|
|
69
|
+
}) : t(i) }, `${e}-${r}`);
|
|
70
|
+
})] }, `${e}-${n}`)) })]
|
|
71
|
+
})
|
|
72
|
+
}) : /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("div", {
|
|
73
|
+
className: "kapi-heatmap__plot",
|
|
74
|
+
role: "img",
|
|
75
|
+
"aria-label": P,
|
|
76
|
+
children: /* @__PURE__ */ d("div", {
|
|
77
|
+
className: "kapi-heatmap__grid",
|
|
78
|
+
style: { "--kapi-heatmap-cols": g.length },
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ u("span", { className: "kapi-heatmap__corner" }),
|
|
81
|
+
g.map((e, t) => /* @__PURE__ */ u("span", {
|
|
82
|
+
className: "kapi-heatmap__colhead",
|
|
83
|
+
children: e
|
|
84
|
+
}, `col-${e}-${t}`)),
|
|
85
|
+
h.map((e, r) => /* @__PURE__ */ d(f, { children: [/* @__PURE__ */ u("span", {
|
|
86
|
+
className: "kapi-heatmap__rowhead",
|
|
87
|
+
children: e
|
|
88
|
+
}), g.map((i, a) => {
|
|
89
|
+
let o = N(r, a), s = o === void 0 ? 0 : c(o, j), l = o === void 0 || !Number.isFinite(o) ? D.noData : t(o);
|
|
90
|
+
return /* @__PURE__ */ u(n, {
|
|
91
|
+
label: `${e} · ${i}: ${l}`,
|
|
92
|
+
className: "kapi-heatmap__cellwrap",
|
|
93
|
+
children: /* @__PURE__ */ u("span", {
|
|
94
|
+
className: `kapi-heatmap__cell${s === 0 ? " kapi-heatmap__cell--empty" : ""}`,
|
|
95
|
+
style: m(s)
|
|
96
|
+
})
|
|
97
|
+
}, `cell-${i}-${a}`);
|
|
98
|
+
})] }, `row-${e}-${r}`))
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
}), /* @__PURE__ */ u("ul", {
|
|
102
|
+
className: "kapi-heatmap__legend",
|
|
103
|
+
"aria-label": D.legend,
|
|
104
|
+
children: o(j).map(([e, n], r) => /* @__PURE__ */ d("li", {
|
|
105
|
+
className: "kapi-heatmap__legenditem",
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ u("span", {
|
|
108
|
+
className: "kapi-heatmap__swatch",
|
|
109
|
+
style: m(r + 1)
|
|
110
|
+
}),
|
|
111
|
+
t(Math.round(e)),
|
|
112
|
+
"–",
|
|
113
|
+
t(Math.round(n))
|
|
114
|
+
]
|
|
115
|
+
}, e))
|
|
116
|
+
})] })]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { p as DEFAULT_HEATMAP_LABELS, h as KapiHeatmap };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
3
|
+
import { type KapiChartLabels, type KapiChartView } from "./chartFrame";
|
|
4
|
+
import "./KapiLineChart.css";
|
|
5
|
+
/** Una serie de la línea: un valor por categoría, en el mismo orden que `categories`. */
|
|
6
|
+
export type KapiLineChartSeries = {
|
|
7
|
+
/** Id estable de la serie; clave de React y de la fila en la tabla. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Nombre en la leyenda, en la tabla y en la etiqueta del extremo. */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Un valor por categoría. Lo que falte queda en cero; lo que sobre se ignora. */
|
|
12
|
+
values: readonly number[];
|
|
13
|
+
};
|
|
14
|
+
export type KapiLineChartProps = Omit<HTMLAttributes<HTMLDivElement>, "title" | "children"> & {
|
|
15
|
+
/** Etiquetas del eje horizontal, en orden. Normalmente tiempo. */
|
|
16
|
+
categories: readonly string[];
|
|
17
|
+
/** Series a dibujar. El color sale del slot N de la paleta de datos, en orden y sin ciclar. */
|
|
18
|
+
series: readonly KapiLineChartSeries[];
|
|
19
|
+
/** Título visible. Sin título hay que pasar `aria-label`. */
|
|
20
|
+
title?: ReactNode;
|
|
21
|
+
/** Pasos del eje vertical sobre el cero. @default 4 */
|
|
22
|
+
tickCount?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Rellena el área bajo la línea. **Sólo con una serie**: dos áreas superpuestas se tapan y
|
|
25
|
+
* dejan de poder compararse, así que con más de una se ignora y quedan las líneas.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
area?: boolean;
|
|
29
|
+
/** Vista mostrada, si la controla el consumidor. */
|
|
30
|
+
view?: KapiChartView;
|
|
31
|
+
/** Vista inicial cuando el componente la maneja solo. @default "chart" */
|
|
32
|
+
defaultView?: KapiChartView;
|
|
33
|
+
/** Avisa que se cambió de vista. */
|
|
34
|
+
onViewChange?: (view: KapiChartView) => void;
|
|
35
|
+
/** Textos propios; pisan al provider y a los defaults. */
|
|
36
|
+
labels?: KapiLabelsOverride<KapiChartLabels>;
|
|
37
|
+
/** Ref al contenedor. */
|
|
38
|
+
ref?: Ref<HTMLDivElement>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Gráfico de líneas, para tendencia en el tiempo.
|
|
42
|
+
*
|
|
43
|
+
* Los trazos van en un SVG con `viewBox` de 0 a 100 y `preserveAspectRatio="none"`, así se
|
|
44
|
+
* estiran a cualquier caja sin medirla; el ancho del trazo lo salva `vector-effect`. Todo lo que
|
|
45
|
+
* tiene forma propia —los puntos y cada texto— es HTML posicionado en porcentajes, porque dentro
|
|
46
|
+
* de ese SVG un círculo saldría ovalado y la tipografía deformada.
|
|
47
|
+
*
|
|
48
|
+
* Igual que las barras: la vista de tabla no es opcional, y el plot es `role="img"`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function KapiLineChart({ categories, series, title, tickCount, area, view, defaultView, onViewChange, labels, className, ref, ...rest }: KapiLineChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatDataValue as e } from "../../hooks/numberFormatLogic.js";
|
|
3
|
+
import { KapiTooltip as t } from "../overlays/KapiTooltip.js";
|
|
4
|
+
import { KapiChartFrame as n, chartSummary as r, chartVars as i, useChartLabels as a, useChartTitleId as o, useChartView as s } from "./chartFrame.js";
|
|
5
|
+
import { barHeight as c, barScale as l, barTickLabel as u } from "./barChartLogic.js";
|
|
6
|
+
import { areaPath as d, lineEndpoint as f, linePath as p, linePoints as m } from "./lineChartLogic.js";
|
|
7
|
+
/* empty css */
|
|
8
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
9
|
+
import "react";
|
|
10
|
+
//#region src/components/data/KapiLineChart.tsx
|
|
11
|
+
var _ = 4;
|
|
12
|
+
function v({ categories: v, series: y, title: b, tickCount: x = 4, area: S = !1, view: C, defaultView: w = "chart", onViewChange: T, labels: E, className: D, ref: O, ...k }) {
|
|
13
|
+
let A = a(E), j = o(), { current: M, setView: N } = s(C, w, T), P = y.slice(0, 8);
|
|
14
|
+
y.length > 8 && process.env.NODE_ENV !== "production" && console.warn(`KapiLineChart: ${y.length} series y la paleta tiene 8 slots. Se dibujan las primeras 8; agrupá el resto en vez de perderlo.`);
|
|
15
|
+
let F = (e, t) => P[e]?.values[t] ?? 0, I = P.flatMap((e) => v.map((t, n) => e.values[n] ?? 0)), { max: L, ticks: R } = l(I, x), z = P.map((e) => m(e.values, L, v.length)), B = S && P.length === 1, V = P.length > 1 && P.length <= _, H = r(A.kindLine, A, P.length, v.length);
|
|
16
|
+
return /* @__PURE__ */ h("div", {
|
|
17
|
+
...k,
|
|
18
|
+
ref: O,
|
|
19
|
+
className: [
|
|
20
|
+
"kapi-linechart",
|
|
21
|
+
V && "kapi-linechart--endlabels",
|
|
22
|
+
D
|
|
23
|
+
].filter(Boolean).join(" "),
|
|
24
|
+
role: "group",
|
|
25
|
+
...b ? { "aria-labelledby": j } : {},
|
|
26
|
+
children: /* @__PURE__ */ h(n, {
|
|
27
|
+
title: b,
|
|
28
|
+
titleId: j,
|
|
29
|
+
series: P,
|
|
30
|
+
categories: v,
|
|
31
|
+
valueAt: F,
|
|
32
|
+
view: M,
|
|
33
|
+
onViewChange: N,
|
|
34
|
+
text: A,
|
|
35
|
+
block: "kapi-linechart",
|
|
36
|
+
children: /* @__PURE__ */ g("div", {
|
|
37
|
+
className: "kapi-linechart__plot",
|
|
38
|
+
role: "img",
|
|
39
|
+
"aria-label": H,
|
|
40
|
+
children: [
|
|
41
|
+
/* @__PURE__ */ h("div", {
|
|
42
|
+
className: "kapi-linechart__axis",
|
|
43
|
+
children: R.map((e) => /* @__PURE__ */ h("div", {
|
|
44
|
+
className: "kapi-linechart__tick",
|
|
45
|
+
style: i({ y: c(e, L) }),
|
|
46
|
+
children: /* @__PURE__ */ h("span", {
|
|
47
|
+
className: "kapi-linechart__ticklabel",
|
|
48
|
+
children: u(e)
|
|
49
|
+
})
|
|
50
|
+
}, e))
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ g("div", {
|
|
53
|
+
className: "kapi-linechart__canvas",
|
|
54
|
+
children: [
|
|
55
|
+
/* @__PURE__ */ g("svg", {
|
|
56
|
+
className: "kapi-linechart__svg",
|
|
57
|
+
viewBox: "0 0 100 100",
|
|
58
|
+
preserveAspectRatio: "none",
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
focusable: "false",
|
|
61
|
+
children: [P.map((e, t) => B ? /* @__PURE__ */ h("path", {
|
|
62
|
+
className: "kapi-linechart__area",
|
|
63
|
+
d: d(z[t]),
|
|
64
|
+
style: i({ slot: t })
|
|
65
|
+
}, `${e.id}-area`) : null), P.map((e, t) => /* @__PURE__ */ h("path", {
|
|
66
|
+
className: "kapi-linechart__line",
|
|
67
|
+
d: p(z[t]),
|
|
68
|
+
style: i({ slot: t }),
|
|
69
|
+
vectorEffect: "non-scaling-stroke"
|
|
70
|
+
}, e.id))]
|
|
71
|
+
}),
|
|
72
|
+
P.map((n, r) => z[r].map((a, o) => /* @__PURE__ */ h(t, {
|
|
73
|
+
label: `${n.label} · ${v[o] ?? ""}: ${e(a.value)}`,
|
|
74
|
+
className: "kapi-linechart__dotwrap",
|
|
75
|
+
style: i({
|
|
76
|
+
slot: r,
|
|
77
|
+
x: a.x,
|
|
78
|
+
y: a.y
|
|
79
|
+
}),
|
|
80
|
+
children: /* @__PURE__ */ h("span", { className: "kapi-linechart__dot" })
|
|
81
|
+
}, `${n.id}-${o}`))),
|
|
82
|
+
V ? P.map((e, t) => {
|
|
83
|
+
let n = f(z[t]);
|
|
84
|
+
return n ? /* @__PURE__ */ h("span", {
|
|
85
|
+
className: "kapi-linechart__endlabel",
|
|
86
|
+
style: i({ y: n.y }),
|
|
87
|
+
children: e.label
|
|
88
|
+
}, `${e.id}-end`) : null;
|
|
89
|
+
}) : null
|
|
90
|
+
]
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ h("div", {
|
|
93
|
+
className: "kapi-linechart__cats",
|
|
94
|
+
children: v.map((e, t) => /* @__PURE__ */ h("span", {
|
|
95
|
+
className: "kapi-linechart__cat",
|
|
96
|
+
children: e
|
|
97
|
+
}, `${e}-${t}`))
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { v as KapiLineChart };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type HTMLAttributes, type Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
3
|
+
import { type KapiSparklineLabelParts } from "./sparklineLogic";
|
|
4
|
+
import "./KapiSparkline.css";
|
|
5
|
+
/** Textos del sparkline: sólo su nombre accesible. */
|
|
6
|
+
export type KapiSparklineLabels = KapiSparklineLabelParts;
|
|
7
|
+
export declare const DEFAULT_SPARKLINE_LABELS: KapiSparklineLabels;
|
|
8
|
+
export type KapiSparklineProps = Omit<HTMLAttributes<HTMLSpanElement>, "children" | "slot"> & {
|
|
9
|
+
/** Los valores, en orden. Lo no finito se lee como cero. */
|
|
10
|
+
values: readonly number[];
|
|
11
|
+
/**
|
|
12
|
+
* Slot de la paleta de datos, 1-based, igual que en los otros gráficos. Con `tone` el color
|
|
13
|
+
* sale de un color de estado en vez de la paleta. @default 1
|
|
14
|
+
*/
|
|
15
|
+
slot?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Usa un color de estado en vez de la paleta. Es para cuando la línea **significa** algo —una
|
|
18
|
+
* métrica que empeoró—, no para distinguirla de otra: para eso está `slot`.
|
|
19
|
+
*/
|
|
20
|
+
tone?: "success" | "warning" | "danger" | "info";
|
|
21
|
+
/** Rellena el área bajo la línea. @default false */
|
|
22
|
+
area?: boolean;
|
|
23
|
+
/** Marca el último punto, que es donde se lee «dónde quedó». @default true */
|
|
24
|
+
last?: boolean;
|
|
25
|
+
/** Textos propios; pisan al provider y a los defaults. */
|
|
26
|
+
labels?: KapiLabelsOverride<KapiSparklineLabels>;
|
|
27
|
+
/** Ref al contenedor. */
|
|
28
|
+
ref?: Ref<HTMLSpanElement>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Línea de tendencia en miniatura, sin ejes ni leyenda, para meter al lado de un número.
|
|
32
|
+
*
|
|
33
|
+
* **Se nombra solo.** Un sparkline no tiene eje ni leyenda, así que su nombre accesible es lo
|
|
34
|
+
* único que un lector de pantalla recibe: se arma del dato («Tendencia: sube, de 820 a 1380») en
|
|
35
|
+
* vez de obligar al consumidor a escribirlo, que es el camino seguro a que quede sin nombre. Se
|
|
36
|
+
* pisa con `aria-label`, o se silencia con `aria-hidden` cuando el texto de al lado ya lo dice.
|
|
37
|
+
*
|
|
38
|
+
* **El eje llega hasta el máximo, sin redondear**: un sparkline no tiene ticks que alinear, y
|
|
39
|
+
* estirar hasta un número redondo sólo achataría la forma, que es lo único que tiene para decir.
|
|
40
|
+
*/
|
|
41
|
+
export declare function KapiSparkline({ values, slot, tone, area, last, labels, className, ref, ...rest }: KapiSparklineProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
+
import { formatDataValue as t } from "../../hooks/numberFormatLogic.js";
|
|
4
|
+
import { chartVars as n } from "./chartFrame.js";
|
|
5
|
+
import { areaPath as r, linePath as i, linePoints as a } from "./lineChartLogic.js";
|
|
6
|
+
import { sparklineLabel as o, sparklineMax as s } from "./sparklineLogic.js";
|
|
7
|
+
/* empty css */
|
|
8
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
9
|
+
import "react";
|
|
10
|
+
//#region src/components/data/KapiSparkline.tsx
|
|
11
|
+
var u = {
|
|
12
|
+
trend: "Tendencia",
|
|
13
|
+
up: "sube",
|
|
14
|
+
down: "baja",
|
|
15
|
+
flat: "estable",
|
|
16
|
+
from: "de",
|
|
17
|
+
to: "a"
|
|
18
|
+
};
|
|
19
|
+
function d({ values: d, slot: f = 1, tone: p, area: m = !1, last: h = !0, labels: g, className: _, ref: v, ...y }) {
|
|
20
|
+
let b = e("sparkline", u, g), x = s(d), S = a(d, x), C = S[S.length - 1], w = n({ slot: Math.max(1, Math.floor(f)) - 1 }), T = p ? `var(--kapi-${p})` : w["--kapi-chart-slot"];
|
|
21
|
+
return /* @__PURE__ */ l("span", {
|
|
22
|
+
...y,
|
|
23
|
+
ref: v,
|
|
24
|
+
className: ["kapi-sparkline", _].filter(Boolean).join(" "),
|
|
25
|
+
role: "img",
|
|
26
|
+
"aria-label": y["aria-label"] ?? o(d, b, t),
|
|
27
|
+
style: {
|
|
28
|
+
"--kapi-chart-slot": T,
|
|
29
|
+
...y.style
|
|
30
|
+
},
|
|
31
|
+
children: [/* @__PURE__ */ l("svg", {
|
|
32
|
+
className: "kapi-sparkline__svg",
|
|
33
|
+
viewBox: "0 0 100 100",
|
|
34
|
+
preserveAspectRatio: "none",
|
|
35
|
+
"aria-hidden": "true",
|
|
36
|
+
focusable: "false",
|
|
37
|
+
children: [m ? /* @__PURE__ */ c("path", {
|
|
38
|
+
className: "kapi-sparkline__area",
|
|
39
|
+
d: r(S)
|
|
40
|
+
}) : null, /* @__PURE__ */ c("path", {
|
|
41
|
+
className: "kapi-sparkline__line",
|
|
42
|
+
d: i(S),
|
|
43
|
+
vectorEffect: "non-scaling-stroke"
|
|
44
|
+
})]
|
|
45
|
+
}), h && C ? /* @__PURE__ */ c("span", {
|
|
46
|
+
className: "kapi-sparkline__last",
|
|
47
|
+
style: n({
|
|
48
|
+
x: C.x,
|
|
49
|
+
y: C.y
|
|
50
|
+
})
|
|
51
|
+
}) : null]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { u as DEFAULT_SPARKLINE_LABELS, d as KapiSparkline };
|