Skip to content

Commit 9f279d3

Browse files
committed
Added an ability to add custom items to panel header menu (Close #7)
1 parent 0f60293 commit 9f279d3

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Yii2 Gentelella Change Log
44
1.2.0 under development
55
-----------------------
66

7+
- Enh #7: Add a an ability to add custom items to dropdown list of `yiister\gentelella\widgets\Panel` (fps01)
78
- New #8: Added a `yiister\gentelella\widgets\Timeline` widget (fps01)
89
- New #5: Added an ability to keep a sidebar state (fps01)
910
- Fix #6: using a PHP 5.4 instead of 5.5
1011

1112
1.1.0 June 26, 2016
12-
-----------------------
13+
-------------------
1314

1415
- New #3: Added a `yiister\gentelella\widgets\StatsTile` widget (fps01)
1516
- New #2: Added a `yiister\gentelella\widgets\grid\GridView` widget (fps01)

widgets/Panel.php

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
use rmrevin\yii\fontawesome\component\Icon;
1111
use yii\base\Widget;
12+
use yii\bootstrap\Nav;
1213
use yii\helpers\Html;
1314

1415
class Panel extends Widget
1516
{
1617
/**
17-
* @var string[]
18+
* @var array the configuration array for creating a [[Dropdown]] widget
1819
*/
1920
protected $tools = [];
2021

@@ -49,23 +50,38 @@ class Panel extends Widget
4950
public $removable = false;
5051

5152
/**
52-
* Inits tool buttons
53+
* @var array|string, optional, the configuration array for creating a [[Dropdown]] widget,
54+
* or a string representing the dropdown menu.
55+
*/
56+
public $headerMenu = [];
57+
58+
/**
59+
* Init tool buttons
5360
*/
5461
protected function initTools()
5562
{
5663
if ($this->expandable === true || $this->collapsable === true) {
57-
$this->tools[] = Html::tag(
58-
'a',
59-
new Icon('chevron-' . ($this->expandable === true ? 'down' : 'up')),
60-
['class' => 'collapse-link']
61-
);
64+
$this->tools[] = [
65+
'encode' => false,
66+
'label' => new Icon('chevron-' . ($this->expandable === true ? 'down' : 'up')),
67+
'linkOptions' => ['class' => 'collapse-link'],
68+
'url' => null,
69+
];
70+
}
71+
if (empty($this->headerMenu) === false) {
72+
$this->tools[] = [
73+
'encode' => false,
74+
'items' => $this->headerMenu,
75+
'label' => new Icon('wrench'),
76+
];
6277
}
6378
if ($this->removable === true) {
64-
$this->tools[] = Html::tag(
65-
'a',
66-
new Icon('close'),
67-
['class' => 'close-link']
68-
);
79+
$this->tools[] = [
80+
'encode' => false,
81+
'label' => new Icon('close'),
82+
'linkOptions' => ['class' => 'close-link'],
83+
'url' => null,
84+
];
6985
}
7086
}
7187

@@ -82,10 +98,14 @@ public function init()
8298
echo Html::beginTag('div', ['class' => 'x_title']);
8399
echo Html::tag('h2', ($this->icon !== null ? new Icon($this->icon) . ' ' : '') . $this->header);
84100
if (empty($this->tools) === false) {
85-
echo Html::tag(
86-
'ul',
87-
'<li>' . implode("</li>\n<li>", $this->tools) . '</li>',
88-
['class' => 'nav navbar-right panel_toolbox']
101+
echo Nav::widget(
102+
[
103+
'dropDownCaret' => '',
104+
'items' => $this->tools,
105+
'options' => [
106+
'class' => 'nav navbar-right panel_toolbox',
107+
],
108+
]
89109
);
90110
}
91111
echo Html::tag('div', null, ['class' => 'clearfix']);

0 commit comments

Comments
 (0)