@asanchez-sa/abby 0.3.0 → 0.5.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/dist/components/badge/badge.d.ts +3 -2
- package/dist/components/badge/badge.js +27 -11
- package/dist/components/calendar/calendar.d.ts +26 -5
- package/dist/components/calendar/calendar.js +387 -72
- package/dist/components/chart/chart.d.ts +7 -0
- package/dist/components/chart/chart.js +7 -0
- package/dist/components/chart/parts/bar.d.ts +32 -0
- package/dist/components/chart/parts/bar.js +348 -0
- package/dist/components/chart/parts/categories.d.ts +32 -0
- package/dist/components/chart/parts/categories.js +212 -0
- package/dist/components/chart/parts/legend.d.ts +16 -0
- package/dist/components/chart/parts/legend.js +82 -0
- package/dist/components/chart/parts/line.d.ts +43 -0
- package/dist/components/chart/parts/line.js +266 -0
- package/dist/components/chart/parts/scale.js +96 -0
- package/dist/components/chart/parts/scatter.d.ts +67 -0
- package/dist/components/chart/parts/scatter.js +157 -0
- package/dist/components/chart/parts/surface.d.ts +26 -0
- package/dist/components/chart/parts/surface.js +76 -0
- package/dist/components/chart/parts/table.js +105 -0
- package/dist/components/chart/parts/types.d.ts +44 -0
- package/dist/components/chart/parts/types.js +12 -0
- package/dist/components/filter-chip/filter-chip.d.ts +36 -0
- package/dist/components/filter-chip/filter-chip.js +97 -0
- package/dist/components/graph/graph.d.ts +151 -0
- package/dist/components/graph/graph.js +959 -0
- package/dist/components/model-selector/model-selector.d.ts +38 -3
- package/dist/components/model-selector/model-selector.js +331 -73
- package/dist/components/number-input/number-input.d.ts +14 -3
- package/dist/components/number-input/number-input.js +193 -34
- package/dist/components/spinner/spinner.d.ts +7 -1
- package/dist/components/spinner/spinner.js +86 -26
- package/dist/components/toast/toast.d.ts +19 -2
- package/dist/components/toast/toast.js +211 -49
- package/dist/components/toggle/toggle.d.ts +18 -4
- package/dist/components/toggle/toggle.js +167 -32
- package/dist/components/week-strip/week-strip.d.ts +27 -5
- package/dist/components/week-strip/week-strip.js +288 -134
- package/dist/styles/components.css +66 -0
- package/package.json +5 -1
- package/skills/agent-ready-ui/SKILL.md +1 -1
- package/skills/blocks/SKILL.md +1 -1
- package/skills/compose-screens/SKILL.md +48 -5
- package/skills/compose-screens/references/calendar-week.md +77 -0
- package/skills/compose-screens/references/charts-and-maps.md +298 -0
- package/skills/compose-screens/references/filter-chips.md +61 -0
- package/skills/compose-screens/references/number-units.md +52 -0
- package/skills/note-editor/SKILL.md +1 -1
- package/skills/note-status/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChartLegend } from "./legend.js";
|
|
3
|
+
import { seriesColor, valueFormatter } from "./scale.js";
|
|
4
|
+
import { Chart } from "./surface.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { defineChart, dot } from "@tanstack/charts";
|
|
7
|
+
import { tooltip } from "@tanstack/charts/tooltip";
|
|
8
|
+
import { scaleLinear } from "@tanstack/charts/scales/linear";
|
|
9
|
+
// src/components/chart/parts/scatter.tsx
|
|
10
|
+
/**
|
|
11
|
+
* A dot's radius from its value, with the area proportional to the value: the
|
|
12
|
+
* square root of the value's share of the largest, times the largest radius.
|
|
13
|
+
* A value at or under zero gets the smallest radius, so it still shows.
|
|
14
|
+
*/
|
|
15
|
+
function sqrtRadius(largest, [smallest, biggest]) {
|
|
16
|
+
return (value) => {
|
|
17
|
+
if (!(largest > 0) || !(value > 0)) return smallest;
|
|
18
|
+
return Math.max(smallest, Math.sqrt(Math.min(1, value / largest)) * biggest);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Rows plotted by two numbers: `x` across, `y` up, `size` for the dot's area
|
|
23
|
+
* and `color` for its group. A pointer or the arrows reach each dot and its
|
|
24
|
+
* tooltip names the row with every value; a hidden table holds them all. The
|
|
25
|
+
* chart's name (`aria-label` or `aria-labelledby`) is required.
|
|
26
|
+
*/
|
|
27
|
+
function ScatterChart({ data, x, y, size, color, colors = {}, label, rowKey, xLabel = x, yLabel = y, sizeLabel = size, colorLabel = color, xFormat, yFormat, sizeFormat, locale, radius = [3, 18], height = 280, description, legend = color !== void 0, categoryHeader = "Name", onFocusChange, onSelect, className, ...name }) {
|
|
28
|
+
const read = (row, key) => row[key];
|
|
29
|
+
const formatX = valueFormatter(locale, xFormat);
|
|
30
|
+
const formatY = valueFormatter(locale, yFormat);
|
|
31
|
+
const formatSize = valueFormatter(locale, sizeFormat);
|
|
32
|
+
const groups = color ? Array.from(/* @__PURE__ */ new Set([...Object.keys(colors), ...data.map((row_0) => String(row_0[color]))])) : [];
|
|
33
|
+
const series = groups.map((group, index) => ({
|
|
34
|
+
key: group,
|
|
35
|
+
name: group,
|
|
36
|
+
color: colors[group] ?? `chart-${index % 5 + 1}`
|
|
37
|
+
}));
|
|
38
|
+
const largest = size ? Math.max(0, ...data.map((row_1) => read(row_1, size))) : 0;
|
|
39
|
+
const definition = defineChart({
|
|
40
|
+
marks: [dot(data, {
|
|
41
|
+
x: (row_2) => read(row_2, x),
|
|
42
|
+
y: (row_3) => read(row_3, y),
|
|
43
|
+
...size ? {
|
|
44
|
+
r: (row_4) => read(row_4, size),
|
|
45
|
+
rScale: sqrtRadius(largest, radius)
|
|
46
|
+
} : {},
|
|
47
|
+
...color ? { color: (row_5) => String(row_5[color]) } : { fill: "var(--chart-1)" },
|
|
48
|
+
...rowKey ? { key: (row_6) => rowKey(row_6) } : {},
|
|
49
|
+
fillOpacity: .72,
|
|
50
|
+
stroke: "var(--background)",
|
|
51
|
+
strokeWidth: 1
|
|
52
|
+
})],
|
|
53
|
+
scales: {
|
|
54
|
+
x: {
|
|
55
|
+
scale: scaleLinear,
|
|
56
|
+
nice: true,
|
|
57
|
+
grid: true,
|
|
58
|
+
axis: {
|
|
59
|
+
label: xLabel,
|
|
60
|
+
ticks: { format: (value) => formatX(value, "") }
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
y: {
|
|
64
|
+
scale: scaleLinear,
|
|
65
|
+
nice: true,
|
|
66
|
+
grid: true,
|
|
67
|
+
axis: {
|
|
68
|
+
label: yLabel,
|
|
69
|
+
ticks: { format: (value_0) => formatY(value_0, "") }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
...color ? { color: {
|
|
74
|
+
domain: groups,
|
|
75
|
+
range: series.map((each, index_0) => seriesColor(each, index_0))
|
|
76
|
+
} } : {},
|
|
77
|
+
tooltip: {
|
|
78
|
+
use: tooltip,
|
|
79
|
+
content: (points) => {
|
|
80
|
+
const point = points[0];
|
|
81
|
+
if (!point) return { rows: [] };
|
|
82
|
+
const row_7 = point.datum;
|
|
83
|
+
return {
|
|
84
|
+
title: label(row_7),
|
|
85
|
+
color: point.color,
|
|
86
|
+
rows: [
|
|
87
|
+
...color ? [{
|
|
88
|
+
label: String(colorLabel),
|
|
89
|
+
value: String(row_7[color])
|
|
90
|
+
}] : [],
|
|
91
|
+
{
|
|
92
|
+
label: String(xLabel),
|
|
93
|
+
value: formatX(read(row_7, x), "")
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
label: String(yLabel),
|
|
97
|
+
value: formatY(read(row_7, y), "")
|
|
98
|
+
},
|
|
99
|
+
...size ? [{
|
|
100
|
+
label: String(sizeLabel),
|
|
101
|
+
value: formatSize(read(row_7, size), "")
|
|
102
|
+
}] : []
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return /* @__PURE__ */ jsxs(Chart, {
|
|
109
|
+
...name,
|
|
110
|
+
definition,
|
|
111
|
+
height,
|
|
112
|
+
description,
|
|
113
|
+
className,
|
|
114
|
+
onFocusChange: onFocusChange ? (point_0) => onFocusChange(point_0?.datum ?? null) : void 0,
|
|
115
|
+
onSelect: onSelect ? (point_1) => onSelect(point_1?.datum ?? null) : void 0,
|
|
116
|
+
children: [legend && series.length > 0 ? /* @__PURE__ */ jsx(ChartLegend, { series }) : null, /* @__PURE__ */ jsx("div", {
|
|
117
|
+
"data-slot": "chart-table",
|
|
118
|
+
className: "sr-only",
|
|
119
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
120
|
+
"aria-label": name["aria-label"],
|
|
121
|
+
"aria-labelledby": name["aria-labelledby"],
|
|
122
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
123
|
+
/* @__PURE__ */ jsx("th", {
|
|
124
|
+
scope: "col",
|
|
125
|
+
children: categoryHeader
|
|
126
|
+
}),
|
|
127
|
+
color ? /* @__PURE__ */ jsx("th", {
|
|
128
|
+
scope: "col",
|
|
129
|
+
children: colorLabel
|
|
130
|
+
}) : null,
|
|
131
|
+
/* @__PURE__ */ jsx("th", {
|
|
132
|
+
scope: "col",
|
|
133
|
+
children: xLabel
|
|
134
|
+
}),
|
|
135
|
+
/* @__PURE__ */ jsx("th", {
|
|
136
|
+
scope: "col",
|
|
137
|
+
children: yLabel
|
|
138
|
+
}),
|
|
139
|
+
size ? /* @__PURE__ */ jsx("th", {
|
|
140
|
+
scope: "col",
|
|
141
|
+
children: sizeLabel
|
|
142
|
+
}) : null
|
|
143
|
+
] }) }), /* @__PURE__ */ jsx("tbody", { children: data.map((row_8, index_1) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
144
|
+
/* @__PURE__ */ jsx("th", {
|
|
145
|
+
scope: "row",
|
|
146
|
+
children: label(row_8)
|
|
147
|
+
}),
|
|
148
|
+
color ? /* @__PURE__ */ jsx("td", { children: String(row_8[color]) }) : null,
|
|
149
|
+
/* @__PURE__ */ jsx("td", { children: formatX(read(row_8, x), "") }),
|
|
150
|
+
/* @__PURE__ */ jsx("td", { children: formatY(read(row_8, y), "") }),
|
|
151
|
+
size ? /* @__PURE__ */ jsx("td", { children: formatSize(read(row_8, size), "") }) : null
|
|
152
|
+
] }, rowKey ? rowKey(row_8) : index_1)) })]
|
|
153
|
+
})
|
|
154
|
+
})]
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
export { ScatterChart, sqrtRadius };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ChartName } from "./types.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { ChartProps } from "@tanstack/charts/react";
|
|
4
|
+
import { ChartValue } from "@tanstack/charts";
|
|
5
|
+
type ChartProps$1<TDatum, TXValue extends ChartValue = ChartValue, TYValue extends ChartValue = ChartValue> = Omit<ChartProps<TDatum, TXValue, TYValue>, "ariaLabel" | "ariaDescription" | "className" | "style"> & ChartName & {
|
|
6
|
+
/** Read after the name: the units, the period, what a gap means. */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** On the wrapper that holds the plot and its `children`. */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Drawn under the plot: a `ChartLegend`, a note, the values as a table. */
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A chart drawn from a TanStack Charts definition (`defineChart` and its
|
|
15
|
+
* marks), in abby's look: the palette is `chart-1` … `chart-5`, the grid and
|
|
16
|
+
* the axes are hairlines, and the tooltip and the focus ring are abby's. Build
|
|
17
|
+
* the definition in the component that renders the chart: React Compiler
|
|
18
|
+
* keeps it while the values it reads stay the same.
|
|
19
|
+
*
|
|
20
|
+
* The plot is an image named by `aria-label` or `aria-labelledby` (required),
|
|
21
|
+
* one tab stop whose arrows move between points; the tooltip announces each
|
|
22
|
+
* point it reaches. Put the exact values in `children` too (a table, a
|
|
23
|
+
* summary) when a person needs them without a pointer.
|
|
24
|
+
*/
|
|
25
|
+
declare function Chart$1<TDatum, TXValue extends ChartValue = ChartValue, TYValue extends ChartValue = ChartValue>({ "aria-label": label, "aria-labelledby": labelledBy, description, className, children, initialWidth, ...props }: ChartProps$1<TDatum, TXValue, TYValue>): import("react").JSX.Element;
|
|
26
|
+
export { Chart$1 as Chart, ChartProps$1 as ChartProps };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../../utilities/cn/index.js";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { Chart } from "@tanstack/charts/react";
|
|
7
|
+
// src/components/chart/parts/surface.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Whether the app was built for production. A bundler replaces
|
|
10
|
+
* `process.env.NODE_ENV` with a string; where nothing does and `process`
|
|
11
|
+
* doesn't exist (a browser loading the module as is), reading it throws and
|
|
12
|
+
* the chart counts as in development. Read once, never during render.
|
|
13
|
+
*/
|
|
14
|
+
const production = (() => {
|
|
15
|
+
try {
|
|
16
|
+
return process.env.NODE_ENV === "production";
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
21
|
+
/** The text of the element an `aria-labelledby` points to, read once it's on the page. */
|
|
22
|
+
function useLabelText(id) {
|
|
23
|
+
const $ = c(6);
|
|
24
|
+
const [text, setText] = useState("");
|
|
25
|
+
let t0;
|
|
26
|
+
if ($[0] !== id || $[1] !== text) {
|
|
27
|
+
t0 = (node) => {
|
|
28
|
+
if (!node || !id) return;
|
|
29
|
+
const found = node.ownerDocument.getElementById(id)?.textContent?.trim() ?? "";
|
|
30
|
+
if (found !== text) setText(found);
|
|
31
|
+
};
|
|
32
|
+
$[0] = id;
|
|
33
|
+
$[1] = text;
|
|
34
|
+
$[2] = t0;
|
|
35
|
+
} else t0 = $[2];
|
|
36
|
+
const read = t0;
|
|
37
|
+
let t1;
|
|
38
|
+
if ($[3] !== read || $[4] !== text) {
|
|
39
|
+
t1 = {
|
|
40
|
+
text,
|
|
41
|
+
read
|
|
42
|
+
};
|
|
43
|
+
$[3] = read;
|
|
44
|
+
$[4] = text;
|
|
45
|
+
$[5] = t1;
|
|
46
|
+
} else t1 = $[5];
|
|
47
|
+
return t1;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A chart drawn from a TanStack Charts definition (`defineChart` and its
|
|
51
|
+
* marks), in abby's look: the palette is `chart-1` … `chart-5`, the grid and
|
|
52
|
+
* the axes are hairlines, and the tooltip and the focus ring are abby's. Build
|
|
53
|
+
* the definition in the component that renders the chart: React Compiler
|
|
54
|
+
* keeps it while the values it reads stay the same.
|
|
55
|
+
*
|
|
56
|
+
* The plot is an image named by `aria-label` or `aria-labelledby` (required),
|
|
57
|
+
* one tab stop whose arrows move between points; the tooltip announces each
|
|
58
|
+
* point it reaches. Put the exact values in `children` too (a table, a
|
|
59
|
+
* summary) when a person needs them without a pointer.
|
|
60
|
+
*/
|
|
61
|
+
function Chart$1({ "aria-label": label, "aria-labelledby": labelledBy, description, className, children, initialWidth = 640, ...props }) {
|
|
62
|
+
if (!production && !label && !labelledBy) throw new Error("A chart needs a name: pass aria-label or aria-labelledby");
|
|
63
|
+
const named = useLabelText(labelledBy);
|
|
64
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
65
|
+
ref: named.read,
|
|
66
|
+
"data-slot": "chart",
|
|
67
|
+
className: cn("flex w-full min-w-0 flex-col gap-3 chart-surface", className),
|
|
68
|
+
children: [/* @__PURE__ */ jsx(Chart, {
|
|
69
|
+
...props,
|
|
70
|
+
initialWidth,
|
|
71
|
+
ariaLabel: label ?? named.text,
|
|
72
|
+
ariaDescription: description
|
|
73
|
+
}), children]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export { Chart$1 as Chart };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { stackTotal } from "./scale.js";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/chart/parts/table.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The same data as a table, hidden from sight: categories down, series across.
|
|
8
|
+
* The bars give each value one at a time; this is how a screen reader reads
|
|
9
|
+
* the whole chart. It has one row per category, whatever the data holds.
|
|
10
|
+
*/
|
|
11
|
+
function ChartTable(t0) {
|
|
12
|
+
const $ = c(27);
|
|
13
|
+
const { rows, series, categoryHeader, missing, format, name, totalHeader } = t0;
|
|
14
|
+
let t1;
|
|
15
|
+
if ($[0] !== categoryHeader) {
|
|
16
|
+
t1 = /* @__PURE__ */ jsx("th", {
|
|
17
|
+
scope: "col",
|
|
18
|
+
children: categoryHeader
|
|
19
|
+
});
|
|
20
|
+
$[0] = categoryHeader;
|
|
21
|
+
$[1] = t1;
|
|
22
|
+
} else t1 = $[1];
|
|
23
|
+
let t2;
|
|
24
|
+
if ($[2] !== series) {
|
|
25
|
+
t2 = series.map(_temp);
|
|
26
|
+
$[2] = series;
|
|
27
|
+
$[3] = t2;
|
|
28
|
+
} else t2 = $[3];
|
|
29
|
+
let t3;
|
|
30
|
+
if ($[4] !== totalHeader) {
|
|
31
|
+
t3 = totalHeader === void 0 ? null : /* @__PURE__ */ jsx("th", {
|
|
32
|
+
scope: "col",
|
|
33
|
+
children: totalHeader
|
|
34
|
+
});
|
|
35
|
+
$[4] = totalHeader;
|
|
36
|
+
$[5] = t3;
|
|
37
|
+
} else t3 = $[5];
|
|
38
|
+
let t4;
|
|
39
|
+
if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3) {
|
|
40
|
+
t4 = /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
41
|
+
t1,
|
|
42
|
+
t2,
|
|
43
|
+
t3
|
|
44
|
+
] }) });
|
|
45
|
+
$[6] = t1;
|
|
46
|
+
$[7] = t2;
|
|
47
|
+
$[8] = t3;
|
|
48
|
+
$[9] = t4;
|
|
49
|
+
} else t4 = $[9];
|
|
50
|
+
let t5;
|
|
51
|
+
if ($[10] !== format || $[11] !== missing || $[12] !== rows || $[13] !== series || $[14] !== totalHeader) {
|
|
52
|
+
let t6;
|
|
53
|
+
if ($[16] !== format || $[17] !== missing || $[18] !== series || $[19] !== totalHeader) {
|
|
54
|
+
t6 = (row, index) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
55
|
+
/* @__PURE__ */ jsx("th", {
|
|
56
|
+
scope: "row",
|
|
57
|
+
children: row.label
|
|
58
|
+
}),
|
|
59
|
+
series.map((each_0) => /* @__PURE__ */ jsx("td", { children: format(row.values[each_0.key], missing) }, each_0.key)),
|
|
60
|
+
totalHeader === void 0 ? null : /* @__PURE__ */ jsx("td", { children: format(stackTotal(row, series), missing) })
|
|
61
|
+
] }, `${row.id ?? row.label}-${index}`);
|
|
62
|
+
$[16] = format;
|
|
63
|
+
$[17] = missing;
|
|
64
|
+
$[18] = series;
|
|
65
|
+
$[19] = totalHeader;
|
|
66
|
+
$[20] = t6;
|
|
67
|
+
} else t6 = $[20];
|
|
68
|
+
t5 = rows.map(t6);
|
|
69
|
+
$[10] = format;
|
|
70
|
+
$[11] = missing;
|
|
71
|
+
$[12] = rows;
|
|
72
|
+
$[13] = series;
|
|
73
|
+
$[14] = totalHeader;
|
|
74
|
+
$[15] = t5;
|
|
75
|
+
} else t5 = $[15];
|
|
76
|
+
let t6;
|
|
77
|
+
if ($[21] !== t5) {
|
|
78
|
+
t6 = /* @__PURE__ */ jsx("tbody", { children: t5 });
|
|
79
|
+
$[21] = t5;
|
|
80
|
+
$[22] = t6;
|
|
81
|
+
} else t6 = $[22];
|
|
82
|
+
let t7;
|
|
83
|
+
if ($[23] !== name || $[24] !== t4 || $[25] !== t6) {
|
|
84
|
+
t7 = /* @__PURE__ */ jsx("div", {
|
|
85
|
+
"data-slot": "chart-table",
|
|
86
|
+
className: "sr-only",
|
|
87
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
88
|
+
...name,
|
|
89
|
+
children: [t4, t6]
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
$[23] = name;
|
|
93
|
+
$[24] = t4;
|
|
94
|
+
$[25] = t6;
|
|
95
|
+
$[26] = t7;
|
|
96
|
+
} else t7 = $[26];
|
|
97
|
+
return t7;
|
|
98
|
+
}
|
|
99
|
+
function _temp(each) {
|
|
100
|
+
return /* @__PURE__ */ jsx("th", {
|
|
101
|
+
scope: "col",
|
|
102
|
+
children: each.name
|
|
103
|
+
}, each.key);
|
|
104
|
+
}
|
|
105
|
+
export { ChartTable };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A theme color token a series can take by name. */
|
|
2
|
+
export type ChartToken = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5" | "primary" | "muted" | "warning" | "success" | "destructive";
|
|
3
|
+
/** A token, or any CSS color the app passes (an area's color, `var(--area)`). */
|
|
4
|
+
export type ChartColor = ChartToken | (string & {});
|
|
5
|
+
export type ChartSeries = {
|
|
6
|
+
/** The key of this series' value in each row's `values`. */
|
|
7
|
+
key: string;
|
|
8
|
+
/** The name read in the tooltip, the table and the screen reader. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Defaults to `chart-1` … `chart-5`, in the order of `series`. */
|
|
11
|
+
color?: ChartColor;
|
|
12
|
+
/**
|
|
13
|
+
* `forecast` draws what hasn't happened yet: a dashed outline over a faint
|
|
14
|
+
* fill. It shares the column of the first series instead of taking one.
|
|
15
|
+
*/
|
|
16
|
+
variant?: "default" | "forecast";
|
|
17
|
+
};
|
|
18
|
+
export type ChartRow = {
|
|
19
|
+
/** The category's text: the x label, and the start of a bar's name. */
|
|
20
|
+
label: string;
|
|
21
|
+
/** Identifies the category for `highlight`. Defaults to `label`. */
|
|
22
|
+
id?: string;
|
|
23
|
+
/** One value per series key. A missing or `null` value draws no bar. */
|
|
24
|
+
values: Record<string, number | null | undefined>;
|
|
25
|
+
};
|
|
26
|
+
/** A chart is named by one of these, and it's required. */
|
|
27
|
+
export type ChartName = {
|
|
28
|
+
"aria-label": string;
|
|
29
|
+
"aria-labelledby"?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
"aria-label"?: undefined;
|
|
32
|
+
"aria-labelledby": string;
|
|
33
|
+
};
|
|
34
|
+
/** The texts a chart shows when the app doesn't replace them. */
|
|
35
|
+
export type ChartTexts = {
|
|
36
|
+
/** Shown instead of the plot when `data` is empty. */
|
|
37
|
+
empty?: string;
|
|
38
|
+
/** The header of the table's first column. */
|
|
39
|
+
categoryHeader?: string;
|
|
40
|
+
/** What the table shows for a value that is missing. */
|
|
41
|
+
missing?: string;
|
|
42
|
+
/** The header of the table's total column, when the bars are stacked. */
|
|
43
|
+
totalHeader?: string;
|
|
44
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/components/chart/parts/types.ts
|
|
2
|
+
const defaultTexts = {
|
|
3
|
+
empty: "No data",
|
|
4
|
+
categoryHeader: "Category",
|
|
5
|
+
missing: "No value",
|
|
6
|
+
totalHeader: "Total"
|
|
7
|
+
};
|
|
8
|
+
/** A chart's name as one of its two forms, to hand from a preset's props to `Chart`. */
|
|
9
|
+
function nameOf(props) {
|
|
10
|
+
return props["aria-label"] === void 0 && props["aria-labelledby"] !== void 0 ? { "aria-labelledby": props["aria-labelledby"] } : { "aria-label": props["aria-label"] };
|
|
11
|
+
}
|
|
12
|
+
export { defaultTexts, nameOf };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChangeDetails } from "../../core/ui-sdk.js";
|
|
2
|
+
import "../../core/index.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type FilterChipItem = string | {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type FilterChipProps = Omit<ComponentProps<"div">, "onChange" | "children" | "defaultValue"> & {
|
|
10
|
+
/** The options, one of them chosen. A string is an option whose label and value match. */
|
|
11
|
+
items: FilterChipItem[];
|
|
12
|
+
/** The chosen value. */
|
|
13
|
+
value?: string;
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
/** Runs when a choice wants to change. `details.cancel()` keeps the current one. */
|
|
16
|
+
onValueChange?: (value: string, details: ChangeDetails<string>) => void;
|
|
17
|
+
/** The value that means "no filter". The chip is active while the value is any other. */
|
|
18
|
+
allValue: string;
|
|
19
|
+
/** What the filter is, in grey before the value: "Persona". Its colon is yours to write. */
|
|
20
|
+
prefix?: string;
|
|
21
|
+
/** Draws a chevron after the value. */
|
|
22
|
+
chevron?: boolean;
|
|
23
|
+
/** A CSS color, the area's, for the small square before the value while the chip is active. */
|
|
24
|
+
color?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Shows a × while the chip is active. The × goes back to `allValue` through
|
|
27
|
+
* `onValueChange` (reason `"clear-press"`, which can cancel it), controlled
|
|
28
|
+
* or not, and then runs `onClear`.
|
|
29
|
+
*/
|
|
30
|
+
onClear?: () => void;
|
|
31
|
+
/** The × button's name. Give each chip its own when a page holds several. */
|
|
32
|
+
clearLabel?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
};
|
|
35
|
+
declare function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel, disabled, className, ...props }: FilterChipProps): import("react").JSX.Element;
|
|
36
|
+
export { FilterChip, type FilterChipItem, type FilterChipProps };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utilities/cn/index.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { Menu, MenuContent, MenuItemIndicator, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../menu/menu.js";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { ArrowDown01Icon, Cancel01Icon } from "@hugeicons/core-free-icons";
|
|
9
|
+
// src/components/filter-chip/filter-chip.tsx
|
|
10
|
+
const trigger = [
|
|
11
|
+
"flex h-full min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-full ps-2.5 pe-2.5 text-sm outline-none select-none",
|
|
12
|
+
"transition-colors motion-reduce:transition-none hover:bg-accent data-open:bg-accent",
|
|
13
|
+
"disabled:pointer-events-none"
|
|
14
|
+
];
|
|
15
|
+
function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel = "Clear filter", disabled, className, ...props }) {
|
|
16
|
+
const [own, setOwn] = useState(defaultValue ?? allValue);
|
|
17
|
+
const current = value ?? own;
|
|
18
|
+
const options = items.map((item) => typeof item === "string" ? {
|
|
19
|
+
value: item,
|
|
20
|
+
label: item
|
|
21
|
+
} : item);
|
|
22
|
+
const label = options.find((option) => option.value === current)?.label ?? current;
|
|
23
|
+
const active = current !== allValue;
|
|
24
|
+
function clear(event, press) {
|
|
25
|
+
let canceled = false;
|
|
26
|
+
const details = {
|
|
27
|
+
reason: "clear-press",
|
|
28
|
+
event: event.nativeEvent,
|
|
29
|
+
source: press.source,
|
|
30
|
+
cancel: () => {
|
|
31
|
+
canceled = true;
|
|
32
|
+
},
|
|
33
|
+
get canceled() {
|
|
34
|
+
return canceled;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
onValueChange?.(allValue, details);
|
|
38
|
+
if (details.canceled) return;
|
|
39
|
+
setOwn(allValue);
|
|
40
|
+
onClear?.();
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
43
|
+
"data-slot": "filter-chip",
|
|
44
|
+
"data-active": active ? "" : void 0,
|
|
45
|
+
"data-disabled": disabled ? "" : void 0,
|
|
46
|
+
className: cn("inline-flex h-7 max-w-full items-center rounded-full border border-input text-sm text-foreground transition-colors focus-ring-within motion-reduce:transition-none data-active:border-ring data-disabled:opacity-50", className),
|
|
47
|
+
...props,
|
|
48
|
+
children: [/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsxs(MenuTrigger, {
|
|
49
|
+
disabled,
|
|
50
|
+
className: cn(trigger),
|
|
51
|
+
children: [
|
|
52
|
+
prefix && /* @__PURE__ */ jsxs("span", {
|
|
53
|
+
className: "shrink-0 text-muted-foreground",
|
|
54
|
+
children: [prefix, " "]
|
|
55
|
+
}),
|
|
56
|
+
active && color && /* @__PURE__ */ jsx("span", {
|
|
57
|
+
"aria-hidden": "true",
|
|
58
|
+
"data-slot": "filter-chip-color",
|
|
59
|
+
className: "size-2 shrink-0 rounded-2xs",
|
|
60
|
+
style: { backgroundColor: color }
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("span", {
|
|
63
|
+
className: cn("truncate", active && "font-medium"),
|
|
64
|
+
children: label
|
|
65
|
+
}),
|
|
66
|
+
chevron && /* @__PURE__ */ jsx(Icon, {
|
|
67
|
+
icon: ArrowDown01Icon,
|
|
68
|
+
className: "size-2.5 text-muted-foreground"
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
}), /* @__PURE__ */ jsx(MenuContent, { children: /* @__PURE__ */ jsx(MenuRadioGroup, {
|
|
72
|
+
value: current,
|
|
73
|
+
onValueChange: (next, details_0) => {
|
|
74
|
+
onValueChange?.(next, details_0);
|
|
75
|
+
if (!details_0.canceled) setOwn(next);
|
|
76
|
+
},
|
|
77
|
+
children: options.map((option_0) => /* @__PURE__ */ jsxs(MenuRadioItem, {
|
|
78
|
+
value: option_0.value,
|
|
79
|
+
disabled: option_0.disabled,
|
|
80
|
+
closeOnSelect: true,
|
|
81
|
+
children: [option_0.label, /* @__PURE__ */ jsx(MenuItemIndicator, {})]
|
|
82
|
+
}, option_0.value))
|
|
83
|
+
}) })] }), active && onClear && /* @__PURE__ */ jsx(Button, {
|
|
84
|
+
variant: "ghost",
|
|
85
|
+
size: "icon-xs",
|
|
86
|
+
"aria-label": clearLabel,
|
|
87
|
+
disabled,
|
|
88
|
+
onClick: clear,
|
|
89
|
+
className: "me-px shrink-0",
|
|
90
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
91
|
+
icon: Cancel01Icon,
|
|
92
|
+
className: "size-3"
|
|
93
|
+
})
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export { FilterChip };
|