Nexus DSdocs

AlertDialog

Installation

npm install @radix-ui/react-alert-dialog@^1.1.15 @radix-ui/react-slot@^1.2.4 @tabler/icons-react@^3.36.1 class-variance-authority@^0.7.1 clsx@^2.1.1 tailwind-merge@^3.4.0
components/button-group/button-group-context.ts
components/button/button.tsx
components/button/index.ts
components/overlay-layout/overlay-layout.ts
components/spinner/index.ts
components/spinner/spinner.tsx
lib/icons.ts
lib/utils.ts
components/alert-dialog/alert-dialog.tsx
components/alert-dialog/index.ts

Code

'use client';

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

export default function AlertDialogDemo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="outline">Show dialog</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. This will permanently update your
            account settings.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Continue</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

Props

AlertDialog

AlertDialog adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogAction

AlertDialogAction props
PropTypeDefaultDescription
size"default" | "sm" | "lg" | "icon-sm" | "icon" | "icon-lg" | null"default"No description
variant"link" | "default" | "error" | "destructive" | "outline" | "dashed" | "secondary" | "ghost" | null"default"No description

AlertDialogBody

AlertDialogBody adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogCancel

AlertDialogCancel props
PropTypeDefaultDescription
size"default" | "sm" | "lg" | "icon-sm" | "icon" | "icon-lg" | null"default"No description
variant"link" | "default" | "error" | "destructive" | "outline" | "dashed" | "secondary" | "ghost" | null"outline"No description

AlertDialogContent

AlertDialogContent props
PropTypeDefaultDescription
variant"default" | "center""default"

Layout variant for the alert dialog content.

default keeps the header left-aligned and footer actions horizontal. center centers the header and stacks full-width footer actions.

AlertDialogDescription

AlertDialogDescription adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogFooter adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogHeader

AlertDialogHeader props
PropTypeDefaultDescription
variant"default" | "center" | null"default"No description

AlertDialogOverlay

AlertDialogOverlay adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogPortal

AlertDialogPortal adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogTitle

AlertDialogTitle adds no props of its own; it accepts the props of the element or primitive it wraps.

AlertDialogTrigger

AlertDialogTrigger adds no props of its own; it accepts the props of the element or primitive it wraps.

Examples

Destructive action

'use client';

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

export default function AlertDialogDestructiveAction() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="destructive">Delete account</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Delete your account?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. This will permanently delete your
            account and remove your data from our servers.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

Center

'use client';

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

export default function AlertDialogCenter() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="outline">Discard draft</Button>
      </AlertDialogTrigger>
      <AlertDialogContent variant="center">
        <AlertDialogHeader>
          <AlertDialogTitle>Discard this draft?</AlertDialogTitle>
          <AlertDialogDescription>
            Your unsaved changes will be lost.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Discard</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}