shelving 1.290.0 → 1.291.1
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/package.json +1 -1
- package/schema/ChoiceSchema.d.ts +2 -2
- package/schema/ChoiceSchema.js +4 -2
- package/ui/dialog/Modal.md +4 -4
- package/ui/dialog/Modal.module.css +4 -3
- package/ui/input/SchemaInput.d.ts +0 -1
- package/ui/input/SchemaInput.js +1 -4
- package/ui/input/SchemaInput.md +2 -2
- package/ui/input/SchemaInput.tsx +1 -4
package/package.json
CHANGED
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface ChoiceSchemaOptions<O extends string, I = never> extends Schema
|
|
|
40
40
|
readonly value?: O | I;
|
|
41
41
|
/**
|
|
42
42
|
* Input control hint for downstream UIs.
|
|
43
|
-
*
|
|
43
|
+
* @default "radio" for 8 or fewer options, otherwise "select"
|
|
44
44
|
*/
|
|
45
45
|
readonly input?: ChoiceInputType | undefined;
|
|
46
46
|
}
|
|
@@ -55,7 +55,7 @@ export interface ChoiceSchemaOptions<O extends string, I = never> extends Schema
|
|
|
55
55
|
export declare class ChoiceSchema<O extends string, I = never> extends Schema<O> {
|
|
56
56
|
readonly value: O | I | undefined;
|
|
57
57
|
readonly options: ChoiceOptions<O>;
|
|
58
|
-
readonly input: ChoiceInputType
|
|
58
|
+
readonly input: ChoiceInputType;
|
|
59
59
|
constructor({ one, title, placeholder, options, value, input, ...rest }: ChoiceSchemaOptions<O, I>);
|
|
60
60
|
/**
|
|
61
61
|
* Get an unknown value as one of the allowed choices, or `undefined` if it isn't one.
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isArray } from "../util/array.js";
|
|
2
|
-
import { isProp } from "../util/object.js";
|
|
2
|
+
import { getKeys, isProp } from "../util/object.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Get a `ChoiceOptions` object for a set of `PossibleChoiceOptions`. */
|
|
5
5
|
function _getChoiceOptions(options) {
|
|
@@ -8,6 +8,8 @@ function _getChoiceOptions(options) {
|
|
|
8
8
|
function _getChoiceOption(k) {
|
|
9
9
|
return [k, k];
|
|
10
10
|
}
|
|
11
|
+
/** Maximum number of options for which a `ChoiceSchema` defaults to radio inputs. */
|
|
12
|
+
const MAX_RADIO_OPTIONS = 8;
|
|
11
13
|
/**
|
|
12
14
|
* Schema that validates a value against a fixed set of allowed string choices.
|
|
13
15
|
*
|
|
@@ -22,7 +24,7 @@ export class ChoiceSchema extends Schema {
|
|
|
22
24
|
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value, input, ...rest }) {
|
|
23
25
|
super({ one, title, value, placeholder, ...rest });
|
|
24
26
|
this.options = _getChoiceOptions(options);
|
|
25
|
-
this.input = input;
|
|
27
|
+
this.input = input ?? (getKeys(this.options).length <= MAX_RADIO_OPTIONS ? "radio" : "select");
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Get an unknown value as one of the allowed choices, or `undefined` if it isn't one.
|
package/ui/dialog/Modal.md
CHANGED
|
@@ -8,11 +8,11 @@ The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the conte
|
|
|
8
8
|
- `Modal` sets its text back to `--tint-00`, so it reads on its own `--tint-100` surface.
|
|
9
9
|
- `DialogsStore.show()` wraps its content in a `<Dialog>` only. It does not add a `Modal`, so put the `Modal` in the content yourself.
|
|
10
10
|
- `Modal` only styles the box. Lay out its contents with the usual block components.
|
|
11
|
-
- A centred `Modal` fills the width of its `<Dialog>`, so set `--dialog-width` to change it. `--modal-width` sets the width of a `left` or `right` panel.
|
|
11
|
+
- A centred `Modal` fills the width of its `<Dialog>`, so set `--dialog-width` to change it. `--modal-width` sets the width of a `left` or `right` panel, and the maximum width of a `top` or `bottom` panel.
|
|
12
12
|
- The `padding` variant (for example `padding="large"`) sets the top and bottom padding, and the `indent` variant sets the left and right padding, the same as on `<Panel>`.
|
|
13
13
|
- The `radius` variant sets the corner radius. On a pinned panel, corners that touch a screen edge stay square.
|
|
14
14
|
- It has a `--shadow-normal` drop shadow by default. Set `shadow="none"`, `shadow="small"` or `shadow="large"` to change it, the same as on `<Card>`.
|
|
15
|
-
- Set `top`, `right`, `bottom`, or `left` to pin the panel to that edge of the screen. A top or bottom panel is full width
|
|
15
|
+
- Set `top`, `right`, `bottom`, or `left` to pin the panel to that edge of the screen. A top or bottom panel is full width up to `--modal-width`, and centred on a wider screen. A left or right panel is full height. Use these for mobile menus, bottom sheets, and side menus.
|
|
16
16
|
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place.
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
@@ -96,11 +96,11 @@ A link click inside a `<Dialog>` closes it, so the menu slides out as the page c
|
|
|
96
96
|
|
|
97
97
|
## Styling
|
|
98
98
|
|
|
99
|
-
`Modal` paints a shadowed surface with no border. Set `--modal-stroke` (for example `var(--stroke-normal)`) to show the themed border, or `--modal-border` to replace it. A pinned panel then
|
|
99
|
+
`Modal` paints a shadowed surface with no border. Set `--modal-stroke` (for example `var(--stroke-normal)`) to show the themed border, or `--modal-border` to replace it. A pinned panel then has no border on the side that touches the screen edge. On a pinned panel, only the corners that do not touch a screen edge are round. Override these hooks at `:root` (or any ancestor scope) to retheme.
|
|
100
100
|
|
|
101
101
|
| Variable | Styles | Default |
|
|
102
102
|
|---|---|---|
|
|
103
|
-
| `--modal-width` | Width of a `left` or `right` panel (a centred panel takes `--dialog-width`) | `var(--width-narrow)` |
|
|
103
|
+
| `--modal-width` | Width of a `left` or `right` panel, and maximum width of a `top` or `bottom` panel (a centred panel takes `--dialog-width`) | `var(--width-narrow)` |
|
|
104
104
|
| `--modal-stroke` | Border width | `0` (no border) |
|
|
105
105
|
| `--modal-border` | Border shorthand | `var(--modal-stroke)` solid `--tint-80` |
|
|
106
106
|
| `--modal-radius` | Corner radius (the `radius` variant wins over it) | `var(--radius-normal)` (16px) |
|
|
@@ -37,10 +37,13 @@
|
|
|
37
37
|
view-transition-name: match-element;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/* Top and bottom panels fill the screen width up to `--modal-width`, and stay centred when the screen is wider. */
|
|
40
41
|
&.top,
|
|
41
42
|
&.bottom {
|
|
42
43
|
inset-inline: 0;
|
|
44
|
+
margin-inline: auto;
|
|
43
45
|
width: auto;
|
|
46
|
+
max-width: var(--modal-width, var(--width-narrow));
|
|
44
47
|
max-height: var(--modal-max-height, 100%);
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -51,18 +54,16 @@
|
|
|
51
54
|
width: var(--modal-width, var(--width-narrow));
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
/* If a theme sets `--modal-stroke` or `--modal-border`,
|
|
57
|
+
/* If a theme sets `--modal-stroke` or `--modal-border`, remove the border on each side that touches the edge of the screen. */
|
|
55
58
|
&.top {
|
|
56
59
|
top: 0;
|
|
57
60
|
border-top: none;
|
|
58
|
-
border-inline: none;
|
|
59
61
|
view-transition-class: modal-top;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
&.bottom {
|
|
63
65
|
bottom: 0;
|
|
64
66
|
border-bottom: none;
|
|
65
|
-
border-inline: none;
|
|
66
67
|
view-transition-class: modal-bottom;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -83,7 +83,6 @@ export interface ChoiceSchemaInputProps extends SchemaInputProps<ChoiceSchema<st
|
|
|
83
83
|
* Show a choice input for a `ChoiceSchema` — radio inputs or a select.
|
|
84
84
|
*
|
|
85
85
|
* - The schema's `input` picks the control: `"radio"` for radio inputs, `"select"` for a select.
|
|
86
|
-
* - When `input` is not set, it shows radio inputs for up to 8 options, otherwise a select.
|
|
87
86
|
* - The value is normalised through the schema's `get()`, so invalid or sentinel values (e.g. a `CountrySchema`'s `"detect"`) resolve to a real option or fall back to the placeholder rather than mis-selecting the first option.
|
|
88
87
|
*
|
|
89
88
|
* @returns A `ChoiceRadioInputs` or `SelectInput` element bound to the schema.
|
package/ui/input/SchemaInput.js
CHANGED
|
@@ -14,7 +14,6 @@ import { isArray } from "../../util/array.js";
|
|
|
14
14
|
import { isData } from "../../util/data.js";
|
|
15
15
|
import { isDictionary } from "../../util/dictionary.js";
|
|
16
16
|
import { getNumber } from "../../util/number.js";
|
|
17
|
-
import { getKeys } from "../../util/object.js";
|
|
18
17
|
import { getSource, requireSource } from "../../util/source.js";
|
|
19
18
|
import { getString } from "../../util/string.js";
|
|
20
19
|
import { Field } from "../form/Field.js";
|
|
@@ -97,7 +96,6 @@ export function NumberSchemaInput({ schema, value, ...props }) {
|
|
|
97
96
|
* Show a choice input for a `ChoiceSchema` — radio inputs or a select.
|
|
98
97
|
*
|
|
99
98
|
* - The schema's `input` picks the control: `"radio"` for radio inputs, `"select"` for a select.
|
|
100
|
-
* - When `input` is not set, it shows radio inputs for up to 8 options, otherwise a select.
|
|
101
99
|
* - The value is normalised through the schema's `get()`, so invalid or sentinel values (e.g. a `CountrySchema`'s `"detect"`) resolve to a real option or fall back to the placeholder rather than mis-selecting the first option.
|
|
102
100
|
*
|
|
103
101
|
* @returns A `ChoiceRadioInputs` or `SelectInput` element bound to the schema.
|
|
@@ -108,8 +106,7 @@ export function NumberSchemaInput({ schema, value, ...props }) {
|
|
|
108
106
|
export function ChoiceSchemaInput({ schema, value, ...props }) {
|
|
109
107
|
const choice = requireSource(ChoiceSchema, schema);
|
|
110
108
|
const string = choice.get(value);
|
|
111
|
-
|
|
112
|
-
if (input === "radio")
|
|
109
|
+
if (choice.input === "radio")
|
|
113
110
|
return _jsx(ChoiceRadioInputs, { ...schema, value: string, ...props });
|
|
114
111
|
return _jsx(SelectInput, { ...schema, value: string, ...props });
|
|
115
112
|
}
|
package/ui/input/SchemaInput.md
CHANGED
|
@@ -17,8 +17,8 @@ The schema-to-input mapping:
|
|
|
17
17
|
| `NumberSchema` | `<NumberInput>` (formatted on blur) |
|
|
18
18
|
| `DateSchema` | `<DateInput>` |
|
|
19
19
|
| `BooleanSchema` | `<CheckboxInput>` |
|
|
20
|
-
| `ChoiceSchema` (`input: "radio"`,
|
|
21
|
-
| `ChoiceSchema` (`input: "select"`,
|
|
20
|
+
| `ChoiceSchema` (`input: "radio"`, the default for ≤ 8 options) | `<ChoiceRadioInputs>` |
|
|
21
|
+
| `ChoiceSchema` (`input: "select"`, the default for > 8 options) | `<SelectInput>` |
|
|
22
22
|
| `ArraySchema` | `<ArrayInput>` |
|
|
23
23
|
| `DictionarySchema` | `<DictionaryInput>` |
|
|
24
24
|
| `DataSchema` | `<DataInput>` |
|
package/ui/input/SchemaInput.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import { isArray } from "../../util/array.js";
|
|
|
15
15
|
import { type Data, isData } from "../../util/data.js";
|
|
16
16
|
import { isDictionary } from "../../util/dictionary.js";
|
|
17
17
|
import { getNumber } from "../../util/number.js";
|
|
18
|
-
import { getKeys } from "../../util/object.js";
|
|
19
18
|
import { getSource, requireSource } from "../../util/source.js";
|
|
20
19
|
import { getString } from "../../util/string.js";
|
|
21
20
|
import type { ValidatorType } from "../../util/validate.js";
|
|
@@ -151,7 +150,6 @@ export interface ChoiceSchemaInputProps extends SchemaInputProps<ChoiceSchema<st
|
|
|
151
150
|
* Show a choice input for a `ChoiceSchema` — radio inputs or a select.
|
|
152
151
|
*
|
|
153
152
|
* - The schema's `input` picks the control: `"radio"` for radio inputs, `"select"` for a select.
|
|
154
|
-
* - When `input` is not set, it shows radio inputs for up to 8 options, otherwise a select.
|
|
155
153
|
* - The value is normalised through the schema's `get()`, so invalid or sentinel values (e.g. a `CountrySchema`'s `"detect"`) resolve to a real option or fall back to the placeholder rather than mis-selecting the first option.
|
|
156
154
|
*
|
|
157
155
|
* @returns A `ChoiceRadioInputs` or `SelectInput` element bound to the schema.
|
|
@@ -162,8 +160,7 @@ export interface ChoiceSchemaInputProps extends SchemaInputProps<ChoiceSchema<st
|
|
|
162
160
|
export function ChoiceSchemaInput({ schema, value, ...props }: ChoiceSchemaInputProps): ReactElement {
|
|
163
161
|
const choice = requireSource(ChoiceSchema, schema);
|
|
164
162
|
const string = choice.get(value);
|
|
165
|
-
|
|
166
|
-
if (input === "radio") return <ChoiceRadioInputs {...schema} value={string} {...props} />;
|
|
163
|
+
if (choice.input === "radio") return <ChoiceRadioInputs {...schema} value={string} {...props} />;
|
|
167
164
|
return <SelectInput {...schema} value={string} {...props} />;
|
|
168
165
|
}
|
|
169
166
|
|