TuMarca

Alert Dialog

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

stable
Tipo: ui
Versión: 1.0.0
feedback overlay interactive modal confirmation vanilla-js

Comparación entre la versión Astro (Saastro) y React (shadcn/ui)

🚀 saastro/ui (Astro)
⚛️ shadcn/ui (React)

Installation

Usage

---
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogHeader,
  AlertDialogFooter,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel,
} from "@/components/ui-saastro/alert-dialog"
import { Button } from "@/components/ui-saastro/button"
---

<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="outline">Open Dialog</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Examples

Basic

<AlertDialog>
  <AlertDialogTrigger>Open</AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Confirm action</AlertDialogTitle>
      <AlertDialogDescription>
        Are you sure you want to proceed?
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>No</AlertDialogCancel>
      <AlertDialogAction>Yes</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

With Custom Trigger

Use asChild to use your own button component as trigger.

<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="destructive">Delete Account</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete Account</AlertDialogTitle>
      <AlertDialogDescription>
        This will permanently delete your account. This action cannot be undone.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Keep Account</AlertDialogCancel>
      <AlertDialogAction>Delete</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Props

AlertDialog

PropTypeDefaultDescription
idstringautoUnique identifier for the dialog
classstring-Additional CSS classes

AlertDialogTrigger

PropTypeDefaultDescription
asChildbooleanfalseRender child element instead of button
forstring-ID of dialog to trigger (for external triggers)
classstring-Additional CSS classes

AlertDialogContent

PropTypeDefaultDescription
animationDurationnumber200Animation duration in milliseconds
classstring-Additional CSS classes

AlertDialogHeader / AlertDialogFooter

PropTypeDefaultDescription
classstring-Additional CSS classes

AlertDialogTitle / AlertDialogDescription

PropTypeDefaultDescription
classstring-Additional CSS classes

AlertDialogAction / AlertDialogCancel

PropTypeDefaultDescription
asChildbooleanfalseRender child element instead of button
classstring-Additional CSS classes

Accessibility

  • Uses native <dialog> element with role="alertdialog"
  • Automatic aria-labelledby and aria-describedby attributes
  • Focus is trapped within the dialog when open
  • ESC key closes the dialog
  • Cannot be closed by clicking outside (unlike regular Dialog)
  • Screen reader announces the dialog title and description

Performance

Performance Benchmark

Bundle Size

~3KB vs ~180KB

98% menos

Hydration

0ms vs --

Sin hydration

Open Response

-- vs --

Interactúa para medir

Saastro (Vanilla JS)
shadcn (React)

Haz click en "Ejecutar Test" o interactúa con los componentes (click) para medir el rendimiento.