For vue2 projects, use @94ai/common-ui
LLMs.md

Confirm ​

Custom confirmation dialogs with async loading, callbacks, promises and Chalk/OEM themes.

The default export is a component plugin; the named Confirm export is the callable service. CommonUI or app.use(NfConfirm) installs this.$openConfirm. In setup, useConfirm() inherits provider injections and locale and cleans up on unmount. createConfirm(appContext) creates an app-scoped service. Direct Confirm does not implicitly bind the last installed app; pass appContext as its second argument when needed.

Basic usage ​

Loading example…
Basic usage

Status types ​

Loading example…
Status types

Promises and asynchronous close ​

Loading example…
Promises and asynchronous close

Callbacks and retry ​

Loading example…
Callbacks and retry

Text, HTML, VNode and component ​

Loading example…
Text, HTML, VNode and component

Interactive example ​

Without retry, confirm resolves the Promise and waits for done(). Press Escape to cancel.

Installation ​

ts
import NfConfirm, { Confirm, useConfirm, createConfirm } from '@94ai-plus/nf-confirm'
import 'element-plus/dist/index.css'
import '@94ai-plus/nf-theme-chalk/nf-confirm.css'

app.use(NfConfirm)
Confirm({ title: 'Confirm', message: 'Continue?' }).then(done => done()).catch(() => {})
// setup(): const confirm = useConfirm()
const confirm = createConfirm(app._context)

Options ​

AttributeDescriptionTypeAccepted valuesDefault
titleTitlestring—''
messageDescription textstring / VNode—''
dangerouslyUseHTMLStringWhether to render message as HTML; trusted content onlyboolean—false
widthConfirm width in pxnumber—400
typeTheme style; unsupported values are ignoredstringsuccess / warning / info / error''
iconClassCustom icon class; a valid type takes precedencestring—''
customClassCustom class namestring—''
cancelButtonTextCancel button textstring—Current locale
confirmButtonTextConfirm button textstring—Current locale
onCancelCancel callback; done() closes Confirm, done(false) only stops loading(done: ConfirmDone) => void | Promise<void>——
onConfirmConfirm callback; done() closes Confirm, done(false) only stops loading(done: ConfirmDone) => void | Promise<void>——
modelValueVisibility with v-model; takes precedence over visibleboolean—false
visibleVisibility with v-model:visibleboolean—false

Events ​

EventDescriptionPayload
cancelCancel callback; done() closes Confirm, done(false) only stops loadingdone: ConfirmDone
confirmConfirm callback; done() closes Confirm, done(false) only stops loadingdone: ConfirmDone
update:modelValueEmitted when visibility changesvalue: boolean
update:visibleEmitted when visibility changesvalue: boolean
closeEmitted on close—
destroyEmitted after the leave transition—

Slots ​

SlotDescriptionPayload
defaultBody content; takes precedence over message—

Methods and instance ​

APIDescription
Confirm(options?, appContext?)Promise<ConfirmDone>
done() / done(true)Clear loading and close
done(false)Clear loading, keep dialog open
Confirm.closeAll()Cancel all Confirm instances on the page
createConfirm(appContext) / useConfirm()Scoped service; closeAll only cancels owned instances
component ref.close(close?)Close or clear loading

Migration notes ​

Preserves 400px width, 35vh top, four types, both buttons and async loading. No close icon; backdrop clicks do not close. Escape is treated as cancellation, invokes onCancel and rejects with undefined after closing, fixing the legacy unresolved Promise. Default labels follow eight languages; explicit labels win. Recognized type icons take priority over iconClass. Titles/strings are escaped; HTML mode is only for trusted content. VNode content now renders correctly.

Without a custom onConfirm, confirmation resolves with done and does not close automatically. Call done() to close. done(false) only clears loading; a resolved Promise does not run then again. Use onConfirm for retryable operations. With custom callbacks, done(false) keeps the Promise pending; done() settles according to the current action. This fixes promises that never settled with legacy callbacks. Synchronous errors/async rejections clear loading and reject(error), without auto-closing. An internal rejection observer prevents ignored callback-style returns from becoming unhandled; explicit catch still receives cancellations/errors.

Each dialog owns its Promise, fixing the global currentMsg cross-instance bug. Attempt-scoped done functions cannot affect later retries, cancellation or reopened dialogs. Loading blocks repeated confirmation. Adds declarative v-model/v-model:visible, default slot and typed close(); declarative components without action listeners close normally. The default slot is new; the legacy component had no usable slot.

Element Plus Dialog provides focus, scroll locking and layering. App/provider services only clean up owned dialogs; direct Confirm.closeAll() cancels all Confirm instances without touching Message/Notification. Closing/unmount releases the Vue tree; SSR returns a resolved no-op done Promise without DOM access. Dialogs mount into body and follow root data-nf-theme. The duplicate legacy /3 anchor maps to basic usage; its incorrectly named notification Options anchor does not override notification routes.