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

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