Skip to content

Alert ​

Persistent banner for page-level warnings, form errors, and inline status. Pure CSS — no Reka primitive needed.

bash
npm install @vuecs/elements
vue
<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>
css
@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.

vue
<VCAlert color="info">All systems operational.</VCAlert>

Title + description compound ​

For multi-line alerts use the structured parts:

vue
<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:

vue
<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:

vue
<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:

vue
<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:

vue
<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:

vue
<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):

vue
<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 ​

ComponentElement defaultRole
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 ​

KeySlotsNotes
alertroot, icon, content, actions, closeIcon, closecolor × variant × size matrix on root (15-cell compoundVariants); align variant (start / center / end) on root + icon
alertTitleroot
alertDescriptionroot

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
infolucide:infofa6-solid:circle-info
successlucide:circle-checkfa6-solid:circle-check
warninglucide:triangle-alertfa6-solid:triangle-exclamation
errorlucide:circle-xfa6-solid:circle-xmark

Override per-app via defaults:

ts
app.use(vuecs, {
    defaults: {
        alert: { errorIcon: 'mdi:alert-octagon' },
    },
});

Accessibility ​

<VCAlert> derives ARIA role from color:

colorrolearia-live
error / warningalertassertive (announced immediately)
info / success / neutralstatuspolite (announced when AT is idle)

Override via <VCAlert role="log"> for custom interaction patterns (e.g. chat logs).

Distinction from <VCToast> ​

Concern<VCAlert><VCToast>
LifetimePermanent until dismissedAuto-dismisses after duration
PlacementInline in document flowFixed-position viewport
QueueNone — one per markup siteManaged by useToast()
Use caseForm errors, page warningsTransient action feedback

API Reference ​

<VCAlert> ​

PropTypeDefaultDescription
color'primary' | 'neutral' | 'info' | 'success' | 'warning' | 'error'undefinedFolded 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'undefinedFolded into themeVariant.
size'xs' | 'sm' | 'md' | 'lg'undefinedFolded 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.
iconstringundefined (preset default for color)Iconify name. Pass '' to suppress. Overridden by the #icon slot.
rolestringderived from colorARIA role override.
asstring'div'HTML tag to render.

Slots ​

SlotPropsDescription
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> ​

PropTypeDefaultDescription
iconbooleanfalseForce corner-X presentation. Slot-presence smart default decides otherwise.
asstring'button'HTML tag to render.

Emits a native click event on the underlying button — no extra side effects. Wire @click to your visibility ref.

Released under the Apache 2.0 License.