# AlertDialog

> A confirmation dialog for consequential, hard-to-undo actions — fixed confirm/cancel actions, never dismissed by an outside click.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Overlays
- Tags: alert, dialog, confirm, destructive, overlay, modal
- Dependencies: dialog, button
- Types: `AlertDialogProps`
- Docs: https://fancy-ui.rama.app/docs/components/alert-dialog
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/alert-dialog

## Import

```tsx
import { AlertDialog } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | Whether the alert dialog is open; bindable |
| `onOpenChange` | `(open: boolean) => void` | — | Fires whenever open changes — Confirm, Cancel, or Escape |
| `title` | `string` | — | The heading. Omitted entirely (not just visually) when not given |
| `description` | `string` | — | The warning copy under the title. Same omission rule as title |
| `confirmLabel` | `string` | `"Confirm"` | Label of the destructive action |
| `cancelLabel` | `string` | `"Cancel"` | Label of the safe action |
| `onConfirm` | `() => void` | — | Called when the destructive action is activated, before the surface closes |
| `onCancel` | `() => void` | — | Called when the safe action is activated, and also when Escape closes it |
| `initialFocus` | `HTMLElement \| null` | — | Element to focus once the surface opens; defaults to the Cancel button |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes for the panel |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the panel element |
| `sound` | `boolean` | `false` | Plays open on the trigger, select on a confirmed action and close on Cancel or Escape, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `trigger` | Optional trigger; renders in place and opens the surface on activation |

## Example

```tsx
import { useState } from "react";
import { AlertDialog, Button } from "fancy-ui-react";

export function AlertDialogExample() {
	const [status, setStatus] = useState("");

	return (
		<>
			<AlertDialog
				sound
				trigger={<Button variant="destructive">Delete project</Button>}
				title="Delete this project?"
				description="This action is irreversible. All data will be lost."
				confirmLabel="Delete"
				onConfirm={() => setStatus("Project deleted.")}
				onCancel={() => setStatus("Cancelled.")}
			/>

			{status ? <p className="text-muted-foreground mt-2 text-[12px]">{status}</p> : null}
		</>
	);
}
```
