Skip to main content

Introduction

Horizon uses a custom web component architecture built on native Web Components APIs. All components extend from a base Component 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 DOM
  • disconnectedCallback() - Called when the component is removed from the DOM
  • updatedCallback() - 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 with ref attributes:

Declarative Event Handling

Use the on: attribute syntax for event handling:
The event handler methods are automatically called on the closest component instance:

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 items
  • cart-quantity-selector-component - Quantity selection in cart
  • cart-drawer-component - Slide-out cart drawer
  • cart-icon - Cart icon with item count
  • cart-note - Customer cart notes
  • cart-discount-component - Discount code management
Learn more about cart components →

Product Components

Components that power product pages and product cards:
  • product-form-component - Main add-to-cart form
  • add-to-cart-component - Add to cart button container
  • variant-picker - Product variant selection
  • product-price - Dynamic price display
  • product-inventory - Stock level display
  • quantity-selector-component - Quantity input with validation
Learn more about product components →

Event System

Horizon uses custom events for cross-component communication:

Theme Events

Global events dispatched on document:
Key theme events:
  • ThemeEvents.cartUpdate - Cart contents changed
  • ThemeEvents.cartAdd - Item added to cart
  • ThemeEvents.variantUpdate - Product variant changed
  • ThemeEvents.variantSelected - Variant option selected
  • ThemeEvents.discountUpdate - Discount code applied/removed
  • ThemeEvents.quantitySelectorUpdate - Quantity changed

Defining Custom Components

To create a new component:

TypeScript Support

Components support TypeScript generics for type-safe refs:

Best Practices

Next Steps

Component Base Classes

Learn about Component and DeclarativeShadowElement

Cart Components

Explore cart-related web components

Product Components

Discover product page components