1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Stack.php |
4
|
|
|
* @author Revin Roman |
5
|
|
|
* @link https://rmrevin.ru |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace rmrevin\yii\fontawesome\component; |
9
|
|
|
|
10
|
|
|
use yii\helpers\Html; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Stack |
14
|
|
|
* @package rmrevin\yii\fontawesome\component |
15
|
|
|
*/ |
16
|
|
|
class Stack |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
public static $defaultTag = 'span'; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $tag; |
24
|
|
|
|
25
|
|
|
/** @var array */ |
26
|
|
|
private $options = []; |
27
|
|
|
|
28
|
|
|
/** @var Icon */ |
29
|
|
|
private $icon_front; |
30
|
|
|
|
31
|
|
|
/** @var Icon */ |
32
|
|
|
private $icon_back; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $options |
36
|
|
|
*/ |
37
|
1 |
|
public function __construct($options = []) |
38
|
|
|
{ |
39
|
|
|
Html::addCssClass($options, 'fa-stack'); |
40
|
|
|
|
41
|
1 |
|
$this->options = $options; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function __toString() |
48
|
|
|
{ |
49
|
|
|
return $this->render(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string|Icon $icon |
54
|
|
|
* @param array $options |
55
|
|
|
* @return self |
56
|
|
|
*/ |
57
|
|
|
public function icon($icon, $options = []) |
58
|
|
|
{ |
59
|
|
|
if (is_string($icon)) { |
60
|
|
|
$icon = new Icon($icon, $options); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->icon_front = $icon; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string|Icon $icon |
70
|
|
|
* @param array $options |
71
|
|
|
* @return self |
72
|
|
|
*/ |
73
|
|
|
public function on($icon, $options = []) |
74
|
|
|
{ |
75
|
|
|
if (is_string($icon)) { |
76
|
|
|
$icon = new Icon($icon, $options); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->icon_back = $icon; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Change html tag. |
86
|
|
|
* @param string $tag |
87
|
|
|
* @return static |
88
|
|
|
* @throws \yii\base\InvalidParamException |
89
|
|
|
*/ |
90
|
1 |
|
public function tag($tag) |
91
|
|
|
{ |
92
|
1 |
|
$this->tag = $tag; |
93
|
|
|
|
94
|
1 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string|null $tag |
99
|
|
|
* @param array $options |
100
|
|
|
* @return string |
101
|
|
|
* @throws \yii\base\InvalidConfigException |
102
|
|
|
*/ |
103
|
|
|
public function render($tag = null, $options = []) |
104
|
|
|
{ |
105
|
|
|
$tag = empty($tag) ? |
106
|
|
|
(empty($this->tag) ? static::$defaultTag : $this->tag) |
107
|
|
|
: $tag; |
108
|
|
|
|
109
|
|
|
$options = array_merge($this->options, $options); |
110
|
|
|
|
111
|
|
|
$icon_back = $this->icon_back instanceof Icon |
112
|
|
|
? $this->icon_back->addCssClass('fa-stack-2x') |
113
|
|
|
: null; |
114
|
|
|
|
115
|
|
|
$icon_front = $this->icon_front instanceof Icon |
116
|
|
|
? $this->icon_front->addCssClass('fa-stack-1x') |
117
|
|
|
: null; |
118
|
|
|
|
119
|
|
|
return Html::tag( |
120
|
|
|
$tag, |
121
|
|
|
$icon_back . $icon_front, |
122
|
|
|
$options |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |