Alert Dialog

Alert Dialog is a component that displays important information requiring user acknowledgment.

Import

import { AlertDialog } from "css-materials";

Usage

const [isDialogOpen, setIsDialogOpen] = useState(false);

return (
    <>
        <AlertDialog
            isOpen={isDialogOpen}
            onClose={handleDialogClose}
            title="Unsaved Changes"
            message="You have unsaved changes. Are you sure you want to leave without saving?"
        />
    </>
)

Custom Footer

const [isDialogOpen, setIsDialogOpen] = useState(false);

return (
    <>
        <AlertDialog
            isOpen={isDialogOpen}
            onClose={handleDialogClose}
            title="New Idea"
            message="You have a brilliant new idea to review."
            confirmText='Review Now'
            cancelText='Later'
        />
    </>
)

onConfirm

You can set the processing that occurs when the Confirm button is clicked.

const [isDialogOpen, setIsDialogOpen] = useState(false);

const showAlert = () => alert("The Delete button has been clicked!");

return (
    <>
        <AlertDialog
            isOpen={isDialogOpen}
            onClose={handleDialogClose}
            title="Delete Item"
            message="Are you sure you want to delete this item? This action cannot be undone."
            confirmText='Delete'
            cancelText='Cancel'
            onConfirm={showAlert}
        />
    </>
)