forked from Shopify/dawn
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathswatch-input.liquid
52 lines (50 loc) · 1.62 KB
/
swatch-input.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{% 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)
- additional_props: {String} (optional) additional properties to attach to the input
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 %}"
{% if checked %}
checked
{% endif %}
{% if disabled %}
disabled
{% endif %}
{% if additional_props %}
{{ additional_props }}
{% 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>