Feedback & overlays / Confirm

Feedback & overlays

Confirm

Ask a yes-or-no question from anywhere and await the answer: a dialog with no body that names the consequence, and runs the work with the commit button loading.

import { useConfirm, EcoConfirmHost } from "vue-ecosphere"

Ask, then act

The promise resolves true for the commit and false for every way out. Replaces Modal.confirm and a-popconfirm.

Destructive, with the work inside

Pass onConfirm and the commit shows its spinner while it runs; the dialog closes when it succeeds.

When it fails

Throw from onConfirm to keep the dialog open. Say what went wrong yourself, with a toast; the user retries or cancels. This demo fails once, then succeeds.

API

NameTypeDefaultDescription
useConfirm()(options) => Promise<boolean>—Returns confirm(). It resolves true once confirmed (after onConfirm succeeds), false on Cancel, ×, Escape or the scrim. Questions queue and show one at a time.
options.titlestring—The question, as the dialog title: “Delete this report?”.
options.textstring—The subtitle: what happens, and for a destructive action what is lost.
options.confirmLabelstring—Required. The commit button: name the consequence (“Delete report”), never “OK”.
options.cancelLabelstring"Cancel"The button that backs out. “Keep it” reads well beside a deletion.
options.dangerbooleanfalseThe commit becomes btn--danger.
options.onConfirm() => unknown—Runs on commit with the button loading; Cancel, ×, Escape and the scrim do nothing meanwhile. Settles → closes and resolves true. Throws → stays open; report the error yourself.
<EcoConfirmHost>component—Renders the queue as an EcoDialog. Mount once near the app root. Without it, confirm() logs one console error and resolves false; on the server it resolves false.