Using plugins
A plugin changes how a value is cut into pieces, how those pieces move, or both. Each one is its own import, so you only ship the ones you use.
import { classic } from "torph";
import { mask } from "torph/plugins/mask";
<TextMorph plugins={[mask(), ...classic()]}>{headline}</TextMorph>;The default set
torph's own look is a set of plugins too, classic():
numbers()rolls figures by place value.groups()moves a long run of replaced text as one piece.fade()fades text in as it arrives and out as it leaves.scale()adds the slight shrink as it does.
With no plugins option, that set runs. Set plugins and your list replaces it, so to add to torph's look, spread classic() after yours.
Order matters
Plugins run in the order you list them. The first plugin with a hook for a piece of text moves it, and the first plugin that claims a word cuts it up. Put yours first, so it wins over the classic ones:
In the second row, fade() comes first and handles arriving text, so mask() never gets a turn. The mix demo shows which plugins override which, for any combination.
Leaving parts out
To drop part of the default look, list the parts you want:
import { fade, groups, numbers, scale } from "torph";
plugins={[groups(), fade(), scale()]} // no number rolling
plugins={[numbers(), groups(), fade()]} // no shrinkscale() scales whatever moves the text, a plugin's motion included. Leave it out when a plugin scales text itself.
plugins={[]} is the engine on its own: staying text still slides, arriving text appears and leaving text disappears.
Re-renders
A new array on every render is fine. torph matches plugins by name and options, and only rebuilds the morph when one of those changes.
The plugins
Each one is imported from torph/plugins/<name>. See them all moving, with their source, on the plugins page.
Everyday
mask() | New text rises into place behind a mask. |
fadeUp() | New text fades up into place. |
cascade() | Text arrives a line at a time. |
ticker() | New text pushes the old out. |
fadeThrough() | Fades out, then fades in growing. |
sharedAxis() | Old leaves one way, new arrives the other. |
blur() | Letters rise into focus and blur away. |
words() | A changed word swaps whole. |
Numbers
odometer() | Each wheel turns the way the value went. |
countup() | Counts through the values between. |
trend() | Flashes green up, red down. |
roll() | The value rolls round like a barrel. |
slot() | Changes roll through a window. |
reveal() | Each place turns over to its new character. |
flap() | Letters flip like a departure board. |
Editing and structure
redline() | Track changes: struck out, then underlined. |
rows() | Reordered lines slide to their place. |
tokens() | Identifiers change at their joins. |
caseless() | A change of case pops in place. |
typewriter() | Backspaces, then types the new text. |
Playful
squash() | Stretch, squash and splat. |
wave() | Letters drop in with a bounce. |
stamp() | New text slams down like a stamp. |
stack() | The whole value slides like a card. |
scramble() | Letters scramble in and out. |
lookalike() | Letters step through lookalike glyphs. |
smoke() | Old text wisps away like smoke. |
glitch() | Changes come through a glitch. |
neon() | Flickers on like a neon tube. |
shatter() | Old text cracks into falling shards. |
dissolve() | Letters break into dots and gather. |
ripple() | New letters ripple out from the change. |