forked from worstinme/yii2-uikit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavBar.php
78 lines (71 loc) · 2.08 KB
/
NavBar.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
<?php
namespace worstinme\uikit;
use yii\helpers\Html;
use Yii;
/**
* NavBar renders a navbar HTML component.
*
* Any content enclosed between the [[begin()]] and [[end()]] calls of NavBar
* is treated as the content of the navbar. You may use widgets such as [[Nav]]
* or [[\yii\widgets\Menu]] to build up such content. For example,
*
* ```php
* use yii\uikit\NavBar;
* use yii\uikit\Nav;
*
* NavBar::begin();
* echo Nav::widget([
* 'items' => [
* ['label' => 'Home', 'url' => ['/site/index']],
* ['label' => 'About', 'url' => ['/site/about']],
* ],
* ]);
* NavBar::end();
* ```
*
* @see http://www.getuikit.com/docs/navbar.html
* @author Nikolay Kostyurin <nikolay@artkost.ru>
* @since 2.0
*/
class NavBar extends Widget
{
public $brandLabel = false;
public $brandUrl = false;
public $container = false;
public $brandOptions = [];
public $offcanvas = false;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->clientOptions = false;
Html::addCssClass($this->options, 'uk-navbar');
if (empty($this->options['role'])) {
$this->options['role'] = 'navigation';
}
echo Html::beginTag('nav', $this->options);
if ($this->container) {
echo Html::beginTag('div', ['class'=>'uk-container uk-container-center']);
}
if ($this->offcanvas) {
echo Html::a('','#'.($this->offcanvas === true ? 'offcanvas' : $this->offcanvas),
['class'=>'uk-navbar-toggle uk-visible-small','data-uk-offcanvas'=>true]);
}
if ($this->brandLabel !== false) {
Html::addCssClass($this->brandOptions, ['widget' => 'uk-navbar-brand']);
echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
}
}
/**
* Renders the widget.
*/
public function run()
{
if ($this->container) {
echo Html::endTag('div');
}
echo Html::endTag('nav');
}
}