Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
Uncontrolled
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger
} from '@immit/ui/alert-dialog'
import { Button } from '@immit/ui/button'
export function AlertDialogUncontrolled() {
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button>Show Dialog</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Heads Up</AlertDialogTitle>
<AlertDialogDescription>
This is a warning before you perform an action. Be very careful with
your next choice.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Confirm</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}Controlled
'use client'
import { useState } from 'react'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger
} from '@immit/ui/alert-dialog'
import { Button } from '@immit/ui/button'
export function AlertDialogControlled() {
const [open, setOpen] = useState(false)
return (
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogTrigger asChild>
<Button>Show Dialog</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Controlled Alert Example</AlertDialogTitle>
<AlertDialogDescription>
This example demonstrates how to control the dialog with component
state.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={(event) => {
event.preventDefault()
setOpen(false)
}}
>
Confirm
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}Action Variants
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger
} from '@immit/ui/alert-dialog'
import { Button } from '@immit/ui/button'
export function AlertDialogActionVariants() {
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button>Show Dialog</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Looking Good!</AlertDialogTitle>
<AlertDialogDescription>
You look great today. Want to share a photo of your outfit?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel variant="destructive">Cancel</AlertDialogCancel>
<AlertDialogAction variant="primary">Confirm</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}