-
Notifications
You must be signed in to change notification settings - Fork 0
/
Badge.php
56 lines (53 loc) · 1.33 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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace makroxyz\materializecss;
use yii\helpers\ArrayHelper;
/**
* Badge renders a materialize button.
*
* For example,
*
* ```php
* echo Badge::widget([
* 'label' => 'Action',
* 'options' => ['class' => 'new'],
* ]);
* ```
* @see http://materializecss.com/badges.html
* @author webmaxx <[email protected]>
* @since 2.0
*/
class Badge extends Widget
{
/**
* @var string the button label
*/
public $label = '';
/**
* @var boolean whether the label should be HTML-encoded.
*/
public $encodeLabel = true;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
$this->clientOptions = false;
Html::addCssClass($this->options, 'badge');
}
/**
* Renders the widget.
*/
public function run()
{
MaterializeAsset::register($this->getView());
$tag = ArrayHelper::remove($this->options, 'tag', 'span');
return Html::tag($tag, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options);
}
}