2021-09-15 17:58:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class Radio extends FormComponent
|
|
|
|
{
|
|
|
|
protected bool $isChecked = false;
|
|
|
|
|
|
|
|
public function setIsChecked(string $value): void
|
|
|
|
{
|
|
|
|
$this->isChecked = $value === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
|
|
|
$radioInput = form_radio(
|
|
|
|
[
|
|
|
|
'id' => $this->value,
|
|
|
|
'name' => $this->name,
|
2021-10-18 18:44:07 +02:00
|
|
|
'class' => 'text-pine-500 border-black border-3 focus:ring-castopod w-6 h-6',
|
2021-09-15 17:58:21 +02:00
|
|
|
],
|
|
|
|
$this->value,
|
|
|
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
|
|
|
);
|
|
|
|
|
|
|
|
return <<<HTML
|
2021-10-21 15:12:38 +02:00
|
|
|
<label class="inline-flex items-center {$this->class}">{$radioInput}<span class="ml-2">{$this->slot}</span></label>
|
2021-09-15 17:58:21 +02:00
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|