60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?php
 | |
| 
 | |
| namespace App\View\Form;
 | |
| 
 | |
| use App\View\Traits\HasFormDimensions;
 | |
| use Illuminate\View\Component;
 | |
| 
 | |
| class Select extends Component
 | |
| {
 | |
| 
 | |
|     use HasFormDimensions;
 | |
| 
 | |
|     public string $id;
 | |
| 
 | |
|     public function __construct(
 | |
|         public string $name,
 | |
|         public string $size = 'default',
 | |
|         public ?string $hint = null,
 | |
|         public bool $required = false,
 | |
|         public string $label = '',
 | |
|         public $options = [],
 | |
|         public bool $disabled = false,
 | |
|     ) {
 | |
|         $this->id = str()->uuid()->toString();
 | |
|     }
 | |
| 
 | |
|     public function render()
 | |
|     {
 | |
|         return <<<'HTML'
 | |
|             <label class="flex flex-col group {{$heightClass}}" for="{{$id}}" style="{{$heightVars}}">
 | |
|                 @if ($label)
 | |
|                 <x-form::label :required="$required">{{$label}}</x-form::label>
 | |
|                 @endif
 | |
| 
 | |
|                 <div class="relative flex-none flex">
 | |
|                     <select {{$attributes}} @if($disabled) disabled @endif name="{{$name}}" id="{{$id}}"
 | |
|                         class="
 | |
|                             w-full h-[var(--height)] border-gray-600 border-solid text-gray-300 bg-gray-700 leading-none rounded-lg
 | |
|                             group-[.size-default]:border-2 group-[.size-sm]:border
 | |
|                             group-[.size-default]:text-sm group-[.size-sm]:text-xs
 | |
|                             group-[.size-default]:px-2 group-[.size-sm]:px-1
 | |
|                             py-0
 | |
|                         "
 | |
|                     >
 | |
|                         <option value="">-- kein --</option>
 | |
|                         @foreach ($options as $option)
 | |
|                         <option value="{{$option['id']}}">{{ $option['name'] }}</option>
 | |
|                         @endforeach
 | |
|                     </select>
 | |
|                     <x-ui::errors :for="$name" />
 | |
|                     @if($hint)
 | |
|                     <x-form::hint class="right-6">{{$hint}}</x-form::hint>
 | |
|                     @endif
 | |
|                 </div>
 | |
| 
 | |
|             </label>
 | |
|         HTML;
 | |
|     }
 | |
| }
 |