1.1.2 ā€¢ Published 8 months ago

react-casino-roulette v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React Casino Roulette

The first open source React casino roulette. This includes both table and wheel. No canvas used, only pure HTML, CSS, and JS for the best performance. No loading screens needed.

That's like selling. Fewer clicks mean more purchases. Faster loading speed leads to higher conversion rates.

Live example - react-casino-roulette.ivanadmaers.com
Another one - codesandbox.io/s/react-casino-roulette-example-ksw8u4

If you need the same functionality, plus 2 supported types (American and European roulette), and plain CSS and JS implementation, take a look at - https://github.com/IvanAdmaers/casino-roulette.

Please, pay your attention, some of the bet types names (STRAIGHT_UP, CORNER, etc) you receive when handeling user's bet may be incorrect. Everything else works great. It's fixed in https://github.com/IvanAdmaers/casino-roulette.

React Casino Roulette

Features

  • šŸš€ No canvas, pure HTML, CSS, JS
  • šŸ’Ŗ The first open source casino roulette
  • šŸ”„ Table + Wheel
  • āŒ› No loading screens needed
  • āœ… Ease of use
  • šŸ“ MIT license
  • šŸ“¦ Lightweight
  • šŸ”§ Jest
  • šŸŽ‰ NextJS, GatsbyJS and RemixJS support

Installation

# Via npm:
npm i react-casino-roulette
# Via yarn:
yarn add react-casino-roulette

Usage

Table

import { useState } from 'react';
import { RouletteTable } from 'react-casino-roulette';

import 'react-casino-roulette/dist/index.css';

export const Table = () => {
  const [bets, setBets] = useState({});

  const handleBet = (betData) => {
    const { id } = betData;

    setBets((prevState) => ({
      ...prevState,
      [id]: {
        icon: 'https://cdn-icons-png.flaticon.com/512/10095/10095709.png',
      },
    }));
  };

  return (
    <div style={{ maxWidth: 800, margin: 'auto' }}>
      <RouletteTable bets={bets} onBet={handleBet} />
    </div>
  );
};

Wheel

import { useState } from 'react';
import { RouletteWheel } from 'react-casino-roulette';

import 'react-casino-roulette/dist/index.css';

export const Wheel = () => {
  const [start, setStart] = useState(false);
  const [winningBet, setWinningBet] = useState('-1');

  const doSpin = () => {
    setWinningBet('00');
    setStart(true);
  };

  return (
    <div>
      <div
        style={{ display: 'flex', justifyContent: 'center' }}
      >
        <RouletteWheel start={start} winningBet={winningBet} />
      </div>
      <div>
        <button type="button" disabled={start} onClick={doSpin}>
          Spin
        </button>
      </div>
    </div>
  );
};

Props

Where * means required

Table

PropTypeDefault valueDescription
bets*object-Object of bets for the table. See its BetType type here.
onBet*(params: IOnBetParams) => void-Triggers when user choose a bet on the table. See its IOnBetParams interface here
isDebugbooleanfalseSets debug mode

Wheel

PropTypeDefault valueDescription
start*boolean-Sets when the wheel should start spinning
winningBet*string-Sets the wheel winning bet. Available values: -1, 0, 00 and 1 - 36
onSpinningEnd() => void() => undefinedTriggers when the wheel stops spinning
withAnimationbooleantrueSets should the wheel plays rotating animation
addRestbooleantrueAdds an animation of the ball shifting after the end of the spinning

FAQ

ā“ Where can I find an example of using this package?
šŸ’¬ Use the links below:

ā“ How can I customize the table or wheel?
šŸ’¬ At this moment this is possible by overriding default css styles.

ā“ Can I use this with SSR?
šŸ’¬ Of course. And if you are using NextJS we would like to recommend you to import this package dynamically to decrease your project final bundle size.

ā“ What React versions does this package support?
šŸ’¬ This project requires:

  • react >=17.0.0
  • react-dom >=17.0.0

ā“ Are ideas welcome?
šŸ’¬ We value all ideas, improvements, suggestions and pull requests ā¤ļø.

Local development

  1. Clone the project

  2. In the root directory run

npm ci i

npm start

The last command runs webpack to compile our package to a dist folder

  1. cd example/

  2. Run

npm ci i

npm start

The last command runs Webpack Dev Server so you can see the app in browser.

  1. Enjoy the power!

enjoying the power

License

MIT

IMAGE ALT TEXT HERE