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

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