Skip to main content

Confirm dialog

A controlled confirm/cancel modal built on the shadcn AlertDialog, with a loading spinner on the confirm button while an async action runs.

import { ConfirmDialog } from '@rtorcato/shadcn-ui/components/ui-extended/confirm-dialog'

Usage

const [open, setOpen] = useState(false)
const [loading, setLoading] = useState(false)

<ConfirmDialog
open={open}
onOpenChange={setOpen}
title="Delete project?"
description="This can't be undone."
confirmLabel="Delete"
confirmVariant="destructive"
loading={loading}
onConfirm={async () => {
setLoading(true)
await deleteProject()
setLoading(false)
setOpen(false)
}}
/>

Props

PropTypeDefaultDescription
openbooleanControlled open state.
onOpenChange(open: boolean) => voidCalled when the dialog requests open/close.
onConfirm() => void | Promise<void>Confirm handler.
onCancel() => voidOptional cancel handler.
titlestring'Are you sure?'Heading.
descriptionstringBody text.
confirmLabelstring'Confirm'Confirm button label.
cancelLabelstring'Cancel'Cancel button label.
confirmVariantButtonVariant'default'Confirm button variant (e.g. destructive).
loadingbooleanfalseShows a spinner and disables the confirm button.