-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring back swatch-input snippet #3299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||
{% comment %} | ||||||||
Renders a swatch input component. | ||||||||
Accepts: | ||||||||
- id: {String} unique input id | ||||||||
- type: {String} input type. Accepts 'radio' or 'checkbox', defaults to 'radio' (optional) | ||||||||
- name: {String} input name, | ||||||||
- value: {ProductOptionValueDrop} input value | ||||||||
- swatch: {SwatchDrop} the swatch drop | ||||||||
- product_form_id: {String} id of the form associted with the input | ||||||||
- checked: {Boolean} default checked status | ||||||||
- disabled: {Boolean} default disabled status (optional) | ||||||||
- visually_disabled: {Boolean} style the swatch as disabled, but leave the input enabled (optional) | ||||||||
- shape: {String} swatch shape. Accepts 'square', defaults to circle (optional) | ||||||||
- help_text: {String} additional content to render inside the label (optional) | ||||||||
|
||||||||
Usage: | ||||||||
{% render 'swatch-input', | ||||||||
id: input_id, | ||||||||
name: input_name, | ||||||||
value: input_value, | ||||||||
swatch: swatch, | ||||||||
product_form_id: product_form_id, | ||||||||
checked: checked | ||||||||
%} | ||||||||
{% endcomment %} | ||||||||
|
||||||||
<input | ||||||||
type="{{ type | default: 'radio' }}" | ||||||||
id="{{ id }}" | ||||||||
name="{{ name }}" | ||||||||
value="{{ value }}" | ||||||||
form="{{ product_form_id }}" | ||||||||
class="swatch-input__input{% if visually_disabled %} visually-disabled{% endif %}" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because dawn/assets/component-product-variant-picker.css Lines 37 to 39 in 76152c5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - updated |
||||||||
{% if checked %} | ||||||||
checked | ||||||||
{% endif %} | ||||||||
{% if disabled %} | ||||||||
disabled | ||||||||
{% endif %} | ||||||||
> | ||||||||
<label | ||||||||
for="{{ id }}" | ||||||||
title="{{ value }}" | ||||||||
class="swatch-input__label{% if shape == 'square' %} swatch-input__label--square{% endif %}" | ||||||||
> | ||||||||
{% render 'swatch', swatch: swatch, shape: shape %} | ||||||||
{{ help_text }} | ||||||||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? Liquid is ruby, I would expect
nil
to be the correct empty state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and is what is configured for the Shopify Liquid plugin. It automatically changes those for me. I asked @charlespwd about this and he linked me to this bit of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a video of the formatter automatically changing
nil
tonull
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jas7457 you have unlocked secret Shopify knowledge. Mind cutting an update the the Dev docs that records
null
as a falsy value? 🙏🏻 https://shopify.dev/docs/api/liquid/basics#truthy-and-falsy