-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBadge.php
90 lines (80 loc) · 1.82 KB
/
Badge.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
<?php
namespace demogorgorn\uikit;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Badge renders an Badge component.
*
* For example,
*
* ```php
* echo Badge::widget([
* 'options' => [
* 'class' => 'uk-badge-success',
* ],
* 'body' => 'Say hello...',
* ]);
* ```
*
* The following example will show the content enclosed between the [[begin()]]
* and [[end()]] calls within the Badge box:
*
* ```php
* Badge::begin([
* 'isNotification' => true,
* 'options' => [
* 'class' => 'uk-badge-success',
* ],
* ]);
*
* echo 'Say hello...';
*
* Badge::end();
* ```
*
* @author Oleg Martemjanov <[email protected]>
* @since 2.0
*
*/
class Badge extends Widget
{
/**
* @var string the body content in the Badge component. Note that anything between
* the [[begin()]] and [[end()]] calls of the Badge widget will also be treated
* as the body content, and will be rendered before this.
*/
public $body;
/**
* @var boolean use the notification type of the Badge component.
*/
public $isNotification = false;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->initOptions();
echo Html::beginTag('div', $this->options) . "\n";
}
/**
* Renders the widget.
*/
public function run()
{
echo "\n" . $this->body;
echo "\n" . Html::endTag('div');
$this->registerAsset();
}
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected function initOptions()
{
Html::addCssClass($this->options, 'uk-badge');
if($this->isNotification)
Html::addCssClass($this->options, 'uk-badge-notification');
}
}