-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathIcon.php
70 lines (65 loc) · 1.4 KB
/
Icon.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
<?php namespace webmaxx\materialize;
use yii\helpers\Html;
/**
* Icon renders a materialize icon.
*
* For example,
*
* ```php
* echo Icon::widget([
* 'name' => 'grade',
* 'size' => 'large',
* ]);
* ```
*
* or
*
* ```php
* echo Icon::show('grade', 'large');
* ```
* @see http://materializecss.com/icons.html
* @author webmaxx <[email protected]>
* @since 2.0
*/
class Icon extends Widget
{
/**
* @var string the tag to use to render the icon
*/
public $tagName = 'i';
/**
* @var string the icon name
*/
public $name;
/**
* @var string the icon size (tiny, small, medium or large)
*/
public $size = '';
/**
* 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, $this->size);
Html::addCssClass($this->options, 'material-icons');
}
/**
* Renders the widget.
*/
public function run()
{
return Html::tag($this->tagName, $this->name, $this->options);
}
/**
* Render icon.
*/
public static function show($name, $size='', $class = '')
{
return self::widget(['name' => $name, 'size' => $size, 'options' => [
'class' => $class,
]]);
}
}