MazIndicator
MazIndicator is a small dot or counter to show a status or a number of notifications. Use it alone, inline in a badge or a list row, or on the corner of an avatar, a button or an icon.
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
Basic usage
Without content, the indicator is a dot, to show a status (online, away, recording). Used alone, it is rendered inline and follows the font size of its context.
<script lang="ts" setup>
import MazIndicator from 'maz-ui/components/MazIndicator'
</script>
<template>
<span class="inline-flex items-center gap-2"><MazIndicator color="success" /> Online</span>
<span class="inline-flex items-center gap-2"><MazIndicator color="warning" /> Away</span>
<span class="inline-flex items-center gap-2"><MazIndicator color="destructive" /> Busy</span>
</template>Counter
Set content to a number or a short text to get a counter (unread messages, notifications). Above max (99 by default), a number shows {max}+.
<template>
<MazIndicator :content="3" color="destructive" />
<MazIndicator :content="42" color="destructive" />
<!-- Above `max` (99 by default): 99+ -->
<MazIndicator :content="128" color="destructive" />
<!-- 128 -->
<MazIndicator :content="128" :max="999" color="destructive" />
<!-- A short text -->
<MazIndicator content="New" color="info" />
</template>Show zero
A counter at 0 is hidden, like an empty notification count. Set show-zero to display it anyway. A text content ('0' for instance) is always displayed.
<template>
<!-- Renders nothing -->
<MazIndicator :content="0" />
<MazIndicator :content="0" show-zero />
</template>Colors
Available colors: primary (default), secondary, accent, info, success, warning, destructive and contrast.
<template>
<MazIndicator color="primary" />
<MazIndicator color="success" />
<MazIndicator color="destructive" :content="8" />
</template>Sizes
By default, the indicator is sized in em: it follows the font size of its context (a text, a badge, an avatar). Set size to force one of the maz-ui sizes.
<template>
<MazIndicator size="mini" color="success" />
<MazIndicator size="xs" color="success" />
<MazIndicator size="sm" color="success" />
<MazIndicator size="md" color="success" />
<MazIndicator size="lg" color="success" />
<MazIndicator size="xl" color="success" />
<MazIndicator size="xl" :content="12" color="destructive" />
</template>On an element
Put content in the default slot (an avatar, a button, an icon): the indicator sits on one of its corners. The wrapper is an inline-flex element that takes the size of its content.
Avatar
For an avatar, prefer the indicator prop of MazAvatar, which sets the position and the overlap for you.
<script lang="ts" setup>
import MazAvatar from 'maz-ui/components/MazAvatar'
import MazIndicator from 'maz-ui/components/MazIndicator'
</script>
<template>
<MazIndicator color="success" position="bottom-end" overlap="circular" label="Online">
<MazAvatar caption="Camille Durand" color="auto" rounded-size="full" />
</MazIndicator>
<MazIndicator :content="3" color="destructive" overlap="circular" label="3 unread messages">
<MazAvatar caption="Nina Rossi" color="auto" rounded-size="full" />
</MazIndicator>
</template>Button
MazBtn clips its content (overflow-hidden): a prop on the button would be cut. Wrap the button in a MazIndicator instead. It works with a normal button and with a fab one.
<script lang="ts" setup>
import { MazBell } from '@maz-ui/icons/static/MazBell'
import MazBtn from 'maz-ui/components/MazBtn'
import MazIndicator from 'maz-ui/components/MazIndicator'
</script>
<template>
<MazIndicator :content="3" color="destructive" label="3 new messages">
<MazBtn>Inbox</MazBtn>
</MazIndicator>
<!-- A round fab button: `overlap="circular"` keeps the indicator on its edge -->
<MazIndicator :content="12" color="destructive" overlap="circular" label="12 notifications">
<MazBtn fab :icon="MazBell" aria-label="Notifications" />
</MazIndicator>
</template>Icon
<script lang="ts" setup>
import { MazBell } from '@maz-ui/icons/static/MazBell'
import { MazEnvelope } from '@maz-ui/icons/static/MazEnvelope'
import MazIndicator from 'maz-ui/components/MazIndicator'
</script>
<template>
<MazIndicator :content="5" color="destructive" label="5 notifications">
<MazBell class="size-8" />
</MazIndicator>
<MazIndicator color="info">
<MazEnvelope class="size-8" />
</MazIndicator>
</template>Position and overlap
position sets the corner: top-start, top-end (default), bottom-start or bottom-end. Corners follow the reading direction (start and end flip in right-to-left languages).
overlap describes the shape of the content: on a circular one (a round avatar, a fab button), the indicator moves in to stay on the edge of the circle instead of floating in the empty corner.
<template>
<!-- rectangular (default) -->
<MazIndicator position="top-start" :content="1" color="destructive">
<div class="size-12 rounded-md bg-surface-600" />
</MazIndicator>
<!-- circular -->
<MazIndicator position="bottom-end" overlap="circular" :content="1" color="destructive">
<div class="size-12 rounded-full bg-surface-600" />
</MazIndicator>
</template>Attached
attached places the indicator on a corner of its nearest positioned parent (an element with position: relative), without wrapping anything. It is the way to add an indicator inside a component, like MazAvatar and MazSidebarMenuButton do.
<template>
<div class="relative size-12 rounded-md bg-surface-600">
<MazIndicator attached :content="4" color="destructive" />
</div>
<div class="relative size-12 rounded-full bg-surface-600">
<MazIndicator attached overlap="circular" position="bottom-end" color="success" />
</div>
</template>Ring
A thin ring detaches the indicator from the content it sits on. bordered is true by default with a default slot or attached, and false when the indicator is inline. Set :bordered="false" to remove it.
The ring takes the color of the surface behind (the container background, or the page surface). On another background, such as a colored header, override the --m-indicator-ring CSS variable so the ring blends in.
<template>
<header class="flex items-center gap-6 bg-primary p-6 [--m-indicator-ring:var(--maz-primary)]">
<MazIndicator color="success" position="bottom-end" overlap="circular">
<MazAvatar caption="Louis Mazel" color="auto" rounded-size="full" />
</MazIndicator>
</header>
<MazIndicator :content="3" color="destructive" :bordered="false">
<MazBtn>No ring</MazBtn>
</MazIndicator>
</template>Pulse
pulse adds an animated halo around the indicator, for a live status (recording, incoming call). The animation is disabled when the user asks to reduce motion.
<template>
<span class="inline-flex items-center gap-2"><MazIndicator color="destructive" pulse /> Recording</span>
<MazIndicator :content="2" color="destructive" pulse label="2 incoming calls">
<MazBtn>Calls</MazBtn>
</MazIndicator>
</template>Invisible
invisible hides the indicator and keeps the wrapped content. Bind it to your state, for instance "no more unread messages".
<script lang="ts" setup>
import MazBtn from 'maz-ui/components/MazBtn'
import MazIndicator from 'maz-ui/components/MazIndicator'
import MazSwitch from 'maz-ui/components/MazSwitch'
import { ref } from 'vue'
const hidden = ref(false)
</script>
<template>
<MazSwitch v-model="hidden">Invisible</MazSwitch>
<MazIndicator color="success" :invisible="hidden">
<MazBtn>Status</MazBtn>
</MazIndicator>
</template>Custom content
The content slot replaces the text of a counter. It receives { text }, the text computed from content and max (99+ for instance). It is not rendered for a dot.
<template>
<MazIndicator :content="250" color="destructive" label="250 unread messages">
<template #content="{ text }">
{{ text }} new
</template>
</MazIndicator>
</template>In a badge
A dot before the text of a pastel MazBadge is a compact status.
<template>
<MazBadge color="success" pastel class="gap-2">
<MazIndicator color="success" /> Online
</MazBadge>
<MazBadge color="destructive" pastel class="gap-2">
<MazIndicator color="destructive" pulse /> Live
</MazBadge>
</template>In a list
Inline, the indicator fits the end slot of a MazListItem (a status or a count). For a member avatar, use the indicator prop of MazAvatar.
<script lang="ts" setup>
import MazIndicator from 'maz-ui/components/MazIndicator'
import MazList from 'maz-ui/components/MazList'
import MazListItem from 'maz-ui/components/MazListItem'
const channels = [
{ name: 'General', unread: 12, live: false },
{ name: 'Design', unread: 0, live: true },
{ name: 'Random', unread: 0, live: false },
]
</script>
<template>
<MazList title="Channels">
<MazListItem v-for="channel in channels" :key="channel.name" :title="channel.name" clickable>
<template #end>
<MazIndicator
v-if="channel.unread"
:content="channel.unread"
color="destructive"
:label="`${channel.unread} unread messages`"
/>
<MazIndicator v-else-if="channel.live" color="success" pulse label="Live" />
</template>
</MazListItem>
</MazList>
</template>Accessibility
- Without
label, the indicator is decorative: it is hidden from assistive technologies (aria-hidden). A status shown only by a colored dot is invisible to screen readers and ambiguous for color-blind users: setlabel("Online", "3 unread messages") whenever the indicator carries information. With alabel, it is exposed as an image (role="img") named byaria-label. - Give the label in the language of the page, and update it with the state (
:label="online ? 'Online' : 'Offline'"). - Do not rely on color alone for a status that matters: pair the dot with a text when you can (see "In a badge").
- The wrapped content keeps its own semantics. Name a button with an indicator on it (
aria-label, or thelabelof the indicator for the count) and do not repeat the information twice. - The indicator ignores pointer events (
pointer-events: none) in a wrapper or whenattached: the wrapped element stays clickable. pulseis turned off withprefers-reduced-motion.
Props
| Name | Description | Type | Required | Default | Possible values |
|---|---|---|---|---|---|
| content | Content of the indicator: a number for a counter (notifications, unread messages) or a short text. Without it, the indicator is a dot (a status) | string | number | No | - | - |
| max | Highest number displayed by a counter: above, it shows {max}+ | number | No | 99 | - |
| show-zero | Show the counter when its content is 0 (hidden by default, like an empty notification count) | boolean | No | false | - |
| color | Color of the indicator | "primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | No | "primary" | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'destructive' | 'contrast' |
| position | Corner of the wrapped content where the indicator sits (with a default slot or attached) | MazIndicatorPosition | No | "top-end" | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' |
| overlap | Shape of the wrapped content: on a circular one (an avatar), the indicator moves in to stay on the edge of the circle | "rectangular" | "circular" | No | "rectangular" | 'rectangular' | 'circular' |
| size | Size of the indicator. Without it, it follows the font size of its context | "xs" | "sm" | "md" | "lg" | "xl" | "mini" | No | - | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'mini' |
| bordered | Ring around the indicator to detach it from the wrapped content. It takes the container background: override --m-indicator-ring on another surface | boolean | No | true with a default slot or attached, false otherwise | - |
| pulse | Animated halo around the indicator (a live status). Disabled when the user reduces motion | boolean | No | false | - |
| attached | Place the indicator on a corner of its nearest positioned parent instead of inline, to add it to an element without wrapping it | boolean | No | false | - |
| invisible | Hide the indicator (the wrapped content stays) | boolean | No | false | - |
| label | Accessible name of the indicator ("Online", "3 unread messages"...). Without it, the indicator is decorative and hidden from assistive technologies | string | No | - | - |
Slots
| Name | Description | Bindings |
|---|---|---|
| default | Content on a corner of which the indicator sits (an avatar, a button, an icon) | - |
| content | Replace the text of a counter | text string |