UNPKG

react-prize-wheel

Version:
61 lines 2.17 kB
import type { AnimationConfig, SpinResult, WheelSegment } from '../types'; /** * Configuration options for the useSpinWheel hook * * @interface UseSpinWheelOptions */ interface UseSpinWheelOptions { /** Array of wheel segments to display */ segments: WheelSegment[]; /** Animation configuration (duration, easing, spins) */ animation?: Partial<AnimationConfig>; /** Callback triggered when spin starts */ onSpinStart?: () => void; /** Callback triggered when spin completes with result */ onSpinComplete?: (result: SpinResult) => void; /** Whether the wheel is disabled */ disabled?: boolean; /** Predefined result for testing (segment index or ID) */ predefinedResult?: number | string; /** Pointer position for calculating results */ pointerPosition?: 'top' | 'right' | 'bottom' | 'left'; } /** * React hook for managing spin wheel state and animations * * @description Provides all the logic needed for a spinning wheel including: * - State management (rotation, spinning status, results) * - Animation with customizable easing and duration * - Weighted random selection with validation * - Segment validation and error handling * * @since 2025-07-25 * @version 1.0.0 * * @example * ```tsx * const { rotation, isSpinning, spin, lastResult } = useSpinWheel({ * segments: [ * { id: '1', text: 'Prize 1', color: '#ff0000' }, * { id: '2', text: 'Prize 2', color: '#00ff00' } * ], * onSpinComplete: (result) => console.log('Winner:', result.segment.text) * }); * ``` * * @param options - Configuration options for the wheel behavior * @returns Object containing wheel state, validation results, and control functions */ export declare function useSpinWheel({ segments, animation, onSpinStart, onSpinComplete, disabled, predefinedResult, pointerPosition, }: UseSpinWheelOptions): { rotation: number; isSpinning: boolean; lastResult: SpinResult | null; progress: number; isValid: boolean; validationErrors: string[]; spin: () => void; reset: () => void; animationConfig: AnimationConfig; }; export {}; //# sourceMappingURL=useSpinWheel.d.ts.map