Rreact-raffle-picker

API

Every prop, one page.

This is the flat reference — everything the compound API exposes, no clicking through tabs. For a live, interactive version of every prop, use the Storybook or the Playground.

import { RafflePick } from 'react-raffle-picker'

;<RafflePick items={['Alice', 'Bob', 'Carol']} inertia autoStart={false}>
  <RafflePick.Value animation="roll" />
  <RafflePick.Button startLabel="Draw" stopLabel="Stop" />
  <RafflePick.Countdown seconds={5} />
</RafflePick>

<RafflePick>

root

Owns the engine — cycling, phase machine, no-repeat history. Provides context; renders no DOM opinion beyond the wrapper element.

PropTypeDefaultNotes
min, maxnumber1, 100Numeric range. Ignored if items is set.
itemsstring[]—Switches to item mode — cycles through names instead of numbers.
intervalnumber100Tick speed in ms, clamped to a minimum of 50.
randombooleantrueRandom pick per tick vs sequential increment.
inertiabooleanfalseSoft-start / soft-stop ramp instead of an instant flip.
autoStartbooleantrueBegin cycling on mount.
noRepeatbooleantrueExcludes previously frozen values from later rounds — no duplicate winners.
initialValuenumber | string—Value shown before the first run.
finalValuenumber | string—Forces settle to land on this value while the cycle still looks random.
onSelect(value) => void—Fires once per round, when the phase settles to frozen.
onExhausted() => void—Fires when start() runs but noRepeat has already drawn every candidate.
asElementType'div'Wrapper element/component.
className, stylestring, CSSProperties—Wrapper class / inline style.
childrenReactNode—Compound sub-components — Value, Button, Countdown, Slots.

<RafflePick.Value>

consumer

Renders the cycling value. Writes textContent imperatively per tick — no React re-render while running. Multiple instances inside one root are supported.

PropTypeDefaultNotes
animation'roll' | 'fade' | 'blur' | 'reel''roll'Opt-in CSS animation, bound to the current tick duration.
asElementType'span'Rendered element.
className, stylestring, CSSProperties—Class / inline style.

<RafflePick.Button>

consumer

Toggles start / freeze based on the current phase.

PropTypeDefaultNotes
startLabelReactNode—Shown in idle / frozen — click starts a round.
stopLabelReactNode—Shown in running / starting — click stops.
waitLabelReactNode—Shown in settling. Button is disabled.
childrenReactNode—Fallback label when no state-specific label is set.
disabledboolean—External disable, on top of the automatic disable during settling / when noRepeat is exhausted.
className, stylestring, CSSProperties—Class / inline style.

<RafflePick.Countdown>

consumer

Schedules auto-freeze after seconds. Renders an SVG ring + numeric label by default.

PropTypeDefaultNotes
secondsnumber—Required. Auto-freeze delay. Renders only while running.
className, stylestring, CSSProperties—Class / inline style.
children(remaining: number) => ReactNode—Render-prop for fully custom output instead of the built-in ring + label.

<RafflePick.Slots>

consumer

Independent multi-reel slot machine. Each reel ticks on its own and stops with a stagger, left to right.

PropTypeDefaultNotes
lengthnumber3Number of independent reels.
charsstring'0123456789'Charset pool each reel picks from. Emoji-safe.
spinIntervalnumber80Tick rate per reel, ms, clamped ≥ 50.
staggerMsnumber220Delay between consecutive reel stops on settle.
onResult(joined: string) => void—Fires when the last reel lands, with the joined result.
className, slotClassNamestring—Class for the row wrapper / each individual reel.
style, slotStyleCSSProperties—Inline style for the row wrapper / each reel.

<RafflePick.Wheel>

consumer

Spinning wheel that lands on the value the root picks. Segments come from items or the min/max range. Needs no stylesheet, and honours prefers-reduced-motion.

Reveal results from the wheel's onResult, not the root's onSelect: the root commits the winner when it freezes, which is the moment the landing animation starts.

PropTypeDefaultNotes
segmentsstring[]root poolRelabel segments. The winner still comes from the root; label i maps to pool position i.
sizenumber320Outer diameter in px.
colorsstring[]6-color paletteSegment fills, cycled across segments.
labelColorstring'#fff'Label text color.
maxLabelsnumber40Hide labels past this many segments — they overlap into noise. Segments still work.
spinDurationnumber4200Landing animation length in ms, from freeze to rest.
turnsnumber4Extra full revolutions before the landing angle.
spinIntervalnumber1800Free-spin speed while running, ms per full turn.
pointer'top' | 'right''top'Where the pointer sits on the rim.
hidePointerbooleanfalseDrop the built-in triangle to render your own.
onResult(value) => void—Fires when the wheel comes to rest. Use this — not the root onSelect — to reveal a result.
className, stylestring, CSSProperties—Style hooks on the wheel wrapper.

useRaffleContext()

escape hatch

For fully custom renderers. Must be called under <RafflePick> — throws otherwise.

PropTypeDefaultNotes
phase'idle' | 'starting' | 'running' | 'settling' | 'frozen'—Current state machine phase.
displayednumber | string—Value to render post-freeze / pre-cycle.
noRepeat, exhausted, remainingboolean, boolean, number—no-repeat pool state.
start, freeze, reset() => void—Phase actions — start() is a no-op + fires onExhausted when the pool is empty.
resetHistory() => void—Clears the noRepeat draw history without unmounting.
subscribe(fn: (value: number) => void) => () => void—Tick subscription — for building fully custom renderers.
totalnumber—Pool size — item count, or max - min + 1.
valueAt(position: number) => number | string—Pool entry at a 0-based position, whichever mode the root is in.

Exported types

typescript
PropTypeDefaultNotes
RafflePickValuenumber | string—Value type used across value, onSelect, initialValue, finalValue.
AnimationType'roll' | 'fade' | 'blur' | 'reel'—Value animation kinds.
RafflePickPhase'idle' | 'starting' | 'running' | 'settling' | 'frozen'—The phase state machine.
RaffleContextValueobject—Return type of useRaffleContext() — everything above.

Full prop docs, recipes, and CSS custom properties live in the README on GitHub.