Dialog
A modal dialog with role="dialog". Use it for content the user works with at their own pace, such as forms, details, and notices. For confirmations that interrupt the user and require an immediate answer, use AlertDialog.
View in Storybook (opens in a new tab)
Installation
import { Dialog } from "@ginga-ui/core";Basic usage
A simple dialog example.
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { PanelTop, X } from "lucide-react";
import styles from "./dialog.module.css";
export function BasicExample() {
return (
<DialogTrigger>
<Button variant="filled" startIcon={<PanelTop />}>
Open dialog
</Button>
<Modal>
<Dialog>
<DialogTitle>Welcome</DialogTitle>
<p>This is a basic dialog.</p>
<div className={styles.actions}>
<Button slot="close" variant="outline" startIcon={<X />}>
Close
</Button>
</div>
</Dialog>
</Modal>
</DialogTrigger>
);
}With a form
An example of a form inside a dialog. Passing a function as children gives you close, which closes the dialog on submit.
import { Button, Dialog, DialogTitle, DialogTrigger, FormControl, Input, Modal } from "@ginga-ui/core";
import { Plus, UserPlus } from "lucide-react";
import styles from "./dialog.module.css";
export function FormExample() {
return (
<DialogTrigger>
<Button variant="filled" startIcon={<UserPlus />}>
Sign up
</Button>
<Modal>
<Dialog>
{({ close }) => (
<form
onSubmit={(e) => {
e.preventDefault();
close();
}}
>
<DialogTitle>Create account</DialogTitle>
<div className={styles.formFields}>
<FormControl label="Name">
<Input type="text" autoComplete="name" />
</FormControl>
<FormControl label="Email address">
<Input type="email" autoComplete="email" />
</FormControl>
<FormControl label="Password">
<Input type="password" autoComplete="new-password" />
</FormControl>
</div>
<div className={styles.actions}>
<Button slot="close" variant="outline">
Cancel
</Button>
<Button type="submit" variant="filled" startIcon={<Plus />}>
Create
</Button>
</div>
</form>
)}
</Dialog>
</Modal>
</DialogTrigger>
);
}Notice
A dialog that shows information to read. For confirmations that interrupt the user and require an immediate answer, use AlertDialog instead.
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { Check, Megaphone } from "lucide-react";
import styles from "./dialog.module.css";
export function NoticeExample() {
return (
<DialogTrigger>
<Button variant="outline" startIcon={<Megaphone />}>
Important notice
</Button>
<Modal>
<Dialog>
<DialogTitle>System maintenance</DialogTitle>
<p>
System maintenance is scheduled for December 20, 2024, from 2:00 to
4:00 AM. The service will be unavailable during this time.
</p>
<div className={styles.actions}>
<Button slot="close" variant="filled" startIcon={<Check />}>
Got it
</Button>
</div>
</Dialog>
</Modal>
</DialogTrigger>
);
}Props
DialogTrigger
Accepts the props of React Aria's DialogTrigger (opens in a new tab).
Modal
| Name | Type | Default | Description |
|---|---|---|---|
dismissable | boolean | false | Closes the modal when the user clicks outside it. |
overlayClassName | string | - | Class name added to the overlay behind the modal. |
className | string | ((renderProps) => string) | - | Class name added to the modal element, not the overlay. |
render | (props, renderProps) => ReactElement | - | Replaces the modal element. Like className, it applies to the modal, not the overlay. |
Also accepts the props of React Aria's ModalOverlay (opens in a new tab).
Dialog
Accepts the props of React Aria's Dialog (opens in a new tab).
DialogTitle
Accepts the props of React Aria's Heading (opens in a new tab).