2021-08-19 14:00:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
namespace App\Views\Components\Forms;
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
class Select extends FormComponent
|
2021-08-19 14:00:14 +00:00
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
protected array $props = ['options', 'selected'];
|
|
|
|
|
|
|
|
protected array $casts = [
|
|
|
|
'options' => 'array',
|
|
|
|
];
|
|
|
|
|
2021-08-19 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected array $options = [];
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
protected string $selected = '';
|
2021-09-10 16:02:25 +00:00
|
|
|
|
2021-08-19 14:00:14 +00:00
|
|
|
public function render(): string
|
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('w-full focus:border-contrast border-3 rounded-lg bg-elevated border-contrast');
|
2021-08-19 14:00:14 +00:00
|
|
|
$defaultAttributes = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'data-select-text' => lang('Common.forms.multiSelect.selectText'),
|
|
|
|
'data-loading-text' => lang('Common.forms.multiSelect.loadingText'),
|
2021-09-22 14:50:54 +00:00
|
|
|
'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'),
|
|
|
|
'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'),
|
2023-06-12 14:47:38 +00:00
|
|
|
'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'),
|
2021-08-19 14:00:14 +00:00
|
|
|
];
|
2024-05-09 17:55:41 +00:00
|
|
|
$extra = [...$defaultAttributes, ...$this->attributes];
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2021-09-20 15:45:38 +00:00
|
|
|
return form_dropdown($this->name, $this->options, old($this->name, $this->selected !== '' ? [$this->selected] : []), $extra);
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|