-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPanel.php
137 lines (122 loc) · 2.83 KB
/
Panel.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace demogorgorn\uikit;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Panel renders an panel component.
*
* For example,
*
* ```php
* echo Panel::widget([
* 'options' => [
* 'class' => 'some class',
* ],
* 'body' => '<p>Say hello...</p>',
* ]);
* ```
*
* The following example will show the content enclosed between the [[begin()]]
* and [[end()]] calls within the alert box:
*
* ```php
* Panel::begin([
* 'title' => 'First Panel',
* 'badge' => '09 May 2014',
* 'options' => ['class' => 'some class'],
* 'isBox' => true,
* ]);
*
* echo '<p>Say hello...</p>';
*
* Panel::end();
* ```
*
* @author Oleg Martemjanov <demogorgorn@gmail.com>
* @since 2.0
*
*/
class Panel extends Widget
{
/**
* @var string the badge data of the panel.
*/
public $badge;
/**
* @var string the title of the panel.
*/
public $title;
/**
* @var string the body content in the panel component. Note that anything between
* the [[begin()]] and [[end()]] calls of the Panel widget will also be treated
* as the body content, and will be rendered before this.
*/
public $body;
/**
* @var boolean the box
*/
public $isBox = false;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->initOptions();
echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderBadge() . "\n";
echo $this->renderTitle() . "\n";
}
/**
* Renders the widget.
*/
public function run()
{
echo "\n" . $this->renderBody();
echo "\n" . Html::endTag('div');
$this->registerAsset();
}
/**
* Renders the badge.
* @return string the rendering result
*/
protected function renderBadge()
{
if ($this->badge !== null) {
return Html::tag('div', $this->badge, ['class' => 'uk-panel-badge uk-badge']);
} else {
return null;
}
}
/**
* Renders the title of the panel.
* @return string the rendering result
*/
protected function renderTitle()
{
if ($this->title !== null) {
return Html::tag('h3', $this->title, ['class' => 'uk-panel-title']);
} else {
return null;
}
}
/**
* Renders the panel body (if any).
* @return string the rendering result
*/
protected function renderBody()
{
return $this->body . "\n";
}
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected function initOptions()
{
Html::addCssClass($this->options, 'uk-panel');
if ($this->isBox)
Html::addCssClass($this->options, 'uk-panel-box');
}
}