Git Product home page Git Product logo

react-effect-typewriter's Introduction

React Effect Typewriter

react-effect-typewriter is a lightweight and highly customizable React library that allows you to create captivating typewriter effects. The library's primary focus is on simplicity, customizability, SEO-friendliness and accessibility, ensuring that you can deliver engaging text animations while maintaining best coding practices.

The package comprises two main components - Paragraph and Container. The Paragraph component animates your text to appear one character at a time, and the Container component, a wrapper component, can hold multiple Paragraph components or other nested Container components to create more complex animations.

Installation

npm install react-effect-typewriter

Usage

All you need to start using the library is importing it & using the Paragraph element & it'll immediately give you the effect, see the code below:

import * as Typewriter from "react-effect-typewriter";

const App = () => {
  return <Typewriter.Paragraph>Hello Typewriter!</Typewriter.Paragraph>;
};

Under the hood, the Typewriter.Paragraph is a normal <p> element, so you can pass to it any props you can normal pass to a <p> element like className, id, onClick, ...etc.

In addition to that, there are a couple of custom props that you can use to customize the effect. These options are:

Parameter Description Default Value
typingSpeed? (Optional) The speed with which the characters are typed. Defined in milliseconds. 50
startAnimation? (Optional) If true, will start animation on mount, otherwise will wait for the prop value to become true. true
onStart? (Optional) A callback that is triggered when the typing animation starts. -
onEnd? (Optional) A callback that is triggered when the typing animation ends. -
onCancel? (Optional) A callback that is triggered if the typing animation is cancelled. -
onCharacter? (Optional) A callback that is triggered each time a character is typed. The typed character is passed as an argument to this function. -

Nesting Paragraphs

By default, the Paragraph element will start its animation as soon as it mounts on the DOM. However, you might have multiple paragraphs & you only want a paragraph to start appearing once the previous paragraphs have fully appeared, or you want them to only appear once a certain condition is met, for that, there is another element which is the Typewriter.Container element.

The Container element will make all its Paragraph children (doesn't have to be direct) only animate one after the other, based on the order of their appearance in the tree. It can also have another Container component as a children, so it will wait for the child Container to finish all its nested children before moving to other elements.

Example Usage:

import * as Typewriter from "react-effect-typewriter";

function App() {
  return (
    <Typewriter.Container>
      <Typewriter.Paragraph>This will appear #1</Typewriter.Paragraph>
      <Typewriter.Container>
        <Typewriter.Paragraph>This will appear #2</Typewriter.Paragraph>
        <Typewriter.Paragraph typingSpeed={20}>
          This will appear #3
        </Typewriter.Paragraph>
      </Typewriter.Container>
      <Typewriter.Paragraph typingSpeed={20}>
        This will appear #4
      </Typewriter.Paragraph>
    </Typewriter.Container>
  );
}

The Container component can take the following props:

Parameter Description Default Value
typingSpeed? (Optional) The speed with which the characters are typed. Defined in milliseconds. -
startAnimation? (Optional) If true, will start animation on mount, otherwise will wait for the prop value to become true. true
delayBetweenElements? (Optional) The delay between the start of the animation of each child element. Defined in milliseconds. 0

How the effect is created

I've written a vanilla CSS/Javascript article a while ago explaining the core idea behind creating this effect in an accessible way, you can check this article here: How to create a typewriter effect that is accessible & SEO friendly

Feedback

If you have any feedback or suggestions for improvement, please feel free to open an issue or submit a pull request on GitHub. We appreciate your contributions!

react-effect-typewriter's People

Contributors

mtg2000 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.