Promo Code
ProNewA 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
| Prop | Type | Default |
|---|---|---|
| applied | { code: string; label: string } | nullThe code in use, with what it does, e.g. `{ code: "SPRING10", label: "10% off" }`. | — |
| onApply* | (code: string) => Promise<PromoResult> | PromoResultChecks a code. Resolve with `ok: true` and set `applied`, or with a message that says why it failed. | — |
| onRemove* | () => voidRemoves the code in use. | — |
| prompt | stringThe text of the link that opens the field. | "Add a promo code" |
| className | string | — |
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.