PromoCodeField

A discount-code row. A refusal shakes the field and says why; an accepted code collapses into a chip with what it saved and a way to remove it. Inputs.

Open playground

Try SMOOTH10, EXPIRED, or anything else.

About

PromoCodeField is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { PromoCodeField } from "@ashutoshswamy/smoui" and set onApply, onRemove, placeholder.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { PromoCodeField } from "@ashutoshswamy/smoui";

<PromoCodeField onApply={async (code) => { await api.check(code); return "10% off"; }} />

Props 3

onApply

Resolve with a short description of the saving; reject with an Error to refuse. The message is shown.

(code: string) => Promise<string | void>
onRemove

Called when the chip is removed.

() => void
placeholder

Default Promo code.

string