Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Spinning Wheel

ProNew

A prize wheel with an email form: it spins, lands on a weighted or server-chosen segment and reveals a coupon code with confetti.

Installation

pnpm dlx shadcn@latest add @viewport/spinning-wheel

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
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"
openboolean

Controlled visibility.

—
defaultOpenboolean

Initial visibility when uncontrolled.

true
onOpenChange(open: boolean) => void

Called when the card is closed, declined or claimed.

—
titlestring

Heading above the form.

"Spin & Win!"
descriptionstring

Text under the heading.

"Try your luck and spin the wheel for a chance to win exciting rewards. What will you win today?"
collectEmailboolean

Ask for an email before the spin.

true
emailPlaceholderstring

Placeholder of the email field.

"Enter your email..."
spinLabelstring

Label of the spin button.

"Spin Now"
declineLabelstring

Label 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) => void

Called when the wheel has stopped.

—
onDecline() => void

Called when the visitor declines.

—
onClaim(segment: WheelSegment) => void

Called when the visitor presses the button under the result.

—
spinsnumber

How many times the visitor may spin. Landing on a prize ends the game.

1
winTitlestring

Result heading for a prize; `{prize}` is replaced by the segment label.

"You won {prize}!"
winTextstring

Text under the result heading for a prize.

"Use this code at checkout."
loseTitlestring

Result heading for a segment marked `lose`.

"So close!"
loseTextstring

Text under the result heading for a segment marked `lose`.

"No prize this time."
claimLabelstring

Label of the button under the result.

"Continue shopping"
againLabelstring

Label of the button that starts another spin.

"Spin again"
errorTextstring

Message shown when `onSpin` fails.

"Something went wrong. Please try again."
emptyTextstring

Message shown when there are fewer than two segments.

"No prizes to win right now."
accentstring

Wheel, pointer and button color. Any CSS color.

"#0b3a8d"
durationnumber

Length of the spin in milliseconds.

5200
turnsnumber

Full turns before the wheel settles.

6
confettiboolean

Confetti: the strip along the top and the burst on a win.

true
closableboolean

Show the close button.

true
disabledboolean

Disables the form.

false
classNamestring—

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.