@volvel/ui 0.0.0-stage → 0.7.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 (137) hide show
  1. package/LICENSE +202 -0
  2. package/THIRD_PARTY_NOTICES.md +23036 -0
  3. package/dist/Badge.d.ts +20 -0
  4. package/dist/Badge.js +35 -0
  5. package/dist/Button.d.ts +56 -0
  6. package/dist/Button.js +52 -0
  7. package/dist/Chart.d.ts +23 -0
  8. package/dist/Chart.js +98 -0
  9. package/dist/Combobox.d.ts +45 -0
  10. package/dist/Combobox.js +42 -0
  11. package/dist/ContextMenu.d.ts +16 -0
  12. package/dist/ContextMenu.js +38 -0
  13. package/dist/DateInput.d.ts +31 -0
  14. package/dist/DateInput.js +329 -0
  15. package/dist/Details.d.ts +12 -0
  16. package/dist/Details.js +9 -0
  17. package/dist/Dialog.d.ts +44 -0
  18. package/dist/Dialog.js +95 -0
  19. package/dist/Dialogs.d.ts +56 -0
  20. package/dist/Dialogs.js +95 -0
  21. package/dist/Doc.d.ts +25 -0
  22. package/dist/Doc.js +118 -0
  23. package/dist/DocServed.d.ts +6 -0
  24. package/dist/DocServed.js +154 -0
  25. package/dist/DocZoom.d.ts +11 -0
  26. package/dist/DocZoom.js +133 -0
  27. package/dist/Facts.d.ts +12 -0
  28. package/dist/Facts.js +10 -0
  29. package/dist/Fields.d.ts +184 -0
  30. package/dist/Fields.js +249 -0
  31. package/dist/Form.d.ts +47 -0
  32. package/dist/Form.js +189 -0
  33. package/dist/Grid.d.ts +118 -0
  34. package/dist/Grid.js +475 -0
  35. package/dist/HeadingSlot.d.ts +13 -0
  36. package/dist/HeadingSlot.js +19 -0
  37. package/dist/JsonView.d.ts +11 -0
  38. package/dist/JsonView.js +68 -0
  39. package/dist/LogViewer.d.ts +45 -0
  40. package/dist/LogViewer.js +299 -0
  41. package/dist/Markdown.d.ts +21 -0
  42. package/dist/Markdown.js +27 -0
  43. package/dist/MarkdownBody.d.ts +6 -0
  44. package/dist/MarkdownBody.js +14 -0
  45. package/dist/Menu.d.ts +29 -0
  46. package/dist/Menu.js +8 -0
  47. package/dist/MoveButtons.d.ts +19 -0
  48. package/dist/MoveButtons.js +22 -0
  49. package/dist/Notice.d.ts +47 -0
  50. package/dist/Notice.js +50 -0
  51. package/dist/PageShell.d.ts +42 -0
  52. package/dist/PageShell.js +14 -0
  53. package/dist/Pagination.d.ts +13 -0
  54. package/dist/Pagination.js +9 -0
  55. package/dist/Panel.d.ts +31 -0
  56. package/dist/Panel.js +33 -0
  57. package/dist/Pickers.d.ts +37 -0
  58. package/dist/Pickers.js +44 -0
  59. package/dist/Popover.d.ts +24 -0
  60. package/dist/Popover.js +12 -0
  61. package/dist/ResultView.d.ts +28 -0
  62. package/dist/ResultView.js +140 -0
  63. package/dist/SchemaForm.d.ts +45 -0
  64. package/dist/SchemaForm.js +626 -0
  65. package/dist/SideSheet.d.ts +31 -0
  66. package/dist/SideSheet.js +136 -0
  67. package/dist/Sparkline.d.ts +14 -0
  68. package/dist/Sparkline.js +23 -0
  69. package/dist/Surfaces.d.ts +30 -0
  70. package/dist/Surfaces.js +34 -0
  71. package/dist/Switch.d.ts +18 -0
  72. package/dist/Switch.js +11 -0
  73. package/dist/Table.d.ts +15 -0
  74. package/dist/Table.js +6 -0
  75. package/dist/Tabs.d.ts +32 -0
  76. package/dist/Tabs.js +11 -0
  77. package/dist/Term.d.ts +82 -0
  78. package/dist/Term.js +153 -0
  79. package/dist/Timeline.d.ts +29 -0
  80. package/dist/Timeline.js +39 -0
  81. package/dist/Toast.d.ts +43 -0
  82. package/dist/Toast.js +140 -0
  83. package/dist/Tooltip.d.ts +34 -0
  84. package/dist/Tooltip.js +70 -0
  85. package/dist/Tree.d.ts +51 -0
  86. package/dist/Tree.js +233 -0
  87. package/dist/chartEngine.d.ts +32 -0
  88. package/dist/chartEngine.js +72 -0
  89. package/dist/chartTheme.d.ts +41 -0
  90. package/dist/chartTheme.js +131 -0
  91. package/dist/contrast.d.ts +27 -0
  92. package/dist/contrast.js +110 -0
  93. package/dist/dates.d.ts +61 -0
  94. package/dist/dates.js +294 -0
  95. package/dist/drawer/Chips.d.ts +37 -0
  96. package/dist/drawer/Chips.js +32 -0
  97. package/dist/drawer/Choices.d.ts +47 -0
  98. package/dist/drawer/Choices.js +81 -0
  99. package/dist/drawer/Drawer.d.ts +125 -0
  100. package/dist/drawer/Drawer.js +150 -0
  101. package/dist/drawer/EditorBodies.d.ts +95 -0
  102. package/dist/drawer/EditorBodies.js +169 -0
  103. package/dist/drawer/NumberFormat.d.ts +36 -0
  104. package/dist/drawer/NumberFormat.js +98 -0
  105. package/dist/drawer/SortableRows.d.ts +35 -0
  106. package/dist/drawer/SortableRows.js +23 -0
  107. package/dist/drawer/edgeShadows.d.ts +7 -0
  108. package/dist/drawer/edgeShadows.js +17 -0
  109. package/dist/drawer/index.d.ts +8 -0
  110. package/dist/drawer/index.js +8 -0
  111. package/dist/drawer/useSortable.d.ts +53 -0
  112. package/dist/drawer/useSortable.js +323 -0
  113. package/dist/format.d.ts +6 -0
  114. package/dist/format.js +17 -0
  115. package/dist/icons.d.ts +20 -0
  116. package/dist/icons.js +16 -0
  117. package/dist/index.d.ts +48 -0
  118. package/dist/index.js +48 -0
  119. package/dist/markdownKnowledge.d.ts +45 -0
  120. package/dist/markdownKnowledge.js +37 -0
  121. package/dist/overlay.d.ts +7 -0
  122. package/dist/overlay.js +10 -0
  123. package/dist/pageIcons.d.ts +12 -0
  124. package/dist/pageIcons.js +32 -0
  125. package/dist/presence.d.ts +41 -0
  126. package/dist/presence.js +108 -0
  127. package/dist/returnFocus.d.ts +9 -0
  128. package/dist/returnFocus.js +44 -0
  129. package/dist/tokens.css +437 -0
  130. package/dist/type-scale.css +34 -0
  131. package/dist/useFlip.d.ts +32 -0
  132. package/dist/useFlip.js +118 -0
  133. package/fonts/OFL.txt +193 -0
  134. package/fonts/geist-latin.woff2 +0 -0
  135. package/fonts/geist-mono-latin.woff2 +0 -0
  136. package/package.json +52 -3
  137. package/README.md +0 -3
package/dist/dates.js ADDED
@@ -0,0 +1,294 @@
1
+ import { readerLocale } from "@volvel/widgets";
2
+ const pad = (n, to = 2) => String(n).padStart(to, "0");
3
+ /** A day as a UTC date. Years below 100 are what they say, not 19xx. */
4
+ function utcDate({ y, m, d }) {
5
+ const at = new Date(0);
6
+ at.setUTCFullYear(y, m - 1, d);
7
+ return at;
8
+ }
9
+ export const ymdText = ({ y, m, d }) => `${pad(y, 4)}-${pad(m)}-${pad(d)}`;
10
+ export const hmText = ({ h, mi }) => `${pad(h)}:${pad(mi)}`;
11
+ export function validYmd({ y, m, d }) {
12
+ if (!(y >= 1 && y <= 9999 && m >= 1 && m <= 12 && d >= 1 && d <= 31))
13
+ return false;
14
+ return d <= daysInMonth(y, m);
15
+ }
16
+ export function daysInMonth(y, m) {
17
+ return utcDate({ y, m: m + 1, d: 0 }).getUTCDate();
18
+ }
19
+ export function addDays(day, n) {
20
+ const at = utcDate(day);
21
+ at.setUTCDate(at.getUTCDate() + n);
22
+ return { y: at.getUTCFullYear(), m: at.getUTCMonth() + 1, d: at.getUTCDate() };
23
+ }
24
+ /** A month on, clamped to the length of the month it lands in (31 Jan + 1 month is 28 Feb). */
25
+ export function addMonths(day, n) {
26
+ const index = day.y * 12 + (day.m - 1) + n;
27
+ const y = Math.floor(index / 12);
28
+ const m = (index % 12) + 1;
29
+ return { y, m, d: Math.min(day.d, daysInMonth(y, m)) };
30
+ }
31
+ /** 0 for Sunday. */
32
+ export const weekdayOf = (day) => utcDate(day).getUTCDay();
33
+ export const compareYmd = (a, b) => ymdText(a).localeCompare(ymdText(b));
34
+ export const sameDay = (a, b) => a !== undefined && b !== undefined && a.y === b.y && a.m === b.m && a.d === b.d;
35
+ export function todayYmd(now = new Date()) {
36
+ return { y: now.getFullYear(), m: now.getMonth() + 1, d: now.getDate() };
37
+ }
38
+ /** What a wall string holds. Seconds and a zone mark after the minute are ignored. */
39
+ export function readWall(text) {
40
+ if (!text)
41
+ return undefined;
42
+ const hit = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}))?/.exec(text);
43
+ if (!hit)
44
+ return undefined;
45
+ const day = { y: Number(hit[1]), m: Number(hit[2]), d: Number(hit[3]) };
46
+ if (!validYmd(day))
47
+ return undefined;
48
+ const time = hit[4] === undefined ? undefined : { h: Number(hit[4]), mi: Number(hit[5]) };
49
+ return { day, time };
50
+ }
51
+ // ---------------------------------------------------------------------------
52
+ // The person's locale
53
+ export const localeOf = readerLocale;
54
+ /** In which order the locale writes day, month and year in numbers: `["m", "d", "y"]` in the US. */
55
+ export function dateOrder(locale) {
56
+ try {
57
+ const parts = new Intl.DateTimeFormat(locale, {
58
+ year: "numeric",
59
+ month: "numeric",
60
+ day: "numeric",
61
+ timeZone: "UTC",
62
+ }).formatToParts(Date.UTC(2033, 10, 22));
63
+ const order = parts.flatMap((part) => part.type === "day"
64
+ ? ["d"]
65
+ : part.type === "month"
66
+ ? ["m"]
67
+ : part.type === "year"
68
+ ? ["y"]
69
+ : []);
70
+ return order.length === 3 ? order : ["m", "d", "y"];
71
+ }
72
+ catch {
73
+ return ["m", "d", "y"];
74
+ }
75
+ }
76
+ /**
77
+ * What an empty date box says, as a hint and never as a value: the shape the locale writes
78
+ * ("mm/dd/yyyy", "dd.mm.yyyy"), with " hh:mm" for a date and time. "Pick a date" where the
79
+ * locale cannot say it.
80
+ */
81
+ export function datePattern(locale, withTime) {
82
+ try {
83
+ const parts = new Intl.DateTimeFormat(locale, {
84
+ year: "numeric",
85
+ month: "2-digit",
86
+ day: "2-digit",
87
+ timeZone: "UTC",
88
+ }).formatToParts(Date.UTC(2033, 10, 22));
89
+ const words = parts
90
+ .map((part) => part.type === "day"
91
+ ? "dd"
92
+ : part.type === "month"
93
+ ? "mm"
94
+ : part.type === "year"
95
+ ? "yyyy"
96
+ : part.type === "literal"
97
+ ? part.value
98
+ : "")
99
+ .join("");
100
+ if (!/dd/.test(words) || !/mm/.test(words) || !/yyyy/.test(words))
101
+ return "Pick a date";
102
+ return withTime ? `${words} hh:mm` : words;
103
+ }
104
+ catch {
105
+ return "Pick a date";
106
+ }
107
+ }
108
+ /** Which day a week starts on in the locale, 0 for Sunday. */
109
+ export function firstDayOf(locale) {
110
+ try {
111
+ const info = new Intl.Locale(locale);
112
+ const first = (info.getWeekInfo?.() ?? info.weekInfo)?.firstDay;
113
+ if (first !== undefined)
114
+ return first % 7;
115
+ }
116
+ catch {
117
+ // fall through
118
+ }
119
+ return /^(en-(US|CA)|es-(US|MX)|ja|he|ko|pt-BR|zh)/.test(locale) || locale === "en" ? 0 : 1;
120
+ }
121
+ export function monthNames(locale, style) {
122
+ const format = new Intl.DateTimeFormat(locale, { month: style, timeZone: "UTC" });
123
+ return Array.from({ length: 12 }, (_, index) => format.format(Date.UTC(2021, index, 15)));
124
+ }
125
+ /** Names of the days from Sunday: 2021-08-01 was one. */
126
+ export function weekdayNames(locale, style) {
127
+ const format = new Intl.DateTimeFormat(locale, { weekday: style, timeZone: "UTC" });
128
+ return Array.from({ length: 7 }, (_, index) => format.format(Date.UTC(2021, 7, 1 + index)));
129
+ }
130
+ export function formatDay(day, locale, style = "medium") {
131
+ return new Intl.DateTimeFormat(locale, { dateStyle: style, timeZone: "UTC" }).format(utcDate(day));
132
+ }
133
+ export function formatTime(time, locale) {
134
+ return new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone: "UTC" }).format(Date.UTC(1970, 0, 1, time.h, time.mi));
135
+ }
136
+ export function formatWall(text, locale, withTime) {
137
+ const read = readWall(text);
138
+ if (!read)
139
+ return "";
140
+ if (!withTime)
141
+ return formatDay(read.day, locale);
142
+ return `${formatDay(read.day, locale)}, ${formatTime(read.time ?? { h: 0, mi: 0 }, locale)}`;
143
+ }
144
+ // ---------------------------------------------------------------------------
145
+ // Reading what was typed
146
+ const KEYWORDS = { today: 0, tomorrow: 1, yesterday: -1 };
147
+ const fold = (word) => word.toLowerCase().replace(/\.$/, "").normalize("NFD").replace(/[̀-ͯ]/g, "");
148
+ function monthOfWord(word, locale) {
149
+ const w = fold(word);
150
+ if (!/^\p{L}+$/u.test(w))
151
+ return undefined;
152
+ const lists = [
153
+ monthNames(locale, "long"),
154
+ monthNames(locale, "short"),
155
+ monthNames("en", "long"),
156
+ monthNames("en", "short"),
157
+ ].map((names) => names.map(fold));
158
+ for (const names of lists) {
159
+ const exact = names.indexOf(w);
160
+ if (exact >= 0)
161
+ return exact + 1;
162
+ }
163
+ if (w.length < 3)
164
+ return undefined;
165
+ for (const names of lists) {
166
+ const starts = names.flatMap((name, index) => (name.startsWith(w) ? [index + 1] : []));
167
+ if (starts.length === 1)
168
+ return starts[0];
169
+ }
170
+ return undefined;
171
+ }
172
+ const fullYear = (text) => (text.length <= 2 ? 2000 + Number(text) : Number(text));
173
+ /** A day from what a person typed, or nothing if it can't be read. */
174
+ export function parseDay(raw, locale, now = new Date()) {
175
+ const text = raw.trim().replace(/\s+/g, " ");
176
+ if (!text)
177
+ return undefined;
178
+ const word = text.toLowerCase();
179
+ if (word in KEYWORDS)
180
+ return addDays(todayYmd(now), KEYWORDS[word] ?? 0);
181
+ const tokens = text
182
+ .replace(/(\d)(st|nd|rd|th)\b/gi, "$1")
183
+ .split(/[\s,./-]+/)
184
+ .filter(Boolean);
185
+ if (tokens.every((token) => /^\d+$/.test(token))) {
186
+ if (tokens.length < 2 || tokens.length > 3 || tokens.some((token) => token.length > 4)) {
187
+ return undefined;
188
+ }
189
+ const nums = tokens.map(Number);
190
+ const current = todayYmd(now).y;
191
+ if (tokens.length === 3 && tokens[0]?.length === 4) {
192
+ const day = { y: nums[0] ?? 0, m: nums[1] ?? 0, d: nums[2] ?? 0 };
193
+ return validYmd(day) ? day : undefined;
194
+ }
195
+ const order = dateOrder(locale).filter((part) => tokens.length === 3 || part !== "y");
196
+ const place = (parts) => {
197
+ const at = (part) => parts.indexOf(part);
198
+ return {
199
+ y: tokens.length === 3 ? fullYear(tokens[at("y")] ?? "") : current,
200
+ m: nums[at("m")] ?? 0,
201
+ d: nums[at("d")] ?? 0,
202
+ };
203
+ };
204
+ const first = place(order);
205
+ if (validYmd(first))
206
+ return first;
207
+ // 21/11/2026 in a month-first locale: the month can't be 21, so it is the other way round.
208
+ const swapped = place(order.map((part) => (part === "d" ? "m" : part === "m" ? "d" : part)));
209
+ return validYmd(swapped) ? swapped : undefined;
210
+ }
211
+ let month;
212
+ const numbers = [];
213
+ for (const token of tokens) {
214
+ if (/^\d+$/.test(token)) {
215
+ numbers.push(token);
216
+ continue;
217
+ }
218
+ const found = monthOfWord(token, locale);
219
+ if (found !== undefined && month === undefined) {
220
+ month = found;
221
+ continue;
222
+ }
223
+ const isWeekday = [weekdayNames(locale, "long"), weekdayNames(locale, "short")]
224
+ .concat([weekdayNames("en", "long"), weekdayNames("en", "short")])
225
+ .some((names) => names.map(fold).some((name) => name === fold(token)));
226
+ if (!isWeekday)
227
+ return undefined;
228
+ }
229
+ if (month === undefined || numbers.length === 0 || numbers.length > 2)
230
+ return undefined;
231
+ const yearAt = numbers.findIndex((token) => token.length === 4);
232
+ const dayText = numbers.find((_, index) => index !== yearAt);
233
+ if (dayText === undefined || dayText.length > 2)
234
+ return undefined;
235
+ const yearText = yearAt >= 0 ? numbers[yearAt] : numbers.length === 2 ? numbers[1] : undefined;
236
+ const day = {
237
+ y: yearText === undefined ? todayYmd(now).y : fullYear(yearText),
238
+ m: month,
239
+ d: Number(dayText),
240
+ };
241
+ return validYmd(day) ? day : undefined;
242
+ }
243
+ const TIME_WORD = "\\d{1,2}(?:[:.h]\\d{2})?\\s*(?:am|pm|a\\.m\\.|p\\.m\\.)|\\d{1,2}[:h]\\d{2}|noon|midnight";
244
+ /** A time of day from "14:30", "2:30 PM", "9am", "noon". */
245
+ export function parseTime(raw) {
246
+ const text = raw.trim().toLowerCase();
247
+ if (text === "noon")
248
+ return { h: 12, mi: 0 };
249
+ if (text === "midnight")
250
+ return { h: 0, mi: 0 };
251
+ const hit = /^(\d{1,2})(?:[:.h](\d{2}))?\s*(am|pm|a\.m\.|p\.m\.)?$/.exec(text);
252
+ if (!hit)
253
+ return undefined;
254
+ let h = Number(hit[1]);
255
+ const mi = hit[2] === undefined ? 0 : Number(hit[2]);
256
+ if (hit[2] === undefined && hit[3] === undefined)
257
+ return undefined;
258
+ if (mi > 59)
259
+ return undefined;
260
+ if (hit[3]) {
261
+ if (h < 1 || h > 12)
262
+ return undefined;
263
+ h = (h % 12) + (hit[3].startsWith("p") ? 12 : 0);
264
+ }
265
+ else if (h > 23) {
266
+ return undefined;
267
+ }
268
+ return { h, mi };
269
+ }
270
+ /**
271
+ * What a box holds, read: a day, and with a time asked for, a time too. `2026-11-21T14:30`,
272
+ * "21 nov 2026 9am", "tomorrow 14:30". A day alone keeps the time the field had.
273
+ */
274
+ export function parseEntry(raw, withTime, locale, now = new Date()) {
275
+ const text = raw.trim();
276
+ const iso = /^(\d{4}-\d{1,2}-\d{1,2})[T ](\d{1,2}:\d{2})(?::\d{2}(?:\.\d+)?)?Z?$/i.exec(text);
277
+ if (iso) {
278
+ const day = parseDay(iso[1] ?? "", locale, now);
279
+ const time = parseTime(iso[2] ?? "");
280
+ return day && time ? { day, time: withTime ? time : undefined } : undefined;
281
+ }
282
+ if (!withTime) {
283
+ const day = parseDay(text, locale, now);
284
+ return day ? { day, time: undefined } : undefined;
285
+ }
286
+ const split = new RegExp(`^(.*?)[,\\s]+(?:at\\s+)?(${TIME_WORD})$`, "i").exec(text);
287
+ if (split) {
288
+ const day = parseDay(split[1] ?? "", locale, now);
289
+ const time = parseTime(split[2] ?? "");
290
+ return day && time ? { day, time } : undefined;
291
+ }
292
+ const day = parseDay(text, locale, now);
293
+ return day ? { day, time: undefined } : undefined;
294
+ }
@@ -0,0 +1,37 @@
1
+ import type { ComponentPropsWithRef, ReactElement, ReactNode } from "react";
2
+ /** Chips, laid out in a wrapping row. */
3
+ export declare function ChipSet({ children, label }: {
4
+ children: ReactNode;
5
+ label?: string;
6
+ }): import("react").JSX.Element;
7
+ /**
8
+ * "✓ Clinic": a thing that is followed or on. Pressing it switches it off, and it then draws
9
+ * dashed, as the filter a widget does not follow.
10
+ */
11
+ export declare function CheckChip({ checked, onChange, children, disabled, }: {
12
+ checked: boolean;
13
+ onChange: (next: boolean) => void;
14
+ children: ReactNode;
15
+ disabled?: boolean;
16
+ }): import("react").JSX.Element;
17
+ /**
18
+ * A sentence as a chip, with a ×: "Status is Unpaid". Pass the sentence as children, its value
19
+ * in `<strong>`. Pressing the sentence runs `onEdit`; the × runs `onRemove`. (The brief calls it
20
+ * ValueChip; `ValueChip` is already the console's colored value badge in this kit.)
21
+ */
22
+ export declare function SentenceChip({ children, onEdit, onRemove, removeLabel, wrapEdit, }: {
23
+ children: ReactNode;
24
+ onEdit?: () => void;
25
+ onRemove?: () => void;
26
+ /** What the × says to a screen reader: "Remove Status is Unpaid". */
27
+ removeLabel?: string;
28
+ /** Puts the sentence's button in a `DrawerEditor` as its trigger, so the editor opens beside it. */
29
+ wrapEdit?: (button: ReactElement) => ReactElement;
30
+ }): import("react").JSX.Element;
31
+ /**
32
+ * The dashed "+ Condition". It passes its other props on, so it can be the trigger of a
33
+ * `DrawerEditor`: `<DrawerEditor trigger={<AddChip>Condition</AddChip>}>`.
34
+ */
35
+ export declare function AddChip({ children, ...rest }: {
36
+ children: ReactNode;
37
+ } & ComponentPropsWithRef<"button">): ReactElement;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Check, Plus, X } from "lucide-react";
3
+ const focus = "outline-offset-2 focus-visible:outline-2 focus-visible:outline-focus";
4
+ /** Chips, laid out in a wrapping row. */
5
+ export function ChipSet({ children, label }) {
6
+ return (_jsx("div", { role: "group", ...(label ? { "aria-label": label } : {}), className: "flex flex-wrap gap-1.5", children: children }));
7
+ }
8
+ /**
9
+ * "✓ Clinic": a thing that is followed or on. Pressing it switches it off, and it then draws
10
+ * dashed, as the filter a widget does not follow.
11
+ */
12
+ export function CheckChip({ checked, onChange, children, disabled = false, }) {
13
+ return (_jsxs("button", { type: "button", "aria-pressed": checked, disabled: disabled, onClick: () => onChange(!checked), className: `inline-flex min-h-7 cursor-pointer items-center gap-1.5 rounded-control border px-3 py-0.5 text-left text-body-sm disabled:cursor-not-allowed disabled:opacity-60 ${focus} ${checked
14
+ ? "border-action bg-action-soft text-action"
15
+ : "border-dashed border-line-strong text-ink-muted hover:text-ink"}`, children: [checked ? _jsx(Check, { "aria-hidden": "true", size: 14 }) : null, children] }));
16
+ }
17
+ /**
18
+ * A sentence as a chip, with a ×: "Status is Unpaid". Pass the sentence as children, its value
19
+ * in `<strong>`. Pressing the sentence runs `onEdit`; the × runs `onRemove`. (The brief calls it
20
+ * ValueChip; `ValueChip` is already the console's colored value badge in this kit.)
21
+ */
22
+ export function SentenceChip({ children, onEdit, onRemove, removeLabel = "Remove", wrapEdit, }) {
23
+ const button = (_jsx("button", { type: "button", ...(onEdit ? { onClick: onEdit } : {}), className: `h-full cursor-pointer rounded-l-control pr-1 pl-3 ${focus}`, children: children }));
24
+ return (_jsxs("span", { className: "inline-flex h-7 items-center rounded-control border border-line-strong bg-sunken text-body-sm text-ink", children: [wrapEdit ? (wrapEdit(button)) : onEdit ? (button) : (_jsx("span", { className: "pr-1 pl-3", children: children })), onRemove ? (_jsx("button", { type: "button", onClick: onRemove, "aria-label": removeLabel, className: `grid h-full w-6 cursor-pointer place-items-center rounded-r-control text-ink-muted hover:text-ink ${focus}`, children: _jsx(X, { "aria-hidden": "true", size: 14 }) })) : (_jsx("span", { className: "w-1.5" }))] }));
25
+ }
26
+ /**
27
+ * The dashed "+ Condition". It passes its other props on, so it can be the trigger of a
28
+ * `DrawerEditor`: `<DrawerEditor trigger={<AddChip>Condition</AddChip>}>`.
29
+ */
30
+ export function AddChip({ children, ...rest }) {
31
+ return (_jsxs("button", { type: "button", ...rest, className: `inline-flex h-7 cursor-pointer items-center gap-1 rounded-control border border-dashed border-line-strong px-3 text-body-sm text-ink-muted hover:border-action hover:text-ink ${focus}`, children: [_jsx(Plus, { "aria-hidden": "true", size: 14 }), children] }));
32
+ }
@@ -0,0 +1,47 @@
1
+ import { type ReactNode } from "react";
2
+ import type { DrawerIcon } from "./Drawer.tsx";
3
+ export interface TileOption<Value extends string> {
4
+ value: Value;
5
+ label: string;
6
+ icon?: DrawerIcon;
7
+ /** The thing drawn as it is, in place of the icon: a button in its style. */
8
+ preview?: ReactNode;
9
+ disabled?: boolean;
10
+ /** Why it is disabled, under its label: "needs a date". */
11
+ reason?: string;
12
+ }
13
+ /**
14
+ * Tiles chosen by looking: an icon and a label, or the thing itself. One is chosen; a tile may
15
+ * be disabled with the reason under it. Arrow keys move between the enabled ones.
16
+ */
17
+ export declare function TilePicker<Value extends string>({ label, options, value, onChange, columns, }: {
18
+ label: string;
19
+ options: readonly TileOption<Value>[];
20
+ value: Value | undefined;
21
+ onChange: (value: Value) => void;
22
+ columns?: 2 | 3 | 4;
23
+ }): import("react").JSX.Element;
24
+ /** Cards with a radio, a title and a line: "Open record detail · Passes the clicked invoice along". */
25
+ export declare function RadioCards<Value extends string>({ label, options, value, onChange, }: {
26
+ label: string;
27
+ options: readonly {
28
+ value: Value;
29
+ title: string;
30
+ line?: string;
31
+ disabled?: boolean;
32
+ }[];
33
+ value: Value | undefined;
34
+ onChange: (value: Value) => void;
35
+ }): import("react").JSX.Element;
36
+ export declare const POSITIONS: readonly ["top-left", "top-center", "top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", "bottom-right"];
37
+ export type Position = (typeof POSITIONS)[number];
38
+ /**
39
+ * A 3 × 3 grid of positions, for where a button sits in its cell. One radio group: the arrow
40
+ * keys move over the grid (and choose as they go), and each place has its name for a screen
41
+ * reader: "Top left".
42
+ */
43
+ export declare function PositionPicker({ label, value, onChange, }: {
44
+ label?: string;
45
+ value: Position;
46
+ onChange: (value: Position) => void;
47
+ }): import("react").JSX.Element;
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useRef } from "react";
3
+ const ring = "has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-focus";
4
+ /**
5
+ * Tiles chosen by looking: an icon and a label, or the thing itself. One is chosen; a tile may
6
+ * be disabled with the reason under it. Arrow keys move between the enabled ones.
7
+ */
8
+ export function TilePicker({ label, options, value, onChange, columns = 3, }) {
9
+ const name = useId();
10
+ return (_jsxs("fieldset", { className: "m-0 min-w-0 border-0 p-0", children: [_jsx("legend", { className: "sr-only", children: label }), _jsx("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` }, children: options.map((option) => {
11
+ const on = option.value === value;
12
+ const Icon = option.icon;
13
+ const reasonId = `${name}-${option.value}-why`;
14
+ return (_jsxs("label", { "data-selected": on ? "" : undefined, className: `flex min-h-16 flex-col items-center justify-center gap-1 rounded-control border px-2 py-2 text-center text-body-sm ${ring} ${option.disabled
15
+ ? "cursor-default border-dashed border-line text-ink-muted opacity-60"
16
+ : on
17
+ ? "cursor-pointer border-action bg-action-soft text-action"
18
+ : "cursor-pointer border-line text-ink hover:border-line-strong"}`, children: [_jsx("input", { type: "radio", name: name, value: option.value, checked: on, disabled: option.disabled, onChange: () => onChange(option.value), ...(option.reason ? { "aria-describedby": reasonId } : {}), className: "sr-only" }), option.preview ?? (Icon ? _jsx(Icon, { size: 16, "aria-hidden": true }) : null), _jsx("span", { children: option.label }), option.reason ? (_jsx("span", { id: reasonId, className: "text-tag text-ink-muted", children: option.reason })) : null] }, option.value));
19
+ }) })] }));
20
+ }
21
+ /** Cards with a radio, a title and a line: "Open record detail · Passes the clicked invoice along". */
22
+ export function RadioCards({ label, options, value, onChange, }) {
23
+ const name = useId();
24
+ return (_jsxs("fieldset", { className: "m-0 flex min-w-0 flex-col gap-1.5 border-0 p-0", children: [_jsx("legend", { className: "sr-only", children: label }), options.map((option) => {
25
+ const on = option.value === value;
26
+ const lineId = `${name}-${option.value}-line`;
27
+ return (_jsxs("label", { className: `flex cursor-pointer items-start gap-3 rounded-control border px-3 py-3 has-[:disabled]:cursor-default has-[:disabled]:opacity-60 ${ring} ${on ? "border-action bg-action-soft" : "border-line hover:border-line-strong"}`, children: [_jsx("input", { type: "radio", name: name, value: option.value, checked: on, disabled: option.disabled, onChange: () => onChange(option.value), ...(option.line ? { "aria-describedby": lineId } : {}), className: "mt-0.5 size-4 shrink-0 accent-[var(--vx-action)]" }), _jsxs("span", { className: "min-w-0", children: [_jsx("span", { className: "block text-body-sm font-medium text-ink", children: option.title }), option.line ? (_jsx("span", { id: lineId, className: "block text-meta text-ink-muted", children: option.line })) : null] })] }, option.value));
28
+ })] }));
29
+ }
30
+ export const POSITIONS = [
31
+ "top-left",
32
+ "top-center",
33
+ "top-right",
34
+ "middle-left",
35
+ "middle-center",
36
+ "middle-right",
37
+ "bottom-left",
38
+ "bottom-center",
39
+ "bottom-right",
40
+ ];
41
+ const positionName = (position) => {
42
+ const [row, column] = position.split("-");
43
+ const words = row === "middle" && column === "center" ? "Center" : `${row} ${column}`;
44
+ return words.charAt(0).toUpperCase() + words.slice(1).replace("-", " ");
45
+ };
46
+ /**
47
+ * A 3 × 3 grid of positions, for where a button sits in its cell. One radio group: the arrow
48
+ * keys move over the grid (and choose as they go), and each place has its name for a screen
49
+ * reader: "Top left".
50
+ */
51
+ export function PositionPicker({ label = "Position", value, onChange, }) {
52
+ const refs = useRef([]);
53
+ const at = POSITIONS.indexOf(value);
54
+ const go = (event, from) => {
55
+ const row = Math.floor(from / 3);
56
+ const column = from % 3;
57
+ const to = event.key === "ArrowLeft"
58
+ ? row * 3 + Math.max(0, column - 1)
59
+ : event.key === "ArrowRight"
60
+ ? row * 3 + Math.min(2, column + 1)
61
+ : event.key === "ArrowUp"
62
+ ? Math.max(0, row - 1) * 3 + column
63
+ : event.key === "ArrowDown"
64
+ ? Math.min(2, row + 1) * 3 + column
65
+ : -1;
66
+ if (to < 0)
67
+ return;
68
+ event.preventDefault();
69
+ const next = POSITIONS[to];
70
+ if (!next)
71
+ return;
72
+ onChange(next);
73
+ refs.current[to]?.focus();
74
+ };
75
+ return (_jsx("div", { role: "radiogroup", "aria-label": label, className: "inline-grid w-fit grid-cols-3 gap-1 rounded-control border border-line bg-sunken p-1", children: POSITIONS.map((position, index) => {
76
+ const on = position === value;
77
+ return (_jsx("button", { ref: (node) => {
78
+ refs.current[index] = node;
79
+ }, type: "button", role: "radio", "aria-checked": on, "aria-label": positionName(position), tabIndex: on || (at < 0 && index === 0) ? 0 : -1, onClick: () => onChange(position), onKeyDown: (event) => go(event, index), className: "grid size-8 cursor-pointer place-items-center rounded-inner outline-offset-1 hover:bg-surface focus-visible:outline-2 focus-visible:outline-focus", children: _jsx("span", { "aria-hidden": "true", className: `size-2.5 rounded-full ${on ? "bg-action ring-4 ring-action-soft" : "bg-line-strong"}` }) }, position));
80
+ }) }));
81
+ }
@@ -0,0 +1,125 @@
1
+ import { type ComponentType, type ReactElement, type ReactNode } from "react";
2
+ /** An icon component from `@volvel/ui/icons`, or any component that takes a class and a size. */
3
+ export type DrawerIcon = ComponentType<{
4
+ size?: number;
5
+ className?: string;
6
+ "aria-hidden"?: boolean | "true";
7
+ }>;
8
+ /** The head of a drawer: the widget's icon tile, its name, its kind, and a ⋯ menu. */
9
+ export declare function DrawerHeader({ icon: Icon, name, kind, menu, }: {
10
+ icon?: DrawerIcon;
11
+ name: string;
12
+ /** "Stat", "Chart", "Table". */
13
+ kind: string;
14
+ /** The ⋯ menu: pass a `Menu` or any button. */
15
+ menu?: ReactNode;
16
+ }): import("react").JSX.Element;
17
+ export interface DrawerTab {
18
+ id: string;
19
+ label: string;
20
+ /**
21
+ * Something in this tab needs fixing: a dot in the attention tone, and these words (what is
22
+ * wrong) for a screen reader and a tooltip. Left out, there is no dot: it is never "something is
23
+ * set here".
24
+ */
25
+ attention?: string;
26
+ /** A count, in place of the dot. */
27
+ count?: number;
28
+ }
29
+ /**
30
+ * The segmented tab bar. Left and Right (and Home and End) move between the tabs and open the
31
+ * one they land on. Pair it with `DrawerPanel`, with the same `idPrefix`.
32
+ */
33
+ export declare function DrawerTabs({ tabs, value, onChange, idPrefix, label, }: {
34
+ tabs: readonly DrawerTab[];
35
+ value: string;
36
+ onChange: (id: string) => void;
37
+ idPrefix: string;
38
+ label?: string;
39
+ }): import("react").JSX.Element;
40
+ /** What a tab holds. */
41
+ export declare function DrawerPanel({ idPrefix, tab, children, }: {
42
+ idPrefix: string;
43
+ tab: string;
44
+ children: ReactNode;
45
+ }): import("react").JSX.Element;
46
+ /** An UPPERCASE small label, a bordered list of rows, and a note under it. */
47
+ export declare function DrawerGroup({ label, aside, note, children, }: {
48
+ label: string;
49
+ /** Right of the label: "6 of 8 shown". */
50
+ aside?: ReactNode;
51
+ note?: ReactNode;
52
+ children: ReactNode;
53
+ }): import("react").JSX.Element;
54
+ /** Free content in a group, padded as a row is: chips, a sentence, a preview. */
55
+ export declare function DrawerBlock({ children, label, className, }: {
56
+ children: ReactNode;
57
+ label?: string;
58
+ className?: string;
59
+ }): import("react").JSX.Element;
60
+ /**
61
+ * One row of a group: its label on the left, an icon and the current value, a chevron. With an
62
+ * `editor` it opens a small editor beside it, and shows as selected while it is open; with
63
+ * `onClick` it runs an action; with neither it only reads.
64
+ */
65
+ export declare function DrawerRow({ label, icon: Icon, value, mono, hint, active, editor, editorTitle, editorFooter, open, onOpenChange, onClick, side, }: {
66
+ label: string;
67
+ icon?: DrawerIcon;
68
+ /** The current value. */
69
+ value?: ReactNode;
70
+ /** The value is a number or a record number: Geist Mono. */
71
+ mono?: boolean;
72
+ /** A quieter second part of the value: "Money" after "$43,120.00". */
73
+ hint?: ReactNode;
74
+ /** Selected, as the row of an open editor: the accent rail. */
75
+ active?: boolean;
76
+ /** The body of a small editor that opens from the row. */
77
+ editor?: ReactNode;
78
+ editorTitle?: string;
79
+ /** "Done" closes the editor; `false` leaves it out. Default: shown. */
80
+ editorFooter?: boolean;
81
+ open?: boolean;
82
+ onOpenChange?: (open: boolean) => void;
83
+ onClick?: () => void;
84
+ side?: "left" | "right" | "bottom";
85
+ }): import("react").JSX.Element;
86
+ /**
87
+ * A small editor that opens beside a row or a chip: a title, a close ×, a body, and a "Done"
88
+ * footer. Escape and a click outside close it, and focus goes back to what opened it.
89
+ */
90
+ export declare function DrawerEditor({ trigger, title, children, footer, doneLabel, open, onOpenChange, onDone, side, boundary, }: {
91
+ /** The element that opens it: a button. */
92
+ trigger: ReactElement;
93
+ title: string;
94
+ children: ReactNode;
95
+ footer?: boolean;
96
+ doneLabel?: string;
97
+ open?: boolean;
98
+ onOpenChange?: (open: boolean) => void;
99
+ /** Runs when "Done" is pressed, before it closes. */
100
+ onDone?: () => void;
101
+ side?: "left" | "right" | "bottom";
102
+ /** An element it stays inside (the canvas, so it never covers the settings or the header). */
103
+ boundary?: Element | null | undefined;
104
+ }): import("react").JSX.Element;
105
+ /** A switch: on or off. */
106
+ export declare function DrawerSwitch({ checked, onChange, labelledBy, describedBy, label, }: {
107
+ checked: boolean;
108
+ onChange: (next: boolean) => void;
109
+ labelledBy?: string;
110
+ describedBy?: string;
111
+ label?: string;
112
+ }): import("react").JSX.Element;
113
+ /** A label, a help line, and a switch: "Show values on bars". */
114
+ export declare function ToggleRow({ label, help, checked, onChange, }: {
115
+ label: string;
116
+ help?: ReactNode;
117
+ checked: boolean;
118
+ onChange: (next: boolean) => void;
119
+ }): import("react").JSX.Element;
120
+ /** The dashed "+ Add a step", "+ Column": full width, or as wide as its words. */
121
+ export declare function DashedAdd({ children, onClick, inline, }: {
122
+ children: ReactNode;
123
+ onClick?: () => void;
124
+ inline?: boolean;
125
+ }): import("react").JSX.Element;