2021-11-08 17:52:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class ColorRadioButton extends FormComponent
|
|
|
|
{
|
|
|
|
protected bool $isChecked = false;
|
|
|
|
|
2021-12-08 18:05:34 +01:00
|
|
|
protected string $style = '';
|
|
|
|
|
2021-11-08 17:52:20 +01:00
|
|
|
public function setIsChecked(string $value): void
|
|
|
|
{
|
|
|
|
$this->isChecked = $value === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2022-01-02 15:11:05 +01:00
|
|
|
$data = [
|
|
|
|
'id' => $this->value,
|
|
|
|
'name' => $this->name,
|
|
|
|
'class' => 'color-radio-btn',
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->required) {
|
|
|
|
$data['required'] = 'required';
|
|
|
|
}
|
|
|
|
|
2021-11-08 17:52:20 +01:00
|
|
|
$radioInput = form_radio(
|
2022-01-02 15:11:05 +01:00
|
|
|
$data,
|
2021-11-08 17:52:20 +01:00
|
|
|
$this->value,
|
|
|
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
|
|
|
);
|
|
|
|
|
|
|
|
return <<<HTML
|
2021-12-08 18:05:34 +01:00
|
|
|
<div class="{$this->class}" style="{$this->style}">
|
2021-11-08 17:52:20 +01:00
|
|
|
{$radioInput}
|
|
|
|
<label for="{$this->value}" title="{$this->slot}" data-tooltip="bottom"></label>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|