Skip to content

Commit 4e4642c

Browse files
committed
Update docs with v3 migration guide
1 parent 37944a9 commit 4e4642c

7 files changed

Lines changed: 512 additions & 1368 deletions

File tree

packages/docs-v3/src/content/docs/concepts/animations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Animations
55
It's a common UI pattern for dialogs to have entry and exit animations. In order to support exit animations,
66
React Dialog Async will not unmount the dialog immediately after it is closed.
77

8-
By default, this delay is set to `500ms`, which should be sufficient for most use cases. Generally exit animations are recommended to be under 150-200ms.
8+
By default, this delay is set to `300ms`, which should be sufficient for most use cases. Generally exit animations are recommended to be under 150-200ms.
99

1010
:::note
1111
Note that the promise returned by `dialog.open()` will still resolve immediately after the dialog is closed and is not affected by the delay.

packages/docs-v3/src/content/docs/guides/v3-migration.mdx

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,101 @@
22
title: Migrating to V3
33
---
44

5-
React Dialog Async V3 introduces a number of breaking changes, however most of these require minimal effort to migrate.
5+
Introducing React Dialog Async V3! This new major version includes an improved API, new features for more flexible use,
6+
and much more polished documentation.
7+
8+
## Why V3?
9+
React Dialog Async started out as a small library for personal use, first published over 4 years ago. At the time I was focused
10+
on a small set of features for solving my own personal use case. Over time it's grown to support a wider range of use cases, but
11+
the core API has remained largely unchanged since day one.
12+
13+
Over time as the library has matured, I've started to disagree with some of the original decisions I made. I've held off making
14+
any breaking changes, but I feel that now is the right time to pay down some technical debt, and bundle all of the breaking changes
15+
together into a newer, more polished version of the library.
16+
17+
[//]: # (# New Features)
18+
19+
[//]: # ()
20+
[//]: # (## Static Dialogs)
21+
22+
[//]: # ()
23+
[//]: # (## Lazy Loading)
24+
25+
## Breaking Changes
26+
27+
### `show` and `hide` methods removed from `useDialog()`
28+
29+
The methods returned by `useDialog()` have changed. `show` and `hide` were deprecated in `2.4.0`, and have been removed in `3.0.0` in favour of `open` and `close`.
30+
31+
```diff lang="tsx"
32+
33+
const myDialog = useDialog(MyDialog);
34+
35+
-await myDialog.show(...);
36+
+await myDialog.open(...);
37+
38+
-await myDialog.hide();
39+
+await myDialog.close();
40+
41+
```
42+
43+
### Updated Options for `useDialog()`
44+
45+
* `customKey` has been removed. This option was not used internally, and was a legacy option from early versions of the library.
46+
47+
* `hideOnHookUnmount` has been renamed to `persistOnUnmount`. This should be more intuitive, as setting this option to `true` will persist the dialog when the hook unmounts.
48+
49+
```diff lang="tsx"
50+
51+
const myDialog = useDialog(MyDialog, {
52+
- customKey: 'my-dialog',
53+
54+
- hideOnHookUnmount: false
55+
+ persistOnUnmount: true
56+
});
57+
58+
```
59+
60+
### `<DialogOutlet/>` is now required
61+
62+
In previous versions of the library, `<DialogOutlet/>` was optional, and if it was not required, dialogs would be rendered as children of the `<DialogProvider/>`.
63+
64+
In V3, this is not longer the case, and `<DialogOutlet/>` is now required for dialogs to render. If one is not found, an error will be thrown when attempting to open a dialog.
65+
66+
```diff lang="tsx"
67+
68+
<DialogProvider>
69+
<App />
70+
+ <DialogOutlet />
71+
</DialogProvider>
72+
```
73+
74+
### `mounted` prop removed from dialog components
75+
The `mounted` prop passed to dialog components has been removed. This prop was always set to `true`, which made it effectively useless.
76+
77+
```diff lang="tsx"
78+
- export const MyDialog = ({ mounted }: AsyncDialogProps) => {
79+
+ export const MyDialog = ({ }: AsyncDialogProps) => {
80+
// ...
81+
}
82+
```
83+
84+
### `open` and `focused` props renamed to `isOpen` and `isFocused`
85+
The `open` and `focused` props passed to dialog components have been renamed to `isOpen` and `isFocused` respectively. This is to make it more clear that these props are booleans, and to differentiate them from the `open()` method returned by `useDialog()`.
86+
87+
```diff lang="tsx"
88+
- export const MyDialog = ({ open, focused }: AsyncDialogProps) => {
89+
+ export const MyDialog = ({ isOpen, isFocused }: AsyncDialogProps) => {
90+
// ...
91+
}
92+
```
93+
94+
### defaultUnmountDelayInMs now defaults to 300ms
95+
96+
The `defaultUnmountDelayInMs` option for `<DialogProvider/>` now defaults to `300`. This is to provide a better out-of-the-box experience, as most dialogs will have some form of exit animation.
97+
98+
If you want to retain the previous behaviour, explicitly set this option to `0`.
99+
```diff lang="tsx"
100+
<DialogProvider
101+
+ defaultUnmountDelayInMs={0}
102+
/>

packages/docs-v3/src/content/docs/reference/components/dialog-provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function DialogProvider(props: DialogProviderProps): JSX.Element
2626
| Prop | Type | Default | Description |
2727
|-|-|---------|-----------|
2828
| `children` | `React.ReactNode` | - | Children |
29-
| `defaultUnmountDelayInMs` | `number` | `500` | Default delay in milliseconds to wait before unmounting a dialog after it is closed |
29+
| `defaultUnmountDelayInMs` | `number` | `300` | Default delay in milliseconds to wait before unmounting a dialog after it is closed |
3030

3131
## Source
3232

packages/react-dialog-async/src/DialogProvider/DialogProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '../context/DialogActionsContext.js';
1414

1515
export const DialogProvider = ({
16-
defaultUnmountDelayInMs,
16+
defaultUnmountDelayInMs = 300,
1717
children,
1818
}: DialogProviderProps) => {
1919
// This ref tracks timers for unmount dialogs after they're closed

packages/react-dialog-async/src/DialogProvider/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { PropsWithChildren } from 'react';
33
export interface DialogProviderProps extends PropsWithChildren {
44
/**
55
* The default delay in milliseconds to wait before unmounting a dialog after it's closed.
6+
* @default 300
67
*/
78
defaultUnmountDelayInMs?: number;
89
}

packages/react-dialog-async/src/useDialog/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ export type useDialogOptions<D, DE extends D | undefined> = {
33
* Default data to pass to the dialog when .open() is called
44
*/
55
defaultData?: DE;
6-
/**
7-
* A custom key to register this dialog against
8-
*/
9-
customKey?: string;
106
/**
117
* If specified, the dialog will remain mounted for this many milliseconds.
128
* Useful for allowing a close animation to play before unmounting the dialog.

0 commit comments

Comments
 (0)