{"_rev":"2-0b32713d331b20aee72e717e081afb13","time":{"created":"2024-04-09T09:15:08.916Z","1.4.1":"2024-04-09T08:54:55.624Z","modified":"2024-04-09T09:15:09.443Z","1.4.2":"2024-04-09T09:15:09.185Z"},"_id":"@boriska420/react-custom-roulette","name":"@boriska420/react-custom-roulette","dist-tags":{"latest":"1.4.2"},"versions":{"1.4.2":{"name":"@boriska420/react-custom-roulette","version":"1.4.2","description":"Customizable React roulette wheel with spinning animation","main":"./dist/bundle.js","repository":{"type":"git","url":"git+https://github.com/effectussoftware/react-custom-roulette.git"},"keywords":["react","custom","roulette","spinning","wheel","fortune","prize"],"license":"MIT","types":"./dist/index.d.ts","private":false,"peerDependencies":{"react":"^18.2.0","react-dom":"^18.2.0"},"devDependencies":{"@testing-library/jest-dom":"^5.9.0","@testing-library/react":"^10.0.6","@testing-library/user-event":"^11.0.0","@types/jest":"^25.2.3","@types/node":"^14.0.9","@types/react":"^18.0.28","@types/react-dom":"^18.0.11","@types/webfontloader":"^1.6.34","@typescript-eslint/eslint-plugin":"^4.16.1","@typescript-eslint/parser":"^4.16.1","babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-loader":"8.1.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-plugin-transform-react-jsx":"^6.24.1","babel-preset-env":"^1.7.0","css-loader":"^3.5.3","eslint":"^7.21.0","eslint-config-airbnb-typescript-prettier":"^2.1.1","eslint-plugin-react":"^7.22.0","husky":"^4.2.5","jest-canvas-mock":"^2.2.0","prettier":"^2.0.5","react-scripts":"^4.0.3","styled-components":"^5.1.1","ts-loader":"8.0.7","typescript":"^4.6.2","url-loader":"^4.1.0","webfontloader":"^1.6.28","webpack":"4.44.2","webpack-cli":"^3.3.11","webpack-dev-server":"3.11.1"},"scripts":{"start-server":"react-scripts start","start":"webpack --watch","build":"webpack && tsc && cp -R ./src/assets ./dist","test":"react-scripts test","coverage":"CI=true npm test -- --env=jsdom --coverage","eject":"react-scripts eject","format":"prettier --write src/**/*.{js,ts,tsx}","lint":"eslint src/**/*.{js,ts,tsx}","link-react":"cd example/node_modules/react && yarn link && cd ../react-dom && yarn link && cd ../../.. && yarn link react react-dom"},"husky":{"hooks":{"pre-commit":"yarn format && yarn lint"}},"jest":{"coveragePathIgnorePatterns":["src/serviceWorker.ts"]},"eslintConfig":{"extends":"react-app"},"browserslist":{"production":[">0.2%","not dead","not op_mini all"],"development":["last 1 chrome version","last 1 firefox version","last 1 safari version"]},"gitHead":"fd077bc54aaaeeb170b8078b545f59759151f0ba","bugs":{"url":"https://github.com/effectussoftware/react-custom-roulette/issues"},"homepage":"https://github.com/effectussoftware/react-custom-roulette#readme","_id":"@boriska420/react-custom-roulette@1.4.2","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-WsYOXWFtnLTt//6UCmt42w3JoKqFt2PqgLj3qXrpJ0tQvOKmQSki9gAE2FEbVc5qxEFUS9cGTsdo+t0KqobJlw==","shasum":"4ce204aafa751f7a7c80ae10a82afb3bdd291c6a","tarball":"https://registry.npmjs.org/@boriska420/react-custom-roulette/-/react-custom-roulette-1.4.2.tgz","fileCount":40,"unpackedSize":131963,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDDqfH4RbgGcXmAJ2C0noUQtVkxiiS3IxY2F7hbMx5/swIgWqG6JS32tvB2x6bqoHjTmR9L8FMYFuyCJ0TMz4466Kk="}]},"_npmUser":{"name":"boriska420","email":"laurentiu.malai@hotmail.com"},"directories":{},"maintainers":[{"name":"boriska420","email":"laurentiu.malai@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-custom-roulette_1.4.2_1712654109017_0.0653250375285479"},"_hasShrinkwrap":false}},"maintainers":[{"name":"boriska420","email":"laurentiu.malai@hotmail.com"}],"description":"Customizable React roulette wheel with spinning animation","homepage":"https://github.com/effectussoftware/react-custom-roulette#readme","keywords":["react","custom","roulette","spinning","wheel","fortune","prize"],"repository":{"type":"git","url":"git+https://github.com/effectussoftware/react-custom-roulette.git"},"bugs":{"url":"https://github.com/effectussoftware/react-custom-roulette/issues"},"license":"MIT","readme":"<h1 align=\"center\">React Custom Roulette</h1>\r\n\r\n<div align=\"center\">\r\n\r\n  [![npm version](https://img.shields.io/npm/v/react-custom-roulette)](https://www.npmjs.com/package/react-custom-roulette)\r\n  [![Types](https://img.shields.io/npm/types/react-custom-roulette)](https://www.typescriptlang.org/index.html)\r\n  [![npm downloads](https://img.shields.io/npm/dm/react-custom-roulette)](https://www.npmjs.com/package/react-custom-roulette)\r\n\r\n</div>\r\n\r\n<p align=\"center\">Customizable React roulette wheel with spinning animation</p>\r\n\r\n<div align=\"center\">\r\n\r\n  ![React Custom Roulette](https://github.com/effectussoftware/react-custom-roulette/raw/master/demo/roulette-demo.gif)\r\n\r\n</div>\r\n\r\n## Features\r\n\r\n- Customizable design\r\n- Prize selection with props\r\n- Spinning animation (customizable spin duration)\r\n- **[NEW!]** Images as items (see [Types](#types))\r\n- **[NEW!]** Customizable pointer image\r\n- Multiple consecutive spins (see [Multi Spin](#multi-spin))\r\n- Compatible with TypeScript\r\n\r\n## Install\r\n\r\n    $ npm install react-custom-roulette\r\n\r\nor\r\n\r\n    $ yarn add react-custom-roulette\r\n\r\n## Quickstart\r\n\r\n#### Wheel Component\r\n\r\n```jsx\r\nimport React from 'react'\r\nimport { Wheel } from 'react-custom-roulette'\r\n\r\nconst data = [\r\n  { option: '0', style: { backgroundColor: 'green', textColor: 'black' } },\r\n  { option: '1', style: { backgroundColor: 'white' } },\r\n  { option: '2' },\r\n]\r\n\r\nexport default () => (\r\n  <>\r\n    <Wheel\r\n      mustStartSpinning={mustSpin}\r\n      prizeNumber={3}\r\n      data={data}\r\n      backgroundColors={['#3e3e3e', '#df3428']}\r\n      textColors={['#ffffff']}\r\n    />\r\n  </>\r\n)\r\n```\r\n\r\n#### Props\r\n\r\n| **Prop**                        | **Type**           | **Default**               | **Description**                                                    |\r\n|---------------------------------|--------------------|---------------------------|--------------------------------------------------------------------|\r\n| mustStartSpinning _(required)_  | `boolean`          | -                         | Sets when the roulette must start the spinning animation                                              |\r\n| prizeNumber _(required)_        | `number`           | -                         | Sets the winning option. It's value must be between 0 and data.lenght-1                                               |\r\n| data _(required)_               | `Array<WheelData>` | -                         | Array of options. Can contain styling information for a specific option (see [WheelData](#wheeldata))                          |\r\n| onStopSpinning                  | `function`         | () => null                | Callback function that is called when the roulette ends the spinning animation                                              |\r\n| backgroundColors                | `Array<string>`    | ['darkgrey', 'lightgrey'] | Array of colors that will fill the background of the roulette options, starting from option 0                                 |\r\n| textColors                      | `Array<string>`    | ['black']                 | Array of colors that will fill the text of the roulette options, starting from option 0                                 |\r\n| outerBorderColor                | `string`           | 'black'                   | Color of the roulette's outer border line                                                   |\r\n| outerBorderWidth                | `number`           | 5                         | Width of the roulette's outer border line (0 represents no outer border line)                                                  |\r\n| innerRadius                     | `number [0..100]`  | 0                         | Distance of the inner radius from the center of the roulette                                               |\r\n| innerBorderColor                | `string`           | 'black'                   | Color of the roulette's inner border line                                                   |\r\n| innerBorderWidth                | `number`           | 0                         | Width of the roulette's inner border line (0 represents no inner border line)                                                  |\r\n| radiusLineColor                 | `string`           | 'black'                   | Color of the radial lines that separate each option                                                 |\r\n| radiusLineWidth                 | `number`           | 5                         | Width of the radial lines that separate each option (0 represents no radial lines)                                          |\r\n| fontFamily                      | `string`           | 'Helvetica, Arial'        | Global font family of the option string. Non-Web safe fonts are fetched from https://fonts.google.com/. All available fonts can be found there.            |\r\n| fontSize                        | `number`           | 20                        | Global font size of the option string                            |\r\n| fontWeight                      | `number | string`  | 'bold'                    | Global font weight of the option string                          |\r\n| fontStyle                       | `string`           | 'normal'                  | Global font style of the option string                           |\r\n| perpendicularText               | `boolean`          | false                     | When 'true', sets the option texts perpendicular to the roulette's radial lines                                           |\r\n| textDistance                    | `number [0..100]`  | 60                        | Distance of the option texts from the center of the roulette     |\r\n| spinDuration                    | `number [0.01 ..]` | 1.0                       | Coefficient to adjust the default spin duration                  |\r\n| startingOptionIndex             | `number`           | -                         | Set which option (through its index in the `data` array) will be initially selected by the roulette (before spinning). If not specified the roulette will render without choosing a starting option                    |\r\n| pointerProps                    | `PointerProps`     | { src: roulettePointer }  | Image source and CSS styling to apply to the pointer image.                                                 |\r\n| disableInitialAnimation         | `boolean`          | false                     | When 'true', disables the initial backwards wheel animation      |\r\n\r\n## Types\r\n\r\n#### WheelData\r\n\r\n```jsx\r\ninterface WheelData {\r\n  option?: string;\r\n  image?: ImageProps;\r\n  style?: StyleType; // Optional\r\n  optionSize?: number; // Optional\r\n}\r\n```\r\n\r\n| **Prop**   | **Type**     | **Default** | **Description**                                                                                       |\r\n|------------|--------------|-------------|-------------------------------------------------------------------------------------------------------|\r\n| option     | `string`     | ''          | String to be rendered inside an option.                                                               |\r\n| image      | `ImageProps` | -           | Image to be rendered inside an option. It is configured through [ImageProps](#imageprops)             |\r\n| style      | `StyleType`  | -           | Styles for option. It is configured through [StyleType](#styletype)                                   |\r\n| optionSize | `number`     | 1           | Integer that sets the size of the option measured in roulette pieces. For example: if `data` provides 2 options A and B, and you set A's `optionSize` to `2`, B's `optionSize` to `1`, the roulette will render `3` pieces: 2 corresponding to A and 1 corresponding to B. Therefore, A will appear to be twice as big as B. |\r\n\r\n#### StyleType\r\n\r\n```jsx\r\ninterface StyleType {\r\n  backgroundColor?: string; // Optional\r\n  textColor?: string; // Optional\r\n  fontFamily?: string; // Optional\r\n  fontSize?: number; // Optional\r\n  fontWeight?: number | string; // Optional\r\n  fontStyle?: string; // Optional\r\n}\r\n```\r\n\r\n| **Prop**        | **Type**          | **Default**               | **Description**                                                    |\r\n|-----------------|-------------------|---------------------------|--------------------------------------------------------------------|\r\n| backgroundColor | `string`          | 'darkgrey' or 'lightgrey' | Background color for option                                        |\r\n| textColor       | `string`          | 'black'                   | Text color                                                         |\r\n| fontFamily      | `string`          | 'Helvetica, Arial'        | String containing text font and its fallbacks separated by commas  |\r\n| fontSize        | `number`          | 20                        | Font size number                                                   |\r\n| fontWeight      | `number | string` | 'bold'                    | Font weight string or number                                       |\r\n| fontStyle       | `string`          | 'normal'                  | Font style string                                                  |\r\n\r\n#### ImageProps\r\n\r\n```jsx\r\ninterface ImageProps {\r\n  uri: string;\r\n  offsetX?: number; // Optional\r\n  offsetY?: number; // Optional\r\n  sizeMultiplier?: number; // Optional\r\n  landscape?: boolean; // Optional\r\n}\r\n```\r\n\r\n| **Prop**       | **Type**  | **Default** | **Description**                                                                       |\r\n|----------------|-----------|-------------|---------------------------------------------------------------------------------------|\r\n| uri            | `string`  | -           | Image source. It can be url or path.                                                  |\r\n| offsetX        | `number`  | 0           | Image offset in its X axis                                                            |\r\n| offsetY        | `number`  | 0           | Image offset in its Y axis                                                            |\r\n| sizeMultiplier | `number`  | 1           | A value of 1 means image height is calculated as `200px * sizeMultiplier` and width will be calculated to keep aspect ratio. |\r\n| landscape      | `boolean` | false       | If true, image will be rotated 90 degrees so as to render in a landscape orientation. |\r\n\r\n#### PointerProps\r\n\r\n```jsx\r\ninterface PointerProps {\r\n  src?: string; // Optional\r\n  style?: React.CSSProperties; // Optional\r\n}\r\n```\r\n\r\n| **Prop** | **Type**              | **Default**               | **Description**             |\r\n|----------|-----------------------|---------------------------|-----------------------------|\r\n| src      | `string`              | -                         | Image src.                  |\r\n| style    | `React.CSSProperties` | -                         | Styling for pointer image.  |\r\n\r\n## Multi Spin\r\n\r\n#### Example (using useState)\r\n\r\n```jsx\r\nimport React, { useState } from 'react'\r\nimport { Wheel } from 'react-custom-roulette'\r\n\r\nconst data = [\r\n  { option: '0' },\r\n  { option: '1' },\r\n  { option: '2' },\r\n]\r\n\r\nexport default () => {\r\n  const [mustSpin, setMustSpin] = useState(false);\r\n  const [prizeNumber, setPrizeNumber] = useState(0);\r\n\r\n  const handleSpinClick = () => {\r\n    if (!mustSpin) {\r\n      const newPrizeNumber = Math.floor(Math.random() * data.length);\r\n      setPrizeNumber(newPrizeNumber);\r\n      setMustSpin(true);\r\n    }\r\n  }\r\n\r\n  return (\r\n    <>\r\n      <Wheel\r\n        mustStartSpinning={mustSpin}\r\n        prizeNumber={prizeNumber}\r\n        data={data}\r\n\r\n        onStopSpinning={() => {\r\n          setMustSpin(false);\r\n        }}\r\n      />\r\n      <button onClick={handleSpinClick}>SPIN</button>\r\n    </>\r\n  )\r\n}\r\n```\r\n\r\n## Contributors\r\n\r\nThis project exists thanks to all the people who contribute!\r\n\r\n<ul>\r\n    <li><a href=\"https://github.com/luchozamora1\">Luis Felipe Zamora</a></li>\r\n    <li><a href=\"https://github.com/nazabalm20\">Martin Nazabal</a></li>\r\n    <li><a href=\"https://github.com/jpmazza\">JP Mazza</a></li>\r\n    <li><a href=\"https://github.com/TakeshiOnishi\">TakeshiOnishi</a></li>\r\n    <li><a href=\"https://github.com/Gaston-Gonzalez\">Gastón González</a></li>\r\n    <li><a href=\"https://github.com/jpmartinezeff\">Juan Pablo Martinez</a></li>\r\n    <li><a href=\"https://github.com/Acarvajal904\">Andres Carvajal</a></li>\r\n</ul>\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT license, Copyright (c) 2023 <a href=\"https://effectussoftware.com\">Effectus Software</a>. [[License](LICENSE)]\r\n","readmeFilename":"README.md"}