CartControl
Cart control that syncs with a datasource and exposes pending vs verified state.
import { CartControl } from "@schukai/monster/source/components/form/cart-control.mjs";Purpose and scope
Cart control that syncs with a datasource and exposes pending vs verified state.
This page documents the <monster-cart-control> custom element. Use the Usage examples for a working starting point and the API tab for the complete public contract.
When to use it
Use this module when its focused responsibility matches the surrounding workflow. Prefer its public options, properties, methods and events over reaching into rendered internals.
Cart Summary
Renders item count and total from local cart data using the public mapping options.
Javascript
import "@schukai/monster/source/components/form/cart-control.mjs";
const cart = document.getElementById("cart-summary");
cart.setOption("mapping.totalTemplate", "total");
cart.setOption("mapping.currencyTemplate", "currency");
cart.setOption("data", {
items: [{sku: "MONSTER-1", qty: 2}, {sku: "MONSTER-2", qty: 1}],
total: 87.5,
currency: "EUR",
});
cart.refresh();HTML
<monster-cart-control id="cart-summary"></monster-cart-control>Stylesheet
/** no additional stylesheet is defined **/Verified Cart Updates
Applies a verified cart snapshot and consumes the component's update event.
Javascript
import "@schukai/monster/source/components/form/cart-control.mjs";
const cart = document.getElementById("cart-updates");
const status = document.getElementById("cart-updates-status");
cart.setOption("mapping.totalTemplate", "total");
cart.setOption("mapping.currencyTemplate", "currency");
cart.addEventListener("monster-cart-control-update", event => {
status.textContent = `${event.detail.count} items, ${event.detail.total} ${event.detail.currency}`;
});
document.getElementById("cart-updates-refresh").addEventListener("click", () => {
cart.setOption("data", {
items: [{sku: "MONSTER-1", qty: 4}],
total: 116,
currency: "EUR",
});
cart.refresh();
});HTML
<section style="display:grid;gap:var(--monster-space-3)">
<monster-cart-control id="cart-updates"></monster-cart-control>
<button id="cart-updates-refresh" type="button">Apply verified cart</button>
<output id="cart-updates-status">Waiting for a cart update.</output>
</section>Stylesheet
/** no additional stylesheet is defined **/Component Design
monster-cart-control separates the cart summary from transport state. It renders item count and total while reporting idle, pending, verified, and error states.
Data and Interaction
Supply verified cart snapshots through the public data and mapping options. Use addOrChange() only when a write datasource is configured, and consume the public lifecycle events for user feedback.
Customizing With Parts
You can adapt the visual appearance through exported parts instead of modifying the internal template. This reference is generated from the current component source.
The component exposes these part names:
control: Outer wrapper of the component.count: Element representing the count.status: Live component status region.summary: Summary region.total: Rendered total value.
HTML Structure
<monster-cart-control></monster-cart-control>JavaScript Initialization
const element = document.createElement('monster-cart-control');
document.body.appendChild(element);Exported
CartControlDerived from
CustomControlOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomControl.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomControl.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomControl.
Behavioral methods
addOrChange(payload)payload{object}: payload
refresh()- {CartControl}
Static methods
[instanceSymbol]()getCSSStyleSheet()getTag()Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()Events
The component emits the following events:
monster-cart-control-pendingmonster-cart-control-verifiedmonster-cart-control-errormonster-cart-control-update
For more information on how to handle events, see the mdn documentation.