generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HasDataToggle.php
33 lines (27 loc) · 825 Bytes
/
HasDataToggle.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
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Attribute\Data;
/**
* Is used by widgets that implement the dataToggle method.
*/
trait HasDataToggle
{
protected bool|string $dataToggle = false;
/**
* Set the `HTML` `data-toggle` attribute for the toggle.
*
* @param bool|string $value The `data-toggle` attribute value. If `true`, the value of the `id` attribute will be
* used.
*
* @return static A new instance of the current class with the specified toggle attributes.
*/
public function dataToggle(bool|string $value = true): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributeValues::TOGGLE => $value]);
}
$new = clone $this;
$new->dataToggle = $value;
return $new;
}
}