2021-09-15 15:58:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
use Override;
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
class Radio extends FormComponent
|
|
|
|
{
|
2024-05-09 17:55:41 +00:00
|
|
|
protected array $props = ['isChecked'];
|
2021-09-15 15:58:21 +00:00
|
|
|
|
2024-05-09 17:55:41 +00:00
|
|
|
protected array $casts = [
|
|
|
|
'isChecked' => 'boolean',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected bool $isChecked = false;
|
2021-09-15 15:58:21 +00:00
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-09-15 15:58:21 +00:00
|
|
|
public function render(): string
|
|
|
|
{
|
|
|
|
$radioInput = form_radio(
|
|
|
|
[
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => $this->value,
|
|
|
|
'name' => $this->name,
|
2024-05-09 17:55:41 +00:00
|
|
|
'class' => 'text-accent-base bg-elevated border-contrast border-3 w-6 h-6',
|
2021-09-15 15:58:21 +00:00
|
|
|
],
|
|
|
|
$this->value,
|
|
|
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
|
|
|
);
|
|
|
|
|
2024-05-09 17:55:41 +00:00
|
|
|
$this->mergeClass('inline-flex items-center');
|
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
return <<<HTML
|
2024-05-09 17:55:41 +00:00
|
|
|
<label {$this->getStringifiedAttributes()}>{$radioInput}<span class="ml-2">{$this->slot}</span></label>
|
2021-09-15 15:58:21 +00:00
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|