A React component for creating typing animations.

Overview

react-typewriter

A react component for animated typing text.

Installation

npm install --save react-typewriter

Usage

Pass in children to the TypeWriter component like any other component. Make sure to set the typing property to 1 when you want the component to begin animating.

import React from 'react';
import TypeWriter from 'react-typewriter';

class YourReactClass extends React.Component {

  render() {
    return (
      // Passing in text.
      <TypeWriter typing={1}>Hello World!</TypeWriter>
    );
  }

}

You can also pass in other components such as anchor tags and spans.

<TypeWriter typing={1}>
  Hello
  <span style={{color: 'blue'}}>World</span>
  !
</TypeWriter>

Child components can be nested as deep as necessary. Text is typed out as each character appears in a pre-order traversal of the nested structure.

Documentation

TypeWriter

props.typing

type: Integer default: 0

A value of 1 will cause the component type text left to right until completion. A value of -1 will cause the component to erase text right to left.

props.initDelay

type: Integer default: 1000

Delay before typing begins in milliseconds.

props.maxDelay

type: Integer default: 100

The maximum delay between each typed token in milliseconds.

props.minDelay

type: Integer default: 20

The minimum delay between each typed token in milliseconds.

props.fixed

type: Boolean default: false

This flag will ensure the enclosing container's size and shape is fixed. Prevents the text from shifting around as it grows into its container.

props.delayMap

type: Array[Object] default: none

Allows for setting characters or indexes that will increase or decrease the delay period until the next character.

The array contains objects requiring two keys: at: can either be a character, integer, or regex. If there are characters that match the string or regex, the delay period following that character will be increased by the delay: amount.

var delays = [{
  // At index 4, increase the delay period by 100ms.
  at: 4,
  delay: 100
},
{
  // Add a 400ms delay following every period character.
  at: '.',
  delay: 400
}];

props.onTyped

type: Function default: none

This callback is called when each token is typed in the typing animation. If the animation is erasing, it is called after each token is erased. The token that was typed/erased is passed as the first parameter in the callback. The token may be either a character or a React component. Will also pass the previous number of visible characters.

props.onTypingEnd

type: Function default: none

This callback is called once the typing animation has completed. This is when all text has been either revealed or erased.

props.stamp

type: Boolean

This property should be set on any TypeWriter child components that should be treated as a single token or stamp. The text inside a component with the stamp property will not be typed out, but will be revealed all at once.

Here, World! will be stamped onto the page instead of typed out:

<TypeWriter typing={1}>
  Hello
  <span stamp>World!</span>
</TypeWriter>

refs.reset

type: Function

This function can be called in order to erase the text immediately.

License

MIT

Comments
  • proxyConsole.js:56 Warning: Unknown props `onTypingEnd`, `initDelay`, `typing`, `maxDelay`, `minDelay` on <span> tag.

    proxyConsole.js:56 Warning: Unknown props `onTypingEnd`, `initDelay`, `typing`, `maxDelay`, `minDelay` on tag.

    Version

    0.4.1

    Steps to reproduce

    1. jsx source code :
                        <TypeWriter
                          onTypingEnd={this.typeIsDone.bind(this)}
                          initDelay={2000}
                          typing={this.state.erase}>
                          {this.state.messages[this.state.index]}
                        </TypeWriter>
    
    1. component same as source 1
      constructor(props) {
        super(props);
    
        this.state={
          messages:["선배와 동기의 A+ 비결", "선배, 친구", "과제, 족보", "썸녀의 썸남저격", "썸남의 썸녀저격"],
          index:0,
          erase:1
        }
      }
      typeIsDone(){
        if(this.state.erase == -1){
          if(this.state.index+1 >=  this.state.messages.length){
            this.setState({
              erase:1,
              index:0
            })
          }else{
            this.setState({
              erase:1,
              index:this.state.index+1
            });
          }
        }else{
          this.setState({
            erase:-1
          })
        }
      }
    
    1. shit.

    proxyConsole.js:56 Warning: Unknown props onTypingEnd, initDelay, typing, maxDelay, minDelay on tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop

    Expected behavior

    loop messages

    Actual behavior

    le.js:56 Warning: Unknown props onTypingEnd, initDelay, typing, maxDelay, minDelay on tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop

    Error Log

    opened by drakejin 5
  • #8 Rollup Build not building

    #8 Rollup Build not building

    Version

    0.2.1

    Steps to reproduce

    1. run npm install in project directory, react-typewriter does not build
    2. cd to node_modules/react-typewriter, run npm install

    Expected behavior

    project should build

    Actual behavior

    Error:

    [email protected] prepublish /Users/xxx/Code/xxx/node_modules/react-typewriter npm run build

    [email protected] build /Users/xxx/Code/xxx/node_modules/react-typewriter rollup-babel-lib-bundler --module-name TypeWriter -d build ./src/index.js

    Error while generating a build: [Error: Could not load null: path must be a string]

    opened by mikedizon 5
  • Fix eslint errors and clean up code

    Fix eslint errors and clean up code

    Since I plan to do some more work on this module I would like to propose a little more consistency in the code. Just a suggestion, hope you guys like it.

    opened by yn5 4
  • Uncaught Invariant Violation

    Uncaught Invariant Violation

    Getting strange error on 0.1.2

    Uncaught Invariant Violation: TypeWriter.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object.

    opened by mikedizon 3
  • Update compatibility for React 0.14

    Update compatibility for React 0.14

    React 0.14 does not want a display name attached to it and does not see it as a valid component. The Babel React transformer should also append the display name if needed.

    @ianbjorndilling Let me know if I should prepare a release for this. (Bump the minor package version, tagging the release and publishing to NPM)

    opened by frostney 2
  • Fix bug in componentShouldUpdate causing the component never to update when children are strings and have changed

    Fix bug in componentShouldUpdate causing the component never to update when children are strings and have changed

    @frostney, I'm sorry, just found out i made a mistake in my previous pull request: https://github.com/ianbjorndilling/react-typewriter/pull/13. Causing componentShouldUpdate never to return true when children is a string and has changed.

    opened by yn5 1
  • Start typing when typing prop is changed from 0 to 1 as well, not only when the prop is changed from -1 to 1

    Start typing when typing prop is changed from 0 to 1 as well, not only when the prop is changed from -1 to 1

    Currently the typing starts only when the typing prop is either initially set to 1, or when it is changed from -1 to 1. This pull requests allows it to start typing when the typing prop is changed from 0 to 1 as well.

    opened by yn5 1
  • Update react external configuration

    Update react external configuration

    This updates the configuration, so the React module name matches if it's not a global module. In case sensitive environments, the compiled module will not produce an error any more. For reference, this is the same configuration as used in react-router.

    opened by frostney 1
  • Visible chars are now a parameter in onTyped

    Visible chars are now a parameter in onTyped

    I have been in the situation where token alone is not enough in the onTyped callback. This happens when there are multiple occurrences of the same token in the text that's going to be displayed.

    With this pull request, the value of prevState.visibleChars is available as the second parameter in the callback, making it easier to make assumptions based on the token and the position.

    opened by frostney 1
  • Add onTypingStart

    Add onTypingStart

    @frostney
    Hi ! I'm a user about this repo. Thank you for making a great library!!

    When i was using this typewriter component, i wanted to control typing start timing. Previously, some commiters added the initDelay props but i think it is not a simple way enough to control timing.

    So, I add this onTypingStart props. The default value is true, but if user set false to this props initially, when the value trun out to be false, typing starts !!

    if there is no problem, please merge this PR 🙇

    This is a sample code.

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8"/>
        <title>TypeWriter Demo</title>
      </head>
      <body>
        <h1>TypeWriter</h1>
        <div id="type-writer-container"></div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-with-addons.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
        <script src="http://fb.me/JSXTransformer-0.12.1.js"></script>
        <script src="./react-typewriter.js"></script>
        <script type="text/jsx">
          class Sample extends React.Component {
            constructor(props) {
              super(props);
              this.state = {
                onTypingStart: false
              }
            }
            render() {
              return (
                <div>
                  <TypeWriter
                    fixed
                    onTypingStart={this.state.onTypingStart}
                    typing={1}
                    style={{ fontSize: 40 }}
                  >
                    Hello World!!
                  </TypeWriter>
                  <button onClick={() => this.setState({ onTypingStart: !this.state.onTypingStart })}>
                    typing start!!
                  </button>
                </div>
              );
            }
          }
          ReactDOM.render(
            React.createElement(Sample),
            document.getElementById('type-writer-container'));
        </script>
      </body>
    </html>
    
    

    This is demo.

    kapture 2018-10-04 at 23 36 39

    opened by nissy-dev 0
  • Fix for reverse typing bug (Issue #31)

    Fix for reverse typing bug (Issue #31)

    Bug was caused by setting the visibleChars state twice when prop typingis changed.

    Solution is to clear the _handleTimeout from running so that changing state won't fire twice.

    opened by archieherbias 1
  • minDelay / maxDelay

    minDelay / maxDelay

    Version

    0.4.1

    Steps to reproduce

    1. just installed.
    2. Warning: React does not recognize the minDelay prop on a DOM element
    3. same for maxDelay

    Expected behavior

    What should happen not show the error

    Actual behavior

    What is happening

    opened by fabianclain 5
  • Reversing typing order during animation breaks component

    Reversing typing order during animation breaks component

    Version

    0.4.1

    Steps to reproduce

    1. Set typing prop to 1
    2. Change typing prop to -1 during the typing animation
    3. Set typing prop to 1 again after animation

    Expected behavior

    It should (1.) start typing, (2.) erase the currently typed, and (3.) start typing again

    Actual behavior

    The plugin sets the visibleChars value in state to a value 1 of from what is should be.
    E.g., on erase, visibleChars should be -1, but if you change typing during the transition, it is set to -2. After that wrong value, it toggles between -2 and -1 instead of -1 and the length of the sentence.

    opened by rijkvanzanten 2
  • Outdated version of react as dependency

    Outdated version of react as dependency

    As explained in this thread, the react version is outdated and causing the dev tools to spot an outdated version of react. Can you please update or choose peerDependencies?

    opened by marcogreselin 0
  • Hi I used this react-typewriter good, but How to add another sentence?

    Hi I used this react-typewriter good, but How to add another sentence?

    Version

    0.4.1

    Steps to reproduce

    1. This sentence list is what I had. ['Hello World!', 'Welcome to react-typewriter!', 'React is awesome!']
    2. I want to view order by list after erase it. this is order of example.

    'Hello World!' -> erase 'Hello World!' -> 'Welcome to react-typewriter!' -> erase 'Welcome to react-typewriter!' -> ...

    done = () => {
    
        if (this.state.typing === 1) {
          this.setState({ typing: -1 });
        } else if (this.state.typing === -1) {
          this.setState({ typing: 1 });
        }
      }
    <TypeWriter typing={typing}
                         onTypingEnd={this.done}
                         reset={this.typed}
                    >
    

    How come do i get to reach it?

    opened by DDanggle 1
Owner
Ian Dilling
Ian Dilling
A JavaScript Typing Animation Library

Live Demo | View All Demos | View Full Docs | mattboldt.com Typed.js is a library that types. Enter in any string, and watch it type at the speed you'

Matt Boldt 12.6k Dec 31, 2022
Some ideas for modern multi-layer page transitions using CSS Animations.

Multi-Layer Page Reveal Effects Some ideas for modern multi-layer page transitions using CSS Animations. Article on Codrops Demo Sponsor Demo sponsore

Codrops 117 Nov 1, 2022
Modern ways of revealing new content using SVG animations.

Page Loading Effects Modern ways of revealing new content using SVG animations. Article on Codrops Demo Integrate or build upon it for free in your pe

Codrops 635 Dec 30, 2022
CSS loading animations with minimal effort!

Whirl CSS loading animations with minimal effort! whirl is a curation of CSS loading animations(whirls! ?? ). It started as a drop in CSS file to get

Jhey Tompkins 1.4k Jan 4, 2023
🔮 CSS loading animations made by single element.

Three Dots The project is a set of CSS loading animations created with three dots which made by just single element. I think the project can not only

Zongbin 1.2k Dec 29, 2022
Pure css cross-browser loading animations.

[ArtWorx] xLoader Pure css cross-browser loading animations. xLoader is part of the ArtWorx collection. Most of the loaders made by community, You can

Anas Tawfik 21 Nov 15, 2021
Create cool animated SVG spinners, loaders and other looped animations in seconds

SVG Circus SVG Circus enables you to create cool animated SVG spinners, loaders and other looped animations in seconds. Developing To run a local SVG

Alex Kaul 301 Dec 24, 2022
Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. This is a porting to Web Animation API of the fabulous animate.css project.

Animatelo Just-add-water Web Animations Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emp

GibboK 477 Nov 12, 2022
React particles animation background component

particles-bg React component for particles backgrounds This project refers to the source code of the Proton official website, I packaged it into a com

lindelof 561 Dec 24, 2022
A mouse particle effect react component

react-mouse-particles A mouse particle effect react component A very fun react library that can be used to create mouse particle effects, which are as

lindelof 92 Dec 17, 2022
A Snow Effect component for React.

react-snowstorm A Snow Effect component for React. Uses Snowstorm under the hood. Live Demo : http://burakcan.github.io/react-snowstorm Getting Starte

Burak Can 225 Aug 31, 2022
Liquideffect - Javascript Library for creating liquid effect on image and RGB effect on mouse direction.

LiquidEffect Javascript Library for creating liquid effect on image and RGB effect on mouse direction. Demo https://liquideffect.netlify.app/ Dependen

Rohail 8 May 6, 2022
A vue.js particles animation background component

particles-bg-vue A vue.js particles animation background component. Use it to make your website look cool. Check it out if you want to use it in React

lindelof 206 Dec 24, 2022
A-Frame Rainfall effect component

A-Frame Rain component aframe-rain is Rainfall effect component for A-Frame which displays a lot of rain drop/splash objects by using instancing techn

Takahiro 39 Dec 19, 2021
A bursting particles effects buttons component ✨💥❄️🌋

vue-particle-effect-buttons (demo) Bursting particle effect buttons for Vue. This library is a Vue portal of an awesome Codrops Article by Luis Manuel

Vincent Guo 252 Nov 11, 2022
🎨 Aquarelle is a watercolor effect component. Javascript library by @Ramotion

Aquarelle About This project is maintained by Ramotion, Inc. We specialize in the designing and coding of custom UI for Mobile Apps and Websites. Look

Ramotion 1.8k Dec 9, 2022
👓 Parallax tilt hover effect for React JS - tilt.js

React.js - Tilt.js React version of tilt.js Demo https://vx-demo.now.sh/gallery Install yarn: yarn add react-tilt npm: npm install --save react-tilt U

Jon 340 Dec 23, 2022
KenBurns Image Effect for React Native Applications

react-native-kenburns-view KenBurns Image Effect for React Native. Based on Image Component Image Component. Version: 4.1.0 Tested on React Native 0.6

Nimila Hiranya Samarasinghe 58 Sep 3, 2022
A small library for creating typing animations.

A small library for creating typing animations. View a short video demonstration here. Installation npm i tiper-js Usage Initialization is really simp

Carlos Santos 187 Nov 5, 2022