File size: 3,177 Bytes
5f32fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@aware(['icon', 'action', 'size', 'error', 'stepper'])
@props([
    'icon' => null,
    'action' => null,
    'stepper' => null,
    'error' => null,
    'size' => 'md',
    'addNew' => false,
    'name' => null,
])

@if($addNew)
    <div x-data="{ 'newOptions': [] }">
        @endif

        <select {{ $attributes->class([
                        'form-select',
                        'form-input-stepper' => $stepper
                    ]) }}
                :id="$id('text-input')"
                @if($error)
                    aria-invalid="true" autofocus x-bind:aria-describedby="@if ($id ?? '') {{ $id }}-error @else $id('text-input') + '-error' @endif"
                @endif
        >
            {{ $slot ?? '' }}

            @if ($addNew)
                <template
                        x-for="option in newOptions"
                        :key="option"
                >
                    <option
                            x-text="option"
                            x-bind:value="option"
                    ></option>
                </template>
            @endif
        </select>

        @if ($attributes->has('multiple'))
            <small class="mt-1 block">
                {{ __('Hold cmd(on mac) or ctrl(on pc) to select multiple items.') }}
            </small>
        @endif

        @if ($addNew)
            @php
                $newId = str()->random(10);
            @endphp
            <x-modal
                    class:modal-backdrop="backdrop-blur-sm bg-foreground/15"
                    title="{{ __('New value') }}"
            >
                <x-slot:trigger
                        class="mt-3"
                        variant="primary"
                >
                    <x-tabler-plus
                            class="size-3"
                            stroke-width="3"
                    />
                    {{ __('Add New') }}
                </x-slot:trigger>

                <x-slot:modal x-data>
                    <x-form.text
                            id="new_{{ $newId }}"
                            @keyup.enter="$refs.submitBtn.click(); modalOpen = false"
                            name="new_{{ $name }}"
                            size="lg"
                            x-ref="new_{{ $newId }}"
                    />
                    <div class="mt-4 border-t pt-3">
                        <x-button
                                @click.prevent="modalOpen = false"
                                variant="outline"
                        >
                            {{ __('Cancel') }}
                        </x-button>
                        <x-button
                                tag="button"
                                variant="primary"
                                x-ref="submitBtn"
                                @click="newOptions.push($refs.new_{{ $newId }}.value); $refs.new_{{ $newId }}.value = ''; modalOpen = false;"
                        >
                            {{ __('Add') }}
                        </x-button>
                    </div>
                </x-slot:modal>
            </x-modal>
        @endif
        @if($addNew)
    </div>
@endif