alert-dialog.tsx

Overview

alert-dialog.tsx is a React component module that provides a customizable and accessible alert dialog UI component built on top of the @radix-ui/react-alert-dialog primitives. It wraps and extends Radix UI's AlertDialog primitives with styling and layout enhancements tailored for the application's design system.

This file exports a set of components that can be used together to create modal alert dialogs with consistent behavior, animation, and styling. The components facilitate creating dialogs with overlays, titles, descriptions, action buttons, and cancel buttons, following best practices for accessibility and user experience.


Component Explanations

The file mainly exports React components that correspond to Radix UI AlertDialog primitives, enhanced with styling and layout wrappers.

1. AlertDialog


2. AlertDialogTrigger


3. AlertDialogPortal


4. AlertDialogOverlay


5. AlertDialogContent


6. AlertDialogHeader


7. AlertDialogFooter


8. AlertDialogTitle


9. AlertDialogDescription


10. AlertDialogAction


11. AlertDialogCancel


Important Implementation Details


Interaction with Other System Parts


Usage Example

import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogCancel,
  AlertDialogAction,
} from './alert-dialog';

function ConfirmDeleteDialog({ onConfirm }: { onConfirm: () => void }) {
  return (
    <AlertDialog>
      <AlertDialogTrigger>
        <button>Delete Item</button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Confirm Deletion</AlertDialogTitle>
        </AlertDialogHeader>
        <AlertDialogDescription>
          Are you sure you want to delete this item? This action cannot be undone.
        </AlertDialogDescription>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction onClick={onConfirm}>Delete</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

Mermaid Component Diagram

componentDiagram
    component AlertDialog
    component AlertDialogTrigger
    component AlertDialogPortal
    component AlertDialogOverlay
    component AlertDialogContent
    component AlertDialogHeader
    component AlertDialogFooter
    component AlertDialogTitle
    component AlertDialogDescription
    component AlertDialogAction
    component AlertDialogCancel

    AlertDialog <|-- AlertDialogTrigger : uses
    AlertDialog <|-- AlertDialogContent : uses
    AlertDialogContent *-- AlertDialogPortal : contains
    AlertDialogContent *-- AlertDialogOverlay : contains
    AlertDialogContent *-- AlertDialogHeader : contains
    AlertDialogContent *-- AlertDialogFooter : contains
    AlertDialogHeader *-- AlertDialogTitle : contains
    AlertDialogHeader *-- AlertDialogDescription : contains
    AlertDialogFooter *-- AlertDialogAction : contains
    AlertDialogFooter *-- AlertDialogCancel : contains

Summary

This file provides a styled, accessible alert dialog component suite in React by wrapping Radix UI primitives. It handles the dialog structure (root, trigger, portal, overlay, content), layout components (header, footer), and semantic elements (title, description, action, cancel) with consistent theming and animations. It is designed for straightforward integration into any React-based user interface where alert dialogs are required.