Dialog
A modal that grows out of its trigger, traps focus and keeps its header and footer in view while long content scrolls. Alert mode guards destructive decisions; the confirm button handles async work and failure itself. Overlays.
Open playgroundAbout
Dialog is a React component in the Overlays category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { Dialog } from "@ashutoshswamy/smoui" and set trigger, title, onConfirm among its 9 props.
Install
npm i @ashutoshswamy/smouiUsage
import { Dialog } from "@ashutoshswamy/smoui";
<Dialog
alert
tone="danger"
trigger="Delete project"
title="Delete this project?"
description="This removes 12 files. You can restore it for 30 days."
confirmLabel="Delete"
onConfirm={() => api.deleteProject()} // resolve closes, reject stays open with an error
/>Props 9
- trigger / triggerClassName
The opening button. The dialog grows out of it.
ReactNode / string- title / description / children
Content. Title and description are wired to aria-labelledby and aria-describedby.
ReactNode- onConfirm
Shows built-in Cancel and Confirm buttons. A promise puts the button in a busy state; resolve closes, reject keeps it open with an error.
() => void | Promise<unknown>- confirmLabel / cancelLabel
Built-in button labels.
ReactNodedefault"Confirm" / "Cancel"- tone
Danger colours the confirm button red.
"default""danger"default"default"- alert
Role alertdialog. No close button, a click outside nudges instead of closing, Cancel takes focus.
booleandefaultfalse- size
Width: 380, 440 or 600px.
"sm""md""lg"default"md"- footer
Custom footer. Replaces the built-in buttons. Elements with data-close close the dialog.
ReactNode- open / onOpenChange
Controlled state (omit trigger to drive it yourself).
boolean / (open: boolean) => void
More overlays components
- CommandPaletteCmd+K palette. Type to filter, arrows move one highlight that stretches between rows, Enter runs.
- ConfirmPopoverA small are-you-sure that opens beside its button instead of taking over the page. A failed action stays open and says so.
- ContextMenuRight-click, long-press or press the Menu key for a menu that opens out of the exact point you pressed. It flips to stay on screen and moves with the arrow keys.
- DropdownA menu with one highlight that stretches between rows. Arrow keys, Home and End move it, Enter picks, Escape closes.
- HoverCardA card that opens when you rest on a name, stays while you move onto it and closes when you leave.
- LightboxA grid of pictures. Click one and it grows out of its place into a viewer; swipe, use arrows or keys to move on.