Ant Design Svelte

Message

Short messages: types, display time, queue, update and Promise lifecycle.

When to use

message gives a short temporary response to an action: saving, error or waiting. It doesn't stop working and usually disappears on its own. For a permanent message next to the fields, use Alert; for a detailed notification with actions, use Notification.

CSS prefixes message show global ConfigProvider.prefixCls and local prefixCls without resetting state. The prefix is ​​set by MessageHolder; queue, handles and message timing do not depend on it. For App, the same parameter is set via message.prefixCls. The example is closed manually; holder is released when leaving the page.

Instance and message surface

Create a queue with createMessage() and mount one MessageHolder under the provider you want to use. Create the instance inside a component so each user and each independent area has its own queue.

Problem Opportunity Example
Show result message.info/success/error Main scenario
Change show time duration, pauseOnHover Time and pause
Replace expectation with result identical key Update
Wait for completion callable thenable handle Subsequence
Limit messages maxCount Queue
Collapse a long list stack, threshold Message stack
Connect theme design theme.components.Message Message Subject

Pass an object with content to open(). Typed methods such as message.success() also accept text, a number or a snippet. The number 0 is visible. With null or a boolean, the text is empty. Set type: null for a message without a built-in status icon. A duration and a close callback passed as positional arguments take precedence over the corresponding object fields.

Update, Timer and Termination

duration is measured in seconds, the default instance value is 3. Zero disables automatic closing. loading also uses the instance duration by default: to wait without a timer, set duration:0 explicitly.

Calling the API again with the same key updates the content and display time. This lets you replace a loading message with the result. When the queue reaches maxCount, each new message replaces the oldest one.

The returned handle can be called as a closure function and awaited via await. The result true means the message is completed, false means the holder is disconnected. onClose is not called when detached. For consistency after await, check the result and the owner's relevance; resetting or leaving the page should not trigger a later continuation.

destroy(key) closes the desired entry, destroy() — the queue. onClose is called when closing begins, and await waits for completion. These events do not confirm that data has been saved on the server.

Stack and placement

Enable stack to make a long list take up less space. By default, the fourth message collapses the list to the newest card. The earlier messages stay in the queue. Hover over the stack to expand it. While the pointer is over the stack, timers pause for messages with pauseOnHover enabled. In the example, you can change the threshold or turn stacking off.

To mount the list in a different DOM element, pass getContainer to MessageHolder. The list is still positioned relative to the viewport. If the getter returns no element, the library tries ConfigProvider.getPopupContainer. If that also yields no element, it uses document.body. With neither getter set, the list stays with its holder. Container example.

Context, availability and limitations of

Holder receives the ConfigProvider context where it is located. top specifies the position of the surface. message design tokens change the background, padding, and layer; local style holder and entries take precedence. Changing the theme does not require re-open and should not restart the closing time.

role selects status or alert. For normal results, avoid urgent announcements unless necessary. Leave the important error also available next to the action, so that a short message is not the only explanation.

In the styling example, ConfigProvider.message sets classes and styles for messages under the provider. Use classNames and styles to target the list, text or icon. Classes are combined. Styles are applied in order from the provider to the holder and then to the individual message. Its own style takes precedence.

An alternative to manual createMessage/MessageHolder is App. Child App.useApp() returns message with the same methods and already connected holder. App Defaults apply to new calls; existing timers are not restarted.

Examples

Normal message

Independent instance and one MessageHolder.

Message types

Success, warning and error.

Closed: 0

Display time and pause

duration, pauseOnHover, onClose and callable handle.

loading and update

One key for anticipation, success and error.

Sequence not started.

Sequence via await

Completion, cancellation and protection against late continuation.

Queue limit

Once there are three messages, each new one replaces the oldest.

Message stack

Add a few import messages. Hover over the stack to see them all.

Content and design

The tip and the error share a text style. The border changes with the message type.

Component message Theme

Background, padding and layer; changing the topic preserves the queue, text and closing date of the message.

Messages appear on top without moving focus. There are no more than three active messages left in the queue.

Save settings or show a separate message.

Saving settings

Asynchronous success, error, retry and reset.

General: suite; local: project-message

The prefix is ​​set by MessageHolder; queue, handles and message timing do not depend on it. For App, the same parameter is set via message.prefixCls. The example is closed manually; holder is released when leaving the page.

CSS prefixes message

Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.

API

Example themes
ThemeExample or limitation
Hooks usage (recommended)Svelte: createMessage and one MessageHolder in the required context.
Other types of messagesuccess, warning and error.
Customize durationSeconds, constant message, hover pause and handle.
StackThe list collapses above the threshold. Hover to expand it.
Message with loading indicatorUpdate one record by key.
Promise interfaceAwait completion with boolean result of Svelte API.
Custom semantic stylesShared text styling with different borders for tips and errors.
Update Message ContentThe text and type are changed without duplicating the entry.

MessageInstance

PropertyDescriptionTypeDefault
openCreate or update by key.(config: MessageConfig) => MessageHandle—
infoInformation message.(content | config, duration?, onClose?) => MessageHandleinfo
successSuccessful operation.(content | config, duration?, onClose?) => MessageHandlesuccess
warningWarning.(content | config, duration?, onClose?) => MessageHandlewarning
errorError.(content | config, duration?, onClose?) => MessageHandleerror
loadingWaiting. For a persistent message, explicitly set duration=0.(content | config, duration?, onClose?) => MessageHandleloading
destroyClose one entry or the entire queue.(key?: string | number) => void—

MessageConfig

PropertyDescriptionTypeDefault
contentStrings and numbers appear as text. null and booleans leave the text empty.string | number | boolean | null | Snippetis required
typePass null to omit the built-in status icon.info | success | warning | error | loading | nullinfo
keyStable update ID.string | numberis generated
durationSeconds; 0 disables the timer.number3
pauseOnHoverPause the timer under the pointer.booleantrue
iconOwn decorative icon.MessageContentby type
roleUrgency of the announcement.status | alertstatus
onClickOn click, currentTarget is the root element of the message.(event: MouseEvent) => void—
classNamesCSS classes for message parts, as an object or a function of props.MessageSemantic—
stylesInline CSS for individual parts, as an object or a function of props.MessageSemantic—
onCloseStart of closing. The holder callback does not cause detachment.() => void—
classRecord root class.string—
styleCSS of the entry root.string—

createMessage options

PropertyDescriptionTypeDefault
durationTotal display time of the instance.number3
maxCountSuppresses the oldest messages when exceeded.numberno limit
pauseOnHoverGeneral timer settings.booleantrue

MessageHolder

PropertyDescriptionTypeDefault
messageQueue instance; one connected holder is supported.MessageInstanceis required
idVisual surface identifier.string—
classSurface class.string—
styleCSS surfaces.string—

createMessage / MessageHolder / App.message

PropertyDescriptionTypeDefault
prefixClsFull prefix of MessageHolder and its cards. The empty string/undefined inherit ConfigProvider. Does not change the queue or timers.stringConfigProvider.prefixCls + "-message"
topOffset from the top of the viewport. Numbers are in pixels.number | string8
rtlSets the text direction for this list.booleanConfigProvider.direction
getContainerReturns the DOM element for the list. Its position is relative to the viewport.() => HTMLElement | null | undefined—
stackCollapses the list above the threshold. The default threshold is three messages.boolean | { threshold?: number }false
transitionNameCSS transition name. An empty string disables animation.string—
classNamesCSS classes for message parts, as an object or a function of props.MessageSemantic—
stylesInline CSS for individual parts, as an object or a function of props.MessageSemantic—

MessageHolder props override the corresponding createMessage options.

Semantic DOM

Use these names in classNames and styles to target the list and individual messages.

Message parts
ElementPurpose
listSurface that displays the messages.
listContentList of entries.
rootRoot element of a single message.
wrapperIcon and text.
iconDecorative badge.
titleMessage content.

Registration tokens

theme.components.Message specifies contentBg, contentPadding and zIndexPopup. The settings apply to the holder surface and messages, including nested topics and custom cssVar prefix. Local style holder and entries retain priority. Updating the theme saves the queue, surface position, and remaining display time.

TokenPurpose
zIndexPopupCSS surface layer holder; native popover remains in the top layer.
contentBgRecording background.
contentPaddingRecord indents; number in px or CSS string.
Common tokens of the current topic
TokenMeaning
colorTextrgba(0,0,0,0.88)
colorSuccess#52c41a
colorError#ff4d4f
colorInfo#1677ff
colorWarning#faad14
colorBgElevated#ffffff
borderRadiusLG8

FAQ

Where is the contextHolder from the React example?

In Svelte use createMessage and one MessageHolder inside the desired ConfigProvider.

What does await handle return?

true after message completion, false when holder is disconnected. handle itself is called to close.

How to replace loading with the result?

Pass the same key for loading and success/error.

What does duration:0 mean?

The message remains until handle(), destroy(key) or destroy(). For loading, zero is also set explicitly.

How do I turn off message animations?

Pass transitionName="" to the holder. Supply a CSS transition name for a custom animation. Omit the option to use the built-in animation.

Do I need to reopen a message after changing the subject?

No. Tokens are applied reactively without replacing the queue and closing time.

How does a long word behave?

Transported inside the card. This is the preserved behavior of the Svelte implementation.