Alert
Messages with status: design, description, actions and smooth closing.
When to use
Status, title and actions
title sets the main message, description - details, action - action nearby. These areas take values and Svelte snippets. type selects success/info/warning/error, variant — outlined/filled.
| Problem | Opportunity | Example |
|---|---|---|
| Show short result | title, type |
Key message |
| Explain the reason and next step | description |
Detailed message |
| Allow closing | object closable |
Closing |
| Add action | snippet action |
Actions |
| Place a banner | banner |
Page Banner |
| Handle render failure | svelte:boundary |
Error limit |
showIcon includes an icon. Icon allows you to set your own; defaults by type can be configured in ConfigProvider.alert. banner changes the standard type/showIcon: if necessary, set them explicitly. The color and icon should complement clear text.
Closing and recovery
closable accepts a boolean or an object with closeIcon, disabled, ARIA attributes, onClose and afterClose. onClose reports a closing request; preventDefault does not override it. afterClose is called after the DOM has been removed, unless the component was unmounted first.
Alert does not have a separate open/bind:open. The closure is stored within the instance. To re-display, create a new instance, such as a keyed block, as in the demo. If a button with focus disappears after deletion, choose a logical place to return in advance.
Compositions and design
React Alert.ErrorBoundary is not exported. Error example uses Alert inside a failed-snippet of a regular svelte:boundary. The moving banner is also the logic of the example: CSS animation with a switch and reduced motion, without an external marquee library.
classNames/styles configure root/icon/section/title/description/actions/close; styles contains CSS strings. For a long title without description, the default alignment can be in the center. For the first line, set semantic styles to match your font and content, rather than a universal calculated offset.
ConfigProvider.alert sets defaults for appearance, closing and icons. Alert design tokens are applied through the theme. In the public package the radius is called borderRadius; the new name containerBorderRadius from the official documentation is not yet its contract.
By default, root has role:alert. For a calm informational message, you can select the appropriate role/aria-live; Don't declare a large immutable block as an urgent event unless necessary.
A non-empty local prefixCls specifies the Alert CSS classes. The empty string and undefined inherit ConfigProvider.prefixCls with the -alert suffix, defaulting to ant-alert. Changing namespace does not reset the closing state, semantic styles and tokens. Example ConfigProvider shows a common prefix along with Collapse and Affix.
Examples
Short message
Normal success message.
<script lang="ts">
import { Alert } from '@woodger/antd';
</script>
<Alert title={("Settings saved")} type="success" role="status" />
Message types
success, info, warning and error.
<script lang="ts">
import { Alert } from '@woodger/antd';
const types = ['success', 'info', 'warning', 'error'] as const;
const titles = {
success: "Data saved",
info: "Update available",
warning: "Check settings",
error: "Failed to save"
};
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
<div
class="examples"
>{#each types as type (type)}<Alert
{type}
title={(titles[type])}
role="status"
/>{/each}</div>
Filled
Filled design without frame.
<script lang="ts">
import { Alert } from '@woodger/antd';
const types = ['success', 'info', 'warning', 'error'] as const;
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
<div class="examples">{#each types as type (type)}<Alert {type} title={("Filled: " + String((type)) + "")} variant="filled" showIcon role="status" />{/each}</div>
Closing and recovery
disabled, own label and completion of closure.
<script lang="ts">
import { Alert, Button, Checkbox } from '@woodger/antd';
let disabled = $state(false);
let revision = $state(0);
let phase = $state(("Message open."));
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-bottom: 24px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="settings"
>
<Checkbox
bind:checked={disabled}
>{("Prohibit closing")}</Checkbox>
<Button onclick={() => { revision++; phase = ("Message open."); }}>
{("Restore Alert")}
</Button>
</div>
{#key revision}
<Alert title={("Closing message")} description={("The button reports the request and completion of the closure.")}
type="info" showIcon role="status" aria-label={("Lockable Alert")} closable={{
disabled,
'aria-label': "Hide message",
closeIcon: "Hide",
onClose: () => { phase = ("Closing…"); },
afterClose: () => { phase = ("Message closed."); }
}} />
{/key}
<output aria-label={("Closing state Alert")}>{phase}</output>
Details
Text and Snippet descriptions.
<script lang="ts">
import { Alert } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
{#snippet description()}
<span>{("Open ")}<strong>
{("project settings")}
</strong>{(" and check member access.")}</span>
{/snippet}
<div
class="examples"
>
<Alert
type="warning"
title={("There are unsaved changes")}
description={(description)}
showIcon
role="status"
/>
<Alert type="error" title={("Publication not completed")} description={("Please try again after checking the connection.")} showIcon role="status" />
</div>
Badges
Standard, custom and shared icon.
<script lang="ts">
import { Alert, ConfigProvider } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
{#snippet icon()}<span aria-hidden="true">★</span>{/snippet}
<div class="examples">
<Alert title={("Standard badge")} type="success" showIcon role="status" />
<Alert title={("Own icon")} type="info" showIcon {icon} role="status" />
<ConfigProvider
alert={{ warningIcon: icon }}
><Alert
title={("Icon from provider")}
type="warning"
showIcon
role="status"
/></ConfigProvider>
</div>
Moving banner
CSS example, switch and reduced motion.
<script lang="ts">
import { Alert, Checkbox } from '@woodger/antd';
let moving = $state(false);
</script>
<style>
.settings { margin-bottom: 20px; }
.line {
overflow: hidden;
min-width: 0;
}
.text { display: inline-block; }
.moving {
white-space: nowrap;
animation: ticker 18s linear infinite;
}
@keyframes ticker {
from {
transform: translateX(100%);
}
to {
transform: translateX(-100%);
}
}
@media (prefers-reduced-motion: reduce) {
.moving {
animation: none;
white-space: normal;
}
}
</style>
{#snippet title()}<div class="line"><span class="text" class:moving>{("Scheduled maintenance: documentation will remain available during the update.")}</span></div>{/snippet}
<div
class="settings"
><Checkbox
bind:checked={moving}
>{("Banner movement")}</Checkbox></div>
<Alert banner title={(title)} role="status" />
Action in message
Accept and cancel settings.
<script lang="ts">
import { Alert, Button } from '@woodger/antd';
let accepted = $state(false);
</script>
{#snippet action()}<Button size="small" onclick={() => { accepted = !accepted; }}>{(accepted ? "Cancel selection" : "Accept settings")}</Button>{/snippet}
<Alert
type={accepted ? 'success' : 'info'}
title={(accepted ? "Settings accepted" : "Check settings")}
description={("The action inside Alert updates the state of the example.")}
{action}
showIcon
role="status"
/>
Alignment of long title
First line via semantic styles.
<script lang="ts">
import { Alert, Button } from '@woodger/antd';
</script>
{#snippet action()}
<Button size="small" href={("#alert-demo-application")}>
{("Settings")}
</Button>
{/snippet}
<Alert
title={("Long warning about the need to check the project settings before publishing a new version of the documentation.")}
type="warning"
showIcon
{action}
role="status"
closable={{ 'aria-label': "Hide long warning" }}
styles={{
root: 'align-items: flex-start',
icon: 'margin-top: 4px',
close: 'margin-top: 4px'
}}
/>
Section content is available.
Rendering error in Svelte
Applied svelte:boundary with Alert in failed-snippet.
Boundary.svelte<script lang="ts"> import { Alert, Button } from '@woodger/antd'; import FragileContent from './FragileContent.svelte'; let fail = $state(false); </script> <style> .settings { margin-bottom: 20px; } </style> <div class="settings"> <Button onclick={() => { fail = true; }}> {("Check render error")} </Button> </div> <svelte:boundary> <FragileContent {fail} /> {#snippet failed(error: unknown, reset: () => void)} {#snippet action()} <Button size="small" onclick={() => { fail = false; reset(); }}> {("Restore partition")} </Button> {/snippet} <Alert type="error" title={("Section not available")} description={(error instanceof Error ? error.message : "Rendering error")} {action} showIcon /> {/snippet} </svelte:boundary>FragileContent.svelte<script lang="ts"> let { fail }: { fail: boolean } = $props(); let text = $derived.by(() => { if (fail) { throw new Error(("Failed to build partition content.")); } return ("Section content is available."); }); </script> <p>{text}</p>
Semantic DOM
Styles object and function.
<script lang="ts">
import { Alert, ConfigProvider } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
<ConfigProvider alert={{ styles: { title: 'font-weight: 600' } }}>
<div class="examples">
<Alert title={("Styles object")} showIcon role="status" classNames={{
root: 'alert-object'
}}
styles={{
root: 'border-style: dashed',
icon: 'color: #d48806'
}} />
<Alert title={("Styles function")} type="warning" role="status" classNames={{
root: 'alert-function'
}}
styles={({ props }) => ({ title: props.type === 'warning' ? 'font-weight: 700' : '' })} />
</div>
</ConfigProvider>
Tokens and RTL
Radius, padding and icon size.
<script lang="ts">
import { Alert, ConfigProvider } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
</style>
<ConfigProvider direction="rtl" theme={{
components: {
Alert: {
borderRadius: 12,
defaultPadding: '12px 18px',
withDescriptionPadding: '24px 28px',
withDescriptionIconSize: 30
}
}
}}>
<div
class="examples"
><Alert
title={("Thematic message")}
type="info"
role="status"
/>
<Alert
title={("Thematic description")}
description={("Settings are applied in the nested topic.")}
type="warning"
showIcon
role="status"
/></div>
</ConfigProvider>
Notification settings
Original application example with actions and replay.
<script lang="ts">
import { Alert, Button, Checkbox, type AlertType, type AlertVariant } from '@woodger/antd';
let type = $state<AlertType>('info');
let variant = $state<AlertVariant>('outlined');
let banner = $state(false);
let showIcon = $state(true);
let description = $state(true);
let closable = $state(true);
let customIcon = $state(false);
let closeText = $state(false);
let polite = $state(true);
let revision = $state(0);
let result = $state(("Apply the settings or close the message."));
const titles: Record<AlertType, string> = {
success: "Settings saved",
info: "Notification settings",
warning: "There are unsaved changes",
error: "Failed to save settings"
};
const descriptions: Record<AlertType, string> = {
success: "The new parameters will be used for the following notifications.",
info: "Check your notification settings before saving.",
warning: "Apply the settings to save the changes.",
error: "Save again. The entered parameters are saved."
};
function apply() {
type = 'success';
result = ("Settings are applied.");
}
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 24px;
}
.settings label {
display: flex;
align-items: center;
gap: 8px;
}
select {
padding: 4px 8px;
color: var(--ant-color-text);
background: var(--ant-color-bg-container);
border: 1px solid var(--ant-color-border);
border-radius: 6px;
font: inherit;
}
.footer {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-top: 24px;
}
output { color: var(--ant-color-text-secondary); }
</style>
{#snippet icon()}<span>★</span>{/snippet}
{#snippet action()}
<Button
size="small"
style="
max-width: 100%;
height: auto;
min-height: var(--ant-control-height-sm);
white-space: normal;
"
onclick={apply}
>
{(type === 'error' ? "Repeat saving" : "Apply settings")}
</Button>
{/snippet}
<div class="settings">
<label>{("Message type ")}<select bind:value={type}>
<option value="info">
{("Information")}
</option>
<option
value="success"
>{("Success")}</option>
<option
value="warning"
>{("Warning")}</option>
<option
value="error"
>{("Error")}</option>
</select></label>
<label>{("Message formatting ")}<select
bind:value={variant}
><option
value="outlined"
>{("With frame")}</option><option
value="filled"
>{("Without frame")}</option></select></label>
<Checkbox bind:checked={showIcon}>{("Message icon")}</Checkbox>
<Checkbox bind:checked={description}>{("Message Description")}</Checkbox>
<Checkbox bind:checked={banner}>{("Notification bar")}</Checkbox>
<Checkbox bind:checked={closable}>{("Close message button")}</Checkbox>
<Checkbox bind:checked={customIcon}>{("Custom message icon")}</Checkbox>
<Checkbox bind:checked={closeText}>{("Text instead of a cross")}</Checkbox>
<Checkbox bind:checked={polite}>{("Soft message announcement")}</Checkbox>
</div>
{#key revision}
<Alert
aria-label={("Custom message")}
role={polite ? 'status' : 'alert'}
{type}
{variant}
{banner}
{showIcon}
title={(titles[type])}
description={(description ? descriptions[type] : undefined)}
icon={customIcon ? icon : undefined}
{action}
closable={closable
&& {
closeIcon: closeText ? "Hide" : undefined,
onClose: () => { result = ("Closing the message..."); },
afterClose: () => { result = ("Message closed."); }
}}
/>
{/key}
<div class="footer"><Button
onclick={() => {
revision++;
result = ("Message restored.");
}}
>
{("Show message again")}
</Button><output aria-label={("Notification result")}>
{result}
</output></div>
API
Thirteen ant.design 6.7.0 themes mapped to the public Svelte API. The Loop banner and ErrorBoundary adaptations are separate from the Alert capabilities.
| Theme | Example or limitation |
|---|---|
| Basic | Short message. |
| More types | success, info, warning and error. |
| Filled | Design without frame. |
| Closable | disabled, button label and callbacks. |
| Description | Details in text and Snippet. |
| Icon | Standard, native and provider icon. |
| Banner | Warning strip and explicit type. |
| Loop Banner | Movement - CSS example, with controls and reduced motion. |
| Smoothly Unmount | afterClose reports the completion of closing. |
| ErrorBoundary | Adaptation via svelte:boundary. React Alert.ErrorBoundary is missing from the package. |
| Custom action | The button changes the state of the message. |
| Custom title alignment | Semantic styles align elements to the first line. |
| Custom semantic dom styling | Object and callback with props. |
Alert
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS prefix for Alert and its states. The empty string and undefined inherit ConfigProvider.prefixCls; default is ant-alert. | string | ConfigProvider + -alert |
title | Text, number, Snippet or array of content. | AlertContent | — |
type | Meaning, background and standard message icon. | success | info | warning | error | info / warning in banner |
variant | Design with or without frame. | outlined | filled | outlined |
description | Message details. | AlertContent | — |
showIcon | Show icon. | boolean | false / true in banner |
icon | Your icon at showIcon. | AlertContent | by type |
action | Action buttons and links. | AlertContent | — |
banner | Message strip with its own default type/showIcon. | boolean | false |
closable | Button and lifecycle closure. | boolean | AlertClosable | false |
role | For quiet static examples, you can use status. | HTML div role | alert |
classNames | Semantic slots classes. | AlertSemanticSlots | callback | — |
styles | CSS lines slots; callback gets allowed props. | AlertSemanticSlots | callback | — |
nativeElement | bind:nativeElement is cleared after closing. | HTMLDivElement | — |
AlertClosable
| Property | Description | Type | Default |
|---|---|---|---|
disabled | Disables the close button. | boolean | false |
closeIcon | Text or Snippet buttons. | AlertContent | cross |
onClose | Closing request. preventDefault is not a veto. | (event: MouseEvent) => void | — |
afterClose | After removing DOM; is canceled when the owner is unmounted. | () => void | — |
aria-label | Available button name. | string | localization |
The title is specified via title; Closing callbacks are in closable. ConfigProvider.alert specifies the variant, appearance, close defaults, and type icons.
Semantic DOM
Root has role=alert by default. Actions preserves native buttons and links, close is a real button with an accessible name. title is part of the message, not the title of the page.
| Slot | Purpose |
|---|---|
root | Message container. |
icon | Icon. |
section | Text area. |
title | Message title. |
description | Details. |
actions | Actions. |
close | Close button. |
Registration tokens
The installed package supports borderRadius, defaultPadding, withDescriptionPadding and withDescriptionIconSize. The name containerBorderRadius from the 6.7 documentation is not yet in the public package type.
| Token | Purpose |
|---|---|
borderRadius | Container radius in the installed Svelte package. |
defaultPadding | Short message indents. |
withDescriptionPadding | Indents with description. |
withDescriptionIconSize | Icon size with description. |
| Token | Meaning |
|---|---|
colorInfoBg | #e6f4ff |
colorSuccessBg | #f6ffed |
colorWarningBg | #fffbe6 |
colorErrorBg | #fff2f0 |
colorText | rgba(0,0,0,0.88) |
lineHeight | 1.5714285714285714 |
fontSize | 14 |
FAQ
Why does the information Alert in a dark theme remain light?
In the current native path, set only via mode/primary/compact, info/outlined has light text, but the background remains light. This is observed with both standard and common prefix. The source configuration with cssVar and token.colorPrimary in the tested example uses a dark palette. Setting up the algorithms is described in topic guide; regular prefixCls does not switch the palette.
How to show a closed Alert again?
Create a new instance via key or composition state. It doesn't have open/bind:open.
Which event to use after deletion?
closable.afterClose. onClose is also inside a closable object; the title is set by title.
Is there an Alert.ErrorBoundary?
No. Use svelte:boundary and Alert in failed-snippet, as in the example.
Where does the movement in Loop banner come from?
From the CSS demo. There is a switch, and reduced motion leaves the text motionless.
What is the radius token called?
In the installed public API - borderRadius. ContainerBorderRadius from the new official page is not supported yet.
How to align a long title to the first line?
Set up semantic styles for a specific composition. A standard Alert without description can center the content.