shelving 1.323.2 → 1.324.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/guides/building-with-shelving.md +3 -3
- package/docs/llms-full.txt +345 -149
- package/docs/react/SequenceTransitionOptions.md +24 -0
- package/docs/react/useSequenceTransition.md +70 -0
- package/docs/react.md +2 -0
- package/docs/ui/BackButton.md +1 -1
- package/docs/ui/Head.md +1 -1
- package/docs/ui/HorizontalTransition.md +1 -1
- package/docs/ui/Image.md +3 -0
- package/docs/ui/Meta.md +2 -0
- package/docs/ui/Navigation.md +18 -17
- package/docs/ui/NavigationContext.md +2 -2
- package/docs/ui/NavigationDirection.md +12 -0
- package/docs/ui/NavigationEntryState.md +3 -3
- package/docs/ui/NavigationEvent.md +28 -0
- package/docs/ui/{NavigationStore → NavigationSequence}/back.md +6 -5
- package/docs/ui/NavigationSequence/committed.md +13 -0
- package/docs/ui/NavigationSequence/current.md +13 -0
- package/docs/ui/{NavigationStore → NavigationSequence}/forward.md +4 -4
- package/docs/ui/{NavigationStore → NavigationSequence}/history.md +3 -3
- package/docs/ui/{NavigationStore → NavigationSequence}/listen.md +3 -3
- package/docs/ui/NavigationSequence/publish.md +14 -0
- package/docs/ui/{NavigationStore → NavigationSequence}/replace.md +4 -4
- package/docs/ui/NavigationSequence.md +187 -0
- package/docs/ui/RouteCache.md +16 -15
- package/docs/ui/RouteCacheProps.md +1 -1
- package/docs/ui/Router.md +2 -2
- package/docs/ui/Transition.md +1 -1
- package/docs/ui/VerticalTransition.md +1 -1
- package/docs/ui/mergeMeta.md +1 -0
- package/docs/ui/requireContext.md +1 -1
- package/docs/ui/requireNavigation.md +3 -3
- package/docs/ui.md +6 -6
- package/package.json +1 -1
- package/react/index.d.ts +1 -0
- package/react/index.js +1 -0
- package/react/useSequenceTransition.d.ts +38 -0
- package/react/useSequenceTransition.js +44 -0
- package/ui/block/Image.d.ts +3 -0
- package/ui/block/Image.js +18 -1
- package/ui/block/Image.module.css +27 -0
- package/ui/block/Image.tsx +24 -1
- package/ui/page/Head.d.ts +1 -1
- package/ui/page/Head.js +9 -4
- package/ui/page/Head.tsx +8 -4
- package/ui/router/BackButton.js +6 -3
- package/ui/router/BackButton.md +1 -1
- package/ui/router/BackButton.tsx +6 -3
- package/ui/router/Navigation.d.ts +5 -5
- package/ui/router/Navigation.js +24 -49
- package/ui/router/Navigation.md +13 -12
- package/ui/router/Navigation.tsx +25 -59
- package/ui/router/NavigationContext.d.ts +7 -15
- package/ui/router/NavigationContext.js +4 -13
- package/ui/router/NavigationContext.tsx +7 -17
- package/ui/router/{NavigationStore.d.ts → NavigationSequence.d.ts} +93 -51
- package/ui/router/{NavigationStore.js → NavigationSequence.js} +132 -80
- package/ui/router/NavigationSequence.md +129 -0
- package/ui/router/{NavigationStore.test.ts → NavigationSequence.test.ts} +126 -61
- package/ui/router/{NavigationStore.tsx → NavigationSequence.tsx} +160 -92
- package/ui/router/RouteCache.d.ts +8 -7
- package/ui/router/RouteCache.js +34 -29
- package/ui/router/RouteCache.md +9 -8
- package/ui/router/RouteCache.tsx +39 -36
- package/ui/router/Router.d.ts +2 -2
- package/ui/router/Router.js +3 -5
- package/ui/router/Router.md +1 -1
- package/ui/router/Router.tsx +4 -5
- package/ui/router/StackButton.d.ts +1 -1
- package/ui/router/StackButton.js +5 -7
- package/ui/router/StackButton.tsx +6 -7
- package/ui/router/index.d.ts +1 -1
- package/ui/router/index.js +1 -1
- package/ui/router/index.ts +1 -1
- package/ui/transition/HorizontalTransition.md +1 -1
- package/ui/transition/Transition.md +1 -1
- package/ui/transition/VerticalTransition.md +1 -1
- package/ui/util/meta.d.ts +2 -0
- package/ui/util/meta.ts +2 -0
- package/ui/util/requireContext.md +1 -1
- package/docs/ui/NavigationPosition.md +0 -24
- package/docs/ui/NavigationPositionContext.md +0 -8
- package/docs/ui/NavigationStore.md +0 -164
- package/ui/router/NavigationStore.md +0 -110
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# NavigationStore
|
|
2
|
-
|
|
3
|
-
- Kind: class
|
|
4
|
-
- Import: `import { NavigationStore } from "shelving/ui";`
|
|
5
|
-
- Extends: `URLStore`
|
|
6
|
-
|
|
7
|
-
Store that holds the current navigation URL, drives browser history, and keeps a stack of pages for each tab.
|
|
8
|
-
|
|
9
|
-
- Extends `URLStore`, so its `value` is the current URL.
|
|
10
|
-
- With the browser Navigation API, each history entry saves a `NavigationEntryState`, and each stack is read from `navigation.entries()` when it is needed. Nothing else is kept.
|
|
11
|
-
- `stack` is a sub-store that holds the root of the current stack, or `null` for a floating page. It only changes when the stack changes.
|
|
12
|
-
- A page outside the listed stacks is floating: its stack is `null`. The floating stack has no root page and no tab.
|
|
13
|
-
- In a listed stack, depth `0` is always the stack's root path.
|
|
14
|
-
- Without the Navigation API (older browsers and server renders) there are no stacks: `stack` stays the starting stack, `history()` is empty, and `stack` arguments are ignored.
|
|
15
|
-
- Owned by `<Navigation>`. Read it with `requireNavigation()`.
|
|
16
|
-
|
|
17
|
-
The store that holds the current URL, drives browser history, and keeps one stack of pages for each tab. It extends `URLStore`, so its `value` is the current URL. `<Navigation>` owns it. Read it with `requireNavigation()`, and do not make your own.
|
|
18
|
-
|
|
19
|
-
**Things to know:**
|
|
20
|
-
|
|
21
|
-
- `NavigationStore.stacks` is the root path of each stack, in tab order, from the `stacks` prop on `<Navigation>`. `/` is a normal stack root, like any other path.
|
|
22
|
-
- A page that is not in a listed stack is **floating**: its stack is `null`. See [Floating pages](#floating-pages).
|
|
23
|
-
- In a listed stack, depth `0` is always the stack's root path. A deeper page always has the root below it.
|
|
24
|
-
- `NavigationStore.stack` is a sub-store that holds the root of the current stack, or `null` on a floating page. It changes only when the stack changes, so `useStore(nav.stack)` re-renders only on a tab change.
|
|
25
|
-
- `NavigationStore.path` is the current path relative to the app root, without its `?query`.
|
|
26
|
-
- `NavigationStore.history()` returns the pages in the current stack (or a given stack), root first.
|
|
27
|
-
- `NavigationStore.position` is the current stack and depth, the depth of the top page of each stack, and the page before this one. `<RouteCache>` and `<BackButton>` use it.
|
|
28
|
-
- All URLs resolve against the store's `base`. Each method also takes a full same-origin URL.
|
|
29
|
-
- Without the browser Navigation API there is no stack history: `stack` stays the starting stack, `history()` returns `[]`, `position` is `undefined`, and every `stack` argument is ignored. `forward()` and `back()` push a history entry, and `replace()` replaces it.
|
|
30
|
-
|
|
31
|
-
## Methods
|
|
32
|
-
|
|
33
|
-
| Method | What it does | Slide |
|
|
34
|
-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
|
|
35
|
-
| `forward(href, stack?)` | Opens `href` as a new page on top of the stack. If `href` is the top page of another stack, it switches to that stack (a tab switch). If `href` is the current URL, it is a replace. | Forward. Across stacks, by tab order. |
|
|
36
|
-
| `back(href, stack?)` | Goes back to `href`. If `href` is in the stack, the stack goes back to it, and the pages above it leave the stack. If `href` is the root of the stack, the stack goes to its root. Otherwise `href` takes the place of the top page of the stack. | Back |
|
|
37
|
-
| `replace(href, stack?)` | Changes the URL of the current page. The stack, the depth and the mounted page stay the same. No new history entry. With another `stack`, the page moves into that stack: at its root if `href` is the root, else on top of its pages. | None |
|
|
38
|
-
| `history(stack?)` | Returns the pages in `stack`, root first. | — |
|
|
39
|
-
|
|
40
|
-
`stack` defaults to the current stack. Pass `null` to name the floating stack.
|
|
41
|
-
|
|
42
|
-
## Floating pages
|
|
43
|
-
|
|
44
|
-
A page changes stack only when you say so: with a `<StackButton>`, or with a `stack` argument to `forward()`, `back()` or `replace()`. Links never change stack. The page the app opens at starts in the `stack` set on `<Navigation>` (or the surrounding `<Meta>`), else it **floats**: its stack is `null`. For example: a deep link into the app, a fresh open of `/post/9`, or a login page.
|
|
45
|
-
|
|
46
|
-
- The floating stack is outside every tab. It has no root page and no `<StackButton>`, so no stack button is selected on a floating page.
|
|
47
|
-
- Links from a floating page push deeper in the floating stack, even a link to a stack root.
|
|
48
|
-
- To leave the floating stack, tap a `<StackButton>`, or name the stack. To move a page back into it, pass `null` as the `stack`.
|
|
49
|
-
- `<RouteCache>` gives floating pages no protection: they are dropped like any other page past `maxCached`.
|
|
50
|
-
- With no `stacks`, every page floats.
|
|
51
|
-
|
|
52
|
-
## Opening the app
|
|
53
|
-
|
|
54
|
-
- To select a tab when the app starts, set `stack` on `<Navigation>`. The app decides which stack the opening URL belongs to. After a reload, each history entry keeps the stack it had.
|
|
55
|
-
- A deep page the app opens at, in a listed stack, starts at depth 1, so the stack root is its parent. A `<StackButton>` or a back gesture then goes to the root. A stack root starts at depth 0.
|
|
56
|
-
- A `stack` that is not in `stacks` is ignored: the page floats.
|
|
57
|
-
|
|
58
|
-
For example, a login page sends the user home after they log in, and names the Home stack:
|
|
59
|
-
|
|
60
|
-
```tsx
|
|
61
|
-
const nav = requireNavigation();
|
|
62
|
-
nav.replace("/home", "/home");
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## How stacks work
|
|
66
|
-
|
|
67
|
-
The store saves a small state on each browser history entry: the `stack` the page is in, and its `depth` in that stack (`0` is the root). See `NavigationEntryState`. To read a stack, the store walks back through the browser history from the current entry. It takes the newest entry in that stack, then the newest earlier entry with a lower depth, and so on down to depth `0`.
|
|
68
|
-
|
|
69
|
-
Why depth? A browser history entry cannot be changed or removed. So when you go back in one stack while another stack's pages are after it in the history, the store cannot go back in the browser. It pushes a new entry for the page you went back to, at that page's depth. The pages that were above it now have a higher depth than the newest entry, so they are no longer in the stack.
|
|
70
|
-
|
|
71
|
-
For example, with tabs `/home` and `/profile`:
|
|
72
|
-
|
|
73
|
-
| Step | New history entry | Home stack | Profile stack |
|
|
74
|
-
| ------------------- | ------------------------ | ----------------------- | ------------- |
|
|
75
|
-
| Start at `/home` | `/home` (depth 0) | `/home` | — |
|
|
76
|
-
| Open a post | `/home/post/1` (depth 1) | `/home`, `/home/post/1` | — |
|
|
77
|
-
| Tap the Profile tab | `/profile` (depth 0) | `/home`, `/home/post/1` | `/profile` |
|
|
78
|
-
| Tap the Home tab | `/home/post/1` (depth 1) | `/home`, `/home/post/1` | `/profile` |
|
|
79
|
-
| Tap the back button | `/home` (depth 0) | `/home` | `/profile` |
|
|
80
|
-
|
|
81
|
-
When the page you go back to is the entry just before the current one, `back()` goes back in the browser history and pushes nothing.
|
|
82
|
-
|
|
83
|
-
The browser back and forward buttons walk the history entries one at a time, as usual. Each entry knows its stack and depth, so the stacks are always right and the slide goes the right way.
|
|
84
|
-
|
|
85
|
-
## Usage
|
|
86
|
-
|
|
87
|
-
```tsx
|
|
88
|
-
import { Button, requireNavigation } from "shelving/ui";
|
|
89
|
-
|
|
90
|
-
function LogoutButton() {
|
|
91
|
-
const nav = requireNavigation();
|
|
92
|
-
return <Button onClick={() => nav.replace("/login")}>Log out</Button>;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Read the current stack in a component:
|
|
97
|
-
|
|
98
|
-
```tsx
|
|
99
|
-
import { useStore } from "shelving/react";
|
|
100
|
-
import { requireNavigation } from "shelving/ui";
|
|
101
|
-
|
|
102
|
-
function TabTitle() {
|
|
103
|
-
const nav = requireNavigation();
|
|
104
|
-
const stack = useStore(nav.stack).value;
|
|
105
|
-
return <h1>{stack === "/profile" ? "Profile" : "Home"}</h1>;
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
List the pages in a stack (for example, for breadcrumbs):
|
|
110
|
-
|
|
111
|
-
```tsx
|
|
112
|
-
const nav = requireNavigation();
|
|
113
|
-
nav.history("/home"); // ["/home", "/home/post/1", "/home/post/1/comments"]
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Make a store by hand only in tests:
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
import { NavigationStore } from "shelving/ui";
|
|
120
|
-
|
|
121
|
-
// URL, root, starting stack, then the stacks in tab order.
|
|
122
|
-
const nav = new NavigationStore("https://example.com/home", "https://example.com/", "/home", "/home", "/profile");
|
|
123
|
-
nav.forward("/home/post/1");
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
## Signatures
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
new NavigationStore(url: PossibleURL = typeof window === "undefined" ? "/" : window.location.href, base?: PossibleURL, stack: AbsolutePath | null = null, ...stacks: AbsolutePath[])
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Parameters
|
|
134
|
-
|
|
135
|
-
| Param | Type | Description |
|
|
136
|
-
| --- | --- | --- |
|
|
137
|
-
| `url` | `PossibleURL` | Defaults to `typeof window === "undefined" ? "/" : window.location.href`. |
|
|
138
|
-
| `base` | `PossibleURL` | Optional. |
|
|
139
|
-
| `stack` | `AbsolutePath \| null` | Defaults to `null`. |
|
|
140
|
-
| `stacks` | `AbsolutePath[]` | |
|
|
141
|
-
|
|
142
|
-
## Returns
|
|
143
|
-
|
|
144
|
-
| Type | Description |
|
|
145
|
-
| --- | --- |
|
|
146
|
-
| `NavigationStore` | |
|
|
147
|
-
|
|
148
|
-
## Properties
|
|
149
|
-
|
|
150
|
-
| Property | Type | Description |
|
|
151
|
-
| --- | --- | --- |
|
|
152
|
-
| `stacks` | `readonly AbsolutePath[]` | Root path of each stack, in tab order. With none, every page floats. Read only. |
|
|
153
|
-
| `stack` | `Store<AbsolutePath \| null>` | Root path of the current stack, or `null` for a floating page. - It starts at the `stack` given to the constructor (default `null`). Without the Navigation API, it stays there. Read only. |
|
|
154
|
-
| `transition` | `TransitionType \| null` | Transition type of the most recent change, read by `<Navigation>` when the value changes. - `null` means no transition: a replace, a change the browser already animated (for example a swipe-back), or no Navigation API. Defaults to `null`. |
|
|
155
|
-
| `path` | `AbsolutePath \| undefined` | Path of the current URL relative to the app root (without its `?query`), or `undefined` if the URL is outside the app. Read only. |
|
|
156
|
-
| `position` | `NavigationPosition \| undefined` | Where the app is now: the current stack and depth, and the top depth of each stack. Read only. |
|
|
157
|
-
|
|
158
|
-
## Methods
|
|
159
|
-
|
|
160
|
-
- [NavigationStore.listen()](NavigationStore/listen.md): Start listening to the browser (back, forward and swipe).
|
|
161
|
-
- [NavigationStore.history()](NavigationStore/history.md): Get the pages in a stack, root first, or every page in every stack.
|
|
162
|
-
- [NavigationStore.forward()](NavigationStore/forward.md): Go forward to a URL, as a link does.
|
|
163
|
-
- [NavigationStore.back()](NavigationStore/back.md): Go back to a URL, as a back button does.
|
|
164
|
-
- [NavigationStore.replace()](NavigationStore/replace.md): Replace the current URL, with no transition.
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# NavigationStore
|
|
2
|
-
|
|
3
|
-
The store that holds the current URL, drives browser history, and keeps one stack of pages for each tab. It extends `URLStore`, so its `value` is the current URL. `<Navigation>` owns it. Read it with `requireNavigation()`, and do not make your own.
|
|
4
|
-
|
|
5
|
-
**Things to know:**
|
|
6
|
-
|
|
7
|
-
- `NavigationStore.stacks` is the root path of each stack, in tab order, from the `stacks` prop on `<Navigation>`. `/` is a normal stack root, like any other path.
|
|
8
|
-
- A page that is not in a listed stack is **floating**: its stack is `null`. See [Floating pages](#floating-pages).
|
|
9
|
-
- In a listed stack, depth `0` is always the stack's root path. A deeper page always has the root below it.
|
|
10
|
-
- `NavigationStore.stack` is a sub-store that holds the root of the current stack, or `null` on a floating page. It changes only when the stack changes, so `useStore(nav.stack)` re-renders only on a tab change.
|
|
11
|
-
- `NavigationStore.path` is the current path relative to the app root, without its `?query`.
|
|
12
|
-
- `NavigationStore.history()` returns the pages in the current stack (or a given stack), root first.
|
|
13
|
-
- `NavigationStore.position` is the current stack and depth, the depth of the top page of each stack, and the page before this one. `<RouteCache>` and `<BackButton>` use it.
|
|
14
|
-
- All URLs resolve against the store's `base`. Each method also takes a full same-origin URL.
|
|
15
|
-
- Without the browser Navigation API there is no stack history: `stack` stays the starting stack, `history()` returns `[]`, `position` is `undefined`, and every `stack` argument is ignored. `forward()` and `back()` push a history entry, and `replace()` replaces it.
|
|
16
|
-
|
|
17
|
-
## Methods
|
|
18
|
-
|
|
19
|
-
| Method | What it does | Slide |
|
|
20
|
-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
|
|
21
|
-
| `forward(href, stack?)` | Opens `href` as a new page on top of the stack. If `href` is the top page of another stack, it switches to that stack (a tab switch). If `href` is the current URL, it is a replace. | Forward. Across stacks, by tab order. |
|
|
22
|
-
| `back(href, stack?)` | Goes back to `href`. If `href` is in the stack, the stack goes back to it, and the pages above it leave the stack. If `href` is the root of the stack, the stack goes to its root. Otherwise `href` takes the place of the top page of the stack. | Back |
|
|
23
|
-
| `replace(href, stack?)` | Changes the URL of the current page. The stack, the depth and the mounted page stay the same. No new history entry. With another `stack`, the page moves into that stack: at its root if `href` is the root, else on top of its pages. | None |
|
|
24
|
-
| `history(stack?)` | Returns the pages in `stack`, root first. | — |
|
|
25
|
-
|
|
26
|
-
`stack` defaults to the current stack. Pass `null` to name the floating stack.
|
|
27
|
-
|
|
28
|
-
## Floating pages
|
|
29
|
-
|
|
30
|
-
A page changes stack only when you say so: with a `<StackButton>`, or with a `stack` argument to `forward()`, `back()` or `replace()`. Links never change stack. The page the app opens at starts in the `stack` set on `<Navigation>` (or the surrounding `<Meta>`), else it **floats**: its stack is `null`. For example: a deep link into the app, a fresh open of `/post/9`, or a login page.
|
|
31
|
-
|
|
32
|
-
- The floating stack is outside every tab. It has no root page and no `<StackButton>`, so no stack button is selected on a floating page.
|
|
33
|
-
- Links from a floating page push deeper in the floating stack, even a link to a stack root.
|
|
34
|
-
- To leave the floating stack, tap a `<StackButton>`, or name the stack. To move a page back into it, pass `null` as the `stack`.
|
|
35
|
-
- `<RouteCache>` gives floating pages no protection: they are dropped like any other page past `maxCached`.
|
|
36
|
-
- With no `stacks`, every page floats.
|
|
37
|
-
|
|
38
|
-
## Opening the app
|
|
39
|
-
|
|
40
|
-
- To select a tab when the app starts, set `stack` on `<Navigation>`. The app decides which stack the opening URL belongs to. After a reload, each history entry keeps the stack it had.
|
|
41
|
-
- A deep page the app opens at, in a listed stack, starts at depth 1, so the stack root is its parent. A `<StackButton>` or a back gesture then goes to the root. A stack root starts at depth 0.
|
|
42
|
-
- A `stack` that is not in `stacks` is ignored: the page floats.
|
|
43
|
-
|
|
44
|
-
For example, a login page sends the user home after they log in, and names the Home stack:
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
const nav = requireNavigation();
|
|
48
|
-
nav.replace("/home", "/home");
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## How stacks work
|
|
52
|
-
|
|
53
|
-
The store saves a small state on each browser history entry: the `stack` the page is in, and its `depth` in that stack (`0` is the root). See `NavigationEntryState`. To read a stack, the store walks back through the browser history from the current entry. It takes the newest entry in that stack, then the newest earlier entry with a lower depth, and so on down to depth `0`.
|
|
54
|
-
|
|
55
|
-
Why depth? A browser history entry cannot be changed or removed. So when you go back in one stack while another stack's pages are after it in the history, the store cannot go back in the browser. It pushes a new entry for the page you went back to, at that page's depth. The pages that were above it now have a higher depth than the newest entry, so they are no longer in the stack.
|
|
56
|
-
|
|
57
|
-
For example, with tabs `/home` and `/profile`:
|
|
58
|
-
|
|
59
|
-
| Step | New history entry | Home stack | Profile stack |
|
|
60
|
-
| ------------------- | ------------------------ | ----------------------- | ------------- |
|
|
61
|
-
| Start at `/home` | `/home` (depth 0) | `/home` | — |
|
|
62
|
-
| Open a post | `/home/post/1` (depth 1) | `/home`, `/home/post/1` | — |
|
|
63
|
-
| Tap the Profile tab | `/profile` (depth 0) | `/home`, `/home/post/1` | `/profile` |
|
|
64
|
-
| Tap the Home tab | `/home/post/1` (depth 1) | `/home`, `/home/post/1` | `/profile` |
|
|
65
|
-
| Tap the back button | `/home` (depth 0) | `/home` | `/profile` |
|
|
66
|
-
|
|
67
|
-
When the page you go back to is the entry just before the current one, `back()` goes back in the browser history and pushes nothing.
|
|
68
|
-
|
|
69
|
-
The browser back and forward buttons walk the history entries one at a time, as usual. Each entry knows its stack and depth, so the stacks are always right and the slide goes the right way.
|
|
70
|
-
|
|
71
|
-
## Usage
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
import { Button, requireNavigation } from "shelving/ui";
|
|
75
|
-
|
|
76
|
-
function LogoutButton() {
|
|
77
|
-
const nav = requireNavigation();
|
|
78
|
-
return <Button onClick={() => nav.replace("/login")}>Log out</Button>;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Read the current stack in a component:
|
|
83
|
-
|
|
84
|
-
```tsx
|
|
85
|
-
import { useStore } from "shelving/react";
|
|
86
|
-
import { requireNavigation } from "shelving/ui";
|
|
87
|
-
|
|
88
|
-
function TabTitle() {
|
|
89
|
-
const nav = requireNavigation();
|
|
90
|
-
const stack = useStore(nav.stack).value;
|
|
91
|
-
return <h1>{stack === "/profile" ? "Profile" : "Home"}</h1>;
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
List the pages in a stack (for example, for breadcrumbs):
|
|
96
|
-
|
|
97
|
-
```tsx
|
|
98
|
-
const nav = requireNavigation();
|
|
99
|
-
nav.history("/home"); // ["/home", "/home/post/1", "/home/post/1/comments"]
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Make a store by hand only in tests:
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
import { NavigationStore } from "shelving/ui";
|
|
106
|
-
|
|
107
|
-
// URL, root, starting stack, then the stacks in tab order.
|
|
108
|
-
const nav = new NavigationStore("https://example.com/home", "https://example.com/", "/home", "/home", "/profile");
|
|
109
|
-
nav.forward("/home/post/1");
|
|
110
|
-
```
|