# Txtrvl - Text Reveal React Library Txtrvl is a text animation library for React, built around a ready-to-use `Txtrvl` component. It is designed to keep text animations working through text changes, resolution variations, font size adjustments, and line wrapping. The library provides customizable styles, multiple reveal effects, trigger controls, and TypeScript support. The component animates text one visual line at a time. Lines are measured from the browser's layout and update when the available width, text, or fonts change. [![NPM Version](https://img.shields.io/npm/v/txtrvl?logo=npm&color=e02a1d&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Ftxtrvl)](https://www.npmjs.com/package/txtrvl) ![Static Badge](https://img.shields.io/badge/license-MIT-purple) ![React >= 16.14.0](https://img.shields.io/badge/react-%3E%3D%2016.14.0-61dbfb?logo=react) ![Static Badge](https://img.shields.io/badge/lang-typescript-0b52b0) [![AI-friendly docs](https://img.shields.io/badge/AI--friendly-docs-8b5cf6)](./llms.txt) ## [DEMO PAGE](https://txtrvl.com/) ## Motivation ### Common challenges with text animation libraries and components: - ❌ Limited animation choices or different setup requirements for each effect - ❌ Animations are disrupted when the text content changes - ❌ Resizing the screen or container breaks the animation layout - ❌ Font size changes and web font loading require extra handling - ❌ Effects stop working correctly when text wraps onto more lines - ❌ Complicated styling, timing, and playback control - ❌ Missing TypeScript types or support for reduced-motion preferences ### Txtrvl outperforms other packages! Txtrvl gives you six interchangeable animation effects through one shared React component API. Every effect follows the browser's actual text layout, so you can change the animation while keeping support for responsive widths, font changes, and multiline text. - ✅ Six effects: `reveal`, `fade`, `slide-up`, `slide-left`, `blur`, and `scale` - ✅ Switch effects with a single `animation` prop - ✅ Supports text content updates without manual line splitting - ✅ Adapts to changes in screen size and container width - ✅ Adapts to font size changes and web font loading - ✅ Animates visual lines whether the text wraps onto two lines or ten - ✅ Customize styles, transition duration, and delay between lines - ✅ Control playback with scroll and manual triggers - ✅ TypeScript types included - ✅ Supports reduced motion and keeps text accessible to assistive technology ## Installation ```bash npm install txtrvl ``` ## Usage ```tsx import { Txtrvl } from "txtrvl"; export function Heading() { return ( ); } ``` The default animation is `reveal`. Available modes are `reveal`, `fade`, `slide-up`, `slide-left`, `blur`, and `scale`. Each mode uses the same duration and delay between visual lines. ## Next.js and module formats The published entry points include `"use client"`, so the component can be imported from a Next.js App Router page. Keep callback props and interactive state in a Client Component. ```tsx import { Txtrvl } from "txtrvl"; export default function Page() { return ; } ``` Both ESM (`import { Txtrvl } from "txtrvl"`) and CommonJS (`const { Txtrvl } = require("txtrvl")`) are supported, with declarations for each module format. Styles are included automatically; `txtrvl/styles.css` is also available for an explicit stylesheet import. ## Switch animations Use the `animation` prop to change the effect. A manual trigger lets you reset and play it again. Disable the scroll trigger when you want the button to control visibility on its own. ```tsx import { useState } from "react"; import { Txtrvl, type TxtrvlProps } from "txtrvl"; type Animation = NonNullable; const animations: Animation[] = [ "reveal", "fade", "slide-up", "slide-left", "blur", "scale", ]; export function AnimationPicker() { const [animation, setAnimation] = useState("reveal"); const [isVisible, setIsVisible] = useState(false); return (
{" "}
); } ``` Select a mode, then press **Play animation**. Press **Reset animation** before replaying it. ## Responsive text The component keeps natural text layout in the document, so its height follows the actual number of lines. It remeasures when its size changes and after fonts load. Use a fluid width and font size, and give the surrounding layout enough room to shrink. In flex or grid layouts, `minWidth: 0` on the text container can help. Explicit newlines are supported. Long tokens can wrap instead of overflowing a narrow container: ```tsx ``` Set typography through `style` or `className`, including your web font. When the user requests reduced motion with `prefers-reduced-motion: reduce`, text appears without animated transitions. The text remains available to assistive technology without repeated announcements from the visual line layers. ## Props ![image](https://github.com/MichalKowalczyk/Txtrvl/assets/17525378/50faf7cc-77d8-4acd-8d63-c364ba77d522) | Prop | Type | Default | Description | | --- | --- | --- | --- | | `text` | `string` | Required | Text to display, including optional newlines. | | `animation` | `"reveal" \| "fade" \| "slide-up" \| "slide-left" \| "blur" \| "scale"` | `"reveal"` | Effect applied to each visual line. | | `duration` | `number` | `1000` | Transition duration in milliseconds. | | `delayPerRow` | `number` | `200` | Delay between successive lines in milliseconds. | | `style` | `React.CSSProperties` | — | Container dimensions and text styling. | | `className` | `string` | — | Additional CSS class for the container. | | `onChange` | `(isVisible: boolean) => void` | — | Callback for scroll-trigger visibility changes. | | `scrollTrigger` | See below | Enabled | Configure visibility from scrolling. | | `manualTrigger` | `{ isVisible: boolean }` | — | Control visibility from React state. | `scrollTrigger` accepts `offsetY`, `disabled`, `resetPolicy`, `threshold`, and `delay`. `resetPolicy` accepts `"no-reset"`, `"above"`, or `"both"`. `offsetY` is measured in pixels and `delay` in milliseconds. When both scroll and manual triggers are enabled, either trigger can reveal the text. `TxtrvlProps` is exported for TypeScript consumers. ## Scroll-trigger behavior The trigger uses `IntersectionObserver` to detect intersection with the viewport or an optional `scrollTrigger.root` element. Clipping by scrollable ancestors is taken into account, including text taller than the visible scroll area. | Option | Default | Meaning | | --- | --- | --- | | `root` | `null` | Viewport by default; an ancestor DOM element can be supplied as the scroll root. | | `threshold` | `0.5` | Fraction of the maximum visible area that fits in the viewport and clipping containers. | | `offsetY` | `0` | Expands or shrinks the root vertically, in pixels. Horizontal bounds stay unchanged. | | `delay` | `0` | Delay in milliseconds before applying a visibility change; cancelled if the condition changes. | | `resetPolicy` | `"above"` | Reset when the text goes below the visible area. `"both"` resets on either exit; `"no-reset"` keeps revealed text visible. | | `disabled` | `false` | Disables automatic triggering. Use `manualTrigger` to control playback instead. | For short, fully fitting text, a threshold of `0.5` means half its area. Taller text uses the part that fits in the visible container, so it can still start animating. Intersection describes geometry; it does not detect whether another element covers the text. ## Performance and typography Ordinary text is rendered once for accessible content and once across the visual line layers. Line boundaries are found with binary searches, and measurement updates are batched with `requestAnimationFrame`. Inherited typography updates through ancestor classes, inline styles, and direction attributes also trigger remeasurement. Some text needs its full paragraph context to preserve layout, including RTL scripts, emoji, tabs, justification, text transformations, and hyphenation. These cases retain a paragraph copy per line and are more expensive for long passages. Use animated text selectively for large amounts of content; blur also adds rendering work. ## Development Use Node.js 22 or 24 to develop and build the library. Build tools such as `sass-loader` are development dependencies and are not installed as runtime dependencies of Txtrvl. ```bash npm run storybook ``` Storybook includes an animation selector, a responsive paragraph, and examples of each effect. Use the controls to change the text, typography, width, duration, and delay between lines. ## Credits If you like what you see, write to us and let's build or destroy something together. [contact@txtrvl.com](mailto:contact@txtrvl.com) #### Designed by [SPNM](https://www.spnm.pl) Szymon P. Nowak Mieszkiełło #### Developed by [Codeebo](https://codeebo.pl) Michał Kowalczyk