Newer
Older

Yassine Doghri
committed
<?php
declare(strict_types=1);
namespace App\Views\Components\Forms;

Yassine Doghri
committed
use ViewComponents\Component;
class Label extends Component
{
protected ?string $for = null;

Yassine Doghri
committed
protected ?string $hint = null;

Yassine Doghri
committed
protected bool $isOptional = false;

Yassine Doghri
committed
public function setIsOptional(string $value): void
{
$this->isOptional = $value === 'true';
}

Yassine Doghri
committed
public function render(): string
{
$labelClass = 'text-sm ' . $this->attributes['class'];

Yassine Doghri
committed
unset($this->attributes['class']);
$optionalText = $this->isOptional ? '<small class="ml-1 lowercase">(' .
lang('Common.optional') .
')</small>' : '';
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');

Yassine Doghri
committed
unset($this->attributes['isOptional']);
unset($this->attributes['hint']);
unset($this->attributes['slot']);
$attributes = stringify_attributes($this->attributes);

Yassine Doghri
committed
return <<<HTML
<label class="{$labelClass}" {$attributes}>{$this->slot}{$optionalText}{$hint}</label>
HTML;