PromoCode
The promo code box of a cart or checkout.
- WALLS10 10% off prints
Have a promo code?
View code
<PromoCode
action="/cart/promo"
value={submission?.code}
error={submission?.error}
applied={cart.codes.map((code) => ({
code: code.code,
label: code.description,
remove: { action: "/cart/promo/remove", fields: { code: code.code } },
}))}
labels={{ toggle: "Have a promo code?", field: "Promo code", apply: "Apply", remove: "Remove" }}
/>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { PromoCode } from "@sdxc/ui/commerce";Renders the applied codes first, then the disclosure, open whenever the reader has typed a code or the server refused one, so a failed post lands on the field with its error showing.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
action | string | Yes | Where the code posts. |
name | string | No | |
value | string | No | The code the reader last sent, kept in the field after an error. |
error | RemixNode | No | Why the server refused the code; the field is marked invalid and described by it. |
fields | Record<string, string> | No | Hidden fields the post carries, such as the page to return to. |
applied | Applied[] | No | |
labels | Labels | Yes |
Also accepts everything in Omit<TagProps<"div">, "children">.