Components

Alert

Communicate status with banners, tonal alerts, snackbars, and toasts.

UiAlert surfaces a message. type controls the surface (banner, tonal, snackbar) and variant the intent (success, warning, danger, …). For programmatic toasts, use useToast.

Show a banner alert

<template>
  <UiAlert
    type="banner"
    variant="success"
    title="Saved"
    message="Your changes were saved."
  />
</template>

Use tonal and critical styles

<template>
  <UiAlert type="tonal" variant="info" message="Heads up — read this." />
  <UiAlert
    type="tonal"
    variant="danger"
    title="Error"
    message="Something went wrong."
    :critical="true"
  />
</template>

Position a snackbar

placement only applies when type="snackbar":

<template>
  <UiAlert
    type="snackbar"
    variant="warning"
    message="Connection lost"
    placement="bottom-right"
  />
</template>

A snackbar is an inverse surface: dark in light mode, light in dark mode. Its icon takes --cffy-{variant}-inverse, and inside it --cffy-primary-base and --cffy-on-background point to their inverse tones, so a text button such as "Undo" in the actions slot stays readable without extra classes.

Dismissible alerts

Set dismissible to render a close button. The alert manages its own visibility internally (no v-model needed) and emits dismiss when closed:

<template>
  <UiAlert
    type="banner"
    variant="info"
    title="Heads up"
    message="Click the close button to hide this alert."
    dismissible
    @dismiss="onDismiss"
  />
</template>

Auto-hide with duration

Set duration (ms) to auto-hide banner and tonal alerts after a delay; it also emits dismiss when the timer fires. The timer starts on mount and is cleared if the alert is dismissed manually or unmounted first. duration is ignored for type="snackbar" — use useToast/UiAlertToast's own duration option for those instead:

<template>
  <UiAlert
    type="tonal"
    variant="success"
    message="This alert hides itself automatically after 3 seconds."
    :duration="3000"
    @dismiss="onDismiss"
  />
</template>

Trigger a toast programmatically

Mount a UiAlertToast and pass its ref to useToast. It returns success, warning, danger, info, and primary helpers, plus a generic onToastMessage(variant, message, opts):

<script setup lang="ts">
import { useToast } from '@colorffy/ui'
import { ref } from 'vue'

const toastRef = ref(null)
const toast = useToast(toastRef)

function onSave() {
  toast.success('Saved!', { duration: 3000 })
}
</script>

<template>
  <UiAlertToast ref="toastRef" placement="bottom-right" />
  <UiButton text="Save" @click="onSave" />
</template>

Props

PropTypeDefaultDescription
type'banner' | 'tonal' | 'snackbar''banner'Surface style.
variant'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'danger' | 'info' | 'transparent' | 'default''danger'Intent color.
titlestring—Optional title.
messagestring—Body text.
size'sm'—Smaller size.
criticalbooleanfalseEmphasized critical styling.
roundedbooleanfalseFully rounded shape.
placement'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right''bottom'Snackbar position. A corner snackbar grows with its text up to --cffy-container-lg; on screens up to 576px wide every placement spans the screen, centered.
customClassstring | string[] | Record<string, boolean>—Extra classes.
dismissiblebooleanfalseRenders a close button; clicking it hides the alert and emits dismiss.
durationnumber—Auto-hide delay in ms for non-snackbar types; emits dismiss when it fires.
closeLabelstring—Accessible label for the close button. Without it, the button uses the alert.close label ("Close").

Emits: dismiss — fired when the alert is closed via the close button or the duration timer.

Slots: #content, #actions.

UiAlertToast props

PropTypeDefaultDescription
snackbarTitlestring''Toast title.
snackbarMessagestring''Initial message; showToast({ message }) replaces it.
snackbarVariant'primary' | 'secondary' | 'accent' | 'neutral' | 'success' | 'warning' | 'danger' | 'info' | 'transparent' | 'default''success'Initial intent color; showToast({ variant }) replaces it.
placement'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right''bottom'Initial snackbar position; showToast({ placement }) replaces it.

Exposed: showToast(options?) shows the toast; options (IToastOptions) takes message, variant, placement and duration (auto-hide delay in ms, default 3000). Also title, message, variant and placement, the refs holding the current values.

CSS variables

Set these on :root, or on any wrapper to restyle only the alerts inside it. Banner, tonal, critical and transparent alerts keep their own colors, rounded its pill shape, and alerts with a title their wider gap. The --cffy-alert-snackbar-* and --cffy-alert-toast-* variables only affect snackbars.

:root {
  --cffy-alert-radius: var(--cffy-radius-md);
  --cffy-alert-snackbar-bg-color: var(--cffy-primary-a10);
  --cffy-alert-snackbar-color: var(--cffy-on-primary);
}
VariableDefaultControls
--cffy-alert-bg-color / --cffy-alert-border-color--cffy-surface-container-lowBackground and border
--cffy-alert-color / --cffy-alert-icon-color--cffy-on-backgroundText and icon
--cffy-alert-radius--cffy-shape-containerCorners
--cffy-alert-font-size / --cffy-alert-font-weight--cffy-fs-3xs / --cffy-fw-400Message text
--cffy-alert-title-font-size / --cffy-alert-title-font-weight--cffy-fs-xs / --cffy-fw-600Title
--cffy-alert-icon-size1.75emLeading icon
--cffy-alert-padding-block / --cffy-alert-padding-inline--cffy-space-12Padding
--cffy-alert-gap--cffy-space-8Space between icon, text and actions
--cffy-alert-stack-gapthe block paddingSpace below each stacked alert
--cffy-alert-snackbar-bg-color / --cffy-alert-snackbar-color--cffy-surface-toast / --cffy-on-background-inverseSnackbar background and text
--cffy-alert-toast-offset / --cffy-alert-toast-min-width--cffy-space-32 / --cffy-container-2xs (18rem)Snackbar distance from the screen edge and minimum width
Copyright © 2026