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).

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.

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, closeIcon, closecolor × variant × size matrix on root (15-cell compoundVariants)
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'sm' | 'md' | 'lg'undefinedFolded into themeVariant.
iconstringundefined (preset default for color)Iconify name. Pass '' to suppress.
rolestringderived from colorARIA role override.
asstring'div'HTML tag to render.

<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.