shelving 1.319.0 → 1.319.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/docs/llms-full.txt +48 -12
- package/docs/ui/Dialog.md +11 -8
- package/docs/ui/DialogProps.md +1 -1
- package/docs/ui/Form.md +1 -1
- package/docs/ui/Modal.md +1 -1
- package/docs/ui/Notices.md +1 -1
- package/docs/ui/requestDialogClose.md +28 -0
- package/docs/ui.md +1 -0
- package/package.json +1 -1
- package/ui/dialog/Dialog.d.ts +15 -3
- package/ui/dialog/Dialog.js +17 -10
- package/ui/dialog/Dialog.md +9 -6
- package/ui/dialog/Dialog.tsx +18 -11
- package/ui/dialog/Modal.md +1 -1
- package/ui/form/Form.js +4 -3
- package/ui/form/Form.md +1 -1
- package/ui/form/Form.tsx +3 -2
- package/ui/notice/Notices.md +1 -1
package/docs/llms-full.txt
CHANGED
|
@@ -20205,6 +20205,7 @@ The components below are listed in the index following this page; this is the sh
|
|
|
20205
20205
|
- [ButtonClickable()](ui/ButtonClickable.md): Render a <button> element that runs its onClick handler through a BusyStore and shows a loading spinner while busy.
|
|
20206
20206
|
- [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when none of href, onClick or disabled is provided, e.g. a plain tag.
|
|
20207
20207
|
- [SubmitButton()](ui/SubmitButton.md): Submit button for a form that disables itself and shows a spinner while the form is busy.
|
|
20208
|
+
- [requestDialogClose()](ui/requestDialogClose.md): Ask a <dialog> element to close, the same way as the Escape key.
|
|
20208
20209
|
- [requireDialogs()](ui/requireDialogs.md): Read the current DialogsStore from the nearest <DialogsContext>.
|
|
20209
20210
|
- [getDocumentationKindColor()](ui/getDocumentationKindColor.md): Get the raw colour variant for a documented symbol's kind, or undefined for an unknown kind.
|
|
20210
20211
|
- [splitType()](ui/splitType.md): Split a type expression on | into its individual union members.
|
|
@@ -23489,7 +23490,7 @@ Props for `<Dialog>` — optional `children` content and an `onClose` callback.
|
|
|
23489
23490
|
|
|
23490
23491
|
| Property | Type | Description |
|
|
23491
23492
|
| --- | --- | --- |
|
|
23492
|
-
| `onClose` | `Callback` | Called when the user
|
|
23493
|
+
| `onClose` | `Callback` | Called when the user asks to close the dialog. It must unmount the `<Dialog>`. Unmount it inside `startTransition()` to animate it out (`<Dialogs>` does this for you). Optional. |
|
|
23493
23494
|
|
|
23494
23495
|
|
|
23495
23496
|
---
|
|
@@ -23503,9 +23504,9 @@ Modal `<dialog>` element that opens on mount and includes a close button.
|
|
|
23503
23504
|
|
|
23504
23505
|
- Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
|
|
23505
23506
|
- A tap on a control (button, input, select, textarea, label) or inside a `<Modal>` panel does not close it. A tap on a link or a `<nav>` button always closes it.
|
|
23506
|
-
-
|
|
23507
|
+
- It knows nothing about transitions. It fades in and out only when the update that mounts or unmounts it is a transition, e.g. from `<Dialogs>` or your own `startTransition()`. A `<Modal>` pinned to an edge then slides in its own layer.
|
|
23507
23508
|
- A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
|
|
23508
|
-
- With `onClose`, a close request calls `onClose()
|
|
23509
|
+
- With `onClose`, it is declarative: a close request calls `onClose()`, and the dialog stays open until it unmounts, so a view transition can capture it as it leaves.
|
|
23509
23510
|
- Children sit in one wrapper in normal block layout, `--dialog-width` wide and centred on the screen. Content taller than the screen scrolls from its top.
|
|
23510
23511
|
- Wraps content in `<Suspense>` so lazy children can stream in.
|
|
23511
23512
|
|
|
@@ -23519,10 +23520,13 @@ A native `<dialog>` element opened in modal mode. It opens via `showModal()` whe
|
|
|
23519
23520
|
- Children sit in one wrapper in normal block layout, so several children stack as they would on the page. The wrapper is `--dialog-width` wide (never wider than the screen) and centred on the screen. A centred `<Modal>` fills it. Content taller than the screen starts at the top, and the dialog scrolls.
|
|
23520
23521
|
- While a dialog is open, the page behind it does not scroll. A scroll inside the dialog never passes on to the page.
|
|
23521
23522
|
- `Dialog` only dims the page. Its text is white (`--tint-100`) so it reads on the dark overlay. Wrap the content in `<Modal>` to give it a panel with dark text on a light surface.
|
|
23522
|
-
- `
|
|
23523
|
-
-
|
|
23523
|
+
- `Dialog` is declarative. While it is mounted, it is open. When the user asks to close it, it calls `onClose` and stays open until it unmounts. `onClose` must unmount it: clear the React state that mounts it, or (when pushed via a store) remove it from the list.
|
|
23524
|
+
- To close a dialog from your own code, call `requestDialogClose()` on the `<dialog>` element, not `dialog.close()`. `requestDialogClose()` goes through `onClose` like the Escape key, so the dialog can animate out. `dialog.close()` closes it at once. A successful `<Form>` submit inside a dialog uses `requestDialogClose()`.
|
|
23525
|
+
- The dialog can animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). The whole dialog fades in and out as one layer. A `<Modal>` pinned to an edge takes its own layer and slides.
|
|
23524
23526
|
- A change inside an open dialog (new content, a Suspense reveal) runs no view transition, so the dialog never ignores a tap while its content changes. The page ignores taps while a view transition runs.
|
|
23525
|
-
-
|
|
23527
|
+
- `Dialog` knows nothing about transitions. React runs a view transition only for an update made inside `startTransition()`, so the code that mounts and unmounts the dialog decides if it animates:
|
|
23528
|
+
- `<Dialogs>` renders a `DialogsStore` inside transitions, so a dialog opened with `DialogsStore.show()` animates in and out for you.
|
|
23529
|
+
- A `Dialog` you mount yourself appears and goes at once, unless you set the state that mounts and unmounts it inside `startTransition()`. See the declarative example below.
|
|
23526
23530
|
- A browser without view transitions shows and hides the dialog at once.
|
|
23527
23531
|
- Pair with `DialogsStore`, `<DialogsContext>`, and `<Dialogs>` to open dialogs imperatively from anywhere in the app.
|
|
23528
23532
|
|
|
@@ -23546,9 +23550,9 @@ function ConfirmDelete({ onConfirm, onClose }: { onConfirm: () => void; onClose:
|
|
|
23546
23550
|
);
|
|
23547
23551
|
}
|
|
23548
23552
|
|
|
23549
|
-
// In the parent. Open inside `startTransition()` so the dialog animates in.
|
|
23553
|
+
// In the parent. Open and close inside `startTransition()` so the dialog animates in and out.
|
|
23550
23554
|
<button type="button" onClick={() => startTransition(() => setShowConfirm(true))}>Delete</button>
|
|
23551
|
-
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => setShowConfirm(false)} />}
|
|
23555
|
+
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => startTransition(() => setShowConfirm(false))} />}
|
|
23552
23556
|
```
|
|
23553
23557
|
|
|
23554
23558
|
### Imperative
|
|
@@ -23571,7 +23575,7 @@ function DeleteButton({ onConfirm }: { onConfirm: () => void }) {
|
|
|
23571
23575
|
}
|
|
23572
23576
|
```
|
|
23573
23577
|
|
|
23574
|
-
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel.
|
|
23578
|
+
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel. `<Dialogs>` renders the list inside transitions, so the dialog animates in and out with no `startTransition()` of your own.
|
|
23575
23579
|
|
|
23576
23580
|
## Styling
|
|
23577
23581
|
|
|
@@ -23592,6 +23596,38 @@ The fade uses the `fade` class from `<FadeTransition>`, so `--fade-transition-du
|
|
|
23592
23596
|
|
|
23593
23597
|
|
|
23594
23598
|
|
|
23599
|
+
---
|
|
23600
|
+
|
|
23601
|
+
# requestDialogClose()
|
|
23602
|
+
|
|
23603
|
+
- Kind: function
|
|
23604
|
+
- Import: `import { requestDialogClose } from "shelving/ui";`
|
|
23605
|
+
|
|
23606
|
+
Ask a `<dialog>` element to close, the same way as the Escape key.
|
|
23607
|
+
- Fires a cancelable `cancel` event, so a `<Dialog>` keeps itself open and calls its `onClose`. Its parent then unmounts it, and it can animate out.
|
|
23608
|
+
- Closes the dialog at once only if nothing cancels the event.
|
|
23609
|
+
- Use it instead of `dialog.close()`, which closes at once and fires no `cancel` event, so the dialog vanishes with no transition.
|
|
23610
|
+
- Not `requestClose()`: some browsers lack it, and Safari fires its `cancel` event as not cancelable. Both close the dialog at once.
|
|
23611
|
+
|
|
23612
|
+
## Signatures
|
|
23613
|
+
|
|
23614
|
+
```ts
|
|
23615
|
+
requestDialogClose(dialog: HTMLDialogElement): void
|
|
23616
|
+
```
|
|
23617
|
+
|
|
23618
|
+
## Parameters
|
|
23619
|
+
|
|
23620
|
+
| Param | Type | Description |
|
|
23621
|
+
| --- | --- | --- |
|
|
23622
|
+
| `dialog` | `HTMLDialogElement` | The `<dialog>` element to close. |
|
|
23623
|
+
|
|
23624
|
+
## Examples
|
|
23625
|
+
|
|
23626
|
+
```ts
|
|
23627
|
+
requestDialogClose(dialog) // Like pressing Escape.
|
|
23628
|
+
```
|
|
23629
|
+
|
|
23630
|
+
|
|
23595
23631
|
---
|
|
23596
23632
|
|
|
23597
23633
|
# DialogCloseButtonProps
|
|
@@ -23874,7 +23910,7 @@ The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the conte
|
|
|
23874
23910
|
- The `radius` variant sets the corner radius. On a pinned panel, corners that touch a screen edge stay square.
|
|
23875
23911
|
- It has a `--shadow-large` drop shadow by default. Set `shadow="none"`, `shadow="small"` or `shadow="normal"` to change it, the same as on `<Card>`.
|
|
23876
23912
|
- Set `top`, `right`, `bottom`, or `left` to pin the panel to that edge of the screen. A top or bottom panel is full width up to `--modal-width`, and centred on a wider screen. A left or right panel is full height. Use these for mobile menus, bottom sheets, and side menus.
|
|
23877
|
-
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place.
|
|
23913
|
+
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place. `Modal` has no transition of its own: it animates only when its `<Dialog>` does (see `Dialog`).
|
|
23878
23914
|
|
|
23879
23915
|
## Usage
|
|
23880
23916
|
|
|
@@ -25848,7 +25884,7 @@ The entry point for shelving forms. `Form` creates a `FormStore` from a `schema`
|
|
|
25848
25884
|
- If you provide no `children`, `Form` renders `<FormFields>` (one auto-input per schema property) followed by `<FormFooter>` (submit button + error message), so a usable form is one prop away.
|
|
25849
25885
|
- Pass `data` to pre-populate an edit form. Pass `messages` (a string or dictionary) to seed initial field errors — useful when a server returns validation failures.
|
|
25850
25886
|
- The whole `<fieldset>` is disabled while a submit is in flight, so inputs and buttons lock automatically.
|
|
25851
|
-
- A successful submit inside a `<dialog>` closes the dialog automatically.
|
|
25887
|
+
- A successful submit inside a `<dialog>` closes the dialog automatically, through `requestDialogClose()`, so a `<Dialog>` can animate out.
|
|
25852
25888
|
- Notices are surfaced from the `onSubmit` return/throw — see [Notices and error surfacing](#notices-and-error-surfacing) below.
|
|
25853
25889
|
|
|
25854
25890
|
## Usage
|
|
@@ -32138,7 +32174,7 @@ Renders the global list of active notices and subscribes to incoming `"notice"`
|
|
|
32138
32174
|
- Notices auto-dismiss after a short delay unless they carry a `"loading"` status.
|
|
32139
32175
|
- Backed by the `NOTICES` store singleton; for advanced use you can keep a reference to a notice to update or close it manually.
|
|
32140
32176
|
- The list shows in the bottom-right corner. Set `position` to `"top-left"`, `"top-center"`, `"top-right"`, `"bottom-left"`, `"bottom-center"`, or `"bottom-right"` to choose a different place.
|
|
32141
|
-
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
32177
|
+
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). `Notices` renders the store inside transitions, so a notice animates with no `startTransition()` of your own. A single `<Notice>` knows nothing about transitions, the same as `<Dialog>`. A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
32142
32178
|
- With reduced motion, notices fade in and out in place, and the others move at once. A browser without view transitions shows the changes at once.
|
|
32143
32179
|
|
|
32144
32180
|
## Usage
|
package/docs/ui/Dialog.md
CHANGED
|
@@ -7,9 +7,9 @@ Modal `<dialog>` element that opens on mount and includes a close button.
|
|
|
7
7
|
|
|
8
8
|
- Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
|
|
9
9
|
- A tap on a control (button, input, select, textarea, label) or inside a `<Modal>` panel does not close it. A tap on a link or a `<nav>` button always closes it.
|
|
10
|
-
-
|
|
10
|
+
- It knows nothing about transitions. It fades in and out only when the update that mounts or unmounts it is a transition, e.g. from `<Dialogs>` or your own `startTransition()`. A `<Modal>` pinned to an edge then slides in its own layer.
|
|
11
11
|
- A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
|
|
12
|
-
- With `onClose`, a close request calls `onClose()
|
|
12
|
+
- With `onClose`, it is declarative: a close request calls `onClose()`, and the dialog stays open until it unmounts, so a view transition can capture it as it leaves.
|
|
13
13
|
- Children sit in one wrapper in normal block layout, `--dialog-width` wide and centred on the screen. Content taller than the screen scrolls from its top.
|
|
14
14
|
- Wraps content in `<Suspense>` so lazy children can stream in.
|
|
15
15
|
|
|
@@ -23,10 +23,13 @@ A native `<dialog>` element opened in modal mode. It opens via `showModal()` whe
|
|
|
23
23
|
- Children sit in one wrapper in normal block layout, so several children stack as they would on the page. The wrapper is `--dialog-width` wide (never wider than the screen) and centred on the screen. A centred `<Modal>` fills it. Content taller than the screen starts at the top, and the dialog scrolls.
|
|
24
24
|
- While a dialog is open, the page behind it does not scroll. A scroll inside the dialog never passes on to the page.
|
|
25
25
|
- `Dialog` only dims the page. Its text is white (`--tint-100`) so it reads on the dark overlay. Wrap the content in `<Modal>` to give it a panel with dark text on a light surface.
|
|
26
|
-
- `
|
|
27
|
-
-
|
|
26
|
+
- `Dialog` is declarative. While it is mounted, it is open. When the user asks to close it, it calls `onClose` and stays open until it unmounts. `onClose` must unmount it: clear the React state that mounts it, or (when pushed via a store) remove it from the list.
|
|
27
|
+
- To close a dialog from your own code, call `requestDialogClose()` on the `<dialog>` element, not `dialog.close()`. `requestDialogClose()` goes through `onClose` like the Escape key, so the dialog can animate out. `dialog.close()` closes it at once. A successful `<Form>` submit inside a dialog uses `requestDialogClose()`.
|
|
28
|
+
- The dialog can animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). The whole dialog fades in and out as one layer. A `<Modal>` pinned to an edge takes its own layer and slides.
|
|
28
29
|
- A change inside an open dialog (new content, a Suspense reveal) runs no view transition, so the dialog never ignores a tap while its content changes. The page ignores taps while a view transition runs.
|
|
29
|
-
-
|
|
30
|
+
- `Dialog` knows nothing about transitions. React runs a view transition only for an update made inside `startTransition()`, so the code that mounts and unmounts the dialog decides if it animates:
|
|
31
|
+
- `<Dialogs>` renders a `DialogsStore` inside transitions, so a dialog opened with `DialogsStore.show()` animates in and out for you.
|
|
32
|
+
- A `Dialog` you mount yourself appears and goes at once, unless you set the state that mounts and unmounts it inside `startTransition()`. See the declarative example below.
|
|
30
33
|
- A browser without view transitions shows and hides the dialog at once.
|
|
31
34
|
- Pair with `DialogsStore`, `<DialogsContext>`, and `<Dialogs>` to open dialogs imperatively from anywhere in the app.
|
|
32
35
|
|
|
@@ -50,9 +53,9 @@ function ConfirmDelete({ onConfirm, onClose }: { onConfirm: () => void; onClose:
|
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
// In the parent. Open inside `startTransition()` so the dialog animates in.
|
|
56
|
+
// In the parent. Open and close inside `startTransition()` so the dialog animates in and out.
|
|
54
57
|
<button type="button" onClick={() => startTransition(() => setShowConfirm(true))}>Delete</button>
|
|
55
|
-
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => setShowConfirm(false)} />}
|
|
58
|
+
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => startTransition(() => setShowConfirm(false))} />}
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
### Imperative
|
|
@@ -75,7 +78,7 @@ function DeleteButton({ onConfirm }: { onConfirm: () => void }) {
|
|
|
75
78
|
}
|
|
76
79
|
```
|
|
77
80
|
|
|
78
|
-
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel.
|
|
81
|
+
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel. `<Dialogs>` renders the list inside transitions, so the dialog animates in and out with no `startTransition()` of your own.
|
|
79
82
|
|
|
80
83
|
## Styling
|
|
81
84
|
|
package/docs/ui/DialogProps.md
CHANGED
|
@@ -18,4 +18,4 @@ Props for `<Dialog>` — optional `children` content and an `onClose` callback.
|
|
|
18
18
|
|
|
19
19
|
| Property | Type | Description |
|
|
20
20
|
| --- | --- | --- |
|
|
21
|
-
| `onClose` | `Callback` | Called when the user
|
|
21
|
+
| `onClose` | `Callback` | Called when the user asks to close the dialog. It must unmount the `<Dialog>`. Unmount it inside `startTransition()` to animate it out (`<Dialogs>` does this for you). Optional. |
|
package/docs/ui/Form.md
CHANGED
|
@@ -14,7 +14,7 @@ The entry point for shelving forms. `Form` creates a `FormStore` from a `schema`
|
|
|
14
14
|
- If you provide no `children`, `Form` renders `<FormFields>` (one auto-input per schema property) followed by `<FormFooter>` (submit button + error message), so a usable form is one prop away.
|
|
15
15
|
- Pass `data` to pre-populate an edit form. Pass `messages` (a string or dictionary) to seed initial field errors — useful when a server returns validation failures.
|
|
16
16
|
- The whole `<fieldset>` is disabled while a submit is in flight, so inputs and buttons lock automatically.
|
|
17
|
-
- A successful submit inside a `<dialog>` closes the dialog automatically.
|
|
17
|
+
- A successful submit inside a `<dialog>` closes the dialog automatically, through `requestDialogClose()`, so a `<Dialog>` can animate out.
|
|
18
18
|
- Notices are surfaced from the `onSubmit` return/throw — see [Notices and error surfacing](#notices-and-error-surfacing) below.
|
|
19
19
|
|
|
20
20
|
## Usage
|
package/docs/ui/Modal.md
CHANGED
|
@@ -23,7 +23,7 @@ The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the conte
|
|
|
23
23
|
- The `radius` variant sets the corner radius. On a pinned panel, corners that touch a screen edge stay square.
|
|
24
24
|
- It has a `--shadow-large` drop shadow by default. Set `shadow="none"`, `shadow="small"` or `shadow="normal"` to change it, the same as on `<Card>`.
|
|
25
25
|
- Set `top`, `right`, `bottom`, or `left` to pin the panel to that edge of the screen. A top or bottom panel is full width up to `--modal-width`, and centred on a wider screen. A left or right panel is full height. Use these for mobile menus, bottom sheets, and side menus.
|
|
26
|
-
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place.
|
|
26
|
+
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place. `Modal` has no transition of its own: it animates only when its `<Dialog>` does (see `Dialog`).
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
package/docs/ui/Notices.md
CHANGED
|
@@ -17,7 +17,7 @@ Renders the global list of active notices and subscribes to incoming `"notice"`
|
|
|
17
17
|
- Notices auto-dismiss after a short delay unless they carry a `"loading"` status.
|
|
18
18
|
- Backed by the `NOTICES` store singleton; for advanced use you can keep a reference to a notice to update or close it manually.
|
|
19
19
|
- The list shows in the bottom-right corner. Set `position` to `"top-left"`, `"top-center"`, `"top-right"`, `"bottom-left"`, `"bottom-center"`, or `"bottom-right"` to choose a different place.
|
|
20
|
-
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
20
|
+
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). `Notices` renders the store inside transitions, so a notice animates with no `startTransition()` of your own. A single `<Notice>` knows nothing about transitions, the same as `<Dialog>`. A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
21
21
|
- With reduced motion, notices fade in and out in place, and the others move at once. A browser without view transitions shows the changes at once.
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# requestDialogClose()
|
|
2
|
+
|
|
3
|
+
- Kind: function
|
|
4
|
+
- Import: `import { requestDialogClose } from "shelving/ui";`
|
|
5
|
+
|
|
6
|
+
Ask a `<dialog>` element to close, the same way as the Escape key.
|
|
7
|
+
- Fires a cancelable `cancel` event, so a `<Dialog>` keeps itself open and calls its `onClose`. Its parent then unmounts it, and it can animate out.
|
|
8
|
+
- Closes the dialog at once only if nothing cancels the event.
|
|
9
|
+
- Use it instead of `dialog.close()`, which closes at once and fires no `cancel` event, so the dialog vanishes with no transition.
|
|
10
|
+
- Not `requestClose()`: some browsers lack it, and Safari fires its `cancel` event as not cancelable. Both close the dialog at once.
|
|
11
|
+
|
|
12
|
+
## Signatures
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
requestDialogClose(dialog: HTMLDialogElement): void
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
| Param | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `dialog` | `HTMLDialogElement` | The `<dialog>` element to close. |
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
requestDialogClose(dialog) // Like pressing Escape.
|
|
28
|
+
```
|
package/docs/ui.md
CHANGED
|
@@ -231,6 +231,7 @@ The components below are listed in the index following this page; this is the sh
|
|
|
231
231
|
- [ButtonClickable()](ui/ButtonClickable.md): Render a <button> element that runs its onClick handler through a BusyStore and shows a loading spinner while busy.
|
|
232
232
|
- [SpanClickable()](ui/SpanClickable.md): Render a non-interactive <span> element, used as the fallback when none of href, onClick or disabled is provided, e.g. a plain tag.
|
|
233
233
|
- [SubmitButton()](ui/SubmitButton.md): Submit button for a form that disables itself and shows a spinner while the form is busy.
|
|
234
|
+
- [requestDialogClose()](ui/requestDialogClose.md): Ask a <dialog> element to close, the same way as the Escape key.
|
|
234
235
|
- [requireDialogs()](ui/requireDialogs.md): Read the current DialogsStore from the nearest <DialogsContext>.
|
|
235
236
|
- [getDocumentationKindColor()](ui/getDocumentationKindColor.md): Get the raw colour variant for a documented symbol's kind, or undefined for an unknown kind.
|
|
236
237
|
- [splitType()](ui/splitType.md): Split a type expression on | into its individual union members.
|
package/package.json
CHANGED
package/ui/dialog/Dialog.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import "../transition/FadeTransition.css";
|
|
|
9
9
|
* @see https://shelving.cc/ui/DialogProps
|
|
10
10
|
*/
|
|
11
11
|
export interface DialogProps extends OptionalChildProps {
|
|
12
|
-
/** Called when the user
|
|
12
|
+
/** Called when the user asks to close the dialog. It must unmount the `<Dialog>`. Unmount it inside `startTransition()` to animate it out (`<Dialogs>` does this for you). */
|
|
13
13
|
onClose?: Callback;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -17,9 +17,9 @@ export interface DialogProps extends OptionalChildProps {
|
|
|
17
17
|
*
|
|
18
18
|
* - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
|
|
19
19
|
* - A tap on a control (button, input, select, textarea, label) or inside a `<Modal>` panel does not close it. A tap on a link or a `<nav>` button always closes it.
|
|
20
|
-
* -
|
|
20
|
+
* - It knows nothing about transitions. It fades in and out only when the update that mounts or unmounts it is a transition, e.g. from `<Dialogs>` or your own `startTransition()`. A `<Modal>` pinned to an edge then slides in its own layer.
|
|
21
21
|
* - A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
|
|
22
|
-
* - With `onClose`, a close request calls `onClose()
|
|
22
|
+
* - With `onClose`, it is declarative: a close request calls `onClose()`, and the dialog stays open until it unmounts, so a view transition can capture it as it leaves.
|
|
23
23
|
* - Children sit in one wrapper in normal block layout, `--dialog-width` wide and centred on the screen. Content taller than the screen scrolls from its top.
|
|
24
24
|
* - Wraps content in `<Suspense>` so lazy children can stream in.
|
|
25
25
|
*
|
|
@@ -27,6 +27,18 @@ export interface DialogProps extends OptionalChildProps {
|
|
|
27
27
|
* @see https://shelving.cc/ui/Dialog
|
|
28
28
|
*/
|
|
29
29
|
export declare const Dialog: import("react").MemoExoticComponent<({ children, onClose, ...props }: DialogProps) => import("react").JSX.Element>;
|
|
30
|
+
/**
|
|
31
|
+
* Ask a `<dialog>` element to close, the same way as the Escape key.
|
|
32
|
+
* - Fires a cancelable `cancel` event, so a `<Dialog>` keeps itself open and calls its `onClose`. Its parent then unmounts it, and it can animate out.
|
|
33
|
+
* - Closes the dialog at once only if nothing cancels the event.
|
|
34
|
+
* - Use it instead of `dialog.close()`, which closes at once and fires no `cancel` event, so the dialog vanishes with no transition.
|
|
35
|
+
* - Not `requestClose()`: some browsers lack it, and Safari fires its `cancel` event as not cancelable. Both close the dialog at once.
|
|
36
|
+
*
|
|
37
|
+
* @param dialog The `<dialog>` element to close.
|
|
38
|
+
* @example requestDialogClose(dialog) // Like pressing Escape.
|
|
39
|
+
* @see https://shelving.cc/ui/requestDialogClose
|
|
40
|
+
*/
|
|
41
|
+
export declare function requestDialogClose(dialog: HTMLDialogElement): void;
|
|
30
42
|
/**
|
|
31
43
|
* Props for `<DialogCloseButton>` — button styling variants and optional `children` to override the X icon.
|
|
32
44
|
*
|
package/ui/dialog/Dialog.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { memo, Suspense,
|
|
2
|
+
import { memo, Suspense, ViewTransition } from "react";
|
|
3
3
|
import { CloseIcon } from "shelving/icon/CloseIcon";
|
|
4
4
|
import { getButtonClass } from "../button/Button.js";
|
|
5
5
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
@@ -11,9 +11,9 @@ import modalStyles from "./Modal.module.css";
|
|
|
11
11
|
*
|
|
12
12
|
* - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
|
|
13
13
|
* - A tap on a control (button, input, select, textarea, label) or inside a `<Modal>` panel does not close it. A tap on a link or a `<nav>` button always closes it.
|
|
14
|
-
* -
|
|
14
|
+
* - It knows nothing about transitions. It fades in and out only when the update that mounts or unmounts it is a transition, e.g. from `<Dialogs>` or your own `startTransition()`. A `<Modal>` pinned to an edge then slides in its own layer.
|
|
15
15
|
* - A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
|
|
16
|
-
* - With `onClose`, a close request calls `onClose()
|
|
16
|
+
* - With `onClose`, it is declarative: a close request calls `onClose()`, and the dialog stays open until it unmounts, so a view transition can capture it as it leaves.
|
|
17
17
|
* - Children sit in one wrapper in normal block layout, `--dialog-width` wide and centred on the screen. Content taller than the screen scrolls from its top.
|
|
18
18
|
* - Wraps content in `<Suspense>` so lazy children can stream in.
|
|
19
19
|
*
|
|
@@ -22,11 +22,11 @@ import modalStyles from "./Modal.module.css";
|
|
|
22
22
|
*/
|
|
23
23
|
export const Dialog = memo(({ children, onClose, ...props }) => {
|
|
24
24
|
return (_jsx(Suspense, { fallback: null, children: _jsx(ViewTransition, { default: "none", enter: "fade", exit: "fade", children: _jsxs("dialog", { ref: _showModal, className: getModuleClass(styles, "dialog"), onClick: _closeOnClick, onCancel: e => {
|
|
25
|
-
// Keep the dialog open
|
|
25
|
+
// Keep the dialog open until the parent unmounts it. An uncancelable request closes natively and fires `onClose` from the `close` event.
|
|
26
26
|
if (!onClose || !e.cancelable)
|
|
27
27
|
return;
|
|
28
28
|
e.preventDefault();
|
|
29
|
-
|
|
29
|
+
onClose();
|
|
30
30
|
}, onClose: onClose, ...props, children: [_jsx("div", { className: getModuleClass(styles, "content"), children: children }), _jsx("div", { className: getModuleClass(styles, "close"), children: _jsx(DialogCloseButton, {}) })] }) }) }));
|
|
31
31
|
});
|
|
32
32
|
/**
|
|
@@ -50,13 +50,20 @@ function _closeOnClick({ currentTarget, target }) {
|
|
|
50
50
|
if (target.closest("dialog") !== currentTarget)
|
|
51
51
|
return;
|
|
52
52
|
if (target.closest(CLOSE_SELECTOR) || !target.closest(KEEP_SELECTOR))
|
|
53
|
-
|
|
53
|
+
requestDialogClose(currentTarget);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* Ask a `<dialog>` to close
|
|
57
|
-
* -
|
|
56
|
+
* Ask a `<dialog>` element to close, the same way as the Escape key.
|
|
57
|
+
* - Fires a cancelable `cancel` event, so a `<Dialog>` keeps itself open and calls its `onClose`. Its parent then unmounts it, and it can animate out.
|
|
58
|
+
* - Closes the dialog at once only if nothing cancels the event.
|
|
59
|
+
* - Use it instead of `dialog.close()`, which closes at once and fires no `cancel` event, so the dialog vanishes with no transition.
|
|
60
|
+
* - Not `requestClose()`: some browsers lack it, and Safari fires its `cancel` event as not cancelable. Both close the dialog at once.
|
|
61
|
+
*
|
|
62
|
+
* @param dialog The `<dialog>` element to close.
|
|
63
|
+
* @example requestDialogClose(dialog) // Like pressing Escape.
|
|
64
|
+
* @see https://shelving.cc/ui/requestDialogClose
|
|
58
65
|
*/
|
|
59
|
-
function
|
|
66
|
+
export function requestDialogClose(dialog) {
|
|
60
67
|
if (dialog.dispatchEvent(new Event("cancel", { cancelable: true })))
|
|
61
68
|
dialog.close();
|
|
62
69
|
}
|
|
@@ -74,5 +81,5 @@ export function DialogCloseButton({ children = _jsx(CloseIcon, {}), plain = true
|
|
|
74
81
|
function _closeOnButtonClick({ currentTarget }) {
|
|
75
82
|
const dialog = currentTarget.closest("dialog");
|
|
76
83
|
if (dialog)
|
|
77
|
-
|
|
84
|
+
requestDialogClose(dialog);
|
|
78
85
|
}
|
package/ui/dialog/Dialog.md
CHANGED
|
@@ -10,10 +10,13 @@ A native `<dialog>` element opened in modal mode. It opens via `showModal()` whe
|
|
|
10
10
|
- Children sit in one wrapper in normal block layout, so several children stack as they would on the page. The wrapper is `--dialog-width` wide (never wider than the screen) and centred on the screen. A centred `<Modal>` fills it. Content taller than the screen starts at the top, and the dialog scrolls.
|
|
11
11
|
- While a dialog is open, the page behind it does not scroll. A scroll inside the dialog never passes on to the page.
|
|
12
12
|
- `Dialog` only dims the page. Its text is white (`--tint-100`) so it reads on the dark overlay. Wrap the content in `<Modal>` to give it a panel with dark text on a light surface.
|
|
13
|
-
- `
|
|
14
|
-
-
|
|
13
|
+
- `Dialog` is declarative. While it is mounted, it is open. When the user asks to close it, it calls `onClose` and stays open until it unmounts. `onClose` must unmount it: clear the React state that mounts it, or (when pushed via a store) remove it from the list.
|
|
14
|
+
- To close a dialog from your own code, call `requestDialogClose()` on the `<dialog>` element, not `dialog.close()`. `requestDialogClose()` goes through `onClose` like the Escape key, so the dialog can animate out. `dialog.close()` closes it at once. A successful `<Form>` submit inside a dialog uses `requestDialogClose()`.
|
|
15
|
+
- The dialog can animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). The whole dialog fades in and out as one layer. A `<Modal>` pinned to an edge takes its own layer and slides.
|
|
15
16
|
- A change inside an open dialog (new content, a Suspense reveal) runs no view transition, so the dialog never ignores a tap while its content changes. The page ignores taps while a view transition runs.
|
|
16
|
-
-
|
|
17
|
+
- `Dialog` knows nothing about transitions. React runs a view transition only for an update made inside `startTransition()`, so the code that mounts and unmounts the dialog decides if it animates:
|
|
18
|
+
- `<Dialogs>` renders a `DialogsStore` inside transitions, so a dialog opened with `DialogsStore.show()` animates in and out for you.
|
|
19
|
+
- A `Dialog` you mount yourself appears and goes at once, unless you set the state that mounts and unmounts it inside `startTransition()`. See the declarative example below.
|
|
17
20
|
- A browser without view transitions shows and hides the dialog at once.
|
|
18
21
|
- Pair with `DialogsStore`, `<DialogsContext>`, and `<Dialogs>` to open dialogs imperatively from anywhere in the app.
|
|
19
22
|
|
|
@@ -37,9 +40,9 @@ function ConfirmDelete({ onConfirm, onClose }: { onConfirm: () => void; onClose:
|
|
|
37
40
|
);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
// In the parent. Open inside `startTransition()` so the dialog animates in.
|
|
43
|
+
// In the parent. Open and close inside `startTransition()` so the dialog animates in and out.
|
|
41
44
|
<button type="button" onClick={() => startTransition(() => setShowConfirm(true))}>Delete</button>
|
|
42
|
-
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => setShowConfirm(false)} />}
|
|
45
|
+
{showConfirm && <ConfirmDelete onConfirm={handleDelete} onClose={() => startTransition(() => setShowConfirm(false))} />}
|
|
43
46
|
```
|
|
44
47
|
|
|
45
48
|
### Imperative
|
|
@@ -62,7 +65,7 @@ function DeleteButton({ onConfirm }: { onConfirm: () => void }) {
|
|
|
62
65
|
}
|
|
63
66
|
```
|
|
64
67
|
|
|
65
|
-
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel.
|
|
68
|
+
`dialogs.show()` wraps the content in a `<Dialog>` for you, so you pass plain children rather than a `<Dialog>` element. It does not add a `<Modal>`; include one in the content if you want a panel. `<Dialogs>` renders the list inside transitions, so the dialog animates in and out with no `startTransition()` of your own.
|
|
66
69
|
|
|
67
70
|
## Styling
|
|
68
71
|
|
package/ui/dialog/Dialog.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MouseEvent, memo, type ReactElement, Suspense,
|
|
1
|
+
import { type MouseEvent, memo, type ReactElement, Suspense, ViewTransition } from "react";
|
|
2
2
|
import { CloseIcon } from "shelving/icon/CloseIcon";
|
|
3
3
|
import type { Callback } from "../../util/function.js";
|
|
4
4
|
import { type ButtonVariants, getButtonClass } from "../button/Button.js";
|
|
@@ -14,7 +14,7 @@ import modalStyles from "./Modal.module.css";
|
|
|
14
14
|
* @see https://shelving.cc/ui/DialogProps
|
|
15
15
|
*/
|
|
16
16
|
export interface DialogProps extends OptionalChildProps {
|
|
17
|
-
/** Called when the user
|
|
17
|
+
/** Called when the user asks to close the dialog. It must unmount the `<Dialog>`. Unmount it inside `startTransition()` to animate it out (`<Dialogs>` does this for you). */
|
|
18
18
|
onClose?: Callback;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -23,9 +23,9 @@ export interface DialogProps extends OptionalChildProps {
|
|
|
23
23
|
*
|
|
24
24
|
* - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
|
|
25
25
|
* - A tap on a control (button, input, select, textarea, label) or inside a `<Modal>` panel does not close it. A tap on a link or a `<nav>` button always closes it.
|
|
26
|
-
* -
|
|
26
|
+
* - It knows nothing about transitions. It fades in and out only when the update that mounts or unmounts it is a transition, e.g. from `<Dialogs>` or your own `startTransition()`. A `<Modal>` pinned to an edge then slides in its own layer.
|
|
27
27
|
* - A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
|
|
28
|
-
* - With `onClose`, a close request calls `onClose()
|
|
28
|
+
* - With `onClose`, it is declarative: a close request calls `onClose()`, and the dialog stays open until it unmounts, so a view transition can capture it as it leaves.
|
|
29
29
|
* - Children sit in one wrapper in normal block layout, `--dialog-width` wide and centred on the screen. Content taller than the screen scrolls from its top.
|
|
30
30
|
* - Wraps content in `<Suspense>` so lazy children can stream in.
|
|
31
31
|
*
|
|
@@ -43,10 +43,10 @@ export const Dialog = memo(({ children, onClose, ...props }: DialogProps) => {
|
|
|
43
43
|
className={getModuleClass(styles, "dialog")}
|
|
44
44
|
onClick={_closeOnClick}
|
|
45
45
|
onCancel={e => {
|
|
46
|
-
// Keep the dialog open
|
|
46
|
+
// Keep the dialog open until the parent unmounts it. An uncancelable request closes natively and fires `onClose` from the `close` event.
|
|
47
47
|
if (!onClose || !e.cancelable) return;
|
|
48
48
|
e.preventDefault();
|
|
49
|
-
|
|
49
|
+
onClose();
|
|
50
50
|
}}
|
|
51
51
|
onClose={onClose}
|
|
52
52
|
{...props}
|
|
@@ -83,14 +83,21 @@ function _closeOnClick({ currentTarget, target }: MouseEvent<HTMLDialogElement>)
|
|
|
83
83
|
// Ignore taps in a nested dialog. React events bubble through the React tree, so they can reach an outer dialog.
|
|
84
84
|
if (target.closest("dialog") !== currentTarget) return;
|
|
85
85
|
|
|
86
|
-
if (target.closest(CLOSE_SELECTOR) || !target.closest(KEEP_SELECTOR))
|
|
86
|
+
if (target.closest(CLOSE_SELECTOR) || !target.closest(KEEP_SELECTOR)) requestDialogClose(currentTarget);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Ask a `<dialog>` to close
|
|
91
|
-
* -
|
|
90
|
+
* Ask a `<dialog>` element to close, the same way as the Escape key.
|
|
91
|
+
* - Fires a cancelable `cancel` event, so a `<Dialog>` keeps itself open and calls its `onClose`. Its parent then unmounts it, and it can animate out.
|
|
92
|
+
* - Closes the dialog at once only if nothing cancels the event.
|
|
93
|
+
* - Use it instead of `dialog.close()`, which closes at once and fires no `cancel` event, so the dialog vanishes with no transition.
|
|
94
|
+
* - Not `requestClose()`: some browsers lack it, and Safari fires its `cancel` event as not cancelable. Both close the dialog at once.
|
|
95
|
+
*
|
|
96
|
+
* @param dialog The `<dialog>` element to close.
|
|
97
|
+
* @example requestDialogClose(dialog) // Like pressing Escape.
|
|
98
|
+
* @see https://shelving.cc/ui/requestDialogClose
|
|
92
99
|
*/
|
|
93
|
-
function
|
|
100
|
+
export function requestDialogClose(dialog: HTMLDialogElement): void {
|
|
94
101
|
if (dialog.dispatchEvent(new Event("cancel", { cancelable: true }))) dialog.close();
|
|
95
102
|
}
|
|
96
103
|
|
|
@@ -129,5 +136,5 @@ export function DialogCloseButton({
|
|
|
129
136
|
|
|
130
137
|
function _closeOnButtonClick({ currentTarget }: MouseEvent<HTMLButtonElement>): void {
|
|
131
138
|
const dialog = currentTarget.closest("dialog");
|
|
132
|
-
if (dialog)
|
|
139
|
+
if (dialog) requestDialogClose(dialog);
|
|
133
140
|
}
|
package/ui/dialog/Modal.md
CHANGED
|
@@ -14,7 +14,7 @@ The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the conte
|
|
|
14
14
|
- The `radius` variant sets the corner radius. On a pinned panel, corners that touch a screen edge stay square.
|
|
15
15
|
- It has a `--shadow-large` drop shadow by default. Set `shadow="none"`, `shadow="small"` or `shadow="normal"` to change it, the same as on `<Card>`.
|
|
16
16
|
- Set `top`, `right`, `bottom`, or `left` to pin the panel to that edge of the screen. A top or bottom panel is full width up to `--modal-width`, and centred on a wider screen. A left or right panel is full height. Use these for mobile menus, bottom sheets, and side menus.
|
|
17
|
-
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place.
|
|
17
|
+
- A centred panel fades in and out with its `<Dialog>`. A pinned panel slides in from its edge and out to it, in its own view-transition layer. With reduced motion, a pinned panel fades in place. `Modal` has no transition of its own: it animates only when its `<Dialog>` does (see `Dialog`).
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
package/ui/form/Form.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useInstance } from "../../react/useInstance.js";
|
|
3
3
|
import { useStore } from "../../react/useStore.js";
|
|
4
4
|
import { isAsync } from "../../util/async.js";
|
|
5
|
+
import { requestDialogClose } from "../dialog/Dialog.js";
|
|
5
6
|
import { getBlockClass } from "../style/Block.js";
|
|
6
7
|
import { getClass } from "../util/css.js";
|
|
7
8
|
import { notifySuccess, notifyThrown } from "../util/notice.js";
|
|
@@ -21,9 +22,9 @@ export function Form({ schema, data: initialData, onSubmit, submit, messages, cl
|
|
|
21
22
|
const dialog = form.closest("dialog");
|
|
22
23
|
// Submit the form to the callback.
|
|
23
24
|
const result = await store.submit(callNotifiedForm, store, form, onSubmit, e);
|
|
24
|
-
// Close the parent dialog on successful submit.
|
|
25
|
-
if (result)
|
|
26
|
-
dialog
|
|
25
|
+
// Close the parent dialog on successful submit, through its `cancel` event so a `<Dialog>` can animate out.
|
|
26
|
+
if (result && dialog)
|
|
27
|
+
requestDialogClose(dialog);
|
|
27
28
|
}, className: getClass(getBlockClass(props), className), noValidate: true, children: _jsx("fieldset", { className: getBlockClass({}), disabled: busy, children: _jsx(FormContext, { value: store, children: children }) }) }, store.key));
|
|
28
29
|
}
|
|
29
30
|
/**
|
package/ui/form/Form.md
CHANGED
|
@@ -7,7 +7,7 @@ The entry point for shelving forms. `Form` creates a `FormStore` from a `schema`
|
|
|
7
7
|
- If you provide no `children`, `Form` renders `<FormFields>` (one auto-input per schema property) followed by `<FormFooter>` (submit button + error message), so a usable form is one prop away.
|
|
8
8
|
- Pass `data` to pre-populate an edit form. Pass `messages` (a string or dictionary) to seed initial field errors — useful when a server returns validation failures.
|
|
9
9
|
- The whole `<fieldset>` is disabled while a submit is in flight, so inputs and buttons lock automatically.
|
|
10
|
-
- A successful submit inside a `<dialog>` closes the dialog automatically.
|
|
10
|
+
- A successful submit inside a `<dialog>` closes the dialog automatically, through `requestDialogClose()`, so a `<Dialog>` can animate out.
|
|
11
11
|
- Notices are surfaced from the `onSubmit` return/throw — see [Notices and error surfacing](#notices-and-error-surfacing) below.
|
|
12
12
|
|
|
13
13
|
## Usage
|
package/ui/form/Form.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { isAsync } from "../../util/async.js";
|
|
|
6
6
|
import type { Data, PartialData } from "../../util/data.js";
|
|
7
7
|
import type { ImmutableDictionary } from "../../util/dictionary.js";
|
|
8
8
|
import type { Arguments } from "../../util/function.js";
|
|
9
|
+
import { requestDialogClose } from "../dialog/Dialog.js";
|
|
9
10
|
import { type BlockVariants, getBlockClass } from "../style/Block.js";
|
|
10
11
|
import { getClass } from "../util/css.js";
|
|
11
12
|
import { type NoticeCallback, notifySuccess, notifyThrown } from "../util/notice.js";
|
|
@@ -89,8 +90,8 @@ export function Form({
|
|
|
89
90
|
// Submit the form to the callback.
|
|
90
91
|
const result = await store.submit(callNotifiedForm, store, form, onSubmit, e);
|
|
91
92
|
|
|
92
|
-
// Close the parent dialog on successful submit.
|
|
93
|
-
if (result) dialog
|
|
93
|
+
// Close the parent dialog on successful submit, through its `cancel` event so a `<Dialog>` can animate out.
|
|
94
|
+
if (result && dialog) requestDialogClose(dialog);
|
|
94
95
|
}}
|
|
95
96
|
className={getClass(getBlockClass(props), className)}
|
|
96
97
|
noValidate={true}
|
package/ui/notice/Notices.md
CHANGED
|
@@ -8,7 +8,7 @@ Renders the global list of active notices and subscribes to incoming `"notice"`
|
|
|
8
8
|
- Notices auto-dismiss after a short delay unless they carry a `"loading"` status.
|
|
9
9
|
- Backed by the `NOTICES` store singleton; for advanced use you can keep a reference to a notice to update or close it manually.
|
|
10
10
|
- The list shows in the bottom-right corner. Set `position` to `"top-left"`, `"top-center"`, `"top-right"`, `"bottom-left"`, `"bottom-center"`, or `"bottom-right"` to choose a different place.
|
|
11
|
-
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
11
|
+
- Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). `Notices` renders the store inside transitions, so a notice animates with no `startTransition()` of your own. A single `<Notice>` knows nothing about transitions, the same as `<Dialog>`. A new notice slides in from the side of its corner, and a closed notice slides out to that side. In a centred list, notices slide in and out from the top or bottom edge. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
|
|
12
12
|
- With reduced motion, notices fade in and out in place, and the others move at once. A browser without view transitions shows the changes at once.
|
|
13
13
|
|
|
14
14
|
## Usage
|