castopod/app/Views/Components/Forms/Checkbox.php
Yassine Doghri a505a1de56 feat: restyle episode and person cards + add focus style to interactive elements for a11y
fix components in follow and remote action pages by calling new instances directly
2021-12-29 12:02:53 +00:00

41 lines
1.1 KiB
PHP

<?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
{
$attributes = [
'id' => $this->value,
'name' => $this->name,
'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-castopod w-6 h-6',
];
if ($this->required) {
$attributes['required'] = 'required';
}
$checkboxInput = form_checkbox(
$attributes,
'yes',
old($this->name) ? old($this->name) === $this->value : $this->isChecked,
);
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
return <<<HTML
<label class="inline-flex items-center {$this->class}">{$checkboxInput}<span class="ml-2">{$this->slot}{$hint}</span></label>
HTML;
}
}