generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHasContainerCollection.php
82 lines (69 loc) · 2.26 KB
/
HasContainerCollection.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
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Concern;
use UIAwesome\Html\Helper\CssClass;
use function array_merge;
/**
* Is used by widgets that implement container collection class.
*/
trait HasContainerCollection
{
protected array $containerAttributes = [];
protected false|string $containerTag = false;
/**
* Set the `HTML` attributes for the container.
*
* @param array $values Attribute values indexed by attribute names.
*
* @return static A new instance of the current class with the specified container attributes.
*/
public function containerAttributes(array $values = []): static
{
$new = clone $this;
$new->containerAttributes = array_merge($new->containerAttributes, $values);
return $new;
}
/**
* Sets the `CSS` class that will be assigned to the container.
*
* @param string $value The CSS class name.
* @param bool $override If `true` the value will be overridden.
*
* @return static A new instance of the current class with the specified container class.
*/
public function containerClass(string $value, bool $override = false): static
{
$new = clone $this;
CssClass::add($new->containerAttributes, $value, $override);
return $new;
}
/**
* Set the container tag name.
*
* @param false|string $value The tag name for the container element.
* If `false` the container tag will be disabled.
*
* @throws \InvalidArgumentException If the container tag is an empty string.
*
* @return static A new instance of the current class with the specified container tag.
* If `false` the container tag will be disabled.
*/
public function containerTag(false|string $value = 'div'): static
{
if ($value === '') {
throw new \InvalidArgumentException('The container tag must be a non-empty string.');
}
$new = clone $this;
$new->containerTag = $value;
return $new;
}
/**
* Get the `HTML` attributes for the container.
*
* @return array Attribute values indexed by attribute names.
*/
public function getContainerAttributes(): array
{
return $this->containerAttributes;
}
}