Skip to content
Snippets Groups Projects
Label.php 1.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • namespace App\Views\Components\Forms;
    
    
    use ViewComponents\Component;
    
    class Label extends Component
    {
    
        public function setIsOptional(string $value): void
        {
            $this->isOptional = $value === 'true';
        }
    
    
            $labelClass = 'text-sm ' . $this->attributes['class'];
    
            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');
    
            unset($this->attributes['isOptional']);
            unset($this->attributes['hint']);
            unset($this->attributes['slot']);
    
            $attributes = stringify_attributes($this->attributes);
    
    
            return <<<HTML
                <label class="{$labelClass}" {$attributes}>{$this->slot}{$optionalText}{$hint}</label>
            HTML;