stack/src/components/fields/checkbox-field/checkbox-field.twig line 1

Open in your IDE?
  1. {%- set class_name = [
  2.   "f-checkbox",
  3.   "d-inline-flex align-items-center gap-2 u-posr",
  4.   props.type == "radio" ? "--radio" : "--checkbox",
  5.   props.disabled == true ? "--disabled" : null,
  6.   props.extra_class ? props.extra_class : null,
  7. ]|join(' ')|trim -%}
  8. {%- set attrs = [
  9.   'class="' ~ class_name ~ '"',
  10. ] -%}
  11. {%- set attrs = attrs|join(' ')|trim -%}
  12. {# Input attrs #}
  13. {%- set class_name_input = [
  14.   "f-checkbox__input",
  15.   "u-posa",
  16. ]|join(' ')|trim -%}
  17. {%- set attrs_input = [
  18.   'class="' ~ class_name_input ~ '"',
  19. ] -%}
  20. {% set type = props.type == "radio" ? "radio" : "checkbox" %}
  21. {%- set attrs_input = attrs_input|merge(['type="' ~ type ~ '"']) -%}
  22. {%- if props.id is defined %}
  23.   {%- set attrs_input = attrs_input|merge(['id="' ~ props.id ~ '"']) -%}
  24. {%- endif -%}
  25. {%- if props.required == true %}
  26.   {%- set attrs_input = attrs_input|merge(['required']) -%}
  27. {%- endif -%}
  28. {%- if props.value is defined %}
  29.   {%- set attrs_input = attrs_input|merge(['value="' ~ props.value ~ '"']) -%}
  30. {%- endif -%}
  31. {%- if props.checked == true %}
  32.   {% set attrs_input = attrs_input|merge(['checked="checked"']) %}
  33. {%- endif -%}
  34. {%- if props.disabled == true %}
  35.   {% set attrs_input = attrs_input|merge(['disabled']) %}
  36. {%- endif -%}
  37. {%- if props.name is defined %}
  38.   {% set attrs_input = attrs_input|merge(['name=' ~ props.name ~ '']) %}
  39. {%- endif -%}
  40. {%- if props.data is defined -%}
  41.   {%- set data_attrs = [] -%}
  42.   {%- for key, attribute in props.data -%}
  43.     {%- set data_attrs = data_attrs|merge(['data-' ~ key ~ '="' ~ attribute ~ '"']) -%}
  44.   {%- endfor -%}
  45.   {%- set data_attrs = data_attrs|join(' ')|trim -%}
  46.   {%- set attrs_input = attrs_input|merge([data_attrs]) -%}
  47. {%- endif -%}
  48. {%- set attrs_input = attrs_input|join(' ')|trim -%}
  49. <label {{ attrs|raw }}>
  50.   <input {{ attrs_input|raw }}>
  51.   <span class="f-checkbox__visual flex-shrink-0 d-flex align-items-center justify-content-center">
  52.     {% include "@Images/svg/check.svg" %}
  53.   </span>
  54.   <div class="f-checkbox__body d-flex flex-column">
  55.     <span class="f-checkbox__title u-color-primary u-fz-sm u-fw-600">
  56.       {% block content %}
  57.         {% if props.label %}
  58.           {{ props.label|raw }}
  59.         {% endif %}
  60.       {% endblock %}
  61.       {% if props.count %}
  62.         <span class="f-checkbox__count u-fw-400">({{ props.count }})</span>
  63.       {% endif %}
  64.     </span>
  65.     {% if props.description %}
  66.       <div class="f-checkbox__description u-fz-xs">{{ props.description|raw }}</div>
  67.     {% endif %}
  68.   </div>
  69.   {% include "@Components/fields/error-field/error-field.twig" with {props: {}} %}
  70. </label>