1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/DMGPage/yii2-materialize |
4
|
|
|
* @copyright Copyright (c) 2018 Dmitrijs Reinmanis |
5
|
|
|
* @license https://github.com/DMGPage/yii2-materialize/blob/master/LICENSE |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace dmgpage\yii2materialize\helpers; |
9
|
|
|
|
10
|
|
|
use yii\helpers\BaseHtml; |
11
|
|
|
use yii\helpers\ArrayHelper; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Html is an enhanced version of [[\yii\helpers\Html]] helper class dedicated to the Materialize needs. |
15
|
|
|
* This class inherits all functionality available at [[\yii\helpers\Html]] and can be used as substitute. |
16
|
|
|
* |
17
|
|
|
* @package helpers |
18
|
|
|
*/ |
19
|
|
|
class Html extends BaseHtml |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Generates a start tag for row. |
23
|
|
|
* |
24
|
|
|
* @param array $options the tag options in terms of name-value pairs. These will be rendered as |
25
|
|
|
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
26
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
27
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
28
|
|
|
* |
29
|
|
|
* @return string the generated start tag |
30
|
|
|
* |
31
|
|
|
* @see https://materializecss.com/grid.html |
32
|
|
|
* @see endGridRow() |
33
|
|
|
*/ |
34
|
|
|
public static function beginGridRow($options = []) |
35
|
|
|
{ |
36
|
|
|
static::addCssClass($options, 'row'); |
37
|
|
|
return static::beginTag('div', $options); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Generates an end tag for row. |
42
|
|
|
* |
43
|
|
|
* @return string the generated end tag |
44
|
|
|
* @see beginGridRow() |
45
|
|
|
*/ |
46
|
|
|
public static function endGridRow() |
47
|
|
|
{ |
48
|
|
|
return static::endTag('div'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generates a start tag for column. |
53
|
|
|
* |
54
|
|
|
* @param array $options the tag options in terms of name-value pairs. These will be rendered as |
55
|
|
|
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
56
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
57
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
58
|
|
|
* |
59
|
|
|
* @return string the generated start tag |
60
|
|
|
* |
61
|
|
|
* @see https://materializecss.com/grid.html |
62
|
|
|
* @see endGridCol() |
63
|
|
|
*/ |
64
|
|
|
public static function beginGridCol($options = []) |
65
|
|
|
{ |
66
|
|
|
static::addCssClass($options, 'col'); |
67
|
|
|
return static::beginTag('div', $options); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Generates an end tag for column. |
72
|
|
|
* |
73
|
|
|
* @return string the generated end tag |
74
|
|
|
* @see beginGridCol() |
75
|
|
|
*/ |
76
|
|
|
public static function endGridCol() |
77
|
|
|
{ |
78
|
|
|
return static::endTag('div'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Generates a complete HTML tag for column. |
83
|
|
|
* |
84
|
|
|
* @param string $content the content to be enclosed between the start and end tags. It will not be HTML-encoded. |
85
|
|
|
* If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. |
86
|
|
|
* @param array $options the HTML tag attributes (HTML options) in terms of name-value pairs. |
87
|
|
|
* These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
88
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
89
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
90
|
|
|
* |
91
|
|
|
* @return string the generated HTML tag |
92
|
|
|
* @see beginGridCol() |
93
|
|
|
* @see endGridCol() |
94
|
|
|
*/ |
95
|
|
|
public static function gridCol($content = '', $options = []) |
96
|
|
|
{ |
97
|
|
|
static::addCssClass($options, 'col'); |
98
|
|
|
return static::tag('div', $content, $options); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Generates a start tag for blockquote. |
103
|
|
|
* |
104
|
|
|
* @param array $options the tag options in terms of name-value pairs. These will be rendered as |
105
|
|
|
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
106
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
107
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
108
|
|
|
* |
109
|
|
|
* @return string the generated start tag |
110
|
|
|
* |
111
|
|
|
* @see https://materializecss.com/typography.html |
112
|
|
|
* @see endBlockquote() |
113
|
|
|
*/ |
114
|
|
|
public static function beginBlockquote($options = []) |
115
|
|
|
{ |
116
|
|
|
return static::beginTag('blockquote', $options); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Generates an end tag for blockquote. |
121
|
|
|
* |
122
|
|
|
* @return string the generated end tag |
123
|
|
|
* @see beginBlockquote() |
124
|
|
|
*/ |
125
|
|
|
public static function endBlockquote() |
126
|
|
|
{ |
127
|
|
|
return static::endTag('blockquote'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Generates a complete HTML tag for blockquote. |
132
|
|
|
* |
133
|
|
|
* @param string $content the content to be enclosed between the start and end tags. It will not be HTML-encoded. |
134
|
|
|
* If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. |
135
|
|
|
* @param array $options the HTML tag attributes (HTML options) in terms of name-value pairs. |
136
|
|
|
* These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
137
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
138
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
139
|
|
|
* |
140
|
|
|
* @return string the generated HTML tag |
141
|
|
|
* @see beginBlockquote() |
142
|
|
|
* @see beginBlockquote() |
143
|
|
|
*/ |
144
|
|
|
public static function blockquote($content = '', $options = []) |
145
|
|
|
{ |
146
|
|
|
return static::tag('blockquote', $content, $options); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Generates a complete HTML tag for badge. |
151
|
|
|
* |
152
|
|
|
* @param string $content the content to be enclosed between the start and end tags. It will not be HTML-encoded. |
153
|
|
|
* If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. |
154
|
|
|
* @param array $options the HTML tag attributes (HTML options) in terms of name-value pairs. |
155
|
|
|
* These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
156
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
157
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
158
|
|
|
* |
159
|
|
|
* @return string the generated HTML tag |
160
|
|
|
*/ |
161
|
|
|
public static function badge($content = '', $options = []) |
162
|
|
|
{ |
163
|
|
|
static::addCssClass($options, 'badge'); |
164
|
|
|
return static::tag('span', $content, $options); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Generates a complete HTML tag for badge with background. |
169
|
|
|
* |
170
|
|
|
* @param string $content the content to be enclosed between the start and end tags. It will not be HTML-encoded. |
171
|
|
|
* If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. |
172
|
|
|
* @param array $options the HTML tag attributes (HTML options) in terms of name-value pairs. |
173
|
|
|
* These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. |
174
|
|
|
* If a value is null, the corresponding attribute will not be rendered. |
175
|
|
|
* See [[renderTagAttributes()]] for details on how attributes are being rendered. |
176
|
|
|
* |
177
|
|
|
* @return string the generated HTML tag |
178
|
|
|
*/ |
179
|
|
|
public static function newBadge($content = '', $options = []) |
180
|
|
|
{ |
181
|
|
|
static::addCssClass($options, 'badge'); |
182
|
|
|
static::addCssClass($options, 'new'); |
183
|
|
|
return static::tag('span', $content, $options); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Composes icon HTML for Material Design Icons. |
188
|
|
|
* |
189
|
|
|
* @param string $name icon short name, for example: 'alarm' |
190
|
|
|
* @param array $options the tag options in terms of name-value pairs. These will be rendered as |
191
|
|
|
* the attributes of the resulting tag. There are also a special option: |
192
|
|
|
* |
193
|
|
|
* - tag: string, tag to be rendered, by default 'i' is used. |
194
|
|
|
* |
195
|
|
|
* @return string icon HTML. |
196
|
|
|
* @see https://materializecss.com/icons.html |
197
|
|
|
*/ |
198
|
|
|
public static function icon($name, $options = []) |
199
|
|
|
{ |
200
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'i'); |
201
|
|
|
static::addCssClass($options, 'material-icons'); |
202
|
|
|
return static::tag($tag, $name, $options); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Adds wave effect classes to the specified options. |
207
|
|
|
* |
208
|
|
|
* @param string|array $effects the effects to be added |
209
|
|
|
* @param array $options the options to be modified. |
210
|
|
|
* @return array modificated options, to use in html element |
211
|
|
|
* |
212
|
|
|
* @see \dmgpage\yii2materialize\helpers\Waves |
213
|
|
|
* @see addCssClass() |
214
|
|
|
* @see https://materializecss.com/waves.html |
215
|
|
|
*/ |
216
|
|
|
public static function addWaves($effects, $options = []) |
217
|
|
|
{ |
218
|
|
|
$effectTypes = is_array($effects) ? $effects : [$effects]; |
219
|
|
|
$effectTypes[] = Waves::INIT; |
220
|
|
|
|
221
|
|
|
foreach ($effectTypes as $effect) { |
222
|
|
|
Html::addCssClass($options, "waves-$effect"); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
return $options; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|