shelving 1.326.0 → 1.328.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.
Files changed (63) hide show
  1. package/docs/llms-full.txt +377 -21
  2. package/docs/ui/BackSwipe.md +50 -0
  3. package/docs/ui/Dialog.md +10 -6
  4. package/docs/ui/DialogCloseButton.md +5 -2
  5. package/docs/ui/DialogControl.md +25 -0
  6. package/docs/ui/DialogControlContext.md +6 -0
  7. package/docs/ui/Modal.md +5 -1
  8. package/docs/ui/Notice.md +2 -0
  9. package/docs/ui/NoticeProps.md +2 -0
  10. package/docs/ui/Notices.md +1 -0
  11. package/docs/ui/SwipeDirection.md +12 -0
  12. package/docs/ui/SwipeOptions.md +34 -0
  13. package/docs/ui/TransitionScrub/cancel.md +14 -0
  14. package/docs/ui/TransitionScrub/finish.md +12 -0
  15. package/docs/ui/TransitionScrub/seek.md +13 -0
  16. package/docs/ui/TransitionScrub.md +68 -0
  17. package/docs/ui/useSwipe.md +92 -0
  18. package/docs/ui.md +8 -2
  19. package/package.json +1 -1
  20. package/ui/dialog/Dialog.d.ts +9 -5
  21. package/ui/dialog/Dialog.js +44 -15
  22. package/ui/dialog/Dialog.md +6 -4
  23. package/ui/dialog/Dialog.module.css +1 -1
  24. package/ui/dialog/Dialog.tsx +77 -30
  25. package/ui/dialog/DialogControl.d.ts +14 -0
  26. package/ui/dialog/DialogControl.js +4 -0
  27. package/ui/dialog/DialogControl.ts +18 -0
  28. package/ui/dialog/Dialogs.js +3 -2
  29. package/ui/dialog/Dialogs.tsx +3 -2
  30. package/ui/dialog/Modal.d.ts +2 -1
  31. package/ui/dialog/Modal.js +18 -2
  32. package/ui/dialog/Modal.md +4 -1
  33. package/ui/dialog/Modal.module.css +42 -0
  34. package/ui/dialog/Modal.tsx +19 -1
  35. package/ui/notice/Notice.d.ts +4 -2
  36. package/ui/notice/Notice.js +2 -2
  37. package/ui/notice/Notice.tsx +5 -1
  38. package/ui/notice/Notices.js +15 -5
  39. package/ui/notice/Notices.md +1 -0
  40. package/ui/notice/Notices.tsx +18 -5
  41. package/ui/router/BackSwipe.d.ts +13 -0
  42. package/ui/router/BackSwipe.js +61 -0
  43. package/ui/router/BackSwipe.md +26 -0
  44. package/ui/router/BackSwipe.ts +61 -0
  45. package/ui/router/index.d.ts +1 -0
  46. package/ui/router/index.js +1 -0
  47. package/ui/router/index.ts +1 -0
  48. package/ui/transition/TransitionScrub.d.ts +51 -0
  49. package/ui/transition/TransitionScrub.js +151 -0
  50. package/ui/transition/TransitionScrub.md +25 -0
  51. package/ui/transition/TransitionScrub.test.ts +28 -0
  52. package/ui/transition/TransitionScrub.ts +158 -0
  53. package/ui/transition/index.d.ts +2 -0
  54. package/ui/transition/index.js +2 -0
  55. package/ui/transition/index.tsx +2 -0
  56. package/ui/transition/useSwipe.d.ts +57 -0
  57. package/ui/transition/useSwipe.js +188 -0
  58. package/ui/transition/useSwipe.md +59 -0
  59. package/ui/transition/useSwipe.ts +240 -0
  60. package/docs/ui/useTransitionValue.md +0 -28
  61. package/ui/transition/useTransitionValue.d.ts +0 -12
  62. package/ui/transition/useTransitionValue.js +0 -16
  63. package/ui/transition/useTransitionValue.ts +0 -18
package/docs/ui/Dialog.md CHANGED
@@ -3,21 +3,24 @@
3
3
  - Kind: component
4
4
  - Import: `import { Dialog } from "shelving/ui";`
5
5
 
6
- Modal `<dialog>` element that opens on mount and includes a close button.
6
+ Modal `<dialog>` element that opens on mount.
7
7
 
8
- - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
8
+ - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, or the Escape key.
9
+ - It has no close button. Give the content an explicit button that closes it (for example "OK"), or add a `<DialogCloseButton>`.
9
10
  - 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
11
  - 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
12
  - A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
12
13
  - 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
14
  - 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
15
  - Wraps content in `<Suspense>` so lazy children can stream in.
16
+ - With `onClose`, a `<Modal>` pinned to an edge can swipe it away. During the swipe the dialog is hidden in an `<Activity>`, not unmounted, so a cancelled swipe keeps its state.
15
17
 
16
- A native `<dialog>` element opened in modal mode. It opens via `showModal()` when mounted and includes a built-in close button, so it works equally well mounted declaratively in the tree or pushed imperatively through a `DialogsStore`.
18
+ A native `<dialog>` element opened in modal mode. It opens via `showModal()` when mounted, so it works equally well mounted declaratively in the tree or pushed imperatively through a `DialogsStore`.
17
19
 
18
20
  **Things to know:**
19
21
 
20
- - Closes on a tap anywhere on it, the Escape key, or the built-in `<DialogCloseButton>` (an X icon, top-right).
22
+ - Closes on a tap anywhere on it, or the Escape key.
23
+ - It has no close button. Give the content an explicit button that closes it (for example "OK"), or add a `<DialogCloseButton>` anywhere inside it. That button is an X icon fixed to the top-right corner.
21
24
  - A tap on a control (`<button>`, `<input>`, `<select>`, `<textarea>`, `<label>`) does not close it. A tap anywhere inside a `<Modal>` panel does not close it either, so a form in a `<Modal>` is safe. A tap on a link or a `<nav>` button always closes it.
22
25
  - Children render inside a `<Suspense>` boundary, so lazy content can stream in.
23
26
  - 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.
@@ -33,6 +36,7 @@ A native `<dialog>` element opened in modal mode. It opens via `showModal()` whe
33
36
  - A `Dialog` you mount from a store read with `useStore()` never animates. `useStore()` applies each change at once, so `startTransition()` around the store write does not help.
34
37
  - To open a dialog from app code, use `requireDialogs()` and `DialogsStore.show()`. Pass the `DialogsStore` into any function that opens one.
35
38
  - A browser without view transitions shows and hides the dialog at once.
39
+ - With `onClose`, a pinned `<Modal>` inside can swipe the dialog away. During the swipe, the dialog is hidden in a React `<Activity>`, not unmounted, so a swipe that goes back shows it again with its state (typed text, scroll place).
36
40
  - Pair with `DialogsStore`, `<DialogsContext>`, and `<Dialogs>` to open dialogs imperatively from anywhere in the app.
37
41
 
38
42
  ## Usage
@@ -96,7 +100,7 @@ function DeleteButton({ onConfirm }: { onConfirm: () => void }) {
96
100
 
97
101
  ## Styling
98
102
 
99
- `Dialog` paints the full-screen overlay and resets the browser's default `<dialog>` border, size limits, and `::backdrop`. Transparent borders as wide as the screen's safe areas keep the content and the close button clear of the notch, rounded corners and home bar. The inner panel comes from its children, usually `<Modal>`. Override these hooks at `:root` (or any ancestor scope) to retheme.
103
+ `Dialog` paints the full-screen overlay and resets the browser's default `<dialog>` border, size limits, and `::backdrop`. Transparent borders as wide as the screen's safe areas keep the content and any `<DialogCloseButton>` clear of the notch, rounded corners and home bar. The inner panel comes from its children, usually `<Modal>`. Override these hooks at `:root` (or any ancestor scope) to retheme.
100
104
 
101
105
  | Variable | Styles | Default |
102
106
  | ----------------------- | -------------------------------------------------------------- | ----------------------------- |
@@ -105,7 +109,7 @@ function DeleteButton({ onConfirm }: { onConfirm: () => void }) {
105
109
  | `--dialog-width` | Width of the centred content, and so of a centred `<Modal>` | `var(--width-narrow)` (36rem) |
106
110
  | `--dialog-background` | Overlay fill behind the content | `var(--color-backdrop)` |
107
111
  | `--dialog-color` | Text colour directly on the overlay | `var(--tint-100)` (white) |
108
- | `--dialog-close-offset` | Inset of the close button from the top-right corner | `var(--space-small)` (12px) |
112
+ | `--dialog-close-offset` | Inset of a `<DialogCloseButton>` from the top-right corner | `var(--space-small)` (12px) |
109
113
 
110
114
  The fade uses the `fade` class from `<FadeTransition>`, so `--fade-transition-duration` sets its length. It runs only as the dialog opens and closes; an open dialog stays still while other dialogs open and close.
111
115
 
@@ -4,8 +4,10 @@
4
4
  - Import: `import { DialogCloseButton } from "shelving/ui";`
5
5
 
6
6
  Button that closes its wrapping `<dialog>`, showing an X icon by default.
7
- - Styled with the shared `Button` classes (positioning comes from the `<Dialog>`'s own `.close` wrapper rules).
8
- - `plain` by default so only the icon shows until hover or focus — pass `plain={false}` for a solid button.
7
+ - A `<Dialog>` has no close button of its own. Put this anywhere inside the dialog to add one.
8
+ - It is fixed to the top-right corner of the screen, clear of the safe areas.
9
+ - Styled with the shared `Button` classes.
10
+ - `plain` and `small` by default, so only a small icon shows until hover or focus. Pass `plain={false}` for a solid button, or `small={false}` for a normal size.
9
11
 
10
12
  ## Signatures
11
13
 
@@ -13,6 +15,7 @@ Button that closes its wrapping `<dialog>`, showing an X icon by default.
13
15
  DialogCloseButton({
14
16
  children = <CloseIcon />,
15
17
  plain = true,
18
+ small = true,
16
19
  className,
17
20
  ...variants
18
21
  }: DialogCloseButtonProps): ReactElement
@@ -0,0 +1,25 @@
1
+ # DialogControl
2
+
3
+ - Kind: interface
4
+ - Import: `import { DialogControl } from "shelving/ui";`
5
+
6
+ Controls for the nearest `<Dialog>`, so a `<Modal>` inside it can swipe it away.
7
+ - Internal: not exported from the `shelving/ui` barrel.
8
+
9
+ ## Signatures
10
+
11
+ ```ts
12
+ {
13
+ readonly hide: () => void;
14
+ readonly show: () => Promise<void>;
15
+ readonly close: () => void;
16
+ }
17
+ ```
18
+
19
+ ## Properties
20
+
21
+ | Property | Type | Description |
22
+ | --- | --- | --- |
23
+ | `hide` | `() => void` | Hide the dialog in a `"dialog"` transition, so its exit transition runs. It stays mounted, with its state. Read only. |
24
+ | `show` | `() => Promise<void>` | Show the hidden dialog again at once, with no transition. Resolves after React commits it. Read only. |
25
+ | `close` | `() => void` | Close the dialog for real (calls its `onClose`). Read only. |
@@ -0,0 +1,6 @@
1
+ # DialogControlContext
2
+
3
+ - Kind: constant
4
+ - Import: `import { DialogControlContext } from "shelving/ui";`
5
+
6
+ Context with the controls for the nearest `<Dialog>`, or `undefined` outside one (or in a `<Dialog>` with no `onClose`).
package/docs/ui/Modal.md CHANGED
@@ -8,6 +8,7 @@ Styled `<aside>` panel for content inside a `<Dialog>`, with dark text on a ligh
8
8
  - Centred by default. It fades in and out with its `<Dialog>`.
9
9
  - Has a `--shadow-large` drop shadow by default. Set `shadow="none"`, `shadow="small"` or `shadow="normal"` to change it.
10
10
  - `top`, `right`, `bottom`, or `left` pins it to that edge. It then takes its own layer in the `<Dialog>` view transition, and slides in from that edge and out to it.
11
+ - A pinned panel in a `<Dialog>` with `onClose` can be swiped toward its edge to close the dialog. The swipe scrubs the same slide, and shows a grab handle on the inner side. A swipe that goes back closes nothing, and the dialog keeps its state.
11
12
 
12
13
  The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the content a shadowed surface with dark text on a light fill.
13
14
 
@@ -24,6 +25,8 @@ The panel inside a `<Dialog>`. `<Dialog>` dims the page; `Modal` gives the conte
24
25
  - 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
26
  - 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
27
  - 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`).
28
+ - In a `<Dialog>` with `onClose` (every dialog from `DialogsStore.show()`), a pinned panel can be swiped toward its edge to close the dialog: down for `bottom`, up for `top`, and so on. The swipe scrubs the same slide-out with the finger, through `useSwipe()`. Release past about a third, or flick, to close. Otherwise the panel slides back, and the dialog keeps its state.
29
+ - A swipeable panel shows a grab handle: a short rounded bar on the side away from its edge.
27
30
 
28
31
  ## Usage
29
32
 
@@ -133,8 +136,9 @@ A link click inside a `<Dialog>` closes it, so the menu slides out as the page c
133
136
  | `--modal-max-height` | Maximum height of a `top` or `bottom` panel (it scrolls past this) | `100%` |
134
137
  | `--modal-transition-duration` | Length of the slide for a pinned panel. Keep it the same as `--fade-transition-duration`, so the panel and the `<Dialog>` overlay finish together | `var(--duration-fast)` (150ms) |
135
138
  | `--modal-shadow` | Drop shadow (the `shadow` variant wins over it) | `var(--shadow-large)` |
139
+ | `--modal-handle-color` | Colour of the grab handle on a swipeable pinned panel | `var(--tint-80)` |
136
140
 
137
- **Global tokens it reads** — move these to retheme broadly: the tint ladder `--tint-00` / `--tint-80` / `--tint-100`, plus `--width-narrow`, `--space-normal`, `--radius-normal`, `--shadow-large`, and `--duration-fast`.
141
+ **Global tokens it reads** — move these to retheme broadly: the tint ladder `--tint-00` / `--tint-80` / `--tint-100`, plus `--width-narrow`, `--space-xsmall`, `--space-normal`, `--radius-normal`, `--shadow-large`, and `--duration-fast`.
138
142
 
139
143
 
140
144
  ## Signatures
package/docs/ui/Notice.md CHANGED
@@ -62,6 +62,7 @@ Notice({
62
62
  children, //
63
63
  icon,
64
64
  className,
65
+ ref,
65
66
  ...props
66
67
  }: NoticeProps): void
67
68
  ```
@@ -72,3 +73,4 @@ Notice({
72
73
  | --- | --- | --- |
73
74
  | `props` | `NoticeProps` | |
74
75
  | `.icon` | `ReactElement \| false \| undefined` | Icon for the notice (or `null` or `false` to hide the icon, defaults to `<StatusIcon>`). Optional. |
76
+ | `.ref` | `Ref<HTMLElement> \| undefined` | Ref to the notice's `<aside>` element. Optional. |
@@ -11,6 +11,7 @@ Props for `<Notice>` — flex/colour/status styling variants, optional `children
11
11
  ```ts
12
12
  {
13
13
  icon?: ReactElement | false | undefined;
14
+ ref?: Ref<HTMLElement> | undefined;
14
15
  }
15
16
  ```
16
17
 
@@ -19,3 +20,4 @@ Props for `<Notice>` — flex/colour/status styling variants, optional `children
19
20
  | Property | Type | Description |
20
21
  | --- | --- | --- |
21
22
  | `icon` | `ReactElement \| false \| undefined` | Icon for the notice (or `null` or `false` to hide the icon, defaults to `<StatusIcon>`). Optional. |
23
+ | `ref` | `Ref<HTMLElement> \| undefined` | Ref to the notice's `<aside>` element. Optional. |
@@ -19,6 +19,7 @@ Renders the global list of active notices and subscribes to incoming `"notice"`
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
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
  - The list has its own layer in every view transition, so it stays still above a page that slides under it.
22
+ - Swipe a notice toward the side it slides out to (up or down in a centred list) to close it. The swipe scrubs the slide-out with the finger, through `useSwipe()`. A swipe that goes back adds the notice back.
22
23
  - 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.
23
24
 
24
25
  ## Usage
@@ -0,0 +1,12 @@
1
+ # SwipeDirection
2
+
3
+ - Kind: type
4
+ - Import: `import { SwipeDirection } from "shelving/ui";`
5
+
6
+ Which way the finger moves to complete a swipe.
7
+
8
+ ## Signatures
9
+
10
+ ```ts
11
+ "up" | "down" | "left" | "right"
12
+ ```
@@ -0,0 +1,34 @@
1
+ # SwipeOptions
2
+
3
+ - Kind: interface
4
+ - Import: `import { SwipeOptions } from "shelving/ui";`
5
+
6
+ Options for `useSwipe()`.
7
+
8
+ ## Signatures
9
+
10
+ ```ts
11
+ {
12
+ readonly direction: SwipeDirection;
13
+ readonly start: () => unknown;
14
+ readonly cancel: () => PromiseLike<void> | void;
15
+ readonly commit?: (() => void) | undefined;
16
+ readonly edge?: number | undefined;
17
+ readonly distance?: number | undefined;
18
+ readonly ignore?: string | undefined;
19
+ readonly disabled?: boolean | undefined;
20
+ }
21
+ ```
22
+
23
+ ## Properties
24
+
25
+ | Property | Type | Description |
26
+ | --- | --- | --- |
27
+ | `direction` | `SwipeDirection` | Which way the finger moves to complete the swipe. Read only. |
28
+ | `start` | `() => unknown` | Make the change that starts the view transition, for example close a dialog inside `startTransition()`. - Return `false` to start no swipe (for example when there is nothing to go back to). Read only. |
29
+ | `cancel` | `() => PromiseLike<void> \| void` | Put back the state from before `start()`, when the swipe is cancelled. - Return a promise that resolves after React commits, so the transition ends on the right page. Read only. |
30
+ | `commit` | `(() => void) \| undefined` | Finish the change for real, after the slide reaches the end. Read only. Optional. |
31
+ | `edge` | `number \| undefined` | Start only when the finger goes down this close to the screen edge it moves away from, in pixels (for example `24` for swipe-back). - Leave it out to start anywhere on the target. Read only. Optional. |
32
+ | `distance` | `number \| undefined` | Part of the target's size a slow drag must pass to complete. Read only. Defaults to `0.35`. |
33
+ | `ignore` | `string \| undefined` | Never start a swipe on an element inside one that matches this selector, for example `"nav"`. Read only. Optional. |
34
+ | `disabled` | `boolean \| undefined` | Turn the swipe off. Read only. Optional. |
@@ -0,0 +1,14 @@
1
+ # TransitionScrub.cancel()
2
+
3
+ - Kind: method
4
+ - Member of: `TransitionScrub`
5
+
6
+ Play the transition back to the start, run `undo()`, and then end the transition.
7
+ - `undo()` must put back the state from before the update, so the page matches the start of the transition when it ends.
8
+ - If `undo()` returns a promise (for example one that resolves after React commits), it waits for it before it ends the transition.
9
+
10
+ ## Signatures
11
+
12
+ ```ts
13
+ cancel(undo: () => PromiseLike<void> | void): Promise<void>
14
+ ```
@@ -0,0 +1,12 @@
1
+ # TransitionScrub.finish()
2
+
3
+ - Kind: method
4
+ - Member of: `TransitionScrub`
5
+
6
+ Play the transition from where it is to the end, then end it.
7
+
8
+ ## Signatures
9
+
10
+ ```ts
11
+ finish(): Promise<void>
12
+ ```
@@ -0,0 +1,13 @@
1
+ # TransitionScrub.seek()
2
+
3
+ - Kind: method
4
+ - Member of: `TransitionScrub`
5
+
6
+ Move the transition to a point, from `0` (start) to `1` (end).
7
+ - Safe to call before the transition is ready: it moves there as soon as it is.
8
+
9
+ ## Signatures
10
+
11
+ ```ts
12
+ seek(progress: number): void
13
+ ```
@@ -0,0 +1,68 @@
1
+ # TransitionScrub
2
+
3
+ - Kind: class
4
+ - Import: `import { TransitionScrub } from "shelving/ui";`
5
+
6
+ Take manual control of the view transition that an update starts.
7
+
8
+ - The constructor runs `update()` at once and catches the next view transition that starts (for example the one React starts for a state change inside `startTransition()`).
9
+ - When the transition is ready, it pauses every animation of the transition, so `seek()` can move it by hand.
10
+ - `finish()` plays it to the end. `cancel()` plays it back to the start, runs an undo, and ends it.
11
+ - Without view transitions (older browsers), or if `update()` starts none, the update still happens: `seek()` does nothing, `finish()` ends at once, and `cancel()` just runs the undo.
12
+ - If `update()` returns `false`, nothing is caught, and `started` is `false`.
13
+ - Only one view transition runs at a time. A new one skips this one, which ends it at its end state.
14
+
15
+ Take manual control of the view transition that an update starts: move it to any point, then play it to the end, or play it back and undo the update.
16
+
17
+ **Things to know:**
18
+
19
+ - The constructor runs the update at once and catches the next view transition that starts. With React, that is the transition React starts for a state change inside `startTransition()`.
20
+ - When the transition is ready, every animation in it is paused. `TransitionScrub.seek()` moves them, from `0` (start) to `1` (end).
21
+ - `TransitionScrub.finish()` plays from where it is to the end. `TransitionScrub.cancel()` plays back to the start, runs your undo, waits for it, and then ends the transition. The undo must put the page back as it was before the update.
22
+ - If the update returns `false`, nothing is caught and `TransitionScrub.started` is `false`.
23
+ - Without view transitions, or when the update starts none within a second, the update still happens: `seek()` does nothing, `finish()` ends at once, and `cancel()` only runs the undo.
24
+ - Only one view transition runs at a time. Another one that starts skips this one to its end.
25
+ - `useSwipe()` drives a `TransitionScrub` from a finger. Use the class directly for other inputs, such as a slider.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { TransitionScrub } from "shelving/ui";
31
+
32
+ const scrub = new TransitionScrub(() => dialogs.delete(dialog));
33
+ scrub.seek(0.4); // 40% of the way through the close.
34
+ await scrub.finish(); // Play to the end.
35
+ // Or play back to the start and undo the change:
36
+ await scrub.cancel(() => dialogs.add(dialog));
37
+ ```
38
+
39
+
40
+ ## Signatures
41
+
42
+ ```ts
43
+ new TransitionScrub(update: () => unknown)
44
+ ```
45
+
46
+ ## Parameters
47
+
48
+ | Param | Type | Description |
49
+ | --- | --- | --- |
50
+ | `update` | `() => unknown` | A change that starts a view transition. Return `false` to start nothing. |
51
+
52
+ ## Returns
53
+
54
+ | Type | Description |
55
+ | --- | --- |
56
+ | `TransitionScrub` | |
57
+
58
+ ## Properties
59
+
60
+ | Property | Type | Description |
61
+ | --- | --- | --- |
62
+ | `started` | `boolean` | `false` if `update()` returned `false`, so there is nothing to scrub. Read only. |
63
+
64
+ ## Methods
65
+
66
+ - [TransitionScrub.seek()](TransitionScrub/seek.md): Move the transition to a point, from 0 (start) to 1 (end).
67
+ - [TransitionScrub.finish()](TransitionScrub/finish.md): Play the transition from where it is to the end, then end it.
68
+ - [TransitionScrub.cancel()](TransitionScrub/cancel.md): Play the transition back to the start, run undo(), and then end the transition.
@@ -0,0 +1,92 @@
1
+ # useSwipe()
2
+
3
+ - Kind: function
4
+ - Import: `import { useSwipe } from "shelving/ui";`
5
+
6
+ Swipe a target to complete a change, and scrub the change's view transition with the finger.
7
+
8
+ - When the finger moves the right way, it calls `start()` and catches the view transition that starts, with `TransitionScrub`.
9
+ - While the finger moves, the transition follows it. Progress is the drag distance divided by the target's size in that direction (the screen size for `document`).
10
+ - On release, past `distance` or after a flick, it plays the transition to the end and calls `commit()`. Otherwise it plays it back and calls `cancel()`.
11
+ - It does not start when the finger is on a field, inside an element that can still scroll that way, or inside a `<dialog>` that does not hold the target.
12
+ - Only one swipe runs at a time. A swipe on `document` listens first, so an edge swipe wins over a swipe on an element below it.
13
+
14
+ Swipe an element (or the whole page) to make a change, and scrub the change's view transition with the finger.
15
+
16
+ **Things to know:**
17
+
18
+ - Give it three functions. `start` makes the change, inside a transition, so React starts a view transition. `cancel` puts back the state from before. `commit` finishes the change for real after the slide ends.
19
+ - `start` runs when the finger has moved a few pixels in `direction`. Return `false` from it to start no swipe.
20
+ - While the finger moves, the transition follows it through `TransitionScrub`. Progress is the drag distance divided by the target's size in that direction (the screen size for `document`).
21
+ - On release past `distance` (default 35%), or after a flick, the slide plays to the end and `commit` runs. Otherwise the slide plays back and `cancel` runs. Return a promise from `cancel` that resolves after React commits, so the slide ends on the right state.
22
+ - It does not start on a field, inside an element that can still scroll the other way, or inside a `<dialog>` that does not hold the target.
23
+ - `edge` limits the start to a strip along the screen edge the finger moves away from, for example `24` for swipe-back from the left edge.
24
+ - Only one swipe runs at a time. A swipe on `document` decides first, so an edge swipe wins over a swipe on an element below it.
25
+ - The swipe keeps working when `start` takes the touched element out of the page. If the content can keep state, hide it in a React `<Activity>` instead of unmounting it, so `cancel` can show it again as it was.
26
+
27
+ ## Usage
28
+
29
+ ### Swipe a panel down to close it
30
+
31
+ `<Modal>` does this for every pinned panel in a `<Dialog>`:
32
+
33
+ ```tsx
34
+ const ref = useRef<HTMLElement>(null);
35
+ useSwipe(ref, {
36
+ direction: "down",
37
+ start: () => dialog.hide(), // Hide in a transition.
38
+ cancel: () => dialog.show(), // Show again at once.
39
+ commit: () => dialog.close(),
40
+ });
41
+ ```
42
+
43
+ ### Swipe a notice away
44
+
45
+ A notice holds no state, so removing it and adding it back is enough:
46
+
47
+ ```tsx
48
+ useSwipe(ref, {
49
+ direction: "right",
50
+ start: () => notice.close(),
51
+ cancel: () => NOTICES.add(notice),
52
+ });
53
+ ```
54
+
55
+ ### Swipe between tabs
56
+
57
+ ```tsx
58
+ useSwipe(ref, {
59
+ direction: "left",
60
+ start: () => {
61
+ if (!next) return false;
62
+ startTransition(() => {
63
+ addTransitionType("tab-forward");
64
+ setShown(next);
65
+ });
66
+ },
67
+ cancel: () => flushSync(() => setShown(current)),
68
+ commit: () => setTab(next),
69
+ });
70
+ ```
71
+
72
+
73
+ ## Signatures
74
+
75
+ ```ts
76
+ useSwipe(target: RefObject<Element | null> | Document, options: SwipeOptions): void
77
+ ```
78
+
79
+ ## Parameters
80
+
81
+ | Param | Type | Description |
82
+ | --- | --- | --- |
83
+ | `target` | `RefObject<Element \| null> \| Document` | The element to swipe, or `document` for the whole page. |
84
+ | `options` | `SwipeOptions` | What the swipe does. |
85
+ | `.direction` | `SwipeDirection` | Which way the finger moves to complete the swipe. Read only. |
86
+ | `.start` | `() => unknown` | Make the change that starts the view transition, for example close a dialog inside `startTransition()`. - Return `false` to start no swipe (for example when there is nothing to go back to). Read only. |
87
+ | `.cancel` | `() => PromiseLike<void> \| void` | Put back the state from before `start()`, when the swipe is cancelled. - Return a promise that resolves after React commits, so the transition ends on the right page. Read only. |
88
+ | `.commit` | `(() => void) \| undefined` | Finish the change for real, after the slide reaches the end. Read only. Optional. |
89
+ | `.edge` | `number \| undefined` | Start only when the finger goes down this close to the screen edge it moves away from, in pixels (for example `24` for swipe-back). - Leave it out to start anywhere on the target. Read only. Optional. |
90
+ | `.distance` | `number \| undefined` | Part of the target's size a slow drag must pass to complete. Read only. Defaults to `0.35`. |
91
+ | `.ignore` | `string \| undefined` | Never start a swipe on an element inside one that matches this selector, for example `"nav"`. Read only. Optional. |
92
+ | `.disabled` | `boolean \| undefined` | Turn the swipe off. Read only. Optional. |
package/docs/ui.md CHANGED
@@ -105,7 +105,7 @@ The components below are listed in the index following this page; this is the sh
105
105
  - [Clickable](ui/Clickable.md): Render an <a href="">, a <button>, or a plain <span>, from the href, onClick and disabled props.
106
106
  - [FullscreenButton](ui/FullscreenButton.md): Button to toggle the surrounding <figure> element or <body> element in/out of fullscreen mode.
107
107
  - [RetryButton](ui/RetryButton.md): Button that retries the nearest <Catcher> error boundary when clicked.
108
- - [Dialog](ui/Dialog.md): Modal <dialog> element that opens on mount and includes a close button.
108
+ - [Dialog](ui/Dialog.md): Modal <dialog> element that opens on mount.
109
109
  - [DialogCloseButton](ui/DialogCloseButton.md): Button that closes its wrapping <dialog>, showing an X icon by default.
110
110
  - [DialogsContext](ui/DialogsContext.md): Provider that creates a fresh DialogsStore and shares it with its subtree.
111
111
  - [Dialogs](ui/Dialogs.md): Render the open dialogs from the current DialogsContext.
@@ -198,6 +198,7 @@ The components below are listed in the index following this page; this is the sh
198
198
  - [HTML](ui/HTML.md): Render the full <html> document shell wrapping <head> and <body>.
199
199
  - [Page](ui/Page.md): Wrap a single page (or screen) within an app, applying its meta and head tags.
200
200
  - [BackButton](ui/BackButton.md): Back button for the current stack.
201
+ - [BackSwipe](ui/BackSwipe.md): Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
201
202
  - [Navigation](ui/Navigation.md): Top-level navigation provider, with one stack of pages for each tab.
202
203
  - [RouteCache](ui/RouteCache.md): Keep-alive page cache for the pages in the navigation stacks. Put it in a layout's content slot, around a <Scroll vertical cover> box.
203
204
  - [Router](ui/Router.md): Match the current URL against routes and render the matched element.
@@ -283,7 +284,7 @@ The components below are listed in the index following this page; this is the sh
283
284
  - [getStrokeClass()](ui/getStrokeClass.md): Get the border-thickness class for a component from its stroke variant prop.
284
285
  - [getTypographyClass()](ui/getTypographyClass.md): Get the typography class for a component from its typographic variant props.
285
286
  - [getWidthClass()](ui/getWidthClass.md): Get the width class for a component from its width / grow variant props.
286
- - [useTransitionValue()](ui/useTransitionValue.md): Read a store's value, and re-render inside startTransition() when it changes, so <ViewTransition> boundaries animate.
287
+ - [useSwipe()](ui/useSwipe.md): Swipe a target to complete a change, and scrub the change's view transition with the finger.
287
288
  - [setTransitionType()](ui/setTransitionType.md): Type-safe passthrough for React's addTransitionType() that checks type is one of our known view-transition types.
288
289
  - [useTreeMap()](ui/useTreeMap.md): Use the flattened tree lookup map from context.
289
290
  - [getTreeElement()](ui/getTreeElement.md): Resolve a reference string to its tree element — by exact key first, then by a normalised key with the prose display decorations stripped.
@@ -327,6 +328,7 @@ The components below are listed in the index following this page; this is the sh
327
328
  - [NoticesStore](ui/NoticesStore.md): Store holding the live list of NoticeStore notices currently shown.
328
329
  - [NoticeStore](ui/NoticeStore.md): Store holding a single notice's content and status, owned by a NoticesStore.
329
330
  - [NavigationSequence](ui/NavigationSequence.md): Sequence of navigation events that drives browser history and keeps a stack of pages for each tab.
331
+ - [TransitionScrub](ui/TransitionScrub.md): Take manual control of the view transition that an update starts.
330
332
 
331
333
  ## Interfaces
332
334
 
@@ -363,6 +365,7 @@ The components below are listed in the index following this page; this is the sh
363
365
  - [SubmitButtonProps](ui/SubmitButtonProps.md): Component props for <SubmitButton>, a form submit button.
364
366
  - [DialogProps](ui/DialogProps.md): Props for <Dialog> — optional children content and an onClose callback.
365
367
  - [DialogCloseButtonProps](ui/DialogCloseButtonProps.md): Props for <DialogCloseButton> — button styling variants and optional children to override the X icon.
368
+ - [DialogControl](ui/DialogControl.md): Controls for the nearest <Dialog>, so a <Modal> inside it can swipe it away.
366
369
  - [DialogsContextProps](ui/DialogsContextProps.md): Props for <DialogsContext> — the children subtree the dialogs store is provided to.
367
370
  - [DialogsProps](ui/DialogsProps.md): Props for <Dialogs> — takes no props (branded empty interface).
368
371
  - [ModalVariants](ui/ModalVariants.md): Variant props for <Modal> — pin the panel to one edge of the screen.
@@ -493,6 +496,7 @@ The components below are listed in the index following this page; this is the sh
493
496
  - [HorizontalTransitionProps](ui/HorizontalTransitionProps.md): Props for the HorizontalTransition component — the shared transition variant props.
494
497
  - [TransitionVariants](ui/TransitionVariants.md): Variant props shared by every transition component.
495
498
  - [TransitionProps](ui/TransitionProps.md): React props for <Transition> component.
499
+ - [SwipeOptions](ui/SwipeOptions.md): Options for useSwipe().
496
500
  - [VerticalTransitionProps](ui/VerticalTransitionProps.md): Props for the VerticalTransition component — the shared transition variant props.
497
501
  - [TreeAppProps](ui/TreeAppProps.md): Props for the TreeApp component — the tree to render plus optional extra routes and app meta.
498
502
  - [TreeBreadcrumbsProps](ui/TreeBreadcrumbsProps.md): Props for the TreeBreadcrumbs component — typography, space, and flex variant props.
@@ -541,6 +545,7 @@ The components below are listed in the index following this page; this is the sh
541
545
  - [CaseVariant](ui/CaseVariant.md): Allowed values for text case for components that support TypographyVariants
542
546
  - [FontVariant](ui/FontVariant.md): Allowed values for font family for components that support TypographyVariants
543
547
  - [WidthVariant](ui/WidthVariant.md): Enumerated width selectable via the width variant prop.
548
+ - [SwipeDirection](ui/SwipeDirection.md): Which way the finger moves to complete a swipe.
544
549
  - [TransitionClasses](ui/TransitionClasses.md): Map of view-transition types to their CSS class names in { type: className } format.
545
550
  - [TransitionType](ui/TransitionType.md): Known view-transition type names that all transitions support — the keys of TransitionClasses.
546
551
  - [Classes](ui/Classes.md): Set of classnames that can be joined into a single className string.
@@ -556,6 +561,7 @@ The components below are listed in the index following this page; this is the sh
556
561
  ## Constants
557
562
 
558
563
  - [RetryContext](ui/RetryContext.md): Context for providing a "retry" callback to descendant <RetryButton> elements.
564
+ - [DialogControlContext](ui/DialogControlContext.md): Context with the controls for the nearest <Dialog>, or undefined outside one (or in a <Dialog> with no onClose).
559
565
  - [DOCUMENTATION_LIVE_RULE](ui/DOCUMENTATION_LIVE_RULE.md): Markup rule that renders a fenced code block with a live flag as a <DocumentationLive> example, e.g. tsx live "Card with a link" `.
560
566
  - [DOCUMENTATION_MARKUP_RULES](ui/DOCUMENTATION_MARKUP_RULES.md): Markup rules for docs site content: DOCUMENTATION_LIVE_RULE then TREE_MARKUP_RULES, so fenced code blocks with a live flag run.
561
567
  - [PLAYGROUND_FRAME_PATH](ui/PLAYGROUND_FRAME_PATH.md): Path of the frame page that runs playground code, relative to the docs site root.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.326.0",
3
+ "version": "1.328.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,15 +12,17 @@ export interface DialogProps extends OptionalChildProps {
12
12
  onClose?: Callback;
13
13
  }
14
14
  /**
15
- * Modal `<dialog>` element that opens on mount and includes a close button.
15
+ * Modal `<dialog>` element that opens on mount.
16
16
  *
17
- * - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, the close button, or the Escape key.
17
+ * - Opens via `showModal()` when mounted, and closes on a tap anywhere on it, or the Escape key.
18
+ * - It has no close button. Give the content an explicit button that closes it (for example "OK"), or add a `<DialogCloseButton>`.
18
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.
19
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.
20
21
  * - A change inside an open dialog (new content, a Suspense reveal) runs no view transition. The page ignores taps while one runs.
21
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.
22
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.
23
24
  * - Wraps content in `<Suspense>` so lazy children can stream in.
25
+ * - With `onClose`, a `<Modal>` pinned to an edge can swipe it away. During the swipe the dialog is hidden in an `<Activity>`, not unmounted, so a cancelled swipe keeps its state.
24
26
  *
25
27
  * @kind component
26
28
  * @see https://shelving.cc/ui/Dialog
@@ -47,10 +49,12 @@ export interface DialogCloseButtonProps extends ButtonVariants, OptionalChildPro
47
49
  }
48
50
  /**
49
51
  * Button that closes its wrapping `<dialog>`, showing an X icon by default.
50
- * - Styled with the shared `Button` classes (positioning comes from the `<Dialog>`'s own `.close` wrapper rules).
51
- * - `plain` by default so only the icon shows until hover or focus — pass `plain={false}` for a solid button.
52
+ * - A `<Dialog>` has no close button of its own. Put this anywhere inside the dialog to add one.
53
+ * - It is fixed to the top-right corner of the screen, clear of the safe areas.
54
+ * - Styled with the shared `Button` classes.
55
+ * - `plain` and `small` by default, so only a small icon shows until hover or focus. Pass `plain={false}` for a solid button, or `small={false}` for a normal size.
52
56
  *
53
57
  * @kind component
54
58
  * @see https://shelving.cc/ui/DialogCloseButton
55
59
  */
56
- export declare function DialogCloseButton({ children, plain, className, ...variants }: DialogCloseButtonProps): ReactElement;
60
+ export declare function DialogCloseButton({ children, plain, small, className, ...variants }: DialogCloseButtonProps): ReactElement;