Text Morph
Morphs between numeric strings grapheme by grapheme and between words as whole tokens, keeping aligned matches still and gliding shifted slots with FLIP transforms.
Customize
Installation
npx shadcn@latest add @kinetic/text-morphUsage
Pass the current string to text. When text changes, TextMorph morphs only the slots that changed while keeping identical aligned characters still.
"use client";
import { useState } from "react";
import { TextMorph } from "@/components/kinetic/ui/text-morph";
const VALUES = ["$1,240.00", "$1,580.50", "$2,040.50"] as const;
export function RevenueCounter() {
const [index, setIndex] = useState(0);
return (
<button
type="button"
onClick={() => setIndex((prev) => (prev + 1) % VALUES.length)}
className="text-3xl font-semibold tracking-tight"
>
<TextMorph text={VALUES[index] ?? VALUES[0]} />
</button>
);
}Numeric and word modes
Strings made of digits, currency symbols, signs, punctuation, and spaces split grapheme by grapheme using tabular-nums, so unchanged digits stay locked in place. Non-numeric phrases split by whole word and glide shifted matches with translate3d FLIP transforms instead of animating cell widths.
interface StatusLabelProps {
readonly status: string;
}
export function StatusLabel({ status }: StatusLabelProps) {
return <TextMorph text={status} blurPx={6} durationMs={420} staggerMs={24} />;
}Imperative control
Attach a TextMorphHandle ref to replay the entrance with play() or hide the text with a reverse blur-slide using reverse(). Combine with trigger="manual" when playback should wait for an explicit action.
"use client";
import { useRef } from "react";
import { TextMorph, type TextMorphHandle } from "@/components/kinetic/ui/text-morph";
export function ControlledMorph() {
const morphRef = useRef<TextMorphHandle>(null);
return (
<div className="flex flex-col items-start gap-3">
<TextMorph ref={morphRef} text="₫480.000" trigger="manual" />
<div className="flex gap-2">
<button type="button" onClick={() => morphRef.current?.play()}>
Play
</button>
<button type="button" onClick={() => morphRef.current?.reverse()}>
Reverse
</button>
</div>
</div>
);
}Motion preferences
blurPx (clamped to a maximum of 8), durationMs, staggerMs, and speed tune the morph cadence and scale with the document tempo. When reduced motion is active, TextMorph renders the final string immediately with no blur or slide and calls onComplete.
API Reference
TextMorph
Numeric and label text morphing with unchanged slot preservation and FLIP gliding.
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | - | Current string value to display. |
blurPx | number | 8 | Blur radius for entering and exiting glyphs. |
durationMs | number | 480 | Base morph duration in milliseconds. |
trigger | "mount" | "inView" | "manual" | "mount" | Activation trigger mode. |
speed | number | 1 | Speed multiplier. |