react-coupon-wheel
v1.0.1
Published
A customizable React component for creating interactive coupon wheels
Downloads
157
Maintainers
Readme
CouponWheel React Component
A customizable, interactive coupon wheel component for React applications. Perfect for gamifying user engagement and promotional activities.
Disclaimer
The react-coupon-wheel is intended for promotional and entertainment purposes only. It is not designed or intended for use in gambling applications or on websites that are not compliant with Islamic (Halal) principles.
Features
- Customizable wheel segments with labels and colors
- Smooth spinning animation
- Configurable indicator position
- Option for predetermined winning segment
- Responsive design
- No external CSS dependencies - styles are bundled with the component
Installation
Install the package using npm:
npm install react-coupon-wheel
Or using yarn:
yarn add react-coupon-wheel
Usage
Here's a basic example of how to use the CouponWheel component:
import React from 'react';
import { CouponWheel } from 'react-coupon-wheel';
const App = () => {
const wheelItems = [
{ label: '10% OFF', color: '#FF6B6B' },
{ label: '20% OFF', color: '#4ECDC4' },
{ label: '30% OFF', color: '#45B7D1' },
{ label: '40% OFF', color: '#F9DB6D' },
{ label: '50% OFF', color: '#FF8C42' },
{ label: 'FREE SHIP', color: '#98DDCA' },
];
const handleSpinResult = (result) => {
console.log('Spin result:', result);
};
return (
<div>
<h1>Try Your Luck!</h1>
<CouponWheel
wheelItems={wheelItems}
onFinish={handleSpinResult}
/>
</div>
);
};
export default App;
Props
The CouponWheel component accepts the following props:
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| wheelItems
| Array of { label: string, color: string }
| Required | Defines the segments of the wheel |
| predeterminedWinner
| string | undefined | Label of the predetermined winning segment |
| spinDuration
| number | 4000 | Duration of the spin animation in milliseconds |
| spinDelay
| number | 200 | Delay before the spin starts in milliseconds |
| indicatorPosition
| "12" | "3" | "6" | "9" | "12" | Position of the indicator on the wheel |
| onFinish
| function | undefined | Callback function called when spin finishes, receives the winning label as an argument |
| isOpen
| boolean | false | boolean to reset the wheel in case it is rendered inside a modal for example |
Styling
The component comes with default styles, but you can override them by targeting the following CSS classes:
.coupon-wheel-container
: The main container of the wheel.coupon-wheel-svg
: The SVG element of the wheel.wheel-segment
: Each segment of the wheel.wheel-border-light
: The lights around the wheel border.wheel-indicator
: The indicator pointing to the winning segment
Development
To set up the project for development:
- Clone the repository
- Install dependencies with
npm install
- Run the build process with
npm run build
- To run tests (if available), use
npm test
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any problems or have any questions, please open an issue in the GitHub repository.
Enjoy using CouponWheel in your React projects!