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-decode-animation

v1.0.7

Published

Decode effect typing animation for React

Downloads

48

Readme

react-decode-animation

Decode effect typing animation for React.

NPM JavaScript Style Guide npm downloads Known Vulnerabilities npm bundle size

preview (click here if preview not shown)

Install

npm install react-decode-animation

Usage

import React, { useRef } from "react";
import DecodeAnimation from "react-decode-animation";

function App() {
	const ref = useRef(null);
	return (
		<div>
			<DecodeAnimation
				ref={ref}
				autoplay // will play when rendered
				text={"This is an animation Example"}
			/>
			<div>
				<button onClick={() => ref.current?.play()}>Play</button>
				<button onClick={() => ref.current?.pause()}>Pause</button>
				<button onClick={() => ref.current?.reset()}>Reset</button>
			</div>
		</div>
	);
}

Props

| Name | Description | Type | Default | | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | --------------------------------------- | | text | The text that will be animated | string | - | | allowedCharacters | A list of character types for the encoded text to use, this will not work if customCharacters is in use.see Choosing Characters | AllowedCharatersList | ['uppercase', 'lowercase', 'numbers'] | | customCharacters | Custom characters for the encoded text to use, this will override allowedCharacters.see Displaying Any Characters | string | - | | autoplay | If True, DecodeAnimation will play once it enters the viewport | boolean | false | | onFinish | onFinish is triggered when the decode animation is finished | Function | - | | interval | The duration of each character reveal (in Milliseconds)see interval | number | 100 | | characterOptions | Options for each characterssee characteroptions | DecodeAnimationCharacterOptions | - | | state | Changing the state willstart, pause or reset the animation. This prop is not recommended, use useRef() instead. see Animate Programatically | 'start' 'pause' 'reset' | - | | ref | A React ref that contains functions for playing, pausing and reseting the animation,recommended. see Animate Programatically | React.Ref<DecodeAnimationRef> | - |


How To Use It

Before get started, please be noted that react-decode-animation is designed for short texts, and it's not ideal for long paragraphs.

Get Started

To get started, install the library.

npm install react-decode-animation

First, import react-decode-animation to your file.

import DecodeAnimation from "react-decode-animation";

Next, call DecodeAnimation and pass a string to text, we can also pass in autoplay if we want it to play once it renders.

<DecodeAnimation
	text={"Hello"} // required
	autoplay // This is optional, will play when rendered
/>

Animate Programatically

Sometime, we don't want the animation to play automatically, we want it to play when it's called. We can animate it by using a useRef() hook.

DecodeAnimationRef provides 3 functions, play() pause() reset().

| Function | Description | | --------- | ---------------------------------- | | play() | Plays the animation. | | pause() | Pauses the animation when playing. | | reset() | Resets and pauses the animation. |

import React, { useRef } from "react";
import DecodeAnimation from "react-decode-animation";

function App() {
	// If you're using TypeScript --> useRef<DecodeAnimationRef>(null) <-- remember to import
	const ref = useRef(null);
	return (
		<div>
			<DecodeAnimation ref={ref} text={"Animating by calling ref."} />
			<div>
				<button onClick={() => ref.current?.play()}>Play</button>
				<button onClick={() => ref.current?.pause()}>Pause</button>
				<button onClick={() => ref.current?.reset()}>Reset</button>
			</div>
		</div>
	);
}

:warning: There is another way to animate: Be very careful! Alternatively, we can animate it via states. Although not recommended(setting the same state will not work), it looks neat if you are just changing it once or twice.

import React, { useState } from "react";
import DecodeAnimation from "react-decode-animation";

function App() {
	// If you're using TypeScript --> useState<DecodeState>("Paused") <-- remember to import
	const [decodeState, setDecodeState] = useState("Paused");
	return (
		<div>
			<DecodeAnimation
				state={decodeState}
				text={"Animating by setting state."}
			/>
			<div>
				<button onClick={() => setDecodeState("Playing")}>Play</button>
				<button onClick={() => setDecodeState("Paused")}>Pause</button>
				<button onClick={() => setDecodeState("Reset")}>Reset</button>
			</div>
		</div>
	);
}

Choosing Characters (AllowedCharatersList)

By default, DecodeAnimation provides some basic character sets to work with. If you want to have a custom set of characters go see customCharacters.

| Sets | Description | Used by Default | | ----------- | ------------------------------------ | --------------- | | uppercase | QWERTYUIOPASDFGHJKLZXCVBNM | Yes | | lowercase | qwertyuiopasdfghjklzxcvbnm | Yes | | numbers | 1234567890 | Yes | | symbols | `~!@#$%^&*()-_=+{}[];:'"|\<>,.?/ | No |

You can choose what goes to your DecodeAnimation by specifying it on allowedCharacters.

// If you are only using one set
<DecodeAnimation
  text={"This text has numbers."}
  allowedCharacters="numbers"
/>

// If you are using multiple sets
<DecodeAnimation
  text={"This text has numbers and symbols."}
  allowedCharacters={["numbers", "symbols"]}
/>

Displaying Any Characters

<DecodeAnimation
	text={"This Text is encoded with greek alphabets."}
	customCharacters="ΑΒΓΔΕΖΗΘΙΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω" // looks AWESOME
/>
// output: θαυνπΨοΙΧσγιολΣΨσιξηβθλΡζΓυΞΧγθηεΓαμΥυΙΜΔζ

You can input a custom set of characters if the provided allowedCharacters is not what you need. In this example, we can use some greek alphabets to generate the code. We don't have to worry about duplicated characters DecodeAnimation will remove it automatically.


Animation Duration

There are 2 intervals that we can set. Play around to get the desired results.

interval

The duration of each character reveal (in Milliseconds). if inverval={1000}, DecodeAnimation will reveal a character every 1 second.

<DecodeAnimation
	text={"This Text is encoded with greek alphabets."}
	interval={100} // reveals a character every 100ms
/>

characterOptions

It is for the duration of each character looping speed. By default, characterOptions={{ intervalDeviation: 10, interval: 100 }}. characterOptions.interval is the base interval, and characterOptions.intervalDeviation is the milliseconds that the interval can deviate from.

// Example
<DecodeAnimation
	text={"This Text is encoded with greek alphabets."}
	characterOptions={{ intervalDeviation: 20, interval: 70 }}
/>
// the interval of each character is ranged from 50 - 90
// the lower the interval, the smoother loop it gets

License

MIT © MrGGTo