Text Morph

Animated

A short label that rearranges its letters into the next one.

Source
$npx @dinachi/cli@latest add text-morph
Deploying
children
blur
distance
duration

Usage

import { TextMorph } from "@/components/ui/text-morph"

export function DeployStatus({ done }: { done: boolean }) {
  return <TextMorph>{done ? "Deployed" : "Deploying"}</TextMorph>
}

Examples

Deploying
A status label rearranging in place.
import { useState } from 'react';
import { TextMorph } from '@/components/ui/text-morph';

const statuses = ['Deploying', 'Deployed', 'Deploy failed'];

export function Example() {
  const [index, setIndex] = useState(0);

  return (
    <TextMorph className="text-xl font-medium">{statuses[index]}</TextMorph>
  );
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

When to use it

Characters shared by both strings slide to their new places; the rest fade. The more the strings share, the better it works.

  • Short labels that change in place: Deploying to Deployed, a unit, a toggle's label.
  • Skip it for unrelated strings and sentences; every character animates, at a cost per character.
  • For numbers, use Number Ticker.

Behaviour

  • Exits run at 60% of the entrance duration.
  • Departing characters leave the flow at once, so the gap closes immediately.
  • Splits by grapheme: combining accents and multi-codepoint emoji stay whole. Repeated characters keep distinct identities.
  • No per-character stagger.

API

childrenstring
The text to show. Changing it runs the morph. Required.
blurnumber = 2
Blur radius in px on arriving and departing characters.
distancenumber = 8
Vertical travel in px for arriving and departing characters.
durationnumber = 0.25
Seconds. Keep it under 0.3.

Accessibility

  • At rest the text is one text node: selectable, findable and wrappable. It splits only during the morph.
  • During the morph, split characters are aria-hidden and a visually hidden copy is read instead.
  • Reduced motion never splits the text; the change becomes a short crossfade.