Skip to content

Coupon ​

Both forms share the same card rendering:

  • Coupon card (default): amount, minimum spend, validity and status colors;
  • Selection sheet (when list is present): a trigger button plus a bottom sheet; available coupons can be picked, expired / used / minimum-spend-unmet coupons are disabled, and picking dispatches oas-select and 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-drawer open 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, and oas-select-invalid fires (detail: { reason: 'max-select', limit, code, codes, coupons }). The trigger shows n 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 in oas-select's removed field). 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)

Open sheet

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()

Open sheetClear selection

API ​

oas-coupon ​

Attributes ​

AttributeDescriptionTypeDefault
amountFace value (number, required in card mode)——
codeCoupon identifier returned in event details——
currencyISO 4217 currency, default CNYstringCNY
endValidity end (YYYY-MM-DD)——
listSelection list JSON array [{ code, amount, threshold?, start?, end?, validity?, status?, reason? }]; switches to the sheet formCouponData[] | string—
localeAmount and date formatting locale; defaults to the document <html lang>, then en——
max-selectUpper 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 modestring—
multipleMultiple mode: options become checkboxes; every toggle dispatches an array detail { codes, coupons } and the sheet stays open; default single-select unchangedboolean—
openSheet open state (controlled: host attribute / property writes are silent; user interaction and openOverlay() / closeOverlay() dispatch oas-open-change)boolean | string—
reasonReason text shown when status="unavailable"——
selectedSelected marker for outer layout compositionboolean—
show-countAdds a count pill to the available / unavailable group titlesboolean—
startValidity start (YYYY-MM-DD)——
statusStatus: available (default) / expired / used / unavailable (minimum spend unmet, etc.)stringavailable
thresholdMinimum spend (number, 0 or absent = no minimum)——
trigger-textTrigger label (defaults to i18n coupon.select; shows the selected amount once picked)——
validityValidity text override (e.g. "No expiry"), wins over the formatted start/end——
z-indexOverlay 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 ​

MethodSignatureDescription
openOverlayopenOverlay(): voidOpens the sheet (no-op when already open) and dispatches oas-open-change
closeOverlaycloseOverlay(): voidCloses the sheet (no-op when already closed) and dispatches oas-open-change
clearSelectionclearSelection(): voidClears the selected coupon and the amount on the trigger (silent, no events)

Events ​

EventDescription
oas-clearDispatched when the No-coupon exit is clicked (immediately followed by an empty-selection oas-select; the two events come as a pair)
oas-open-changeDispatched on interaction or imperative open/close with { open } (attribute writes are silent), detail: { open: true } satisfies CouponOpenChangeDetail | { open: false } satisfies CouponOpenChangeDetail
oas-selectDispatched 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-invalidFired 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 }

Released under the MIT OR Apache-2.0 License.