PluginProbe
Simple Analytics / trunk
Simple Analytics vtrunk
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / UI / LabelComponent.php

LabelComponent.php in Simple Analytics trunk, at src/UI/LabelComponent.php

63 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics\UI;
4
5 use SimpleAnalytics\Support\Str;
6
7 class LabelComponent
8 {
9 /**
10 * @readonly
11 * @var string
12 */
13 private $value;
14 /**
15 * @readonly
16 * @var string|null
17 */
18 private $docs;
19 /**
20 * @readonly
21 * @var string|null
22 */
23 private $for;
24 /**
25 * @readonly
26 * @var string
27 */
28 private $as = 'label';
29 public function __construct(string $value, ?string $docs, ?string $for = null, string $as = 'label')
30 {
31 $this->value = $value;
32 $this->docs = $docs;
33 $this->for = $for;
34 $this->as = $as;
35 }
36 public function __invoke(): void
37 {
38 $attributes = [
39 'class' => 'block text-sm font-medium leading-6 text-gray-900',
40 ];
41
42 if ($this->as === 'label') {
43 $attributes['for'] = esc_attr($this->for);
44 }
45
46 echo sprintf(
47 '<%1$s %2$s>%3$s%4$s</%1$s>',
48 $this->as,
49 Str::htmlAttributes($attributes),
50 esc_html($this->value),
51 $this->docs ? $this->renderDocsLink() : ''
52 );
53 }
54
55 protected function renderDocsLink(): string
56 {
57 return sprintf(
58 ' <a href="%s" target="_blank" class="text-primary">(docs)</a>',
59 esc_url($this->docs)
60 );
61 }
62 }
63