Skip to content
LIBRARYText

NumberFlow ​

Added in RC.11.1

Included in Mavis 0.1.0-rc.11.1 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.

Web preview
Open example ↗
vue
<MNumberFlow
  :value="revenue"
  label="Revenue"
  locale="en-US"
  :format="{ style: 'currency', currency: 'USD' }"
/>
PropTypeContract
valuenumberRequired finite canonical value.
locale / formatstring / NumberFlowFormaten-US; consistent server/client formatting.
formatValue(value: number) => stringOverrides locale formatting.
duration / animated / announcenumber / boolean / boolean650 / true / false. Polite announcements are opt-in.
variant / tone / labelText variant / tone / stringTypography and accessible label. Default variant title.
direction / bounceauto | up | down / numberWhich way digits roll (auto), and spring bounce from 0 to 1.
trendbooleanfalse. Shows a decorative green or red arrow for the direction of the last change.

Jolt rolls the changing digits while the canonical formatted value remains available to assistive technology. Currency, grouping, decimal changes and rapidly replaced values use the same presentation. The first SSR/client paint is the final value, with no entrance from zero. Reduced motion settles immediately. Disabling animation stops the active effect. Use formatValue for an application-specific formatter, and keep its output deterministic between server and client.

With trend, a green arrow pops in when the value goes up and a red one when it goes down. The arrow appears from the first change, is hidden from assistive technology and leaves the accessible name and announcements as the value alone. direction forces the digits to roll up or down, for example for a countdown, and bounce tunes the roll's spring.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const revenue = ref(12480.5)
const orders = ref(128)
const currency = ref('USD')
function grow() {
  revenue.value += 1376.25
  orders.value += 17
}
function refund() {
  revenue.value -= 248.75
  orders.value = Math.max(0, orders.value - 3)
}
</script>
<template>
  <MCard padding="xl" gap="lg">
    <MRow justify="between" align="center" wrap gap="sm"
      ><MText
        :text="t('STUDIO / LIVE', 'ESTÚDIO / AO VIVO')"
        variant="overline"
        tone="muted" /><MBadge :text="t('This month', 'Este mês')" tone="success"
    /></MRow>
    <MColumn gap="xs"
      ><MText
        :text="t('Small ideas. Real momentum.', 'Pequenas ideias. Grandes passos.')"
        variant="heading" /><MText
        :text="t('Your work, adding up.', 'Seu trabalho ganhando valor.')"
        tone="muted"
    /></MColumn>
    <MNumberFlow
      id="flow-revenue"
      :value="revenue"
      :label="t('Revenue', 'Receita')"
      :locale="pt ? 'pt-BR' : 'en-US'"
      :format="{ style: 'currency', currency }"
      trend
    />
    <MSeparator />
    <MRow gap="xl" align="center" wrap
      ><MColumn gap="xs"
        ><MText
          :text="t('Orders fulfilled', 'Pedidos entregues')"
          variant="caption"
          tone="muted" /><MNumberFlow
          :value="orders"
          variant="title"
          :bounce="0.35"
          trend
          :label="t('Orders', 'Pedidos')" /></MColumn
      ><MColumn gap="xs"
        ><MText
          :text="t('Goal reached', 'Meta alcançada')"
          variant="caption"
          tone="muted" /><MNumberFlow
          :value="Math.min(1, revenue / 20000)"
          variant="title"
          :format="{ style: 'percent', maximumFractionDigits: 1 }" /></MColumn
    ></MRow>
    <MRow gap="sm" wrap
      ><MButton :text="t('New orders', 'Novos pedidos')" icon="plus" @click="grow" /><MButton
        :text="t('Refund', 'Reembolso')"
        variant="secondary"
        @click="refund" /><MButton
        :text="currency === 'USD' ? 'BRL' : 'USD'"
        variant="ghost"
        @click="currency = currency === 'USD' ? 'BRL' : 'USD'"
    /></MRow>
  </MCard>
</template>

Web uses Intl.NumberFormat; iOS and Android use system number formatters. format accepts style (decimal, currency, percent), currency, currencyDisplay (symbol, code), useGrouping, minimumIntegerDigits, minimumFractionDigits and maximumFractionDigits. Symbols and spacing follow the system locale data. For compact notation, units or custom rules, supply formatValue.

Desktop ​

On the Mac and on Windows the number is one native label formatted with Intl.NumberFormat; a new value rolls in from below or above as a whole, not digit by digit, and trend shows the same arrow. bounce lands the number on a spring, and announce speaks only on the Mac for now. See Desktop components.

Components for NativeScript and Web. Starting with Vue.