@eifi1/ui-kit 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 +20 -16
- package/dist/components/alert-banner.d.ts +26 -1
- package/dist/components/alert-banner.js +10 -7
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +2 -0
- package/dist/components/bulk-action-bar.d.ts +51 -5
- package/dist/components/bulk-action-bar.js +88 -41
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-group.d.ts +58 -3
- package/dist/components/button-group.js +56 -5
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/calculator.d.ts +2 -0
- package/dist/components/calendar-heatmap.d.ts +124 -0
- package/dist/components/calendar-heatmap.js +295 -0
- package/dist/components/calendar-heatmap.js.map +1 -0
- package/dist/components/choice-card.d.ts +34 -2
- package/dist/components/choice-card.js +49 -0
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/copy-button.d.ts +1 -0
- package/dist/components/data-table.js +2 -0
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +52 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/file-button.d.ts +1 -0
- package/dist/components/file-dropzone.d.ts +1 -0
- package/dist/components/floating-panel.d.ts +147 -4
- package/dist/components/floating-panel.js +188 -28
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/list.d.ts +14 -1
- package/dist/components/list.js +7 -1
- package/dist/components/list.js.map +1 -1
- package/dist/components/menu-item.d.ts +11 -1
- package/dist/components/menu-item.js +6 -1
- package/dist/components/menu-item.js.map +1 -1
- package/dist/components/mini-calendar.d.ts +70 -5
- package/dist/components/mini-calendar.js +166 -62
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/nav-pills.d.ts +66 -0
- package/dist/components/nav-pills.js +65 -0
- package/dist/components/nav-pills.js.map +1 -0
- package/dist/components/number-field.d.ts +2 -0
- package/dist/components/number-input.d.ts +2 -0
- package/dist/components/numpad-sheet.d.ts +2 -0
- package/dist/components/progress-bar.d.ts +31 -2
- package/dist/components/progress-bar.js +73 -7
- package/dist/components/progress-bar.js.map +1 -1
- package/dist/components/series-chart.d.ts +16 -0
- package/dist/components/series-chart.js +4 -1
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +1 -0
- package/dist/components/status-dot.d.ts +6 -2
- package/dist/components/status-dot.js +6 -1
- package/dist/components/status-dot.js.map +1 -1
- package/dist/components/table.d.ts +40 -8
- package/dist/components/table.js +41 -7
- package/dist/components/table.js.map +1 -1
- package/dist/components/text.d.ts +8 -1
- package/dist/components/text.js +1 -0
- package/dist/components/text.js.map +1 -1
- package/dist/components/time-input.d.ts +1 -0
- package/dist/components/toggle-group.d.ts +15 -0
- package/dist/components/toggle-group.js +23 -3
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/tooltip.d.ts +11 -3
- package/dist/components/tooltip.js +2 -0
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/ui.d.ts +55 -4
- package/dist/components/ui.js +84 -7
- package/dist/components/ui.js.map +1 -1
- package/dist/components/user-avatar.d.ts +25 -3
- package/dist/components/user-avatar.js +32 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +1 -0
- package/dist/i18n/defaults.d.ts +2 -0
- package/dist/i18n/defaults.js +2 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +3 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +2 -0
- package/dist/i18n/locales/de-CH.d.ts +2 -0
- package/dist/i18n/locales/de-informal.d.ts +2 -0
- package/dist/i18n/locales/de.d.ts +2 -0
- package/dist/i18n/locales/de.js +9 -1
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +2 -0
- package/dist/i18n/locales/es.js +9 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +2 -0
- package/dist/i18n/locales/fr.js +9 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +2 -0
- package/dist/i18n/locales/hu.js +9 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +2 -0
- package/dist/i18n/locales/it.js +9 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +2 -0
- package/dist/i18n/locales/zh.js +9 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/clipping.d.ts +21 -5
- package/dist/lib/clipping.js +3 -0
- package/dist/lib/clipping.js.map +1 -1
- package/dist/lib/dates.d.ts +17 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/rhf/form.d.ts +1 -0
- package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
- package/dist/rhf/use-rhf-wizard-step.js +38 -0
- package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
- package/dist/rhf.d.ts +2 -0
- package/dist/rhf.js +1 -0
- package/dist/rhf.js.map +1 -1
- package/dist/shell/topbar-action-menu.d.ts +73 -3
- package/dist/shell/topbar-action-menu.js +100 -27
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +2 -1
- package/dist/wizard/stepper-nav.d.ts +1 -0
- package/dist/wizard/wizard-context.d.ts +7 -1
- package/dist/wizard/wizard-context.js +4 -0
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/alert-banner.tsx +36 -7
- package/src/components/bulk-action-bar.tsx +163 -57
- package/src/components/button-group.tsx +124 -4
- package/src/components/calendar-heatmap.tsx +504 -0
- package/src/components/choice-card.tsx +97 -1
- package/src/components/data-table.tsx +7 -0
- package/src/components/field.tsx +137 -0
- package/src/components/floating-panel.tsx +366 -15
- package/src/components/list.tsx +28 -2
- package/src/components/menu-item.tsx +22 -1
- package/src/components/mini-calendar.tsx +245 -54
- package/src/components/nav-pills.tsx +145 -0
- package/src/components/progress-bar.tsx +129 -11
- package/src/components/series-chart.tsx +21 -0
- package/src/components/status-dot.tsx +10 -2
- package/src/components/table.tsx +85 -11
- package/src/components/text.tsx +9 -1
- package/src/components/toggle-group.tsx +48 -3
- package/src/components/tooltip.tsx +17 -3
- package/src/components/ui.tsx +149 -11
- package/src/components/user-avatar.tsx +57 -3
- package/src/i18n/defaults.ts +2 -0
- package/src/i18n/kit-labels.tsx +2 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/hu.ts +9 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +5 -0
- package/src/lib/clipping.ts +22 -4
- package/src/lib/dates.ts +37 -0
- package/src/rhf/use-rhf-wizard-step.ts +113 -0
- package/src/rhf.ts +2 -0
- package/src/shell/topbar-action-menu.tsx +239 -49
- package/src/wizard/wizard-context.tsx +9 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { cn } from "../lib/cn.js";
|
|
5
|
+
import { dirOf, horizontalStep } from "../lib/direction.js";
|
|
6
|
+
import { addMonthsClamped, localeWeekStart, parseIsoDate, toLocalIso } from "../lib/dates.js";
|
|
7
|
+
import { useKitLabels, useKitLocale, useKitWeekStart } from "../i18n/kit-labels.js";
|
|
8
|
+
import { Tooltip } from "./tooltip.js";
|
|
9
|
+
const DEFAULT_CALENDAR_HEATMAP_LABELS = {
|
|
10
|
+
grid: "Daily values",
|
|
11
|
+
day: (date, value) => `${date}: ${value}`,
|
|
12
|
+
less: "Less",
|
|
13
|
+
more: "More",
|
|
14
|
+
truncated: (count) => `Showing the most recent days; ${count} earlier ${count === 1 ? "day is" : "days are"} not shown.`
|
|
15
|
+
};
|
|
16
|
+
const DAY_NAME_FORMAT = {
|
|
17
|
+
weekday: "long",
|
|
18
|
+
day: "numeric",
|
|
19
|
+
month: "long",
|
|
20
|
+
year: "numeric"
|
|
21
|
+
};
|
|
22
|
+
const EMPTY_FILL = "color-mix(in oklab, var(--text-primary) 8%, var(--bg-surface))";
|
|
23
|
+
const weekdayIndex = (d, weekStart) => (d.getDay() - weekStart + 7) % 7;
|
|
24
|
+
function heatmapLevel(value, max, levels) {
|
|
25
|
+
if (!(value > 0) || !(max > 0) || levels < 1) return 0;
|
|
26
|
+
return Math.min(levels, Math.max(1, Math.ceil(value / max * levels)));
|
|
27
|
+
}
|
|
28
|
+
function levelPercent(level, levels) {
|
|
29
|
+
if (levels <= 1) return 100;
|
|
30
|
+
return Math.round(20 + 80 * (level - 1) / (levels - 1));
|
|
31
|
+
}
|
|
32
|
+
function levelFill(level, levels, color) {
|
|
33
|
+
if (level === 0) return EMPTY_FILL;
|
|
34
|
+
return `color-mix(in oklab, ${color} ${levelPercent(level, levels)}%, var(--bg-surface))`;
|
|
35
|
+
}
|
|
36
|
+
function CalendarHeatmap({
|
|
37
|
+
data,
|
|
38
|
+
from,
|
|
39
|
+
to,
|
|
40
|
+
layout = "weeks",
|
|
41
|
+
selected,
|
|
42
|
+
onSelect,
|
|
43
|
+
formatValue: formatValueProp,
|
|
44
|
+
tooltip,
|
|
45
|
+
sensitive = true,
|
|
46
|
+
max: maxProp,
|
|
47
|
+
levels = 4,
|
|
48
|
+
color = "var(--brand)",
|
|
49
|
+
maxDays,
|
|
50
|
+
legend = true,
|
|
51
|
+
locale: localeProp,
|
|
52
|
+
weekStartsOn,
|
|
53
|
+
labels: labelsProp,
|
|
54
|
+
className,
|
|
55
|
+
"aria-label": ariaLabel,
|
|
56
|
+
...rest
|
|
57
|
+
}) {
|
|
58
|
+
const labels = useKitLabels("calendarHeatmap", DEFAULT_CALENDAR_HEATMAP_LABELS, labelsProp);
|
|
59
|
+
const locale = useKitLocale(localeProp);
|
|
60
|
+
const providerWeekStart = useKitWeekStart();
|
|
61
|
+
const weekStart = weekStartsOn ?? providerWeekStart ?? localeWeekStart(locale);
|
|
62
|
+
const numberFormat = useMemo(() => new Intl.NumberFormat(locale), [locale]);
|
|
63
|
+
const formatValue = formatValueProp ?? ((v) => numberFormat.format(v));
|
|
64
|
+
const values = useMemo(() => {
|
|
65
|
+
const m = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const p of data) m.set(p.date, (m.get(p.date) ?? 0) + p.value);
|
|
67
|
+
return m;
|
|
68
|
+
}, [data]);
|
|
69
|
+
const { days, dropped } = useMemo(() => {
|
|
70
|
+
const start = parseIsoDate(from);
|
|
71
|
+
const end = parseIsoDate(to);
|
|
72
|
+
const list = [];
|
|
73
|
+
if (!start || !end || end < start) return { days: list, dropped: 0 };
|
|
74
|
+
const cursor = new Date(end);
|
|
75
|
+
const cap = maxDays && maxDays > 0 ? maxDays : Infinity;
|
|
76
|
+
while (cursor >= start && list.length < cap) {
|
|
77
|
+
list.unshift(new Date(cursor));
|
|
78
|
+
cursor.setDate(cursor.getDate() - 1);
|
|
79
|
+
}
|
|
80
|
+
const first = list[0];
|
|
81
|
+
const trimmed = first ? Math.round((first.getTime() - start.getTime()) / 864e5) : 0;
|
|
82
|
+
return { days: list, dropped: Math.max(0, trimmed) };
|
|
83
|
+
}, [from, to, maxDays]);
|
|
84
|
+
const firstIso = days.length ? toLocalIso(days[0]) : "";
|
|
85
|
+
const lastIso = days.length ? toLocalIso(days[days.length - 1]) : "";
|
|
86
|
+
const max = useMemo(() => {
|
|
87
|
+
if (maxProp !== void 0) return maxProp;
|
|
88
|
+
let m = 0;
|
|
89
|
+
for (const d of days) m = Math.max(m, values.get(toLocalIso(d)) ?? 0);
|
|
90
|
+
return m;
|
|
91
|
+
}, [maxProp, days, values]);
|
|
92
|
+
const clampIso = (iso) => iso < firstIso ? firstIso : iso > lastIso ? lastIso : iso;
|
|
93
|
+
const [activeState, setActiveIso] = useState(() => selected || lastIso);
|
|
94
|
+
const [lastSelected, setLastSelected] = useState(selected);
|
|
95
|
+
if (lastSelected !== selected) {
|
|
96
|
+
setLastSelected(selected);
|
|
97
|
+
if (selected) setActiveIso(selected);
|
|
98
|
+
}
|
|
99
|
+
const activeIso = days.length ? clampIso(activeState || lastIso) : "";
|
|
100
|
+
const gridRef = useRef(null);
|
|
101
|
+
const scrollerRef = useRef(null);
|
|
102
|
+
const pendingFocus = useRef(null);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const iso = pendingFocus.current;
|
|
105
|
+
if (!iso) return;
|
|
106
|
+
pendingFocus.current = null;
|
|
107
|
+
gridRef.current?.querySelector(`[data-day="${iso}"]`)?.focus();
|
|
108
|
+
});
|
|
109
|
+
useLayoutEffect(() => {
|
|
110
|
+
const el = scrollerRef.current;
|
|
111
|
+
if (!el || layout !== "weeks") return;
|
|
112
|
+
const toEnd = () => {
|
|
113
|
+
el.scrollLeft = dirOf(el) === "rtl" ? -el.scrollWidth : el.scrollWidth;
|
|
114
|
+
};
|
|
115
|
+
toEnd();
|
|
116
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
117
|
+
let pinned = true;
|
|
118
|
+
const onScroll = () => {
|
|
119
|
+
pinned = Math.abs(el.scrollLeft) >= el.scrollWidth - el.clientWidth - 1;
|
|
120
|
+
};
|
|
121
|
+
const ro = new ResizeObserver(() => {
|
|
122
|
+
if (pinned) toEnd();
|
|
123
|
+
});
|
|
124
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
125
|
+
ro.observe(el);
|
|
126
|
+
return () => {
|
|
127
|
+
ro.disconnect();
|
|
128
|
+
el.removeEventListener("scroll", onScroll);
|
|
129
|
+
};
|
|
130
|
+
}, [layout, firstIso, lastIso]);
|
|
131
|
+
const formatDay = (d) => d.toLocaleDateString(locale, DAY_NAME_FORMAT);
|
|
132
|
+
const weekdayLabels = useMemo(() => {
|
|
133
|
+
const ref = new Date(2024, 0, 7 + weekStart);
|
|
134
|
+
return Array.from({ length: 7 }, (_, i) => {
|
|
135
|
+
const d = new Date(ref);
|
|
136
|
+
d.setDate(ref.getDate() + i);
|
|
137
|
+
return {
|
|
138
|
+
short: d.toLocaleDateString(locale, { weekday: "short" }),
|
|
139
|
+
long: d.toLocaleDateString(locale, { weekday: "long" })
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}, [locale, weekStart]);
|
|
143
|
+
const lead = days.length ? weekdayIndex(days[0], weekStart) : 0;
|
|
144
|
+
const weekCount = Math.ceil((lead + days.length) / 7);
|
|
145
|
+
const dayAt = (i) => i >= lead && i - lead < days.length ? days[i - lead] : null;
|
|
146
|
+
const move = (e) => {
|
|
147
|
+
const current = parseIsoDate(activeIso);
|
|
148
|
+
if (!current) return;
|
|
149
|
+
const next = new Date(current);
|
|
150
|
+
const step = horizontalStep(e.key, e.currentTarget);
|
|
151
|
+
const across = layout === "weeks" ? 7 : 1;
|
|
152
|
+
const down = layout === "weeks" ? 1 : 7;
|
|
153
|
+
switch (step ? "horizontal" : e.key) {
|
|
154
|
+
case "horizontal":
|
|
155
|
+
next.setDate(next.getDate() + step * across);
|
|
156
|
+
break;
|
|
157
|
+
case "ArrowUp":
|
|
158
|
+
next.setDate(next.getDate() - down);
|
|
159
|
+
break;
|
|
160
|
+
case "ArrowDown":
|
|
161
|
+
next.setDate(next.getDate() + down);
|
|
162
|
+
break;
|
|
163
|
+
case "PageUp":
|
|
164
|
+
next.setTime(addMonthsClamped(next, -1).getTime());
|
|
165
|
+
break;
|
|
166
|
+
case "PageDown":
|
|
167
|
+
next.setTime(addMonthsClamped(next, 1).getTime());
|
|
168
|
+
break;
|
|
169
|
+
case "Home":
|
|
170
|
+
next.setTime(days[0].getTime());
|
|
171
|
+
break;
|
|
172
|
+
case "End":
|
|
173
|
+
next.setTime(days[days.length - 1].getTime());
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
const iso = clampIso(toLocalIso(next));
|
|
180
|
+
if (iso === activeIso) return;
|
|
181
|
+
pendingFocus.current = iso;
|
|
182
|
+
setActiveIso(iso);
|
|
183
|
+
};
|
|
184
|
+
const legendLevels = Array.from({ length: levels + 1 }, (_, l) => l);
|
|
185
|
+
const cell = (d, wrapClass, cellClass, withNumber) => {
|
|
186
|
+
const iso = toLocalIso(d);
|
|
187
|
+
const raw = values.get(iso);
|
|
188
|
+
const value = raw ?? 0;
|
|
189
|
+
const level = heatmapLevel(value, max, levels);
|
|
190
|
+
const fill = levelFill(level, levels, color);
|
|
191
|
+
const formattedDate = formatDay(d);
|
|
192
|
+
const formattedValue = formatValue(value);
|
|
193
|
+
const name = labels.day(formattedDate, formattedValue);
|
|
194
|
+
const label = tooltip ? tooltip({ iso, date: d, value, hasData: raw !== void 0, level, formattedDate, formattedValue }) : name;
|
|
195
|
+
const isSelected = selected === iso;
|
|
196
|
+
const strong = level > 0 && levelPercent(level, levels) >= 45;
|
|
197
|
+
const shared = {
|
|
198
|
+
role: "gridcell",
|
|
199
|
+
"data-day": iso,
|
|
200
|
+
"data-level": level,
|
|
201
|
+
tabIndex: iso === activeIso ? 0 : -1,
|
|
202
|
+
"aria-label": name,
|
|
203
|
+
"aria-selected": onSelect ? isSelected : void 0,
|
|
204
|
+
onKeyDown: move,
|
|
205
|
+
onFocus: () => {
|
|
206
|
+
if (iso !== activeIso) setActiveIso(iso);
|
|
207
|
+
},
|
|
208
|
+
style: { background: fill, color: strong ? "var(--bg-surface)" : "var(--text-primary)" },
|
|
209
|
+
className: cn(
|
|
210
|
+
cellClass,
|
|
211
|
+
isSelected && "ring-2 ring-[var(--text-primary)]",
|
|
212
|
+
onSelect && "cursor-pointer hover:ring-1 hover:ring-[var(--brand)]"
|
|
213
|
+
)
|
|
214
|
+
};
|
|
215
|
+
const inner = withNumber ? /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-[11px] leading-none tabular-nums", children: numberFormat.format(d.getDate()) }) : null;
|
|
216
|
+
return /* @__PURE__ */ jsx(Tooltip, { label, portal: true, redact: sensitive, role: "none", className: wrapClass, children: onSelect ? /* @__PURE__ */ jsx("button", { type: "button", ...shared, onClick: () => onSelect(iso), children: inner }) : /* @__PURE__ */ jsx("div", { ...shared, children: inner }) }, iso);
|
|
217
|
+
};
|
|
218
|
+
const gridName = ariaLabel ?? labels.grid;
|
|
219
|
+
let body;
|
|
220
|
+
if (layout === "weeks") {
|
|
221
|
+
const columns = { gridTemplateColumns: `var(--heatmap-label, 2rem) repeat(${weekCount}, var(--heatmap-cell, 0.75rem))` };
|
|
222
|
+
const cellSize = "size-[var(--heatmap-cell,0.75rem)]";
|
|
223
|
+
const monthLabels = Array.from({ length: weekCount }, (_, w) => {
|
|
224
|
+
for (let r = 0; r < 7; r++) {
|
|
225
|
+
const d = dayAt(w * 7 + r);
|
|
226
|
+
if (d && (d.getDate() === 1 || w === 0 && r === lead && d.getDate() <= 14)) {
|
|
227
|
+
return d.toLocaleDateString(locale, { month: "short" });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return "";
|
|
231
|
+
});
|
|
232
|
+
body = /* @__PURE__ */ jsx("div", { ref: scrollerRef, className: "overflow-x-auto pb-1", children: /* @__PURE__ */ jsxs("div", { ref: gridRef, role: "grid", "aria-label": gridName, className: "inline-grid gap-0.5", children: [
|
|
233
|
+
/* @__PURE__ */ jsxs("div", { "aria-hidden": true, className: "grid gap-0.5 text-[10px] leading-3 text-[var(--text-muted)]", style: columns, children: [
|
|
234
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
235
|
+
monthLabels.map((m, w) => /* @__PURE__ */ jsx("span", { className: "overflow-visible whitespace-nowrap", children: m }, w))
|
|
236
|
+
] }),
|
|
237
|
+
Array.from({ length: 7 }, (_, r) => /* @__PURE__ */ jsxs("div", { role: "row", className: "grid gap-0.5", style: columns, children: [
|
|
238
|
+
/* @__PURE__ */ jsx(
|
|
239
|
+
"div",
|
|
240
|
+
{
|
|
241
|
+
role: "rowheader",
|
|
242
|
+
"aria-label": weekdayLabels[r].long,
|
|
243
|
+
className: "overflow-hidden pe-1 text-[10px] leading-3 text-[var(--text-muted)]",
|
|
244
|
+
children: r % 2 === 1 ? weekdayLabels[r].short : ""
|
|
245
|
+
}
|
|
246
|
+
),
|
|
247
|
+
Array.from({ length: weekCount }, (_2, w) => {
|
|
248
|
+
const d = dayAt(w * 7 + r);
|
|
249
|
+
return d ? cell(d, cellSize, cn(cellSize, "block rounded-sm"), false) : /* @__PURE__ */ jsx("div", { role: "gridcell", className: cellSize }, `pad-${w}`);
|
|
250
|
+
})
|
|
251
|
+
] }, r))
|
|
252
|
+
] }) });
|
|
253
|
+
} else {
|
|
254
|
+
const rows = Array.from({ length: weekCount }, (_, w) => w);
|
|
255
|
+
body = /* @__PURE__ */ jsxs("div", { ref: gridRef, role: "grid", "aria-label": gridName, className: "grid gap-1", children: [
|
|
256
|
+
/* @__PURE__ */ jsx("div", { role: "row", className: "grid grid-cols-7 gap-1", children: weekdayLabels.map((w, i) => /* @__PURE__ */ jsx(
|
|
257
|
+
"div",
|
|
258
|
+
{
|
|
259
|
+
role: "columnheader",
|
|
260
|
+
"aria-label": w.long,
|
|
261
|
+
className: "pb-0.5 text-center text-[10px] uppercase tracking-wide text-[var(--text-muted)]",
|
|
262
|
+
children: w.short
|
|
263
|
+
},
|
|
264
|
+
i
|
|
265
|
+
)) }),
|
|
266
|
+
rows.map((w) => /* @__PURE__ */ jsx("div", { role: "row", className: "grid grid-cols-7 gap-1", children: Array.from({ length: 7 }, (_, c) => {
|
|
267
|
+
const d = dayAt(w * 7 + c);
|
|
268
|
+
return d ? cell(d, "aspect-square w-full", "flex h-full w-full items-center justify-center rounded", true) : /* @__PURE__ */ jsx("div", { role: "gridcell", className: "aspect-square" }, `pad-${c}`);
|
|
269
|
+
}) }, w))
|
|
270
|
+
] });
|
|
271
|
+
}
|
|
272
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, className: cn("min-w-0", className), children: [
|
|
273
|
+
dropped > 0 && /* @__PURE__ */ jsx("div", { className: "mb-2 text-xs text-[var(--text-muted)]", children: labels.truncated(dropped) }),
|
|
274
|
+
body,
|
|
275
|
+
legend && /* @__PURE__ */ jsxs("div", { "aria-hidden": true, className: "mt-2 flex items-center justify-end gap-1 text-[10px] text-[var(--text-muted)]", children: [
|
|
276
|
+
/* @__PURE__ */ jsx("span", { className: "me-0.5", children: labels.less }),
|
|
277
|
+
legendLevels.map((l) => /* @__PURE__ */ jsx(
|
|
278
|
+
"span",
|
|
279
|
+
{
|
|
280
|
+
"data-legend-level": l,
|
|
281
|
+
className: "size-2.5 rounded-sm",
|
|
282
|
+
style: { background: levelFill(l, levels, color) }
|
|
283
|
+
},
|
|
284
|
+
l
|
|
285
|
+
)),
|
|
286
|
+
/* @__PURE__ */ jsx("span", { className: "ms-0.5", children: labels.more })
|
|
287
|
+
] })
|
|
288
|
+
] });
|
|
289
|
+
}
|
|
290
|
+
export {
|
|
291
|
+
CalendarHeatmap,
|
|
292
|
+
DEFAULT_CALENDAR_HEATMAP_LABELS,
|
|
293
|
+
heatmapLevel
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=calendar-heatmap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/calendar-heatmap.tsx"],"sourcesContent":["import { useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { dirOf, horizontalStep } from \"../lib/direction\";\nimport { addMonthsClamped, localeWeekStart, parseIsoDate, toLocalIso } from \"../lib/dates\";\nimport { useKitLabels, useKitLocale, useKitWeekStart } from \"../i18n/kit-labels\";\nimport { Tooltip } from \"./tooltip\";\nimport type { WeekDay } from \"./mini-calendar\";\n\n/**\n * Every string the heatmap speaks — the `calendarHeatmap` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. Dates and\n * values arrive already formatted (in `locale`, and through `formatValue`), so the\n * functions only arrange them.\n */\nexport interface CalendarHeatmapLabels {\n /** Accessible name of the grid. */\n grid: string;\n /**\n * One day: its accessible name, and the tooltip unless `tooltip` is given. `date`\n * is the whole date in `locale` (\"Monday, 14 September 2026\"), `value` the day's\n * figure through `formatValue`.\n */\n day: (date: string, value: string) => string;\n /** The two ends of the legend's scale. */\n less: string;\n more: string;\n /** `maxDays` cut the window: how many of its earliest days are not drawn. */\n truncated: (count: number) => string;\n}\n\n/** English defaults, exported as the `calendarHeatmap` namespace of `UiKitLabels`. */\nexport const DEFAULT_CALENDAR_HEATMAP_LABELS: CalendarHeatmapLabels = {\n grid: \"Daily values\",\n day: (date, value) => `${date}: ${value}`,\n less: \"Less\",\n more: \"More\",\n truncated: (count) =>\n `Showing the most recent days; ${count} earlier ${count === 1 ? \"day is\" : \"days are\"} not shown.`,\n};\n\n/** One day's figure. Several entries for one date are added up. */\nexport interface CalendarHeatmapDatum {\n /** \"YYYY-MM-DD\". */\n date: string;\n value: number;\n}\n\n/** What `tooltip` is told about the day under the pointer. */\nexport interface CalendarHeatmapDay {\n iso: string;\n date: Date;\n /** The day's figure; `0` when `data` has no entry for it (see `hasData`). */\n value: number;\n hasData: boolean;\n /** `0` = empty … `levels` = the busiest. */\n level: number;\n /** The whole date in `locale`. */\n formattedDate: string;\n /** `value` through `formatValue`. */\n formattedValue: string;\n}\n\n/**\n * `onSelect` is omitted from the `<div>` attributes for the reason `MiniCalendar` gives:\n * the DOM event of that name is a text-selection event, and this one answers with a date.\n */\nexport interface CalendarHeatmapProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onSelect\"> {\n data: readonly CalendarHeatmapDatum[];\n /** The window, inclusive, as \"YYYY-MM-DD\". */\n from: string;\n to: string;\n /**\n * `\"weeks\"` (default): the contribution-graph shape — one COLUMN per week, the\n * weekdays down the side, month names along the top; a year fits in ~53 small\n * squares and scrolls sideways where it does not. `\"month\"`: a 7-column calendar\n * with day numbers in large square cells, for a single month on a phone (switch on\n * `useMediaQuery` and narrow `from`/`to` to the month).\n */\n layout?: \"weeks\" | \"month\";\n /** The day shown as selected (\"YYYY-MM-DD\"). */\n selected?: string;\n /** Makes each day a button: a click (or Enter/Space) selects it — a drill-down into\n * that day's rows, a day panel. Without it the days are focusable but inert. */\n onSelect?: (iso: string) => void;\n /** How a value is written in the tooltip and the day's name. Default: `Intl.NumberFormat`\n * in `locale`. Pass a currency formatter for money. */\n formatValue?: (value: number) => string;\n /** Tooltip content for a day. Default: `labels.day(date, value)`. */\n tooltip?: (day: CalendarHeatmapDay) => ReactNode;\n /**\n * Tag each tooltip `data-private`, so the host's demo-mode rule blurs it (the\n * attribute `Tooltip redact` and `StatTile sensitive` carry). ON by default: a heatmap\n * is almost always the user's own figures, and a missing tag is silent — the grid\n * looks anonymous and the bubble spells the amount out on hover.\n */\n sensitive?: boolean;\n /** The value that reaches the top of the scale. Default: the largest value ON SCREEN,\n * so a peak outside the window does not wash the drawn days out to empty. */\n max?: number;\n /** How many non-empty intensity steps. Default 4. */\n levels?: number;\n /** The scale's colour, as any CSS colour. Default `var(--brand)`; each step is this\n * mixed into `--bg-surface`, so the ramp follows the theme. */\n color?: string;\n /**\n * The most days to draw. A longer window keeps its LATEST `maxDays` and says how many\n * it left out (`labels.truncated`) rather than silently ending. Default: no cap.\n */\n maxDays?: number;\n /** Draw the Less … More legend. Default `true`. */\n legend?: boolean;\n /** BCP 47 tag for the dates, month and weekday names and numbers. */\n locale?: string;\n /** `0` = Sunday … `6` = Saturday. Default: the provider's, else the locale's. */\n weekStartsOn?: WeekDay;\n labels?: Partial<CalendarHeatmapLabels>;\n className?: string;\n}\n\nconst DAY_NAME_FORMAT: Intl.DateTimeFormatOptions = {\n weekday: \"long\",\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n};\n\n/** The empty day: a wash of the text colour, like `--bg-hover`, so it reads as a cell\n * on both themes without claiming any value. */\nconst EMPTY_FILL = \"color-mix(in oklab, var(--text-primary) 8%, var(--bg-surface))\";\n\nconst weekdayIndex = (d: Date, weekStart: WeekDay) => (d.getDay() - weekStart + 7) % 7;\n\n/** The step a value falls on: 0 for nothing, else 1…levels by its share of `max`. */\nexport function heatmapLevel(value: number, max: number, levels: number): number {\n if (!(value > 0) || !(max > 0) || levels < 1) return 0;\n return Math.min(levels, Math.max(1, Math.ceil((value / max) * levels)));\n}\n\n/** How much of `color` a step mixes into the surface: 20% for the first step, 100% for\n * the last — the floor keeps the smallest value visibly apart from an empty day. */\nfunction levelPercent(level: number, levels: number): number {\n if (levels <= 1) return 100;\n return Math.round(20 + (80 * (level - 1)) / (levels - 1));\n}\n\nfunction levelFill(level: number, levels: number, color: string): string {\n if (level === 0) return EMPTY_FILL;\n return `color-mix(in oklab, ${color} ${levelPercent(level, levels)}%, var(--bg-surface))`;\n}\n\n/**\n * Days as a grid of shaded squares — how much happened on each, at a glance\n * (a contribution graph, a spending calendar).\n *\n * **Every day is a cell you can reach.** The grid is a `role=\"grid\"` with ONE tab\n * stop (the roving tabindex, as in `MiniCalendar`); the arrows move by the grid's own\n * geometry — in `\"weeks\"` ↑/↓ are the previous/next day and ←/→ a week, in `\"month\"`\n * the other way round, mirrored in RTL — PageUp/PageDown move a month and Home/End go\n * to the window's first/last day. Each cell is named with its whole date AND its value,\n * because the colour is not something a screen reader can say, and carries\n * `data-day=\"YYYY-MM-DD\"` as its identity for tests and for the host.\n *\n * The tooltip is portalled (a year of squares always sits in a sideways scroller) and\n * `data-private` unless `sensitive={false}`. Cell size in `\"weeks\"` is the CSS variable\n * `--heatmap-cell` (default `0.75rem`): `style={{ \"--heatmap-cell\": \"1rem\" }}`.\n */\nexport function CalendarHeatmap({\n data,\n from,\n to,\n layout = \"weeks\",\n selected,\n onSelect,\n formatValue: formatValueProp,\n tooltip,\n sensitive = true,\n max: maxProp,\n levels = 4,\n color = \"var(--brand)\",\n maxDays,\n legend = true,\n locale: localeProp,\n weekStartsOn,\n labels: labelsProp,\n className,\n \"aria-label\": ariaLabel,\n ...rest\n}: CalendarHeatmapProps) {\n const labels = useKitLabels(\"calendarHeatmap\", DEFAULT_CALENDAR_HEATMAP_LABELS, labelsProp);\n const locale = useKitLocale(localeProp);\n const providerWeekStart = useKitWeekStart();\n const weekStart: WeekDay = weekStartsOn ?? providerWeekStart ?? localeWeekStart(locale);\n const numberFormat = useMemo(() => new Intl.NumberFormat(locale), [locale]);\n const formatValue = formatValueProp ?? ((v: number) => numberFormat.format(v));\n\n const values = useMemo(() => {\n const m = new Map<string, number>();\n for (const p of data) m.set(p.date, (m.get(p.date) ?? 0) + p.value);\n return m;\n }, [data]);\n\n // The window, trimmed from the FRONT: the days a person looks for are the recent\n // ones, and a cap that kept the oldest would end the calendar before today.\n const { days, dropped } = useMemo(() => {\n const start = parseIsoDate(from);\n const end = parseIsoDate(to);\n const list: Date[] = [];\n if (!start || !end || end < start) return { days: list, dropped: 0 };\n const cursor = new Date(end);\n const cap = maxDays && maxDays > 0 ? maxDays : Infinity;\n while (cursor >= start && list.length < cap) {\n list.unshift(new Date(cursor));\n cursor.setDate(cursor.getDate() - 1);\n }\n const first = list[0];\n const trimmed = first ? Math.round((first.getTime() - start.getTime()) / 86_400_000) : 0;\n return { days: list, dropped: Math.max(0, trimmed) };\n }, [from, to, maxDays]);\n\n const firstIso = days.length ? toLocalIso(days[0]) : \"\";\n const lastIso = days.length ? toLocalIso(days[days.length - 1]) : \"\";\n\n const max = useMemo(() => {\n if (maxProp !== undefined) return maxProp;\n let m = 0;\n for (const d of days) m = Math.max(m, values.get(toLocalIso(d)) ?? 0);\n return m;\n }, [maxProp, days, values]);\n\n const clampIso = (iso: string) => (iso < firstIso ? firstIso : iso > lastIso ? lastIso : iso);\n\n // The roving tab stop: the selected day, else the latest one.\n const [activeState, setActiveIso] = useState(() => selected || lastIso);\n const [lastSelected, setLastSelected] = useState(selected);\n if (lastSelected !== selected) {\n setLastSelected(selected);\n if (selected) setActiveIso(selected);\n }\n const activeIso = days.length ? clampIso(activeState || lastIso) : \"\";\n\n const gridRef = useRef<HTMLDivElement>(null);\n const scrollerRef = useRef<HTMLDivElement>(null);\n const pendingFocus = useRef<string | null>(null);\n useEffect(() => {\n const iso = pendingFocus.current;\n if (!iso) return;\n pendingFocus.current = null;\n gridRef.current?.querySelector<HTMLElement>(`[data-day=\"${iso}\"]`)?.focus();\n });\n\n // Open the sideways scroller on the latest weeks, not the oldest. In RTL the end is\n // on the left, where browsers count scrollLeft down from 0.\n //\n // And KEEP it there while the box changes size — a sidebar or a contents rail that\n // appears after mount narrows the scroller, which leaves scrollLeft where it was and\n // so shows older weeks than it opened on. The pin holds only while the view sits at\n // the end: a user who scrolls back through the year unpins it, and a resize then\n // leaves their position alone. (Scrolling back to the end pins it again.)\n useLayoutEffect(() => {\n const el = scrollerRef.current;\n if (!el || layout !== \"weeks\") return;\n const toEnd = () => {\n el.scrollLeft = dirOf(el) === \"rtl\" ? -el.scrollWidth : el.scrollWidth;\n };\n toEnd();\n if (typeof ResizeObserver === \"undefined\") return;\n // |scrollLeft| covers both directions: 0 → max in LTR, 0 → -max in RTL.\n let pinned = true;\n const onScroll = () => {\n pinned = Math.abs(el.scrollLeft) >= el.scrollWidth - el.clientWidth - 1;\n };\n const ro = new ResizeObserver(() => {\n if (pinned) toEnd();\n });\n el.addEventListener(\"scroll\", onScroll, { passive: true });\n ro.observe(el);\n return () => {\n ro.disconnect();\n el.removeEventListener(\"scroll\", onScroll);\n };\n }, [layout, firstIso, lastIso]);\n\n const formatDay = (d: Date) => d.toLocaleDateString(locale, DAY_NAME_FORMAT);\n\n const weekdayLabels = useMemo(() => {\n const ref = new Date(2024, 0, 7 + weekStart); // 7 January 2024 was a Sunday\n return Array.from({ length: 7 }, (_, i) => {\n const d = new Date(ref);\n d.setDate(ref.getDate() + i);\n return {\n short: d.toLocaleDateString(locale, { weekday: \"short\" }),\n long: d.toLocaleDateString(locale, { weekday: \"long\" }),\n };\n });\n }, [locale, weekStart]);\n\n const lead = days.length ? weekdayIndex(days[0], weekStart) : 0;\n const weekCount = Math.ceil((lead + days.length) / 7);\n /** The day at position `i` of the week-aligned sequence (blanks before the first). */\n const dayAt = (i: number): Date | null => (i >= lead && i - lead < days.length ? days[i - lead] : null);\n\n const move = (e: KeyboardEvent<HTMLElement>) => {\n const current = parseIsoDate(activeIso);\n if (!current) return;\n const next = new Date(current);\n const step = horizontalStep(e.key, e.currentTarget);\n // In \"weeks\" a row is a weekday, so sideways is a week and up/down is a day.\n const across = layout === \"weeks\" ? 7 : 1;\n const down = layout === \"weeks\" ? 1 : 7;\n switch (step ? \"horizontal\" : e.key) {\n case \"horizontal\":\n next.setDate(next.getDate() + step * across);\n break;\n case \"ArrowUp\":\n next.setDate(next.getDate() - down);\n break;\n case \"ArrowDown\":\n next.setDate(next.getDate() + down);\n break;\n case \"PageUp\":\n next.setTime(addMonthsClamped(next, -1).getTime());\n break;\n case \"PageDown\":\n next.setTime(addMonthsClamped(next, 1).getTime());\n break;\n case \"Home\":\n next.setTime(days[0].getTime());\n break;\n case \"End\":\n next.setTime(days[days.length - 1].getTime());\n break;\n default:\n return;\n }\n e.preventDefault();\n const iso = clampIso(toLocalIso(next));\n if (iso === activeIso) return;\n pendingFocus.current = iso;\n setActiveIso(iso);\n };\n\n const legendLevels = Array.from({ length: levels + 1 }, (_, l) => l);\n\n const cell = (d: Date, wrapClass: string, cellClass: string, withNumber: boolean) => {\n const iso = toLocalIso(d);\n const raw = values.get(iso);\n const value = raw ?? 0;\n const level = heatmapLevel(value, max, levels);\n const fill = levelFill(level, levels, color);\n const formattedDate = formatDay(d);\n const formattedValue = formatValue(value);\n const name = labels.day(formattedDate, formattedValue);\n const label = tooltip\n ? tooltip({ iso, date: d, value, hasData: raw !== undefined, level, formattedDate, formattedValue })\n : name;\n const isSelected = selected === iso;\n // Light text once the fill is the stronger half of the mix — `--bg-surface` is the\n // colour the scale is mixed INTO, so it is the one that contrasts with its far end\n // on either theme.\n const strong = level > 0 && levelPercent(level, levels) >= 45;\n const shared = {\n role: \"gridcell\",\n \"data-day\": iso,\n \"data-level\": level,\n tabIndex: iso === activeIso ? 0 : -1,\n \"aria-label\": name,\n \"aria-selected\": onSelect ? isSelected : undefined,\n onKeyDown: move,\n onFocus: () => {\n if (iso !== activeIso) setActiveIso(iso);\n },\n style: { background: fill, color: strong ? \"var(--bg-surface)\" : \"var(--text-primary)\" },\n className: cn(\n cellClass,\n isSelected && \"ring-2 ring-[var(--text-primary)]\",\n onSelect && \"cursor-pointer hover:ring-1 hover:ring-[var(--brand)]\",\n ),\n } as const;\n const inner = withNumber ? (\n <span aria-hidden className=\"text-[11px] leading-none tabular-nums\">\n {numberFormat.format(d.getDate())}\n </span>\n ) : null;\n return (\n <Tooltip key={iso} label={label} portal redact={sensitive} role=\"none\" className={wrapClass}>\n {onSelect ? (\n <button type=\"button\" {...shared} onClick={() => onSelect(iso)}>\n {inner}\n </button>\n ) : (\n <div {...shared}>{inner}</div>\n )}\n </Tooltip>\n );\n };\n\n const gridName = ariaLabel ?? labels.grid;\n let body: ReactNode;\n if (layout === \"weeks\") {\n const columns = { gridTemplateColumns: `var(--heatmap-label, 2rem) repeat(${weekCount}, var(--heatmap-cell, 0.75rem))` } as CSSProperties;\n const cellSize = \"size-[var(--heatmap-cell,0.75rem)]\";\n // A month's name over the first column that holds its 1st — or over the first\n // column, when the window opens far enough before the next month for it to fit.\n const monthLabels = Array.from({ length: weekCount }, (_, w) => {\n for (let r = 0; r < 7; r++) {\n const d = dayAt(w * 7 + r);\n if (d && (d.getDate() === 1 || (w === 0 && r === lead && d.getDate() <= 14))) {\n return d.toLocaleDateString(locale, { month: \"short\" });\n }\n }\n return \"\";\n });\n body = (\n <div ref={scrollerRef} className=\"overflow-x-auto pb-1\">\n <div ref={gridRef} role=\"grid\" aria-label={gridName} className=\"inline-grid gap-0.5\">\n {/* Decoration: every cell's name already carries its month. */}\n <div aria-hidden className=\"grid gap-0.5 text-[10px] leading-3 text-[var(--text-muted)]\" style={columns}>\n <span />\n {monthLabels.map((m, w) => (\n <span key={w} className=\"overflow-visible whitespace-nowrap\">\n {m}\n </span>\n ))}\n </div>\n {Array.from({ length: 7 }, (_, r) => (\n <div key={r} role=\"row\" className=\"grid gap-0.5\" style={columns}>\n <div\n role=\"rowheader\"\n aria-label={weekdayLabels[r].long}\n className=\"overflow-hidden pe-1 text-[10px] leading-3 text-[var(--text-muted)]\"\n >\n {/* Every other weekday, as a contribution graph does: seven labels\n at this size are a smear. The name is there for all seven. */}\n {r % 2 === 1 ? weekdayLabels[r].short : \"\"}\n </div>\n {Array.from({ length: weekCount }, (_, w) => {\n const d = dayAt(w * 7 + r);\n return d ? (\n cell(d, cellSize, cn(cellSize, \"block rounded-sm\"), false)\n ) : (\n <div key={`pad-${w}`} role=\"gridcell\" className={cellSize} />\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n } else {\n const rows = Array.from({ length: weekCount }, (_, w) => w);\n body = (\n <div ref={gridRef} role=\"grid\" aria-label={gridName} className=\"grid gap-1\">\n <div role=\"row\" className=\"grid grid-cols-7 gap-1\">\n {weekdayLabels.map((w, i) => (\n <div\n key={i}\n role=\"columnheader\"\n aria-label={w.long}\n className=\"pb-0.5 text-center text-[10px] uppercase tracking-wide text-[var(--text-muted)]\"\n >\n {w.short}\n </div>\n ))}\n </div>\n {rows.map((w) => (\n <div key={w} role=\"row\" className=\"grid grid-cols-7 gap-1\">\n {Array.from({ length: 7 }, (_, c) => {\n const d = dayAt(w * 7 + c);\n return d ? (\n cell(d, \"aspect-square w-full\", \"flex h-full w-full items-center justify-center rounded\", true)\n ) : (\n <div key={`pad-${c}`} role=\"gridcell\" className=\"aspect-square\" />\n );\n })}\n </div>\n ))}\n </div>\n );\n }\n\n return (\n <div {...rest} className={cn(\"min-w-0\", className)}>\n {dropped > 0 && (\n <div className=\"mb-2 text-xs text-[var(--text-muted)]\">{labels.truncated(dropped)}</div>\n )}\n {body}\n {legend && (\n <div aria-hidden className=\"mt-2 flex items-center justify-end gap-1 text-[10px] text-[var(--text-muted)]\">\n <span className=\"me-0.5\">{labels.less}</span>\n {legendLevels.map((l) => (\n <span\n key={l}\n data-legend-level={l}\n className=\"size-2.5 rounded-sm\"\n style={{ background: levelFill(l, levels, color) }}\n />\n ))}\n <span className=\"ms-0.5\">{labels.more}</span>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";AA4XM,cAqCI,YArCJ;AA5XN,SAAS,WAAW,iBAAiB,SAAS,QAAQ,gBAAgB;AAEtE,SAAS,UAAU;AACnB,SAAS,OAAO,sBAAsB;AACtC,SAAS,kBAAkB,iBAAiB,cAAc,kBAAkB;AAC5E,SAAS,cAAc,cAAc,uBAAuB;AAC5D,SAAS,eAAe;AA0BjB,MAAM,kCAAyD;AAAA,EACpE,MAAM;AAAA,EACN,KAAK,CAAC,MAAM,UAAU,GAAG,IAAI,KAAK,KAAK;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW,CAAC,UACV,iCAAiC,KAAK,YAAY,UAAU,IAAI,WAAW,UAAU;AACzF;AAiFA,MAAM,kBAA8C;AAAA,EAClD,SAAS;AAAA,EACT,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM;AACR;AAIA,MAAM,aAAa;AAEnB,MAAM,eAAe,CAAC,GAAS,eAAwB,EAAE,OAAO,IAAI,YAAY,KAAK;AAG9E,SAAS,aAAa,OAAe,KAAa,QAAwB;AAC/E,MAAI,EAAE,QAAQ,MAAM,EAAE,MAAM,MAAM,SAAS,EAAG,QAAO;AACrD,SAAO,KAAK,IAAI,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAM,QAAQ,MAAO,MAAM,CAAC,CAAC;AACxE;AAIA,SAAS,aAAa,OAAe,QAAwB;AAC3D,MAAI,UAAU,EAAG,QAAO;AACxB,SAAO,KAAK,MAAM,KAAM,MAAM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,UAAK,WAAU,UAAU,iBAAO,MAAK;AAAA,MACrC,aAAa,IAAI,CAAC,MACjB;AAAA,QAAC;AAAA;AAAA,UAEC,qBAAmB;AAAA,UACnB,WAAU;AAAA,UACV,OAAO,EAAE,YAAY,UAAU,GAAG,QAAQ,KAAK,EAAE;AAAA;AAAA,QAH5C;AAAA,MAIP,CACD;AAAA,MACD,oBAAC,UAAK,WAAU,UAAU,iBAAO,MAAK;AAAA,OACxC;AAAA,KAEJ;AAEJ;","names":["_"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ButtonHTMLAttributes, ReactNode, InputHTMLAttributes, ComponentType } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A checkbox or a radio, presented as a bordered card: a title, a line of description,
|
|
@@ -56,6 +56,38 @@ interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "t
|
|
|
56
56
|
required?: boolean;
|
|
57
57
|
}
|
|
58
58
|
declare const ChoiceCard: react.ForwardRefExoticComponent<ChoiceCardProps & react.RefAttributes<HTMLInputElement>>;
|
|
59
|
+
/** The colour of {@link ActionCardProps.meta}. */
|
|
60
|
+
type ActionCardMetaTone = "muted" | "warning" | "danger" | "info" | "success";
|
|
61
|
+
interface ActionCardProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "title"> {
|
|
62
|
+
/** What the card does — the button's accessible name. */
|
|
63
|
+
title: ReactNode;
|
|
64
|
+
/** A line or two on what it means. Attached with `aria-describedby`. */
|
|
65
|
+
description?: ReactNode;
|
|
66
|
+
/**
|
|
67
|
+
* What it costs, or what else to know — a third line, said as prose and not as fine
|
|
68
|
+
* print (keksdose's custody choice: both options are legitimate and neither is free,
|
|
69
|
+
* so a card listing only benefits would be selling rather than explaining). Attached
|
|
70
|
+
* with `aria-describedby` after the description.
|
|
71
|
+
*/
|
|
72
|
+
meta?: ReactNode;
|
|
73
|
+
/** The meta line's colour. Default `muted`; keksdose's cost line is `warning`. */
|
|
74
|
+
metaTone?: ActionCardMetaTone;
|
|
75
|
+
/** A Lucide icon (or any component taking a `className`), shown at the card's start. */
|
|
76
|
+
icon?: ChoiceCardProps["icon"];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A {@link ChoiceCard} that ACTS rather than holds a state: a `<button>` with the
|
|
80
|
+
* card's icon, title and description, plus a `meta` line, that runs `onClick` the
|
|
81
|
+
* moment it is pressed. keksdose's privacy enrolment (privacy-enroll-dialog:345,
|
|
82
|
+
* `CustodyOption`) offers two custody modes this way — picking one IS the next step,
|
|
83
|
+
* so there is no checked state to show and no "Continue" to press after it.
|
|
84
|
+
*
|
|
85
|
+
* A separate component rather than `ChoiceCard as="button"`: a ChoiceCard is an
|
|
86
|
+
* `<input>` (its ref, its `checked`, its form value), and a button shares none of it.
|
|
87
|
+
* Named by the title alone and described by the rest, so a screen reader hears
|
|
88
|
+
* "Keep the key yourself, button" and then the explanation, not one long name.
|
|
89
|
+
*/
|
|
90
|
+
declare const ActionCard: react.ForwardRefExoticComponent<ActionCardProps & react.RefAttributes<HTMLButtonElement>>;
|
|
59
91
|
interface ChoiceCardOption<T extends string> {
|
|
60
92
|
value: T;
|
|
61
93
|
title: ReactNode;
|
|
@@ -114,4 +146,4 @@ type ChoiceCardGroupProps<T extends string> = ChoiceCardSingleProps<T> | ChoiceC
|
|
|
114
146
|
*/
|
|
115
147
|
declare function ChoiceCardGroup<T extends string>(props: ChoiceCardGroupProps<T>): react.JSX.Element;
|
|
116
148
|
|
|
117
|
-
export { ChoiceCard, ChoiceCardGroup, type ChoiceCardGroupProps, type ChoiceCardMultipleProps, type ChoiceCardOption, type ChoiceCardProps, type ChoiceCardSingleProps, type ChoiceCardType };
|
|
149
|
+
export { ActionCard, type ActionCardMetaTone, type ActionCardProps, ChoiceCard, ChoiceCardGroup, type ChoiceCardGroupProps, type ChoiceCardMultipleProps, type ChoiceCardOption, type ChoiceCardProps, type ChoiceCardSingleProps, type ChoiceCardType };
|
|
@@ -124,6 +124,54 @@ const ChoiceCard = forwardRef(function ChoiceCard2({
|
|
|
124
124
|
);
|
|
125
125
|
});
|
|
126
126
|
ChoiceCard.displayName = "ChoiceCard";
|
|
127
|
+
const META_TONE = {
|
|
128
|
+
muted: "text-[var(--text-muted)]",
|
|
129
|
+
warning: "text-[var(--warning)]",
|
|
130
|
+
danger: "text-[var(--danger)]",
|
|
131
|
+
info: "text-[var(--info)]",
|
|
132
|
+
success: "text-[var(--success)]"
|
|
133
|
+
};
|
|
134
|
+
const ActionCard = forwardRef(function ActionCard2({ title, description, meta, metaTone = "muted", icon: Icon, className, id, type = "button", ...rest }, ref) {
|
|
135
|
+
const generated = useId();
|
|
136
|
+
const baseId = id ?? generated;
|
|
137
|
+
const titleId = `${baseId}-title`;
|
|
138
|
+
const descriptionId = `${baseId}-description`;
|
|
139
|
+
const metaId = `${baseId}-meta`;
|
|
140
|
+
const showDescription = hasMessage(description);
|
|
141
|
+
const showMeta = hasMessage(meta);
|
|
142
|
+
return /* @__PURE__ */ jsxs(
|
|
143
|
+
"button",
|
|
144
|
+
{
|
|
145
|
+
ref,
|
|
146
|
+
id,
|
|
147
|
+
type,
|
|
148
|
+
...rest,
|
|
149
|
+
"aria-labelledby": rest["aria-labelledby"] ?? titleId,
|
|
150
|
+
"aria-describedby": mergeDescribedBy(
|
|
151
|
+
rest["aria-describedby"],
|
|
152
|
+
showDescription && descriptionId,
|
|
153
|
+
showMeta && metaId
|
|
154
|
+
),
|
|
155
|
+
className: cn(
|
|
156
|
+
"flex w-full items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 text-start shadow-sm transition-colors",
|
|
157
|
+
"hover:border-[var(--brand)] hover:bg-[var(--bg-hover)]",
|
|
158
|
+
// The outline, as on ChoiceCard: the card is what the eye is on.
|
|
159
|
+
"focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--brand)]",
|
|
160
|
+
"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-[var(--border)] disabled:hover:bg-[var(--bg-surface)]",
|
|
161
|
+
className
|
|
162
|
+
),
|
|
163
|
+
children: [
|
|
164
|
+
Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, className: "mt-0.5 size-5 shrink-0 text-[var(--text-secondary)]" }),
|
|
165
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 space-y-1", children: [
|
|
166
|
+
/* @__PURE__ */ jsx("span", { id: titleId, className: "block text-sm font-medium leading-5 text-[var(--text-primary)]", children: title }),
|
|
167
|
+
showDescription && /* @__PURE__ */ jsx("span", { id: descriptionId, className: "block text-sm text-[var(--text-secondary)]", children: description }),
|
|
168
|
+
showMeta && /* @__PURE__ */ jsx("span", { id: metaId, className: cn("block text-sm", META_TONE[metaTone]), children: meta })
|
|
169
|
+
] })
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
ActionCard.displayName = "ActionCard";
|
|
127
175
|
function ChoiceCardGroup(props) {
|
|
128
176
|
const { options, legend, name, className, cardClassName, disabled, error, required } = props;
|
|
129
177
|
const generated = useId();
|
|
@@ -177,6 +225,7 @@ function ChoiceCardGroup(props) {
|
|
|
177
225
|
) });
|
|
178
226
|
}
|
|
179
227
|
export {
|
|
228
|
+
ActionCard,
|
|
180
229
|
ChoiceCard,
|
|
181
230
|
ChoiceCardGroup
|
|
182
231
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/choice-card.tsx"],"sourcesContent":["import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef } from \"react\";\nimport type { ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode } from \"react\";\nimport { Check, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { assignRef, hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * A checkbox or a radio, presented as a bordered card: a title, a line of description,\n * an optional icon — and the whole card is the hit area.\n *\n * Kastlan built this twice by hand: the \"manage roles\" dialog wraps a `Checkbox` in a\n * bordered `<label>` per role, and the lease wizard's \"set up recurring rent\" option is\n * a `Checkbox` with `className=\"rounded-md border p-3\"`. Neither had a focus ring on\n * the card or a checked look beyond the 16px box, and the role picker's border stayed\n * grey whether the role was on or off.\n *\n * Still a native `<input>` underneath, for the reasons {@link Checkbox} gives: it\n * submits with its form, answers to `required`, and a radio set sharing a `name` gets\n * the browser's own arrow-key behaviour — which already flips in a right-to-left page.\n * The card is a `<label>` wrapped round it, so a click anywhere on the card lands on\n * the input; the input is NAMED by the title alone and DESCRIBED by the description,\n * so a screen reader does not read the whole card as its name.\n *\n * Checked is said three ways, none of them colour alone: the box's tick (or the\n * radio's dot), a heavier border, and the brand-tinted surface.\n */\n\nexport type ChoiceCardType = \"checkbox\" | \"radio\";\n\nexport interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"title\"> {\n /** \"checkbox\" (default) for an on/off option or one of several; \"radio\" for one of\n * a set — give every card of the set the same `name`, or use {@link ChoiceCardGroup}. */\n type?: ChoiceCardType;\n /** The option's name — the input's accessible name. */\n title: ReactNode;\n /** A line or two under the title. Attached with `aria-describedby`. */\n description?: ReactNode;\n /** A Lucide icon (or any component taking a `className`), shown at the card's start. */\n icon?: ComponentType<{ className?: string; \"aria-hidden\"?: boolean }>;\n /** Checkbox only: \"some but not all\". See {@link CheckboxProps.indeterminate}. */\n indeterminate?: boolean;\n /** Paints the card and sets `aria-invalid` together. */\n invalid?: boolean;\n /** What is wrong, in the caller's words. Rendered in the card and attached with\n * `aria-describedby`; implies `invalid`. */\n error?: ReactNode;\n /** The checked state as a boolean. Fires alongside `onChange`, never instead of it. */\n onCheckedChange?: (checked: boolean) => void;\n /** Classes for the `<input>`. `className` styles the card. */\n inputClassName?: string;\n /**\n * Must be ticked to submit. Reaches the `<input>` as the native `required` (a\n * `<form>` refuses to submit without it, a screen reader announces \"required\"),\n * and draws the kit's `aria-hidden` star after the title — {@link Checkbox}'s\n * contract, down to writing the title WITHOUT a literal \"*\". Inside a\n * {@link ChoiceCardGroup} the star goes on the legend instead, once.\n */\n required?: boolean;\n}\n\n/** Set by {@link ChoiceCardGroup}: its legend carries the one required mark, so the\n * cards inside it draw none of their own. Private — not a prop a caller could set\n * by accident on a lone card. */\nconst InGroupContext = createContext(false);\n\n/** The kit's required mark — {@link Label}'s: `aria-hidden`, because the word is\n * announced from the control and a star read out in the name is only noise. */\nfunction RequiredMark() {\n return (\n <span aria-hidden className=\"ms-0.5 text-[var(--danger)]\">\n *\n </span>\n );\n}\n\n// The card. `has-[:checked]` and `has-[:focus-visible]` read the INPUT's state, so an\n// uncontrolled card (`defaultChecked`, a plain form) looks right with no React state.\nconst CARD =\n \"flex cursor-pointer items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 shadow-sm transition-colors \" +\n \"hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)] \" +\n \"has-[:checked]:border-[var(--brand)] has-[:checked]:bg-[var(--brand-bg)] has-[:checked]:ring-1 has-[:checked]:ring-[var(--brand)] \" +\n // The focus mark is the CARD's, not the 16px box's: the card is what was clicked and\n // what the eye is on. An OUTLINE rather than a ring, because the checked state already\n // spends the ring — two `ring-*` widths on one element are decided by stylesheet\n // order, and the loser would be the focus mark. Offset, so the two never merge.\n \"has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--brand)] \" +\n // Read from the input too, so a card disabled by its `<fieldset>` fades as well.\n \"has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-60\";\n\n// No hover offer on a card that cannot be changed.\nconst CARD_DISABLED = \"hover:border-[var(--border)] hover:bg-[var(--bg-surface)]\";\n\nconst CARD_INVALID =\n \"border-[var(--danger-border)] ring-1 ring-[var(--danger-border)] has-[:checked]:border-[var(--danger-border)] has-[:checked]:ring-[var(--danger-border)]\";\n\nconst BOX =\n \"peer size-4 shrink-0 appearance-none border border-[var(--border-strong)] bg-[var(--bg-surface)] transition-colors \" +\n \"checked:border-[var(--brand)] focus:outline-none disabled:cursor-not-allowed\";\nconst CHECKBOX = \"rounded-[4px] checked:bg-[var(--brand)]\";\n// A radio's dot is its BORDER: a 5px brand border round a surface-coloured 4px\n// centre. No glyph to lay over it, and it scales with the box.\nconst RADIO = \"rounded-full checked:border-[5px]\";\n\nexport const ChoiceCard = forwardRef<HTMLInputElement, ChoiceCardProps>(function ChoiceCard(\n {\n type = \"checkbox\",\n title,\n description,\n icon: Icon,\n indeterminate = false,\n invalid,\n error,\n onCheckedChange,\n onChange,\n className,\n inputClassName,\n id,\n disabled,\n required,\n ...rest\n },\n ref,\n) {\n const inGroup = useContext(InGroupContext);\n const generated = useId();\n const inputId = id ?? generated;\n const titleId = `${inputId}-title`;\n const descriptionId = `${inputId}-description`;\n const errorId = `${inputId}-error`;\n const showDescription = hasMessage(description);\n const showError = hasMessage(error);\n const isInvalid = Boolean(invalid) || showError;\n const mixed = type === \"checkbox\" && indeterminate;\n\n const local = useRef<HTMLInputElement | null>(null);\n const setRef = useCallback(\n (node: HTMLInputElement | null) => {\n local.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n // After every render, as Checkbox does: a click clears the DOM property.\n useEffect(() => {\n if (local.current) local.current.indeterminate = mixed;\n });\n\n return (\n <label\n htmlFor={inputId}\n className={cn(CARD, disabled && CARD_DISABLED, isInvalid && CARD_INVALID, className)}\n >\n {/* A 20px cell, so the box centres on the title's first line (text-sm). */}\n <span className=\"relative flex h-5 shrink-0 items-center\">\n <input\n ref={setRef}\n id={inputId}\n disabled={disabled}\n required={required}\n {...rest}\n type={type}\n aria-labelledby={rest[\"aria-labelledby\"] ?? titleId}\n aria-invalid={isInvalid || rest[\"aria-invalid\"] || undefined}\n aria-describedby={mergeDescribedBy(\n rest[\"aria-describedby\"],\n showDescription && descriptionId,\n showError && errorId,\n )}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n onCheckedChange?.(e.target.checked);\n }}\n className={cn(\n BOX,\n type === \"radio\" ? RADIO : CHECKBOX,\n mixed && \"border-[var(--brand)] bg-[var(--brand)]\",\n inputClassName,\n )}\n />\n {type === \"checkbox\" &&\n (mixed ? (\n <Minus\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none absolute inset-0 m-auto size-3 text-[var(--brand-contrast)]\"\n />\n ) : (\n <Check\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none invisible absolute inset-0 m-auto size-3 text-[var(--brand-contrast)] peer-checked:visible\"\n />\n ))}\n </span>\n {Icon && <Icon aria-hidden className=\"mt-0.5 size-4 shrink-0 text-[var(--text-secondary)]\" />}\n <span className=\"min-w-0 flex-1\">\n <span\n id={titleId}\n // `select-none`: a double-click to toggle twice would otherwise select the words.\n className=\"block select-none text-sm font-medium leading-5 text-[var(--text-primary)]\"\n >\n {title}\n {required && !inGroup && <RequiredMark />}\n </span>\n {showDescription && (\n <span id={descriptionId} className=\"mt-0.5 block text-xs text-[var(--text-muted)]\">\n {description}\n </span>\n )}\n {showError && (\n <span id={errorId} className=\"mt-1 block text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </span>\n )}\n </span>\n </label>\n );\n});\nChoiceCard.displayName = \"ChoiceCard\";\n\n/* ── ChoiceCardGroup ─────────────────────────────────────────────────────── */\n\nexport interface ChoiceCardOption<T extends string> {\n value: T;\n title: ReactNode;\n description?: ReactNode;\n icon?: ChoiceCardProps[\"icon\"];\n disabled?: boolean;\n}\n\ninterface ChoiceCardGroupBaseProps<T extends string> {\n options: ChoiceCardOption<T>[];\n /** The question the cards answer. Rendered as the fieldset's `<legend>`, which is\n * what names the group. Without one, pass `aria-label`. */\n legend?: ReactNode;\n \"aria-label\"?: string;\n /** Shared by every input — what a plain form submits under. Generated if omitted. */\n name?: string;\n /** Classes for the card grid. Default: one column, two from `sm` up. */\n className?: string;\n /** Classes for every card. */\n cardClassName?: string;\n disabled?: boolean;\n /** What is wrong with the answer as a whole. Rendered under the cards and attached\n * to the fieldset. */\n error?: ReactNode;\n /**\n * An answer is needed. Draws the required star after the `legend` (none without\n * one — the name then comes from `aria-label`, which has nowhere to draw it), and\n * reaches the inputs as the native `required`:\n * - radios: every radio of the set, which is how HTML marks a radio group — the\n * group is satisfied by any one of them, and each announces \"required\";\n * - checkboxes: every box while NONE is ticked, dropped from all of them once one\n * is — \"at least one\", which checkboxes cannot say natively. A form then refuses\n * to submit an empty set, and nothing is left demanding a second box.\n */\n required?: boolean;\n}\n\n/** One of the set: radios. `value` is `null` while nothing is chosen. */\nexport interface ChoiceCardSingleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple?: false;\n value: T | null;\n onChange: (value: T) => void;\n}\n\n/** Any of the set: checkboxes. */\nexport interface ChoiceCardMultipleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple: true;\n value: T[];\n onChange: (value: T[]) => void;\n}\n\nexport type ChoiceCardGroupProps<T extends string> =\n | ChoiceCardSingleProps<T>\n | ChoiceCardMultipleProps<T>;\n\n/**\n * A set of {@link ChoiceCard}s answering one question, in a `<fieldset>`.\n *\n * `multiple` picks the input: radios (one of the set, the browser's arrow keys\n * between them) or checkboxes (any of the set, Tab between them). The value is kept\n * in the order of `options`, not the order the boxes were ticked, so a list saved\n * from it does not depend on the order someone clicked in.\n */\nexport function ChoiceCardGroup<T extends string>(props: ChoiceCardGroupProps<T>) {\n const { options, legend, name, className, cardClassName, disabled, error, required } = props;\n const generated = useId();\n const groupName = name ?? generated;\n const errorId = `${generated}-error`;\n const showError = hasMessage(error);\n\n const isChecked = (v: T) => (props.multiple ? props.value.includes(v) : props.value === v);\n const toggle = (v: T, on: boolean) => {\n if (props.multiple) {\n const next = new Set(props.value);\n if (on) next.add(v);\n else next.delete(v);\n props.onChange(options.map((o) => o.value).filter((x) => next.has(x)));\n } else if (on) {\n props.onChange(v);\n }\n };\n\n return (\n <InGroupContext.Provider value={true}>\n <fieldset\n aria-label={props[\"aria-label\"]}\n aria-describedby={showError ? errorId : undefined}\n disabled={disabled}\n className=\"min-w-0\"\n >\n {legend !== undefined && (\n <legend className=\"mb-2 text-sm font-medium text-[var(--text-primary)]\">\n {legend}\n {required && <RequiredMark />}\n </legend>\n )}\n <div className={cn(\"grid gap-2 sm:grid-cols-2\", className)}>\n {options.map((o) => (\n <ChoiceCard\n key={o.value}\n type={props.multiple ? \"checkbox\" : \"radio\"}\n name={groupName}\n value={o.value}\n title={o.title}\n description={o.description}\n icon={o.icon}\n disabled={o.disabled}\n invalid={showError}\n required={required && (!props.multiple || props.value.length === 0) ? true : undefined}\n checked={isChecked(o.value)}\n onCheckedChange={(on) => toggle(o.value, on)}\n className={cardClassName}\n />\n ))}\n </div>\n {showError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </fieldset>\n </InGroupContext.Provider>\n );\n}\n"],"mappings":";AAqEI,cAoFE,YApFF;AArEJ,SAAS,eAAe,YAAY,aAAa,YAAY,WAAW,OAAO,cAAc;AAE7F,SAAS,OAAO,aAAa;AAC7B,SAAS,UAAU;AACnB,SAAS,WAAW,YAAY,wBAAwB;AA2DxD,MAAM,iBAAiB,cAAc,KAAK;AAI1C,SAAS,eAAe;AACtB,SACE,oBAAC,UAAK,eAAW,MAAC,WAAU,+BAA8B,eAE1D;AAEJ;AAIA,MAAM,OACJ;AAYF,MAAM,gBAAgB;AAEtB,MAAM,eACJ;AAEF,MAAM,MACJ;AAEF,MAAM,WAAW;AAGjB,MAAM,QAAQ;AAEP,MAAM,aAAa,WAA8C,SAASA,YAC/E;AAAA,EACE,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,UAAU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AA,IAClB;AAAA,EACF;AAEA,SACE,oBAAC,eAAe,UAAf,EAAwB,OAAO,MAC9B;AAAA,IAAC;AAAA;AAAA,MACC,cAAY,MAAM,YAAY;AAAA,MAC9B,oBAAkB,YAAY,UAAU;AAAA,MACxC;AAAA,MACA,WAAU;AAAA,MAET;AAAA,mBAAW,UACV,qBAAC,YAAO,WAAU,uDACf;AAAA;AAAA,UACA,YAAY,oBAAC,gBAAa;AAAA,WAC7B;AAAA,QAEF,oBAAC,SAAI,WAAW,GAAG,6BAA6B,SAAS,GACtD,kBAAQ,IAAI,CAAC,MACZ;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM,MAAM,WAAW,aAAa;AAAA,YACpC,MAAM;AAAA,YACN,OAAO,EAAE;AAAA,YACT,OAAO,EAAE;AAAA,YACT,aAAa,EAAE;AAAA,YACf,MAAM,EAAE;AAAA,YACR,UAAU,EAAE;AAAA,YACZ,SAAS;AAAA,YACT,UAAU,aAAa,CAAC,MAAM,YAAY,MAAM,MAAM,WAAW,KAAK,OAAO;AAAA,YAC7E,SAAS,UAAU,EAAE,KAAK;AAAA,YAC1B,iBAAiB,CAAC,OAAO,OAAO,EAAE,OAAO,EAAE;AAAA,YAC3C,WAAW;AAAA;AAAA,UAZN,EAAE;AAAA,QAaT,CACD,GACH;AAAA,QACC,aACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":["ChoiceCard"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/choice-card.tsx"],"sourcesContent":["import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef } from \"react\";\nimport type { ButtonHTMLAttributes, ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode } from \"react\";\nimport { Check, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { assignRef, hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * A checkbox or a radio, presented as a bordered card: a title, a line of description,\n * an optional icon — and the whole card is the hit area.\n *\n * Kastlan built this twice by hand: the \"manage roles\" dialog wraps a `Checkbox` in a\n * bordered `<label>` per role, and the lease wizard's \"set up recurring rent\" option is\n * a `Checkbox` with `className=\"rounded-md border p-3\"`. Neither had a focus ring on\n * the card or a checked look beyond the 16px box, and the role picker's border stayed\n * grey whether the role was on or off.\n *\n * Still a native `<input>` underneath, for the reasons {@link Checkbox} gives: it\n * submits with its form, answers to `required`, and a radio set sharing a `name` gets\n * the browser's own arrow-key behaviour — which already flips in a right-to-left page.\n * The card is a `<label>` wrapped round it, so a click anywhere on the card lands on\n * the input; the input is NAMED by the title alone and DESCRIBED by the description,\n * so a screen reader does not read the whole card as its name.\n *\n * Checked is said three ways, none of them colour alone: the box's tick (or the\n * radio's dot), a heavier border, and the brand-tinted surface.\n */\n\nexport type ChoiceCardType = \"checkbox\" | \"radio\";\n\nexport interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"title\"> {\n /** \"checkbox\" (default) for an on/off option or one of several; \"radio\" for one of\n * a set — give every card of the set the same `name`, or use {@link ChoiceCardGroup}. */\n type?: ChoiceCardType;\n /** The option's name — the input's accessible name. */\n title: ReactNode;\n /** A line or two under the title. Attached with `aria-describedby`. */\n description?: ReactNode;\n /** A Lucide icon (or any component taking a `className`), shown at the card's start. */\n icon?: ComponentType<{ className?: string; \"aria-hidden\"?: boolean }>;\n /** Checkbox only: \"some but not all\". See {@link CheckboxProps.indeterminate}. */\n indeterminate?: boolean;\n /** Paints the card and sets `aria-invalid` together. */\n invalid?: boolean;\n /** What is wrong, in the caller's words. Rendered in the card and attached with\n * `aria-describedby`; implies `invalid`. */\n error?: ReactNode;\n /** The checked state as a boolean. Fires alongside `onChange`, never instead of it. */\n onCheckedChange?: (checked: boolean) => void;\n /** Classes for the `<input>`. `className` styles the card. */\n inputClassName?: string;\n /**\n * Must be ticked to submit. Reaches the `<input>` as the native `required` (a\n * `<form>` refuses to submit without it, a screen reader announces \"required\"),\n * and draws the kit's `aria-hidden` star after the title — {@link Checkbox}'s\n * contract, down to writing the title WITHOUT a literal \"*\". Inside a\n * {@link ChoiceCardGroup} the star goes on the legend instead, once.\n */\n required?: boolean;\n}\n\n/** Set by {@link ChoiceCardGroup}: its legend carries the one required mark, so the\n * cards inside it draw none of their own. Private — not a prop a caller could set\n * by accident on a lone card. */\nconst InGroupContext = createContext(false);\n\n/** The kit's required mark — {@link Label}'s: `aria-hidden`, because the word is\n * announced from the control and a star read out in the name is only noise. */\nfunction RequiredMark() {\n return (\n <span aria-hidden className=\"ms-0.5 text-[var(--danger)]\">\n *\n </span>\n );\n}\n\n// The card. `has-[:checked]` and `has-[:focus-visible]` read the INPUT's state, so an\n// uncontrolled card (`defaultChecked`, a plain form) looks right with no React state.\nconst CARD =\n \"flex cursor-pointer items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 shadow-sm transition-colors \" +\n \"hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)] \" +\n \"has-[:checked]:border-[var(--brand)] has-[:checked]:bg-[var(--brand-bg)] has-[:checked]:ring-1 has-[:checked]:ring-[var(--brand)] \" +\n // The focus mark is the CARD's, not the 16px box's: the card is what was clicked and\n // what the eye is on. An OUTLINE rather than a ring, because the checked state already\n // spends the ring — two `ring-*` widths on one element are decided by stylesheet\n // order, and the loser would be the focus mark. Offset, so the two never merge.\n \"has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--brand)] \" +\n // Read from the input too, so a card disabled by its `<fieldset>` fades as well.\n \"has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-60\";\n\n// No hover offer on a card that cannot be changed.\nconst CARD_DISABLED = \"hover:border-[var(--border)] hover:bg-[var(--bg-surface)]\";\n\nconst CARD_INVALID =\n \"border-[var(--danger-border)] ring-1 ring-[var(--danger-border)] has-[:checked]:border-[var(--danger-border)] has-[:checked]:ring-[var(--danger-border)]\";\n\nconst BOX =\n \"peer size-4 shrink-0 appearance-none border border-[var(--border-strong)] bg-[var(--bg-surface)] transition-colors \" +\n \"checked:border-[var(--brand)] focus:outline-none disabled:cursor-not-allowed\";\nconst CHECKBOX = \"rounded-[4px] checked:bg-[var(--brand)]\";\n// A radio's dot is its BORDER: a 5px brand border round a surface-coloured 4px\n// centre. No glyph to lay over it, and it scales with the box.\nconst RADIO = \"rounded-full checked:border-[5px]\";\n\nexport const ChoiceCard = forwardRef<HTMLInputElement, ChoiceCardProps>(function ChoiceCard(\n {\n type = \"checkbox\",\n title,\n description,\n icon: Icon,\n indeterminate = false,\n invalid,\n error,\n onCheckedChange,\n onChange,\n className,\n inputClassName,\n id,\n disabled,\n required,\n ...rest\n },\n ref,\n) {\n const inGroup = useContext(InGroupContext);\n const generated = useId();\n const inputId = id ?? generated;\n const titleId = `${inputId}-title`;\n const descriptionId = `${inputId}-description`;\n const errorId = `${inputId}-error`;\n const showDescription = hasMessage(description);\n const showError = hasMessage(error);\n const isInvalid = Boolean(invalid) || showError;\n const mixed = type === \"checkbox\" && indeterminate;\n\n const local = useRef<HTMLInputElement | null>(null);\n const setRef = useCallback(\n (node: HTMLInputElement | null) => {\n local.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n // After every render, as Checkbox does: a click clears the DOM property.\n useEffect(() => {\n if (local.current) local.current.indeterminate = mixed;\n });\n\n return (\n <label\n htmlFor={inputId}\n className={cn(CARD, disabled && CARD_DISABLED, isInvalid && CARD_INVALID, className)}\n >\n {/* A 20px cell, so the box centres on the title's first line (text-sm). */}\n <span className=\"relative flex h-5 shrink-0 items-center\">\n <input\n ref={setRef}\n id={inputId}\n disabled={disabled}\n required={required}\n {...rest}\n type={type}\n aria-labelledby={rest[\"aria-labelledby\"] ?? titleId}\n aria-invalid={isInvalid || rest[\"aria-invalid\"] || undefined}\n aria-describedby={mergeDescribedBy(\n rest[\"aria-describedby\"],\n showDescription && descriptionId,\n showError && errorId,\n )}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n onCheckedChange?.(e.target.checked);\n }}\n className={cn(\n BOX,\n type === \"radio\" ? RADIO : CHECKBOX,\n mixed && \"border-[var(--brand)] bg-[var(--brand)]\",\n inputClassName,\n )}\n />\n {type === \"checkbox\" &&\n (mixed ? (\n <Minus\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none absolute inset-0 m-auto size-3 text-[var(--brand-contrast)]\"\n />\n ) : (\n <Check\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none invisible absolute inset-0 m-auto size-3 text-[var(--brand-contrast)] peer-checked:visible\"\n />\n ))}\n </span>\n {Icon && <Icon aria-hidden className=\"mt-0.5 size-4 shrink-0 text-[var(--text-secondary)]\" />}\n <span className=\"min-w-0 flex-1\">\n <span\n id={titleId}\n // `select-none`: a double-click to toggle twice would otherwise select the words.\n className=\"block select-none text-sm font-medium leading-5 text-[var(--text-primary)]\"\n >\n {title}\n {required && !inGroup && <RequiredMark />}\n </span>\n {showDescription && (\n <span id={descriptionId} className=\"mt-0.5 block text-xs text-[var(--text-muted)]\">\n {description}\n </span>\n )}\n {showError && (\n <span id={errorId} className=\"mt-1 block text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </span>\n )}\n </span>\n </label>\n );\n});\nChoiceCard.displayName = \"ChoiceCard\";\n\n/* ── ActionCard ──────────────────────────────────────────────────────────── */\n\n/** The colour of {@link ActionCardProps.meta}. */\nexport type ActionCardMetaTone = \"muted\" | \"warning\" | \"danger\" | \"info\" | \"success\";\n\nconst META_TONE: Record<ActionCardMetaTone, string> = {\n muted: \"text-[var(--text-muted)]\",\n warning: \"text-[var(--warning)]\",\n danger: \"text-[var(--danger)]\",\n info: \"text-[var(--info)]\",\n success: \"text-[var(--success)]\",\n};\n\nexport interface ActionCardProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"title\"> {\n /** What the card does — the button's accessible name. */\n title: ReactNode;\n /** A line or two on what it means. Attached with `aria-describedby`. */\n description?: ReactNode;\n /**\n * What it costs, or what else to know — a third line, said as prose and not as fine\n * print (keksdose's custody choice: both options are legitimate and neither is free,\n * so a card listing only benefits would be selling rather than explaining). Attached\n * with `aria-describedby` after the description.\n */\n meta?: ReactNode;\n /** The meta line's colour. Default `muted`; keksdose's cost line is `warning`. */\n metaTone?: ActionCardMetaTone;\n /** A Lucide icon (or any component taking a `className`), shown at the card's start. */\n icon?: ChoiceCardProps[\"icon\"];\n}\n\n/**\n * A {@link ChoiceCard} that ACTS rather than holds a state: a `<button>` with the\n * card's icon, title and description, plus a `meta` line, that runs `onClick` the\n * moment it is pressed. keksdose's privacy enrolment (privacy-enroll-dialog:345,\n * `CustodyOption`) offers two custody modes this way — picking one IS the next step,\n * so there is no checked state to show and no \"Continue\" to press after it.\n *\n * A separate component rather than `ChoiceCard as=\"button\"`: a ChoiceCard is an\n * `<input>` (its ref, its `checked`, its form value), and a button shares none of it.\n * Named by the title alone and described by the rest, so a screen reader hears\n * \"Keep the key yourself, button\" and then the explanation, not one long name.\n */\nexport const ActionCard = forwardRef<HTMLButtonElement, ActionCardProps>(function ActionCard(\n { title, description, meta, metaTone = \"muted\", icon: Icon, className, id, type = \"button\", ...rest },\n ref,\n) {\n const generated = useId();\n const baseId = id ?? generated;\n const titleId = `${baseId}-title`;\n const descriptionId = `${baseId}-description`;\n const metaId = `${baseId}-meta`;\n const showDescription = hasMessage(description);\n const showMeta = hasMessage(meta);\n return (\n <button\n ref={ref}\n id={id}\n type={type}\n {...rest}\n aria-labelledby={rest[\"aria-labelledby\"] ?? titleId}\n aria-describedby={mergeDescribedBy(\n rest[\"aria-describedby\"],\n showDescription && descriptionId,\n showMeta && metaId,\n )}\n className={cn(\n \"flex w-full items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 text-start shadow-sm transition-colors\",\n \"hover:border-[var(--brand)] hover:bg-[var(--bg-hover)]\",\n // The outline, as on ChoiceCard: the card is what the eye is on.\n \"focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--brand)]\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-[var(--border)] disabled:hover:bg-[var(--bg-surface)]\",\n className,\n )}\n >\n {Icon && <Icon aria-hidden className=\"mt-0.5 size-5 shrink-0 text-[var(--text-secondary)]\" />}\n <span className=\"min-w-0 flex-1 space-y-1\">\n <span id={titleId} className=\"block text-sm font-medium leading-5 text-[var(--text-primary)]\">\n {title}\n </span>\n {showDescription && (\n <span id={descriptionId} className=\"block text-sm text-[var(--text-secondary)]\">\n {description}\n </span>\n )}\n {showMeta && (\n <span id={metaId} className={cn(\"block text-sm\", META_TONE[metaTone])}>\n {meta}\n </span>\n )}\n </span>\n </button>\n );\n});\nActionCard.displayName = \"ActionCard\";\n\n/* ── ChoiceCardGroup ─────────────────────────────────────────────────────── */\n\nexport interface ChoiceCardOption<T extends string> {\n value: T;\n title: ReactNode;\n description?: ReactNode;\n icon?: ChoiceCardProps[\"icon\"];\n disabled?: boolean;\n}\n\ninterface ChoiceCardGroupBaseProps<T extends string> {\n options: ChoiceCardOption<T>[];\n /** The question the cards answer. Rendered as the fieldset's `<legend>`, which is\n * what names the group. Without one, pass `aria-label`. */\n legend?: ReactNode;\n \"aria-label\"?: string;\n /** Shared by every input — what a plain form submits under. Generated if omitted. */\n name?: string;\n /** Classes for the card grid. Default: one column, two from `sm` up. */\n className?: string;\n /** Classes for every card. */\n cardClassName?: string;\n disabled?: boolean;\n /** What is wrong with the answer as a whole. Rendered under the cards and attached\n * to the fieldset. */\n error?: ReactNode;\n /**\n * An answer is needed. Draws the required star after the `legend` (none without\n * one — the name then comes from `aria-label`, which has nowhere to draw it), and\n * reaches the inputs as the native `required`:\n * - radios: every radio of the set, which is how HTML marks a radio group — the\n * group is satisfied by any one of them, and each announces \"required\";\n * - checkboxes: every box while NONE is ticked, dropped from all of them once one\n * is — \"at least one\", which checkboxes cannot say natively. A form then refuses\n * to submit an empty set, and nothing is left demanding a second box.\n */\n required?: boolean;\n}\n\n/** One of the set: radios. `value` is `null` while nothing is chosen. */\nexport interface ChoiceCardSingleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple?: false;\n value: T | null;\n onChange: (value: T) => void;\n}\n\n/** Any of the set: checkboxes. */\nexport interface ChoiceCardMultipleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple: true;\n value: T[];\n onChange: (value: T[]) => void;\n}\n\nexport type ChoiceCardGroupProps<T extends string> =\n | ChoiceCardSingleProps<T>\n | ChoiceCardMultipleProps<T>;\n\n/**\n * A set of {@link ChoiceCard}s answering one question, in a `<fieldset>`.\n *\n * `multiple` picks the input: radios (one of the set, the browser's arrow keys\n * between them) or checkboxes (any of the set, Tab between them). The value is kept\n * in the order of `options`, not the order the boxes were ticked, so a list saved\n * from it does not depend on the order someone clicked in.\n */\nexport function ChoiceCardGroup<T extends string>(props: ChoiceCardGroupProps<T>) {\n const { options, legend, name, className, cardClassName, disabled, error, required } = props;\n const generated = useId();\n const groupName = name ?? generated;\n const errorId = `${generated}-error`;\n const showError = hasMessage(error);\n\n const isChecked = (v: T) => (props.multiple ? props.value.includes(v) : props.value === v);\n const toggle = (v: T, on: boolean) => {\n if (props.multiple) {\n const next = new Set(props.value);\n if (on) next.add(v);\n else next.delete(v);\n props.onChange(options.map((o) => o.value).filter((x) => next.has(x)));\n } else if (on) {\n props.onChange(v);\n }\n };\n\n return (\n <InGroupContext.Provider value={true}>\n <fieldset\n aria-label={props[\"aria-label\"]}\n aria-describedby={showError ? errorId : undefined}\n disabled={disabled}\n className=\"min-w-0\"\n >\n {legend !== undefined && (\n <legend className=\"mb-2 text-sm font-medium text-[var(--text-primary)]\">\n {legend}\n {required && <RequiredMark />}\n </legend>\n )}\n <div className={cn(\"grid gap-2 sm:grid-cols-2\", className)}>\n {options.map((o) => (\n <ChoiceCard\n key={o.value}\n type={props.multiple ? \"checkbox\" : \"radio\"}\n name={groupName}\n value={o.value}\n title={o.title}\n description={o.description}\n icon={o.icon}\n disabled={o.disabled}\n invalid={showError}\n required={required && (!props.multiple || props.value.length === 0) ? true : undefined}\n checked={isChecked(o.value)}\n onCheckedChange={(on) => toggle(o.value, on)}\n className={cardClassName}\n />\n ))}\n </div>\n {showError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </fieldset>\n </InGroupContext.Provider>\n );\n}\n"],"mappings":";AAqEI,cAoFE,YApFF;AArEJ,SAAS,eAAe,YAAY,aAAa,YAAY,WAAW,OAAO,cAAc;AAE7F,SAAS,OAAO,aAAa;AAC7B,SAAS,UAAU;AACnB,SAAS,WAAW,YAAY,wBAAwB;AA2DxD,MAAM,iBAAiB,cAAc,KAAK;AAI1C,SAAS,eAAe;AACtB,SACE,oBAAC,UAAK,eAAW,MAAC,WAAU,+BAA8B,eAE1D;AAEJ;AAIA,MAAM,OACJ;AAYF,MAAM,gBAAgB;AAEtB,MAAM,eACJ;AAEF,MAAM,MACJ;AAEF,MAAM,WAAW;AAGjB,MAAM,QAAQ;AAEP,MAAM,aAAa,WAA8C,SAASA,YAC/E;AAAA,EACE,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,UAAU,WAAW,cAAc;AACzC,QAAM,YAAY,MAAM;AACxB,QAAM,UAAU,MAAM;AACtB,QAAM,UAAU,GAAG,OAAO;AAC1B,QAAM,gBAAgB,GAAG,OAAO;AAChC,QAAM,UAAU,GAAG,OAAO;AAC1B,QAAM,kBAAkB,WAAW,WAAW;AAC9C,QAAM,YAAY,WAAW,KAAK;AAClC,QAAM,YAAY,QAAQ,OAAO,KAAK;AACtC,QAAM,QAAQ,SAAS,cAAc;AAErC,QAAM,QAAQ,OAAgC,IAAI;AAClD,QAAM,SAAS;A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M;AAAA,YACN,OAAO,EAAE;AAAA,YACT,OAAO,EAAE;AAAA,YACT,aAAa,EAAE;AAAA,YACf,MAAM,EAAE;AAAA,YACR,UAAU,EAAE;AAAA,YACZ,SAAS;AAAA,YACT,UAAU,aAAa,CAAC,MAAM,YAAY,MAAM,MAAM,WAAW,KAAK,OAAO;AAAA,YAC7E,SAAS,UAAU,EAAE,KAAK;AAAA,YAC1B,iBAAiB,CAAC,OAAO,OAAO,EAAE,OAAO,EAAE;AAAA,YAC3C,WAAW;AAAA;AAAA,UAZN,EAAE;AAAA,QAaT,CACD,GACH;AAAA,QACC,aACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":["ChoiceCard","ActionCard"]}
|
|
@@ -3,6 +3,7 @@ import { ButtonHTMLAttributes } from 'react';
|
|
|
3
3
|
import { ButtonVariant, IconButtonSize, ButtonSize, IconButtonTone, ButtonTone } from './ui.js';
|
|
4
4
|
import { TooltipSide } from './tooltip.js';
|
|
5
5
|
import '../hooks/use-anchored-rect.js';
|
|
6
|
+
import '../lib/clipping.js';
|
|
6
7
|
|
|
7
8
|
/** The words a copy button says. The visible three are short on purpose (they
|
|
8
9
|
* replace the button's own text in the `label` variant); the two announcements
|
|
@@ -621,6 +621,7 @@ function DataTable({
|
|
|
621
621
|
{
|
|
622
622
|
"data-density": density,
|
|
623
623
|
"data-frame": frame ? void 0 : "none",
|
|
624
|
+
"data-clips": frame ? "" : void 0,
|
|
624
625
|
className: cn(
|
|
625
626
|
"group/table",
|
|
626
627
|
frame ? "overflow-clip" : "min-w-0",
|
|
@@ -710,6 +711,7 @@ function DataTable({
|
|
|
710
711
|
/* @__PURE__ */ jsx(
|
|
711
712
|
"div",
|
|
712
713
|
{
|
|
714
|
+
"data-clips": "",
|
|
713
715
|
className: cn("overflow-auto [scrollbar-gutter:stable]", fillHeight && "flex-1 min-h-0"),
|
|
714
716
|
style: fillHeight ? void 0 : { maxHeight: maxBodyHeight },
|
|
715
717
|
children: /* @__PURE__ */ jsxs(
|