PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0-dev2
Elementor Website Builder – more than just a page builder v4.2.0-dev2
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 4.2.0-dev2, at includes/widgets/icon.php

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