Skip to content

AnimateSplit

A line of text arriving a word (or a letter) at a time. AnimateAppear walks down a list a child at a time; this walks along a sentence.

tsx
import { AnimateSplit } from 'neba';

<AnimateSplit render={<h1 />}>A line arriving a word at a time</AnimateSplit>;

Props

PropTypeDefaultDescription
textstringThe text, when it is easier to pass than to nest. Overrides children
by'word' | 'character''word'What one piece is. A heading of eight words is eight boxes; by character it is forty-six
effectNebaAnimation'slide'Which effect each piece arrives on, in the library own vocabulary
from'top' | 'right' | 'bottom' | 'left''bottom'Which edge a slide piece comes from
distancenumber | string'0.4em'How far a slide piece travels
localestringWhich language the text is in, for the word and character boundaries: a word boundary is not a space in Japanese, Thai or Chinese
scalenumberWhere a `grow` or `zoom` piece starts, as a multiple of its final size
anglenumberHow far a `rotate` piece turns from, in degrees
side'top' | 'right' | 'bottom' | 'left'Which edge a `reveal` piece is wiped from
renderuseRender.RenderPropRenders something other than a div (render={<h1 />}). Base UI's own escape hatch
childrenReactNodeThe text to split

Every other <div> attribute passes through to the root. The settings shared by every Animate* are defined in prop conventions.

Only text is split. Pass a string, or text; an element among the children contributes its words and nothing about its markup, because there is no honest way to animate half of a link.

Every piece is an inline-block (an inline box cannot be translated up), and each keeps the space that followed it, so a line still breaks between words and never inside the gap.

Examples

by and effect

by is what one piece is: word by default, because a heading of eight words is eight boxes and the same heading by character is forty-six. effect is which animation each piece arrives on, in the library's own vocabulary, so a split heading's fade and an AnimateFade are the same fade.

stagger

stagger is how long after one piece the next one starts, and it is what the effect is made of: 45 milliseconds by default. durationStep lengthens each successive piece and reverse runs the line from the end.

locale

Which language the text is in, for finding the boundaries. A word boundary is not a space in Japanese, Thai or Chinese, and splitting those on whitespace produces one piece holding the whole sentence.

Accessibility

  • The whole line is in the document once for a screen reader, in a clipped box, and the pieces are hidden from it. Without that a sentence is read as a list of forty-six separate letters and a find-in-page matches nothing.
  • A reduced-motion preference switches the animation off and the line is drawn whole.

Released under the MIT License