@volvel/ui 0.0.0-stage → 0.6.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/LICENSE +202 -0
- package/THIRD_PARTY_NOTICES.md +23018 -0
- package/dist/Badge.d.ts +20 -0
- package/dist/Badge.js +35 -0
- package/dist/Button.d.ts +56 -0
- package/dist/Button.js +52 -0
- package/dist/Chart.d.ts +23 -0
- package/dist/Chart.js +98 -0
- package/dist/Combobox.d.ts +45 -0
- package/dist/Combobox.js +42 -0
- package/dist/ContextMenu.d.ts +16 -0
- package/dist/ContextMenu.js +11 -0
- package/dist/DateInput.d.ts +31 -0
- package/dist/DateInput.js +329 -0
- package/dist/Details.d.ts +12 -0
- package/dist/Details.js +9 -0
- package/dist/Dialog.d.ts +44 -0
- package/dist/Dialog.js +95 -0
- package/dist/Dialogs.d.ts +56 -0
- package/dist/Dialogs.js +95 -0
- package/dist/Doc.d.ts +25 -0
- package/dist/Doc.js +118 -0
- package/dist/DocServed.d.ts +6 -0
- package/dist/DocServed.js +154 -0
- package/dist/DocZoom.d.ts +11 -0
- package/dist/DocZoom.js +133 -0
- package/dist/Facts.d.ts +12 -0
- package/dist/Facts.js +10 -0
- package/dist/Fields.d.ts +184 -0
- package/dist/Fields.js +249 -0
- package/dist/Form.d.ts +47 -0
- package/dist/Form.js +189 -0
- package/dist/Grid.d.ts +118 -0
- package/dist/Grid.js +475 -0
- package/dist/HeadingSlot.d.ts +13 -0
- package/dist/HeadingSlot.js +19 -0
- package/dist/JsonView.d.ts +11 -0
- package/dist/JsonView.js +68 -0
- package/dist/LogViewer.d.ts +45 -0
- package/dist/LogViewer.js +299 -0
- package/dist/Markdown.d.ts +21 -0
- package/dist/Markdown.js +27 -0
- package/dist/MarkdownBody.d.ts +6 -0
- package/dist/MarkdownBody.js +14 -0
- package/dist/Menu.d.ts +29 -0
- package/dist/Menu.js +8 -0
- package/dist/MoveButtons.d.ts +19 -0
- package/dist/MoveButtons.js +22 -0
- package/dist/Notice.d.ts +47 -0
- package/dist/Notice.js +50 -0
- package/dist/PageShell.d.ts +42 -0
- package/dist/PageShell.js +14 -0
- package/dist/Pagination.d.ts +13 -0
- package/dist/Pagination.js +9 -0
- package/dist/Panel.d.ts +31 -0
- package/dist/Panel.js +33 -0
- package/dist/Pickers.d.ts +37 -0
- package/dist/Pickers.js +44 -0
- package/dist/Popover.d.ts +24 -0
- package/dist/Popover.js +12 -0
- package/dist/ResultView.d.ts +28 -0
- package/dist/ResultView.js +140 -0
- package/dist/SchemaForm.d.ts +45 -0
- package/dist/SchemaForm.js +626 -0
- package/dist/SideSheet.d.ts +31 -0
- package/dist/SideSheet.js +136 -0
- package/dist/Sparkline.d.ts +14 -0
- package/dist/Sparkline.js +23 -0
- package/dist/Surfaces.d.ts +30 -0
- package/dist/Surfaces.js +34 -0
- package/dist/Switch.d.ts +18 -0
- package/dist/Switch.js +11 -0
- package/dist/Table.d.ts +15 -0
- package/dist/Table.js +6 -0
- package/dist/Tabs.d.ts +32 -0
- package/dist/Tabs.js +11 -0
- package/dist/Term.d.ts +82 -0
- package/dist/Term.js +153 -0
- package/dist/Timeline.d.ts +29 -0
- package/dist/Timeline.js +39 -0
- package/dist/Toast.d.ts +43 -0
- package/dist/Toast.js +140 -0
- package/dist/Tooltip.d.ts +34 -0
- package/dist/Tooltip.js +70 -0
- package/dist/Tree.d.ts +51 -0
- package/dist/Tree.js +233 -0
- package/dist/chartEngine.d.ts +32 -0
- package/dist/chartEngine.js +72 -0
- package/dist/chartTheme.d.ts +41 -0
- package/dist/chartTheme.js +131 -0
- package/dist/contrast.d.ts +27 -0
- package/dist/contrast.js +110 -0
- package/dist/dates.d.ts +61 -0
- package/dist/dates.js +294 -0
- package/dist/drawer/Chips.d.ts +37 -0
- package/dist/drawer/Chips.js +32 -0
- package/dist/drawer/Choices.d.ts +47 -0
- package/dist/drawer/Choices.js +81 -0
- package/dist/drawer/Drawer.d.ts +125 -0
- package/dist/drawer/Drawer.js +150 -0
- package/dist/drawer/EditorBodies.d.ts +95 -0
- package/dist/drawer/EditorBodies.js +169 -0
- package/dist/drawer/NumberFormat.d.ts +36 -0
- package/dist/drawer/NumberFormat.js +98 -0
- package/dist/drawer/SortableRows.d.ts +35 -0
- package/dist/drawer/SortableRows.js +23 -0
- package/dist/drawer/edgeShadows.d.ts +7 -0
- package/dist/drawer/edgeShadows.js +17 -0
- package/dist/drawer/index.d.ts +8 -0
- package/dist/drawer/index.js +8 -0
- package/dist/drawer/useSortable.d.ts +53 -0
- package/dist/drawer/useSortable.js +323 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +17 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +16 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +48 -0
- package/dist/markdownKnowledge.d.ts +45 -0
- package/dist/markdownKnowledge.js +37 -0
- package/dist/overlay.d.ts +7 -0
- package/dist/overlay.js +10 -0
- package/dist/pageIcons.d.ts +12 -0
- package/dist/pageIcons.js +32 -0
- package/dist/presence.d.ts +41 -0
- package/dist/presence.js +108 -0
- package/dist/returnFocus.d.ts +9 -0
- package/dist/returnFocus.js +44 -0
- package/dist/tokens.css +437 -0
- package/dist/type-scale.css +34 -0
- package/dist/useFlip.d.ts +32 -0
- package/dist/useFlip.js +118 -0
- package/fonts/OFL.txt +193 -0
- package/fonts/geist-latin.woff2 +0 -0
- package/fonts/geist-mono-latin.woff2 +0 -0
- package/package.json +47 -3
- package/README.md +0 -3
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { Button } from "./Button.js";
|
|
4
|
+
import { CheckboxField, DateField, NumberField, SelectField, TextAreaField, TextField, } from "./Fields.js";
|
|
5
|
+
import { MoveButtons } from "./MoveButtons.js";
|
|
6
|
+
import { Notice } from "./Notice.js";
|
|
7
|
+
import { SegmentedControl } from "./Pickers.js";
|
|
8
|
+
import { useFlip, useKeys } from "./useFlip.js";
|
|
9
|
+
/** Text typed into a JSON field that is not JSON yet. */
|
|
10
|
+
class Unparsed {
|
|
11
|
+
text;
|
|
12
|
+
constructor(text) {
|
|
13
|
+
this.text = text;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
17
|
+
/** Up to this many choices are shown side by side. */
|
|
18
|
+
const FEW = 4;
|
|
19
|
+
/**
|
|
20
|
+
* A string is asked for in a box of several lines only when its schema says
|
|
21
|
+
* so: `format: "textarea"`, the name forms give a field of several lines, or,
|
|
22
|
+
* with no format, a `maxLength` above this. A host name of 253 characters or
|
|
23
|
+
* an address of 320 is still one line (H0-26, H0-64, A2-10).
|
|
24
|
+
*/
|
|
25
|
+
const LONG_TEXT = 1000;
|
|
26
|
+
/** Whether a string's schema asks for several lines. */
|
|
27
|
+
function isMultiline(schema) {
|
|
28
|
+
if (schema.format === "textarea")
|
|
29
|
+
return true;
|
|
30
|
+
return (schema.format === undefined &&
|
|
31
|
+
typeof schema.maxLength === "number" &&
|
|
32
|
+
schema.maxLength > LONG_TEXT);
|
|
33
|
+
}
|
|
34
|
+
const isObject = (value) => typeof value === "object" &&
|
|
35
|
+
value !== null &&
|
|
36
|
+
!Array.isArray(value) &&
|
|
37
|
+
!(value instanceof Unparsed);
|
|
38
|
+
/** A JSON Pointer segment, escaped. */
|
|
39
|
+
const segment = (name) => String(name).replace(/~/g, "~0").replace(/\//g, "~1");
|
|
40
|
+
/** The schema with what only says "or nothing" taken off, and whether it said so. */
|
|
41
|
+
function withoutNull(schema) {
|
|
42
|
+
const type = schema.type;
|
|
43
|
+
if (Array.isArray(type) && type.includes("null")) {
|
|
44
|
+
const rest = type.filter((one) => one !== "null");
|
|
45
|
+
return { schema: { ...schema, type: rest.length === 1 ? rest[0] : rest }, nullable: true };
|
|
46
|
+
}
|
|
47
|
+
for (const key of ["anyOf", "oneOf"]) {
|
|
48
|
+
const options = schema[key];
|
|
49
|
+
if (!Array.isArray(options))
|
|
50
|
+
continue;
|
|
51
|
+
const others = options.filter((option) => option.type !== "null");
|
|
52
|
+
if (others.length === options.length - 1 && others.length === 1) {
|
|
53
|
+
const { [key]: _gone, ...rest } = schema;
|
|
54
|
+
return { schema: { ...rest, ...others[0] }, nullable: true };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { schema, nullable: false };
|
|
58
|
+
}
|
|
59
|
+
/** A union of objects told apart by one field that is a constant in each, or nothing. */
|
|
60
|
+
function unionOf(schema) {
|
|
61
|
+
const key = Array.isArray(schema.oneOf)
|
|
62
|
+
? "oneOf"
|
|
63
|
+
: Array.isArray(schema.anyOf)
|
|
64
|
+
? "anyOf"
|
|
65
|
+
: undefined;
|
|
66
|
+
if (!key)
|
|
67
|
+
return undefined;
|
|
68
|
+
const options = schema[key];
|
|
69
|
+
if (options.length < 2 || !options.every((option) => option.type === "object"))
|
|
70
|
+
return undefined;
|
|
71
|
+
const first = options[0]?.properties;
|
|
72
|
+
for (const name of Object.keys(first ?? {})) {
|
|
73
|
+
const values = options.map((option) => {
|
|
74
|
+
const property = option.properties?.[name];
|
|
75
|
+
const single = property?.const ??
|
|
76
|
+
(Array.isArray(property?.enum) && property.enum.length === 1
|
|
77
|
+
? property.enum[0]
|
|
78
|
+
: undefined);
|
|
79
|
+
return typeof single === "string" ? single : undefined;
|
|
80
|
+
});
|
|
81
|
+
if (values.every((value) => value !== undefined) && new Set(values).size === values.length) {
|
|
82
|
+
return {
|
|
83
|
+
key,
|
|
84
|
+
by: name,
|
|
85
|
+
options: options.map((option, index) => ({
|
|
86
|
+
value: values[index],
|
|
87
|
+
schema: option,
|
|
88
|
+
})),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
/** The values a choice offers, or nothing when it is no choice. */
|
|
95
|
+
function choicesOf(schema) {
|
|
96
|
+
if (Array.isArray(schema.enum))
|
|
97
|
+
return schema.enum;
|
|
98
|
+
if (schema.const !== undefined && typeof schema.const !== "object")
|
|
99
|
+
return [schema.const];
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
function shapeOf(schema) {
|
|
103
|
+
if (choicesOf(schema))
|
|
104
|
+
return "choice";
|
|
105
|
+
if (unionOf(schema))
|
|
106
|
+
return "union";
|
|
107
|
+
const type = schema.type;
|
|
108
|
+
if (type === "string")
|
|
109
|
+
return "string";
|
|
110
|
+
if (type === "number" || type === "integer")
|
|
111
|
+
return "number";
|
|
112
|
+
if (type === "boolean")
|
|
113
|
+
return "boolean";
|
|
114
|
+
if (type === "object" && isObject(schema.properties))
|
|
115
|
+
return "object";
|
|
116
|
+
// A map of names to text, such as the headers of a request: rows of a name and its value.
|
|
117
|
+
if (type === "object" &&
|
|
118
|
+
isObject(schema.additionalProperties) &&
|
|
119
|
+
schema.additionalProperties.type === "string" &&
|
|
120
|
+
!choicesOf(schema.additionalProperties))
|
|
121
|
+
return "map";
|
|
122
|
+
if (type === "array" && isObject(schema.items) && !Array.isArray(schema.prefixItems)) {
|
|
123
|
+
const items = withoutNull(schema.items).schema;
|
|
124
|
+
const inner = shapeOf(items);
|
|
125
|
+
if (inner === "object" || inner === "union" || inner === "number" || inner === "choice")
|
|
126
|
+
return "list";
|
|
127
|
+
if (inner === "string" && !items.format)
|
|
128
|
+
return "list";
|
|
129
|
+
}
|
|
130
|
+
return "json";
|
|
131
|
+
}
|
|
132
|
+
function labelOf(name, schema) {
|
|
133
|
+
if (typeof schema.title === "string")
|
|
134
|
+
return schema.title;
|
|
135
|
+
const words = name.replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2");
|
|
136
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
137
|
+
}
|
|
138
|
+
/** What a value starts as: the one given, else the schema's default, else nothing. */
|
|
139
|
+
export function startValue(schema, given) {
|
|
140
|
+
const { schema: plain } = withoutNull(schema);
|
|
141
|
+
const value = given !== undefined ? given : plain.default;
|
|
142
|
+
const shape = shapeOf(plain);
|
|
143
|
+
if (shape === "object") {
|
|
144
|
+
const properties = plain.properties;
|
|
145
|
+
const source = isObject(value) ? value : {};
|
|
146
|
+
const out = {};
|
|
147
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
148
|
+
const started = startValue(property, source[name]);
|
|
149
|
+
if (started !== undefined)
|
|
150
|
+
out[name] = started;
|
|
151
|
+
}
|
|
152
|
+
// What the schema does not name is kept, so that nothing given is lost.
|
|
153
|
+
for (const [name, held] of Object.entries(source))
|
|
154
|
+
if (!(name in out))
|
|
155
|
+
out[name] = held;
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
if (shape === "union" && value === undefined) {
|
|
159
|
+
const union = unionOf(plain);
|
|
160
|
+
const first = union.options[0];
|
|
161
|
+
return startValue(first.schema, { [union.by]: first.value });
|
|
162
|
+
}
|
|
163
|
+
if (shape === "union" && isObject(value)) {
|
|
164
|
+
const union = unionOf(plain);
|
|
165
|
+
const chosen = union.options.find((option) => option.value === value[union.by]);
|
|
166
|
+
return chosen ? startValue(chosen.schema, value) : value;
|
|
167
|
+
}
|
|
168
|
+
if (shape === "choice" && value === undefined && plain.const !== undefined)
|
|
169
|
+
return plain.const;
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
/** The value as it is sent: nothing left empty. JSON half typed is kept, for `checkValue` to refuse. */
|
|
173
|
+
export function cleaned(value) {
|
|
174
|
+
if (value instanceof Unparsed)
|
|
175
|
+
return value;
|
|
176
|
+
if (Array.isArray(value))
|
|
177
|
+
return value.map(cleaned);
|
|
178
|
+
if (isObject(value)) {
|
|
179
|
+
const out = {};
|
|
180
|
+
for (const [name, held] of Object.entries(value)) {
|
|
181
|
+
const next = cleaned(held);
|
|
182
|
+
if (next !== undefined)
|
|
183
|
+
out[name] = next;
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks a value against a schema, as far as the form draws it. Returns a
|
|
191
|
+
* message for each place that does not pass, by JSON Pointer; an empty object
|
|
192
|
+
* when it all passes.
|
|
193
|
+
*/
|
|
194
|
+
export function checkValue(schema, value, at = "") {
|
|
195
|
+
const errors = {};
|
|
196
|
+
check(schema, value, at, errors);
|
|
197
|
+
return errors;
|
|
198
|
+
}
|
|
199
|
+
function check(schema, value, at, errors) {
|
|
200
|
+
if (value instanceof Unparsed) {
|
|
201
|
+
errors[at] = "This is not valid JSON.";
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const { schema: plain, nullable } = withoutNull(schema);
|
|
205
|
+
if (value === null) {
|
|
206
|
+
if (!nullable && plain.type !== "null")
|
|
207
|
+
errors[at] = "This needs a value.";
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (value === undefined)
|
|
211
|
+
return;
|
|
212
|
+
const shape = shapeOf(plain);
|
|
213
|
+
const choices = choicesOf(plain);
|
|
214
|
+
if (shape === "choice" && choices) {
|
|
215
|
+
if (!choices.some((choice) => choice === value))
|
|
216
|
+
errors[at] = "Choose one of the options.";
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (shape === "string") {
|
|
220
|
+
if (typeof value !== "string") {
|
|
221
|
+
errors[at] = "Enter text.";
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const format = plain.format;
|
|
225
|
+
if (typeof plain.minLength === "number" && value.length < plain.minLength) {
|
|
226
|
+
errors[at] =
|
|
227
|
+
plain.minLength === 1 ? "This is required." : `Use at least ${plain.minLength} characters.`;
|
|
228
|
+
}
|
|
229
|
+
else if (typeof plain.maxLength === "number" && value.length > plain.maxLength) {
|
|
230
|
+
errors[at] = `Use at most ${plain.maxLength} characters.`;
|
|
231
|
+
}
|
|
232
|
+
else if (format === "email" && !EMAIL.test(value)) {
|
|
233
|
+
errors[at] = "Enter an email address.";
|
|
234
|
+
}
|
|
235
|
+
else if (format === "uri" && !URL.canParse(value)) {
|
|
236
|
+
errors[at] = "Enter an address, such as https://example.com.";
|
|
237
|
+
}
|
|
238
|
+
else if (format === "date" && !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
239
|
+
errors[at] = "Enter a date.";
|
|
240
|
+
}
|
|
241
|
+
else if (format === "date-time" && Number.isNaN(new Date(value).getTime())) {
|
|
242
|
+
errors[at] = "Enter a date and time.";
|
|
243
|
+
}
|
|
244
|
+
else if (typeof plain.pattern === "string" && format !== "email") {
|
|
245
|
+
let matches = true;
|
|
246
|
+
try {
|
|
247
|
+
matches = new RegExp(plain.pattern, "u").test(value);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// A pattern this browser cannot read is the server's to check.
|
|
251
|
+
}
|
|
252
|
+
if (!matches)
|
|
253
|
+
errors[at] = "This is not in the expected form.";
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (shape === "number") {
|
|
258
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
259
|
+
errors[at] = "Enter a number.";
|
|
260
|
+
}
|
|
261
|
+
else if (plain.type === "integer" && !Number.isInteger(value)) {
|
|
262
|
+
errors[at] = "Enter a whole number.";
|
|
263
|
+
}
|
|
264
|
+
else if (typeof plain.minimum === "number" && value < plain.minimum) {
|
|
265
|
+
errors[at] = `Enter ${plain.minimum} or more.`;
|
|
266
|
+
}
|
|
267
|
+
else if (typeof plain.maximum === "number" && value > plain.maximum) {
|
|
268
|
+
errors[at] = `Enter ${plain.maximum} or less.`;
|
|
269
|
+
}
|
|
270
|
+
else if (typeof plain.exclusiveMinimum === "number" && value <= plain.exclusiveMinimum) {
|
|
271
|
+
errors[at] = `Enter more than ${plain.exclusiveMinimum}.`;
|
|
272
|
+
}
|
|
273
|
+
else if (typeof plain.exclusiveMaximum === "number" && value >= plain.exclusiveMaximum) {
|
|
274
|
+
errors[at] = `Enter less than ${plain.exclusiveMaximum}.`;
|
|
275
|
+
}
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (shape === "boolean") {
|
|
279
|
+
if (typeof value !== "boolean")
|
|
280
|
+
errors[at] = "Choose yes or no.";
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (shape === "object") {
|
|
284
|
+
if (!isObject(value)) {
|
|
285
|
+
errors[at] = "This needs fields.";
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const properties = plain.properties;
|
|
289
|
+
for (const name of plain.required ?? []) {
|
|
290
|
+
const held = value[name];
|
|
291
|
+
if (held === undefined || held === "")
|
|
292
|
+
errors[`${at}/${segment(name)}`] = "This is required.";
|
|
293
|
+
}
|
|
294
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
295
|
+
const pointer = `${at}/${segment(name)}`;
|
|
296
|
+
if (errors[pointer])
|
|
297
|
+
continue;
|
|
298
|
+
check(property, value[name], pointer, errors);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (shape === "union") {
|
|
303
|
+
const union = unionOf(plain);
|
|
304
|
+
const chosen = isObject(value)
|
|
305
|
+
? union.options.find((option) => option.value === value[union.by])
|
|
306
|
+
: undefined;
|
|
307
|
+
if (!chosen)
|
|
308
|
+
errors[`${at}/${segment(union.by)}`] = "Choose one of the options.";
|
|
309
|
+
else
|
|
310
|
+
check(chosen.schema, value, at, errors);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (shape === "map") {
|
|
314
|
+
if (!isObject(value) || Object.values(value).some((held) => typeof held !== "string")) {
|
|
315
|
+
errors[at] = "Each name needs text.";
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (shape === "list") {
|
|
320
|
+
if (!Array.isArray(value)) {
|
|
321
|
+
errors[at] = "This needs a list.";
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (typeof plain.minItems === "number" && value.length < plain.minItems) {
|
|
325
|
+
errors[at] = `Add at least ${plain.minItems}.`;
|
|
326
|
+
}
|
|
327
|
+
else if (typeof plain.maxItems === "number" && value.length > plain.maxItems) {
|
|
328
|
+
errors[at] = `Keep at most ${plain.maxItems}.`;
|
|
329
|
+
}
|
|
330
|
+
value.forEach((item, index) => {
|
|
331
|
+
check(plain.items, item, `${at}/${index}`, errors);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/** One value of the form, drawn as its schema says. */
|
|
336
|
+
function Node(props) {
|
|
337
|
+
const { schema, value, onChange, pointer, label, required, errors, disabled } = props;
|
|
338
|
+
const { schema: plain, nullable } = withoutNull(schema);
|
|
339
|
+
if (nullable) {
|
|
340
|
+
const none = value === null;
|
|
341
|
+
return (_jsxs("div", { className: "flex flex-col gap-1", children: [none ? (_jsx("p", { className: "m-0 text-body-sm font-medium text-ink", children: label })) : (_jsx(Node, { ...props, schema: plain })), _jsx(CheckboxField, { name: `${pointer}#none`, label: `No ${label.toLowerCase()}`, checked: none, disabled: disabled, onChange: (checked) => onChange(checked ? null : startValue(plain, undefined)) })] }));
|
|
342
|
+
}
|
|
343
|
+
const error = errors[pointer];
|
|
344
|
+
const hint = typeof plain.description === "string" ? plain.description : undefined;
|
|
345
|
+
const common = {
|
|
346
|
+
name: pointer || "/",
|
|
347
|
+
label,
|
|
348
|
+
...(hint ? { hint } : {}),
|
|
349
|
+
error,
|
|
350
|
+
required,
|
|
351
|
+
disabled,
|
|
352
|
+
};
|
|
353
|
+
const shape = shapeOf(plain);
|
|
354
|
+
if (shape === "choice") {
|
|
355
|
+
const choices = choicesOf(plain);
|
|
356
|
+
const index = choices.indexOf(value);
|
|
357
|
+
if (choices.length <= FEW && required) {
|
|
358
|
+
return (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("span", { className: "text-body-sm font-medium text-ink", "aria-hidden": true, children: label }), _jsx(SegmentedControl, { label: label, value: index < 0 ? "" : String(index), options: choices.map((choice, at) => ({ value: String(at), label: String(choice) })), onChange: (at) => onChange(choices[Number(at)]) }), error ? (_jsx("p", { role: "alert", className: "m-0 text-body-sm text-danger", children: error })) : hint ? (_jsx("p", { className: "m-0 text-body-sm text-ink-muted", children: hint })) : null] }));
|
|
359
|
+
}
|
|
360
|
+
const options = choices.map((choice, at) => ({ value: String(at), label: String(choice) }));
|
|
361
|
+
if (!required || index < 0)
|
|
362
|
+
options.unshift({ value: "", label: "" });
|
|
363
|
+
return (_jsx(SelectField, { ...common, value: index < 0 ? "" : String(index), options: options, onChange: (at) => onChange(at === "" ? undefined : choices[Number(at)]) }));
|
|
364
|
+
}
|
|
365
|
+
if (shape === "boolean") {
|
|
366
|
+
return (_jsx(CheckboxField, { ...common, required: false, checked: value === true, onChange: (checked) => onChange(checked) }));
|
|
367
|
+
}
|
|
368
|
+
if (shape === "number") {
|
|
369
|
+
return (_jsx(NumberField, { ...common, value: typeof value === "number" ? value : undefined, ...(typeof plain.minimum === "number" ? { min: plain.minimum } : {}), ...(typeof plain.maximum === "number" ? { max: plain.maximum } : {}), ...(plain.type === "integer" ? { step: 1 } : {}), onChange: (next) => onChange(next) }));
|
|
370
|
+
}
|
|
371
|
+
if (shape === "string") {
|
|
372
|
+
const text = typeof value === "string" ? value : "";
|
|
373
|
+
const set = (next) => onChange(next === "" ? undefined : next);
|
|
374
|
+
if (plain.format === "date") {
|
|
375
|
+
return _jsx(DateField, { ...common, value: text, onChange: set });
|
|
376
|
+
}
|
|
377
|
+
if (plain.format === "date-time") {
|
|
378
|
+
return (_jsx(DateField, { ...common, withTime: true, value: localText(text), onChange: (next) => {
|
|
379
|
+
const at = new Date(next);
|
|
380
|
+
set(next === "" ? "" : Number.isNaN(at.getTime()) ? next : at.toISOString());
|
|
381
|
+
} }));
|
|
382
|
+
}
|
|
383
|
+
const limits = {
|
|
384
|
+
...(typeof plain.minLength === "number" ? { minLength: plain.minLength } : {}),
|
|
385
|
+
...(typeof plain.maxLength === "number" ? { maxLength: plain.maxLength } : {}),
|
|
386
|
+
};
|
|
387
|
+
if (isMultiline(plain)) {
|
|
388
|
+
return _jsx(TextAreaField, { ...common, ...limits, value: text, onChange: set });
|
|
389
|
+
}
|
|
390
|
+
return (_jsx(TextField, { ...common, ...limits, type: plain.format === "email" ? "email" : plain.format === "password" ? "password" : "text", value: text, onChange: set }));
|
|
391
|
+
}
|
|
392
|
+
if (shape === "object") {
|
|
393
|
+
const properties = plain.properties;
|
|
394
|
+
const needed = new Set(plain.required ?? []);
|
|
395
|
+
const held = isObject(value) ? value : {};
|
|
396
|
+
const fields = Object.entries(properties).map(([name, property]) => (_jsx(Node, { schema: property, value: held[name], onChange: (next) => onChange({ ...held, [name]: next }), pointer: `${pointer}/${segment(name)}`, label: labelOf(name, property), required: needed.has(name), errors: errors, disabled: disabled }, name)));
|
|
397
|
+
if (pointer === "")
|
|
398
|
+
return _jsx("div", { className: "flex flex-col gap-4", children: fields });
|
|
399
|
+
return (_jsxs("fieldset", { className: "m-0 flex min-w-0 flex-col gap-3 rounded-control border border-line p-3", children: [_jsx("legend", { className: "px-1 text-body-sm font-medium text-ink", children: label }), hint ? _jsx("p", { className: "m-0 text-body-sm text-ink-muted", children: hint }) : null, error ? (_jsx("p", { role: "alert", className: "m-0 text-body-sm text-danger", children: error })) : null, fields] }));
|
|
400
|
+
}
|
|
401
|
+
if (shape === "union") {
|
|
402
|
+
const union = unionOf(plain);
|
|
403
|
+
const held = isObject(value) ? value : {};
|
|
404
|
+
const chosen = union.options.find((option) => option.value === held[union.by]);
|
|
405
|
+
const pick = (next) => {
|
|
406
|
+
const option = union.options.find((one) => one.value === next);
|
|
407
|
+
if (!option)
|
|
408
|
+
return;
|
|
409
|
+
// What the options share is kept; the rest starts again.
|
|
410
|
+
const shared = Object.fromEntries(Object.entries(held).filter(([name]) => name !== union.by && name in (option.schema.properties ?? {})));
|
|
411
|
+
onChange(startValue(option.schema, { ...shared, [union.by]: next }));
|
|
412
|
+
};
|
|
413
|
+
const rest = chosen
|
|
414
|
+
? {
|
|
415
|
+
...chosen.schema,
|
|
416
|
+
properties: Object.fromEntries(Object.entries(chosen.schema.properties).filter(([name]) => name !== union.by)),
|
|
417
|
+
}
|
|
418
|
+
: undefined;
|
|
419
|
+
const choice = (_jsx(SelectField, { name: `${pointer}/${segment(union.by)}`, label: pointer === "" ? labelOf(union.by, {}) : label, value: chosen?.value ?? "", required: true, disabled: disabled, error: errors[`${pointer}/${segment(union.by)}`], options: [
|
|
420
|
+
...(chosen ? [] : [{ value: "", label: "" }]),
|
|
421
|
+
...union.options.map((option) => ({
|
|
422
|
+
value: option.value,
|
|
423
|
+
label: typeof option.schema.title === "string" ? option.schema.title : option.value,
|
|
424
|
+
})),
|
|
425
|
+
], onChange: pick }));
|
|
426
|
+
return (_jsxs("div", { className: "flex flex-col gap-3", children: [choice, rest && Object.keys(rest.properties).length > 0 ? (_jsx(Node, { ...props, schema: rest, pointer: pointer, value: held, onChange: (next) => onChange({ ...next, [union.by]: chosen?.value }),
|
|
427
|
+
// The subform's fields sit under the choice, not in a box of their own.
|
|
428
|
+
label: label })) : null] }));
|
|
429
|
+
}
|
|
430
|
+
if (shape === "list") {
|
|
431
|
+
return _jsx(ListNode, { ...props, schema: plain });
|
|
432
|
+
}
|
|
433
|
+
if (shape === "map") {
|
|
434
|
+
return _jsx(MapNode, { ...props, schema: plain });
|
|
435
|
+
}
|
|
436
|
+
return _jsx(JsonNode, { ...props, schema: plain });
|
|
437
|
+
}
|
|
438
|
+
/** A list: rows that can be added, removed and moved, each drawn by the items' schema. */
|
|
439
|
+
function ListNode({ schema, value, onChange, pointer, label, errors, disabled }) {
|
|
440
|
+
const items = schema.items;
|
|
441
|
+
const list = Array.isArray(value) ? value : [];
|
|
442
|
+
const hint = typeof schema.description === "string" ? schema.description : undefined;
|
|
443
|
+
const set = (index, next) => onChange(list.map((held, at) => (at === index ? next : held)));
|
|
444
|
+
const move = (index, by) => {
|
|
445
|
+
const next = [...list];
|
|
446
|
+
const [taken] = next.splice(index, 1);
|
|
447
|
+
next.splice(index + by, 0, taken);
|
|
448
|
+
names.move(index, index + by);
|
|
449
|
+
onChange(next);
|
|
450
|
+
};
|
|
451
|
+
// A row has no identity of its own: this name stays with it as it moves, so it is seen to move.
|
|
452
|
+
const names = useKeys(list.length);
|
|
453
|
+
const rows = useFlip(names.keys.join(" "));
|
|
454
|
+
const itemLabel = typeof items.title === "string" ? items.title : "Item";
|
|
455
|
+
return (_jsxs("fieldset", { ref: rows, className: "m-0 flex min-w-0 flex-col gap-2 rounded-control border border-line p-3", children: [_jsx("legend", { className: "px-1 text-body-sm font-medium text-ink", children: label }), hint ? _jsx("p", { className: "m-0 text-body-sm text-ink-muted", children: hint }) : null, errors[pointer] ? (_jsx("p", { role: "alert", className: "m-0 text-body-sm text-danger", children: errors[pointer] })) : null, list.map((held, index) => (_jsxs("div", { "data-flip-key": names.keys[index], className: "flex min-w-0 flex-col gap-2 border-line border-b pb-2 last:border-b-0", children: [_jsx(Node, { schema: items, value: held, onChange: (next) => set(index, next), pointer: `${pointer}/${index}`, label: `${itemLabel} ${index + 1}`, required: true, errors: errors, disabled: disabled }), _jsxs("div", { className: "flex flex-wrap gap-1", children: [_jsx(MoveButtons, { label: `${itemLabel.toLowerCase()} ${index + 1}`, at: index, count: list.length, disabled: disabled === true, onMove: (by) => move(index, by) }), _jsx(Button, { size: "small", disabled: disabled, "aria-label": `Remove ${itemLabel.toLowerCase()} ${index + 1}`, onClick: () => {
|
|
456
|
+
names.remove(index);
|
|
457
|
+
onChange(list.filter((_, at) => at !== index));
|
|
458
|
+
}, children: "Remove" })] })] }, names.keys[index]))), _jsx("div", { children: _jsxs(Button, { size: "small", disabled: disabled, onClick: () => onChange([...list, startValue(items, undefined)]), children: ["Add ", itemLabel.toLowerCase()] }) })] }));
|
|
459
|
+
}
|
|
460
|
+
/** A map of names to text: a row for each, with its name and its value, added and removed. */
|
|
461
|
+
function MapNode({ schema, value, onChange, pointer, label, required, errors, disabled, }) {
|
|
462
|
+
const hint = typeof schema.description === "string" ? schema.description : undefined;
|
|
463
|
+
const held = isObject(value) ? value : {};
|
|
464
|
+
const toRows = (map) => Object.entries(map).map(([name, text]) => ({
|
|
465
|
+
name,
|
|
466
|
+
text: typeof text === "string" ? text : "",
|
|
467
|
+
}));
|
|
468
|
+
// Rows are kept as typed, so a row with no name yet, or a name typed twice, is not lost.
|
|
469
|
+
const [rows, setRows] = useState(() => toRows(held));
|
|
470
|
+
const names = useKeys(rows.length);
|
|
471
|
+
const asMap = (list) => Object.fromEntries(list.filter((one) => one.name !== "").map((one) => [one.name, one.text]));
|
|
472
|
+
// What the form holds from outside (a reset, switching to JSON and back) replaces the rows.
|
|
473
|
+
const outside = JSON.stringify(held);
|
|
474
|
+
if (outside !== JSON.stringify(asMap(rows))) {
|
|
475
|
+
setRows(toRows(held));
|
|
476
|
+
}
|
|
477
|
+
const send = (list) => {
|
|
478
|
+
setRows(list);
|
|
479
|
+
const map = asMap(list);
|
|
480
|
+
onChange(Object.keys(map).length === 0 && !required ? undefined : map);
|
|
481
|
+
};
|
|
482
|
+
const duplicate = (name) => name !== "" && rows.filter((one) => one.name === name).length > 1;
|
|
483
|
+
return (_jsxs("fieldset", { className: "m-0 flex min-w-0 flex-col gap-2 rounded-control border border-line p-3", children: [_jsx("legend", { className: "px-1 text-body-sm font-medium text-ink", children: label }), hint ? _jsx("p", { className: "m-0 text-body-sm text-ink-muted", children: hint }) : null, errors[pointer] ? (_jsx("p", { role: "alert", className: "m-0 text-body-sm text-danger", children: errors[pointer] })) : null, rows.map((row, index) => (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 border-line border-b pb-2 last:border-b-0 sm:flex-row sm:items-end", children: [_jsx("div", { className: "min-w-0 sm:w-2/5", children: _jsx(TextField, { name: `${pointer}/${index}#name`, label: `Name ${index + 1}`, value: row.name, disabled: disabled, error: duplicate(row.name) ? "This name is used twice. The last one is kept." : undefined, onChange: (name) => send(rows.map((one, at) => (at === index ? { ...one, name } : one))) }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(TextField, { name: `${pointer}/${index}#value`, label: `Value ${index + 1}`, value: row.text, disabled: disabled, onChange: (text) => send(rows.map((one, at) => (at === index ? { ...one, text } : one))) }) }), _jsx("div", { children: _jsx(Button, { size: "small", disabled: disabled, "aria-label": `Remove ${row.name || `row ${index + 1}`}`, onClick: () => {
|
|
484
|
+
names.remove(index);
|
|
485
|
+
send(rows.filter((_, at) => at !== index));
|
|
486
|
+
}, children: "Remove" }) })] }, names.keys[index]))), _jsx("div", { children: _jsx(Button, { size: "small", disabled: disabled, onClick: () => send([...rows, { name: "", text: "" }]), children: "Add" }) })] }));
|
|
487
|
+
}
|
|
488
|
+
/** What the form cannot draw, asked for as JSON: this part alone. */
|
|
489
|
+
function JsonNode({ value, onChange, pointer, label, required, errors, disabled, schema, }) {
|
|
490
|
+
const [text, setText] = useState(() => value instanceof Unparsed
|
|
491
|
+
? value.text
|
|
492
|
+
: value === undefined
|
|
493
|
+
? ""
|
|
494
|
+
: JSON.stringify(value, null, 2));
|
|
495
|
+
const hint = typeof schema.description === "string" ? `${schema.description} As JSON.` : "As JSON.";
|
|
496
|
+
return (_jsx(TextAreaField, { name: pointer || "/", label: label, hint: hint, error: errors[pointer], required: required, disabled: disabled, rows: 4, value: text, onChange: (next) => {
|
|
497
|
+
setText(next);
|
|
498
|
+
if (next.trim() === "")
|
|
499
|
+
return onChange(undefined);
|
|
500
|
+
try {
|
|
501
|
+
onChange(JSON.parse(next));
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
onChange(new Unparsed(next));
|
|
505
|
+
}
|
|
506
|
+
} }));
|
|
507
|
+
}
|
|
508
|
+
/** An instant as a date-and-time control holds it: local time, to the minute. */
|
|
509
|
+
function localText(instant) {
|
|
510
|
+
if (!instant)
|
|
511
|
+
return "";
|
|
512
|
+
const at = new Date(instant);
|
|
513
|
+
if (Number.isNaN(at.getTime()))
|
|
514
|
+
return instant;
|
|
515
|
+
const two = (part) => String(part).padStart(2, "0");
|
|
516
|
+
return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}T${two(at.getHours())}:${two(at.getMinutes())}`;
|
|
517
|
+
}
|
|
518
|
+
/** A form drawn from a JSON Schema, with a JSON view of the whole value beside it. */
|
|
519
|
+
export function SchemaForm({ schema, value, onSubmit, submitLabel, onCancel, errors, disabled, onChange, json = true, }) {
|
|
520
|
+
const [held, setHeld] = useState(() => startValue(schema, value));
|
|
521
|
+
const [mode, setMode] = useState(() => shapeOf(withoutNull(schema).schema) === "json" ? "json" : "fields");
|
|
522
|
+
// A form that starts as JSON shows what it was given.
|
|
523
|
+
const [text, setText] = useState(() => {
|
|
524
|
+
if (shapeOf(withoutNull(schema).schema) !== "json")
|
|
525
|
+
return "";
|
|
526
|
+
const given = cleaned(startValue(schema, value));
|
|
527
|
+
return given === undefined ? "" : JSON.stringify(given, null, 2);
|
|
528
|
+
});
|
|
529
|
+
const [found, setFound] = useState({});
|
|
530
|
+
const [failure, setFailure] = useState();
|
|
531
|
+
const [busy, setBusy] = useState(false);
|
|
532
|
+
const form = useRef(null);
|
|
533
|
+
const off = disabled === true || busy;
|
|
534
|
+
const drawable = json && shapeOf(withoutNull(schema).schema) !== "json";
|
|
535
|
+
const change = (next) => {
|
|
536
|
+
setHeld(next);
|
|
537
|
+
setFound({});
|
|
538
|
+
onChange?.(cleaned(next));
|
|
539
|
+
};
|
|
540
|
+
const fromText = () => {
|
|
541
|
+
try {
|
|
542
|
+
return { ok: true, value: text.trim() === "" ? undefined : JSON.parse(text) };
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
setFound({ "": "That is not valid JSON." });
|
|
546
|
+
return { ok: false };
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const switchTo = (next) => {
|
|
550
|
+
if (next === mode)
|
|
551
|
+
return;
|
|
552
|
+
if (next === "json") {
|
|
553
|
+
const current = cleaned(held);
|
|
554
|
+
setText(current instanceof Unparsed ? "" : JSON.stringify(current ?? {}, null, 2));
|
|
555
|
+
setFound({});
|
|
556
|
+
setMode("json");
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const parsed = fromText();
|
|
560
|
+
if (!parsed.ok)
|
|
561
|
+
return;
|
|
562
|
+
setHeld(startValue(schema, parsed.value));
|
|
563
|
+
setFound({});
|
|
564
|
+
setMode("fields");
|
|
565
|
+
onChange?.(cleaned(startValue(schema, parsed.value)));
|
|
566
|
+
};
|
|
567
|
+
const submit = async (event) => {
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
if (off)
|
|
570
|
+
return;
|
|
571
|
+
let value = cleaned(held);
|
|
572
|
+
if (mode === "json") {
|
|
573
|
+
const parsed = fromText();
|
|
574
|
+
if (!parsed.ok)
|
|
575
|
+
return;
|
|
576
|
+
value = parsed.value;
|
|
577
|
+
}
|
|
578
|
+
const problems = checkValue(schema, value);
|
|
579
|
+
// At the top, nothing given is an object with nothing in it.
|
|
580
|
+
if (value === undefined && withoutNull(schema).schema.type === "object")
|
|
581
|
+
value = {};
|
|
582
|
+
setFound(problems);
|
|
583
|
+
const first = Object.keys(problems)[0];
|
|
584
|
+
if (first !== undefined) {
|
|
585
|
+
if (mode === "fields") {
|
|
586
|
+
const control = form.current?.querySelector(`[name="${CSS.escape(first || "/")}"]`);
|
|
587
|
+
if (control instanceof HTMLElement)
|
|
588
|
+
control.focus();
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
setBusy(true);
|
|
593
|
+
setFailure(undefined);
|
|
594
|
+
try {
|
|
595
|
+
await onSubmit?.(value);
|
|
596
|
+
}
|
|
597
|
+
catch (caught) {
|
|
598
|
+
setFailure(caught instanceof Error ? caught.message : String(caught));
|
|
599
|
+
}
|
|
600
|
+
finally {
|
|
601
|
+
setBusy(false);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
const shown = { ...errors, ...found };
|
|
605
|
+
const jsonErrors = Object.entries(shown)
|
|
606
|
+
.map(([pointer, message]) => (pointer ? `${pointer}: ${message}` : message))
|
|
607
|
+
.join(" ");
|
|
608
|
+
const inner = (_jsxs(_Fragment, { children: [failure ? _jsx(Notice, { tone: "danger", children: failure }) : null, drawable ? (_jsx(SegmentedControl, { label: "How to give it", size: "small", value: mode, options: [
|
|
609
|
+
{ value: "fields", label: "Fields" },
|
|
610
|
+
{ value: "json", label: "JSON" },
|
|
611
|
+
], onChange: switchTo })) : null, mode === "fields" ? (_jsx(Node, { schema: schema, value: held, onChange: change, pointer: "", label: typeof schema.title === "string" ? schema.title : "Input", required: true, errors: shown, disabled: off })) : (_jsx(TextAreaField, { name: "json", label: "As JSON", rows: 10, value: text, disabled: off, ...(jsonErrors ? { error: jsonErrors } : {}), onChange: (next) => {
|
|
612
|
+
setText(next);
|
|
613
|
+
setFound({});
|
|
614
|
+
if (!onSubmit) {
|
|
615
|
+
try {
|
|
616
|
+
onChange?.(next.trim() === "" ? undefined : JSON.parse(next));
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
onChange?.(new Unparsed(next));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
} })), onSubmit ? (_jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [onCancel ? _jsx(Button, { onClick: onCancel, children: "Cancel" }) : null, _jsx(Button, { type: "submit", variant: "primary", disabled: off, children: submitLabel })] })) : null] }));
|
|
623
|
+
if (!onSubmit)
|
|
624
|
+
return _jsx("div", { className: "flex min-w-0 max-w-xl flex-col gap-4", children: inner });
|
|
625
|
+
return (_jsx("form", { ref: form, noValidate: true, onSubmit: submit, className: "flex min-w-0 max-w-xl flex-col gap-4", children: inner }));
|
|
626
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface SideSheetProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** A line under the title. */
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
/** Drawn in a tile before the title, as the boards head a drawer. */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
/** Kept in view at the foot of the sheet: the buttons that finish what it is for. */
|
|
11
|
+
footer?: ReactNode;
|
|
12
|
+
/** `wide` is for a sheet with a table or two columns in it. */
|
|
13
|
+
size?: "regular" | "wide" | "narrow";
|
|
14
|
+
/** Its width in pixels, or `"full"` for the window less a margin, as its maker chose; on a phone it is the screen. Left out, `size`. */
|
|
15
|
+
width?: number | "full";
|
|
16
|
+
/** The edge it comes from. A menu comes from the left. */
|
|
17
|
+
side?: "right" | "left";
|
|
18
|
+
/**
|
|
19
|
+
* Where the focus goes when it closes. Left out, or answering nothing, it goes back to what
|
|
20
|
+
* opened it. A sheet that steps through records gives the row of the one it was last on.
|
|
21
|
+
*/
|
|
22
|
+
returnFocus?: () => HTMLElement | null;
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A panel that slides over the right of the screen, for work that needs more
|
|
27
|
+
* room than a dialog and should keep the page beneath in view. On a phone it
|
|
28
|
+
* takes the whole screen. Escape and the backdrop close it, and focus goes
|
|
29
|
+
* back to what opened it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function SideSheet({ open, onClose, title, description, icon, footer, size, width: chosen, side, returnFocus, children, }: SideSheetProps): import("react").JSX.Element;
|