npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

roulette-for-project

v3.1.2

Published

The best React roulette

Downloads

11

Readme

React Roulette Pro

The best React roulette. Focus on optimization, customization and ease of use. Live example - react-roulette-pro.ivanadmaers.com

React Roulette Pro 3.0 realised! See these release notes and this migration guide

Features

  • 🚀 Optimization
  • 🎨 Easily customizable
  • 🔌 Design plugins architecture [🔥NEW🔥]
  • 🔫 Two types: horizontal and vertical [🔥NEW🔥]
  • 💪 Powerful
  • ✅ Ease of use
  • 📝 MIT license
  • 🔥 Just cool
  • 📦 Lightweight
  • 🔧 Well-tested
  • 🎉 NextJS, GatsbyJS and RemixJS support

Installation

# Via npm:
npm i react-roulette-pro

# Via yarn:
yarn add react-roulette-pro

Usage

import { useState } from 'react';

import RoulettePro from 'react-roulette-pro';
import 'react-roulette-pro/dist/index.css';

const prizes = [
  {
    image: 'https://i.ibb.co/6Z6Xm9d/good-1.png',
  },
  {
    image: 'https://i.ibb.co/T1M05LR/good-2.png',
  },
  {
    image: 'https://i.ibb.co/Qbm8cNL/good-3.png',
  },
  {
    image: 'https://i.ibb.co/5Tpfs6W/good-4.png',
  },
  {
    image: 'https://i.ibb.co/64k8D1c/good-5.png',
  },
];

const winPrizeIndex = 0;

const reproductionArray = (array = [], length = 0) => [
  ...Array(length)
    .fill('_')
    .map(() => array[Math.floor(Math.random() * array.length)]),
];

const reproducedPrizeList = [
  ...prizes,
  ...reproductionArray(prizes, prizes.length * 3),
  ...prizes,
  ...reproductionArray(prizes, prizes.length),
];

const generateId = () =>
  `${Date.now().toString(36)}-${Math.random().toString(36).substring(2)}`;

const prizeList = reproducedPrizeList.map((prize) => ({
  ...prize,
  id: typeof crypto.randomUUID === 'function' ? crypto.randomUUID() : generateId(),
}));

const App = () => {
  const [start, setStart] = useState(false);

  const prizeIndex = prizes.length * 4 + winPrizeIndex;

  const handleStart = () => {
    setStart((prevState) => !prevState);
  };

  const handlePrizeDefined = () => {
    console.log('🥳 Prize defined! 🥳');
  };

  return (
    <>
      <RoulettePro
        prizes={prizeList}
        prizeIndex={prizeIndex}
        start={start}
        onPrizeDefined={handlePrizeDefined}
      />
      <button onClick={handleStart}>Start</button>
    </>
  );
};

export default App;

Props

Where * means required

| Prop | Type | Default value | Description | |--|--|--|--| | start* | boolean | - | Sets when the roulette must start spinning | | prizes* | Array | - | Array of objects. Objects must have required fields: id and image. A field text is optional. Each prize must have a unique id. Make sure you pass enough prize items for correct spinning. See an example in the Usage section above. | | prizeIndex* | number | - | The index of a prize that will win | | type | string | horizontal | The roulette type. Available values: horizontal, vertical | | onPrizeDefined | Function | () => {} | Function to be called when the roulette stops spinning | | spinningTime | number | 10 | The roulette spinning time in seconds | | prizeItemRenderFunction | (item) => JSX | - | Function that renders the roulette prize items | | topChildren | node | - | Children before the roulette prize list | | bottomChildren | node | - | Children after the roulette prize list | | designPlugin | (props) => ({}) | - | Design plugin for the roulette. If not setted the roulette will use its default built-in design. See this guide to know how to create your own design plugin | | defaultDesignOptions | object | {} | Default design options. Available options: hideCenterDelimiter - optional, boolean type and prizesWithText - optional, boolean type | | classes | object | {} | Classes that will be applied to the roulette. Available keys: wrapper - the roulette wrapper class, prizeListWrapper - the roulette prize list class and prizeItem - class for prize items | | soundWhileSpinning | string | - | Path to a sound file that will be played while the roulette spinning | | options | object | {} | The roulette options. Available options: stopInCenter - optional, boolean type and withoutAnimation - optional, boolean type | | transitionFunction | string | cubic-bezier(0.0125, 0.1, 0.1, 1) | The roulette animation transition function |


Design plugins

FAQ

🧐 Where can I find an example of how to use the package?
📣 You can find a live example on this site - react-roulette-pro.ivanadmaers.com and in the example folder.

🧐 How can I customize the roulette?
📣 First, you can pass a prizeItemRenderFunction to render prize items by yourself. Second, you can use a specific design plugin. Third, you can pass your specific classes via classes prop. Avoid to rewrite the roulette and its plugins default styles.

🧐 Is it possible to use this package with SSR?
📣 Of course! This package does not use a global object window. You can use this package without any problems. And I'd like to recommend you to use dynamic in NextJS to decrease your bundle size and render it only on client side.

import dynamic from 'next/dynamic';

const RoulettePro = dynamic(() => import('react-roulette-pro'), {
  ssr: false,
});

🧐 What version of React does this package support?
📣 Your versions should be:

  • react >=17.0.0
  • react-dom >=17.0.0
  • NodeJS >=10

🧐 Are pull requests welcome?
📣 Any ideas to improve this package are very welcome!

How to bootstrap the project locally

  1. Clone the project

  2. 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

  1. Enjoy the magic!

enjoying the magic

License

MIT

Copyright (c) 2021-present, Ivan Admaers