Vitral 0.2
Misc

Badge

A count or a status dot, on its own or pinned to the corner of what it wraps with OverlayBadge.

Import

main.ts
import { Badge } from '@vitral/vue';

Severities

12345678
<script setup lang="ts">import { Badge } from '@vitral/vue'; const severities = ['primary', 'secondary', 'success', 'info', 'warn', 'danger', 'help', 'contrast'] as const;</script> <template>    <Badge v-for="(s, i) in severities" :key="s" :value="i + 1" :severity="s" /></template>

Sizes and dot

Without a value the badge is a dot.

888899+
<script setup lang="ts">import { Badge } from '@vitral/vue';</script> <template>    <Badge value="8" size="small" />    <Badge value="8" />    <Badge value="8" size="large" />    <Badge value="8" size="xlarge" />    <Badge value="99+" severity="danger" />    <Badge severity="success" />    <Badge severity="danger" /></template>

OverlayBadge

Bind the slot’s `badgeId` as aria-describedby: “Notifications, 4”.

4
12
AS
<script setup lang="ts">import { Button, OverlayBadge } from '@vitral/vue';</script> <template>    <OverlayBadge value="4" severity="danger">        <template #default="{ badgeId }">            <Button icon="bell" severity="secondary" aria-label="Notifications" :aria-describedby="badgeId" />        </template>    </OverlayBadge>    <OverlayBadge value="12">        <template #default="{ badgeId }">            <Button icon="menu" severity="secondary" variant="outlined" aria-label="Inbox" :aria-describedby="badgeId" />        </template>    </OverlayBadge>    <OverlayBadge severity="success">        <span class="demo-avatar" role="img" aria-label="Ana Souza, online">AS</span>    </OverlayBadge></template> <style scoped>.demo-avatar {    display: inline-flex;    align-items: center;    justify-content: center;    width: 2.5rem;    height: 2.5rem;    border-radius: 999px;    font-weight: 600;    color: var(--vt-primary-contrast-color);    background: var(--vt-primary-color);}</style>

API

Read from packages/vue/src/components/Badge/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
valuestring | number | nullWithout a value (or slot content) the badge is a dot.
severitySeverityDefaults to `'primary'`.
sizeBadgeSize—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
default——