Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

1.8 KB
Raw Blame

category: Overlays

Focus-trapped confirmation prompt (Radix AlertDialog). Unlike Dialog, it has no close X, cannot be dismissed by clicking the overlay, and always ends in a choice. Use it before an irreversible or costly action (delete a site, leave an organization, regenerate a key); use Dialog for forms and everything else.

Parts: AlertDialog (root, open/onOpenChange) β†’ AlertDialogTrigger (asChild around a Button) β†’ AlertDialogContent (centered 512px panel) β†’ AlertDialogHeader / AlertDialogTitle / AlertDialogDescription β†’ optional body β†’ AlertDialogFooter with AlertDialogCancel (already styled as an outline Button, closes on click) and AlertDialogAction (accepts Button variant and size; closes on click, so attach the real work to onClick).

Conventions: title is a question naming the object ("Delete tomato.gg?"); description states the consequence and whether it can be undone; the cancel label is a verb ("Keep site"), not "No". The action is variant="destructive" for deletes and variant="accent" for non-destructive confirms. Never put more than two buttons in the footer.

<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="destructive">Delete site</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete tomato.gg?</AlertDialogTitle>
      <AlertDialogDescription>
        This removes the site and its 2.4M events. This cannot be undone.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Keep site</AlertDialogCancel>
      <AlertDialogAction variant="destructive" onClick={deleteSite}>Delete site</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>