Promo Code Field
Apply a promo code with checking and refusal states; applied codes stay as removable tokens with their saving.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
codes | PromoCode[] | [] | The applied codes. |
max | number | 1 | How many codes may apply at once. 0 means no limit. |
collapsed | boolean | false | Starts as an "Add a promo code" link that opens the field. |
case-sensitive | boolean | false | Keeps the case the reader typed instead of upper-casing codes. |
label | string | — | The field's accessible name and placeholder. Default: "Promo code". |
disabled | boolean | false | Turns the field, the Apply button and the tokens' remove buttons off. |
Events
| Name | Type | Description |
|---|---|---|
apply | CustomEvent<{ code: string; label?: string }> | Fired when a code was accepted. Does not bubble. |
reject | CustomEvent<{ code: string; error: string }> | Fired when a code was refused. Does not bubble. |
remove | CustomEvent<{ code: string }> | Fired when the reader removed an applied code. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
codes | The row of applied codes. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-promo-code-field--gap | pixel | 8px | Space between the field row and the tokens. |
--c2-promo-code-field__row--gap | pixel | 8px | Space between the field and the Apply button. |
--c2-promo-code-field__codes--gap | pixel | 6px | |
--c2-promo-code-field__saving--color | color | #71717a | The saving beside a code. |
--c2-promo-code-field__code--font-weight | font-weight | 600 | |
--c2-promo-code-field__code--letter-spacing | string | 0.02em | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under promo-code-field, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Promo code | — |
apply | Apply | — |
add | Add a promo code | — |
remove | Remove {0} | {0} code |
applied | {0} applied | {0} code |
appliedWith | {0} applied: {1} | {0} code {1} label |
removed | {0} removed | {0} code |
alreadyApplied | {0} is already applied | {0} code |
failed | This code could not be checked. Try again. | — |
codes | Applied codes | — |