generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasLabelCollection.php
105 lines (89 loc) · 2.73 KB
/
HasLabelCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Concern;
use UIAwesome\Html\{Helper\CssClass, Helper\Sanitize, Interop\RenderInterface};
use function array_merge;
/**
* Is used by widgets that implement the label collection class.
*/
trait HasLabelCollection
{
protected bool $disableLabel = false;
protected string $label = '';
protected array $labelAttributes = [];
protected string $labelClass = '';
protected string|null $labelFor = null;
/**
* Disable the label.
*
* @return static A new instance or clone of the current object with the label disabled.
*/
public function disableLabel(): static
{
$new = clone $this;
$new->disableLabel = true;
return $new;
}
/**
* Get the `HTML` attributes for the label.
*
* @return array Attribute values indexed by attribute names.
*/
public function getLabelAttributes(): array
{
return $this->labelAttributes;
}
/**
* Set the `HTML` label content.
*
* @param RenderInterface|string ...$values The `HTML` label content value.
*
* @return static A new instance of the current class with the specified `HTML` label content.
*/
public function label(RenderInterface|string ...$values): static
{
$new = clone $this;
$new->label = Sanitize::html(...$values);
return $new;
}
/**
* Set the `HTML` attributes for the label.
*
* @param array $values Attribute values indexed by attribute names.
*
* @return static A new instance of the current class with the specified label attributes.
*/
public function labelAttributes(array $values): static
{
$new = clone $this;
$new->labelAttributes = array_merge($new->labelAttributes, $values);
return $new;
}
/**
* Sets the `CSS` class that will be assigned to the label.
*
* @param string $value The value of the class attribute.
* @param bool $override If `true` the value will be overridden.
*
* @return static A new instance of the current class with the specified label class.
*/
public function labelClass(string $value, bool $override = false): static
{
$new = clone $this;
CssClass::add($new->labelAttributes, $value, $override);
return $new;
}
/**
* Set the `for` attribute for the label.
*
* @param string|null $value The value for the `for` attribute.
*
* @return static A new instance of the current class with the specified label `for` attribute.
*/
public function labelFor(string|null $value): static
{
$new = clone $this;
$new->labelFor = $value;
return $new;
}
}