Skip to content
LIBRARYBaseUpdated

Badge ​

MBadge adds context with text or a number: a category, a status or a count. It conveys information and has no built-in action.

Next alpha

Available in 0.1.0-alpha.4.

Web preview
Open example ↗

Usage ​

vue
<m-badge text="Published" tone="success" />
<m-badge :text="0" tone="accent" accessibilityLabel="0 unread messages" />
<m-badge text="99+" size="sm" accessibilityLabel="More than 99 messages" />

Props ​

PropTypeDefaultBehavior
textstring | numberrequiredContent; zero is displayed.
toneneutral | primary | accent | success | warning | dangerneutralTheme colors.
sizesm | mdmdText and spacing scale.
visiblebooleantruefalse plays the exit and only then removes the badge from the layout; true pops it back.
appearbooleanfalsePops in when first presented.
pulsebooleanfalseA decorative ring that keeps asking for attention. Stops under reduced motion and in the background.
accessibilityLabelstring—Describes the count in context when needed.
accessibilityHiddenbooleanfalseHides redundant information.
idstring—Optional identifier.

Primary and accent use their soft surfaces; neutral and semantic states use the elevated surface. Visible content should convey meaning without relying on color alone. Height follows text and long labels can wrap. Use a wrapping Row to allow a list of badges to continue on another line.

State and composition ​

The app controls the value, translation, limits and formatting. 99+ is an app-selected string, not a component rule. There are no slots, events, close button, keyboard focus or automatic announcements on updates. Supply an app status region when an update needs to be announced.

accessibilityLabel can announce “3 unread ideas” while the count shows 3. Web uses an image role with alternative text for that label; native exposes one named text element. Do not nest an interactive control inside a badge. For overlaid indicators, compose with Box and own the positioning in the app layout.

Profile uses Badge for the category and form editing state.

Motion ​

A changed text gives the badge a small bump while the new value is shown at once. Use visible instead of v-if to let a count pop in and shrink away. pulse is decoration only: pair it with a meaningful label or count. On NativeScript a pulsing badge sits inside a box that draws the ring, and attributes such as margins apply to that box.

The pulse uses one repeating Jolt playback. Hiding the badge or enabling reduced motion stops the ring while the count keeps its current value.

When a numeric label changes, the new number rolls in as the badge bumps. The accessible value changes immediately. An ordinary text label keeps the bump.

Desktop ​

On the Mac and on Windows the badge keeps its tones, sizes and label. Its entrance and its pulse grow and fade around its centre, as on the other renderers. See Desktop components.

Full example ​

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
import type { BadgeTone } from '@getcortexlabs/mavis-core'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const { theme } = useMavisTheme()
const count = ref(3)
const alerts = ref(1)
const tones: BadgeTone[] = ['neutral', 'primary', 'accent', 'success', 'warning', 'danger']
const labels = computed(() =>
  pt.value
    ? ['Rascunho', 'Destaque', 'Design', 'Publicado', 'Em revisão', 'Precisa de atenção']
    : ['Draft', 'Featured', 'Design', 'Published', 'In review', 'Needs attention'],
)
</script>

<template>
  <m-column gap="lg">
    <m-column padding="lg" gap="lg" radius="lg" :backgroundColor="theme.colors.primarySoft">
      <m-row justify="between" gap="sm">
        <m-text variant="overline" tone="primary">{{
          t(pt ? 'PEQUENOS SINAIS' : 'SMALL SIGNALS')
        }}</m-text>
        <m-badge :text="t(pt ? 'Novo' : 'New')" tone="primary" />
      </m-row>
      <m-text variant="title">{{ t(pt ? 'Cada detalhe conta.' : 'Every detail counts.') }}</m-text>
      <m-text tone="muted">{{
        t(
          pt
            ? 'Contexto, estado e prioridade. Em poucas palavras.'
            : 'Context, status and priority. In a few words.',
        )
      }}</m-text>
    </m-column>
    <m-card gap="lg">
      <m-text variant="overline" tone="muted">{{
        t(pt ? 'UMA PALETA DE SIGNIFICADOS' : 'A PALETTE OF MEANING')
      }}</m-text>
      <m-row gap="sm" wrap>
        <m-badge
          v-for="(tone, index) in tones"
          :key="tone"
          :tone="tone"
          :text="t(labels[index]!)"
        />
      </m-row>
    </m-card>
    <m-card gap="lg">
      <m-row gap="md">
        <m-avatar name="Mavis Studio" shape="square" />
        <m-column :width="0" :grow="1" gap="xs">
          <m-text variant="heading">{{ t('Mavis Studio') }}</m-text>
          <m-text variant="caption" tone="muted">{{
            t(pt ? 'Sua caixa de ideias' : 'Your idea inbox')
          }}</m-text>
        </m-column>
        <m-badge
          id="badge-count"
          :text="t(count)"
          tone="accent"
          :accessibilityLabel="t(pt ? `${count} ideias não lidas` : `${count} unread ideas`)"
        />
      </m-row>
      <m-row gap="sm" wrap>
        <m-button size="sm" variant="secondary" @click="count++">{{
          t(pt ? 'Nova ideia' : 'New idea')
        }}</m-button>
        <m-button size="sm" variant="ghost" @click="count = 0">{{
          t(pt ? 'Marcar como lidas' : 'Mark as read')
        }}</m-button>
      </m-row>
    </m-card>
    <m-card gap="lg">
      <m-text variant="overline" tone="muted">{{
        t(pt ? 'CHEGA, CHAMA, VAI EMBORA' : 'ARRIVES, CALLS, LEAVES')
      }}</m-text>
      <m-row gap="md" align="center">
        <m-icon name="bell" tone="muted" />
        <m-column :width="0" :grow="1" gap="xs">
          <m-text variant="heading">{{ t(pt ? 'Avisos' : 'Alerts') }}</m-text>
          <m-text variant="caption" tone="muted">{{
            t(
              pt
                ? 'O sinal só existe enquanto há algo para ver.'
                : 'The signal exists only while there is something to see.',
            )
          }}</m-text>
        </m-column>
        <m-badge
          id="badge-alerts"
          :text="t(alerts)"
          tone="danger"
          :visible="alerts > 0"
          appear
          pulse
          :accessibilityLabel="t(pt ? `${alerts} avisos novos` : `${alerts} new alerts`)"
        />
      </m-row>
      <m-row gap="sm" wrap>
        <m-button size="sm" variant="secondary" @click="alerts++">{{
          t(pt ? 'Chegou um aviso' : 'New alert')
        }}</m-button>
        <m-button size="sm" variant="ghost" @click="alerts = 0">{{
          t(pt ? 'Limpar avisos' : 'Clear alerts')
        }}</m-button>
      </m-row>
    </m-card>
    <m-row gap="md" wrap>
      <m-badge :text="t('Small')" size="sm" tone="primary" />
      <m-badge :text="t('Medium')" tone="primary" />
      <m-badge
        :text="t('99+')"
        size="sm"
        :accessibilityLabel="t(pt ? 'Mais de 99 mensagens' : 'More than 99 messages')"
      />
    </m-row>
  </m-column>
</template>

Components for NativeScript and Web. Starting with Vue.