Theme Switcher

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

import {
	AlertDialog,
	AlertDialogAction,
	AlertDialogBody,
	AlertDialogCancel,
	AlertDialogContent,
	AlertDialogDescription,
	AlertDialogFooter,
	AlertDialogHeader,
	AlertDialogIcon,
	AlertDialogTitle,
	AlertDialogTrigger,
} from "@ngrok/mantle/alert-dialog";
import { Button } from "@ngrok/mantle/button";

<AlertDialog priority="info">
	<AlertDialogTrigger asChild>
		<Button type="button" appearance="outlined">
			Show Info Alert Dialog
		</Button>
	</AlertDialogTrigger>

	<AlertDialogContent>
		<AlertDialogIcon />
		<AlertDialogBody>
			<AlertDialogHeader>
				<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
				<AlertDialogDescription>
					 Proident quis nisi tempor irure sunt ut minim occaecat mollit sunt.
				</AlertDialogDescription>
			</AlertDialogHeader>
			<AlertDialogFooter>
				<AlertDialogCancel type="button">Cancel</AlertDialogCancel>
				<AlertDialogAction type="button">Continue</AlertDialogAction>
			</AlertDialogFooter>
		</AlertDialogBody>
	</AlertDialogContent>
</AlertDialog>

<AlertDialog priority="danger">
	<AlertDialogTrigger asChild>
		<Button type="button" appearance="outlined">
			With a form
		</Button>
	</AlertDialogTrigger>
	<AlertDialogContent>
		<AlertDialogIcon />
		<AlertDialogBody>
			<AlertDialogHeader>
				<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
				<AlertDialogDescription>
					 Proident quis nisi tempor irure sunt ut minim occaecat mollit sunt.
				</AlertDialogDescription>
			</AlertDialogHeader>
			<AlertDialogFooter>
				<AlertDialogCancel type="button">Cancel</AlertDialogCancel>
				<form
					onSubmit={(event) => {
						event.preventDefault();
						window.alert("Form submitted!");
					}}
				>
					<AlertDialogAction type="submit">Continue</AlertDialogAction>
				</form>
			</AlertDialogFooter>
		</AlertDialogBody>
	</AlertDialogContent>
</AlertDialog>

API Reference

The AlertDialog components are built on top of Radix Alert Dialog.

AlertDialog

The root component for the Alert Dialog.

All props from Radix Dialog.Root, plus:

PropTypeDefaultDescription
priority
  • info
  • danger

Indicates the importance or impact level of the AlertDialog, affecting its color and styling to communicate its purpose to the user.

AlertDialogTrigger

A button that opens the Alert Dialog.

Radix Dialog.Trigger props.

AlertDialogContent

The popover Alert Dialog container. Renders on top of the overlay and is centered in the viewport.

Radix Dialog.Content props, plus:

PropTypeDefaultDescription
preferredWidth
stringmax-w-md

The preferred width of the AlertDialogContent as a tailwind max-w- class.

By default, a AlertDialogContent's content width is responsive with a default preferred width: the maxiumum width of the AlertDialogContent.

AlertDialogBody

Contains the main content of the alert dialog.

The AlertDialogBody accepts the following props in addition to the standard HTML div attributes.

PropTypeDefaultDescription
asChild
booleanfalse

Use the asChild prop to compose the AlertDialogBody styling and functionality onto alternative element types or your own React components.

AlertDialogHeader

Contains the header content of the dialog, including the title and description.

The AlertDialogHeader accepts the following props in addition to the standard HTML div attributes.

PropTypeDefaultDescription
asChild
booleanfalse

Use the asChild prop to compose the AlertDialogHeader styling and functionality onto alternative element types or your own React components.

Contains the footer content of the dialog, including the action and cancel buttons.

The AlertDialogFooter accepts the following props in addition to the standard HTML div attributes.

PropTypeDefaultDescription
asChild
booleanfalse

Use the asChild prop to compose the AlertDialogFooter styling and functionality onto alternative element types or your own React components.

AlertDialogTitle

An accessible name to be announced when the dialog is opened.

Alternatively, you can provide aria-label or aria-labelledby to AlertDialogContent and exclude this component.

Radix Dialog.Title props.

AlertDialogDescription

An accessible description to be announced when the dialog is opened.

Alternatively, you can provide aria-describedby to AlertDialogContent and exclude this component.

Radix Dialog.Description props.

AlertDialogAction

A button that confirms the Alert Dialog action. Will default to appearance="filled", as well as the priority color from the AlertDialog. Does not close the alert dialog by default.

These buttons should be distinguished visually from the AlertDialogCancel button.

Composes around the mantle Button component.

Same props as the Button component.

AlertDialogCancel

A button that closes the dialog and cancels the action. Will default to appearance="outlined" and priority="neutral".

This button should be distinguished visually from AlertDialogAction buttons.

Composes around the mantle Button component.

Same props as the Button component.