Cart Panel
Manages Shopify cart data and AJAX, and delegates modal behaviour to dialog-panel. Includes the <cart-item> element for each line, imported from @magic-spells/cart-panel/cart-item.
v2.0.0@magic-spells/cart-panel
Usage
<!-- Cart with dialog-panel wrapper -->
<dialog-panel id="cart-dialog">
<dialog aria-labelledby="cart-title">
<cart-panel manual>
<div class="cart-header">
<h2 id="cart-title">Shopping Cart</h2>
<button aria-label="Close cart" class="close-button" data-action-hide-cart>
×
</button>
</div>
<div class="cart-body">
<!-- Cart has items section -->
<div data-cart-has-items>
<div class="cart-items" data-content-cart-items>
<!-- Cart items rendered dynamically -->
</div>
</div>
<!-- Cart is empty section -->
<div data-cart-is-empty>
<div class="empty-cart">
<p>Your cart is empty</p>
<p>Add some items to get started!</p>
</div>
</div>
</div>
<div class="cart-footer">
<div class="cart-total">
Subtotal: <span data-content-cart-subtotal>$0.00</span>
</div>About
A slide-out shopping cart web component. The panel owns the cart data, the Shopify AJAX and the item rendering; @magic-spells/dialog-panel owns the modal.
Entry points
| Element | Import | Stylesheet |
|---|---|---|
<cart-panel> + <cart-item> | @magic-spells/cart-panel | @magic-spells/cart-panel/css |
<cart-panel> | @magic-spells/cart-panel/panel | @magic-spells/cart-panel/panel/css |
<cart-item> | @magic-spells/cart-panel/cart-item | @magic-spells/cart-panel/cart-item/css |
Features
- Complete cart management - Handles cart data, AJAX requests, and item rendering
- One import - The root entry registers the panel and the item together; both are also on their own subpaths if you want only one
- Swappable item element - The panel resolves `` from the custom element registry at render time, so you can substitute your own
- Two render modes - JS templates by default, or let a Shopify section render the line items: the server renders content, JS renders behavior
- Optimistic updates - Opt in and quantity changes land on the click, not on the response, with coalescing and stale-response guards behind them
- Delegates modal to dialog-panel - Works with @magic-spells/dialog-panel for accessible modal behavior
Configuration
| Attribute | Type | Description |
|---|---|---|
| manual | Boolean | Skip auto-refresh on connect, require explicit refreshCart() |
| section | String | Shopify section id that renders the line items. Absent, a JS template renders them — see Render Modes |
| optimistic | Boolean | Apply quantity changes and removals locally before the server answers — see Optimistic Updates |
| hide-count-when-empty | Boolean | Hide every [data-content-cart-count] element on the page while the cart is empty |
| state | String | Reflected attribute: 'has-items' or 'empty' |
About, features, usage and options are taken from the package README.