Introduction
Horizon uses a custom web component architecture built on native Web Components APIs. All components extend from a baseComponent class that provides powerful features like automatic DOM reference management, declarative event handling, and shadow DOM support.
Core Architecture
Component Lifecycle
All Horizon web components follow the standard Custom Elements lifecycle:connectedCallback()- Called when the component is inserted into the DOMdisconnectedCallback()- Called when the component is removed from the DOMupdatedCallback()- Called when the component is re-rendered by the Section Rendering API
Base Classes
Horizon provides two fundamental base classes:Component
Main base class with refs, event handling, and lifecycle management
DeclarativeShadowElement
Handles declarative shadow DOM hydration
Key Features
Automatic Refs Management
Components automatically track elements withref attributes:
Declarative Event Handling
Use theon: attribute syntax for event handling:
Event Data Passing
Pass data to event handlers using query string syntax:Component Categories
Horizon’s web components are organized into functional categories:Cart Components
Components that manage cart functionality:cart-items-component- Displays and manages cart itemscart-quantity-selector-component- Quantity selection in cartcart-drawer-component- Slide-out cart drawercart-icon- Cart icon with item countcart-note- Customer cart notescart-discount-component- Discount code management
Product Components
Components that power product pages and product cards:product-form-component- Main add-to-cart formadd-to-cart-component- Add to cart button containervariant-picker- Product variant selectionproduct-price- Dynamic price displayproduct-inventory- Stock level displayquantity-selector-component- Quantity input with validation
Event System
Horizon uses custom events for cross-component communication:Theme Events
Global events dispatched ondocument:
ThemeEvents.cartUpdate- Cart contents changedThemeEvents.cartAdd- Item added to cartThemeEvents.variantUpdate- Product variant changedThemeEvents.variantSelected- Variant option selectedThemeEvents.discountUpdate- Discount code applied/removedThemeEvents.quantitySelectorUpdate- Quantity changed
Defining Custom Components
To create a new component:TypeScript Support
Components support TypeScript generics for type-safe refs:Best Practices
Always call super in lifecycle methods
Always call super in lifecycle methods
Use requiredRefs for critical elements
Use requiredRefs for critical elements
Clean up event listeners
Clean up event listeners
Use AbortController for fetch requests
Use AbortController for fetch requests
Next Steps
Component Base Classes
Learn about Component and DeclarativeShadowElement
Cart Components
Explore cart-related web components
Product Components
Discover product page components