New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@mertercelik/react-prize-wheel

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mertercelik/react-prize-wheel

A customizable and animated prize wheel component for React

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
48
9.09%
Maintainers
1
Weekly downloads
 
Created
Source

React Prize Wheel

A highly customizable, animated prize wheel component for React applications with TypeScript support.

Demo

Live Demo

Installation

npm install @mertercelik/react-prize-wheel
yarn add @mertercelik/react-prize-wheel
pnpm add @mertercelik/react-prize-wheel

Quick Start

import { useRef } from 'react';
import { PrizeWheel } from '@mertercelik/react-prize-wheel';
import type { Sector, PrizeWheelRef } from '@mertercelik/react-prize-wheel';
import '@mertercelik/react-prize-wheel/style.css';

function App() {
  const wheelRef = useRef<PrizeWheelRef>(null);

  const sectors: Sector[] = [
    { id: 1, label: 'Prize 1', probability: 10 },
    { id: 2, label: 'Prize 2', probability: 20 },
    { id: 3, label: 'Prize 3', probability: 15 },
    { id: 4, label: 'Prize 4', probability: 5 },
  ];

  const handleSpinEnd = (sector: Sector) => {
    console.log('Winner:', sector.label);
  };

  return (
    <div>
      <PrizeWheel
        ref={wheelRef}
        sectors={sectors}
        onSpinEnd={handleSpinEnd}
      />
      <button onClick={() => wheelRef.current?.spin()}>
        Spin the Wheel
      </button>
    </div>
  );
}

API Reference

PrizeWheel Component

Props

PropTypeDefaultDescription
sectorsSector[]requiredArray of prize sectors
onSpinStart() => voidundefinedCallback fired when spin starts
onSpinEnd(sector: Sector) => voidundefinedCallback fired when spin ends with winning sector
durationnumber4Spin duration in seconds
minSpinsnumber5Minimum number of full rotations
maxSpinsnumber8Maximum number of full rotations

Customization Props

Colors
PropTypeDefaultDescription
frameColorstring'#ddd'Outer frame color
middleColorstring'#ddd'Center circle color
middleDotColorstring'#bbb'Center dot color
winIndicatorColorstring'#ddd'Win indicator arrow color
winIndicatorDotColorstring'#bbb'Win indicator dot color
sticksColorstring'#ddd'Divider sticks color
wheelColors[string, string]['#1592e8', '#14c187']Alternating sector colors
borderColorstring'#ddd'Sector border color
textColorstring'#fff'Sector text color
Styling
PropTypeDefaultDescription
borderWidthnumber2Sector border width in pixels
textFontSizenumber18Sector text font size in pixels
Shadows
PropTypeDefaultDescription
wheelShadowColorstring'#000'Wheel shadow color
wheelShadowOpacitynumber0.15Wheel shadow opacity (0-1)
middleShadowColorstring'#000'Middle circle shadow color
middleShadowOpacitynumber0.2Middle circle shadow opacity (0-1)
indicatorShadowColorstring'#000'Indicator shadow color
indicatorShadowOpacitynumber0.22Indicator shadow opacity (0-1)

Sector Interface

interface Sector {
  id: number | string;
  label: string;
  text?: string;
  probability?: number;
}
PropertyTypeRequiredDescription
idnumber | stringYesUnique identifier for the sector
labelstringYesLabel returned in callbacks
textstringNoText displayed on the sector (defaults to label)
probabilitynumberNoRelative probability weight (default: 10)

Ref API

The component exposes a ref with the following methods and properties:

interface PrizeWheelRef {
  spin: () => void;
  isSpinning: boolean;
}
MemberTypeDescription
spin() => voidProgrammatically trigger a spin
isSpinningbooleanCurrent spinning state

Advanced Usage

Custom Button with State

import { useRef, useState } from 'react';
import { PrizeWheel } from '@mertercelik/react-prize-wheel';
import type { Sector, PrizeWheelRef } from '@mertercelik/react-prize-wheel';
import '@mertercelik/react-prize-wheel/style.css';

function App() {
  const wheelRef = useRef<PrizeWheelRef>(null);
  const [isSpinning, setIsSpinning] = useState(false);
  const [winner, setWinner] = useState<Sector | null>(null);

  const handleSpinStart = () => {
    setIsSpinning(true);
    setWinner(null);
  };

  const handleSpinEnd = (sector: Sector) => {
    setIsSpinning(false);
    setWinner(sector);
  };

  return (
    <div>
      <PrizeWheel
        ref={wheelRef}
        sectors={sectors}
        onSpinStart={handleSpinStart}
        onSpinEnd={handleSpinEnd}
      />
      <button 
        onClick={() => wheelRef.current?.spin()}
        disabled={isSpinning}
      >
        {isSpinning ? 'Spinning...' : 'Spin the Wheel'}
      </button>
      {winner && <p>Winner: {winner.label}</p>}
    </div>
  );
}

Probability System

The probability system uses relative weights. Higher values increase the chance of winning.

const sectors = [
  { id: 1, label: 'Common', probability: 50 },   // 50% chance
  { id: 2, label: 'Uncommon', probability: 30 }, // 30% chance
  { id: 3, label: 'Rare', probability: 15 },     // 15% chance
  { id: 4, label: 'Legendary', probability: 5 }, // 5% chance
];

Full Customization

<PrizeWheel
  ref={wheelRef}
  sectors={sectors}
  onSpinStart={handleSpinStart}
  onSpinEnd={handleSpinEnd}
  duration={6}
  minSpins={4}
  maxSpins={4}
  frameColor="#ffd700"
  middleColor="#ffd700"
  middleDotColor="#8b7500"
  winIndicatorColor="#ffd700"
  winIndicatorDotColor="#8b7500"
  sticksColor="#ffd700"
  wheelColors={['#0a1d3f', '#0a2249']}
  borderColor="#ffd700"
  borderWidth={3}
  textColor="#ffffff"
  textFontSize={20}
  wheelShadowColor="#000"
  wheelShadowOpacity={0.2}
  middleShadowColor="#000"
  middleShadowOpacity={0.25}
  indicatorShadowColor="#000"
  indicatorShadowOpacity={0.3}
/>

TypeScript

The package includes full TypeScript definitions. Import types as needed:

import type { 
  Sector, 
  PrizeWheelProps, 
  PrizeWheelRef 
} from '@mertercelik/react-prize-wheel';

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Dependencies

  • React 18+
  • GSAP 3+

Credits

The wheel SVG design is based on the work by Soma Szoboszlai.

License

MIT

Acknowledgments

  • Wheel design inspiration: Soma Szoboszlai
  • Animation library: GSAP

Contributing

Contributions are welcome. Please open an issue or submit a pull request.

Support

For issues and feature requests, please use the GitHub issue tracker.

Keywords

react

FAQs

Package last updated on 04 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts