Coupon
Both forms share the same card rendering:
- Coupon card (default): amount, minimum spend, validity and status colors;
- Selection sheet (when
listis present): a trigger button plus a bottom sheet; available coupons can be picked, expired / used / minimum-spend-unmet coupons are disabled, and picking dispatchesoas-selectand closes the sheet.
Coupon card
amount is the face value, threshold the minimum spend (0 or absent = no minimum) and start / end the validity (or validity text to take over the display entirely):
Available coupons
Status semantics
status="expired|used" uses a muted surface and disabled text; status="unavailable" pairs with reason to explain why (minimum spend unmet etc.):
Expired / used / not eligible
Currency, coupon code and selected marker
currency / locale control amount and date formatting; code is the coupon identifier returned in the oas-select detail for host bookkeeping; selected is only a selected-state marker (used by outer layout composition, it does not drive selection logic):
Multi-currency + coupon code + selected state
Selection sheet
list takes the coupon array; the trigger opens a bottom sheet (role="dialog", focus moved in, Esc / backdrop closes). Picking an available coupon dispatches oas-select and closes the sheet; the selected amount is shown on the trigger and trigger-text overrides the trigger label (shown while nothing is picked):
The sheet follows the shared overlay stacking protocol: opening it locks page scrolling (a cross-component reference-counted lock that restores the host's original value when the last overlay closes), and Esc is resolved by the shared layer stack — topmost first. With
oas-modal/oas-draweropen at the same time, one Esc closes only the top layer. Re-attaching the host while open re-acquires both.
Select a coupon + event feedback
Click the trigger to select a coupon.
Groups, counts and the "No coupon" exit
The sheet list renders two groups — available / unavailable (titles via i18n; empty groups are skipped); show-count adds a count pill to each group title. A fixed "No coupon" exit sits at the top of the list: clicking it dispatches oas-clear, then an empty-selection oas-select (single-mode detail { code: '', coupon: null }), and closes the sheet — the host receives both events and can use either:
Groups + counts + exit
Open the sheet to see the groups; click "No coupon" to see oas-clear feedback.
Multiple selection
multiple turns the options into checkboxes: every toggle dispatches oas-select with an array detail ({ codes, coupons }), and the sheet stays open (the host decides when to close it); the trigger shows how many coupons are picked. The default single-select behavior is unchanged (radio + close on pick):
Stacking multiple coupons
Open the sheet and pick several coupons; each toggle shows the array detail.
Stacking rules (max-select / exclusive groups)
Multiple selection can layer two combination rules, both with explicit feedback beyond oas-select:
max-select: upper bound on selected coupons (positive integer;0/ invalid = unlimited with one warning). Once the limit is reached, further picks do not take effect — the checkbox reverts, the selection stays unchanged, andoas-select-invalidfires (detail: { reason: 'max-select', limit, code, codes, coupons }). The trigger showsn of m selected.- Exclusive groups: list entries may declare
exclusiveGroup; coupons in the same group are mutually exclusive — picking one automatically deselects the other selected coupons of that group (auto-resolved combinations are not blocked; the dropped codes come back inoas-select'sremovedfield). Different groups and group-less coupons coexist. - When both rules apply, the limit is judged on the net count after the swap: a same-group swap drops the peer first, so it never needs an extra slot (picking a peer while already at 2 of 2 is not rejected).
- Single-select mode is inherently exclusive and ignores
max-select/exclusiveGroup.
max-select=2 + exclusive group (store keeps only one)
Try picking three coupons: the limit dispatches oas-select-invalid, and same-group swaps report removed codes.
Imperative open/close and selection reset
open is a controlled attribute (host attribute / property writes are silent); openOverlay() / closeOverlay() are the imperative calls (they dispatch oas-open-change), and clearSelection() clears the picked coupon silently for hosts that need to reset the selection. z-index adds a numeric level on top of --oas-z-index-base (the default keeps the --oas-z-modal step, same shape as modal / drawer); the demo below uses 1300.
openOverlay() / closeOverlay() / clearSelection()
API
oas-coupon
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
amount | Face value (number, required in card mode) | — | — |
code | Coupon identifier returned in event details | — | — |
currency | ISO 4217 currency, default CNY | string | CNY |
end | Validity end (YYYY-MM-DD) | — | — |
list | Selection list JSON array [{ code, amount, threshold?, start?, end?, validity?, status?, reason? }]; switches to the sheet form | CouponData[] | string | — |
locale | Amount and date formatting locale; defaults to the document <html lang>, then en | — | — |
max-select | Upper bound on selected coupons in multiple mode (positive integer; 0 / invalid = unlimited with one warning): further picks do not take effect (checkbox reverts, selection unchanged, oas-select-invalid fires); the trigger shows n of m selected. Ignored in single-select mode | string | — |
multiple | Multiple mode: options become checkboxes; every toggle dispatches an array detail { codes, coupons } and the sheet stays open; default single-select unchanged | boolean | — |
open | Sheet open state (controlled: host attribute / property writes are silent; user interaction and openOverlay() / closeOverlay() dispatch oas-open-change) | boolean | string | — |
reason | Reason text shown when status="unavailable" | — | — |
selected | Selected marker for outer layout composition | boolean | — |
show-count | Adds a count pill to the available / unavailable group titles | boolean | — |
start | Validity start (YYYY-MM-DD) | — | — |
status | Status: available (default) / expired / used / unavailable (minimum spend unmet, etc.) | string | available |
threshold | Minimum spend (number, 0 or absent = no minimum) | — | — |
trigger-text | Trigger label (defaults to i18n coupon.select; shows the selected amount once picked) | — | — |
validity | Validity text override (e.g. "No expiry"), wins over the formatted start/end | — | — |
z-index | Overlay stacking level (numeric value added on top of --oas-z-index-base; default keeps the --oas-z-modal step, same shape as modal / drawer) | — | — |
Methods
| Method | Signature | Description |
|---|---|---|
openOverlay | openOverlay(): void | Opens the sheet (no-op when already open) and dispatches oas-open-change |
closeOverlay | closeOverlay(): void | Closes the sheet (no-op when already closed) and dispatches oas-open-change |
clearSelection | clearSelection(): void | Clears the selected coupon and the amount on the trigger (silent, no events) |
Events
| Event | Description |
|---|---|
oas-clear | Dispatched when the No-coupon exit is clicked (immediately followed by an empty-selection oas-select; the two events come as a pair) |
oas-open-change | Dispatched on interaction or imperative open/close with { open } (attribute writes are silent), detail: { open: true } satisfies CouponOpenChangeDetail | { open: false } satisfies CouponOpenChangeDetail |
oas-select | Dispatched when an available coupon is picked. Single mode (default) detail { code, coupon } and the sheet closes; multiple mode detail { codes, coupons } (arrays, sheet stays open); the No-coupon exit dispatches an empty selection — single { code: empty string, coupon: null } / multiple { codes: [], coupons: [] } |
oas-select-invalid | Fired when a multiple-mode combination check rejects a pick (over max-select); the pick does not take effect and the selection is unchanged; detail: { reason: "max-select", limit, code, codes, coupons } |