@sincpro/web-ui 2.3.0 → 2.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.
Files changed (70) hide show
  1. package/README.md +71 -6
  2. package/dist/components/activity/Activity.d.ts +20 -1
  3. package/dist/components/activity/Activity.js +44 -7
  4. package/dist/components/activity/index.d.ts +1 -1
  5. package/dist/components/board/Board.d.ts +74 -2
  6. package/dist/components/board/Board.js +65 -2
  7. package/dist/components/board/index.d.ts +1 -1
  8. package/dist/components/board/index.js +1 -1
  9. package/dist/components/canvas/canvas.css +6 -1
  10. package/dist/components/form/Form.js +11 -0
  11. package/dist/components/form/FormIndex.d.ts +11 -0
  12. package/dist/components/form/FormIndex.js +96 -0
  13. package/dist/components/form/Sheet.js +5 -0
  14. package/dist/components/guide/Guide.d.ts +33 -0
  15. package/dist/components/guide/Guide.js +288 -0
  16. package/dist/components/guide/GuideSpot.d.ts +14 -0
  17. package/dist/components/guide/GuideSpot.js +13 -0
  18. package/dist/components/guide/index.d.ts +4 -0
  19. package/dist/components/guide/index.js +6 -0
  20. package/dist/components/guide/place.d.ts +44 -0
  21. package/dist/components/guide/place.js +69 -0
  22. package/dist/components/guide/target.d.ts +41 -0
  23. package/dist/components/guide/target.js +55 -0
  24. package/dist/components/index.d.ts +1 -0
  25. package/dist/components/index.js +1 -0
  26. package/dist/components/listing/ChartExplorer.js +10 -5
  27. package/dist/components/listing/Listing.js +7 -5
  28. package/dist/components/listing/Row.js +8 -7
  29. package/dist/components/navigation/NavigationTree.js +1 -1
  30. package/dist/components/record/DirtyActions.d.ts +19 -8
  31. package/dist/components/record/DirtyActions.js +89 -13
  32. package/dist/components/record/RecordHeader.js +17 -11
  33. package/dist/components/record/ThumbBar.js +2 -1
  34. package/dist/components/shell/SearchEntry.d.ts +29 -0
  35. package/dist/components/shell/SearchEntry.js +34 -0
  36. package/dist/components/shell/Sidebar.d.ts +5 -1
  37. package/dist/components/shell/Sidebar.js +4 -3
  38. package/dist/components/shell/TopBar.d.ts +5 -1
  39. package/dist/components/shell/TopBar.js +3 -2
  40. package/dist/components/shell/index.d.ts +1 -0
  41. package/dist/components/shell/index.js +3 -0
  42. package/dist/foundations/calendar.d.ts +12 -0
  43. package/dist/foundations/calendar.js +50 -0
  44. package/dist/foundations/chart.d.ts +10 -1
  45. package/dist/foundations/chart.js +17 -1
  46. package/dist/foundations/copy.d.ts +39 -2
  47. package/dist/foundations/copy.es.js +19 -0
  48. package/dist/foundations/copy.js +19 -0
  49. package/dist/foundations/form.d.ts +6 -0
  50. package/dist/foundations/form.js +7 -0
  51. package/dist/foundations/index.d.ts +3 -2
  52. package/dist/foundations/index.js +4 -2
  53. package/dist/foundations/pivot.d.ts +6 -0
  54. package/dist/foundations/pivot.js +1 -0
  55. package/dist/foundations/shortcut.d.ts +18 -0
  56. package/dist/foundations/shortcut.js +20 -0
  57. package/dist/primitives/chart/BarList.d.ts +30 -0
  58. package/dist/primitives/chart/BarList.js +27 -0
  59. package/dist/primitives/chart/Chart.d.ts +13 -0
  60. package/dist/primitives/chart/Chart.js +71 -19
  61. package/dist/primitives/chart/Sparkline.d.ts +30 -0
  62. package/dist/primitives/chart/Sparkline.js +53 -0
  63. package/dist/primitives/chart/index.d.ts +2 -0
  64. package/dist/primitives/chart/index.js +2 -0
  65. package/dist/primitives/field/Field.d.ts +6 -2
  66. package/dist/primitives/field/Field.js +35 -6
  67. package/dist/primitives/value/Metric.d.ts +12 -1
  68. package/dist/primitives/value/Metric.js +9 -4
  69. package/dist/tokens.css +92 -22
  70. package/package.json +1 -1
@@ -4,9 +4,11 @@ import { SERIES_COLORS, } from "../../foundations/chart.js";
4
4
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
5
  import { Empty } from "../notice/Notice.js";
6
6
  import { useMemo, useState } from "react";
7
- import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, LabelList, Line, LineChart, Pie, PieChart, ReferenceLine, Tooltip, XAxis, YAxis, } from "recharts";
7
+ import { Area, Bar, BarChart, CartesianGrid, Cell, ComposedChart, LabelList, Line, Pie, PieChart, ReferenceLine, Tooltip, XAxis, YAxis, } from "recharts";
8
8
  const MAX_BAR = 24;
9
9
  const RADIUS = 4;
10
+ /* The wash under a line: the series hue at a tenth, never a saturated block. */
11
+ const WASH = 0.1;
10
12
  function colorOf(point, index, alone) {
11
13
  /* The tail and the previous period are context, not the subject: the de-emphasis grey. */
12
14
  if (point.rest === true || point.previous === true)
@@ -37,11 +39,16 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
37
39
  const peak = Math.max(0, ...data.values.flatMap((row) => row.map((value) => Math.abs(value ?? 0))));
38
40
  const negative = data.values.some((row) => row.some((value) => (value ?? 0) < 0));
39
41
  /* In full up to the millions (7.000, 14.000), compact from there (2,5 M): Spanish compact
40
- thousands come out as «7 K» next to «14 k» on the same axis. */
41
- const tick = (value) => peak >= 1_000_000 ? compact.format(value) : number.format(value);
42
+ thousands come out as «7 K» next to «14 k» on the same axis. A measure that knows its
43
+ short form («76 MB») says it itself. */
44
+ const tick = (value) => data.measure.formatShort?.(value) ??
45
+ (peak >= 1_000_000 ? compact.format(value) : number.format(value));
42
46
  /* One object per category, the shape Recharts reads: `s0`, `s1`… per series. */
43
47
  const rows = useMemo(() => data.categories.map((category, c) => {
44
- const row = { label: category.label };
48
+ const row = {
49
+ label: category.label,
50
+ tick: category.tick ?? category.label,
51
+ };
45
52
  data.series.forEach((_, s) => {
46
53
  row[`s${String(s)}`] = data.values[c]?.[s] ?? null;
47
54
  });
@@ -113,7 +120,16 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
113
120
  : horizontal
114
121
  ? { height: `${String(data.categories.length * (1 + perCategory * 0.75) + 3)}rem` }
115
122
  : {};
116
- const grid = (_jsx(CartesianGrid, { vertical: horizontal, horizontal: !horizontal, stroke: "var(--color-line)" }));
123
+ /* The value rides the tip of its bar when there is ONE series: the axis gives the scale,
124
+ the tip gives the number, and nobody has to hover thirty bars to read them. With
125
+ several series it would be a number on every mark, which is noise. */
126
+ const tips = kind === "bar" &&
127
+ !stacked &&
128
+ visible.length === 1 &&
129
+ (horizontal || data.categories.length <= 12);
130
+ /* Every bar says its number: the value axis and its grid would say it twice. */
131
+ const labelled = tips;
132
+ const grid = labelled ? null : (_jsx(CartesianGrid, { vertical: horizontal, horizontal: !horizontal, stroke: "var(--color-line)" }));
117
133
  const tickStyle = { fill: "currentColor" };
118
134
  const valueAxis = {
119
135
  type: "number",
@@ -121,21 +137,18 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
121
137
  tick: tickStyle,
122
138
  tickLine: false,
123
139
  axisLine: false,
140
+ hide: labelled,
124
141
  };
125
142
  const categoryAxis = {
126
143
  type: "category",
127
- dataKey: "label",
144
+ dataKey: "tick",
128
145
  tick: tickStyle,
129
146
  tickLine: false,
130
147
  axisLine: { stroke: "var(--color-line-strong)" },
131
148
  };
132
- const axes = horizontal ? (_jsxs(_Fragment, { children: [_jsx(XAxis, { ...valueAxis }), _jsx(YAxis, { ...categoryAxis, width: "auto", interval: 0 })] })) : (_jsxs(_Fragment, { children: [_jsx(XAxis, { ...categoryAxis, interval: "preserveStartEnd", minTickGap: 8 }), _jsx(YAxis, { ...valueAxis, width: "auto" })] }));
149
+ const axes = horizontal ? (_jsxs(_Fragment, { children: [_jsx(XAxis, { ...valueAxis }), _jsx(YAxis, { ...categoryAxis, width: "auto", interval: 0 })] })) : (_jsxs(_Fragment, { children: ["/* Every Nth tick, the same N all along: an axis that skips unevenly reads as missing periods. */", _jsx(XAxis, { ...categoryAxis, interval: "equidistantPreserveStart", minTickGap: 12 }), _jsx(YAxis, { ...valueAxis, width: "auto" })] }));
133
150
  const zero = negative ? (_jsx(ReferenceLine, { ...(horizontal ? { x: 0 } : { y: 0 }), stroke: "var(--color-line-strong)" })) : null;
134
151
  const readout = (props) => (_jsx(Readout, { ...props, format: format, compare: data.compare === true }));
135
- /* The value rides the tip of its bar when there is ONE series: the axis gives the scale,
136
- the tip gives the number, and nobody has to hover thirty bars to read them. With
137
- several series it would be a number on every mark, which is noise. */
138
- const tips = !stacked && visible.length === 1 && (horizontal || data.categories.length <= 12);
139
152
  let plot;
140
153
  if (kind === "bar") {
141
154
  plot = (_jsxs(BarChart, { data: rows, layout: horizontal ? "vertical" : "horizontal", responsive: true, width: "100%", height: "100%", title: label, barGap: 2, barCategoryGap: "20%", margin: {
@@ -154,7 +167,6 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
154
167
  : { onClick: (_, at) => open(at, one.index) }), children: tips ? (_jsx(LabelList, { dataKey: one.key, content: (props) => (_jsx(Tip, { viewBox: props.viewBox, value: props.value, horizontal: horizontal, format: format })) })) : null }, one.point.id)))] }));
155
168
  }
156
169
  else {
157
- const dots = rows.length <= 24;
158
170
  const common = {
159
171
  data: rows,
160
172
  responsive: true,
@@ -174,12 +186,49 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
174
186
  }),
175
187
  };
176
188
  const ring = { r: 5, stroke: "var(--color-surface)", strokeWidth: 2 };
177
- const tooltip = (_jsx(Tooltip, { isAnimationActive: false, cursor: { stroke: "var(--color-line-strong)" }, content: readout }));
178
- plot = stacked ? (_jsxs(AreaChart, { ...common, stackOffset: negative ? "sign" : "none", children: [grid, axes, zero, tooltip, visible.map((one) => (_jsx(Area, { type: "monotone", dataKey: one.key, name: one.point.label, stackId: "stack", stroke: one.color, strokeWidth: 2, fill: one.color, fillOpacity: 0.12, dot: false, activeDot: { ...ring, fill: one.color }, isAnimationActive: false }, one.point.id)))] })) : (_jsxs(LineChart, { ...common, children: [grid, axes, zero, tooltip, visible.map((one) => (_jsx(Line, { type: "monotone", dataKey: one.key, name: one.point.label, stroke: one.color, strokeWidth: 2, dot: dots
179
- ? { r: 4, fill: one.color, stroke: "var(--color-surface)", strokeWidth: 2 }
180
- : false, activeDot: { ...ring, fill: one.color }, connectNulls: false, isAnimationActive: false }, one.point.id)))] }));
189
+ const filled = kind === "area" || stacked;
190
+ const valueAt = (s, c) => data.values[c]?.[s] ?? null;
191
+ /* A dot only where the line cannot draw: a value alone between two holes (or at an edge
192
+ next to one), and the last value of a series — where it stands now. */
193
+ const marked = (s, c) => {
194
+ if (valueAt(s, c) === null)
195
+ return false;
196
+ const before = c === 0 ? null : valueAt(s, c - 1);
197
+ const after = c === rows.length - 1 ? null : valueAt(s, c + 1);
198
+ const last = data.values.every((_, at) => at <= c || valueAt(s, at) === null);
199
+ return (before === null && after === null) || last;
200
+ };
201
+ /* A hole INSIDE a series: a null with a value somewhere before and after it. */
202
+ const holed = (s) => data.values.some((_, c) => valueAt(s, c) === null &&
203
+ data.values.some((__, at) => at < c && valueAt(s, at) !== null) &&
204
+ data.values.some((__, at) => at > c && valueAt(s, at) !== null));
205
+ plot = (_jsxs(ComposedChart, { ...common, stackOffset: negative ? "sign" : "none", children: [grid, axes, zero, _jsx(Tooltip, { isAnimationActive: false, cursor: { stroke: "var(--color-line-strong)" }, content: readout }), stacked
206
+ ? null
207
+ : visible
208
+ .filter((one) => holed(one.index))
209
+ .map((one) => (_jsx(Line, { type: "monotone", dataKey: one.key, stroke: "var(--color-line-strong)", strokeWidth: 1.5, strokeDasharray: "3 4", connectNulls: true, dot: false, activeDot: false, legendType: "none", tooltipType: "none", isAnimationActive: false }, `${one.point.id}\u0000gap`))), visible.map((one) => {
210
+ const dot = (props) => props.index !== undefined &&
211
+ props.cx !== undefined &&
212
+ props.cy !== undefined &&
213
+ marked(one.index, props.index) ? (_jsx("circle", { cx: props.cx, cy: props.cy, r: 4, fill: one.color, stroke: "var(--color-surface)", strokeWidth: 2 })) : null;
214
+ const shared = {
215
+ type: "monotone",
216
+ dataKey: one.key,
217
+ name: one.point.label,
218
+ stroke: one.color,
219
+ strokeWidth: 2,
220
+ dot,
221
+ activeDot: { ...ring, fill: one.color },
222
+ connectNulls: false,
223
+ isAnimationActive: false,
224
+ };
225
+ return filled ? (_jsx(Area, { ...shared, ...(stacked ? { stackId: "stack", dot: false } : {}), fill: one.color, fillOpacity: WASH }, one.point.id)) : (_jsx(Line, { ...shared }, one.point.id));
226
+ })] }));
181
227
  }
182
- return (_jsxs("figure", { "aria-label": label, className: "flex min-w-0 flex-col gap-3", children: [alone ? null : (_jsx("ul", { className: "flex min-w-0 flex-wrap items-center gap-x-1 gap-y-1", children: series.map((one) => (_jsx("li", { className: "min-w-0", children: _jsxs("button", { type: "button", "aria-pressed": one.shown, "aria-label": fillCopy(one.shown ? words.hideSeries : words.showSeries, {
228
+ return (_jsxs("figure", { "aria-label": label, className: "flex min-w-0 flex-col gap-3", children: [alone ? null : (
229
+ /* At the top right, where the eye ends the title: the key to the colours, out of
230
+ the way of the plot's own reading from the left. */
231
+ _jsx("ul", { className: "flex min-w-0 flex-wrap items-center justify-end gap-x-1 gap-y-1", children: series.map((one) => (_jsx("li", { className: "min-w-0", children: _jsxs("button", { type: "button", "aria-pressed": one.shown, "aria-label": fillCopy(one.shown ? words.hideSeries : words.showSeries, {
183
232
  name: one.point.label,
184
233
  }),
185
234
  /* The last one on cannot be turned off: a chart with nothing on it reads
@@ -191,7 +240,7 @@ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizo
191
240
  else
192
241
  next.add(one.point.id);
193
242
  return next;
194
- }), className: `inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-control px-1.5 py-0.5 text-meta transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 focus-visible:outline-2 focus-visible:outline-primary ${one.shown ? "text-ink" : "text-muted line-through"}`, children: [_jsx(Swatch, { color: one.shown ? one.color : "var(--color-line-strong)", line: kind === "line" }), _jsx("span", { className: "truncate", children: one.point.label })] }) }, one.point.id))) })), _jsx("div", { className: `min-w-0 text-micro text-muted ${height === undefined && !horizontal ? "h-72" : ""}`, style: size, children: plot }), note] }));
243
+ }), className: `inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-control px-1.5 py-0.5 text-meta transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 focus-visible:outline-2 focus-visible:outline-primary ${one.shown ? "text-ink" : "text-muted line-through"}`, children: [_jsx(Swatch, { color: one.shown ? one.color : "var(--color-line-strong)", line: kind === "line" || kind === "area" }), _jsx("span", { className: "truncate", children: one.point.label })] }) }, one.point.id))) })), _jsx("div", { className: `min-w-0 text-micro text-muted ${height === undefined && !horizontal ? "h-72" : ""}`, style: size, children: plot }), note] }));
195
244
  }
196
245
  /**
197
246
  * The number at the tip of a bar, on ONE line. Recharts' own label wraps to the bar's
@@ -217,7 +266,10 @@ function Readout({ active, payload, label, format, compare = false, }) {
217
266
  }), [copy.locale]);
218
267
  if (active !== true || payload === undefined || payload.length === 0)
219
268
  return null;
220
- const heading = label ?? payload[0]?.name;
269
+ /* The full label of the category («Enero de 2025»), not the tick the axis wrote («ene»). */
270
+ const row = payload[0]?.payload;
271
+ const full = typeof row === "object" && row !== null && "label" in row ? String(row.label) : undefined;
272
+ const heading = full ?? label ?? payload[0]?.name;
221
273
  /* Now against before, said as a change: the number a comparison is asked for. */
222
274
  const now = payload[0]?.value;
223
275
  const before = payload[1]?.value;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A SPARKLINE: the shape of the last periods, drawn under a figure — no axis, no grid, no
3
+ * tooltip. It answers «and lately?» beside a number that answers «how much now?».
4
+ *
5
+ * Context: a board's headline figure said one number and nothing about its direction; the
6
+ * only way to see the trend was a whole chart. A sparkline is the trend at the size of a
7
+ * word. It is not a small chart, and it does not try to be one: no scale (its height is the
8
+ * series' own range), so it is never read for a value — the figure beside it says the
9
+ * value. That is why it draws in the soft data hue and marks only the LAST point in the full
10
+ * one: the current period is the one the figure talks about.
11
+ *
12
+ * - A series flat at zero is drawn flat on the floor, not in the middle: nothing happened,
13
+ * and the baseline is where nothing is.
14
+ * - A hole is a hole — the line breaks — because there is no axis here to say why.
15
+ * - With nothing to draw (no values, all holes) it draws nothing, not an empty frame.
16
+ *
17
+ * Pure SVG and no Recharts: a board with eight of them should not load a chart engine for
18
+ * lines without axes. The SVG stretches to its box (`preserveAspectRatio="none"`) with a
19
+ * stroke that does not stretch (`non-scaling-stroke`); the end dot is an HTML mark laid over
20
+ * it, so it stays round at any width.
21
+ */
22
+ export type SparklineProps = {
23
+ /** The values, oldest first. `null` is a period with nothing recorded. */
24
+ values: readonly (number | null)[];
25
+ /** What it shows, for a screen reader: «Mensajes recibidos, últimas 24 horas». */
26
+ label: string;
27
+ /** The wash under the line, for a quantity read as an amount (memory, stock). */
28
+ area?: boolean;
29
+ };
30
+ export declare function Sparkline({ values, label, area }: SparklineProps): import("react").JSX.Element | null;
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const WIDTH = 100;
3
+ const HEIGHT = 40;
4
+ /* Room for the stroke and the end dot at the top and the bottom. */
5
+ const PAD = 4;
6
+ export function Sparkline({ values, label, area = true }) {
7
+ const known = values.filter((value) => value !== null);
8
+ if (known.length === 0)
9
+ return null;
10
+ /* Its own range, not from zero: memory between 40 and 66 MB drawn from 0 is a flat block
11
+ with a ripple on top, and the turn is what a sparkline is for. */
12
+ const low = Math.min(...known);
13
+ const high = Math.max(...known);
14
+ const range = high - low;
15
+ const x = (at) => values.length === 1 ? WIDTH / 2 : (at / (values.length - 1)) * WIDTH;
16
+ /* Flat at zero sits on the floor; flat anywhere else, in the middle. */
17
+ const y = (value) => range === 0
18
+ ? high === 0
19
+ ? HEIGHT - PAD
20
+ : HEIGHT / 2
21
+ : PAD + (1 - (value - low) / range) * (HEIGHT - 2 * PAD);
22
+ /* The runs between holes, each its own stroke. */
23
+ const runs = [];
24
+ values.forEach((value, at) => {
25
+ if (value === null)
26
+ return;
27
+ const previous = values[at - 1];
28
+ if (at === 0 || previous === null || previous === undefined)
29
+ runs.push([]);
30
+ runs[runs.length - 1].push({ at, value });
31
+ });
32
+ const point = (one) => `${x(one.at).toFixed(2)},${y(one.value).toFixed(2)}`;
33
+ const line = (run) => `M${run.map(point).join(" L")}`;
34
+ const wash = (run) => {
35
+ const first = run[0];
36
+ const last = run[run.length - 1];
37
+ return `${line(run)} L${x(last.at).toFixed(2)},${HEIGHT} L${x(first.at).toFixed(2)},${HEIGHT} Z`;
38
+ };
39
+ let lastAt = values.length - 1;
40
+ while (values[lastAt] === null)
41
+ lastAt -= 1;
42
+ const end = { x: x(lastAt), y: y(values[lastAt]) };
43
+ return (_jsxs("div", { className: "relative h-(--size-sparkline) w-full min-w-0", children: [_jsxs("svg", { role: "img", "aria-label": label, viewBox: `0 0 ${String(WIDTH)} ${String(HEIGHT)}`, preserveAspectRatio: "none", className: "block size-full overflow-visible", children: [area
44
+ ? runs
45
+ .filter((run) => run.length > 1)
46
+ .map((run) => (_jsx("path", { d: wash(run), fill: "var(--color-data-soft)", fillOpacity: 0.1 }, `wash-${String(run[0].at)}`)))
47
+ : null, runs
48
+ .filter((run) => run.length > 1)
49
+ .map((run) => (_jsx("path", { d: line(run), fill: "none", stroke: "var(--color-data-soft)", strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round", vectorEffect: "non-scaling-stroke" }, `line-${String(run[0].at)}`)))] }), _jsx("span", { "aria-hidden": true, className: "absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-pill bg-data ring-2 ring-surface", style: {
50
+ left: `${String((end.x / WIDTH) * 100)}%`,
51
+ top: `${String((end.y / HEIGHT) * 100)}%`,
52
+ } })] }));
53
+ }
@@ -1 +1,3 @@
1
+ export { BarList, type BarListProps } from "./BarList.js";
1
2
  export { Chart, type ChartProps } from "./Chart.js";
3
+ export { Sparkline, type SparklineProps } from "./Sparkline.js";
@@ -1 +1,3 @@
1
+ export { BarList } from "./BarList.js";
1
2
  export { Chart } from "./Chart.js";
3
+ export { Sparkline } from "./Sparkline.js";
@@ -3,9 +3,10 @@ import { type FormMode } from "../../foundations/form.js";
3
3
  import { type FieldNote } from "./note.js";
4
4
  import { type Rounding } from "../value/rounding.js";
5
5
  import { type ReactNode } from "react";
6
- export declare function Field({ label, hint, error, required, children, htmlFor, layout, action, mode, note, changed, copy: copyAs, }: {
6
+ export declare function Field({ label, hint, error, required, children, htmlFor, layout, action, mode, note, changed, optional, copy: copyAs, }: {
7
7
  label: string;
8
- /** What is expected. A `?` on the label that opens it on press. */
8
+ /** What is expected. A `?` on the label that opens it on press — in the «settings» form
9
+ * style, written out under the label. */
9
10
  hint?: string;
10
11
  /** What has to be corrected. It goes BELOW, close to the cursor, and it says
11
12
  * what to put. */
@@ -37,6 +38,9 @@ export declare function Field({ label, hint, error, required, children, htmlFor,
37
38
  * «2 cambios sin guardar» is about — in a form of twenty, the reason to look before
38
39
  * saving — and it is read as part of the field's description. */
39
40
  changed?: boolean;
41
+ /** It may stay empty: «(opcional)» beside the label — drawn only in the «settings» form
42
+ * style, where every row says what it asks. Ignored with `required`. */
43
+ optional?: boolean;
40
44
  /** The copy button by the label (see `clipboard.tsx`): on by default, copying what the
41
45
  * control shows. A string copies that instead; `false` removes the button from this
42
46
  * field. */
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { AriaLocale } from "../../foundations/aria.js";
4
4
  import { useUiCopy } from "../../foundations/copy.js";
5
5
  import { byDensity, useDensity } from "../../foundations/density.js";
6
6
  import { FieldIdsContext, useFieldIds, } from "../../foundations/form.js";
7
- import { controlName, FormModeProvider, useFormMode, } from "../../foundations/form.js";
7
+ import { controlName, FormModeProvider, useFormMode, useFormStyle, } from "../../foundations/form.js";
8
8
  import { focusRing, tv } from "../../foundations/variants.js";
9
9
  import { FieldGroup, listOptionStyles } from "./aria.js";
10
10
  import { FieldCopy, useFieldCopy } from "./clipboard.js";
@@ -41,10 +41,25 @@ import { Button as AriaButton, Input, ListBox, ListBoxItem, NumberField as AriaN
41
41
  * Help is a `?` next to the name, opened with a press. A paragraph above the
42
42
  * control ate a line on every field. The error still goes below, close to
43
43
  * the cursor, and it says what to put.
44
+ *
45
+ * ── In the «settings» style a field is a ROW that explains itself ───
46
+ *
47
+ * `FormStyleProvider value="settings"` (an application's choice, see `foundations/form`):
48
+ * the label and its help — written out, muted, under it — on the left, the control on the
49
+ * right, «(opcional)» beside a label that may stay empty. A form filled once in a while is
50
+ * read before it is typed into, and there the paragraph is the point, not a lost line.
51
+ * The ids do not change: the written help is still what describes the control.
44
52
  * ==================================================================== */
45
- export function Field({ label, hint, error, required = false, children, htmlFor, layout, action, mode, note, changed = false, copy: copyAs, }) {
53
+ /** The label of a field in the «settings» style: the name, `*` or «(opcional)», the
54
+ * field's marks, and the help written out under it — it describes the control (`hintId`). */
55
+ function SettingsLabel({ name, hint, hintId, optional, marks, inline, }) {
56
+ const copy = useUiCopy();
57
+ return (_jsxs("div", { "data-ui": "field.label", className: `flex min-w-0 flex-col gap-0.5 ${inline ? "pt-1.5" : ""}`, children: [_jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-meta font-medium text-ink transition-colors duration-(--duration-quick) group-focus-within/field:text-primary", children: [name, optional ? (_jsxs("span", { className: "text-micro font-normal text-muted", children: ["(", copy.field.optional, ")"] })) : null, marks] }), hint === undefined ? null : (_jsx("p", { id: hintId, className: "max-w-prose text-micro text-muted", children: hint }))] }));
58
+ }
59
+ export function Field({ label, hint, error, required = false, children, htmlFor, layout, action, mode, note, changed = false, optional = false, copy: copyAs, }) {
46
60
  const d = useDensity();
47
61
  const copy = useUiCopy();
62
+ const settings = useFormStyle() === "settings";
48
63
  const copies = useFieldCopy() && copyAs !== false;
49
64
  const shown = useRef(null);
50
65
  const auto = useId();
@@ -57,10 +72,12 @@ export function Field({ label, hint, error, required = false, children, htmlFor,
57
72
  const changedId = `${id}-changed`;
58
73
  /* The error first: what has to be corrected is heard before what is worth knowing. */
59
74
  const describedBy = describedByOf(hint === undefined ? null : hintId, error === undefined ? null : errorId, note === undefined ? null : noteId, changed ? changedId : null);
60
- const labelNode = (
75
+ const name = (_jsxs("label", { id: `${id}-label`, htmlFor: id, className: inline && !settings ? "min-w-0 truncate" : "", children: [label, required ? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-ink", "aria-hidden": true, children: [" ", "*"] }), _jsxs("span", { className: "sr-only", children: [", ", copy.field.required] })] })) : null] }));
76
+ const marks = (_jsxs(_Fragment, { children: [note === undefined ? null : _jsx(NoteFlag, { note: note }), changed ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, title: copy.field.changed, className: "size-1.5 shrink-0 rounded-pill bg-accent transition-transform duration-(--duration-quick) ease-(--ease-out) starting:scale-0" }), _jsx("span", { id: changedId, className: "sr-only", children: copy.field.changed })] })) : null, copies ? (_jsx(FieldCopy, { label: label, scope: shown, ...(typeof copyAs === "string" ? { value: copyAs } : {}) })) : null] }));
77
+ const labelNode = settings ? (_jsx(SettingsLabel, { name: name, hint: hint, hintId: hintId, optional: optional && !required, marks: marks, inline: inline })) : (
61
78
  /* The label follows its control's focus: in a form of twenty fields, the eye finds the
62
79
  row being written by its name as much as by the ring. */
63
- _jsxs("span", { className: `flex min-w-0 items-center gap-1 text-micro font-medium text-muted transition-colors duration-(--duration-quick) group-focus-within/field:text-primary ${inline ? "pt-2" : ""}`, children: [_jsxs("label", { id: `${id}-label`, htmlFor: id, className: inline ? "min-w-0 truncate" : "", children: [label, required ? (_jsxs(_Fragment, { children: [_jsxs("span", { className: "text-ink", "aria-hidden": true, children: [" ", "*"] }), _jsxs("span", { className: "sr-only", children: [", ", copy.field.required] })] })) : null] }), hint === undefined ? null : _jsx(Hint, { id: hintId, children: hint }), note === undefined ? null : _jsx(NoteFlag, { note: note }), changed ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, title: copy.field.changed, className: "size-1.5 shrink-0 rounded-pill bg-accent transition-transform duration-(--duration-quick) ease-(--ease-out) starting:scale-0" }), _jsx("span", { id: changedId, className: "sr-only", children: copy.field.changed })] })) : null, copies ? (_jsx(FieldCopy, { label: label, scope: shown, ...(typeof copyAs === "string" ? { value: copyAs } : {}) })) : null] }));
80
+ _jsxs("span", { className: `flex min-w-0 items-center gap-1 text-micro font-medium text-muted transition-colors duration-(--duration-quick) group-focus-within/field:text-primary ${inline ? "pt-2" : ""}`, children: [name, hint === undefined ? null : _jsx(Hint, { id: hintId, children: hint }), marks] }));
64
81
  /* Last in the field so it is read last; absolutely placed, it still sits at the field's
65
82
  top — the static position of an absolute child of a flex or grid box is its start. */
66
83
  const noteCard = note === undefined ? null : _jsx(NoteCard, { note: note, id: noteId, owner: label });
@@ -78,6 +95,13 @@ export function Field({ label, hint, error, required = false, children, htmlFor,
78
95
  inside it then also finds the label that names it, not only the id it is handed. */
79
96
  const content = (_jsx(FieldIdsContext.Provider, { value: ids, children: _jsx("div", { ref: shown, className: "contents", children: typeof children === "function" ? children(ids) : children }) }));
80
97
  const body = (_jsxs(_Fragment, { children: [mode === undefined ? (content) : (_jsx(FormModeProvider, { value: mode, children: content })), error === undefined ? null : (_jsxs("p", { id: errorId, role: "alert", className: "flex items-start gap-1.5 text-micro text-danger", children: [_jsx(AlertCircle, { className: "mt-px size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "max-w-prose", children: error }), _jsx(CopyButton, { label: copy.copyable.report, value: () => `${label}: ${error}` })] }))] }));
98
+ if (inline && settings) {
99
+ /* The row: what it asks on the left, the answer on the right (`grid-setting`). */
100
+ return (_jsxs("div", { "data-ui": "field", "data-style": "settings", className: "grid-setting grid min-w-0 items-start gap-x-8 gap-y-2 group/field", children: [labelNode, _jsx("div", { className: "flex min-w-0 flex-col gap-1", children: body }), action === undefined ? null : (_jsx("div", { "data-under-control": true, className: "flex items-center gap-2", children: action })), noteCard] }));
101
+ }
102
+ if (settings) {
103
+ return (_jsxs("div", { "data-ui": "field", "data-style": "settings", className: "group/field flex min-w-0 flex-col gap-2", children: [_jsxs("div", { className: "flex min-w-0 items-start gap-2", children: [labelNode, action === undefined ? null : _jsx("span", { className: "ml-auto shrink-0", children: action })] }), body, noteCard] }));
104
+ }
81
105
  if (inline) {
82
106
  return (_jsxs("div", { className: "grid-label grid min-w-0 items-start gap-x-4 gap-y-1 group/field", children: [labelNode, _jsx("div", { className: "flex min-w-0 flex-col gap-1", children: body }), action === undefined ? null : (_jsx("div", { "data-under-control": true, className: "flex items-center gap-2", children: action })), noteCard] }));
83
107
  }
@@ -97,6 +121,7 @@ export function Field({ label, hint, error, required = false, children, htmlFor,
97
121
  */
98
122
  export function DataField({ label, value, hint, layout, mono = false, action, note, copy: copyAs, }) {
99
123
  const d = useDensity();
124
+ const settings = useFormStyle() === "settings";
100
125
  const shown = useRef(null);
101
126
  const allowed = useFieldCopy() && copyAs !== false;
102
127
  const noteId = `${useId()}-note`;
@@ -104,9 +129,13 @@ export function DataField({ label, value, hint, layout, mono = false, action, no
104
129
  const inline = layout === "inline" || (layout === undefined && sheetLayout === "horizontal");
105
130
  const empty = value === undefined || value === null || value === "";
106
131
  const unset = useUiCopy().field.unset;
107
- const labelNode = (_jsxs("span", { className: `flex min-w-0 items-center gap-1 text-micro font-medium text-muted ${inline ? "pt-0.5" : ""}`, children: [_jsx("span", { className: inline ? "min-w-0 truncate" : "", children: label }), hint === undefined ? null : _jsx(Hint, { children: hint }), note === undefined ? null : _jsx(NoteFlag, { note: note }), allowed && !empty ? (_jsx(FieldCopy, { label: label, scope: shown, ...(typeof copyAs === "string" ? { value: copyAs } : {}) })) : null] }));
132
+ const marks = (_jsxs(_Fragment, { children: [note === undefined ? null : _jsx(NoteFlag, { note: note }), allowed && !empty ? (_jsx(FieldCopy, { label: label, scope: shown, ...(typeof copyAs === "string" ? { value: copyAs } : {}) })) : null] }));
133
+ const labelNode = settings ? (_jsx(SettingsLabel, { name: _jsx("span", { children: label }), hint: hint, hintId: undefined, optional: false, marks: marks, inline: false })) : (_jsxs("span", { className: `flex min-w-0 items-center gap-1 text-micro font-medium text-muted ${inline ? "pt-0.5" : ""}`, children: [_jsx("span", { className: inline ? "min-w-0 truncate" : "", children: label }), hint === undefined ? null : _jsx(Hint, { children: hint }), marks] }));
108
134
  const noteCard = note === undefined ? null : _jsx(NoteCard, { note: note, id: noteId, owner: label });
109
135
  const valueNode = (_jsx("span", { ref: shown, ...(note === undefined ? {} : { "aria-describedby": noteId }), className: `min-w-0 text-meta ${empty ? "text-muted italic" : "text-ink"} ${mono ? "font-mono tabular-nums" : ""}`, children: empty ? unset : value }));
136
+ if (inline && settings) {
137
+ return (_jsxs("div", { "data-ui": "field", "data-style": "settings", className: "grid-setting grid min-w-0 items-start gap-x-8 gap-y-1 group/field", children: [labelNode, _jsxs("span", { className: "flex min-w-0 items-baseline gap-2", children: [valueNode, action] }), noteCard] }));
138
+ }
110
139
  if (inline) {
111
140
  return (_jsxs("div", { className: "grid-label grid min-w-0 items-baseline gap-x-4 gap-y-0.5 group/field", children: [labelNode, _jsxs("span", { className: "flex min-w-0 items-baseline gap-2", children: [valueNode, action] }), noteCard] }));
112
141
  }
@@ -29,6 +29,10 @@ export type MetricProps = {
29
29
  * zero. */
30
30
  value?: number | string;
31
31
  label: string;
32
+ /** A second reading of the same count, already formatted, under the label: «6 · Bs
33
+ * 1.000,00» is how many AND how much. Muted and small — the figure on top is still the
34
+ * one compared across the row. */
35
+ detail?: string;
32
36
  /** The figure is being read. The label stays and the box keeps its size, so a row of
33
37
  * metrics does not jump when the numbers land one at a time. */
34
38
  loading?: boolean;
@@ -50,7 +54,14 @@ export type MetricProps = {
50
54
  better?: "up" | "down";
51
55
  };
52
56
  };
53
- export declare function Metric({ value, label, tone, icon: Icon, onClick, active, change, loading, }: MetricProps): import("react").JSX.Element;
57
+ export declare function Metric({ value, label, detail, tone, icon: Icon, onClick, active, change, loading, }: MetricProps): import("react").JSX.Element;
58
+ /** How a figure moved against a named period: «↗ +18 % vs 2025». The arrow carries the
59
+ * direction and the words the period, so the colour is never the only channel. A board's
60
+ * stat tile says it the same way. */
61
+ export declare function MetricChange({ change, format, }: {
62
+ change: NonNullable<MetricProps["change"]>;
63
+ format: (value: number) => string;
64
+ }): import("react").JSX.Element;
54
65
  /** The row of metrics. It wraps if they don't fit; it doesn't scroll: a hidden
55
66
  * metric is a filter nobody finds. */
56
67
  export declare function Metrics({ children }: {
@@ -14,7 +14,7 @@ const TONE = {
14
14
  ink and the tone is only visible when the card is lit up. */
15
15
  accent: { background: "bg-accent/20", text: "text-ink", edge: "border-accent/50" },
16
16
  };
17
- export function Metric({ value, label, tone = "neutral", icon: Icon, onClick, active = false, change, loading = false, }) {
17
+ export function Metric({ value, label, detail, tone = "neutral", icon: Icon, onClick, active = false, change, loading = false, }) {
18
18
  const copy = useUiCopy();
19
19
  const sup = useSurface();
20
20
  const t = TONE[tone];
@@ -40,13 +40,18 @@ export function Metric({ value, label, tone = "neutral", icon: Icon, onClick, ac
40
40
  const content = (_jsxs(_Fragment, { children: [_jsxs("span", { className: `flex items-center gap-1.5 text-title font-semibold tabular-nums ${t.text}`, children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2, "aria-hidden": true })), loading ? (
41
41
  /* A bar one line of the figure tall (`h-lh`), so the box is the size it will
42
42
  be. It appears late, like every skeleton: a fast read never shows it. */
43
- _jsx("span", { "aria-hidden": true, className: `inline-block h-lh w-16 animate-reveal-late rounded-control ${bySurface(sup, "bg-ink/8", "bg-chrome-ink/12")}` })) : (figure)] }), _jsx("span", { className: `text-micro ${bySurface(sup, "text-muted", "text-chrome-muted")}`, children: label }), change === undefined || loading ? null : (_jsx(Change, { change: change, format: percent.format }))] }));
43
+ _jsx("span", { "aria-hidden": true, className: `inline-block h-lh w-16 animate-reveal-late rounded-control ${bySurface(sup, "bg-ink/8", "bg-chrome-ink/12")}` })) : (figure)] }), _jsx("span", { className: `text-micro ${bySurface(sup, "text-muted", "text-chrome-muted")}`, children: label }), detail === undefined || loading ? null : (_jsx("span", { "data-ui": "metric.detail", className: `text-micro tabular-nums ${bySurface(sup, "text-muted", "text-chrome-muted")}`, children: detail })), change === undefined || loading ? null : (_jsx(MetricChange, { change: change, format: percent.format }))] }));
44
44
  if (onClick === undefined) {
45
- return (_jsx("div", { "data-ui": "metric", className: box, "aria-label": loading ? `${label}: ${copy.failed.loading}` : `${figure} ${label}`, ...(loading ? { "aria-busy": true } : {}), children: content }));
45
+ return (_jsx("div", { "data-ui": "metric", className: box, "aria-label": loading
46
+ ? `${label}: ${copy.failed.loading}`
47
+ : `${figure} ${label}${detail === undefined ? "" : `, ${detail}`}`, ...(loading ? { "aria-busy": true } : {}), children: content }));
46
48
  }
47
49
  return (_jsxs("button", { type: "button", onClick: onClick, "aria-pressed": active, ...(loading ? { "aria-busy": true } : {}), "data-ui": "metric", className: box, children: [content, loading ? _jsx("span", { className: "sr-only", children: copy.failed.loading }) : null] }));
48
50
  }
49
- function Change({ change, format, }) {
51
+ /** How a figure moved against a named period: «↗ +18 % vs 2025». The arrow carries the
52
+ * direction and the words the period, so the colour is never the only channel. A board's
53
+ * stat tile says it the same way. */
54
+ export function MetricChange({ change, format, }) {
50
55
  const copy = useUiCopy();
51
56
  const sup = useSurface();
52
57
  const up = change.by > 0;