Components
Morph Text
Text that morphs from the old value to the new one when it changes.
Animates a label when its text changes. Characters the old and new text share slide to their new place, and the rest fade. Built on torph.
Click the button to step through a transaction’s labels.
Installation
Section titled “Installation”npx shadcn@latest add @0xui/morph-textpnpm dlx shadcn@latest add @0xui/morph-textyarn dlx shadcn@latest add @0xui/morph-textbunx --bun shadcn@latest add @0xui/morph-textimport { MorphText } from "@/components/morph-text";
<Button> <MorphText>{isPending ? "Pending…" : "Send"}</MorphText></Button>;Keep one MorphText mounted and change its text. Swapping between two MorphText elements replaces the label without a morph.
Examples
Section titled “Examples”Numbers
Section titled “Numbers”Digits roll by place value, so only the places that changed move. Use tabular-nums on the parent to stop the width from shifting.
<span className="tabular-nums"> <MorphText>{blockNumber.toLocaleString()}</MorphText></span>Where 0xui uses it
Section titled “Where 0xui uses it”| Component | What morphs |
|---|---|
| Transaction Button, Batch Transaction, Sign Message, Add Token | The button label, across phases. This covers Approve Button, Send and Swap too. |
| Contract Form | “Read” and “Reading…”. |
| Chain Selector | The current chain’s name. |
| Block Number, Gas Price | The live value. |
| Balance, Token Input | The balance and the fiat value. |
| Swap, Portfolio | The rate, price impact and total value. |
Token Amount only morphs with animate, so long lists don’t pay for it.
Behavior
Section titled “Behavior”| Case | What happens |
|---|---|
Text and numbers, alone or mixed like Approve {symbol} |
Joined into one label and morphed. |
| Children that hold an element | Rendered as-is, with no animation. |
| Screen readers | Read the plain text once. The animated characters are hidden from them. |
prefers-reduced-motion |
The text changes without animating. |
| No Web Animations API, as in jsdom | Plain text in a span, so tests can query the label. |
The text never wraps: torph sets white-space: nowrap. Use it for short labels and values, not sentences.
torph adds one <style> element to the page. Under a strict Content Security Policy, allow it or set disabled.
Also accepts torph’s options, such as ease, scale, numbers, decimals, locale and onAnimationComplete.
| Prop | Type | Default | Description |
|---|---|---|---|
children |
ReactNode |
— | Text to show. |
duration |
number |
400 |
Length of the morph, in ms. |
disabled |
boolean |
false |
Change the text without animating. |
className |
string |
— | Class for the wrapping span. |
