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

Open in your IDE?
  1. {%- set class_name = [
  2.   "f-text",
  3.   "d-flex flex-column gap-1 u-posr",
  4.   props.extra_class ? props.extra_class : null,
  5.   props.icon_before ? "--icon-before" : null,
  6.   props.icon_after ? "--icon-after" : null,
  7.   props.type == "password" ? "--password" : null,
  8. ]|join(' ')|trim -%}
  9. {%- set attrs = [
  10.   'class="' ~ class_name ~ '"',
  11. ] -%}
  12. {%- set attrs = attrs|join(' ')|trim -%}
  13. {# Input attrs #}
  14. {%- set class_name_input = [
  15.   "f-base",
  16.   "f-text__input",
  17. ]|join(' ')|trim -%}
  18. {%- set attrs_input = [
  19.   'class="' ~ class_name_input ~ '"',
  20. ] -%}
  21. {%- set input_type = props.type in ["email", "password", "url", "text", "tel", "search", "number"] ? props.type : "text" -%}
  22. {%- set attrs_input = attrs_input|merge(['type="' ~ input_type ~ '"']) -%}
  23. {%- if props.id is defined %}
  24.   {%- set attrs_input = attrs_input|merge(['id="' ~ props.id ~ '"']) -%}
  25. {%- endif -%}
  26. {%- if props.placeholder %}
  27.   {%- set attrs_input = attrs_input|merge(['placeholder="' ~ props.placeholder ~ '"']) -%}
  28. {%- endif -%}
  29. {%- if props.value is defined %}
  30.   {%- set attrs_input = attrs_input|merge(['value="' ~ props.value ~ '"']) -%}
  31. {%- endif -%}
  32. {%- if props.full_name is defined %}
  33.   {% set attrs_input = attrs_input|merge(['name=' ~ props.full_name ~ '']) %}
  34. {%- endif -%}
  35. {%- if props.maxlength is defined %}
  36.   {%- set attrs_input = attrs_input|merge(['maxlength="' ~ props.maxlength ~ '"']) -%}
  37. {%- endif -%}
  38. {% if props.pattern is defined %}
  39.   {%- set attrs_input = attrs_input|merge(['pattern="' ~ props.pattern ~ '"']) -%}
  40. {% endif %}
  41. {% if props.validity.pattern_mismatch %}
  42.   {%- set attrs_input = attrs_input|merge(['data-validity-pattern-mismatch="' ~ props.validity.pattern_mismatch ~ '"']) -%}
  43. {% endif %}
  44. {% if props.validity.value_missing %}
  45.   {%- set attrs_input = attrs_input|merge(['data-validity-value-missing="' ~ props.validity.value_missing ~ '"']) -%}
  46. {% endif %}
  47. {% if props.step and input_type == 'number' %}
  48.   {%- set attrs_input = attrs_input|merge(['step="' ~ props.step ~ '"']) -%}
  49. {% endif %}
  50. {%- if props.required == true %}
  51.   {%- set attrs_input = attrs_input|merge(['required']) -%}
  52. {%- endif -%}
  53. {%- if props.disabled == true %}
  54.   {%- set attrs_input = attrs_input|merge(['disabled']) -%}
  55. {%- endif -%}
  56. {%- if props.readonly == true %}
  57.   {%- set attrs_input = attrs_input|merge(['readonly']) -%}
  58. {%- endif -%}
  59. {%- if props.autocomplete is defined %}
  60.   {%- set attrs_input = attrs_input|merge(['autocomplete="' ~ (props.autocomplete == true ? 'on' : 'off') ~ '"']) -%}
  61. {%- endif -%}
  62. {%- set attrs_input = attrs_input|join(' ')|trim -%}
  63. <div {{ attrs|raw }}>
  64.   {% if props.label %}
  65.     {% include "@Components/fields/label-field/label-field.twig" with {props: {
  66.       title: props.label,
  67.       id: props.id,
  68.       required: props.required,
  69.     }} %}
  70.   {% endif %}
  71.   <div class="f-text__wrap d-flex align-items-center u-posr">
  72.     {% if props.icon_before %}
  73.       <span class="f-text__icon --before">
  74.         {% include "@Components/icon/icon.twig" with {props: {
  75.           src: props.icon_before.src,
  76.           color: props.icon_before.color,
  77.         }} %}
  78.       </span>
  79.     {% endif %}
  80.     <input {{ attrs_input|raw }}>
  81.     {% if input_type != "password" and props.icon_after %}
  82.       <span class="f-text__icon --after">
  83.         {% include "@Components/icon/icon.twig" with {props: {
  84.           src: props.icon_after.src,
  85.           color: props.icon_after.color,
  86.         }} %}
  87.       </span>
  88.     {% endif %}
  89.     {% if input_type == "password" %}
  90.       <div class="f-text__toggle u-posa u-translate-middle-y u-top-50-p justify-content-center align-center d-grid u-cursor-pointer">
  91.         {% include "@Components/icon/icon.twig" with {props: {
  92.           src: "@Images/svg/eye-outline.svg",
  93.           extra_class: "f-text__toggle-icon --on",
  94.         }} %}
  95.         {% include "@Components/icon/icon.twig" with {props: {
  96.           src: "@Images/svg/eye-off-outline.svg",
  97.           extra_class: "f-text__toggle-icon --off",
  98.         }} %}
  99.       </div>
  100.     {% endif %}
  101.   </div>
  102.   {% include "@Components/fields/error-field/error-field.twig" with {props: {}} %}
  103. </div>