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

485 lines 12.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 /**
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->add_responsive_control(
164 'align',
165 [
166 'label' => esc_html__( 'Alignment', 'elementor' ),
167 'type' => Controls_Manager::CHOOSE,
168 'options' => [
169 'left' => [
170 'title' => esc_html__( 'Left', 'elementor' ),
171 'icon' => 'eicon-text-align-left',
172 ],
173 'center' => [
174 'title' => esc_html__( 'Center', 'elementor' ),
175 'icon' => 'eicon-text-align-center',
176 ],
177 'right' => [
178 'title' => esc_html__( 'Right', 'elementor' ),
179 'icon' => 'eicon-text-align-right',
180 ],
181 ],
182 'default' => 'center',
183 'selectors' => [
184 '{{WRAPPER}} .elementor-icon-wrapper' => 'text-align: {{VALUE}};',
185 ],
186 ]
187 );
188
189 $this->end_controls_section();
190
191 $this->start_controls_section(
192 'section_style_icon',
193 [
194 'label' => esc_html__( 'Icon', 'elementor' ),
195 'tab' => Controls_Manager::TAB_STYLE,
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 'selectors' => [
337 '{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
338 ],
339 'range' => [
340 'em' => [
341 'min' => 0,
342 'max' => 5,
343 ],
344 ],
345 'condition' => [
346 'view!' => 'default',
347 ],
348 ]
349 );
350
351 $this->add_responsive_control(
352 'rotate',
353 [
354 'label' => esc_html__( 'Rotate', 'elementor' ),
355 'type' => Controls_Manager::SLIDER,
356 'size_units' => [ 'deg', 'grad', 'rad', 'turn', 'custom' ],
357 'default' => [
358 'unit' => 'deg',
359 ],
360 'tablet_default' => [
361 'unit' => 'deg',
362 ],
363 'mobile_default' => [
364 'unit' => 'deg',
365 ],
366 'selectors' => [
367 '{{WRAPPER}} .elementor-icon i, {{WRAPPER}} .elementor-icon svg' => 'transform: rotate({{SIZE}}{{UNIT}});',
368 ],
369 ]
370 );
371
372 $this->add_control(
373 'border_width',
374 [
375 'label' => esc_html__( 'Border Width', 'elementor' ),
376 'type' => Controls_Manager::DIMENSIONS,
377 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
378 'selectors' => [
379 '{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
380 ],
381 'condition' => [
382 'view' => 'framed',
383 ],
384 ]
385 );
386
387 $this->add_responsive_control(
388 'border_radius',
389 [
390 'label' => esc_html__( 'Border Radius', 'elementor' ),
391 'type' => Controls_Manager::DIMENSIONS,
392 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
393 'selectors' => [
394 '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
395 ],
396 'condition' => [
397 'view!' => 'default',
398 ],
399 ]
400 );
401
402 $this->end_controls_section();
403 }
404
405 /**
406 * Render icon widget output on the frontend.
407 *
408 * Written in PHP and used to generate the final HTML.
409 *
410 * @since 1.0.0
411 * @access protected
412 */
413 protected function render() {
414 $settings = $this->get_settings_for_display();
415
416 $this->add_render_attribute( 'wrapper', 'class', 'elementor-icon-wrapper' );
417
418 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-icon' );
419
420 if ( ! empty( $settings['hover_animation'] ) ) {
421 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-animation-' . $settings['hover_animation'] );
422 }
423
424 $icon_tag = 'div';
425
426 if ( ! empty( $settings['link']['url'] ) ) {
427 $this->add_link_attributes( 'icon-wrapper', $settings['link'] );
428
429 $icon_tag = 'a';
430 }
431
432 if ( empty( $settings['icon'] ) && ! Icons_Manager::is_migration_allowed() ) {
433 // add old default
434 $settings['icon'] = 'fa fa-star';
435 }
436
437 if ( ! empty( $settings['icon'] ) ) {
438 $this->add_render_attribute( 'icon', 'class', $settings['icon'] );
439 $this->add_render_attribute( 'icon', 'aria-hidden', 'true' );
440 }
441
442 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
443 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
444
445 ?>
446 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
447 <<?php Utils::print_unescaped_internal_string( $icon_tag . ' ' . $this->get_render_attribute_string( 'icon-wrapper' ) ); ?>>
448 <?php if ( $is_new || $migrated ) :
449 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
450 else : ?>
451 <i <?php $this->print_render_attribute_string( 'icon' ); ?>></i>
452 <?php endif; ?>
453 </<?php Utils::print_unescaped_internal_string( $icon_tag ); ?>>
454 </div>
455 <?php
456 }
457
458 /**
459 * Render icon widget output in the editor.
460 *
461 * Written as a Backbone JavaScript template and used to generate the live preview.
462 *
463 * @since 2.9.0
464 * @access protected
465 */
466 protected function content_template() {
467 ?>
468 <# const link = settings.link.url ? 'href="' + _.escape( settings.link.url ) + '"' : '',
469 iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
470 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ),
471 iconTag = link ? 'a' : 'div';
472 #>
473 <div class="elementor-icon-wrapper">
474 <{{{ iconTag }}} class="elementor-icon elementor-animation-{{ settings.hover_animation }}" {{{ link }}}>
475 <# if ( iconHTML && iconHTML.rendered && ( ! settings.icon || migrated ) ) { #>
476 {{{ iconHTML.value }}}
477 <# } else { #>
478 <i class="{{ settings.icon }}" aria-hidden="true"></i>
479 <# } #>
480 </{{{ iconTag }}}>
481 </div>
482 <?php
483 }
484 }
485