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-15 15:58:21 +00:00
|
|
|
class MultiSelect 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',
|
|
|
|
'selected' => 'array',
|
|
|
|
];
|
|
|
|
|
2021-08-19 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected array $options = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected array $selected = [];
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('w-full bg-elevated border-3 border-contrast rounded-lg');
|
|
|
|
|
2021-08-19 14:00:14 +00:00
|
|
|
$defaultAttributes = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'data-class' => $this->attributes['class'],
|
|
|
|
'multiple' => 'multiple',
|
|
|
|
'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-15 15:58:21 +00:00
|
|
|
return form_dropdown($this->name, $this->options, $this->selected, $extra);
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|