Alert dialog
A modal that interrupts to confirm a destructive or irreversible action.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native <dialog>
- 9 parts, named exports
- role="alertdialog" with a name from the title and a description.
- Focus moves to the Cancel button on open and returns to the trigger on close.
- Escape cancels; focus is trapped; the page behind is inert.
- Styles in one file:
dialog.css
Import
import '@monoline/css';
import {AlertDialog} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add alert-dialog
Usage
import {AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Button} from '@monoline/react';
<AlertDialog>
<AlertDialogTrigger asChild><Button variant="danger">Delete project</Button></AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader><AlertDialogTitle>Delete this project?</AlertDialogTitle><AlertDialogDescription>All files and history are removed. This cannot be undone.</AlertDialogDescription></AlertDialogHeader>
<AlertDialogFooter><AlertDialogCancel>Keep it</AlertDialogCancel><AlertDialogAction>Delete project</AlertDialogAction></AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Anatomy
Import the parts you need and nest them like this.
import {AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel} from '@monoline/react';
<AlertDialog>
<AlertDialogTrigger />
<AlertDialogContent />
<AlertDialogHeader />
<AlertDialogFooter />
<AlertDialogTitle />
<AlertDialogDescription />
<AlertDialogAction />
<AlertDialogCancel />
</AlertDialog>
Examples
Confirm a deletion
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.command {
border-color: var(--accent);
}
Accessibility
- role="alertdialog" with a name from the title and a description.
- Focus moves to the Cancel button on open and returns to the trigger on close.
- Escape cancels; focus is trapped; the page behind is inert.
- Clicking the overlay does not close it.
Keyboard
| Keys | Action |
|---|---|
| Escape | Cancels |