Coupon center (scenario recipe)
Three stages assembled from existing components — coupon display, claim confirmation, wallet redemption — using
oas-coupon(coupon cards + built-in selection popup) andoas-bottom-sheet(claim dialog). No new component API; host-owned business states like "claimed" stay on the host, while the component carries coupon forms like "used / expired / threshold not met".
Roles
- Coupon display:
oas-couponcard mode —amount/threshold/ validity /statussemantic colors built in. - Claim confirmation:
oas-bottom-sheetcontrolled dialog —open+oas-closeprotocol; drag handle / backdrop / Esc closing are built into the sheet, claiming is host business. Create dynamically, remove on close: the closed sheet never stays in the DOM, Tab cannot fall into a hidden drawer. - Wallet redemption:
oas-couponlist mode — passlistand you get the selection popup;oas-selectreturns the chosen coupon; selecting means using it.
Claim flow: coupon → dialog → claimed
Batch coupons + bottom-sheet claim (claimed buttons become disabled)
Press "Claim" → confirm in the bottom sheet → the slot flips to "Claimed".
Key points:
- Claim dialog uses
oas-bottom-sheet, created dynamically and removed on close: claiming is a high-frequency light action on mobile; rising from the bottom suits the thumb zone. On each "Claim":createElement→ fill coupon face and buttons → setopen→appendChild; all three close paths —oas-close(detail.reason=drag/backdrop/esc), cancel, confirm — end inremove(). The closed sheet is not in the DOM, so Tab cannot reach a hidden drawer — one step further than the component page's example (which only collapses on close and deletes the old one before the next open). Known edge: the in-panel Tab wrap relies on native focusable elements; this recipe's buttons areoas-button(custom elements) and Tab is observed to escape to the page — an existing bottom-sheet boundary to be consolidated at the component level; the Esc / backdrop / drag-handle close protocol is unaffected. - "Claimed" is not a component state: after confirmation the host disables the slot's button and sets the copy to "Claimed" while the coupon face stays readable — business state and display state are kept apart instead of inventing component attributes.
- The coupon face carries only the coupon's own form: expired coupons use
status="expired"(grayed + expired marker) with the button disabled in sync; "threshold not met" usesstatus="unavailable"+reason. - The coupon inside the dialog reuses the same component: write the chosen coupon's data into the inner
oas-couponattributes — no second coupon template needed.
Wallet: redeem via the built-in selection popup (claimed → used)
Built-in selection popup: selecting redeems (oas-select → status=used)
Open the popup and pick a coupon — selecting redeems it; the face flips to "Used".
Key points:
- The list popup is a built-in coupon capability (
listin, popup out): available / unavailable grouping, Esc on the shared overlay stack, auto close on selection andoas-select(detail{ code, coupon }) — no need to build another selection sheet. - The empty exit is contractual: the "use no coupon" button fires
oas-clearfollowed by an emptyoas-select(coupon: null) — the host falls back to the no-coupon checkout path; guard for null. - Redemption writes back through the data channel: the host sets
status="used"on the chosen coupon and rewrites the wholelist; popup and faces follow — one source of truth (host data).
Key code
ts
// Claim dialog: create dynamically, remove on close (dynamic creation follows the
// bottom-sheet component page example; removing on close goes one step further —
// the example only collapses on close and deletes the old sheet before the next open)
claimBtns.forEach((btn) =>
btn.addEventListener('oas-click', () => openSheet(btn)),
)
function openSheet(btn) {
const sheet = document.createElement('oas-bottom-sheet')
sheet.setAttribute('max-height', '340px')
sheet.innerHTML = '…coupon face (oas-coupon) + "Not now / Confirm claim" buttons…'
sheet.addEventListener('oas-close', () => sheet.remove()) // drag / backdrop / Esc
sheet.querySelector('.cc-cancel').addEventListener('oas-click', () => sheet.remove())
sheet.querySelector('.cc-confirm').addEventListener('oas-click', () => {
sheet.remove()
claimApiCall().then(() => {
btn.setAttribute('disabled', '')
btn.textContent = 'Claimed' // business state: host-owned
})
})
sheet.setAttribute('open', '')
document.body.appendChild(sheet) // with the component already registered, append upgrades it and replays attributes
}
// Wallet redemption (coupon built-in selection popup)
pack.addEventListener('oas-select', (e) => {
const { code, coupon } = e.detail
if (!coupon) return // "use no coupon" empty exit
const list = JSON.parse(pack.getAttribute('list')).map((c) =>
c.code === code ? { ...c, status: 'used' } : c,
)
pack.setAttribute('list', JSON.stringify(list))
})Notes
- Overlays share the Esc stack: with the wallet popup and the claim sheet both open, Esc closes the topmost one; both are "request to close" protocols — the host
remove()s the sheet onoas-closeand syncs its open state on the coupon'soas-open-change. - Coupon cards have no click event: the claim entry is the host's own button — the face is a pure display piece; interaction semantics belong to the host composition.
- No manual z-index work: the bottom-sheet and the coupon popup share the same stacking ladder (
--oas-z-modaltier) by default, also when mixed with modal / drawer. - Rollback on claim failure: close the sheet first, then call the API; on failure roll the slot back (button clickable again) and surface feedback — this demo sets state synchronously for simplicity; real business follows the API result.