# Shopify Storefront Components API Documentation ## Table of Contents - [Attributes](#attributes) - [shopify-attr](#shopify-attr) - [Components](#components) - [shopify-cart](#shopify-cart) - [shopify-context](#shopify-context) - [shopify-list-context](#shopify-list-context) - [shopify-data](#shopify-data) - [shopify-media](#shopify-media) - [shopify-money](#shopify-money) - [shopify-store](#shopify-store) - [shopify-variant-selector](#shopify-variant-selector) ## Attributes ### shopify-attr **Description**: Use the `shopify-attr` attribute to bind an attribute to data from Shopify. Anywhere within the template of a [shopify-context component](#shopify-context), you can use the `shopify-attr--attribute-name` attribute to bind an attribute to data from Shopify. For example, `shopify-attr--href="product.onlineStoreUrl"` can be used to bind the `href` attribute to the `onlineStoreUrl` field on a product context. See the [playground](https://webcomponents.shopify.dev/playground) for more complete examples. **Example**: ```html ``` ## Components ### shopify-cart **Description**: The cart component provides a mini shopping cart functionality for your website. Here's how it works: 1. To add items to the cart: - Use the `addLine()` method - The method needs an event object - The event's target must be inside a product [context component](#shopify-context) 2. To display the cart: - The cart uses a native [HTML `` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog). - To show it as a popup modal, call the `showModal()` method. 3. Customize the cart with CSS parts and slots. > Note: > The cart component does not support mixing products from multiple stores. **Example**: ```html ``` #### Attributes and properties | Name | Type | Description | Optional | | --------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | addLine | (e: Event) => CartAttributes | A method to add an item to the cart. | Yes | | close | () => CartAttributes | A method to close the cart dialog. | Yes | | open | boolean | A property to get the open state of the cart. Example: `getElementById('cart').open` | Yes | | show | () => CartAttributes | A method to display the cart as a modal in a [`dialog` element modelessly](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/show). | Yes | | showModal | () => CartAttributes | A method to display the underlying [cart as a modal](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal) in a `dialog` element. | Yes | | target | string | The [target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target) for the checkout link. Defaults to "\_top". | Yes | #### CSS parts CSS parts allow you to target and override the default styling within the cart component. | Part Name | Description | | ---------------- | ------------------------------------------------------------------------------------- | | dialog | The dialog element. | | line-heading | The cart line-item title element. | | line-image | The cart line-item image element. | | line-options | The cart line-item options element. | | line-price | The cart line-item quantity element. | | primary-button | The primary button element. Used to style the checkout link. | | secondary-button | The secondary button element. Used to style the buttons that modify a cart-line item. | #### Slots Slots allow you to override the default content of the cart component. | Slot Name | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------ | | checkout-button | The content to display in the checkout button. Useful to add a custom checkout button text. | | empty | The content to display when the cart is empty. | | extension | Extend the cart with additional content below the checkout button. Useful to add upsell products or other content. | **Custom Cart Example**: ```html
Ihr Warenkorb ist leer
Zur Kasse
``` ### shopify-context **Description**: The context component defines which Shopify data should be available in different parts of your page. Each `` component requires two attributes: - `type`: Specifies what kind of data you want (for example, `product`). - `handle`: Identifies the specific item. For example, the handle for the URL [`demostore.mock.shop/products/men-t-shirt`](https://demostore.mock.shop/products/men-t-shirt) is `men-t-shirt`. If you're working with a single storefront, then you can add the `` component anywhere on your page (it doesn't need to be inside the `` component). If you're working with multiple storefronts, then nest the context inside its corresponding store component. Every `` component also requires a `