{# Variant Selector Components =========================== Product variant selection (size, color, etc.) for product detail pages. Usage: {% from 'shared/macros/storefront/variant-selector.html' import variant_selector, size_selector, color_swatches %} #} {# Variant Selector ================ Generic variant selector that adapts to variant type. Parameters: - variants_var: Alpine.js expression for variants array (default: 'product.variants') - selected_var: Alpine.js variable for selected variant (default: 'selectedVariant') - type: 'buttons' | 'dropdown' | 'swatches' (default: 'buttons') - label: Label text (default: 'Select Option') - show_stock: Show stock status per variant (default: true) - on_change: Custom change handler (default: none) Expected variant object: { id: 1, name: 'Large', value: 'L', stock: 10, price_modifier: 0, color_hex: '#FF0000', // For swatches image_url: '...' // For swatches with preview } Usage: {{ variant_selector(variants_var='product.sizes', label='Size') }} #} {% macro variant_selector( variants_var='product.variants', selected_var='selectedVariant', type='buttons', label='Select Option', show_stock=true, on_change=none ) %}
{# Label #}
{% if type == 'buttons' %} {{ _variant_buttons(variants_var, selected_var, show_stock, on_change) }} {% elif type == 'dropdown' %} {{ _variant_dropdown(variants_var, selected_var, show_stock, on_change) }} {% elif type == 'swatches' %} {{ _variant_swatches(variants_var, selected_var, show_stock, on_change) }} {% endif %}
{% endmacro %} {# Internal: Variant Buttons #} {% macro _variant_buttons(variants_var, selected_var, show_stock, on_change) %}
{% endmacro %} {# Internal: Variant Dropdown #} {% macro _variant_dropdown(variants_var, selected_var, show_stock, on_change) %} {% endmacro %} {# Internal: Variant Swatches (for colors) #} {% macro _variant_swatches(variants_var, selected_var, show_stock, on_change) %}
{% endmacro %} {# Size Selector ============= Specialized selector for clothing/shoe sizes. Parameters: - sizes_var: Alpine.js expression for sizes array - selected_var: Alpine.js variable for selected size - show_guide: Show size guide link (default: true) - guide_action: Action for size guide button (default: none) Usage: {{ size_selector(sizes_var='product.sizes', guide_action='showSizeGuide = true') }} #} {% macro size_selector( sizes_var='product.sizes', selected_var='selectedSize', show_guide=true, guide_action=none ) %}
{# Label with Size Guide #}
{% if show_guide %} {% endif %}
{# Size Buttons #}
{% endmacro %} {# Color Swatches ============== Specialized selector for color options with preview. Parameters: - colors_var: Alpine.js expression for colors array - selected_var: Alpine.js variable for selected color - size: 'sm' | 'md' | 'lg' (default: 'md') - on_change: Custom change handler (triggers image change, etc.) Expected color object: { id: 1, name: 'Red', value: 'red', color_hex: '#FF0000', stock: 10, image_url: '...' // Optional: product image for this color } Usage: {{ color_swatches(colors_var='product.colors', on_change='updateProductImage(selectedColor)') }} #} {% macro color_swatches( colors_var='product.colors', selected_var='selectedColor', size='md', on_change=none ) %} {% set sizes = { 'sm': {'swatch': 'w-8 h-8', 'icon': 'w-4 h-4'}, 'md': {'swatch': 'w-10 h-10', 'icon': 'w-5 h-5'}, 'lg': {'swatch': 'w-12 h-12', 'icon': 'w-6 h-6'} } %} {% set s = sizes[size] %}
{# Label #}
{# Color Swatches #}
{% endmacro %} {# Multi-Option Variant Selector ============================= Combined selector for products with multiple option types (size + color). Parameters: - product_var: Alpine.js expression for product - on_change: Callback when any variant changes Expected product structure: { options: [ { name: 'Size', values: [...] }, { name: 'Color', values: [...] } ], variants: [ { id: 1, options: { size: 'M', color: 'Red' }, stock: 10, price: 99.99 } ] } Usage: {{ multi_variant_selector(product_var='product') }} #} {% macro multi_variant_selector( product_var='product', on_change=none ) %}
{# Selected Variant Info #}
In Stock Out of Stock
{% endmacro %}