2021-09-15 15:58:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components\Forms;
|
|
|
|
|
|
|
|
class Checkbox extends FormComponent
|
|
|
|
{
|
|
|
|
protected ?string $hint = null;
|
|
|
|
|
|
|
|
protected bool $isChecked = false;
|
|
|
|
|
|
|
|
public function setIsChecked(string $value): void
|
|
|
|
{
|
|
|
|
$this->isChecked = $value === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2021-10-21 13:12:38 +00:00
|
|
|
$attributes = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => $this->value,
|
|
|
|
'name' => $this->name,
|
2021-11-05 14:36:34 +00:00
|
|
|
'class' => 'form-checkbox bg-elevated text-accent-base border-contrast border-3 focus:ring-accent w-6 h-6',
|
2021-10-21 13:12:38 +00:00
|
|
|
];
|
2023-06-21 16:17:11 +00:00
|
|
|
|
2021-09-15 15:58:21 +00:00
|
|
|
$checkboxInput = form_checkbox(
|
2021-10-21 13:12:38 +00:00
|
|
|
$attributes,
|
2021-09-22 14:50:54 +00:00
|
|
|
'yes',
|
2021-09-15 15:58:21 +00:00
|
|
|
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
|
|
|
|
);
|
|
|
|
|
|
|
|
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
|
|
|
|
|
|
|
|
return <<<HTML
|
2021-10-21 13:12:38 +00:00
|
|
|
<label class="inline-flex items-center {$this->class}">{$checkboxInput}<span class="ml-2">{$this->slot}{$hint}</span></label>
|
2021-09-15 15:58:21 +00:00
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|