Skip to content

Alert

A message on the page that needs attention: information, success, a warning or an error. Same markup and props in every style: switch the style in the header to see it change.

Basic

A title and a description, with an icon.

Heads up

You can add components to your app with the VinUI command line.

alert-basic.html
<div class="vin-alert" style="max-width: 480px">
  <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/></svg>
  <div class="vin-alert__content">
    <p class="vin-alert__title">Heads up</p>
    <p class="vin-alert__description">You can add components to your app with the VinUI command line.</p>
  </div>
</div>

Variants

Primary for news, then success, warning and danger. Each has its own icon.

A new version is out

Version 0.2 adds eight components.

Payment received

We've emailed your receipt.

Your trial ends in 3 days

Add a card to keep your projects.

We couldn't save your changes

Check your connection and try again.

alert-variants.html
<div style="display: grid; gap: 12px; width: 100%; max-width: 480px">
  <div class="vin-alert vin-alert--primary">
    <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/></svg>
    <div class="vin-alert__content">
      <p class="vin-alert__title">A new version is out</p>
      <p class="vin-alert__description">Version 0.2 adds eight components.</p>
    </div>
  </div>
  <div class="vin-alert vin-alert--success">
    <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12 2.5 2.5 4.5-5"/></svg>
    <div class="vin-alert__content">
      <p class="vin-alert__title">Payment received</p>
      <p class="vin-alert__description">We've emailed your receipt.</p>
    </div>
  </div>
  <div class="vin-alert vin-alert--warning">
    <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.3 4.2 2.8 17.5A2 2 0 0 0 4.5 20.5h15a2 2 0 0 0 1.7-3L13.7 4.2a2 2 0 0 0-3.4 0z"/><path d="M12 9.5v4"/><path d="M12 17h.01"/></svg>
    <div class="vin-alert__content">
      <p class="vin-alert__title">Your trial ends in 3 days</p>
      <p class="vin-alert__description">Add a card to keep your projects.</p>
    </div>
  </div>
  <div class="vin-alert vin-alert--danger">
    <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5"/><path d="M12 16h.01"/></svg>
    <div class="vin-alert__content">
      <p class="vin-alert__title">We couldn't save your changes</p>
      <p class="vin-alert__description">Check your connection and try again.</p>
    </div>
  </div>
</div>

Actions and dismiss

Buttons under the text, and a close button. In HTML, add data-vin-dismiss to the close button and include vinui.js.

Storage almost full

You've used 9.2 GB of 10 GB. Upgrade or delete old files.

alert-actions.html
<div class="vin-alert vin-alert--warning" style="max-width: 480px">
  <svg class="vin-alert__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.3 4.2 2.8 17.5A2 2 0 0 0 4.5 20.5h15a2 2 0 0 0 1.7-3L13.7 4.2a2 2 0 0 0-3.4 0z"/><path d="M12 9.5v4"/><path d="M12 17h.01"/></svg>
  <div class="vin-alert__content">
    <p class="vin-alert__title">Storage almost full</p>
    <p class="vin-alert__description">You've used 9.2 GB of 10 GB. Upgrade or delete old files.</p>
    <div class="vin-alert__actions">
      <button type="button" class="vin-btn vin-btn--sm">Upgrade</button>
      <button type="button" class="vin-btn vin-btn--outline vin-btn--sm">Manage files</button>
    </div>
  </div>
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-alert__close" aria-label="Dismiss" data-vin-dismiss><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add alert
React
import { Alert } from "@/components/vin/alert";
Vue
import Alert from "@/components/vin/alert.vue";
Svelte
import Alert from "$lib/components/vin/alert.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/alert.json, which every framework version is tested against.

PropValuesDefaultIn HTML
variantneutralprimarysuccesswarningdangerneutralvin-alert--{value}
titleReactNode—<p class="vin-alert__title">
children
The description.
ReactNode—<p class="vin-alert__description">
icon
An icon for the variant is built in. Pass your own, or false for none.
ReactNode | false—<svg class="vin-alert__icon" aria-hidden="true">
actions
Buttons under the text.
ReactNode—<div class="vin-alert__actions">
onDismiss
Shows a close button.
() => void—<button class="vin-btn vin-btn--ghost vin-btn--icon vin-alert__close" aria-label="Dismiss" data-vin-dismiss>; vinui.js removes the alert

Parts

React, Vue, SvelteHTML classes
<Alert>.vin-alert.vin-alert--primary.vin-alert--success.vin-alert--warning.vin-alert--danger.vin-alert__icon.vin-alert__content.vin-alert__title.vin-alert__description.vin-alert__actions.vin-alert__close

Accessibility

  • An alert that is on the page from the start needs no role. Give role="alert" only to one that appears after an action, so it's announced.
  • The title says what happened in words; the colour and icon only support it. Icons are hidden from screen readers.
  • The close button has an aria-label ("Dismiss"). After it closes, focus moves to the next control (or the one before), so keyboard users don't get lost.
  • Text meets 4.5:1 contrast on every tinted background.