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 playground

About

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

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
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.

booleandefault false
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