0.0.2 • Published 1 year ago

react-dice-new-roll v0.0.2

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

React Dice

Library for creating multisided dice and rolling them. Check out the demo here.

sample dice roll

Installation

npm install react-dice-new-roll

Dependencies

Usage (ES6)

import React from 'react'
import ReactDice from 'react-dice-new-roll'
import 'react-dice-new-roll/dist/react-dice-new-roll.css'

class App extends React.Component {

  render() {
    return (
      <div>
        <ReactDice
          numDice={2}
          rollDone={this.rollDoneCallback}
          ref={dice => this.reactDice = dice}
        />
      </div>
    )
  }

  rollAll() {
    this.reactDice.rollAll()
  }

  rollDoneCallback(num) {
    console.log(`You rolled a ${num}`)
  }
}

Available Options

NameTypeDefaultDescription
rollDone{String/Function}nullcallback returns total & individual values from dice roll
numDice{Number}4The number of dice you wish to have
defaultRoll{Number}6The number you want displayed before a roll
outline{Bool}falseShow a 1px outline for each face of the die
outlineColor{String}#000000hex color code for outline color if outline is true
margin{Number}15margin between each die
faceColor{String}#ff00achex color code for the face of the die
dotColor{String}#1eff00hex color code for the dots on the die
dieSize{Number}60px width/height of each dice face
rollTime{Number}2time in seconds for the roll animation
disableIndividual{Bool}falsedisable clicks on die to roll each individually

Provided functions

rollAll([values]): rolls all die and calls rollDone with total from roll. You can preset the values you would like the outcome to be by passing array of numbers, if not result will be random.