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.
<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>Heads up
You can add components to your app with the VinUI command line.
import { Alert } from "@/components/vin/alert";
export function AlertBasic() {
return (
<Alert title="Heads up" style={{ maxWidth: 480 }}>
You can add components to your app with the VinUI command line.
</Alert>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Alert from "@/components/vin/alert.vue";
</script>
<template>
<Alert title="Heads up" style="max-width: 480px">
You can add components to your app with the VinUI command line.
</Alert>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Alert from "$lib/components/vin/alert.svelte";
</script>
<Alert title="Heads up" style="max-width: 480px">You can add components to your app with the VinUI command line.</Alert>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.
<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>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.
import { Alert } from "@/components/vin/alert";
export function AlertVariants() {
return (
<div style={{ display: "grid", gap: 12, width: "100%", maxWidth: 480 }}>
<Alert variant="primary" title="A new version is out">Version 0.2 adds eight components.</Alert>
<Alert variant="success" title="Payment received">We've emailed your receipt.</Alert>
<Alert variant="warning" title="Your trial ends in 3 days">Add a card to keep your projects.</Alert>
<Alert variant="danger" title="We couldn't save your changes">Check your connection and try again.</Alert>
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Alert from "@/components/vin/alert.vue";
</script>
<template>
<div style="display: grid; gap: 12px; width: 100%; max-width: 480px">
<Alert variant="primary" title="A new version is out">Version 0.2 adds eight components.</Alert>
<Alert variant="success" title="Payment received">We've emailed your receipt.</Alert>
<Alert variant="warning" title="Your trial ends in 3 days">Add a card to keep your projects.</Alert>
<Alert variant="danger" title="We couldn't save your changes">Check your connection and try again.</Alert>
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Alert from "$lib/components/vin/alert.svelte";
</script>
<div style="display: grid; gap: 12px; width: 100%; max-width: 480px">
<Alert variant="primary" title="A new version is out">Version 0.2 adds eight components.</Alert>
<Alert variant="success" title="Payment received">We've emailed your receipt.</Alert>
<Alert variant="warning" title="Your trial ends in 3 days">Add a card to keep your projects.</Alert>
<Alert variant="danger" title="We couldn't save your changes">Check your connection and try again.</Alert>
</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.
<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>Storage almost full
You've used 9.2 GB of 10 GB. Upgrade or delete old files.
import * as React from "react";
import { Alert } from "@/components/vin/alert";
import { Button } from "@/components/vin/button";
export function AlertActions() {
const [open, setOpen] = React.useState(true);
if (!open) return null;
return (
<Alert
variant="warning"
title="Storage almost full"
style={{ maxWidth: 480 }}
onDismiss={() => setOpen(false)}
actions={
<>
<Button size="sm">Upgrade</Button>
<Button variant="outline" size="sm">Manage files</Button>
</>
}
>
You've used 9.2 GB of 10 GB. Upgrade or delete old files.
</Alert>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import { ref } from "vue";
import Alert from "@/components/vin/alert.vue";
import Button from "@/components/vin/button.vue";
const open = ref(true);
</script>
<template>
<Alert v-if="open" variant="warning" title="Storage almost full" style="max-width: 480px" @dismiss="open = false">
You've used 9.2 GB of 10 GB. Upgrade or delete old files.
<template #actions>
<Button size="sm">Upgrade</Button>
<Button variant="outline" size="sm">Manage files</Button>
</template>
</Alert>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Alert from "$lib/components/vin/alert.svelte";
import Button from "$lib/components/vin/button.svelte";
let open = $state(true);
</script>
{#if open}
<Alert variant="warning" title="Storage almost full" style="max-width: 480px" onDismiss={() => (open = false)}>
You've used 9.2 GB of 10 GB. Upgrade or delete old files.
{#snippet actions()}
<Button size="sm">Upgrade</Button>
<Button variant="outline" size="sm">Manage files</Button>
{/snippet}
</Alert>
{/if}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:
npx @vinish/ui add alertimport { Alert } from "@/components/vin/alert";import Alert from "@/components/vin/alert.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
variant | neutralprimarysuccesswarningdanger | neutral | vin-alert--{value} |
title | ReactNode | — | <p class="vin-alert__title"> |
childrenThe description. | ReactNode | — | <p class="vin-alert__description"> |
iconAn icon for the variant is built in. Pass your own, or false for none. | ReactNode | false | — | <svg class="vin-alert__icon" aria-hidden="true"> |
actionsButtons under the text. | ReactNode | — | <div class="vin-alert__actions"> |
onDismissShows 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, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.