From c0ca2361c2d15ebc68fb3de432e2c605ce00059e Mon Sep 17 00:00:00 2001 From: Jason Addleman Date: Mon, 26 Feb 2024 18:58:51 +0000 Subject: [PATCH] Bring back swatch-input snippet Additional changes Update styles PR fix Bring back disabled, just in case --- assets/component-product-variant-picker.css | 4 +- assets/component-swatch-input.css | 8 ++-- snippets/product-variant-options.liquid | 43 ++++++++---------- snippets/swatch-input.liquid | 48 +++++++++++++++++++++ 4 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 snippets/swatch-input.liquid diff --git a/assets/component-product-variant-picker.css b/assets/component-product-variant-picker.css index f62ef38157f..71cb55a6130 100644 --- a/assets/component-product-variant-picker.css +++ b/assets/component-product-variant-picker.css @@ -34,7 +34,7 @@ variant-selects { width: 1px; } -.product-form__input input[type='radio']:not(.disabled) + label > .label-unavailable { +.product-form__input input[type='radio']:not(.disabled):not(.visually-disabled) + label > .label-unavailable { display: none; } @@ -43,7 +43,6 @@ variant-selects { margin-bottom: 1.6rem; } - .product-form__input--dropdown .dropdown-swatch + select { padding-left: calc(2.4rem + var(--swatch-input--size)); } @@ -57,7 +56,6 @@ variant-selects { z-index: 1; } - /* Custom styles for Pill display type */ .product-form__input--pill input[type='radio'] + label { border: var(--variant-pills-border-width) solid rgba(var(--color-foreground), var(--variant-pills-border-opacity)); diff --git a/assets/component-swatch-input.css b/assets/component-swatch-input.css index 61a42b7277c..149c51f6746 100644 --- a/assets/component-swatch-input.css +++ b/assets/component-swatch-input.css @@ -24,7 +24,7 @@ } /* Visually disabled */ -.swatch-input__input.disabled:not(:active):not(:checked) + .swatch-input__label:hover { +.swatch-input__input.visually-disabled:not(:active):not(:checked) + .swatch-input__label:hover { outline: none; } @@ -35,14 +35,14 @@ /* Overrides for swatch snippet when used inside disabled swatch-input */ .swatch-input__input:disabled + .swatch-input__label > .swatch, -.swatch-input__input.disabled + .swatch-input__label > .swatch { +.swatch-input__input.visually-disabled + .swatch-input__label > .swatch { position: relative; overflow: hidden; } /* Display white semi-transparent overlay over swatch when input is disabled */ .swatch-input__input:disabled + .swatch-input__label > .swatch::before, -.swatch-input__input.disabled + .swatch-input__label > .swatch::before { +.swatch-input__input.visually-disabled + .swatch-input__label > .swatch::before { content: ''; position: absolute; inset: 0; @@ -51,7 +51,7 @@ /* Display crossed out line over swatch when input is disabled */ .swatch-input__input:disabled + .swatch-input__label > .swatch::after, -.swatch-input__input.disabled + .swatch-input__label > .swatch::after { +.swatch-input__input.visually-disabled + .swatch-input__label > .swatch::after { /* Diagonal of a square = length of the side * sqrt(2) */ --diagonal--size: calc(var(--swatch-input--size) * 1.414); --crossed-line--size: 0.1rem; diff --git a/snippets/product-variant-options.liquid b/snippets/product-variant-options.liquid index 453a4a386cc..d3dbaaa7eca 100644 --- a/snippets/product-variant-options.liquid +++ b/snippets/product-variant-options.liquid @@ -52,7 +52,7 @@ elsif value.swatch.color assign swatch_value = 'rgb(' | append: value.swatch.color.rgb | append: ')' else - assign swatch_value = nil + assign swatch_value = null endif -%} @@ -60,42 +60,35 @@ {{ section.id }}-{{ option.position }}-{{ forloop.index0 -}} {%- endcapture -%} - {%- capture label_unavailable %} + {%- capture label_unavailable -%} {{- 'products.product.variant_sold_out_or_unavailable' | t -}} - {%- endcapture %} + {%- endcapture -%} {%- if picker_type == 'swatch' -%} {% liquid assign checked = false - if option.selected_value == value assign checked = true endif - - assign value_text = value | escape %} - - + {%- endcapture -%} + {% + render 'swatch-input', + id: input_id, + name: option.name, + value: value | escape, + swatch: value.swatch, + product_form_id: product_form_id, + checked: checked, + visually_disabled: option_disabled, + shape: block.settings.swatch_shape, + help_text: help_text + %} {%- elsif picker_type == 'button' -%} +