--- title: "alert-dialog" description: "Modal that interrupts the user and waits for a deliberate response." category: "Overlays" --- # alert-dialog Modal that interrupts the user and waits for a deliberate response. ## Installation ```bash php artisan ui:add alert-dialog ``` ## Dependencies - composer: `gehrisandro/tailwind-merge-laravel` ## Usage ```blade Delete project {{-- Anything marked data-ui-alert-dialog-close dismisses it; the overlay deliberately does not. --}} Cancel Delete ``` ## Example The demo rendered on the docs page. ```blade Delete project Cancel Delete ``` ## Source Copy this file to the path shown above it. `resources/views/components/ui/alert-dialog.blade.php` ```blade @props([ 'title' => null, 'description' => null, ]) @php // Same native dialog element as the dialog component: top layer, focus // trap, Esc and an inert page for free. The differences are deliberate, // an alert dialog is dismissed by choosing an action, so there is no close // button and clicking the overlay does nothing. // // This cannot borrow the dialog component's script. A copied file has to // work on its own (AUTHORING ยง1), so the handler below is a separate copy // under its own data-ui-alert-dialog names and its own guard flag. $id = 'ui-alert-dialog-' . bin2hex(random_bytes(4)); // Not bg-black/50. Tailwind v4 compiles that to oklab(0 0 0 / 0.5), and // Chrome does not paint a modern colour function with alpha inside the // dialog top layer, so the scrim silently renders as nothing. A legacy // rgb() with alpha composites correctly in the same place. $overlay = 'absolute inset-0 bg-[rgb(0_0_0/0.5)] opacity-0 transition-opacity duration-200 group-data-[state=open]/alert:opacity-100'; $panel = \TailwindMerge\Laravel\Facades\TailwindMerge::merge( 'absolute left-1/2 top-1/2 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 scale-95 gap-4 rounded-lg border bg-background p-6 opacity-0 shadow-lg transition-all duration-200 group-data-[state=open]/alert:scale-100 group-data-[state=open]/alert:opacity-100 sm:max-w-lg', $attributes->get('class'), ); @endphp
except('class') }}> {{ $trigger }}
{{-- No data-ui-alert-dialog-close here: the overlay is not a dismiss target, the footer actions are. --}}
@if ($title || $description)
@if ($title)

{{ $title }}

@endif @if ($description)

{{ $description }}

@endif
@endif {{ $slot }} @isset($footer)
{{ $footer }}
@endisset
@once @endonce ``` ## Theme tokens `--background`, `--foreground`, `--muted-foreground`, `--border` Native dialog element plus its own inline