Alert

A message bar that appears in the page after something happens.

Published

The article is now visible to everyone.
<script setup lang="ts">
  import { Alert, Button, Stack } from '@hina-ui/vue'
</script>

<template>
  <Stack class="min-h-48 w-full max-w-xl">
    <Alert tone="success" title="Published" closable>The article is now visible to everyone.</Alert>
    <Alert tone="danger" title="Publishing failed">
      The server is not responding for now; your draft has been kept.
      <template #actions>
        <Button size="sm" variant="soft" tone="danger">Retry</Button>
      </template>
    </Alert>
  </Stack>
</template>
vue

Usage

import { Alert } from '@hina-ui/vue'
ts

An alert reports something that just happened, such as a successful save, a failed publish or a required sign-in. It sits within the page content and screen readers announce it on their own. A fixed note written into the content is a Callout; brief feedback that floats in is a Toast.

Saved to drafts.
<script setup lang="ts">
  import { Alert } from '@hina-ui/vue'
</script>

<template>
  <Alert class="w-full max-w-xl">Saved to drafts.</Alert>
</template>
vue

Examples

Tones

Six tones; the default is neutral. The icon follows the tone, and icon set to false removes it.

Saved to drafts.
A new version is available; refresh the page to try it.
This page was contributed by a user and has not been reviewed yet.
The article has been published.
The article has been published.
<script setup lang="ts">
  import { Alert, Stack } from '@hina-ui/vue'
</script>

<template>
  <Stack class="w-full max-w-xl">
    <Alert>Saved to drafts.</Alert>
    <Alert tone="accent">A new version is available; refresh the page to try it.</Alert>
    <Alert tone="info">This page was contributed by a user and has not been reviewed yet.</Alert>
    <Alert tone="success">The article has been published.</Alert>
    <Alert tone="warning">Your session is about to expire; save your work soon.</Alert>
    <Alert tone="danger">Publishing failed; please try again later.</Alert>
    <Alert tone="success" :icon="false">The article has been published.</Alert>
  </Stack>
</template>
vue

Custom icon

The icon slot replaces the default icon.

A new version is available; refresh the page to try it.
<script setup lang="ts">
  import { Alert } from '@hina-ui/vue'
  import { Sparkles } from '@lucide/vue'
</script>

<template>
  <Alert tone="accent" class="w-full max-w-xl">
    <template #icon><Sparkles class="text-accent-text mt-0.5 size-5 shrink-0" /></template>
    A new version is available; refresh the page to try it.
  </Alert>
</template>
vue

Title

title is shown before the body.

<script setup lang="ts">
  import { Alert } from '@hina-ui/vue'
</script>

<template>
  <Alert tone="warning" title="Your session is about to expire" class="w-full max-w-xl">
    Save what you are editing within five minutes, or you will need to sign in again.
  </Alert>
</template>
vue

Closable

With closable set a close button sits at the end and emits close when clicked. v-model:open controls whether the alert is shown.

The article has been published.
<script setup lang="ts">
  import { ref } from 'vue'
  import { Alert, Button, Stack } from '@hina-ui/vue'

  const open = ref(true)
</script>

<template>
  <Stack class="min-h-28 w-full max-w-xl">
    <Alert v-model:open="open" tone="success" closable>The article has been published.</Alert>
    <Button variant="soft" tone="neutral" :disabled="open" class="self-start" @click="open = true">
      Show again
    </Button>
  </Stack>
</template>
vue

Actions

The actions slot sits after the body, for one or two buttons.

New comments

Your article has received 3 new comments.
<script setup lang="ts">
  import { Alert, Button } from '@hina-ui/vue'
</script>

<template>
  <Alert tone="info" title="New comments" class="w-full max-w-xl">
    Your article has received 3 new comments.
    <template #actions>
      <Button size="sm" variant="soft" tone="neutral">Later</Button>
      <Button size="sm">View</Button>
    </template>
  </Alert>
</template>
vue

Behaviour

  • The alert expands and fades in when it appears, collapses and fades out when closed, and the surrounding content moves smoothly.
  • No entrance animation plays on first render.

Accessibility

  • danger and warning alerts have the alert role and are announced at once; the other tones have the status role and are read after the current announcement.
  • The close button is named “Close”.

API

Props

Prop
Type
Default
Description
tone
'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger'
'neutral'
Tone
title
string
—
Title
icon
boolean
true
Whether to show the icon
closable
boolean
false
Whether to show a close button
open
boolean
true
Whether the alert is shown, v-model:open
class
string
—
Classes appended to the bar

Events

Event
Payload
Description
update:open
open: boolean
The shown state changed
close
—
The close button was clicked

Slots

Slot
Description
default
Body
icon
Replaces the icon
actions
Action area after the body