-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Quick nav and base content styles (#804)
- Loading branch information
Showing
25 changed files
with
1,099 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,63 @@ | ||
# Dialog | ||
|
||
<Subtitle>A popup that opens on top of the entire page.</Subtitle> | ||
|
||
<Demo path="./UnstyledDialogIntroduction" /> | ||
|
||
## Examples | ||
|
||
### State | ||
|
||
By default, Dialog is an uncontrolled component that manages its own state. Use `<Dialog.Trigger>` and `<Dialog.Close>` to open and close the dialog. | ||
|
||
```tsx title="Uncontrolled dialog" | ||
<Dialog.Root> | ||
<Dialog.Trigger>Open</Dialog.Trigger> | ||
<Dialog.Popup> | ||
<Dialog.Title>Example dialog</Dialog.Title> | ||
<Dialog.Close>Close</Dialog.Close> | ||
</Dialog.Popup> | ||
</Dialog.Root> | ||
``` | ||
|
||
Use `open` and `onOpenChange` props if you need to access or control the state of the dialog. | ||
|
||
```tsx title="Controlled dialog" | ||
const [open, setOpen] = React.useState(false); | ||
|
||
return ( | ||
<Dialog.Root open={open} onOpenChange={setOpen}> | ||
<Dialog.Trigger>Open</Dialog.Trigger> | ||
<Dialog.Popup> | ||
<Dialog.Title>Demo dialog</Dialog.Title> | ||
<Dialog.Close>Close</Dialog.Close> | ||
<form | ||
// Close the dialog once data is submitted | ||
onSubmit={async () => { | ||
await submitData(); | ||
setOpen(false); | ||
}} | ||
> | ||
... | ||
</form> | ||
</Dialog.Popup> | ||
</Dialog.Root> | ||
); | ||
``` | ||
|
||
It’s also common to use `onOpenChange` if your app needs to do something when the dialog is closed or opened. This is recommended over `React.useEffect` when reacting to state changes. | ||
|
||
```tsx title="Running code when dialog state changes" | ||
<Dialog.Root | ||
open={open} | ||
onOpenChange={(open) => { | ||
// Do stuff when the dialog is closed | ||
if (!open) { | ||
doStuff(); | ||
} | ||
// Set the new state | ||
setOpen(open); | ||
}} | ||
> | ||
``` | ||
|
||
### Syntax | ||
|
||
The `<Dialog.Trigger>` part renders a native `<button>` element. Don’t take this paragraph too seriously though, I’m just testing the inline syntax highlighting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.