-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuGroup.php
60 lines (47 loc) · 1.17 KB
/
MenuGroup.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
<?php
declare(strict_types=1);
namespace MoonShine\MenuManager;
use Closure;
use MoonShine\Contracts\MenuManager\MenuElementsContract;
/**
* @method static static make(Closure|string $label, iterable $items, string|null $icon = null)
*/
class MenuGroup extends MenuElement
{
protected string $view = 'moonshine::components.menu.group';
public function __construct(
Closure|string $label,
protected iterable $items = [],
?string $icon = null,
) {
parent::__construct();
$this->setLabel($label);
if ($icon) {
$this->icon($icon);
}
}
public function setItems(iterable $items): static
{
$this->items = $items;
return $this;
}
public function getItems(): MenuElementsContract
{
return MenuElements::make($this->items);
}
public function isActive(): bool
{
foreach ($this->getItems() as $item) {
if ($item->isActive()) {
return true;
}
}
return false;
}
protected function viewData(): array
{
return [
'items' => $this->getItems(),
];
}
}