npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-typing-sequence

v1.1.2

Published

A lightweight, composable, React component to render text typing animations.

Downloads

51

Readme

react-typing-sequence

NPM npm

Try it out

Try it here Check the GitHub repo

Introduction

A React Typing library.

Reasons:

There are already other well known Typing libraries that do their job, are well mantained and have been used for years now, so why the need for another library ? I found that to compose sequentially multiple animations with different styles/behaviours, you had to instantiate multiple Typing components and setup an internal React state to handle the trigger of the new text to type when the previous one was ended using something like onComplete or onEnd events. I just thought it was better to have a single component overpowered with the ability to handle sequential text, individually styled and with an individual behaviour.

Purely React based, two hundreds lines of code, fast, light, composable, easy API. The main idea is to be able to compose complex typing sequences, with "yoyo" effects, custom delays, custom CSS styling for each segment, custom cursors, etc... etc... Without having to instantiate multiple Components. You just render one <TypeAnimation text={textSequence} /> and textSequence is gonna be an array containing all the text and settings you wanna dynamically type.

Install

npm install --save react-typing-sequence

Or with yarn:

yarn add react-typing-sequence

Usage

Check the example folder for a comprehensive example of how to import and use the React Component in your application.

This is as simple as doing:

const MyComponent = () => <TypeAnimation text={textSequence} />;

API / Props

| Props | Default value | Required | Type | | ----------- | ------------- | -------- | ------ | | text | undefined | true | (IText | ITypeAnimation |number)[] | [] | | repeat | 0 | false | number | | repeatDelay | 1000 | false | number |

Types

interface ITypeAnimation {
	text: (IText | ITypeAnimation | number)[] | [];
	repeat?: number;
	repeatDelay?: number;
	indexTrigger?: number  // This prop makes sense only if used in a nested animation, since it allows to choose at what index of the nested typing sequence 
					       // to trigger the start of the next element of the main sequence
}

interface IText {
	content: string;
	tag?: string;
	delay?: number; // speed of typing
	yoyo?: boolean;
	cursor?: string;
	cursorDelay?: number;
	cursorColor?: string;
	[key]: string;
}

This is the example app props passed to the Component:

const typingText = [
	{
		content: 'This is',
		className: styles.text1,
	},
	500,
	{
		content: 'react-typing-sequence',
		className: styles.text2,
	},
	{
		content: 'a React Typing Library!',
		className: styles.text1,
	},
	500,
	// This is how you set up a multiple sequence nested in the typing timeline.
	// You can use it to nest infinite repeat yoyo sequences for examples or whatever you like
	{
		text: [
			{
				content: 'Fast',
				className: styles.text3,
				tag: 'span',
				yoyo: true,
			},
			{
				content: 'Highly Customizable',
				className: styles.text3,
				tag: 'span',
				yoyo: true,
			},
			{
				content: 'Composable',
				className: styles.text3,
				tag: 'span',
				yoyo: true,
			},
		],
		repeat: -1,
		repeatDelay: 1000,
	},
	500,
	{
		content: 'Hope you like it!',
		className: styles.text1,
	},
];

As you can see you can customize any chunk of the sequence singularly, they are gonna be executed sequentially, you can decide if some chunk has to perform a yoyo animation, you can style them by using standard JSX attributes className and inline style . You can pass whatever event listener or any other HTML attribute, it'll end up on the container element.

If you wish to nest another typing animation in the main typing animation, with its own isolated lifecycle, you can easily pass an object of type ITypeAnimation instead of IText, it's gonna work out of the box with no overhead since internally it's gonna call itself recursively.

If you pass a number, that's gonna be executed as a delay in ms between the animations.

Notes

Most of these typing libraries use a prop called speed to determine the typing speed, but it usually accepts a number that determines the delay in ms between the typing of each character, so I decided to call it delay instead, so to be clear that, the higher the number, the slower the typing speed.So you have full control on any kind of delay, character typing delay, text chunk delay, and repeat sequence delay.

License

MIT © react-typing-sequence