# simpleanalytics/1.84/src/UI/LabelComponent.php

Simple Analytics, version 1.84. 63 lines.

- Page: https://pluginprobe.com/plugins/simpleanalytics/1.84/code/src/UI/LabelComponent.php
- Raw: https://pluginprobe.com/plugins/simpleanalytics/1.84/raw/src/UI/LabelComponent.php
- Modified: 2024-09-13T11:41:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/simpleanalytics/1.84/code/src/UI/LabelComponent.php#L10-L20`.

```php
<?php

namespace SimpleAnalytics\UI;

use SimpleAnalytics\Support\Str;

class LabelComponent
{
    /**
     * @readonly
     * @var string
     */
    private $value;
    /**
     * @readonly
     * @var string|null
     */
    private $docs;
    /**
     * @readonly
     * @var string|null
     */
    private $for;
    /**
     * @readonly
     * @var string
     */
    private $as = 'label';
    public function __construct(string  $value, ?string $docs, ?string $for = null, string  $as = 'label')
    {
        $this->value = $value;
        $this->docs = $docs;
        $this->for = $for;
        $this->as = $as;
    }
    public function __invoke(): void
    {
        $attributes = [
            'class' => 'block text-sm font-medium leading-6 text-gray-900',
        ];

        if ($this->as === 'label') {
            $attributes['for'] = esc_attr($this->for);
        }

        echo sprintf(
            '<%1$s %2$s>%3$s%4$s</%1$s>',
            $this->as,
            Str::htmlAttributes($attributes),
            esc_html($this->value),
            $this->docs ? $this->renderDocsLink() : ''
        );
    }

    protected function renderDocsLink(): string
    {
        return sprintf(
            ' <a href="%s" target="_blank" class="text-primary">(docs)</a>',
            esc_url($this->docs)
        );
    }
}

```
