Skip to content
Calm motion: animations on this site only fade, with no movement

Coupon input ​

A field for a code, then the saving with a button to remove it

Lets a person type a discount code at checkout. Your server checks the code. If the server takes it, the field changes to a chip with the code and the saving. Use it with the order summary.

Basic

Order summary

  • Home Studio hoodieSize M · BlackQty 1
    $48.00
  • Pop filterQty 2
    $24.00
Subtotal
$72.00
Shipping
Free
Total
$72.00
  • "Apply" or Enter emits apply with the code. With uppercase (on by default), the code is in capital letters. Check the code on your server.
  • While the server checks, set loading. The button shows a spinner, and a second apply does not go out.
  • If the server takes the code, set applied to { code, saving }. The field changes to a chip, and a hidden status line says that the code is applied. The remove button on the chip emits remove with the code.
  • If the server does not take the code, set error to the reason. The field shows it under the field and marks the field as not valid.
  • Change the words with labels or a label pack: label, apply, and remove and applied (functions of the code).

Usage ​

ts
import { BlessCouponInput } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
appliedBlessCoupon—the code that the shop took; with it, a chip shows in place of the field
errorstring—why the shop did not take the code
loadingboolean—the shop is checking the code
uppercasebooleantruewrite the code in capital letters
labelsPartial<{ label: string; apply: string; remove: (code: string) => string; applied: (code: string) => string; }>—

Events

NamePayloadDescription
remove[code: string]
apply[code: string]

Released under the MIT License. Character names and artwork belong to their owners.