Events Reference
All Qariyb components emit custom events that follow a consistent naming pattern and structure.
Event Naming
Events follow the pattern: qariyb:{component}:{action}
| Component | Prefix |
|---|---|
| Checkout | qariyb:checkout:* |
| Tickets | qariyb:tickets:* |
| Button | qariyb:button:* |
| Event Card | qariyb:card:* |
| Event List | qariyb:list:* |
| SDK | qariyb:initialized |
Event Structure
All events have a consistent detail structure:
interface QariybEventDetail<T> {
timestamp: number; // Unix timestamp (ms)
component: string; // Component that emitted
action: string; // Action that occurred
data: T; // Event-specific payload
}
Access via event.detail:
element.addEventListener('qariyb:checkout:success', (e) => {
console.log(e.detail.timestamp); // 1706745600000
console.log(e.detail.component); // 'checkout'
console.log(e.detail.action); // 'success'
console.log(e.detail.data); // { order, tickets, ... }
});
Event Characteristics
All events:
- Bubble: Yes (
bubbles: true) - Cross Shadow DOM: Yes (
composed: true) - Cancelable: Yes (
cancelable: true) - Also dispatch on window: Yes (for global listeners)
Checkout Events
qariyb:checkout:ready
Component mounted and initialized.
{ eventId: string }
qariyb:checkout:event-loaded
Event data successfully fetched.
{ event: QariybEvent }
qariyb:checkout:event-error
Failed to load event data.
{ error: string, eventId: string }
qariyb:checkout:step-changed
Checkout step changed.
{
from: CheckoutStep,
to: CheckoutStep,
eventId: string
}
// CheckoutStep = 'loading' | 'tickets' | 'details' | 'payment' | 'processing' | 'success' | 'error'
qariyb:checkout:cart-updated
Cart items modified.
{
cart: Cart,
action: 'add' | 'remove' | 'clear',
ticketId?: string,
ticketName?: string
}
qariyb:checkout:details-submitted
Customer details form submitted.
{
email: string,
name: string,
phone?: string
}
qariyb:checkout:payment-started
Stripe payment initiated.
{
cartId: string,
amount: number, // cents
currency: string
}
qariyb:checkout:payment-processing
Payment being processed.
{ paymentIntentId?: string }
qariyb:checkout:discount-applied
A discount code was accepted and the PaymentIntent repriced. discount.new_total
is what the card will be charged.
{
discount: DiscountApplication,
previousTotal: number
}
qariyb:checkout:discount-failed
A discount code was rejected. error is the server's reason — show it verbatim.
{
code: string,
error: string
}
qariyb:checkout:success
Checkout completed successfully.
{
order: Order,
tickets: OrderTicket[],
requiresApproval: boolean
}
qariyb:checkout:error
Checkout error occurred.
{
error: string,
code?: string,
step?: CheckoutStep
}
Tickets Events
qariyb:tickets:ready
Component mounted.
{ eventId: string }
qariyb:tickets:loaded
Ticket data fetched.
{
tickets: TicketType[],
event: QariybEvent
}
qariyb:tickets:quantity-changed
User changed ticket quantity.
{
ticketId: string,
ticketName: string,
quantity: number,
previousQuantity: number,
price: number, // cents
currency: string
}
qariyb:tickets:selected
User clicked continue (via on-continue).
{
cart: Cart,
eventId: string
}
qariyb:tickets:error
Error loading tickets.
{
error: string,
eventId: string
}
Button Events
qariyb:button:ready
Component mounted.
{ eventId: string }
qariyb:button:modal-opened
Modal opened.
{ eventId: string }
qariyb:button:modal-closed
Modal closed.
{
eventId: string,
reason: 'success' | 'cancel' | 'escape' | 'overlay'
}
Card Events
qariyb:card:ready
Component mounted.
{ eventId: string }
qariyb:card:loaded
Event data fetched.
{ event: QariybEvent }
qariyb:card:clicked
Card interaction.
{
event: QariybEvent,
action: 'view' | 'tickets'
}
qariyb:card:error
Error loading event.
{
error: string,
eventId: string
}
List Events
qariyb:list:ready
Component mounted.
{ organizationId: string }
qariyb:list:loaded
Events fetched.
{
events: QariybEvent[],
total: number,
hasMore: boolean
}
qariyb:list:error
Error loading events.
{
error: string,
organizationId: string
}
Global SDK Event
qariyb:initialized
SDK loaded (fires once on window).
{
version: string,
config: QariybConfig | undefined
}
window.addEventListener('qariyb:initialized', (e) => {
console.log('SDK loaded:', e.detail.data.version);
});
Listening Patterns
On Specific Element
const checkout = document.querySelector('qariyb-checkout');
checkout.addEventListener('qariyb:checkout:success', handler);
On Window (Global)
window.addEventListener('qariyb:checkout:success', handler);
Using Callback Attributes
<qariyb-checkout on-success="handleSuccess"></qariyb-checkout>
<script>
function handleSuccess(data) {
// data = e.detail.data (unwrapped)
}
</script>
Callback functions must be defined on the window object to be accessible. Use function declarations or explicitly assign to window.
TypeScript Event Handling
import type { QariybCustomEvent, CheckoutSuccessDetail } from '@qariyb/js';
const handler = (e: QariybCustomEvent<CheckoutSuccessDetail>) => {
const { order, tickets } = e.detail.data;
// Fully typed!
};
document.addEventListener('qariyb:checkout:success', handler as EventListener);
Complete Events List
| Event | Component | Callback Attr |
|---|---|---|
qariyb:checkout:ready | Checkout | on-ready |
qariyb:checkout:event-loaded | Checkout | on-event-loaded |
qariyb:checkout:event-error | Checkout | on-event-error |
qariyb:checkout:step-changed | Checkout | on-step-changed |
qariyb:checkout:cart-updated | Checkout | on-cart-updated |
qariyb:checkout:details-submitted | Checkout | on-details-submitted |
qariyb:checkout:payment-started | Checkout | on-payment-started |
qariyb:checkout:payment-processing | Checkout | on-payment-processing |
qariyb:checkout:discount-applied | Checkout | on-discount-applied |
qariyb:checkout:discount-failed | Checkout | on-discount-failed |
qariyb:checkout:success | Checkout | on-success |
qariyb:checkout:error | Checkout | on-error |
qariyb:tickets:ready | Tickets | on-ready |
qariyb:tickets:loaded | Tickets | on-loaded |
qariyb:tickets:quantity-changed | Tickets | on-quantity-changed |
qariyb:tickets:selected | Tickets | on-continue |
qariyb:tickets:error | Tickets | on-error |
qariyb:button:ready | Button | on-ready |
qariyb:button:modal-opened | Button | on-modal-opened |
qariyb:button:modal-closed | Button | on-modal-closed |
qariyb:card:ready | Card | on-ready |
qariyb:card:loaded | Card | on-loaded |
qariyb:card:clicked | Card | on-clicked |
qariyb:card:error | Card | on-error |
qariyb:list:ready | List | on-ready |
qariyb:list:loaded | List | on-loaded |
qariyb:list:error | List | on-error |
qariyb:initialized | SDK | - |