PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.7
Elementor Website Builder – more than just a page builder v3.25.7
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.25.7, at includes/widgets/icon.php

507 lines 12.5 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 esc_html__( '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 protected function is_dynamic_content(): bool {
92 return false;
93 }
94
95 /**
96 * Register icon widget controls.
97 *
98 * Adds different input fields to allow the user to change and customize the widget settings.
99 *
100 * @since 3.1.0
101 * @access protected
102 */
103 protected function register_controls() {
104 $this->start_controls_section(
105 'section_icon',
106 [
107 'label' => esc_html__( 'Icon', 'elementor' ),
108 ]
109 );
110
111 $this->add_control(
112 'selected_icon',
113 [
114 'label' => esc_html__( 'Icon', 'elementor' ),
115 'type' => Controls_Manager::ICONS,
116 'fa4compatibility' => 'icon',
117 'default' => [
118 'value' => 'fas fa-star',
119 'library' => 'fa-solid',
120 ],
121 ]
122 );
123
124 $this->add_control(
125 'view',
126 [
127 'label' => esc_html__( 'View', 'elementor' ),
128 'type' => Controls_Manager::SELECT,
129 'options' => [
130 'default' => esc_html__( 'Default', 'elementor' ),
131 'stacked' => esc_html__( 'Stacked', 'elementor' ),
132 'framed' => esc_html__( 'Framed', 'elementor' ),
133 ],
134 'default' => 'default',
135 'prefix_class' => 'elementor-view-',
136 ]
137 );
138
139 $this->add_control(
140 'shape',
141 [
142 'label' => esc_html__( 'Shape', 'elementor' ),
143 'type' => Controls_Manager::SELECT,
144 'options' => [
145 'square' => esc_html__( 'Square', 'elementor' ),
146 'rounded' => esc_html__( 'Rounded', 'elementor' ),
147 'circle' => esc_html__( 'Circle', 'elementor' ),
148 ],
149 'default' => 'circle',
150 'condition' => [
151 'view!' => 'default',
152 ],
153 'prefix_class' => 'elementor-shape-',
154 ]
155 );
156
157 $this->add_control(
158 'link',
159 [
160 'label' => esc_html__( 'Link', 'elementor' ),
161 'type' => Controls_Manager::URL,
162 'dynamic' => [
163 'active' => true,
164 ],
165 ]
166 );
167
168 $this->end_controls_section();
169
170 $this->start_controls_section(
171 'section_style_icon',
172 [
173 'label' => esc_html__( 'Icon', 'elementor' ),
174 'tab' => Controls_Manager::TAB_STYLE,
175 ]
176 );
177
178 $this->add_responsive_control(
179 'align',
180 [
181 'label' => esc_html__( 'Alignment', 'elementor' ),
182 'type' => Controls_Manager::CHOOSE,
183 'options' => [
184 'left' => [
185 'title' => esc_html__( 'Left', 'elementor' ),
186 'icon' => 'eicon-text-align-left',
187 ],
188 'center' => [
189 'title' => esc_html__( 'Center', 'elementor' ),
190 'icon' => 'eicon-text-align-center',
191 ],
192 'right' => [
193 'title' => esc_html__( 'Right', 'elementor' ),
194 'icon' => 'eicon-text-align-right',
195 ],
196 ],
197 'default' => 'center',
198 'selectors' => [
199 '{{WRAPPER}} .elementor-icon-wrapper' => 'text-align: {{VALUE}};',
200 ],
201 ]
202 );
203
204 $this->start_controls_tabs( 'icon_colors' );
205
206 $this->start_controls_tab(
207 'icon_colors_normal',
208 [
209 'label' => esc_html__( 'Normal', 'elementor' ),
210 ]
211 );
212
213 $this->add_control(
214 'primary_color',
215 [
216 'label' => esc_html__( 'Primary Color', 'elementor' ),
217 'type' => Controls_Manager::COLOR,
218 'default' => '',
219 'selectors' => [
220 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
221 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
222 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon svg' => 'fill: {{VALUE}};',
223 ],
224 'global' => [
225 'default' => Global_Colors::COLOR_PRIMARY,
226 ],
227 ]
228 );
229
230 $this->add_control(
231 'secondary_color',
232 [
233 'label' => esc_html__( 'Secondary Color', 'elementor' ),
234 'type' => Controls_Manager::COLOR,
235 'default' => '',
236 'condition' => [
237 'view!' => 'default',
238 ],
239 'selectors' => [
240 '{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
241 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
242 '{{WRAPPER}}.elementor-view-stacked .elementor-icon svg' => 'fill: {{VALUE}};',
243 ],
244 ]
245 );
246
247 $this->end_controls_tab();
248
249 $this->start_controls_tab(
250 'icon_colors_hover',
251 [
252 'label' => esc_html__( 'Hover', 'elementor' ),
253 ]
254 );
255
256 $this->add_control(
257 'hover_primary_color',
258 [
259 'label' => esc_html__( 'Primary Color', 'elementor' ),
260 'type' => Controls_Manager::COLOR,
261 'default' => '',
262 'selectors' => [
263 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
264 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
265 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover svg' => 'fill: {{VALUE}};',
266 ],
267 ]
268 );
269
270 $this->add_control(
271 'hover_secondary_color',
272 [
273 'label' => esc_html__( 'Secondary Color', 'elementor' ),
274 'type' => Controls_Manager::COLOR,
275 'default' => '',
276 'condition' => [
277 'view!' => 'default',
278 ],
279 'selectors' => [
280 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
281 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
282 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover svg' => 'fill: {{VALUE}};',
283 ],
284 ]
285 );
286
287 $this->add_control(
288 'hover_animation',
289 [
290 'label' => esc_html__( 'Hover Animation', 'elementor' ),
291 'type' => Controls_Manager::HOVER_ANIMATION,
292 ]
293 );
294
295 $this->end_controls_tab();
296
297 $this->end_controls_tabs();
298
299 $this->add_responsive_control(
300 'size',
301 [
302 'label' => esc_html__( 'Size', 'elementor' ),
303 'type' => Controls_Manager::SLIDER,
304 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
305 'range' => [
306 'px' => [
307 'min' => 6,
308 'max' => 300,
309 ],
310 ],
311 'selectors' => [
312 '{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
313 '{{WRAPPER}} .elementor-icon svg' => 'height: {{SIZE}}{{UNIT}};',
314 ],
315 'separator' => 'before',
316 ]
317 );
318
319 $this->add_control(
320 'fit_to_size',
321 [
322 'label' => esc_html__( 'Fit to Size', 'elementor' ),
323 'type' => Controls_Manager::SWITCHER,
324 'description' => 'Avoid gaps around icons when width and height aren\'t equal',
325 'label_off' => esc_html__( 'Off', 'elementor' ),
326 'label_on' => esc_html__( 'On', 'elementor' ),
327 'condition' => [
328 'selected_icon[library]' => 'svg',
329 ],
330 'selectors' => [
331 '{{WRAPPER}} .elementor-icon-wrapper svg' => 'width: 100%;',
332 ],
333 ]
334 );
335
336 $this->add_control(
337 'icon_padding',
338 [
339 'label' => esc_html__( 'Padding', 'elementor' ),
340 'type' => Controls_Manager::SLIDER,
341 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
342 'selectors' => [
343 '{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
344 ],
345 'range' => [
346 'px' => [
347 'max' => 50,
348 ],
349 'em' => [
350 'min' => 0,
351 'max' => 5,
352 ],
353 'rem' => [
354 'min' => 0,
355 'max' => 5,
356 ],
357 ],
358 'condition' => [
359 'view!' => 'default',
360 ],
361 ]
362 );
363
364 $this->add_responsive_control(
365 'rotate',
366 [
367 'label' => esc_html__( 'Rotate', 'elementor' ),
368 'type' => Controls_Manager::SLIDER,
369 'size_units' => [ 'deg', 'grad', 'rad', 'turn', 'custom' ],
370 'default' => [
371 'unit' => 'deg',
372 ],
373 'tablet_default' => [
374 'unit' => 'deg',
375 ],
376 'mobile_default' => [
377 'unit' => 'deg',
378 ],
379 'selectors' => [
380 '{{WRAPPER}} .elementor-icon i, {{WRAPPER}} .elementor-icon svg' => 'transform: rotate({{SIZE}}{{UNIT}});',
381 ],
382 ]
383 );
384
385 $this->add_control(
386 'border_width',
387 [
388 'label' => esc_html__( 'Border Width', 'elementor' ),
389 'type' => Controls_Manager::DIMENSIONS,
390 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
391 'selectors' => [
392 '{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
393 ],
394 'condition' => [
395 'view' => 'framed',
396 ],
397 ]
398 );
399
400 $this->add_responsive_control(
401 'border_radius',
402 [
403 'label' => esc_html__( 'Border Radius', 'elementor' ),
404 'type' => Controls_Manager::DIMENSIONS,
405 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
406 'selectors' => [
407 '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
408 ],
409 'condition' => [
410 'view!' => 'default',
411 ],
412 ]
413 );
414
415 $this->end_controls_section();
416 }
417
418 /**
419 * Render icon widget output on the frontend.
420 *
421 * Written in PHP and used to generate the final HTML.
422 *
423 * @since 1.0.0
424 * @access protected
425 */
426 protected function render() {
427 $settings = $this->get_settings_for_display();
428
429 if ( empty( $settings['selected_icon']['value'] ) ) {
430 return;
431 }
432
433 $this->add_render_attribute( 'wrapper', 'class', 'elementor-icon-wrapper' );
434
435 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-icon' );
436
437 if ( ! empty( $settings['hover_animation'] ) ) {
438 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-animation-' . $settings['hover_animation'] );
439 }
440
441 $icon_tag = 'div';
442
443 if ( ! empty( $settings['link']['url'] ) ) {
444 $this->add_link_attributes( 'icon-wrapper', $settings['link'] );
445
446 $icon_tag = 'a';
447 }
448
449 if ( empty( $settings['icon'] ) && ! Icons_Manager::is_migration_allowed() ) {
450 // add old default
451 $settings['icon'] = 'fa fa-star';
452 }
453
454 if ( ! empty( $settings['icon'] ) ) {
455 $this->add_render_attribute( 'icon', 'class', $settings['icon'] );
456 $this->add_render_attribute( 'icon', 'aria-hidden', 'true' );
457 }
458
459 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
460 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
461
462 ?>
463 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
464 <<?php Utils::print_unescaped_internal_string( $icon_tag . ' ' . $this->get_render_attribute_string( 'icon-wrapper' ) ); ?>>
465 <?php if ( $is_new || $migrated ) :
466 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
467 else : ?>
468 <i <?php $this->print_render_attribute_string( 'icon' ); ?>></i>
469 <?php endif; ?>
470 </<?php Utils::print_unescaped_internal_string( $icon_tag ); ?>>
471 </div>
472 <?php
473 }
474
475 /**
476 * Render icon widget output in the editor.
477 *
478 * Written as a Backbone JavaScript template and used to generate the live preview.
479 *
480 * @since 2.9.0
481 * @access protected
482 */
483 protected function content_template() {
484 ?>
485 <#
486 if ( '' === settings.selected_icon.value ) {
487 return;
488 }
489
490 const link = settings.link.url ? 'href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '"' : '',
491 iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
492 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ),
493 iconTag = link ? 'a' : 'div';
494 #>
495 <div class="elementor-icon-wrapper">
496 <{{{ iconTag }}} class="elementor-icon elementor-animation-{{ settings.hover_animation }}" {{{ link }}}>
497 <# if ( iconHTML && iconHTML.rendered && ( ! settings.icon || migrated ) ) { #>
498 {{{ iconHTML.value }}}
499 <# } else { #>
500 <i class="{{ settings.icon }}" aria-hidden="true"></i>
501 <# } #>
502 </{{{ iconTag }}}>
503 </div>
504 <?php
505 }
506 }
507