A customizable and interactive prize wheel/spinner component for React applications. Designed for giveaways, games, promotions, and interactive user experiences.
- Interactive spinning wheel with smooth animations
- Fully customizable colors, labels, and icons
- Probability-based prize selection
- Flexible prize count - supports any number of prizes
- Responsive design for mobile and desktop
- Support for custom prize data
- TypeScript support with full type definitions
- Callback functionality when prize is selected
- Unique prefixed class names to avoid conflicts
- CSS automatically included (no separate import needed)
npm install react-gift-spinner
# or
yarn add react-gift-spinnerimport React, { useState } from 'react';
import { GiftSpinner } from 'react-gift-spinner';
// CSS is automatically imported
function App() {
const [prize, setPrize] = useState(null);
const handlePrizeSelected = (selectedPrize) => {
setPrize(selectedPrize);
console.log('Selected prize:', selectedPrize);
};
return (
<div className="app">
<h1>Spin to Win!</h1>
<GiftSpinner onPrizeSelected={handlePrizeSelected} />
{prize && (
<div className="winning-message">
<p>Congratulations! You won: {prize.icon} {prize.label}</p>
</div>
)}
</div>
);
}
export default App;You can provide your own custom prizes with different probabilities:
import React from 'react';
import { GiftSpinner } from 'react-gift-spinner';
// The 'probability' value is the exact percentage chance for each prize.
// For example, probability: 10 means 10% chance, probability: 0.5 means 0.5% chance.
const customPrizes = [
{
label: "1000 Points",
color: "#ff4081",
icon: "π",
probability: 10 // 10% chance
},
{
label: "LEXUS LS-2019",
color: "#651fff",
icon: "π",
probability: 0.5 // 0.5% chance (rare)
},
{
label: "500 Points",
color: "#3d5afe",
icon: "π",
probability: 15 // 15% chance
},
{
label: "Golden Race",
color: "#2979ff",
icon: "π",
probability: 10 // 10% chance
},
{
label: "250 Points",
color: "#00b0ff",
icon: "ποΈ",
probability: 30 // 30% chance (common)
},
{
label: "Best Player",
color: "#311b92",
icon: "π",
probability: 4 // 4% chance
},
{
label: "Great Prize",
color: "#4527a0",
icon: "π",
probability: 15 // 15% chance
},
{
label: "NULL Prize",
color: "#512da8",
icon: "β",
probability: 0 // 0% chance - will never be selected
}
];
function App() {
return <GiftSpinner customPrizes={customPrizes} />;
}The spinner automatically adapts to any number of prizes. You can provide as few as 2 or as many as needed:
// Example with 6 prizes
const sixPrizes = [
{ label: "Prize 1", color: "#ff4081", icon: "π", probability: 20 },
{ label: "Prize 2", color: "#651fff", icon: "π", probability: 15 },
{ label: "Prize 3", color: "#3d5afe", icon: "π", probability: 25 },
{ label: "Prize 4", color: "#2979ff", icon: "π", probability: 10 },
{ label: "Prize 5", color: "#00b0ff", icon: "ποΈ", probability: 20 },
{ label: "Prize 6", color: "#311b92", icon: "π", probability: 10 }
];
// Example with many prizes
const manyPrizes = [
// ... 10 or more prizes ...
];
// The spinner will automatically adjust segment sizes, text positioning,
// and font sizes to accommodate the number of prizes| Prop | Type | Default | Description |
|---|---|---|---|
customPrizes |
PrizeItem[] |
defaultPrizes |
Array of prize objects |
onPrizeSelected |
(prize: PrizeItem) => void |
undefined |
Callback function when a prize is selected |
className |
string |
'' |
Additional CSS class for styling |
interface PrizeItem {
label: string; // Text to display on the wheel
color: string; // Background color (hex, rgb, etc.)
icon: string | React.ReactNode; // Emoji, URL to image, or React component
probability: number; // Percentage chance for this prize (e.g. 10 means 10%, 0.5 means 0.5%)
}All CSS classes in this component are prefixed with rgp- to avoid conflicts with your existing styles. Key classes include:
rgp-gift-spinner-container- Main containerrgp-wheel-container- Wheel wrapperrgp-wheel- The spinning wheel itselfrgp-segment- Individual wheel segmentsrgp-center-button- Center spin buttonrgp-indicator- Arrow indicator
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Mobile browsers (iOS Safari, Chrome for Android)
To run the project locally:
- Clone this repo
- Install dependencies:
npm install - Start the development server:
npm start
npm run buildMIT Β© Alireza Azizi
Try it out instantly on CodeSandbox: Live Demo
