AnimatedText
Included in RC.12
Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.
<MAnimatedText :text="headline" by="word" :replayKey="take" variant="display" />| Prop | Type | Default | Contract |
|---|---|---|---|
text / variant / tone | string / typography / palette | required / title / default | Canonical text and shared typography. |
by | word or letter | word | Animation segmentation. |
duration / stagger / distance | number | 650 / 35 / 16 | Milliseconds and vertical px/DIP; positive duration, nonnegative stagger. |
animated / appear / replayKey | boolean / boolean / string or number | true / true / 0 | Enable playback, entrance on attach and explicit replay. |
delay / settle | number / boolean | 0 / false | Milliseconds before the entrance, to chain lines; settle lifts the line softly once its last word lands. |
gradient | MotionTextGradientOptions | none | Opt-in gradient clipped to the letters, 2–8 colors; a sheen sweeps once after the entrance. |
Jolt owns word/letter entrance and replacement playback. Text is explicit, not rich slotted markup. The server renders readable canonical text; animation starts only after the renderer is ready. Updating text or replayKey replays the effect; replay() does the same. animated=false stops playback. Reduced motion follows the runtime policy. There is no automatic phrase timer or endless animation.
delay holds the entrance so a second line can follow the first, as in the demo's caption. With settle, the line gives a soft lift once its last word or letter is in place; the lift is decoration, plays only after a completed entrance and stays still under reduced motion. settle wraps the text in a box, so app attributes still land on the text itself.
With gradient, the entrance owns the letters while it runs; the gradient takes over when it lands, sweeps an optional sheen once and stays as a static fill. It is released before a replay, so the two never paint the same glyphs, and it follows font and theme changes. With animated=false or reduced motion the static gradient appears without a sweep. The text stays one plain node with one accessible name; forced colors on Web keep ordinary text. See text gradient and sheen.
<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 take = ref(0),
replay = ref(0),
letters = ref(false),
animated = ref(true),
settle = ref(true)
const phrase = computed(() =>
t(
['Make room for wonder.', 'Follow the unexpected.', 'Let curiosity lead.'][take.value % 3]!,
['Abra espaço para o encanto.', 'Siga o inesperado.', 'Deixe a curiosidade guiar.'][
take.value % 3
]!,
),
)
</script>
<template>
<MColumn gap="lg">
<MText text="WORDS / IN MOTION" variant="overline" tone="primary" />
<MCard gap="lg" padding="lg"
><MText :text="`0${take + 1}`" variant="caption" tone="muted" /><MAnimatedText
id="animated-phrase"
:text="phrase"
variant="display"
:by="letters ? 'letter' : 'word'"
:replayKey="replay"
:animated="animated"
:settle="settle"
:stagger="letters ? 18 : 65" /><MAnimatedText
id="animated-caption"
:text="
t('A little movement. A different feeling.', 'Um pouco de movimento. Outra sensação.')
"
variant="body"
tone="muted"
:replayKey="`${take}:${replay}`"
:animated="animated"
:delay="letters ? 520 : 360"
:distance="8"
:stagger="30"
/></MCard>
<MRow gap="sm" wrap
><MButton :text="t('Next phrase', 'Próxima frase')" @click="take++" /><MButton
:text="t('Replay', 'Repetir')"
variant="secondary"
@click="replay++"
/></MRow>
<MRow gap="md" wrap
><MSwitch v-model="letters" :label="t('Animate letters', 'Animar letras')" /><MSwitch
v-model="animated"
:label="t('Animation enabled', 'Animação habilitada')" /><MSwitch
v-model="settle"
:label="t('Land with a lift', 'Pousar com um impulso')"
/></MRow>
</MColumn>
</template>Desktop
On the Mac and on Windows each word, or each letter with by="letter", is a native label that rises and fades into place through the Jolt desktop drivers, and the line is read as one name. Reduced motion, animated=false or text longer than 256 characters shows one still label. settle lifts the line around its centre once the last word lands. gradient is accepted and has no effect: the hosts have no fill clipped to glyphs. See Desktop components.