mirror of https://github.com/kcal-app/kcal.git
Add support for optgroups in select lists
This commit is contained in:
parent
ab10dd0342
commit
3bc346848c
|
@ -8,17 +8,17 @@ use Illuminate\View\Component;
|
||||||
|
|
||||||
class Select extends Component
|
class Select extends Component
|
||||||
{
|
{
|
||||||
public Collection $options;
|
public Collection|array $options;
|
||||||
public ?string $selectedValue;
|
public ?string $selectedValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select constructor.
|
* Select constructor.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Support\Collection $options
|
* @param \Illuminate\Support\Collection|array $options
|
||||||
* @param ?string $selectedValue
|
* @param ?string $selectedValue
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Collection $options,
|
Collection|array $options,
|
||||||
?string $selectedValue = '',
|
?string $selectedValue = '',
|
||||||
) {
|
) {
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
@foreach ($options as $option)
|
||||||
|
@if(is_iterable($option['value']))
|
||||||
|
<optgroup label="{{ $option['label'] }}">
|
||||||
|
<x-inputs.select-options :options="$option['value']"
|
||||||
|
:selectedValue="$selectedValue" />
|
||||||
|
</optgroup>
|
||||||
|
@else
|
||||||
|
<option value="{{ $option['value'] }}"
|
||||||
|
@if ($option['value'] == $selectedValue) selected @endif>
|
||||||
|
{{ $option['label'] }}
|
||||||
|
</option>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
|
@ -1,9 +1,4 @@
|
||||||
<select {{ $attributes->merge(['class' => 'rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50']) }}>
|
<select {{ $attributes->merge(['class' => 'rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50']) }}>
|
||||||
{{ $slot }}
|
{{ $slot }}
|
||||||
@foreach ($options as $option)
|
<x-inputs.select-options :options="$options" :selectedValue="$selectedValue" />
|
||||||
<option value="{{ $option['value'] }}"
|
|
||||||
@if ($option['value'] == $selectedValue) selected @endif>
|
|
||||||
{{ $option['label'] }}
|
|
||||||
</option>
|
|
||||||
@endforeach
|
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue