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
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected array $options = [];
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
protected string $selected;
|
|
|
|
|
|
|
|
public function setOptions(string $value): void
|
|
|
|
{
|
|
|
|
// dd(json_decode(html_entity_decode(html_entity_decode($value)), true));
|
|
|
|
$this->options = json_decode(html_entity_decode($value), true);
|
|
|
|
}
|
2021-08-19 14:00:14 +00:00
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
|
|
|
$defaultAttributes = [
|
2021-09-10 16:02:25 +00:00
|
|
|
'data-class' => 'border-3 rounded-lg ' . $this->class,
|
2021-08-19 14:00:14 +00:00
|
|
|
];
|
|
|
|
$extra = array_merge($defaultAttributes, $this->attributes);
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
return form_dropdown($this->name, $this->options, $this->selected !== '' ? [$this->selected] : [], $extra);
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|