New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-type-animation

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-type-animation

React typing animation based on typical.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44K
decreased by-38.35%
Maintainers
1
Weekly downloads
 
Created
Source

react-type-animation

A customizable React typing animation component.

Installation

npm install --save react-type-animation

Requires a react and react-dom version of at least 15.0.0.

Live Demo

A live demo can be found at: https://react-type-animation.vercel.app/

Usage

import { TypeAnimation } from 'react-type-animation';

const ExampleComponent = () => {
  return (
    <TypeAnimation
      cursor={false}
      sequence={[
        'One', 1000, 'Two', 2000, 'Three',
        () => {
          console.log('Done typing!');
        }
      ]}
      wrapper="h2"
      repeat={Infinity}
    />
  );
};

Important Usage Notes ⚠

Immutability

Due to the nature of the animation, this component is immutable once rendered, which means that props changes will never be reflected. Otherwise, the animation would have to be reset completely, which would look unnatural.

Here is an example which shows that you cannot render dynamic prop-values:

const [counter, setCounter] = useState(0)
 <TypeAnimation
      // DO NOT RENDER DYNAMIC VALUES!
      sequence={[`${counter}`, 1000, () => {setCounter(counter++)}]} // ANIMATION WILL ALWAYS RENDER 0!
      repeat={Infinity}
    />

In the example above, counter will always render as "0" within the animation and ignore state changes.

Hot Reload Bug

Because Hot Reload preserves previous state but re-renders the component, the Animation will start bugging out until you hard-reload the page.

Hence, whenever you make changes to the TypeAnimation component, you unfortunately have to reload your page.

Layout-shift

In order to prevent layout shift caused by the TypeAnimation component's text expanding, when typing long texts, you need to either wrap the TextAnimation component in an HTML element with a fixed width/height which is wider than the maximum expansion of the TypeAnimation element, or make that wrapper's position absolute.

Props

PropRequiredTypeExampleDescriptionDefault
sequenceyesarray[]['One', 1000, 'Two']Animation Sequence: [TEXT, DELAY-MS, CALLBACK]none
wrappernostringp,h2,div, strongHTML element tag that wraps the Animationdiv
speednonumber55, 65Speed Of Animation: The lower the slower65
repeatnonumber3, 0, InfinityAmount of animation repetitions0
cursornobooleanfalse, trueDisplay default blinking cursor css-animationtrue
classNamenostringcustom-class-nameHTML class name applied to the wrapper to style the textnone

Custom Cursor Animation

If you want to apply a custom cursor animation, set the cursor prop to false (which prevents any default css-styles from being applied) and set a custom className prop to the TypeAnimation component with your own css styles.

These are the base styles for the cursor animation:

.type::after {
  content: '|';
  animation: cursor 1.1s infinite step-start;
}

@keyframes cursor {
  50% {
    opacity: 0;
  }
}

If you want to modify the styles, simply make a styles.css file, copy and modify the styles and pass the prop className="type" to apply the custom styles.

If you would like the cursor to stop after a specific time, consider using a JSX styling library which lets you define CSS dynamically within your JSX Component, or simply replace infnite with a static finite number (like 2s) inside your custom css file.

Keywords

FAQs

Package last updated on 07 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc