Select

<div class="flex flex-col items-start gap-8 w-full max-w-md">
    <div class="flex flex-col w-full gap-y-1 field field-reserved">
        <div x-data="selectselect" class="input-wrapper input-wrapper-select flex flex-col relative w-full floating-label ">

            <button type="button" @click="openSelect" x-ref="selectButton" class="form-select w-full peer flex justify-between btn gap-x-2 
                required
                
                " :class="selected ? 'option-selected' : ''">
                <span class="flex flex-row items-center gap-2">
                    <template x-if="selected && selected.type === 'leading-icon'">
                        <img :src="selected.image" :alt="selected.name">
                    </template>
                    <span x-text="selected ? selected.name : 'Séléctionnez...'">
                        Séléctionnez...
                    </span>
                </span>
                <span class="transition-all transform flex items-center" :class="{'rotate-180' : show}">
                    <svg class=" shrink-0" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" fill="currentColor" />

                    </svg> </span>
            </button>

            <div class="label-wrapper ">
                <label for="select" class="flex flex-row items-center gap-2">
                    <div class="left-svg">
                        <svg class=" shrink-0" width="16" height="16" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
                            <path d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" stroke="currentColor" stroke-width="1.5" fill="none" />

                        </svg>
                    </div>

                    <span class="flex-grow">label</span>

                    <div class="required text-error">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
                            <path d="M8.48605 7.23022L8.81938 7.03777L11.8608 5.28179C12.0734 5.15906 12.3452 5.23189 12.468 5.44446C12.5907 5.65704 12.5179 5.92886 12.3053 6.05159L9.26383 7.80757L8.9305 8.00002L9.26383 8.19247L12.3053 9.94845C12.5179 10.0712 12.5907 10.343 12.468 10.5556C12.3452 10.7681 12.0734 10.841 11.8608 10.7183L8.81938 8.96226L8.48605 8.76981V9.15471V12.6667C8.48605 12.9121 8.28706 13.1111 8.0416 13.1111C7.79614 13.1111 7.59716 12.9121 7.59716 12.6667V9.15472V8.76982L7.26382 8.96227L4.22237 10.7183L4.32568 10.8972L4.22237 10.7183C4.0098 10.841 3.73798 10.7681 3.61525 10.5556C3.49252 10.343 3.56536 10.0712 3.77793 9.94845L6.81938 8.19247L7.15272 8.00002L6.81938 7.80757L3.77794 6.05159L3.66964 6.23916L3.77794 6.05159C3.56536 5.92886 3.49253 5.65704 3.61526 5.44446C3.73799 5.23189 4.0098 5.15906 4.22238 5.28179L7.26382 7.03776L7.59716 7.23021V6.84531V3.33335C7.59716 3.08789 7.79614 2.88891 8.0416 2.88891C8.28706 2.88891 8.48605 3.08789 8.48605 3.33335V6.84532V7.23022Z" fill="currentColor" stroke="currentColor" stroke-width="0.444444" />
                        </svg>
                    </div>
                </label>
            </div>

            <div class="dropdown-content relative w-full overflow-auto max-h-screen-40" x-show="show" x-transition x-cloak @click.outside="show = false" x-anchor.bottom-start.offset.0="$refs.selectButton">
                <template x-for="option in options">
                    <div>
                        <template x-if="option.type === 'group'">
                            <div class="item-category text-brand-700 font-bold">
                                <div class="dropdown-item-category p-2">
                                    <span class="flex-1" x-text="option.name"></span>
                                </div>
                            </div>
                        </template>

                        <template x-if="option.type !== 'group'">
                            <div @click="select(option.id)" :class="option.checked ? 'selected' : ''">

                                <template x-if="option.href">
                                    <div>
                                        <a :href="option.href" class="dropdown-item cursor-pointer p-2">
                                            <template x-if="option.image">
                                                <img :src="option.image" :alt="option.name">
                                            </template>

                                            <span class="flex-1" x-text="option.name"></span>
                                            <template x-if="option.checked">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                                                    <path d="M21 2H3C2.4 2 2 2.4 2 3V21C2 21.6 2.4 22 3 22H21C21.6 22 22 21.6 22 21V3C22 2.4 21.6 2 21 2ZM17.7 9.3L10.9 16.1C10.5 16.5 9.9 16.5 9.5 16.1L6.3 12.9C5.9 12.5 5.9 11.9 6.3 11.5C6.7 11.1 7.3 11.1 7.7 11.5L10.2 14L16.3 7.9C16.7 7.5 17.3 7.5 17.7 7.9C18.1 8.3 18.1 8.9 17.7 9.3Z" fill="#34A5C3" />
                                                </svg>
                                            </template>
                                        </a>
                                    </div>
                                </template>

                                <template x-if="!option.href">
                                    <div class="dropdown-item cursor-pointer p-2">
                                        <template x-if="option.image">
                                            <img :src="option.image" :alt="option.name">
                                        </template>

                                        <span class="flex-1" x-text="option.name"></span>
                                        <template x-if="option.checked">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                                                <path d="M21 2H3C2.4 2 2 2.4 2 3V21C2 21.6 2.4 22 3 22H21C21.6 22 22 21.6 22 21V3C22 2.4 21.6 2 21 2ZM17.7 9.3L10.9 16.1C10.5 16.5 9.9 16.5 9.5 16.1L6.3 12.9C5.9 12.5 5.9 11.9 6.3 11.5C6.7 11.1 7.3 11.1 7.7 11.5L10.2 14L16.3 7.9C16.7 7.5 17.3 7.5 17.7 7.9C18.1 8.3 18.1 8.9 17.7 9.3Z" fill="#34A5C3" />
                                            </svg>
                                        </template>
                                    </div>
                                </template>
                            </div>
                        </template>
                    </div>
                </template>
            </div>
            <select class="sr-only required" id="select" required name="select" id="select">
                <option value="" selected disabled hidden></option>
                <option value="fr">France</option>
                <option value="it">Italie</option>
                <option value="de">Allemagne</option>
            </select>
        </div>
    </div>

    <script>
        function selectselect() {
            return {
                rawOptions: [{
                    "value": "fr",
                    "text": "France"
                }, {
                    "value": "it",
                    "text": "Italie"
                }, {
                    "value": "de",
                    "text": "Allemagne"
                }],
                options: [],
                show: false,
                selected: null,
                init() {
                    Array.from(this.rawOptions).forEach(option => {
                        if (!option.disabled) {
                            this.options.push({
                                id: option.value,
                                name: option.text,
                                checked: option.selected,
                                image: option.image,
                                href: option.href,
                                type: option.type,
                            })
                        }
                        if (option.selected && option.value) {
                            this.select(option.value);
                        }
                    });
                },
                openSelect() {
                    this.show = !this.show;
                },
                select(id) {
                    this.options = this.options.map(option => {
                        if (option.id === id) {
                            option.checked = true;
                            this.selected = option;
                        } else {
                            option.checked = false;
                        }
                        return option;
                    });
                    document.getElementById('select').value = this.selected.id;
                    this.show = false;
                }
            }
        }
    </script>
</div>
<div class="flex flex-col items-start gap-8 w-full max-w-md">
    {% include "@template-select" with select %}
</div>
{
  "select": {
    "id": "select",
    "name": "select",
    "label": "label",
    "label_icon_left": {
      "name": "heroicons--user-outline"
    },
    "label_floating": true,
    "required": true,
    "disabled": false,
    "placeholder": "Séléctionnez...",
    "options": [
      {
        "value": "fr",
        "text": "France"
      },
      {
        "value": "it",
        "text": "Italie"
      },
      {
        "value": "de",
        "text": "Allemagne"
      }
    ],
    "selectId": "select"
  }
}

No notes defined.