PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / icon.php

icon.php in Elementor Website Builder – more than just a page builder 3.2.3, at includes/widgets/icon.php

467 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9
10 /**
11 * Elementor icon widget.
12 *
13 * Elementor widget that displays an icon from over 600+ icons.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Icon extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve icon widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'icon';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve icon widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return __( 'Icon', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve icon widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-favorite';
59 }
60
61 /**
62 * Get widget categories.
63 *
64 * Retrieve the list of categories the icon widget belongs to.
65 *
66 * Used to determine where to display the widget in the editor.
67 *
68 * @since 2.0.0
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories() {
74 return [ 'basic' ];
75 }
76
77 /**
78 * Get widget keywords.
79 *
80 * Retrieve the list of keywords the widget belongs to.
81 *
82 * @since 2.1.0
83 * @access public
84 *
85 * @return array Widget keywords.
86 */
87 public function get_keywords() {
88 return [ 'icon' ];
89 }
90
91 /**
92 * Register icon widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 3.1.0
97 * @access protected
98 */
99 protected function register_controls() {
100 $this->start_controls_section(
101 'section_icon',
102 [
103 'label' => __( 'Icon', 'elementor' ),
104 ]
105 );
106
107 $this->add_control(
108 'selected_icon',
109 [
110 'label' => __( 'Icon', 'elementor' ),
111 'type' => Controls_Manager::ICONS,
112 'fa4compatibility' => 'icon',
113 'default' => [
114 'value' => 'fas fa-star',
115 'library' => 'fa-solid',
116 ],
117 ]
118 );
119
120 $this->add_control(
121 'view',
122 [
123 'label' => __( 'View', 'elementor' ),
124 'type' => Controls_Manager::SELECT,
125 'options' => [
126 'default' => __( 'Default', 'elementor' ),
127 'stacked' => __( 'Stacked', 'elementor' ),
128 'framed' => __( 'Framed', 'elementor' ),
129 ],
130 'default' => 'default',
131 'prefix_class' => 'elementor-view-',
132 ]
133 );
134
135 $this->add_control(
136 'shape',
137 [
138 'label' => __( 'Shape', 'elementor' ),
139 'type' => Controls_Manager::SELECT,
140 'options' => [
141 'circle' => __( 'Circle', 'elementor' ),
142 'square' => __( 'Square', 'elementor' ),
143 ],
144 'default' => 'circle',
145 'condition' => [
146 'view!' => 'default',
147 ],
148 'prefix_class' => 'elementor-shape-',
149 ]
150 );
151
152 $this->add_control(
153 'link',
154 [
155 'label' => __( 'Link', 'elementor' ),
156 'type' => Controls_Manager::URL,
157 'dynamic' => [
158 'active' => true,
159 ],
160 'placeholder' => __( 'https://your-link.com', 'elementor' ),
161 ]
162 );
163
164 $this->add_responsive_control(
165 'align',
166 [
167 'label' => __( 'Alignment', 'elementor' ),
168 'type' => Controls_Manager::CHOOSE,
169 'options' => [
170 'left' => [
171 'title' => __( 'Left', 'elementor' ),
172 'icon' => 'eicon-text-align-left',
173 ],
174 'center' => [
175 'title' => __( 'Center', 'elementor' ),
176 'icon' => 'eicon-text-align-center',
177 ],
178 'right' => [
179 'title' => __( 'Right', 'elementor' ),
180 'icon' => 'eicon-text-align-right',
181 ],
182 ],
183 'default' => 'center',
184 'selectors' => [
185 '{{WRAPPER}} .elementor-icon-wrapper' => 'text-align: {{VALUE}};',
186 ],
187 ]
188 );
189
190 $this->end_controls_section();
191
192 $this->start_controls_section(
193 'section_style_icon',
194 [
195 'label' => __( 'Icon', 'elementor' ),
196 'tab' => Controls_Manager::TAB_STYLE,
197 ]
198 );
199
200 $this->start_controls_tabs( 'icon_colors' );
201
202 $this->start_controls_tab(
203 'icon_colors_normal',
204 [
205 'label' => __( 'Normal', 'elementor' ),
206 ]
207 );
208
209 $this->add_control(
210 'primary_color',
211 [
212 'label' => __( 'Primary Color', 'elementor' ),
213 'type' => Controls_Manager::COLOR,
214 'default' => '',
215 'selectors' => [
216 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
217 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
218 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon svg' => 'fill: {{VALUE}};',
219 ],
220 'global' => [
221 'default' => Global_Colors::COLOR_PRIMARY,
222 ],
223 ]
224 );
225
226 $this->add_control(
227 'secondary_color',
228 [
229 'label' => __( 'Secondary Color', 'elementor' ),
230 'type' => Controls_Manager::COLOR,
231 'default' => '',
232 'condition' => [
233 'view!' => 'default',
234 ],
235 'selectors' => [
236 '{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
237 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
238 '{{WRAPPER}}.elementor-view-stacked .elementor-icon svg' => 'fill: {{VALUE}};',
239 ],
240 ]
241 );
242
243 $this->end_controls_tab();
244
245 $this->start_controls_tab(
246 'icon_colors_hover',
247 [
248 'label' => __( 'Hover', 'elementor' ),
249 ]
250 );
251
252 $this->add_control(
253 'hover_primary_color',
254 [
255 'label' => __( 'Primary Color', 'elementor' ),
256 'type' => Controls_Manager::COLOR,
257 'default' => '',
258 'selectors' => [
259 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
260 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
261 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover svg' => 'fill: {{VALUE}};',
262 ],
263 ]
264 );
265
266 $this->add_control(
267 'hover_secondary_color',
268 [
269 'label' => __( 'Secondary Color', 'elementor' ),
270 'type' => Controls_Manager::COLOR,
271 'default' => '',
272 'condition' => [
273 'view!' => 'default',
274 ],
275 'selectors' => [
276 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
277 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
278 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover svg' => 'fill: {{VALUE}};',
279 ],
280 ]
281 );
282
283 $this->add_control(
284 'hover_animation',
285 [
286 'label' => __( 'Hover Animation', 'elementor' ),
287 'type' => Controls_Manager::HOVER_ANIMATION,
288 ]
289 );
290
291 $this->end_controls_tab();
292
293 $this->end_controls_tabs();
294
295 $this->add_responsive_control(
296 'size',
297 [
298 'label' => __( 'Size', 'elementor' ),
299 'type' => Controls_Manager::SLIDER,
300 'range' => [
301 'px' => [
302 'min' => 6,
303 'max' => 300,
304 ],
305 ],
306 'selectors' => [
307 '{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
308 ],
309 'separator' => 'before',
310 ]
311 );
312
313 $this->add_control(
314 'icon_padding',
315 [
316 'label' => __( 'Padding', 'elementor' ),
317 'type' => Controls_Manager::SLIDER,
318 'selectors' => [
319 '{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
320 ],
321 'range' => [
322 'em' => [
323 'min' => 0,
324 'max' => 5,
325 ],
326 ],
327 'condition' => [
328 'view!' => 'default',
329 ],
330 ]
331 );
332
333 $this->add_responsive_control(
334 'rotate',
335 [
336 'label' => __( 'Rotate', 'elementor' ),
337 'type' => Controls_Manager::SLIDER,
338 'size_units' => [ 'deg' ],
339 'default' => [
340 'size' => 0,
341 'unit' => 'deg',
342 ],
343 'tablet_default' => [
344 'unit' => 'deg',
345 ],
346 'mobile_default' => [
347 'unit' => 'deg',
348 ],
349 'selectors' => [
350 '{{WRAPPER}} .elementor-icon i, {{WRAPPER}} .elementor-icon svg' => 'transform: rotate({{SIZE}}{{UNIT}});',
351 ],
352 ]
353 );
354
355 $this->add_control(
356 'border_width',
357 [
358 'label' => __( 'Border Width', 'elementor' ),
359 'type' => Controls_Manager::DIMENSIONS,
360 'selectors' => [
361 '{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
362 ],
363 'condition' => [
364 'view' => 'framed',
365 ],
366 ]
367 );
368
369 $this->add_control(
370 'border_radius',
371 [
372 'label' => __( 'Border Radius', 'elementor' ),
373 'type' => Controls_Manager::DIMENSIONS,
374 'size_units' => [ 'px', '%' ],
375 'selectors' => [
376 '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
377 ],
378 'condition' => [
379 'view!' => 'default',
380 ],
381 ]
382 );
383
384 $this->end_controls_section();
385 }
386
387 /**
388 * Render icon widget output on the frontend.
389 *
390 * Written in PHP and used to generate the final HTML.
391 *
392 * @since 1.0.0
393 * @access protected
394 */
395 protected function render() {
396 $settings = $this->get_settings_for_display();
397
398 $this->add_render_attribute( 'wrapper', 'class', 'elementor-icon-wrapper' );
399
400 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-icon' );
401
402 if ( ! empty( $settings['hover_animation'] ) ) {
403 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-animation-' . $settings['hover_animation'] );
404 }
405
406 $icon_tag = 'div';
407
408 if ( ! empty( $settings['link']['url'] ) ) {
409 $this->add_link_attributes( 'icon-wrapper', $settings['link'] );
410
411 $icon_tag = 'a';
412 }
413
414 if ( empty( $settings['icon'] ) && ! Icons_Manager::is_migration_allowed() ) {
415 // add old default
416 $settings['icon'] = 'fa fa-star';
417 }
418
419 if ( ! empty( $settings['icon'] ) ) {
420 $this->add_render_attribute( 'icon', 'class', $settings['icon'] );
421 $this->add_render_attribute( 'icon', 'aria-hidden', 'true' );
422 }
423
424 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
425 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
426
427 ?>
428 <div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
429 <<?php echo $icon_tag . ' ' . $this->get_render_attribute_string( 'icon-wrapper' ); ?>>
430 <?php if ( $is_new || $migrated ) :
431 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
432 else : ?>
433 <i <?php echo $this->get_render_attribute_string( 'icon' ); ?>></i>
434 <?php endif; ?>
435 </<?php echo $icon_tag; ?>>
436 </div>
437 <?php
438 }
439
440 /**
441 * Render icon widget output in the editor.
442 *
443 * Written as a Backbone JavaScript template and used to generate the live preview.
444 *
445 * @since 2.9.0
446 * @access protected
447 */
448 protected function content_template() {
449 ?>
450 <# var link = settings.link.url ? 'href="' + settings.link.url + '"' : '',
451 iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
452 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ),
453 iconTag = link ? 'a' : 'div';
454 #>
455 <div class="elementor-icon-wrapper">
456 <{{{ iconTag }}} class="elementor-icon elementor-animation-{{ settings.hover_animation }}" {{{ link }}}>
457 <# if ( iconHTML && iconHTML.rendered && ( ! settings.icon || migrated ) ) { #>
458 {{{ iconHTML.value }}}
459 <# } else { #>
460 <i class="{{ settings.icon }}" aria-hidden="true"></i>
461 <# } #>
462 </{{{ iconTag }}}>
463 </div>
464 <?php
465 }
466 }
467