vael-ui v0.5.7

Data display

Layout

AnimatedNumber

A number whose changed digits roll to their new value, formatted for any locale. Use it for counters, prices and stats that change on screen.

Install

import { AnimatedNumber } from 'vael-ui'

Playground

60

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { AnimatedNumber } from 'vael-ui'
</script>

<template>
  <AnimatedNumber :value="60" locale="en-US" />
</template>

Props

NameTypeDefaultDescription
valueRequirednumberThe number to show. Changing it rolls each changed digit to its new value.
formatIntl.NumberFormatOptionsIntl.NumberFormat options: currency, percent, compact, fraction digits and so on.
localestringBCP 47 locale for the digits and separators. Unset, it follows the nearest ConfigProvider, then the browser.
motionAnimatedNumberMotiontrueHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }). { when: 'visible' } holds every digit at 0 until the number scrolls into view, then rolls them to the value. false swaps digits without rolling. Unset, it follows the nearest ConfigProvider.
uiPartial<Record<'root', UiPartValue>>Class and style overrides for each part.

Events

No events.

Slots

No slots.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

AnimatedNumber: its appearance, timing for the roll, and when: 'visible'.

<AnimatedNumber
  :motion="{ initial: { root: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitrootSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
spring{ damping, response }Times how its value moves when it changes, from the steppers, the keyboard or your code.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

It has no keyboard interaction of its own.

  • The formatted value sits in visually hidden text, and the rolling digits are aria-hidden. Screen readers read the final value, never an in-between frame.
  • With { when: 'visible' }, the digits wait at 0 on screen, but screen readers already get the value.
  • It has no live region, so value changes are not announced.