1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\PropellerAdmin\Navigation; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
8
|
|
|
use AbterPhp\Framework\Html\Component\Button; |
9
|
|
|
use AbterPhp\Framework\Html\Helper\StringHelper; |
10
|
|
|
use AbterPhp\Framework\Html\IComponent; |
11
|
|
|
use AbterPhp\Framework\Navigation\Item; |
12
|
|
|
|
13
|
|
|
class Header extends Item |
14
|
|
|
{ |
15
|
|
|
const DEFAULT_TAG = Html5::TAG_DIV; |
16
|
|
|
|
17
|
|
|
const HAMBURGER_BTN_INTENT = 'header-btn'; |
18
|
|
|
const HAMBURGER_BTN_ICON = '<i class="material-icons">menu</i>'; |
19
|
|
|
const HAMBURGER_BTN_CLASS = 'btn btn-sm pmd-btn-fab pmd-btn-flat pmd-ripple-effect pull-left margin-r8 pmd-sidebar-toggle'; // nolint |
20
|
|
|
const HAMBURGER_BTN_HREF = 'javascript:void(0);'; |
21
|
|
|
|
22
|
|
|
const BRAND_BTN_CLASS = 'navbar-brand'; |
23
|
|
|
|
24
|
|
|
/** @var array */ |
25
|
|
|
protected $attributes = [ |
26
|
|
|
Html5::ATTR_CLASS => 'navbar-header', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** @var Button */ |
30
|
|
|
protected $brandBtn; |
31
|
|
|
|
32
|
|
|
/** @var IComponent */ |
33
|
|
|
protected $hamburgerBtn; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Header constructor. |
37
|
|
|
* |
38
|
|
|
* @param Button $brandBtn |
39
|
|
|
* @param IComponent|null $hamburgerBtn |
40
|
|
|
* @param array $attributes |
41
|
|
|
* @param string|null $tag |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
Button $brandBtn, |
45
|
|
|
?IComponent $hamburgerBtn = null, |
46
|
|
|
array $attributes = [], |
47
|
|
|
?string $tag = null |
48
|
|
|
) { |
49
|
|
|
parent::__construct(null, [], $attributes, $tag); |
50
|
|
|
|
51
|
|
|
$this->brandBtn = $brandBtn->appendToAttribute(Html5::ATTR_CLASS, static::BRAND_BTN_CLASS); |
52
|
|
|
$this->hamburgerBtn = $hamburgerBtn ?: $this->createDefaultHamburgerBtn(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return Button |
57
|
|
|
*/ |
58
|
|
|
protected function createDefaultHamburgerBtn(): Button |
59
|
|
|
{ |
60
|
|
|
$attribs = [ |
61
|
|
|
Html5::ATTR_CLASS => static::HAMBURGER_BTN_CLASS, |
62
|
|
|
Html5::ATTR_HREF => static::HAMBURGER_BTN_HREF, |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
return new Button(static::HAMBURGER_BTN_ICON, [self::HAMBURGER_BTN_INTENT], $attribs, Html5::TAG_A); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getExtendedNodes(): array |
72
|
|
|
{ |
73
|
|
|
return array_merge([$this->brandBtn, $this->hamburgerBtn], $this->getNodes()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function __toString(): string |
80
|
|
|
{ |
81
|
|
|
$content = (string)$this->hamburgerBtn . (string)$this->brandBtn; |
82
|
|
|
|
83
|
|
|
$content = StringHelper::wrapInTag($content, $this->tag, $this->attributes); |
84
|
|
|
|
85
|
|
|
return $content; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|