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

Promo Code

ProNew

A promo field that is a link until it is wanted, checks a code with a loading state, shakes and explains a failure, and becomes a chip once applied.

Installation

pnpm dlx shadcn@latest add @viewport/promo-code

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
applied{ code: string; label: string } | null

The code in use, with what it does, e.g. `{ code: "SPRING10", label: "10% off" }`.

—
onApply*(code: string) => Promise<PromoResult> | PromoResult

Checks a code. Resolve with `ok: true` and set `applied`, or with a message that says why it failed.

—
onRemove*() => void

Removes the code in use.

—
promptstring

The text of the link that opens the field.

"Add a promo code"
classNamestring—

Accessibility

  • A labelled field; a failed code is announced and keeps its text for correction.
  • The applied code is announced and has a named remove button.
  • The shake is skipped under reduced motion; the message remains.