A window overlaid on either the primary window or another dialog window, rendering the content underneath inert. Built on top of Radix UI Dialog.
import { Dialog } from "@ngrok/mantle/dialog";
import { Button } from "@ngrok/mantle/button";
<Dialog.Root>
<Dialog.Trigger asChild>
<Button type="button">Open dialog</Button>
</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Are you absolutely sure?</Dialog.Title>
<Dialog.CloseIconButton />
</Dialog.Header>
<Dialog.Body>
This action cannot be undone. This will permanently delete your account and remove your data
from our servers.
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close asChild>
<Button type="button" priority="danger" appearance="filled">
Delete
</Button>
</Dialog.Close>
<Dialog.Close asChild>
<Button type="button" priority="neutral" appearance="outlined">
Cancel
</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>;When a dialog contains form inputs, browser autofill or password-manager plugins (e.g. 1Password) may render overlays as siblings to the dialog content. By default, clicking these overlays triggers onPointerDownOutside, which closes the dialog. Use isDialogOverlayTarget to prevent this:
import { Dialog, isDialogOverlayTarget } from "@ngrok/mantle/dialog";
<Dialog.Content
onPointerDownOutside={(event) => {
// Allow closing only when clicking the actual overlay backdrop,
// not browser autofill/password-manager popups
if (isDialogOverlayTarget(event.target)) {
return;
}
event.preventDefault();
}}
>
{/* dialog content with form inputs */}
</Dialog.Content>;In some cases, you might wish to have a tooltip over the dialog trigger. This is helpful if the dialog trigger is an IconButton and you wish to provide more context to what the button does. You can compose them both together to where the dialog trigger is also the tooltip trigger.
import { Dialog } from "@ngrok/mantle/dialog";
import { Button, IconButton } from "@ngrok/mantle/button";
import { Tooltip } from "@ngrok/mantle/tooltip";
import { TrashSimpleIcon } from "@phosphor-icons/react/TrashSimple";
<Dialog.Root>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Dialog.Trigger asChild>
<IconButton type="button" label="Delete" size="sm" icon={<TrashSimpleIcon />} />
</Dialog.Trigger>
</Tooltip.Trigger>
<Tooltip.Content>
<p>Delete</p>
</Tooltip.Content>
</Tooltip.Root>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Are you absolutely sure?</Dialog.Title>
<Dialog.CloseIconButton />
</Dialog.Header>
<Dialog.Body>
This action cannot be undone. This will permanently delete your account and remove your data
from our servers.
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close asChild>
<Button type="button" priority="danger" appearance="filled">
Delete
</Button>
</Dialog.Close>
<Dialog.Close asChild>
<Button type="button" priority="neutral" appearance="outlined">
Cancel
</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>;The root stateful component that manages the open/closed state of the dialog.
A button that opens the dialog.
The container for the dialog content. Renders on top of the overlay and is centered in the viewport.
Contains the header content of the dialog, including the title and close button.
Contains the main content of the dialog.
Contains the footer content of the dialog, including action buttons.
An accessible name to be announced when the dialog is opened.
An accessible description to be announced when the dialog is opened.
A button that closes the dialog when clicked.
An icon button that closes the dialog when clicked.