Message
Success, warning, info and error notifications with auto-close, stacking and Chalk/OEM themes.
The default export is a component plugin; the callable service is the named Message export. Installing CommonUI or app.use(NfMessage) provides this.$openMessage for Options API. In setup, useMessage() inherits provider injections and locale and disposes its messages on unmount. Direct Message does not implicitly bind the last installed app; pass appContext as its second argument or use createMessage(appContext).
Basic usage and types
Manual close and stacking
Text, HTML and VNode
Center, offset and custom icon
Component and default slot
Interactive example
Installation
import NfMessage, { Message, useMessage, createMessage } from '@94ai-plus/nf-message'
import '@94ai-plus/nf-theme-chalk/nf-message.css'
app.use(NfMessage)
Message.success('Saved')
const appMessage = createMessage(app._context)
appMessage.info('App context')
// setup(): const message = useMessage()Options
| Attribute | Description | Type | Accepted values | Default |
|---|---|---|---|---|
| message | Message text | string / VNode | — | '' |
| type | Type | string | success / warning / info / error | info |
| iconClass | Custom icon class, overriding the default type icon | string | — | '' |
| dangerouslyUseHTMLString | Whether to render message as HTML; trusted content only | boolean | — | false |
| customClass | Custom class name | string | — | '' |
| duration | Display duration in ms; 0 disables automatic closing | number | — | 3000 |
| showClose | Whether to show the close button | boolean | — | false |
| center | Whether to center the text | boolean | — | false |
| onClose | Close callback, receiving the closed instance’s public handler | (handler: MessageHandler) => void | — | — |
| offset | Message offset from the viewport top, in px | number | — | 20 |
| zIndex | Stacking level; service calls increment from 3001 | number | — | Auto-incremented |
Events
| Event | Description | Payload |
|---|---|---|
| close | Emitted on close | (handler: MessageHandler) |
| destroy | Emitted after the leave transition | — |
Slots
| Slot | Description | Payload |
|---|---|---|
| default | Body content; takes precedence over message | — |
Methods and handler
| API | Description |
|---|---|
| Message(string / VNode / options, appContext?) | Returns MessageHandler |
| Message.success / warning / info / error(options?) | Type shortcuts; accepts string, VNode or options |
| handler.close() | Close the current Message; repeated calls are harmless |
| Message.close(id, onClose?) | Close by id; optional extra callback (same callback deduplicated) |
| Message.closeAll() | Close a snapshot of active messages |
| createMessage(appContext) / useMessage() | Context-aware scoped service |
Migration notes
Preserves four types, 3000ms default, hover pause/full-duration restart, Escape closing all messages, and 8px stack spacing. The source default offset is 20px (legacy docs incorrectly said 100); explicit zero works. Height changes, window resizing and closing a middle item trigger reflow. Messages render into body and follow the root data-nf-theme. Services share the page stack.
close() is idempotent. close(id) now really closes the DOM message. Timers, listeners and observers are cleaned up. onClose receives MessageHandler (id, el/$el, visible, closed, close), not Vue 2 private instance fields. SSR returns a closed no-op handler. App-scoped close/closeAll only affect that service; direct Message.closeAll() affects the page. Snapshot closing does not close new messages created in callbacks.
Strings are escaped. dangerouslyUseHTMLString is for trusted HTML only, never user input. The default slot overrides message. iconClass replaces the default SVG and removes the type modifier. The keyboard-accessible close button has a translated aria-label; business content is not auto-translated. Declarative components use fixed positioning but do not join the service stack. Use the service for multiple messages.
