{#
component: input
#}
{% set props = {
type: 'text',
label: null,
placeholder: null,
pattern:null,
name: null,
id: null,
ref:null,
autocomplete: null,
min: null,
max: null,
value: null,
checked: false,
required: false,
selected:null,
max_chars:null
}|merge(props|default({})) %}
{# Add * after label if required #}
{% set label = props.label %}
{% if props.required and props.label %}
{% set label = label ~ '*' %}
{% endif %}
{# #}
{# Construct attributes #}
{# #}
{% set attributes = 'ref=input name='~props.name %}
{# Placeholder attribute #}
{% if props.placeholder %}
{% set attributes = attributes ~ ' placeholder="' ~ props.placeholder ~ '"' %}
{% endif %}
{# required attribute #}
{% if props.required %}
{% set attributes = attributes ~ ' required' %}
{% endif %}
{# checked attribute #}
{% if props.checked %}
{% set attributes = attributes ~ ' checked' %}
{% endif %}
{# value attribute #}
{% if props.value %}
{% set attributes = attributes ~ ' value="' ~ props.value ~ '"' %}
{% endif %}
{# ref attribute #}
{% if props.pattern %}
{% set attributes = attributes ~ ' pattern="' ~ props.pattern ~ '"' %}
{% endif %}
{# autocomplete attribute #}
{% if props.autocomplete %}
{% set attributes = attributes ~ ' autocomplete="' ~ props.autocomplete ~ '"' %}
{% endif %}
{# min attribute #}
{% if props.min %}
{% set attributes = attributes ~ ' min="' ~ props.min ~ '"' %}
{% endif %}
{# max attribute #}
{% if props.max %}
{% set attributes = attributes ~ ' max="' ~ props.max ~ '"' %}
{% endif %}
{# tel pattern #}
{# Construct classes #}
{% set classes = ['type' ~ props.type] %}
{# Required #}
{% if props.required %}
{% set classes = classes|merge(['is-required']) %}
{% endif %}
<div
data-component="input" data-type="{{ props.type }}" class="Input-component {{ classes|join(' ') }}"> {# Label #}
<label class="Input-label" for="{{ props.id }}" ref="label">{{ label|raw }}</label>
{# Textarea #}
{% if props.type == 'textarea' %}
<textarea {{ attributes | raw }} id="{{ props.id }}" class="InputForm Input-textarea">{{ props.value }}</textarea>
{% if props.max_chars %}
<p class="Input-textarea-limit">
<span ref="counter">0</span>
/
<span ref="limit">
{{ props.max_chars }}</span>
</p>
{% endif %}
{# Commons inputs #}
{% elseif props.type == 'text' or props.type == 'email' or props.type == 'tel' or props.type == "number" or props.type == "password" %}
<input {{ attributes | raw }} id="{{ props.id }}" type="{{ props.type }}" class="InputForm Input-input">
{% if props.type == 'password' %}
<div class="Input-passwordSee" ref="seeBtn">
{% include "component/svg.html.twig" with {
props: {
name: 'view'
}
} %}
</div>
<div class="Input-passwordHide" ref="hideBtn">
{% include "component/svg.html.twig" with {
props: {
name: 'edit'
}
} %}
</div>
{% endif %}
{# Date input #}
{% elseif props.type == 'date' %}
<div class="BaseInput-date">
<datepicker {{ attributes|raw }} :language="datePickerLang" data-lang="fr"></datepicker>
</div>
<span class="DateIcon">
{% include "component/svg.html.twig" with {
props: {
name: 'calendar'
}
} %}
</span>
{# checkbox #}
{% elseif props.type == 'checkbox' %}
<div class="BaseInput-checkbox">
<div class="BaseInput-checkboxCheck"></div>
<input {{ attributes|raw }} id="{{ props.id }}" type="checkbox">
</div>
{# Radio #}
{% elseif props.type == 'radio' %}
<div class="BaseInput-radio">
<div class="BaseInput-radioCheck"></div>
<input {{ attributes|raw }} id="{{ props.id }}" type="radio">
</div>
{# Select #}
{% elseif props.type == 'select' %}
<div class="BaseInput-select">
<v-select ref="input" id="{{ props.id }}" data-selected="{{ props.selected|json_encode() }}" :options="options" data-options="{{ props.options|json_encode() }}" v-model="selected" :searchable="false" :clearable="false" @input="onChange">
{% verbatim %}
<template #selected-option="{ label }">
<span class="vs__selected-optionsLabel" v-html="label"/>
</template>
<template #search="{attributes, events}">
<input class="vs__search" :required="!selected" v-bind="attributes" v-on="events"/>
</template>
{% endverbatim %}
</v-select>
<input name='{{props.name}}' type="hidden">
</div>
<span class="SelectIcon">
{% include "component/svg.html.twig" with {
props: {
name: 'arrow-down'
}
} %}
</span>
{# File #}
{% elseif props.type == 'file' %}
<div class="BaseInput-file u-alignVerticalCenter">
<input {{ attributes|raw }} id="input_file" type="file" accept=".doc,.docx,.jpg,.jpeg,.png,.pdf">
{% include 'component/base_icon.html.twig' with {
props: {
name: 'upload'
}
} %}
<div class="BaseInput-fileValue u-alignVerticalCenter u-cDark" ref="labelValue"></div>
<div class="BaseInput-placeholder u-alignVerticalCenter" ref="labelPlaceholder">
<div class="BaseInput-fileLabel">Choisissez votre fichier</div>
<div class="BaseInput-fileSpec">DOC, PDF, JPG . Taille max : 2mo</div>
<span></span>
</div>
<label for="input_file" class="BaseInput-fileFakeLabel"/>
</div>
{% endif %}
</div>