0.5.1 • Published 3 years ago

react-scramble v0.5.1

Weekly downloads
47
License
MIT
Repository
github
Last release
3 years ago

npm version code style: prettier

React component for text scramble animation.

Live Demo

Installation

npm install react-scramble --save

Usage

import React from 'react'
import Scramble from 'react-scramble'

class App extends React.Compoent {
  render() {
    return (
      <Scramble
        autoStart
        text="Scramble me!"
        steps={[
          {
            roll: 10,
            action: '+',
            type: 'all',
          },
          {
            action: '-',
            type: 'forward',
          },
        ]}
      />
    )
  }
}

Remember to use monospace fonts to make it looks better.

Step Format

Each step is an Object with following keys:

KeyTypeDefaultDescription
actionstringAction of the step, + as scramble, - as descramble and leave blank for do nothing.
rollnumberTimes of action in the step.
textstringChange the original text.
typestringallScramble/descrmble type of the step, one of all, random, forward.

Scramble Props

PropertyTypeDefaultDescription
autoStartbooleanfalseSet true to auto start animation after render.
bindMethodfunctionMethod binding callback function, see Bind Methods.
mouseEnterTriggerstringEvent trigger type when mouse enter, one of start, pause, reset, restart.
mouseLeaveTriggerstringEvent trigger type when mouse leave, one of start, pause, reset, restart.
noBreakSpacebooleantrueUsing no-break space or not.
preScramblebooleanfalseScramble the text after render.
speedstringmediumSpeed of scramble per second, one of slow, mediun, fast.
stepsarrayScramble steps, a list of Object in Step format.
textstringOriginal text.

Bind Methods

Give callback function to bindMethod to get the control methods of the scramble, for example

class ScrambleCommon extends React.Component {
  render() {
    return (
      <div>
        <Scramble
          text="Nor aware of gain"
          bindMethod={c => {
            this.setState({
              start: c.start,
              pause: c.pause,
            })
          }}
          steps={[
            {
              roll: 10,
              action: '+',
              type: 'all',
            },
            {
              action: '-',
              type: 'forward',
            },
          ]}
        />
        <button onClick={() => this.state.start()}>
          Start
        </button>
        <button onClick={() => this.state.pause()}>
          Pause
        </button>
      </div>
    )
  }
}

methods will be set into state after Scramble component mounted.

It has the following methods: start, pause, reset and restart.

Todo

  • Accept customize speed by giving number
  • Make random decramble fit roll
  • More action type
  • Options for random char pool
0.5.0

3 years ago

0.5.1

3 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago