# Enhanced Shopify Storefront Web Components Rules This file includes examples, guidelines, and documentation for building Storefront Web Components. ## Purpose Create a beautiful, production-ready HTML storefront using Shopify's Storefront Web Components based on the user's specific requirements. ## Core Requirements - Develop a responsive storefront using ONLY Shopify web components - Create a streamlined shopping experience with proper product display and cart functionality - Implement clean, minimal, production-ready code optimized for educational purposes ## Design requirements Strictly follow WCAG color contrast guidelines: - All text and icons must have a minimum contrast ratio of 4.5:1 against their backgrounds (3:1 for large text/icons). - UI components (buttons, input fields, icons) must have at least a 3:1 contrast ratio with adjacent colors. - Use dark text/icons on light backgrounds or vice versa; avoid low-contrast pairs (e.g., light gray on white). - Validate all color choices with a contrast checker and ensure compliance. Maintain consistent and adequate whitespace between all elements: - Use a spacing scale (e.g., multiples of 8px) for margins and paddings. - Apply the law of proximity: group related elements together and separate unrelated elements with more space. - Add generous padding around buttons and interactive elements for easy touch/click. - Use a grid system for alignment and spacing consistency. - Increase whitespace around headings, CTAs, and key content to create visual hierarchy. - Ensure spacing adapts responsively across different screen sizes. Maintain consistent typography throughout the designs Product details modals must be aligned in the center of the page. Display full images on product cards; avoid cropping images to fit. ## Implementation Specifications ### Required Components - **Store Configuration**: Properly configured `` element - **Product Display**: Complete product cards with images, titles, prices, and variants - **Cart Functionality**: - Working "Add to Cart" buttons and "Open Cart" button - Adding to cart should open the cart as well - **Responsive Design**: Layout that works across all device sizes ### Technical Implementation ```html
``` ### Fully-functional example of embedded product card
### Technical Tips - For cart modal after adding items: `document.getElementById('main-cart').showModal()` - In the `shopify-cart::part(secondary-button)` CSS block, always include a `fill` property. - For context updating in dialogs: `document.getElementById('context-id').updateContext(event)` - Default product handles if none specified: `hoodie`, `sweatpants`, `puffer` - For collection pages, use this handle if none specified: `unisex` - Include error handling for product variants and loading states - For grid css columns - don't use `auto-fill` - Don't add attributes on shopify elements that are not specified in the documentation - For product image, using `product.selectedOrFirstAvailableVariant.image` is better than `product.featuredImage` if you want it to change when a variant is selected - Always include this script tag: `` ## Example Steps Breakdown Ideas (if the user asks for something like this) ### 1. A Minimal Product Card with Image and Price **Implementation Steps:** 1. Set up the store configuration using `` with a `store-domain` attribute 2. Create a product context using `` 3. Inside the template: - Add a `` component to display the product image - Add a heading with `` to show the product title - Add `` to display the price 4. Apply basic styling to create a card-like appearance ### 2. A Cool Example Using the 'Buy Now' Button **Implementation Steps:** 1. Set up store configuration with `` 2. Create a product context 3. Inside the template: - Add product details (title, description) using `` - Add variant selector with `` - Create a "Buy Now" button that references the cart component - Set up a `` component with the buyNow method 4. Configure the button's onclick event to use the cart's buyNow method 5. Style the button for visual appeal ### 3. A Grid Collection Page **Implementation Steps:** 1. Set up store configuration 2. Create a collection context: `` 3. Display collection title and description 4. Add a nested product context for the collection's products: ``` ``` 5. Create a grid layout using CSS Grid or Flexbox 6. Within the product template, create product cards with: - Product image using `` - Product title using `` - Product price using `` 7. Add pagination or "load more" functionality if needed ### 4. A Product Details Page Layout **Implementation Steps:** 1. Set up store configuration 2. Create a product context 3. Design a two-column layout: - Left column: - Product images gallery using `` for the featured image - Additional image handling if needed - Right column: - Product title using `` - Product description using `` - Price using `` - Variant selector using `` - Add to cart button that calls a cart component 4. Add a `` component for cart functionality 5. Style with responsive design in mind ### 5. A Blog Post Page Layout **Implementation Steps:** 1. Set up store configuration 2. Create a blog article context: ``` ``` 3. Design the blog post layout: - Header section with: - Article title using `` - Published date using `` - Author information if available - Featured image section using `` - Content section using `` - Tags or categories section if needed 4. Add navigation for related articles or back to blog link 5. Style appropriately for readability ### 6. A Very Customized Variant Selector **Implementation Steps:** 1. Set up store configuration 2. Create a product context 3. Add a basic `` component 4. Create a detailed CSS customization targeting parts: ```css shopify-variant-selector::part(form) { /* Custom layout */ } shopify-variant-selector::part(label) { /* Custom label styling */ } shopify-variant-selector::part(radio) { /* Custom radio button styling */ } shopify-variant-selector::part(radio-selected) { /* Custom styling for selected options */ } shopify-variant-selector::part(color-swatch) { /* Custom color swatch styling */ } shopify-variant-selector::part(color-swatch-selected) { /* Custom styling for selected color swatches */ } ``` 5. Add JavaScript to enhance interactivity if needed 6. Ensure the variant selector updates product images and prices appropriately ## Response Format - Return ONLY HTML code that goes between `` and `` tags - Prioritize any specific requirements from the user's prompt - No explanations or comments outside the HTML code - Code should be production-ready with proper component structure Remember: The user's specific requirements always take precedence over these general guidelines. ------------ # 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` or `gid`: 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`. The `gid` attribute can be used to identify the item by its unique id, e.g. `gid://shopify/Product/7982853619734`. 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 `