Notification
Corner notifications with auto-close, independent stacks, action buttons and Chalk/OEM themes.
The default export is a component plugin; the named Notification export is the callable service. CommonUI or app.use(NfNotification) installs this.$openNotify. In setup, useNotification() inherits provider injections and locale and disposes notifications on unmount. createNotification(appContext) creates an app-scoped service. Direct Notification never implicitly binds the last installed app; pass appContext as its second argument when needed.
Basic usage and positions
Notification types
Cancel and confirm
Text, HTML and VNode
Component and default slot
Interactive example
Installation
import NfNotification, { Notification, useNotification, createNotification } from '@94ai-plus/nf-notification'
import '@94ai-plus/nf-theme-chalk/nf-notification.css'
app.use(NfNotification)
Notification.success({ title: 'Saved', message: 'Success' })
const notify = createNotification(app._context)
notify.info('App context')
// setup(): const notify = useNotification()Options
| Attribute | Description | Type | Accepted values | Default |
|---|---|---|---|---|
| title | Title | string | — | '' |
| message | Description text | string / VNode | — | '' |
| dangerouslyUseHTMLString | Whether to render message as HTML; trusted content only | boolean | — | false |
| type | Theme style; unsupported values are ignored | string | success / warning / info / error | '' |
| iconClass | Custom icon class; a valid type takes precedence | string | — | '' |
| customClass | Custom class name | string | — | '' |
| duration | Display duration in ms; 0 disables automatic closing | number | — | 4500 |
| position | Custom popup position | string | top-right / top-left / bottom-right / bottom-left | top-right |
| showClose | Whether to show the close button | boolean | — | true |
| onClose | Close callback, receiving the closed instance’s public handler | (handler: NotificationHandler) => void | — | — |
| onClick | Callback when Notification is clicked | () => void | — | — |
| offset | Offset shared by simultaneous Notification instances; an additional 16px viewport margin applies | number | — | 0 |
| cancelButtonText | Cancel button text | string | — | '' |
| confirmButtonText | Confirm button text | string | — | '' |
| onCancel | Cancel button callback; does not close the notification automatically | () => void | — | — |
| onConfirm | Confirm button callback; does not close the notification automatically | () => void | — | — |
| zIndex | Stacking level; service calls increment from 3001 | number | — | Auto-incremented |
Events
| Event | Description | Payload |
|---|---|---|
| click | Callback when Notification is clicked | — |
| cancel | Cancel button callback; does not close the notification automatically | — |
| confirm | Confirm button callback; does not close the notification automatically | — |
| close | Emitted on close | (handler: NotificationHandler) |
| destroy | Emitted after the leave transition | — |
Slots
| Slot | Description | Payload |
|---|---|---|
| default | Body content; takes precedence over message | — |
Methods and handler
| API | Description |
|---|---|
| Notification(string / VNode / options, appContext?) | Returns NotificationHandler |
| Notification.success / warning / info / error(options?) | Type shortcuts; accept string, VNode or options |
| handler.close() | Close the current Notification; repeated calls are harmless |
| Notification.close(id, onClose?) | Close by id; identical callback deduplicated |
| Notification.closeAll() | Close a snapshot of active notifications |
| createNotification(appContext) / useNotification() | Context-aware scoped service |
Migration notes
Preserves the 4500ms default, independent corner stacks, 16px edges/gaps, hover pause and full-duration restart on leave. Delete/Backspace pause; other keys restart; Escape closes notifications. Keyboard handling no longer creates duplicate timers or restarts while hovering. Height changes, resizing and middle-item removal trigger reflow.
Cancel/confirm only invoke callbacks, without automatically closing or triggering card onClick. Call handler.close() explicitly when needed. Recognized type icons take priority over iconClass; no type/iconClass means no icon. Titles and strings are escaped. HTML mode is only for trusted content. Slot-only content now renders without message. Business content/action labels are supplied by the caller; close aria-label supports eight languages.
close() is idempotent; close(id) really closes the DOM and releases timers/listeners/observers. onClose receives NotificationHandler (id, position, el/$el/dom, visible, closed, close), not Vue 2 private instance fields. SSR returns a closed no-op handler. Scoped close/closeAll only affect owned notifications; direct Notification.closeAll() affects all notifications on the page. Message and Notification keep separate registries. Notifications mount into body and follow root data-nf-theme; declarative components do not join service stacks.
