Alert
Persistent banner for page-level warnings, form errors, and inline status. Pure CSS — no Reka primitive needed.
npm install @vuecs/elements<script setup lang="ts">
import {
VCAlert,
VCAlertClose,
VCAlertDescription,
VCAlertTitle,
} from '@vuecs/elements';
import { ref } from 'vue';
const open = ref(true);
</script>
<template>
<VCAlert v-if="open" color="error">
<VCAlertTitle>Submission failed</VCAlertTitle>
<VCAlertDescription>
The server rejected the form. Check the highlighted fields and try again.
</VCAlertDescription>
<VCAlertClose @click="open = false" />
</VCAlert>
</template>@import "tailwindcss";
@import "@vuecs/design";
@import "@vuecs/elements";
@custom-variant dark (&:where(.dark, .dark *));Authoring shapes
Inline shorthand
The simplest usage — default slot doubles as the description when no <VCAlertTitle> / <VCAlertDescription> are present.
<VCAlert color="info">All systems operational.</VCAlert>Title + description compound
For multi-line alerts use the structured parts:
<VCAlert color="warning">
<VCAlertTitle>Network unstable</VCAlertTitle>
<VCAlertDescription>
Your changes will be saved as soon as the connection recovers.
</VCAlertDescription>
</VCAlert>Dismissible
<VCAlertClose> is presentational — it emits click only. Wire the click to whichever ref controls visibility. For instant dismissal use v-if:
<script setup lang="ts">
const visible = ref(true);
</script>
<template>
<VCAlert v-if="visible" color="error">
<VCAlertTitle>Cannot save</VCAlertTitle>
<!-- slotless → corner-X icon via the theme's `closeIcon` slot -->
<VCAlertClose @click="visible = false" />
</VCAlert>
</template>For an animated dismiss, wrap with <VCCollapse> (see the next section).
The theme reserves a right-hand gutter for the corner-X only when a slotless <VCAlertClose> (or <VCAlertClose icon>) is actually rendered. An alert without one keeps even padding on both sides. Tailwind does this with has-[.vc-alert-close-icon]. Bootstrap always applies pe-5, and the optional bridge CSS (@import "@vuecs/theme-bootstrap") removes it when no corner close is present. Bulma's .notification keeps its own native right padding.
Actions and alignment
Put trailing controls in the #actions slot. They are laid out beside the content column, so the text keeps its own first-line alignment with the icon:
<VCAlert color="error">
The app could not be reached. Check the connection and try again.
<template #actions>
<VCButton size="sm" @click="retry">Try again</VCButton>
</template>
</VCAlert>By default (align="start") the icon lines up with the first line of text, which is right for text, including text that wraps. When the row is taller than one line of text (a tall control, or your own flex layout in the default slot), set align="center" to center the icon, content and actions against it:
<VCAlert color="error" align="center">
The app could not be reached.
<template #actions>
<VCButton @click="retry">Try again</VCButton>
</template>
</VCAlert>align="end" aligns them to the bottom of the row instead.
Custom icon
:icon accepts any Iconify name and overrides the preset's color-derived default:
<VCAlert color="info" icon="lucide:wifi">
Re-connected to the server.
</VCAlert>Pass an empty string (:icon="''") to suppress the icon entirely.
For full control over the leading visual — a custom-styled <VCIcon>, a spinner, an image, or any component — use the #icon slot. It renders in the alert's icon position and takes precedence over the :icon prop and the color-derived default:
<VCAlert color="warning">
<template #icon>
<VCIcon name="fa6-solid:upload" class="text-lg" />
</template>
Upload one or more code files…
</VCAlert>Precedence is #icon slot → :icon prop → color-derived default. An empty (or v-if="false") slot falls back to the prop / default, so :icon="''" still suppresses when the slot renders nothing.
The color-derived / :icon icon is decorative, so its wrapper is aria-hidden (the alert's role + text carry the meaning). The #icon slot wrapper is not aria-hidden — its content is yours and may be meaningful or interactive (a live role="status" spinner, a focusable control). If you slot a purely decorative icon, mark it aria-hidden yourself.
Dismiss with collapse animation
Compose with <VCCollapse> for a height-collapse on dismiss (instead of instant unmount):
<script setup lang="ts">
const open = ref(true);
</script>
<template>
<VCCollapse v-model:open="open">
<VCCollapseContent>
<VCAlert color="success">
<VCAlertTitle>Profile updated</VCAlertTitle>
<VCAlertClose @click="open = false" />
</VCAlert>
</VCCollapseContent>
</VCCollapse>
</template>The click handler flips open on <VCCollapse>, Reka's Presence plays the accordion-up animation, and the alert unmounts after animationend. Because <VCAlert> is purely presentational it stays mounted (and rendered) throughout the close animation — Collapse owns the unmount cascade.
Compound API
| Component | Element default | Role |
|---|---|---|
VCAlert | <div role="alert|status"> | Outer container; provides theme + color context |
VCAlertTitle | <h4> (configurable as) | Heading text |
VCAlertDescription | <div> | Body text |
VCAlertClose | <button> | Styled close button — emits click only (consumer owns visibility) |
Theme keys
| Key | Slots | Notes |
|---|---|---|
alert | root, icon, content, actions, closeIcon, close | color × variant × size matrix on root (15-cell compoundVariants); align variant (start / center / end) on root + icon |
alertTitle | root | |
alertDescription | root |
Icon defaults
<VCAlert :color> auto-resolves a leading icon from the active icon preset (see Icons setup).
| Color | @vuecs/icons-lucide | @vuecs/icons-font-awesome |
|---|---|---|
info | lucide:info | fa6-solid:circle-info |
success | lucide:circle-check | fa6-solid:circle-check |
warning | lucide:triangle-alert | fa6-solid:triangle-exclamation |
error | lucide:circle-x | fa6-solid:circle-xmark |
Override per-app via defaults:
app.use(vuecs, {
defaults: {
alert: { errorIcon: 'mdi:alert-octagon' },
},
});Accessibility
<VCAlert> derives ARIA role from color:
| color | role | aria-live |
|---|---|---|
error / warning | alert | assertive (announced immediately) |
info / success / neutral | status | polite (announced when AT is idle) |
Override via <VCAlert role="log"> for custom interaction patterns (e.g. chat logs).
Distinction from <VCToast>
| Concern | <VCAlert> | <VCToast> |
|---|---|---|
| Lifetime | Permanent until dismissed | Auto-dismisses after duration |
| Placement | Inline in document flow | Fixed-position viewport |
| Queue | None — one per markup site | Managed by useToast() |
| Use case | Form errors, page warnings | Transient action feedback |
API Reference
<VCAlert>
| Prop | Type | Default | Description |
|---|---|---|---|
color | 'primary' | 'neutral' | 'info' | 'success' | 'warning' | 'error' | undefined | Folded into themeVariant; auto-resolves the icon + ARIA role for info/success/warning/error. primary and neutral use no preset icon by default (pass :icon explicitly to render one). |
variant | 'solid' | 'soft' | 'outline' | undefined | Folded into themeVariant. |
size | 'xs' | 'sm' | 'md' | 'lg' | undefined | Folded into themeVariant. |
align | 'start' | 'center' | 'end' | undefined (theme default 'start') | Cross-axis alignment of icon, content and actions. Folded into themeVariant and reflected as data-align on the root. |
icon | string | undefined (preset default for color) | Iconify name. Pass '' to suppress. Overridden by the #icon slot. |
role | string | derived from color | ARIA role override. |
as | string | 'div' | HTML tag to render. |
Slots
| Slot | Props | Description |
|---|---|---|
default | — | Alert body — title / description compound or inline text. |
actions | — | Trailing controls (e.g. a retry button), rendered in the actions wrapper beside the content column. An empty (or v-if="false") slot renders no wrapper. |
icon | { class: string } | Leading-icon override, rendered inside the icon wrapper in place of the icon prop / color-derived default. class is the resolved icon-wrapper theme class. An empty (or v-if="false") slot falls back to the prop / default. The slot wrapper is not aria-hidden (consumer owns slot a11y); the prop / color-derived icon wrapper is. |
<VCAlert> is presentational — wrap with v-if (instant dismissal) or <VCCollapse v-model:open> (animated). No v-model:open on the alert itself.
<VCAlertClose>
| Prop | Type | Default | Description |
|---|---|---|---|
icon | boolean | false | Force corner-X presentation. Slot-presence smart default decides otherwise. |
as | string | 'button' | HTML tag to render. |
Emits a native click event on the underlying button — no extra side effects. Wire @click to your visibility ref.