2.1.1 • Published 11 months ago

react-text-animate v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

šŸ—‚ļø Table of Contents

šŸ“ Overview

The react-text-animate library offers a seamless blend of ease & functionality, providing declarative, plug-and-play animated text components alongside a range of customization options. Built entirely with TypeScript and powered by Framer Motion, the library delivers production-ready animations with buttery-smooth performance at 60fps. The animated text components also feature built-in viewport detection that activates animations as the component scrolls into view, while also offering customization options to enhance their versatility. With robust code quality maintained by ESLint and Prettier, and an optimized, compact bundle size achieved through Rollup's tree shaking and dead code elimination, this library is both efficient and reliable.

šŸŽ Features

  • 🧩 Simple and Declarative: Plug-and-play components that are easy to use yet customizable.
  • šŸ”­ Built-in Viewport Detection: Activates animations as the component scrolls into view.
  • šŸ“˜ TypeScript-Powered: Components are built purely with TypeScript for type safety and reliability.
  • šŸŒ€ Fueled by Framer Motion: Production-ready, 60fps animations that are smooth and performant.
  • āœ… High-Quality Code: ESLint and Prettier integration ensures clean, robust code.
  • ā™æļø Screen Reader Accessible: The text within the components is fully readable by screen readers.
  • ⚔ Optimized Bundle Size: Rollup's tree shaking and dead code elimination keep the bundle lightweight and efficient.

šŸ“‚ Repository Structure

└── react-text-animate/
    ā”œā”€ā”€ .husky/
    ā”œā”€ā”€ src/
    │   ā”œā”€ā”€ assets/
    │   ā”œā”€ā”€ components/
    │   │   ā”œā”€ā”€ text-effect-3/
    │   │   │   ā”œā”€ā”€ index.tsx
    │   │   │   └── index.css
    │   │   └── ...
    │   ā”œā”€ā”€ index.ts
    │   └── styles.css
    ā”œā”€ā”€ package.json
    ā”œā”€ā”€ rollup.config.ts
    └── ...

šŸš€ Quick Start

Requirements:

A React/Next.js application.

!NOTE This package requires your project to use React v18.0 or higher to function properly.

āš™ļø Installation

Install the react-text-animate library in your React/Next.js application using one of the the below commands (as per the package manager installed in your system).

  • npm
    npm i react-text-animate
  • yarn
    yarn add react-text-animate
  • pnpm
    pnpm add react-text-animate

šŸ’» Usage

Note: Check out the live demo of this package along with many more usage examples on CodeSandbox.

Out of the box, you can use one of the components as shown in the example below:

import { TextEffectOne } from 'react-text-animate'

const App = () => {
  return <TextEffectOne text="TYPOGRAPHY" />
}

export default App

And here is the result! šŸŽ‰

Text Effect One Result

Yes, getting started is that simple! However, don't let the simplicity make you think there's nothing more to it. Each component offers a range of customization options. Feel free to experiment with these settings until you achieve your desired result. Get creative by adjusting colors, letter spacing, font style and font weight, and try different font families using the className and style props! Below are the props available for the <TextEffectOne /> component that was used above:

!NOTE The only required prop is text. Rest all are optional. Most of the props for the <TextEffectOne /> component are common to all other animated text components. Only the additional props for other components will be listed to avoid redundancy. So a component (except <TextEffectOne />) may have more props than those listed in the table below.

🧩 Component: <TextEffectOne />

PropTypeDefaultDescription
wrapperElementkeyof JSX.IntrinsicElementspJSX-equivalent of HTML Element wrapping the entire componentFor e.g. div, span, strong, etc.
textstring | string[]undefinedThe actual text to animate. For e.g. "ELEGANT", ["Multline", "Line 2"], etc.
classNamestringundefinedHTML class name applied to the wrapper element to style the text. Tip: Use tailwind utility classes for styling!
styleCSSPropertiesundefinedJSX inline style object. For e.g. { fontStyle: 'italic' }.
rotationnumber0Rotation Angle of letters (or words, when wordByWord prop is true). For e.g. 67.5, -45, etc (in degrees).
staggerDurationnumber0.1Delay between the animation of each individual letter (in seconds).
fromTopbooleanfalseAnimate letters from top to bottom.
fromLastbooleanfalseAnimate letters from right to left.
wordByWordbooleanfalseAnimate letters word-by-word instead of character-by-character.
initialDelaynumber0Delay before starting the animation (in seconds).
animateOncebooleanfalseWhen the text component scrolls out of view and then back into view, the animation is triggered again. This prop can be used to turn this behaviour off.
elementVisibilityAmountnumber0.5The amount of an element that needs to enter the viewport for the animation to be triggered. This is defined as a number between 0 and 1.
lineHeightnumber0.8 for text with only uppercase letters, else 1.2Specifies the line height to prevent lowercase characters with descenders (like 'g', 'j', 'p', 'q', 'y') from being cut off in some fonts. Adjust this property to fit the font as needed.

🧩 Component: <TextEffectTwo />

PropTypeDefaultDescription
textstringundefinedThe actual text to animate. For e.g. "Hey yo!".
filterbooleantrueToggles the blur effect in the animation.
animationDurationnumber0.1Time taken for the entire animation to complete (in seconds).

🧩 Component: <TextEffectThree />

The props for this component and further components mentioned below include some from both <TextEffectOne /> and <TextEffectTwo />. Note: This component animates on hover! And works best with text that contains only uppercase characters.

🧩 Component: <TextEffectFour />

PropTypeDefaultDescription
cursorConfigCursorConfigundefinedThe styling of the cursor along with some other properties (that are listed in the below table). Use it to create different types of cursors & override the defaults. Note: Initially, this prop is undefined, but default styling is applied to ensure the cursor is visible on the screen.
fromCenterbooleanfalseStart the animation from the center.
Interface: CursorConfig
NameTypeDefaultDescription
typehidden | vertical | horizontalverticalTypes of cursors to choose from.
blinkRatenumber0.35Sets the cursor blink speed/interval (in seconds). Lower values increase blink frequency; higher values decreases it
widthstring1pxCursor width. For e.g. 4px, 1rem, etc.
colorstringcurrentColorCursor color. For e.g. cyan, green, #c4c4c4, etc
marginLeftstring0pxLeft Margin of the cursor (to add some more spacing)

🧭 Project Roadmap

We'll keep adding more animated text components in future! Keep checking back every weekend for updates on new components and enhancements. Additionally, if you want to contribute any, do check out the Contributing section.

šŸ“’ Changelog

šŸ”„ What's new!

2.1.1 (2024-09-01)

Bug Fixes

  • text-effect-4: cursor responsiveness issues fixed; other minor issues handled (002b7ad)

2.1.0 (2024-08-31)

Features

  • components: added grapheme spliter which adds emoji & foreign lang support (b1e0a39)
  • text-effect-1: added new prop 'wordByWord' (4b06a71)
  • text-effect-4: added new component text-effect-4! (e203fb1)

Note: Please read CHANGELOG.md for complete list of changes.

šŸ¤ Contributing

!IMPORTANT Please read CONTRIBUTING.md & CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us. I also strongly recommend that you check if you are using the latest version of the project. If you are not up-to-date, see if updating fixes your issue first. Also, check for open issues and pull requests to see if someone else is working on something similar.

Contributions are welcome! Here are several ways you can contribute:

  • Report Issues: Submit bugs found or log feature requests for the react-text-animate project.
  • Submit Pull Requests: Review open PRs and contribute by submitting your own new animated text component PRs.

šŸ“„ License

This project is protected under the MIT License. For more details, refer to the LICENSE file.

šŸ‘Š Acknowledgments

Some of these animations are inspired by the work of brilliant and generous individuals. I want to extend my heartfelt thanks to them for their invaluable contributions to the community.

Return to 'Overview' ā¬†ļø