shelving 1.301.0 → 1.302.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/package.json +2 -2
- package/schema/ColorSchema.js +1 -1
- package/schema/CurrencyCodeSchema.js +1 -1
- package/schema/EmailSchema.js +1 -1
- package/schema/PhoneSchema.js +1 -1
- package/schema/SlugSchema.js +1 -1
- package/schema/StringSchema.d.ts +10 -4
- package/schema/StringSchema.js +5 -3
- package/schema/URISchema.js +1 -1
- package/schema/URLSchema.js +1 -1
- package/schema/UUIDSchema.js +1 -1
- package/ui/input/Input.test.tsx +2 -2
- package/ui/input/SchemaInput.d.ts +4 -3
- package/ui/input/SchemaInput.js +6 -3
- package/ui/input/SchemaInput.test.tsx +16 -0
- package/ui/input/SchemaInput.tsx +7 -4
- package/ui/input/TextInput.d.ts +6 -9
- package/ui/input/TextInput.js +3 -22
- package/ui/input/TextInput.tsx +7 -50
- package/ui/input/TextareaInput.d.ts +29 -0
- package/ui/input/TextareaInput.js +35 -0
- package/ui/input/TextareaInput.tsx +86 -0
- package/ui/input/index.d.ts +1 -0
- package/ui/input/index.js +1 -0
- package/ui/input/index.ts +1 -0
- package/ui/notice/Notices.d.ts +0 -1
- package/ui/notice/Notices.js +2 -2
- package/ui/notice/Notices.tsx +6 -2
- package/ui/notice/{NoticesTransition.css → NoticesTransition.module.css} +19 -5
- package/ui/transition/CollapseTransition.d.ts +0 -1
- package/ui/transition/CollapseTransition.js +4 -2
- package/ui/transition/CollapseTransition.md +1 -1
- package/ui/transition/{CollapseTransition.css → CollapseTransition.module.css} +0 -1
- package/ui/transition/CollapseTransition.tsx +5 -2
- package/ui/transition/HorizontalTransition.css +1 -1
- package/ui/transition/Transition.d.ts +1 -2
- package/ui/transition/Transition.js +4 -5
- package/ui/transition/Transition.md +1 -1
- package/ui/transition/Transition.module.css +3 -0
- package/ui/transition/Transition.tsx +4 -5
- package/ui/transition/VerticalTransition.css +1 -1
- package/ui/util/css.test.ts +4 -5
- package/ui/transition/Transition.css +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shelving",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.302.0",
|
|
4
4
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"description": "Toolkit for using data in JavaScript.",
|
|
43
43
|
"engineStrict": true,
|
|
44
44
|
"engines": {
|
|
45
|
-
"bun": ">=1.4.
|
|
45
|
+
"bun": ">=1.4.3",
|
|
46
46
|
"node": ">=16.0.0"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
package/schema/ColorSchema.js
CHANGED
|
@@ -25,7 +25,7 @@ export class CurrencyCodeSchema extends StringSchema {
|
|
|
25
25
|
...options,
|
|
26
26
|
max, // Valid currency code is 3 uppercase letters.
|
|
27
27
|
min: 3,
|
|
28
|
-
|
|
28
|
+
multiline: false,
|
|
29
29
|
case: "upper",
|
|
30
30
|
match: /^[A-Z]{3}$/, // Valid currency code is 3 uppercase letters.
|
|
31
31
|
});
|
package/schema/EmailSchema.js
CHANGED
package/schema/PhoneSchema.js
CHANGED
|
@@ -19,7 +19,7 @@ export class PhoneSchema extends StringSchema {
|
|
|
19
19
|
// Valid phone number is 16 digits or fewer (15 numerals with a leading `+` plus).
|
|
20
20
|
max,
|
|
21
21
|
min: 1,
|
|
22
|
-
|
|
22
|
+
multiline: false,
|
|
23
23
|
// Valid phone number is max 16 digits made up of:
|
|
24
24
|
// - Country code (`+` plus character and 1-3 digits, e.g. `+44` or `+1`).
|
|
25
25
|
// - Subscriber number (5-12 digits — the Solomon Islands have five-digit phone numbers apparently).
|
package/schema/SlugSchema.js
CHANGED
package/schema/StringSchema.d.ts
CHANGED
|
@@ -28,8 +28,13 @@ export interface StringSchemaOptions extends SchemaOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
readonly max?: number | undefined;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @default
|
|
31
|
+
* Whether the string keeps line breaks (multiline sanitization). An input for it is a `<textarea>` that grows.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
readonly multiline?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Rows a multiline input shows at first. Set `1` for a box that starts one line high, like a chat message. Single-line inputs ignore it.
|
|
37
|
+
* @default `2` when `multiline`, else `1`
|
|
33
38
|
*/
|
|
34
39
|
readonly rows?: number | undefined;
|
|
35
40
|
/** Regular expression the sanitized string must match. */
|
|
@@ -56,15 +61,16 @@ export declare class StringSchema extends Schema<string> {
|
|
|
56
61
|
readonly min: number;
|
|
57
62
|
readonly max: number;
|
|
58
63
|
readonly rows: number;
|
|
64
|
+
readonly multiline: boolean;
|
|
59
65
|
readonly match: RegExp | undefined;
|
|
60
66
|
readonly case: "upper" | "lower" | undefined;
|
|
61
|
-
constructor({ one, min, max, value, rows, match, case: _case, input, ...options }: StringSchemaOptions);
|
|
67
|
+
constructor({ one, min, max, value, multiline, rows, match, case: _case, input, ...options }: StringSchemaOptions);
|
|
62
68
|
/** Coerce a value to a string, `sanitize()` it, then enforce `match`, `min`, and `max`. */
|
|
63
69
|
validate(value?: unknown): string;
|
|
64
70
|
/**
|
|
65
71
|
* Sanitize the string by removing unwanted characters.
|
|
66
72
|
*
|
|
67
|
-
* - Uses multiline sanitization when `
|
|
73
|
+
* - Uses multiline sanitization when `multiline` is set, otherwise single-line sanitization.
|
|
68
74
|
* - Applies the configured `case` folding (`"upper"` or `"lower"`) if set.
|
|
69
75
|
*
|
|
70
76
|
* @param str String to sanitize.
|
package/schema/StringSchema.js
CHANGED
|
@@ -14,13 +14,15 @@ export class StringSchema extends Schema {
|
|
|
14
14
|
min;
|
|
15
15
|
max;
|
|
16
16
|
rows;
|
|
17
|
+
multiline;
|
|
17
18
|
match;
|
|
18
19
|
case;
|
|
19
|
-
constructor({ one = "string", min = 0, max = Number.POSITIVE_INFINITY, value = "", rows = 1, match, case: _case, input = "text", ...options }) {
|
|
20
|
+
constructor({ one = "string", min = 0, max = Number.POSITIVE_INFINITY, value = "", multiline = false, rows = multiline ? 2 : 1, match, case: _case, input = "text", ...options }) {
|
|
20
21
|
super({ one, value, ...options });
|
|
21
22
|
this.min = min;
|
|
22
23
|
this.max = max;
|
|
23
24
|
this.rows = rows;
|
|
25
|
+
this.multiline = multiline;
|
|
24
26
|
this.match = match;
|
|
25
27
|
this.case = _case;
|
|
26
28
|
this.input = input;
|
|
@@ -45,7 +47,7 @@ export class StringSchema extends Schema {
|
|
|
45
47
|
/**
|
|
46
48
|
* Sanitize the string by removing unwanted characters.
|
|
47
49
|
*
|
|
48
|
-
* - Uses multiline sanitization when `
|
|
50
|
+
* - Uses multiline sanitization when `multiline` is set, otherwise single-line sanitization.
|
|
49
51
|
* - Applies the configured `case` folding (`"upper"` or `"lower"`) if set.
|
|
50
52
|
*
|
|
51
53
|
* @param str String to sanitize.
|
|
@@ -54,7 +56,7 @@ export class StringSchema extends Schema {
|
|
|
54
56
|
* @see https://shelving.cc/schema/StringSchema/sanitize
|
|
55
57
|
*/
|
|
56
58
|
sanitize(str) {
|
|
57
|
-
const sane = this.
|
|
59
|
+
const sane = this.multiline ? sanitizeMultilineText(str) : sanitizeText(str);
|
|
58
60
|
if (this.case === "upper")
|
|
59
61
|
return sane.toUpperCase();
|
|
60
62
|
if (this.case === "lower")
|
package/schema/URISchema.js
CHANGED
package/schema/URLSchema.js
CHANGED
package/schema/UUIDSchema.js
CHANGED
|
@@ -20,7 +20,7 @@ export class UUIDSchema extends StringSchema {
|
|
|
20
20
|
...rest,
|
|
21
21
|
max, // 36 chars including hyphens (which get stripped by sanitize for appearances).
|
|
22
22
|
min: 32,
|
|
23
|
-
|
|
23
|
+
multiline: false,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/** Normalises the input into a canonical lowercase UUID (or `""` if not a valid UUID). */
|
package/ui/input/Input.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import type { ReactElement } from "react";
|
|
3
|
-
import { DateInput, FileInput, ImageInput, NumberInput, TextInput } from "shelving/ui";
|
|
3
|
+
import { DateInput, FileInput, ImageInput, NumberInput, TextareaInput, TextInput } from "shelving/ui";
|
|
4
4
|
import { PASSTHROUGH } from "shelving/util/function";
|
|
5
5
|
|
|
6
6
|
/** The props of the rendered element that the tests read. */
|
|
@@ -13,7 +13,7 @@ describe("value inputs", () => {
|
|
|
13
13
|
// React's `onChange` already fires for each native `input` event, so a second `onInput` handler would call `onValue()` twice.
|
|
14
14
|
const elements: [string, ReactElement][] = [
|
|
15
15
|
["TextInput", TextInput({ name: "x", onValue: PASSTHROUGH })],
|
|
16
|
-
["
|
|
16
|
+
["TextareaInput", TextareaInput({ name: "x", rows: 3, onValue: PASSTHROUGH })],
|
|
17
17
|
["NumberInput", NumberInput({ name: "x", onValue: PASSTHROUGH })],
|
|
18
18
|
["DateInput", DateInput({ name: "x", onValue: PASSTHROUGH })],
|
|
19
19
|
["FileInput", FileInput({ name: "x", onValue: PASSTHROUGH })],
|
|
@@ -31,7 +31,7 @@ export interface SchemaInputProps<T extends Schema, I = never> extends ValueInpu
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Show the appropriate input control for a schema, dispatching on the schema's concrete type.
|
|
34
|
-
* - Picks `DateInput`, `NumberInput`, choice radios/select, `CheckboxInput`, `TextInput`, `ArrayInput`, `DictionaryInput`, or `DataInput`.
|
|
34
|
+
* - Picks `DateInput`, `NumberInput`, choice radios/select, `CheckboxInput`, `TextInput` or `TextareaInput`, `ArrayInput`, `DictionaryInput`, or `DataInput`.
|
|
35
35
|
* - `required` defaults to whether the schema is required.
|
|
36
36
|
*
|
|
37
37
|
* @returns The matching input element for the schema.
|
|
@@ -115,10 +115,11 @@ export declare function BooleanSchemaInput({ schema, value, ...props }: BooleanS
|
|
|
115
115
|
export interface StringSchemaInputProps extends SchemaInputProps<StringSchema, unknown> {
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
* Show a `TextInput` for a `StringSchema`, sanitising and formatting values with the schema.
|
|
118
|
+
* Show a `TextInput` for a `StringSchema`, or a `TextareaInput` when the schema is `multiline`, sanitising and formatting values with the schema.
|
|
119
119
|
* - Publishes the sanitized value through `onValue`; the schema's `format()` only shapes what the input displays (on first render and on blur).
|
|
120
|
+
* - A `TextareaInput` starts at the schema's `rows` (2 by default for a multiline schema).
|
|
120
121
|
*
|
|
121
|
-
* @returns A `TextInput` element bound to the schema.
|
|
122
|
+
* @returns A `TextInput` or `TextareaInput` element bound to the schema.
|
|
122
123
|
* @kind component
|
|
123
124
|
* @example <StringSchemaInput name="email" schema={EMAIL} />
|
|
124
125
|
* @see https://shelving.cc/ui/StringSchemaInput
|
package/ui/input/SchemaInput.js
CHANGED
|
@@ -25,6 +25,7 @@ import { DateInput } from "./DateInput.js";
|
|
|
25
25
|
import { DictionaryInput } from "./DictionaryInput.js";
|
|
26
26
|
import { NumberInput } from "./NumberInput.js";
|
|
27
27
|
import { SelectInput } from "./SelectInput.js";
|
|
28
|
+
import { TextareaInput } from "./TextareaInput.js";
|
|
28
29
|
import { TextInput } from "./TextInput.js";
|
|
29
30
|
/**
|
|
30
31
|
* Whether a schema is required, i.e. not wrapped in an `OptionalSchema` or `NullableSchema`.
|
|
@@ -122,16 +123,18 @@ export function BooleanSchemaInput({ schema, value, ...props }) {
|
|
|
122
123
|
return _jsx(CheckboxInput, { ...schema, value: !!value, ...props });
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
|
-
* Show a `TextInput` for a `StringSchema`, sanitising and formatting values with the schema.
|
|
126
|
+
* Show a `TextInput` for a `StringSchema`, or a `TextareaInput` when the schema is `multiline`, sanitising and formatting values with the schema.
|
|
126
127
|
* - Publishes the sanitized value through `onValue`; the schema's `format()` only shapes what the input displays (on first render and on blur).
|
|
128
|
+
* - A `TextareaInput` starts at the schema's `rows` (2 by default for a multiline schema).
|
|
127
129
|
*
|
|
128
|
-
* @returns A `TextInput` element bound to the schema.
|
|
130
|
+
* @returns A `TextInput` or `TextareaInput` element bound to the schema.
|
|
129
131
|
* @kind component
|
|
130
132
|
* @example <StringSchemaInput name="email" schema={EMAIL} />
|
|
131
133
|
* @see https://shelving.cc/ui/StringSchemaInput
|
|
132
134
|
*/
|
|
133
135
|
export function StringSchemaInput({ schema, value, onValue, ...props }) {
|
|
134
|
-
|
|
136
|
+
const Input = schema.multiline ? TextareaInput : TextInput;
|
|
137
|
+
return (_jsx(Input, { ...schema, value: getString(value), onValue: str => onValue(str === undefined ? undefined : schema.sanitize(str)), formatter: str => schema.format(schema.sanitize(str)), ...props }));
|
|
135
138
|
}
|
|
136
139
|
/**
|
|
137
140
|
* Show an `ArrayInput` for an `ArraySchema`.
|
|
@@ -99,6 +99,22 @@ describe("StringSchemaInput", () => {
|
|
|
99
99
|
expect(URL_SCHEMA.validate(values[0])).toBe("https://example.com/path");
|
|
100
100
|
expect(currentTarget.value).toBe("example.com/path");
|
|
101
101
|
});
|
|
102
|
+
test("renders a one-row textarea when the schema is multiline", () => {
|
|
103
|
+
// `multiline` makes a `<textarea>`, and `rows` sets its first height.
|
|
104
|
+
const schema = new StringSchema({ multiline: true, rows: 1 });
|
|
105
|
+
const html = renderToStaticMarkup(<StringSchemaInput name="text" schema={schema} value="" onValue={PASSTHROUGH} />);
|
|
106
|
+
|
|
107
|
+
expect(html).toContain("<textarea");
|
|
108
|
+
expect(html).toContain('rows="1"');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("renders an input when the schema is not multiline, whatever its rows", () => {
|
|
112
|
+
const schema = new StringSchema({ rows: 3 });
|
|
113
|
+
const html = renderToStaticMarkup(<StringSchemaInput name="text" schema={schema} value="" onValue={PASSTHROUGH} />);
|
|
114
|
+
|
|
115
|
+
expect(html).toContain("<input");
|
|
116
|
+
expect(html).not.toContain("<textarea");
|
|
117
|
+
});
|
|
102
118
|
});
|
|
103
119
|
|
|
104
120
|
describe("ChoiceSchemaInput", () => {
|
package/ui/input/SchemaInput.tsx
CHANGED
|
@@ -29,6 +29,7 @@ import { DictionaryInput } from "./DictionaryInput.js";
|
|
|
29
29
|
import type { ValueInputProps } from "./Input.js";
|
|
30
30
|
import { NumberInput } from "./NumberInput.js";
|
|
31
31
|
import { SelectInput } from "./SelectInput.js";
|
|
32
|
+
import { TextareaInput } from "./TextareaInput.js";
|
|
32
33
|
import { TextInput } from "./TextInput.js";
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -54,7 +55,7 @@ export interface SchemaInputProps<T extends Schema, I = never> extends ValueInpu
|
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* Show the appropriate input control for a schema, dispatching on the schema's concrete type.
|
|
57
|
-
* - Picks `DateInput`, `NumberInput`, choice radios/select, `CheckboxInput`, `TextInput`, `ArrayInput`, `DictionaryInput`, or `DataInput`.
|
|
58
|
+
* - Picks `DateInput`, `NumberInput`, choice radios/select, `CheckboxInput`, `TextInput` or `TextareaInput`, `ArrayInput`, `DictionaryInput`, or `DataInput`.
|
|
58
59
|
* - `required` defaults to whether the schema is required.
|
|
59
60
|
*
|
|
60
61
|
* @returns The matching input element for the schema.
|
|
@@ -191,17 +192,19 @@ export function BooleanSchemaInput({ schema, value, ...props }: BooleanSchemaInp
|
|
|
191
192
|
export interface StringSchemaInputProps extends SchemaInputProps<StringSchema, unknown> {}
|
|
192
193
|
|
|
193
194
|
/**
|
|
194
|
-
* Show a `TextInput` for a `StringSchema`, sanitising and formatting values with the schema.
|
|
195
|
+
* Show a `TextInput` for a `StringSchema`, or a `TextareaInput` when the schema is `multiline`, sanitising and formatting values with the schema.
|
|
195
196
|
* - Publishes the sanitized value through `onValue`; the schema's `format()` only shapes what the input displays (on first render and on blur).
|
|
197
|
+
* - A `TextareaInput` starts at the schema's `rows` (2 by default for a multiline schema).
|
|
196
198
|
*
|
|
197
|
-
* @returns A `TextInput` element bound to the schema.
|
|
199
|
+
* @returns A `TextInput` or `TextareaInput` element bound to the schema.
|
|
198
200
|
* @kind component
|
|
199
201
|
* @example <StringSchemaInput name="email" schema={EMAIL} />
|
|
200
202
|
* @see https://shelving.cc/ui/StringSchemaInput
|
|
201
203
|
*/
|
|
202
204
|
export function StringSchemaInput({ schema, value, onValue, ...props }: StringSchemaInputProps): ReactElement {
|
|
205
|
+
const Input = schema.multiline ? TextareaInput : TextInput;
|
|
203
206
|
return (
|
|
204
|
-
<
|
|
207
|
+
<Input
|
|
205
208
|
{...schema}
|
|
206
209
|
value={getString(value)}
|
|
207
210
|
onValue={str => onValue(str === undefined ? undefined : schema.sanitize(str))}
|
package/ui/input/TextInput.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
import type { StringInputType } from "../../schema/StringSchema.js";
|
|
3
3
|
import { type InputVariants, type ValueInputProps } from "../input/Input.js";
|
|
4
|
-
|
|
4
|
+
/** Formats a string for display in a text input. */
|
|
5
|
+
export type TextFormatter = (str: string) => string;
|
|
5
6
|
/**
|
|
6
|
-
* Props for `TextInput`, a single-
|
|
7
|
+
* Props for `TextInput`, a single-line text input bound to a `string` value.
|
|
7
8
|
*
|
|
8
9
|
* @see https://shelving.cc/ui/TextInputProps
|
|
9
10
|
*/
|
|
10
11
|
export interface TextInputProps extends ValueInputProps<string>, InputVariants {
|
|
11
|
-
rows?: number | undefined;
|
|
12
|
-
multiline?: boolean;
|
|
13
12
|
input?: StringInputType;
|
|
14
13
|
min?: number | undefined;
|
|
15
14
|
max?: number | undefined;
|
|
@@ -17,14 +16,12 @@ export interface TextInputProps extends ValueInputProps<string>, InputVariants {
|
|
|
17
16
|
formatter?: TextFormatter | undefined;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
19
|
+
* Single-line text input bound to a `string` value, rendered as an `<input>`. Use `TextareaInput` for multiline text.
|
|
21
20
|
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
22
|
-
* - Multiline mode auto-grows the textarea to fit its content.
|
|
23
21
|
*
|
|
24
|
-
* @returns A text `<input>`
|
|
22
|
+
* @returns A text `<input>` element.
|
|
25
23
|
* @example <TextInput name="name" value={name} onValue={setName} />
|
|
26
24
|
* @see https://shelving.cc/ui/TextInput
|
|
27
25
|
*/
|
|
28
26
|
export declare function TextInput({ name, title, placeholder, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
|
|
29
|
-
required, disabled, message, value, onValue, input, min, max,
|
|
30
|
-
export {};
|
|
27
|
+
required, disabled, message, value, onValue, input, min, max, formatter, className, ...variants }: TextInputProps): ReactElement;
|
package/ui/input/TextInput.js
CHANGED
|
@@ -4,39 +4,20 @@ import { getInputClass } from "../input/Input.js";
|
|
|
4
4
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
5
5
|
import INPUT_CSS from "./Input.module.css";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Single-line text input bound to a `string` value, rendered as an `<input>`. Use `TextareaInput` for multiline text.
|
|
8
8
|
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
9
|
-
* - Multiline mode auto-grows the textarea to fit its content.
|
|
10
9
|
*
|
|
11
|
-
* @returns A text `<input>`
|
|
10
|
+
* @returns A text `<input>` element.
|
|
12
11
|
* @example <TextInput name="name" value={name} onValue={setName} />
|
|
13
12
|
* @see https://shelving.cc/ui/TextInput
|
|
14
13
|
*/
|
|
15
14
|
export function TextInput({ name, title = "", placeholder = title, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
|
|
16
|
-
required = false, disabled = false, message = "", value, onValue, input = "text", min = 0, max = Number.POSITIVE_INFINITY,
|
|
15
|
+
required = false, disabled = false, message = "", value, onValue, input = "text", min = 0, max = Number.POSITIVE_INFINITY, formatter = PASSTHROUGH, className, ...variants }) {
|
|
17
16
|
const onBlur = ({ currentTarget }) => {
|
|
18
17
|
currentTarget.value = formatter(currentTarget.value);
|
|
19
18
|
};
|
|
20
|
-
if (rows > 1) {
|
|
21
|
-
const onChange = (e) => {
|
|
22
|
-
onValue?.(e.currentTarget.value);
|
|
23
|
-
_resize(e.currentTarget, rows);
|
|
24
|
-
};
|
|
25
|
-
return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, style: { "--input-rows": rows }, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
26
|
-
}
|
|
27
19
|
const onChange = (e) => {
|
|
28
20
|
onValue?.(e.currentTarget.value);
|
|
29
21
|
};
|
|
30
22
|
return (_jsx("input", { name: name, type: input, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
31
23
|
}
|
|
32
|
-
/**
|
|
33
|
-
* @todo This can be removed when Firefox supports `field-sizing:` in CSS.
|
|
34
|
-
* https://caniuse.com/wf-field-sizing
|
|
35
|
-
*/
|
|
36
|
-
function _resize(el, minRows) {
|
|
37
|
-
if (el && !CSS.supports("field-sizing", "content")) {
|
|
38
|
-
el.rows = minRows;
|
|
39
|
-
while (el.scrollHeight > el.clientHeight)
|
|
40
|
-
el.rows++;
|
|
41
|
-
}
|
|
42
|
-
}
|
package/ui/input/TextInput.tsx
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReactElement, SyntheticEvent } from "react";
|
|
2
2
|
import type { StringInputType } from "../../schema/StringSchema.js";
|
|
3
3
|
import { PASSTHROUGH } from "../../util/function.js";
|
|
4
4
|
import { getInputClass, type InputVariants, type ValueInputProps } from "../input/Input.js";
|
|
5
5
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
6
6
|
import INPUT_CSS from "./Input.module.css";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** Formats a string for display in a text input. */
|
|
9
|
+
export type TextFormatter = (str: string) => string;
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* Props for `TextInput`, a single-
|
|
12
|
+
* Props for `TextInput`, a single-line text input bound to a `string` value.
|
|
12
13
|
*
|
|
13
14
|
* @see https://shelving.cc/ui/TextInputProps
|
|
14
15
|
*/
|
|
15
16
|
export interface TextInputProps extends ValueInputProps<string>, InputVariants {
|
|
16
|
-
rows?: number | undefined;
|
|
17
|
-
multiline?: boolean;
|
|
18
17
|
input?: StringInputType;
|
|
19
18
|
min?: number | undefined;
|
|
20
19
|
max?: number | undefined;
|
|
@@ -23,11 +22,10 @@ export interface TextInputProps extends ValueInputProps<string>, InputVariants {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Single-line text input bound to a `string` value, rendered as an `<input>`. Use `TextareaInput` for multiline text.
|
|
27
26
|
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
28
|
-
* - Multiline mode auto-grows the textarea to fit its content.
|
|
29
27
|
*
|
|
30
|
-
* @returns A text `<input>`
|
|
28
|
+
* @returns A text `<input>` element.
|
|
31
29
|
* @example <TextInput name="name" value={name} onValue={setName} />
|
|
32
30
|
* @see https://shelving.cc/ui/TextInput
|
|
33
31
|
*/
|
|
@@ -43,46 +41,16 @@ export function TextInput({
|
|
|
43
41
|
input = "text",
|
|
44
42
|
min = 0,
|
|
45
43
|
max = Number.POSITIVE_INFINITY,
|
|
46
|
-
rows = 1,
|
|
47
44
|
formatter = PASSTHROUGH,
|
|
48
45
|
className,
|
|
49
46
|
...variants
|
|
50
47
|
}: TextInputProps): ReactElement {
|
|
51
|
-
const onBlur = ({ currentTarget }: SyntheticEvent<HTMLInputElement
|
|
48
|
+
const onBlur = ({ currentTarget }: SyntheticEvent<HTMLInputElement>) => {
|
|
52
49
|
currentTarget.value = formatter(currentTarget.value);
|
|
53
50
|
};
|
|
54
|
-
|
|
55
|
-
if (rows > 1) {
|
|
56
|
-
const onChange = (e: SyntheticEvent<HTMLTextAreaElement>) => {
|
|
57
|
-
onValue?.(e.currentTarget.value);
|
|
58
|
-
_resize(e.currentTarget, rows);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<textarea
|
|
63
|
-
ref={el => void (el && _resize(el, rows))}
|
|
64
|
-
name={name}
|
|
65
|
-
defaultValue={value !== undefined ? formatter(value) : ""}
|
|
66
|
-
minLength={Number.isFinite(min) ? min : 0}
|
|
67
|
-
maxLength={Number.isFinite(max) ? max : undefined}
|
|
68
|
-
rows={rows}
|
|
69
|
-
style={{ "--input-rows": rows } as CSSProperties}
|
|
70
|
-
required={required && min > 0}
|
|
71
|
-
disabled={disabled}
|
|
72
|
-
placeholder={placeholder || " "}
|
|
73
|
-
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className)}
|
|
74
|
-
onChange={onChange}
|
|
75
|
-
onBlur={onBlur}
|
|
76
|
-
title={message}
|
|
77
|
-
aria-invalid={!!message}
|
|
78
|
-
/>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
51
|
const onChange = (e: SyntheticEvent<HTMLInputElement>) => {
|
|
83
52
|
onValue?.(e.currentTarget.value);
|
|
84
53
|
};
|
|
85
|
-
|
|
86
54
|
return (
|
|
87
55
|
<input
|
|
88
56
|
name={name}
|
|
@@ -101,14 +69,3 @@ export function TextInput({
|
|
|
101
69
|
/>
|
|
102
70
|
);
|
|
103
71
|
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @todo This can be removed when Firefox supports `field-sizing:` in CSS.
|
|
107
|
-
* https://caniuse.com/wf-field-sizing
|
|
108
|
-
*/
|
|
109
|
-
function _resize(el: HTMLTextAreaElement, minRows: number): void {
|
|
110
|
-
if (el && !CSS.supports("field-sizing", "content")) {
|
|
111
|
-
el.rows = minRows;
|
|
112
|
-
while (el.scrollHeight > el.clientHeight) el.rows++;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { type InputVariants, type ValueInputProps } from "../input/Input.js";
|
|
3
|
+
import type { TextFormatter } from "./TextInput.js";
|
|
4
|
+
/**
|
|
5
|
+
* Props for `TextareaInput`, a multiline text input bound to a `string` value.
|
|
6
|
+
*
|
|
7
|
+
* @see https://shelving.cc/ui/TextareaInputProps
|
|
8
|
+
*/
|
|
9
|
+
export interface TextareaInputProps extends ValueInputProps<string>, InputVariants {
|
|
10
|
+
/**
|
|
11
|
+
* Rows the textarea shows at first (its minimum height). It grows to fit its content.
|
|
12
|
+
* @default 2
|
|
13
|
+
*/
|
|
14
|
+
rows?: number | undefined;
|
|
15
|
+
min?: number | undefined;
|
|
16
|
+
max?: number | undefined;
|
|
17
|
+
/** Optional formatter — when provided the value is reformatted on blur and when initially displayed (the value published through `onValue` is never formatted). */
|
|
18
|
+
formatter?: TextFormatter | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Multiline text input bound to a `string` value, rendered as a `<textarea>` that grows to fit its content.
|
|
22
|
+
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
23
|
+
*
|
|
24
|
+
* @returns A `<textarea>` element.
|
|
25
|
+
* @example <TextareaInput name="bio" rows={4} value={bio} onValue={setBio} />
|
|
26
|
+
* @see https://shelving.cc/ui/TextareaInput
|
|
27
|
+
*/
|
|
28
|
+
export declare function TextareaInput({ name, title, placeholder, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
|
|
29
|
+
required, disabled, message, value, onValue, min, max, rows, formatter, className, ...variants }: TextareaInputProps): ReactElement;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PASSTHROUGH } from "../../util/function.js";
|
|
3
|
+
import { getInputClass } from "../input/Input.js";
|
|
4
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
5
|
+
import INPUT_CSS from "./Input.module.css";
|
|
6
|
+
/**
|
|
7
|
+
* Multiline text input bound to a `string` value, rendered as a `<textarea>` that grows to fit its content.
|
|
8
|
+
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
9
|
+
*
|
|
10
|
+
* @returns A `<textarea>` element.
|
|
11
|
+
* @example <TextareaInput name="bio" rows={4} value={bio} onValue={setBio} />
|
|
12
|
+
* @see https://shelving.cc/ui/TextareaInput
|
|
13
|
+
*/
|
|
14
|
+
export function TextareaInput({ name, title = "", placeholder = title, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
|
|
15
|
+
required = false, disabled = false, message = "", value, onValue, min = 0, max = Number.POSITIVE_INFINITY, rows = 2, formatter = PASSTHROUGH, className, ...variants }) {
|
|
16
|
+
const onBlur = ({ currentTarget }) => {
|
|
17
|
+
currentTarget.value = formatter(currentTarget.value);
|
|
18
|
+
};
|
|
19
|
+
const onChange = (e) => {
|
|
20
|
+
onValue?.(e.currentTarget.value);
|
|
21
|
+
_resize(e.currentTarget, rows);
|
|
22
|
+
};
|
|
23
|
+
return (_jsx("textarea", { ref: el => void (el && _resize(el, rows)), name: name, defaultValue: value !== undefined ? formatter(value) : "", minLength: Number.isFinite(min) ? min : 0, maxLength: Number.isFinite(max) ? max : undefined, rows: rows, style: { "--input-rows": rows }, required: required && min > 0, disabled: disabled, placeholder: placeholder || " ", className: getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className), onChange: onChange, onBlur: onBlur, title: message, "aria-invalid": !!message }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @todo This can be removed when Firefox supports `field-sizing:` in CSS.
|
|
27
|
+
* https://caniuse.com/wf-field-sizing
|
|
28
|
+
*/
|
|
29
|
+
function _resize(el, minRows) {
|
|
30
|
+
if (el && !CSS.supports("field-sizing", "content")) {
|
|
31
|
+
el.rows = minRows;
|
|
32
|
+
while (el.scrollHeight > el.clientHeight)
|
|
33
|
+
el.rows++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement, SyntheticEvent } from "react";
|
|
2
|
+
import { PASSTHROUGH } from "../../util/function.js";
|
|
3
|
+
import { getInputClass, type InputVariants, type ValueInputProps } from "../input/Input.js";
|
|
4
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
5
|
+
import INPUT_CSS from "./Input.module.css";
|
|
6
|
+
import type { TextFormatter } from "./TextInput.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Props for `TextareaInput`, a multiline text input bound to a `string` value.
|
|
10
|
+
*
|
|
11
|
+
* @see https://shelving.cc/ui/TextareaInputProps
|
|
12
|
+
*/
|
|
13
|
+
export interface TextareaInputProps extends ValueInputProps<string>, InputVariants {
|
|
14
|
+
/**
|
|
15
|
+
* Rows the textarea shows at first (its minimum height). It grows to fit its content.
|
|
16
|
+
* @default 2
|
|
17
|
+
*/
|
|
18
|
+
rows?: number | undefined;
|
|
19
|
+
min?: number | undefined;
|
|
20
|
+
max?: number | undefined;
|
|
21
|
+
/** Optional formatter — when provided the value is reformatted on blur and when initially displayed (the value published through `onValue` is never formatted). */
|
|
22
|
+
formatter?: TextFormatter | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Multiline text input bound to a `string` value, rendered as a `<textarea>` that grows to fit its content.
|
|
27
|
+
* - Applies an optional `formatter` on initial display and on blur — the raw typed value is published through `onValue`.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `<textarea>` element.
|
|
30
|
+
* @example <TextareaInput name="bio" rows={4} value={bio} onValue={setBio} />
|
|
31
|
+
* @see https://shelving.cc/ui/TextareaInput
|
|
32
|
+
*/
|
|
33
|
+
export function TextareaInput({
|
|
34
|
+
name,
|
|
35
|
+
title = "",
|
|
36
|
+
placeholder = title, // Placeholder must be defined or `:placeholder-shown` CSS rules won't show.
|
|
37
|
+
required = false,
|
|
38
|
+
disabled = false,
|
|
39
|
+
message = "",
|
|
40
|
+
value,
|
|
41
|
+
onValue,
|
|
42
|
+
min = 0,
|
|
43
|
+
max = Number.POSITIVE_INFINITY,
|
|
44
|
+
rows = 2,
|
|
45
|
+
formatter = PASSTHROUGH,
|
|
46
|
+
className,
|
|
47
|
+
...variants
|
|
48
|
+
}: TextareaInputProps): ReactElement {
|
|
49
|
+
const onBlur = ({ currentTarget }: SyntheticEvent<HTMLTextAreaElement>) => {
|
|
50
|
+
currentTarget.value = formatter(currentTarget.value);
|
|
51
|
+
};
|
|
52
|
+
const onChange = (e: SyntheticEvent<HTMLTextAreaElement>) => {
|
|
53
|
+
onValue?.(e.currentTarget.value);
|
|
54
|
+
_resize(e.currentTarget, rows);
|
|
55
|
+
};
|
|
56
|
+
return (
|
|
57
|
+
<textarea
|
|
58
|
+
ref={el => void (el && _resize(el, rows))}
|
|
59
|
+
name={name}
|
|
60
|
+
defaultValue={value !== undefined ? formatter(value) : ""}
|
|
61
|
+
minLength={Number.isFinite(min) ? min : 0}
|
|
62
|
+
maxLength={Number.isFinite(max) ? max : undefined}
|
|
63
|
+
rows={rows}
|
|
64
|
+
style={{ "--input-rows": rows } as CSSProperties}
|
|
65
|
+
required={required && min > 0}
|
|
66
|
+
disabled={disabled}
|
|
67
|
+
placeholder={placeholder || " "}
|
|
68
|
+
className={getClass(getInputClass(variants), getModuleClass(INPUT_CSS, "text"), getModuleClass(INPUT_CSS, "multiline"), className)}
|
|
69
|
+
onChange={onChange}
|
|
70
|
+
onBlur={onBlur}
|
|
71
|
+
title={message}
|
|
72
|
+
aria-invalid={!!message}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @todo This can be removed when Firefox supports `field-sizing:` in CSS.
|
|
79
|
+
* https://caniuse.com/wf-field-sizing
|
|
80
|
+
*/
|
|
81
|
+
function _resize(el: HTMLTextAreaElement, minRows: number): void {
|
|
82
|
+
if (el && !CSS.supports("field-sizing", "content")) {
|
|
83
|
+
el.rows = minRows;
|
|
84
|
+
while (el.scrollHeight > el.clientHeight) el.rows++;
|
|
85
|
+
}
|
|
86
|
+
}
|
package/ui/input/index.d.ts
CHANGED
package/ui/input/index.js
CHANGED
package/ui/input/index.ts
CHANGED
package/ui/notice/Notices.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
2
|
import { type FlexVariants } from "../style/Flex.js";
|
|
3
3
|
import type { ClassProps } from "../util/props.js";
|
|
4
|
-
import "./NoticesTransition.css";
|
|
5
4
|
/**
|
|
6
5
|
* Corner of the screen where `<Notices>` shows the list of notices.
|
|
7
6
|
*
|
package/ui/notice/Notices.js
CHANGED
|
@@ -5,9 +5,9 @@ import { useTransitionValue } from "../transition/useTransitionValue.js";
|
|
|
5
5
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
6
6
|
import { subscribeNotices } from "../util/notice.js";
|
|
7
7
|
import { Notice } from "./Notice.js";
|
|
8
|
-
import "./NoticesTransition.css";
|
|
9
8
|
import NOTICES_CSS from "./Notices.module.css";
|
|
10
9
|
import { NOTICES } from "./NoticesStore.js";
|
|
10
|
+
import NOTICES_TRANSITION_CSS from "./NoticesTransition.module.css";
|
|
11
11
|
const NOTICES_CLASS = getModuleClass(NOTICES_CSS, "notices");
|
|
12
12
|
/**
|
|
13
13
|
* Render the global list of notices and subscribe to incoming `"notice"` events.
|
|
@@ -36,5 +36,5 @@ function NoticeItem({ notice, position }) {
|
|
|
36
36
|
const { children, status } = useTransitionValue(notice);
|
|
37
37
|
// New and closed notices slide from the side of the corner. A notice that changes in place is drawn from the corner itself.
|
|
38
38
|
const side = position.endsWith("left") ? "left" : "right";
|
|
39
|
-
return (_jsx(ViewTransition, { enter: `notice-${side}
|
|
39
|
+
return (_jsx(ViewTransition, { enter: getModuleClass(NOTICES_TRANSITION_CSS, `notice-${side}`), exit: getModuleClass(NOTICES_TRANSITION_CSS, `notice-${side}`), update: getModuleClass(NOTICES_TRANSITION_CSS, `notice-update-${position}`), children: _jsx(Notice, { status: status, children: children }) }));
|
|
40
40
|
}
|
package/ui/notice/Notices.tsx
CHANGED
|
@@ -7,9 +7,9 @@ import { subscribeNotices } from "../util/notice.js";
|
|
|
7
7
|
import type { ClassProps } from "../util/props.js";
|
|
8
8
|
import { Notice } from "./Notice.js";
|
|
9
9
|
import type { NoticeStore } from "./NoticeStore.js";
|
|
10
|
-
import "./NoticesTransition.css";
|
|
11
10
|
import NOTICES_CSS from "./Notices.module.css";
|
|
12
11
|
import { NOTICES } from "./NoticesStore.js";
|
|
12
|
+
import NOTICES_TRANSITION_CSS from "./NoticesTransition.module.css";
|
|
13
13
|
|
|
14
14
|
const NOTICES_CLASS = getModuleClass(NOTICES_CSS, "notices");
|
|
15
15
|
|
|
@@ -68,7 +68,11 @@ function NoticeItem({ notice, position }: { notice: NoticeStore<Status>; positio
|
|
|
68
68
|
// New and closed notices slide from the side of the corner. A notice that changes in place is drawn from the corner itself.
|
|
69
69
|
const side = position.endsWith("left") ? "left" : "right";
|
|
70
70
|
return (
|
|
71
|
-
<ViewTransition
|
|
71
|
+
<ViewTransition
|
|
72
|
+
enter={getModuleClass(NOTICES_TRANSITION_CSS, `notice-${side}`)}
|
|
73
|
+
exit={getModuleClass(NOTICES_TRANSITION_CSS, `notice-${side}`)}
|
|
74
|
+
update={getModuleClass(NOTICES_TRANSITION_CSS, `notice-update-${position}`)}
|
|
75
|
+
>
|
|
72
76
|
<Notice status={status}>{children}</Notice>
|
|
73
77
|
</ViewTransition>
|
|
74
78
|
);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* Global CSS, not a CSS module. Bun hashes a class inside `::view-transition-*()` from the file basename, but hashes the exported names from the file path, so a module-scoped view-transition class can never match the name that JS passes to `view-transition-class`. Keep these names global until Bun fixes this — see dhoulb/shelving#325. */
|
|
2
1
|
@import url("../style/layers.css");
|
|
3
2
|
@import url("../style/Duration.module.css");
|
|
4
3
|
|
|
@@ -32,21 +31,36 @@
|
|
|
32
31
|
/*
|
|
33
32
|
* A new notice slides in from the side of its corner, and a closed notice slides out to that side.
|
|
34
33
|
* - `:only-child` stops Safari from also starting the animation on the missing image, which stops it later on the real one (see `FadeTransition.css`).
|
|
34
|
+
* - Longhands, not the `animation` shorthand: Bun rewrites `animation-name` to the hashed keyframes name but leaves a shorthand that holds a `var()` untouched.
|
|
35
35
|
*/
|
|
36
36
|
::view-transition-new(.notice-left):only-child {
|
|
37
|
-
animation: notice-from-left
|
|
37
|
+
animation-name: notice-from-left;
|
|
38
|
+
animation-duration: var(--notices-transition-duration);
|
|
39
|
+
animation-timing-function: ease-out;
|
|
40
|
+
animation-fill-mode: both;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
::view-transition-old(.notice-left):only-child {
|
|
41
|
-
animation: notice-from-left
|
|
44
|
+
animation-name: notice-from-left;
|
|
45
|
+
animation-duration: var(--notices-transition-duration);
|
|
46
|
+
animation-timing-function: ease-in;
|
|
47
|
+
animation-direction: reverse;
|
|
48
|
+
animation-fill-mode: both;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
::view-transition-new(.notice-right):only-child {
|
|
45
|
-
animation: notice-from-right
|
|
52
|
+
animation-name: notice-from-right;
|
|
53
|
+
animation-duration: var(--notices-transition-duration);
|
|
54
|
+
animation-timing-function: ease-out;
|
|
55
|
+
animation-fill-mode: both;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
::view-transition-old(.notice-right):only-child {
|
|
49
|
-
animation: notice-from-right
|
|
59
|
+
animation-name: notice-from-right;
|
|
60
|
+
animation-duration: var(--notices-transition-duration);
|
|
61
|
+
animation-timing-function: ease-in;
|
|
62
|
+
animation-direction: reverse;
|
|
63
|
+
animation-fill-mode: both;
|
|
50
64
|
}
|
|
51
65
|
|
|
52
66
|
/* The other notices move to their new places (the default group morph). */
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import "
|
|
2
|
+
import { getModuleClass } from "../util/css.js";
|
|
3
|
+
import COLLAPSE_TRANSITION_CSS from "./CollapseTransition.module.css";
|
|
3
4
|
import { Transition } from "./Transition.js";
|
|
5
|
+
const COLLAPSE_TRANSITION_CLASS = getModuleClass(COLLAPSE_TRANSITION_CSS, "collapse");
|
|
4
6
|
/**
|
|
5
7
|
* Transition that collapses its children in and out by animating their size.
|
|
6
8
|
*
|
|
@@ -8,5 +10,5 @@ import { Transition } from "./Transition.js";
|
|
|
8
10
|
* @see https://shelving.cc/ui/CollapseTransition
|
|
9
11
|
*/
|
|
10
12
|
export function CollapseTransition(props) {
|
|
11
|
-
return _jsx(Transition, { default:
|
|
13
|
+
return _jsx(Transition, { default: COLLAPSE_TRANSITION_CLASS, ...props });
|
|
12
14
|
}
|
|
@@ -24,6 +24,6 @@ function Details({ open }: { open: boolean }) {
|
|
|
24
24
|
|
|
25
25
|
## Styling
|
|
26
26
|
|
|
27
|
-
This preset exposes no own `--collapse-transition-*` hooks. Its `CollapseTransition.css` only sets `overflow: hidden` on `::view-transition-image-pair(.collapse)` so the collapsing content is clipped.
|
|
27
|
+
This preset exposes no own `--collapse-transition-*` hooks. Its `CollapseTransition.module.css` only sets `overflow: hidden` on `::view-transition-image-pair(.collapse)` so the collapsing content is clipped.
|
|
28
28
|
|
|
29
29
|
**Global tokens it reads** — none.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* Global CSS, not a CSS module. Bun hashes a class inside `::view-transition-*()` from the file basename, but hashes the exported names from the file path, so a module-scoped view-transition class can never match the name that JS passes to `view-transition-class`. Keep these names global until Bun fixes this — see dhoulb/shelving#325. */
|
|
2
1
|
::view-transition-image-pair(.collapse) {
|
|
3
2
|
overflow: hidden;
|
|
4
3
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
-
import "
|
|
2
|
+
import { getModuleClass } from "../util/css.js";
|
|
3
|
+
import COLLAPSE_TRANSITION_CSS from "./CollapseTransition.module.css";
|
|
3
4
|
import { Transition, type TransitionProps } from "./Transition.js";
|
|
4
5
|
|
|
6
|
+
const COLLAPSE_TRANSITION_CLASS = getModuleClass(COLLAPSE_TRANSITION_CSS, "collapse");
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Props for the `CollapseTransition` component — the shared transition variant props.
|
|
7
10
|
*
|
|
@@ -16,5 +19,5 @@ export interface CollapseTransitionProps extends TransitionProps {}
|
|
|
16
19
|
* @see https://shelving.cc/ui/CollapseTransition
|
|
17
20
|
*/
|
|
18
21
|
export function CollapseTransition(props: CollapseTransitionProps): ReactElement {
|
|
19
|
-
return <Transition default=
|
|
22
|
+
return <Transition default={COLLAPSE_TRANSITION_CLASS} {...props} />;
|
|
20
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@import url("../style/layers.css");
|
|
2
2
|
@import url("../style/Duration.module.css");
|
|
3
3
|
|
|
4
|
-
/* Global CSS, not a CSS module — see
|
|
4
|
+
/* Global CSS, not a CSS module yet — see dhoulb/shelving#259. */
|
|
5
5
|
@layer defaults {
|
|
6
6
|
:root {
|
|
7
7
|
/* A percentage is of the snapshot's own size, so the old and new content sit edge to edge and never overlap. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
2
|
import type { ChildProps } from "../util/props.js";
|
|
3
|
-
import "./Transition.css";
|
|
4
3
|
/**
|
|
5
4
|
* Variant props shared by every transition component.
|
|
6
5
|
*
|
|
@@ -28,7 +27,7 @@ export interface TransitionProps extends ChildProps, TransitionVariants {
|
|
|
28
27
|
*
|
|
29
28
|
* - Allows known view transition types in `TransitionClasses` (`default`/`forward`/`back`) to be overridden.
|
|
30
29
|
* - These must correspond to a `::view-transition(.className)` that is set in CSS.
|
|
31
|
-
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.css`.
|
|
30
|
+
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.module.css`.
|
|
32
31
|
*
|
|
33
32
|
* @kind component
|
|
34
33
|
* @returns A `<ViewTransition>` element wrapping the children.
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/// <reference types="react/canary" />
|
|
3
3
|
import { ViewTransition } from "react";
|
|
4
|
-
import { getClass } from "../util/css.js";
|
|
5
|
-
import "./Transition.css";
|
|
6
|
-
|
|
7
|
-
const TRANSITION_OVERLAY_CLASS = "overlay";
|
|
4
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
5
|
+
import TRANSITION_CSS from "./Transition.module.css";
|
|
6
|
+
const TRANSITION_OVERLAY_CLASS = getModuleClass(TRANSITION_CSS, "overlay");
|
|
8
7
|
/**
|
|
9
8
|
* Wrap children in a React View Transition, applying the configured transition classes.
|
|
10
9
|
*
|
|
11
10
|
* - Allows known view transition types in `TransitionClasses` (`default`/`forward`/`back`) to be overridden.
|
|
12
11
|
* - These must correspond to a `::view-transition(.className)` that is set in CSS.
|
|
13
|
-
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.css`.
|
|
12
|
+
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.module.css`.
|
|
14
13
|
*
|
|
15
14
|
* @kind component
|
|
16
15
|
* @returns A `<ViewTransition>` element wrapping the children.
|
|
@@ -5,7 +5,7 @@ The base View Transition wrapper. It wraps its children in React 19's `<ViewTran
|
|
|
5
5
|
**Things to know:**
|
|
6
6
|
|
|
7
7
|
- Set `default` for the base transition; `forward` and `back` default to it and let you pick a direction-aware variant. The class names must correspond to `::view-transition-old(.className)` / `::view-transition-new(.className)` rules in your CSS.
|
|
8
|
-
- Pass `overlay` to raise the transition group above surrounding content during the animation (`z-index: 100`, from `Transition.css`).
|
|
8
|
+
- Pass `overlay` to raise the transition group above surrounding content during the animation (`z-index: 100`, from `Transition.module.css`).
|
|
9
9
|
- Direction is driven by the active view-transition type. `<Navigation>` sets it for each page change (`"forward"` for a link or `NavigationStore.forward()`, `"back"` for the browser back button). For any other change, call `setTransitionType("forward")` (or `"back"`) inside a `startTransition()` callback; the variants read that type to choose the correct slide.
|
|
10
10
|
- React runs a view transition only for a transition update (`startTransition()`, `useDeferredValue()` or a Suspense reveal). A sync update, for example a `useStore()` change, swaps the content with no animation.
|
|
11
11
|
- The preset variants honour `prefers-reduced-motion: reduce` — positional movement (slides, collapse) is removed while opacity-only fades are kept (see each preset's page). Custom transition classes should ship their own `@media (prefers-reduced-motion: reduce)` override; `animation: none` on the `::view-transition-*` pseudo-elements makes the swap an instant cut while the DOM update still happens.
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/// <reference types="react/canary" />
|
|
2
2
|
import { type ReactElement, ViewTransition } from "react";
|
|
3
|
-
import { getClass } from "../util/css.js";
|
|
3
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
4
4
|
import type { ChildProps } from "../util/props.js";
|
|
5
|
-
import "./Transition.css";
|
|
5
|
+
import TRANSITION_CSS from "./Transition.module.css";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const TRANSITION_OVERLAY_CLASS = "overlay";
|
|
7
|
+
const TRANSITION_OVERLAY_CLASS = getModuleClass(TRANSITION_CSS, "overlay");
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Variant props shared by every transition component.
|
|
@@ -36,7 +35,7 @@ export interface TransitionProps extends ChildProps, TransitionVariants {
|
|
|
36
35
|
*
|
|
37
36
|
* - Allows known view transition types in `TransitionClasses` (`default`/`forward`/`back`) to be overridden.
|
|
38
37
|
* - These must correspond to a `::view-transition(.className)` that is set in CSS.
|
|
39
|
-
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.css`.
|
|
38
|
+
* - Supports variant classes, e.g. `<Transition overlay>` applies `::view-transition-group(.overlay)` from `Transition.module.css`.
|
|
40
39
|
*
|
|
41
40
|
* @kind component
|
|
42
41
|
* @returns A `<ViewTransition>` element wrapping the children.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@import url("../style/layers.css");
|
|
2
2
|
@import url("../style/Duration.module.css");
|
|
3
3
|
|
|
4
|
-
/* Global CSS, not a CSS module — see
|
|
4
|
+
/* Global CSS, not a CSS module yet — see dhoulb/shelving#259. */
|
|
5
5
|
@layer defaults {
|
|
6
6
|
:root {
|
|
7
7
|
/* A percentage is of the snapshot's own size, so the old and new content sit edge to edge and never overlap. */
|
package/ui/util/css.test.ts
CHANGED
|
@@ -58,18 +58,17 @@ describe("Bun CSS modules", () => {
|
|
|
58
58
|
expect(css).toContain(`animation-name: ${name};`);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
// Before Bun 1.4.3, Bun hashed a class inside `::view-transition-*()` from the file basename but hashed exports from the path, so the two never matched
|
|
62
|
-
test("
|
|
61
|
+
// Before Bun 1.4.3, Bun hashed a class inside `::view-transition-*()` from the file basename but hashed exports from the path, so the two never matched (see dhoulb/shelving#325).
|
|
62
|
+
test("exports a view-transition class with the same hash as its selector", async () => {
|
|
63
63
|
const dir = await mkdtemp(join(tmpdir(), "shelving-css-"));
|
|
64
64
|
try {
|
|
65
65
|
const path = join(dir, "sub", "canary.module.css");
|
|
66
|
-
await Bun.write(path, ".plain { color: red; }\n
|
|
66
|
+
await Bun.write(path, ".plain { color: red; }\n::view-transition-group(.vt) { z-index: 1; }\n");
|
|
67
67
|
const { exports, css } = await _bundle(path);
|
|
68
68
|
expect(exports.plain).toBeString();
|
|
69
69
|
expect(exports.vt).toBeString();
|
|
70
70
|
expect(css).toContain(`.${exports.plain}`);
|
|
71
|
-
|
|
72
|
-
else expect(css).not.toContain(`(.${exports.vt})`);
|
|
71
|
+
expect(css).toContain(`(.${exports.vt})`);
|
|
73
72
|
} finally {
|
|
74
73
|
await rm(dir, { recursive: true, force: true });
|
|
75
74
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/* Global CSS, not a CSS module. Bun hashes a class inside `::view-transition-*()` from the file basename, but hashes the exported names from the file path, so a module-scoped view-transition class can never match the name that JS passes to `view-transition-class`. Keep these names global until Bun fixes this — see dhoulb/shelving#325. */
|
|
2
|
-
::view-transition-group(.overlay) {
|
|
3
|
-
z-index: 100;
|
|
4
|
-
}
|