Skip to content

Alert

The Alert component is used to convey important feedback information to users, such as successful operations, system warnings, or error messages.

Basic Usage

Use the type prop to define the semantic level of the alert. The component will automatically select the most suitable Tabler icon and color scheme.

vue

<TAlert type="success" description="Data saved successfully!"/>
<TAlert type="info" description="You have a new system notification."/>
<TAlert type="warning" description="Please note that this operation may affect your account data."/>
<TAlert type="danger" description="A network error occurred. Please try again later."/>

Icon and Title

When you need to convey richer information, you can use the icon and title props to build a more structured alert.

The description text will automatically turn to a secondary gray color to highlight the title hierarchy.

vue

<TAlert type="success" title="Payment Successful" :icon="IconClipboardTypography">
  Your order has been paid successfully. We will arrange shipment as soon as possible.
</TAlert>
<TAlert type="danger" title="Account Frozen" :icon="IconShieldHalfFilled">
  Suspicious login activity detected. Please contact customer service to unfreeze.
</TAlert>

Important Style

Enable the important prop to give the alert more visual weight.

It typically applies a solid background or a thicker side border, depending on its color type.

This is ideal for critical warnings that users absolutely cannot miss.

vue

<TAlert important type="primary" title="System Upgrade Notice">
  The system will undergo maintenance at 12:00 PM tonight, expected to last 2 hours.
</TAlert>
<TAlert important type="danger" title="Critical Error">
  Database connection failed. Please check the server status immediately!
</TAlert>

Custom Icon

While the component auto-derives icons, you can pass a custom Tabler icon via the icon prop, or hide it entirely with showIcon="false".

vue

<TAlert type="warning" :icon="IconFlame" title="Hot Warning" description="..."/>
<TAlert type="success" :showIcon="false" description="A minimal alert without any icon."/>

Nesting Components (Using Slots)

Since the icon area is exposed as the #icon slot, you can insert not only SVG icons but also any other Vue component.

For example, combining it with the TAvatar component, you can easily build a user message or system dialog with strong visual cues:

vue

<TAlert color="blue" :closable="false">
  <template #icon>
    <TAvatar src="/avatar.png"></TAvatar>
  </template>
  Phone: "您拨打的号码是空号,请核对后再拨。"<br/>
  Outside: "Son, why do you speak a foreign language every day? Mom can't understand, but Mom misses you so much…….."
</TAlert>

Closable Alert

The closable prop is enabled by default, displaying a close button on the right side.

You can listen to the @close event to handle your own business logic.

View Code
vue

<script setup lang="ts">
  import {ref} from "vue";
  import {TAlert, TButton, TButtonGroup} from '@gulcc/tabler-vue';

  const isClosable = ref(true);
  const isClose = ref(true);
</script>
<template>
  <TButtonGroup v-if="isClose">
    <TButton @click="isClosable=true">Allow Close</TButton>
    <TButton @click="isClosable=false">Disable Close</TButton>
  </TButtonGroup>
  <br><br>
  <TAlert type="info" title="Close Event" :closable="isClosable" @close="isClose.value = false">
    When you close this alert, the action buttons above will also disappear.
  </TAlert>
</template>

API

TAlert Props

PropDescriptionTypeDefault
typeThe status type of the alert, automatically maps color and default icon.'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info''info'
titleThe title content of the alert.stringundefined
descriptionThe description content of the alert (overridden by the default slot).stringundefined
iconCustom left icon Vue component instance.Iconundefined
showIconWhether to show the left icon.booleantrue
colorForce a specific alert color (takes priority over type).TablerColorundefined
importantEnable high-saturation solid color emphasis style.booleanfalse
closableWhether to show the close button and allow manual dismissal.booleantrue

TAlert Events

EventDescriptionCallback
closeEmitted when the user clicks the close button and the alert disappears.() => void

TAlert Slots

SlotDescription
defaultThe description content of the alert (overrides the description prop).
titleCustom title (overrides the title prop).
iconCustom icon (overrides the icon prop).