shelving 1.300.0 → 1.301.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 +2 -2
- package/ui/input/ImageInput.d.ts +27 -0
- package/ui/input/ImageInput.js +49 -0
- package/ui/input/ImageInput.md +48 -0
- package/ui/input/ImageInput.module.css +79 -0
- package/ui/input/ImageInput.tsx +100 -0
- package/ui/input/Input.module.css +10 -1
- package/ui/input/Input.test.tsx +33 -1
- package/ui/input/TextInput.js +1 -1
- package/ui/input/TextInput.tsx +2 -1
- 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.301.1",
|
|
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": [
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { FileTypes } from "../../util/file.js";
|
|
3
|
+
import { type BlockVariants } from "../style/Block.js";
|
|
4
|
+
import type { ValueInputProps } from "./Input.js";
|
|
5
|
+
/**
|
|
6
|
+
* Props for `<ImageInput>`, a square image picker that emits the picked `File`.
|
|
7
|
+
*
|
|
8
|
+
* @see https://shelving.cc/ui/ImageInputProps
|
|
9
|
+
*/
|
|
10
|
+
export interface ImageInputProps extends ValueInputProps<File, string>, BlockVariants {
|
|
11
|
+
/**
|
|
12
|
+
* The image types the picker accepts.
|
|
13
|
+
* @default { jpg: "image/jpeg", png: "image/png", webp: "image/webp", gif: "image/gif" }
|
|
14
|
+
*/
|
|
15
|
+
types?: FileTypes | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Square image picker that shows the picked image in the square.
|
|
19
|
+
* - With no image, the square shows a "Choose…" button in the middle (change it with `placeholder`).
|
|
20
|
+
* - With an image, the image fills the square and an X button in the corner clears it (`onValue(undefined)`).
|
|
21
|
+
* - A tap anywhere on the square opens the file picker.
|
|
22
|
+
* - `value` is a picked `File`, or the URL of the current image.
|
|
23
|
+
*
|
|
24
|
+
* @kind component
|
|
25
|
+
* @see https://shelving.cc/ui/ImageInput
|
|
26
|
+
*/
|
|
27
|
+
export declare function ImageInput({ name, title, placeholder, required, disabled, message, value, onValue, types, className, ...variants }: ImageInputProps): ReactElement;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { XMarkIcon } from "@heroicons/react/24/solid";
|
|
3
|
+
import { useEffect, useMemo } from "react";
|
|
4
|
+
import { getButtonClass } from "../button/Button.js";
|
|
5
|
+
import { getBlockClass } from "../style/Block.js";
|
|
6
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
7
|
+
import IMAGE_INPUT_CSS from "./ImageInput.module.css";
|
|
8
|
+
const IMAGE_INPUT_CLASS = getModuleClass(IMAGE_INPUT_CSS, "image-input");
|
|
9
|
+
const IMAGE_INPUT_PICKER_CLASS = getModuleClass(IMAGE_INPUT_CSS, "picker");
|
|
10
|
+
const IMAGE_INPUT_PREVIEW_CLASS = getModuleClass(IMAGE_INPUT_CSS, "preview");
|
|
11
|
+
const IMAGE_INPUT_FILE_CLASS = getModuleClass(IMAGE_INPUT_CSS, "file");
|
|
12
|
+
const IMAGE_INPUT_CHOOSE_CLASS = getClass(getButtonClass({ solid: true }), getModuleClass(IMAGE_INPUT_CSS, "choose"));
|
|
13
|
+
const IMAGE_INPUT_CLEAR_CLASS = getClass(getButtonClass({ solid: true, small: true }), getModuleClass(IMAGE_INPUT_CSS, "clear"));
|
|
14
|
+
/** The image types the picker accepts by default. */
|
|
15
|
+
const IMAGE_TYPES = { jpg: "image/jpeg", png: "image/png", webp: "image/webp", gif: "image/gif" };
|
|
16
|
+
/**
|
|
17
|
+
* Square image picker that shows the picked image in the square.
|
|
18
|
+
* - With no image, the square shows a "Choose…" button in the middle (change it with `placeholder`).
|
|
19
|
+
* - With an image, the image fills the square and an X button in the corner clears it (`onValue(undefined)`).
|
|
20
|
+
* - A tap anywhere on the square opens the file picker.
|
|
21
|
+
* - `value` is a picked `File`, or the URL of the current image.
|
|
22
|
+
*
|
|
23
|
+
* @kind component
|
|
24
|
+
* @see https://shelving.cc/ui/ImageInput
|
|
25
|
+
*/
|
|
26
|
+
export function ImageInput({ name, title = "Image", placeholder = "Choose…", required = false, disabled = false, message, value, onValue, types = IMAGE_TYPES, className, ...variants }) {
|
|
27
|
+
const onChange = (e) => {
|
|
28
|
+
const file = e.currentTarget.files?.[0];
|
|
29
|
+
if (file)
|
|
30
|
+
onValue(file);
|
|
31
|
+
};
|
|
32
|
+
const onClear = ({ currentTarget }) => {
|
|
33
|
+
// Empty the native input too, so picking the same file again still fires `change`.
|
|
34
|
+
const input = currentTarget.parentElement?.querySelector("input");
|
|
35
|
+
if (input)
|
|
36
|
+
input.value = "";
|
|
37
|
+
onValue(undefined);
|
|
38
|
+
};
|
|
39
|
+
return (_jsxs("div", { className: getClass(IMAGE_INPUT_CLASS, getBlockClass(variants), className), children: [_jsxs("label", { className: IMAGE_INPUT_PICKER_CLASS, title: message, "aria-invalid": !!message, children: [value ? _jsx(ImageInputPreview, { value: value }) : _jsx("span", { className: IMAGE_INPUT_CHOOSE_CLASS, children: placeholder }), _jsx("input", { name: name, type: "file", accept: Object.values(types).join(","), required: required && !value, disabled: disabled, "aria-label": title, className: IMAGE_INPUT_FILE_CLASS, onChange: onChange })] }), value && !disabled && (_jsx("button", { type: "button", title: "Clear", className: IMAGE_INPUT_CLEAR_CLASS, onClick: onClear, children: _jsx(XMarkIcon, {}) }))] }));
|
|
40
|
+
}
|
|
41
|
+
/** The image in the square: a URL as is, or a picked `File` through an object URL that is freed when it changes. */
|
|
42
|
+
function ImageInputPreview({ value }) {
|
|
43
|
+
const src = useMemo(() => (typeof value === "string" ? value : URL.createObjectURL(value)), [value]);
|
|
44
|
+
useEffect(() => () => {
|
|
45
|
+
if (typeof value !== "string")
|
|
46
|
+
URL.revokeObjectURL(src);
|
|
47
|
+
}, [value, src]);
|
|
48
|
+
return _jsx("img", { src: src, alt: "", className: IMAGE_INPUT_PREVIEW_CLASS });
|
|
49
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# ImageInput
|
|
2
|
+
|
|
3
|
+
A large square image picker. With no image, it shows a "Choose…" button in the middle. With an image, the image fills the square and an X button in the corner clears it.
|
|
4
|
+
|
|
5
|
+
## Things to know
|
|
6
|
+
|
|
7
|
+
- A tap anywhere on the square opens the file picker. On a phone this is the built-in photo picker, which can also take a photo.
|
|
8
|
+
- `onValue` gets the picked `File`, or `undefined` when the X button clears the image.
|
|
9
|
+
- `value` is the image to show: a picked `File`, or the URL of the current image (for example, a saved profile photo).
|
|
10
|
+
- The square is as wide as its container. Put it in a narrow container to make it smaller.
|
|
11
|
+
- `placeholder` sets the button text (default "Choose…"). `title` labels the input for screen readers.
|
|
12
|
+
- `types` sets the image types the picker accepts (default JPEG, PNG, WebP, and GIF).
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { ImageInput } from "shelving/ui";
|
|
18
|
+
|
|
19
|
+
function PhotoPicker() {
|
|
20
|
+
const [photo, setPhoto] = useState<File>();
|
|
21
|
+
return <ImageInput name="photo" title="Photo" value={photo} onValue={setPhoto} />;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Show the current image
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { ImageInput } from "shelving/ui";
|
|
29
|
+
|
|
30
|
+
// Shows the saved photo. A new pick calls `onValue` with the new `File`.
|
|
31
|
+
<ImageInput name="photo" value={user.photoURL} onValue={upload} />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Styling
|
|
35
|
+
|
|
36
|
+
`ImageInput` paints from the [tint ladder](/ui/TINT_CLASS). The "Choose…" and X buttons are `<Button>` styles, so `--button-*` hooks also move them.
|
|
37
|
+
|
|
38
|
+
| Variable | Styles | Default |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `--image-input-space` | Space above and below the square | `var(--space-small)` (12px) |
|
|
41
|
+
| `--image-input-radius` | Corner radius of the square | `var(--radius-small)` (12px) |
|
|
42
|
+
| `--image-input-background` | Square background when empty | `var(--tint-90)` |
|
|
43
|
+
| `--image-input-preview-background` | Background behind the picked image, seen through a transparent image | `#000` |
|
|
44
|
+
| `--image-input-focus-border` | Outline when the input has focus | `var(--stroke-focus) solid var(--color-focus)` |
|
|
45
|
+
| `--image-input-invalid-border` | Outline when `message` is set | `var(--stroke-focus) solid var(--color-failure)` |
|
|
46
|
+
| `--image-input-clear-inset` | Distance of the X button from the top and end edges | `var(--space-small)` (12px) |
|
|
47
|
+
|
|
48
|
+
Global tokens it reads: `--tint-90`, `--space-small`, `--radius-small`, `--stroke-focus`, `--color-focus`, `--color-failure`.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
@import url("../style/layers.css");
|
|
2
|
+
@import url("../style/Color.module.css");
|
|
3
|
+
@import url("../style/Radius.module.css");
|
|
4
|
+
@import url("../style/Space.module.css");
|
|
5
|
+
@import url("../style/Stroke.module.css");
|
|
6
|
+
@import url("../style/Tint.module.css");
|
|
7
|
+
|
|
8
|
+
@layer components {
|
|
9
|
+
.image-input {
|
|
10
|
+
/* Box: a square as wide as its container. */
|
|
11
|
+
position: relative;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
inline-size: 100%;
|
|
14
|
+
aspect-ratio: 1;
|
|
15
|
+
margin-block: var(--image-input-space, var(--space-small));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* The square itself: a tap anywhere opens the file picker. */
|
|
19
|
+
.picker {
|
|
20
|
+
position: absolute;
|
|
21
|
+
inset: 0;
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
border-radius: var(--image-input-radius, var(--radius-small));
|
|
27
|
+
background: var(--image-input-background, var(--tint-90));
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
|
|
30
|
+
/* The native file input is not seen, so show its focus ring on the square. */
|
|
31
|
+
&:has(:focus-visible) {
|
|
32
|
+
outline: var(--image-input-focus-border, var(--stroke-focus) solid var(--color-focus));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&[aria-invalid="true"] {
|
|
36
|
+
outline: var(--image-input-invalid-border, var(--stroke-focus) solid var(--color-failure));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&:has(:disabled) {
|
|
40
|
+
cursor: default;
|
|
41
|
+
opacity: 0.5;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* The picked image, covering the whole square. */
|
|
46
|
+
.preview {
|
|
47
|
+
position: absolute;
|
|
48
|
+
inset: 0;
|
|
49
|
+
inline-size: 100%;
|
|
50
|
+
block-size: 100%;
|
|
51
|
+
object-fit: cover;
|
|
52
|
+
|
|
53
|
+
/* A transparent image shows on black, not on the empty square's tint. */
|
|
54
|
+
background: var(--image-input-preview-background, #000);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* The native file input: still focusable and opened by its label, but not seen. */
|
|
58
|
+
.file {
|
|
59
|
+
position: absolute;
|
|
60
|
+
inline-size: 1px;
|
|
61
|
+
block-size: 1px;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
clip-path: inset(50%);
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* The "Choose…" button only shows the label's action, so taps go through to the label. */
|
|
68
|
+
.choose {
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* The X button that clears the image, in the top corner. */
|
|
73
|
+
.clear {
|
|
74
|
+
position: absolute;
|
|
75
|
+
inset-block-start: var(--image-input-clear-inset, var(--space-small));
|
|
76
|
+
inset-inline-end: var(--image-input-clear-inset, var(--space-small));
|
|
77
|
+
margin: 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { XMarkIcon } from "@heroicons/react/24/solid";
|
|
2
|
+
import { type MouseEvent, type ReactElement, type SyntheticEvent, useEffect, useMemo } from "react";
|
|
3
|
+
import type { FileTypes } from "../../util/file.js";
|
|
4
|
+
import { getButtonClass } from "../button/Button.js";
|
|
5
|
+
import { type BlockVariants, getBlockClass } from "../style/Block.js";
|
|
6
|
+
import { getClass, getModuleClass } from "../util/css.js";
|
|
7
|
+
import IMAGE_INPUT_CSS from "./ImageInput.module.css";
|
|
8
|
+
import type { ValueInputProps } from "./Input.js";
|
|
9
|
+
|
|
10
|
+
const IMAGE_INPUT_CLASS = getModuleClass(IMAGE_INPUT_CSS, "image-input");
|
|
11
|
+
const IMAGE_INPUT_PICKER_CLASS = getModuleClass(IMAGE_INPUT_CSS, "picker");
|
|
12
|
+
const IMAGE_INPUT_PREVIEW_CLASS = getModuleClass(IMAGE_INPUT_CSS, "preview");
|
|
13
|
+
const IMAGE_INPUT_FILE_CLASS = getModuleClass(IMAGE_INPUT_CSS, "file");
|
|
14
|
+
const IMAGE_INPUT_CHOOSE_CLASS = getClass(getButtonClass({ solid: true }), getModuleClass(IMAGE_INPUT_CSS, "choose"));
|
|
15
|
+
const IMAGE_INPUT_CLEAR_CLASS = getClass(getButtonClass({ solid: true, small: true }), getModuleClass(IMAGE_INPUT_CSS, "clear"));
|
|
16
|
+
|
|
17
|
+
/** The image types the picker accepts by default. */
|
|
18
|
+
const IMAGE_TYPES: FileTypes = { jpg: "image/jpeg", png: "image/png", webp: "image/webp", gif: "image/gif" };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Props for `<ImageInput>`, a square image picker that emits the picked `File`.
|
|
22
|
+
*
|
|
23
|
+
* @see https://shelving.cc/ui/ImageInputProps
|
|
24
|
+
*/
|
|
25
|
+
export interface ImageInputProps extends ValueInputProps<File, string>, BlockVariants {
|
|
26
|
+
/**
|
|
27
|
+
* The image types the picker accepts.
|
|
28
|
+
* @default { jpg: "image/jpeg", png: "image/png", webp: "image/webp", gif: "image/gif" }
|
|
29
|
+
*/
|
|
30
|
+
types?: FileTypes | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Square image picker that shows the picked image in the square.
|
|
35
|
+
* - With no image, the square shows a "Choose…" button in the middle (change it with `placeholder`).
|
|
36
|
+
* - With an image, the image fills the square and an X button in the corner clears it (`onValue(undefined)`).
|
|
37
|
+
* - A tap anywhere on the square opens the file picker.
|
|
38
|
+
* - `value` is a picked `File`, or the URL of the current image.
|
|
39
|
+
*
|
|
40
|
+
* @kind component
|
|
41
|
+
* @see https://shelving.cc/ui/ImageInput
|
|
42
|
+
*/
|
|
43
|
+
export function ImageInput({
|
|
44
|
+
name,
|
|
45
|
+
title = "Image",
|
|
46
|
+
placeholder = "Choose…",
|
|
47
|
+
required = false,
|
|
48
|
+
disabled = false,
|
|
49
|
+
message,
|
|
50
|
+
value,
|
|
51
|
+
onValue,
|
|
52
|
+
types = IMAGE_TYPES,
|
|
53
|
+
className,
|
|
54
|
+
...variants
|
|
55
|
+
}: ImageInputProps): ReactElement {
|
|
56
|
+
const onChange = (e: SyntheticEvent<HTMLInputElement>) => {
|
|
57
|
+
const file = e.currentTarget.files?.[0];
|
|
58
|
+
if (file) onValue(file);
|
|
59
|
+
};
|
|
60
|
+
const onClear = ({ currentTarget }: MouseEvent<HTMLButtonElement>) => {
|
|
61
|
+
// Empty the native input too, so picking the same file again still fires `change`.
|
|
62
|
+
const input = currentTarget.parentElement?.querySelector("input");
|
|
63
|
+
if (input) input.value = "";
|
|
64
|
+
onValue(undefined);
|
|
65
|
+
};
|
|
66
|
+
return (
|
|
67
|
+
<div className={getClass(IMAGE_INPUT_CLASS, getBlockClass(variants), className)}>
|
|
68
|
+
<label className={IMAGE_INPUT_PICKER_CLASS} title={message} aria-invalid={!!message}>
|
|
69
|
+
{value ? <ImageInputPreview value={value} /> : <span className={IMAGE_INPUT_CHOOSE_CLASS}>{placeholder}</span>}
|
|
70
|
+
<input
|
|
71
|
+
name={name}
|
|
72
|
+
type="file"
|
|
73
|
+
accept={Object.values(types).join(",")}
|
|
74
|
+
required={required && !value}
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
aria-label={title}
|
|
77
|
+
className={IMAGE_INPUT_FILE_CLASS}
|
|
78
|
+
onChange={onChange}
|
|
79
|
+
/>
|
|
80
|
+
</label>
|
|
81
|
+
{value && !disabled && (
|
|
82
|
+
<button type="button" title="Clear" className={IMAGE_INPUT_CLEAR_CLASS} onClick={onClear}>
|
|
83
|
+
<XMarkIcon />
|
|
84
|
+
</button>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The image in the square: a URL as is, or a picked `File` through an object URL that is freed when it changes. */
|
|
91
|
+
function ImageInputPreview({ value }: { readonly value: File | string }): ReactElement {
|
|
92
|
+
const src = useMemo(() => (typeof value === "string" ? value : URL.createObjectURL(value)), [value]);
|
|
93
|
+
useEffect(
|
|
94
|
+
() => () => {
|
|
95
|
+
if (typeof value !== "string") URL.revokeObjectURL(src);
|
|
96
|
+
},
|
|
97
|
+
[value, src],
|
|
98
|
+
);
|
|
99
|
+
return <img src={src} alt="" className={IMAGE_INPUT_PREVIEW_CLASS} />;
|
|
100
|
+
}
|
|
@@ -101,7 +101,16 @@
|
|
|
101
101
|
white-space: pre-wrap;
|
|
102
102
|
overflow-wrap: break-word;
|
|
103
103
|
field-sizing: content;
|
|
104
|
-
|
|
104
|
+
|
|
105
|
+
/* `field-sizing` ignores `rows`, so set the minimum height from `--input-rows` (set inline from the `rows` prop). */
|
|
106
|
+
min-block-size: calc(
|
|
107
|
+
var(--input-rows, 2) *
|
|
108
|
+
1lh +
|
|
109
|
+
2 *
|
|
110
|
+
var(--input-padding, var(--space-small)) +
|
|
111
|
+
2 *
|
|
112
|
+
var(--input-stroke, var(--stroke-normal))
|
|
113
|
+
);
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
116
|
|
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, NumberInput, TextInput } from "shelving/ui";
|
|
3
|
+
import { DateInput, FileInput, ImageInput, NumberInput, 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. */
|
|
@@ -36,3 +36,35 @@ describe("FileInput", () => {
|
|
|
36
36
|
expect(values).toEqual([file]);
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
describe("ImageInput", () => {
|
|
41
|
+
type _Element = ReactElement<{ children: ReactElement<{ children: ReactElement[] }>[] }>;
|
|
42
|
+
function _parts(element: ReactElement) {
|
|
43
|
+
const [label, clear] = (element as _Element).props.children;
|
|
44
|
+
const [shown, input] = (label as ReactElement<{ children: ReactElement[] }>).props.children;
|
|
45
|
+
return {
|
|
46
|
+
shown: shown as ReactElement<Record<string, unknown>>,
|
|
47
|
+
input: input as ReactElement<Record<string, unknown>>,
|
|
48
|
+
clear: clear as unknown as ReactElement<Record<string, unknown>> | false | undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
test("shows the Choose… button and no clear button when empty", () => {
|
|
52
|
+
const { shown, clear } = _parts(ImageInput({ name: "x", onValue: PASSTHROUGH }));
|
|
53
|
+
expect(shown.type).toBe("span");
|
|
54
|
+
expect(shown.props.children).toBe("Choose…");
|
|
55
|
+
expect(clear).toBeFalsy();
|
|
56
|
+
});
|
|
57
|
+
test("shows the image and a clear button for a URL value", () => {
|
|
58
|
+
const { shown, clear } = _parts(ImageInput({ name: "x", value: "https://x.com/a.jpg", onValue: PASSTHROUGH }));
|
|
59
|
+
expect(shown.props.value).toBe("https://x.com/a.jpg");
|
|
60
|
+
expect(clear).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
test("calls onValue with the picked file, and with undefined on clear", () => {
|
|
63
|
+
const values: (File | undefined)[] = [];
|
|
64
|
+
const file = new File(["abc"], "a.jpg");
|
|
65
|
+
const { input, clear } = _parts(ImageInput({ name: "x", value: "https://x.com/a.jpg", onValue: v => void values.push(v) }));
|
|
66
|
+
(input.props.onChange as (e: { currentTarget: { files: File[] } }) => void)({ currentTarget: { files: [file] } });
|
|
67
|
+
((clear as ReactElement<Record<string, unknown>>).props.onClick as (e: unknown) => void)({ currentTarget: { parentElement: null } });
|
|
68
|
+
expect(values).toEqual([file, undefined]);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/ui/input/TextInput.js
CHANGED
|
@@ -22,7 +22,7 @@ required = false, disabled = false, message = "", value, onValue, input = "text"
|
|
|
22
22
|
onValue?.(e.currentTarget.value);
|
|
23
23
|
_resize(e.currentTarget, rows);
|
|
24
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, 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 }));
|
|
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
26
|
}
|
|
27
27
|
const onChange = (e) => {
|
|
28
28
|
onValue?.(e.currentTarget.value);
|
package/ui/input/TextInput.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement, SyntheticEvent } from "react";
|
|
1
|
+
import type { CSSProperties, 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";
|
|
@@ -66,6 +66,7 @@ export function TextInput({
|
|
|
66
66
|
minLength={Number.isFinite(min) ? min : 0}
|
|
67
67
|
maxLength={Number.isFinite(max) ? max : undefined}
|
|
68
68
|
rows={rows}
|
|
69
|
+
style={{ "--input-rows": rows } as CSSProperties}
|
|
69
70
|
required={required && min > 0}
|
|
70
71
|
disabled={disabled}
|
|
71
72
|
placeholder={placeholder || " "}
|
package/ui/input/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./DataInput.js";
|
|
|
8
8
|
export * from "./DateInput.js";
|
|
9
9
|
export * from "./DictionaryInput.js";
|
|
10
10
|
export * from "./FileInput.js";
|
|
11
|
+
export * from "./ImageInput.js";
|
|
11
12
|
export * from "./Input.js";
|
|
12
13
|
export * from "./NumberInput.js";
|
|
13
14
|
export * from "./OutputInput.js";
|
package/ui/input/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./DataInput.js";
|
|
|
8
8
|
export * from "./DateInput.js";
|
|
9
9
|
export * from "./DictionaryInput.js";
|
|
10
10
|
export * from "./FileInput.js";
|
|
11
|
+
export * from "./ImageInput.js";
|
|
11
12
|
export * from "./Input.js";
|
|
12
13
|
export * from "./NumberInput.js";
|
|
13
14
|
export * from "./OutputInput.js";
|
package/ui/input/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./DataInput.js";
|
|
|
8
8
|
export * from "./DateInput.js";
|
|
9
9
|
export * from "./DictionaryInput.js";
|
|
10
10
|
export * from "./FileInput.js";
|
|
11
|
+
export * from "./ImageInput.js";
|
|
11
12
|
export * from "./Input.js";
|
|
12
13
|
export * from "./NumberInput.js";
|
|
13
14
|
export * from "./OutputInput.js";
|
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
|
-
}
|