1.0.3 • Published 1 year ago

@jaymar921/react-randomizer v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-randomizer

By: Jaymar921

Figure

A simple Randomizer Component for react projects that can be used for raffle events. With animated scrolling effect 📜.

Installation

npm i @jaymar921/react-randomizer

Demo

Open Webiste - Randomizer-POC-Vercel

Component

Randomizer

PropsDescriptiondefault
backgroundColorChange the background color of the Randomizer Container that matches your site's background.white
textColorChange the text color of the randomizer (shuffling text).black
winnerTextColorChange the text color of the randomizer (winner text shown).black
commandRandomizer Command, start command will start the suffle effect, clear command will clear the screen and ready for reshuffle, reset command reset's the items list back to original.undefined
itemsList\<string>, data that will be used for shuffling.undefined
durationThe duration of the shuffling effect before a winner is drawn.1000 in milliseconds
completeCallbackInvoked when a winner is selected, it will pass a parameter of string, once a winner is selected, the items list will be modified, removing the selected winner in the array.(winner) => { /* your logic goes here */}
fontWeightChange the weight of the font.0
textSizeSize of the Randomizer Text in pixels.20
containerWidthChange the width of the Randomizer Div Container.300
containerHeightChange the height of the Randomizer Div Container.100
classNameCustom className style for the Randomizer Div Container.undefined

How to use

// app.jsx
import { useState } from 'react'
import './App.css'
import { Randomizer } from '@jaymar921/react-randomizer'

function App() {
  const list = ['Jayharron', 'Rodney', 'Kenneth', 'Ada', 'Neal', 'Alyssa', 'Jhon Mark', 'Bo', 'Harold Inacay', 'Harold Cuico', 'Xerxes', 'Raph', 'CJ', 'Dylan'];
  const [command, setCommand] = useState('');

  const onDone = (w) => {
    console.log(w);
  }
  return (
    <>
      <Randomizer 
        backgroundColor='#17A14B' /* Change the Background color of the randomizer */
        textColor='white'         /* Change the Text color of the randomizer (shuffling part) */
        winnerTextColor='red'     /* Change the Text color of the randomizer (winner displayed) */
        command={command}         /* Randomizer command (start, reset, clear) */
        items={list}              /* List of items to be shuffled (array of string) */
        duration={2000}           /* How long will be the shuffling to effect before displaying the winner */
        completeCallback={onDone} /* Invoked when a winner is selected, (winner) => { // your logic }*/
        fontWeight={900}          /* Weight of the font 0 - 900         | default: 0 */ 
        textSize={50}             /* Size of text in pixels             | default: 20 */
        containerWidth={500}      /* Width of the Randomizer container  | default: 300 */
        containerHeight={300}     /* Height of the Randomizer container | default: 100 */
        className=''              /* Custom className style for the Randomizer container */
        />        
      <div>
        <br /> <br />
        <button onClick={() => {setCommand('start')}}>Start</button>
        <button onClick={() => {setCommand('clear')}}>Clear</button>
        <button onClick={() => {setCommand('reset')}}>Reset</button>
      </div>
    </>
  )
}

export default App

Issues / Contribute

Github repo: react-randomizer

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago