2021-09-10 16:02:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class RadioButton extends FormComponent
|
|
|
|
{
|
|
|
|
protected bool $isChecked = false;
|
|
|
|
|
2021-12-24 17:55:56 +00:00
|
|
|
protected ?string $hint = null;
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
public function setIsChecked(string $value): void
|
|
|
|
{
|
|
|
|
$this->isChecked = $value === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2022-01-02 14:11:05 +00:00
|
|
|
$data = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => $this->value,
|
|
|
|
'name' => $this->name,
|
2022-01-02 14:11:05 +00:00
|
|
|
'class' => 'form-radio-btn bg-elevated',
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->required) {
|
|
|
|
$data['required'] = 'required';
|
|
|
|
}
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
$radioInput = form_radio(
|
2022-01-02 14:11:05 +00:00
|
|
|
$data,
|
2021-09-10 16:02:25 +00:00
|
|
|
$this->value,
|
|
|
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
|
|
|
);
|
|
|
|
|
2021-12-24 17:55:56 +00:00
|
|
|
$hint = $this->hint ? hint_tooltip($this->hint, 'ml-1 text-base') : '';
|
|
|
|
|
2021-09-10 16:02:25 +00:00
|
|
|
return <<<HTML
|
2022-01-02 14:11:05 +00:00
|
|
|
<div class="{$this->class}">
|
2021-09-10 16:02:25 +00:00
|
|
|
{$radioInput}
|
2021-12-24 17:55:56 +00:00
|
|
|
<label for="{$this->value}">{$this->slot}{$hint}</label>
|
2021-09-10 16:02:25 +00:00
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|