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

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