JSPM

react-random-reveal

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 160
  • Score
    100M100P100Q83851F
  • License MIT

React component/hook to add a little thrill before revealing the truth via random character animation

Package Exports

  • react-random-reveal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-random-reveal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React Random Reveal

npm GitHub Workflow Status Codecov npm bundle size

React component/hook to add a little thrill before revealing the truth. This effect is achieved via a character animation that shows random characters before revealing the text you want to emphasize. The library provides full control over the reveal run: its duration and easing can be freely adjusted.

  • Animate random letters, numbers, words or even emojis
  • Performance optimized with single requestAnimationFrame loop to animate the random characters (no setInterval used)
  • Built with TypeScript

Installation

yarn add react-random-reveal

or

npm install react-random-reveal

Demos

Text Demo Emoji Demo Words Demo
Edit cslqw Edit kp7ly Edit 8rr2w

Basic usage

As a component:

import { RandomReveal } from 'react-random-reveal'

const AddSuspenseComponent = () => (
  <RandomReveal
    isPlaying
    duration={4.6}
    revealDuration={0.5}
    characters="hello world"
  />
)

As a hook:

import { useRandomReveal } from 'react-random-reveal'

const AddSuspenseComponent = () => {
  const characters = useRandomReveal({
    isPlaying: true,
    duration: 4.6,
    revealDuration: 0.5,
    characters: 'hello world'
  })
  
  return characters
}

Props

Prop Name Type Default Description
isPlaying boolean required Play and pause animation.
duration number required Total duration in seconds. The duration includes the overall time random characters are shown plus the time for revealing the characters.
characters string | Array<string> required Characters to reveal in the end of the duration. These could be letters, numbers, words or emojis.
speed number 8 Characters change speed from 0 to 10. At 10, new the characters will be shown on each frame, approximately every 16.6ms.
revealDuration number 0.6 The duration to reveal all characters is represented as a fraction of the total duration. This is a number between 0 and 1. When set to 0, all characters will be revealed in the end of the duration at once. When set to 1, characters will start revealing from the beginning of the duration.
revealEasing 'linear' | 'easeInQuad' | 'easeOutQuad' | 'random' linear The easing function used to reveal characters during the reveal duration.
characterSet Array<string> English alphabet: ['a', 'b', 'c', ... 'z'] Characters that will be used during the random characters run.
ignoreCharacterSet Array<string> - Characters that won't be animated and will always be revealed. Can be used to ignore animating space or any special characters.
onComplete function(): undefined | [shouldRepeat: boolean, delay: number] - On complete handler. It can be used to repeat the animation by returning an array where the first element shouldRepeat indicates if the loop should start over and second element delay specifies the delay before looping again in milliseconds.