Spinning Wheel
ProNewA prize wheel with an email form: it spins, lands on a weighted or server-chosen segment and reveals a coupon code with confetti.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| segments* | WheelSegment[]Wheel segments, clockwise. At least two. | — |
| display | "inline" | "modal"`inline` renders the card in place; `modal` opens it in a dialog over the page. | "inline" |
| open | booleanControlled visibility. | — |
| defaultOpen | booleanInitial visibility when uncontrolled. | true |
| onOpenChange | (open: boolean) => voidCalled when the card is closed, declined or claimed. | — |
| title | stringHeading above the form. | "Spin & Win!" |
| description | stringText under the heading. | "Try your luck and spin the wheel for a chance to win exciting rewards. What will you win today?" |
| collectEmail | booleanAsk for an email before the spin. | true |
| emailPlaceholder | stringPlaceholder of the email field. | "Enter your email..." |
| spinLabel | stringLabel of the spin button. | "Spin Now" |
| declineLabel | stringLabel of the decline action. Pass an empty string to hide it. | "No, thank you" |
| onSpin | (entry: { email: string }) => number | void | Promise<number | void>Called with the email before the wheel turns. Return a segment index to decide the prize yourself (for example on your server); return nothing to let the wheel pick by weight. Throw or reject to show `errorText`. | — |
| onResult | (segment: WheelSegment, index: number) => voidCalled when the wheel has stopped. | — |
| onDecline | () => voidCalled when the visitor declines. | — |
| onClaim | (segment: WheelSegment) => voidCalled when the visitor presses the button under the result. | — |
| spins | numberHow many times the visitor may spin. Landing on a prize ends the game. | 1 |
| winTitle | stringResult heading for a prize; `{prize}` is replaced by the segment label. | "You won {prize}!" |
| winText | stringText under the result heading for a prize. | "Use this code at checkout." |
| loseTitle | stringResult heading for a segment marked `lose`. | "So close!" |
| loseText | stringText under the result heading for a segment marked `lose`. | "No prize this time." |
| claimLabel | stringLabel of the button under the result. | "Continue shopping" |
| againLabel | stringLabel of the button that starts another spin. | "Spin again" |
| errorText | stringMessage shown when `onSpin` fails. | "Something went wrong. Please try again." |
| emptyText | stringMessage shown when there are fewer than two segments. | "No prizes to win right now." |
| accent | stringWheel, pointer and button color. Any CSS color. | "#0b3a8d" |
| duration | numberLength of the spin in milliseconds. | 5200 |
| turns | numberFull turns before the wheel settles. | 6 |
| confetti | booleanConfetti: the strip along the top and the burst on a win. | true |
| closable | booleanShow the close button. | true |
| disabled | booleanDisables the form. | false |
| className | string | — |
Accessibility
- The wheel is an image named with its prizes; the result is a heading that takes focus when the wheel stops, so it is read at once.
- The email is a labelled field; a missing or bad address is announced with role=alert and marked aria-invalid.
- While it spins the button is aria-busy and a live region says so; the coupon has a named copy button that confirms in the live region.
- As a modal it is a Radix dialog: focus is trapped, Escape closes and focus returns to where it was; panel and backdrop enter together.
- Under reduced motion the wheel and result jump to the end without a pointer flick, confetti fall or modal fade.