-
Notifications
You must be signed in to change notification settings - Fork 22
/
Alert.php
121 lines (106 loc) · 2.83 KB
/
Alert.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
<?php
namespace insolita\wgadminlte;
use yii\bootstrap\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Class Alert
*
* @example
* <?php echo Alert::widget(['type'=>'info','message'=>'some text'])?>
* <?php Alert::begin(['type'=>'info','closable'=>true])?>
* Alert message
* <?php Alert::end()?>
* @package insolita\wgadminlte
*/
class Alert extends Widget
{
/**
* @deprecated use LteConst instead
*/
const TYPE_SUCCESS = 'success';
/**
* @deprecated use LteConst instead
*/
const TYPE_WARNING = 'warning';
/**
* @deprecated use LteConst instead
*/
const TYPE_DANGER = 'danger';
/**
* @deprecated use LteConst instead
*/
const TYPE_INFO = 'info';
/**@var string $type color style of widget* */
public $type = LteConst::TYPE_SUCCESS;
/**@var boolean $closable show or not close button* */
public $closable = true;
/**
* @var string $text your message*
*/
public $text = '';
/**
* @var
*/
public $title;
/**@var string $icon icon class such as "ion ion-bag or fa fa-beer"* */
public $icon;
/**
* @var string
*/
public $templateWithTitle
= <<<HTML
<div {options}>{close}<h4><i class="{icon}"></i> {title}</h4>{message}
HTML;
/**
* @var string
*/
public $template
= <<<HTML
<div {options}>{close}<i class="{icon}"></i> {message}
HTML;
/**
* @var array
*/
public $iconMap
= [
LteConst::TYPE_DANGER => 'fa fa-lg fa-ban',
LteConst::TYPE_INFO => 'fa fa-lg fa-info',
LteConst::TYPE_WARNING => 'fa fa-lg fa-warning',
LteConst::TYPE_SUCCESS => 'fa fa-lg fa-check',
];
/**
*
*/
public function init()
{
parent::init();
if (!$this->icon) {
$this->icon = ArrayHelper::getValue($this->iconMap, $this->type, 'fa fa-question');
}
Html::addCssClass($this->options, 'alert');
Html::addCssClass($this->options, 'alert-' . $this->type);
if ($this->closable) {
Html::addCssClass($this->options, 'alert-dismissable');
}
$template = $this->title ? $this->templateWithTitle : $this->template;
echo strtr(
$template,
[
'{options}' => Html::renderTagAttributes($this->options),
'{close}' => $this->closable
? '<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>' : '',
'{title}' => $this->title,
'{icon}' => $this->icon,
'{message}' => $this->text,
]
);
}
/**
*
*/
public function run()
{
return '</div>';
}
}