PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.9
UiCore Elements – Free widgets and templates for Elementor v1.0.9
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / widgets / counter.php

counter.php in UiCore Elements – Free widgets and templates for Elementor 1.0.9, at includes/widgets/counter.php

1,154 lines 28.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Icons_Manager;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UiCoreElements\UiCoreWidget;
11
12
13 defined('ABSPATH') || exit();
14
15 /**
16 * Counter
17 *
18 * @author Lucas Marini Falbo <lucas@uicore.co>
19 * @since 1.0.0
20 */
21
22 class Counter extends UiCoreWidget
23 {
24
25 public function get_name()
26 {
27 return 'uicore-counter';
28 }
29 public function get_title()
30 {
31 return __( 'Counter', 'uicore-elements' );
32 }
33 public function get_icon()
34 {
35 return 'eicon-counter ui-e-widget';
36 }
37 public function get_keywords()
38 {
39 return ['counter', 'count', 'number'];
40 }
41 public function get_categories()
42 {
43 return [ 'uicore' ];
44 }
45 public function get_styles()
46 {
47 return [ 'counter' ];
48 }
49 public function get_scripts()
50 {
51 return [
52 'counter',
53 'odometer' => [
54 'condition' => [
55 'counter_animation' => 'odometer',
56 ],
57 ]
58 ];
59 }
60 protected function register_controls()
61 {
62
63 /**
64 * Content TAB
65 */
66
67 // Counter SECTION
68 $this->start_controls_section(
69 'content_section',
70 [
71 'label' => __( 'Counter', 'uicore-elements' ),
72 'tab' => Controls_Manager::TAB_CONTENT,
73 ]
74 );
75
76 $this->add_control(
77 'show_icon',
78 [
79 'label' => esc_html__( 'Show Icon', 'uicore-elements' ),
80 'type' => Controls_Manager::SWITCHER,
81 'label_on' => esc_html__( 'Show', 'uicore-elements' ),
82 'label_off' => esc_html__( 'Hide', 'uicore-elements' ),
83 'return_value' => 'true',
84 'prefix_class' => 'ui-e-counter-media-',
85 'render_type' => 'template',
86 ]
87 );
88
89 $this->add_control(
90 'icon_type',
91 [
92 'label' => esc_html__( 'Icon Type', 'uicore-elements' ),
93 'type' => Controls_Manager::CHOOSE,
94 'options' => [
95 'icon' => [
96 'title' => esc_html__( 'Icon', 'uicore-elements' ),
97 'icon' => 'eicon-star',
98 ],
99 'image' => [
100 'title' => esc_html__( 'Image', 'uicore-elements' ),
101 'icon' => 'eicon-image-bold',
102 ],
103
104 ],
105 'default' => 'icon',
106 'toggle' => false,
107 'condition' => [
108 'show_icon' => 'true',
109 ],
110 ]
111 );
112
113 $this->add_control(
114 'selected_icon',
115 [
116 'label' => esc_html__( 'Choose icon', 'uicore-elements' ),
117 'type' => Controls_Manager::ICONS,
118 'condition' => [
119 'show_icon' => 'true',
120 'icon_type' => 'icon',
121 ],
122 ]
123 );
124
125 $this->add_control(
126 'image',
127 [
128 'label' => esc_html__( 'Choose Image', 'uicore-elements' ),
129 'type' => Controls_Manager::MEDIA,
130 'condition' => [
131 'show_icon' => 'true',
132 'icon_type' => 'image',
133 ],
134 'dynamic' => [
135 'active' => true,
136 ],
137 ]
138 );
139
140 $this->add_control(
141 'count_start',
142 [
143 'label' => esc_html__( 'Starting number', 'uicore-elements' ),
144 'type' => Controls_Manager::NUMBER,
145 'step' => 1,
146 'default' => 10,
147 'frontend_available' => true,
148 'dynamic' => [
149 'active' => true,
150 ],
151 'condition' =>[
152 'counter_animation!' => ['motion'],
153 ],
154 ]
155 );
156
157 $this->add_control(
158 'count_end',
159 [
160 'label' => esc_html__( 'Ending number', 'uicore-elements' ),
161 'type' => Controls_Manager::NUMBER,
162 'step' => 1,
163 'default' => 120,
164 'frontend_available' => true,
165 'dynamic' => [
166 'active' => true,
167 ],
168 'condition' =>[
169 'counter_animation!' => ['motion'],
170 ],
171 ]
172 );
173
174 $this->add_control(
175 'count_number',
176 [
177 'label' => esc_html__( 'Number', 'uicore-elements' ),
178 'type' => Controls_Manager::TEXT,
179 'default' => '120,00',
180 'frontend_available' => true,
181 'label_block' => true,
182 'dynamic' => [
183 'active' => true,
184 ],
185 'condition' =>[
186 'counter_animation' => ['motion'],
187 ],
188 ]
189 );
190
191 $this->add_control(
192 'counter_html_tag',
193 [
194 'label' => esc_html__( 'Number HTML class', 'uicore-elements' ),
195 'type' => Controls_Manager::SELECT,
196 'default' => 'h1',
197 'options' => [
198 'h1' => esc_html__( 'H1', 'uicore-elements' ),
199 'h2' => esc_html__( 'H2', 'uicore-elements' ),
200 'h3' => esc_html__( 'H3', 'uicore-elements' ),
201 'h4' => esc_html__( 'H4', 'uicore-elements' ),
202 'h5' => esc_html__( 'H5', 'uicore-elements' ),
203 'h6' => esc_html__( 'H6', 'uicore-elements' ),
204 'p' => esc_html__( 'p', 'uicore-elements' ),
205 'span' => esc_html__( 'span', 'uicore-elements' ),
206 ],
207 ]
208 );
209
210 $this->add_control(
211 'content_text',
212 [
213 'label' => esc_html__( 'Title', 'uicore-elements' ),
214 'type' => Controls_Manager::TEXT,
215 'default' => esc_html__( 'Awesome number', 'uicore-elements' ),
216 'placeholder' => esc_html__( 'Type your title here', 'uicore-elements' ),
217 'separator' => 'before',
218 'label_block' => true,
219 'dynamic' => [
220 'active' => true,
221 ],
222 ]
223 );
224
225 $this->add_control(
226 'content_html_tag',
227 [
228 'label' => esc_html__( 'Title HTML tag', 'uicore-elements' ),
229 'type' => Controls_Manager::SELECT,
230 'default' => 'p',
231 'options' => [
232 'H1' => esc_html__( 'H1', 'uicore-elements' ),
233 'H2' => esc_html__( 'H2', 'uicore-elements' ),
234 'H3' => esc_html__( 'H3', 'uicore-elements' ),
235 'H4' => esc_html__( 'H4', 'uicore-elements' ),
236 'H5' => esc_html__( 'H5', 'uicore-elements' ),
237 'H6' => esc_html__( 'H6', 'uicore-elements' ),
238 'p' => esc_html__( 'p', 'uicore-elements' ),
239 'span' => esc_html__( 'span', 'uicore-elements' ),
240 ],
241 ]
242 );
243
244 $this->add_control(
245 'counter_text_inline',
246 [
247 'label' => esc_html__( 'Text inline', 'uicore-elements' ),
248 'type' => Controls_Manager::SWITCHER,
249 'label_on' => esc_html__( 'True', 'uicore-elements' ),
250 'label_off' => esc_html__( 'False', 'uicore-elements' ),
251 'return_value' => 'true',
252 'prefix_class' => 'ui-e-inline-',
253 'render_type' => 'template',
254 'default' => false,
255 ]
256 );
257
258 $this->add_control(
259 'icon_position',
260 [
261 'label' => esc_html__( 'Icon position', 'uicore-elements' ),
262 'type' => Controls_Manager::CHOOSE,
263 'options' => [
264 'left' => [
265 'title' => esc_html__( 'Left', 'uicore-elements' ),
266 'icon' => 'eicon-h-align-left',
267 ],
268 'top' => [
269 'title' => esc_html__( 'Top', 'uicore-elements' ),
270 'icon' => 'eicon-v-align-top',
271 ],
272 'right' => [
273 'title' => esc_html__( 'Right', 'uicore-elements' ),
274 'icon' => 'eicon-h-align-right',
275 ],
276 ],
277 'default' => 'top',
278 'toggle' => false,
279 'condition' =>[
280 'show_icon' => 'true',
281 'counter_text_inline!' => 'true',
282 ],
283 'prefix_class' => 'ui-e-',
284 'render_type' => 'template',
285 ]
286 );
287
288 $this->add_control(
289 'icon_position_inline',
290 [
291 'label' => esc_html__( 'Icon position', 'uicore-elements' ),
292 'type' => Controls_Manager::CHOOSE,
293 'options' => [
294 'left' => [
295 'title' => esc_html__( 'Left', 'uicore-elements' ),
296 'icon' => 'eicon-h-align-left',
297 ],
298 'right' => [
299 'title' => esc_html__( 'Right', 'uicore-elements' ),
300 'icon' => 'eicon-h-align-right',
301 ],
302 ],
303 'default' => 'left',
304 'toggle' => false,
305 'condition' =>[
306 'show_icon' => 'true',
307 'counter_text_inline' => 'true',
308 ],
309 'prefix_class' => 'ui-e-',
310 'render_type' => 'template',
311 ]
312 );
313
314 $this->add_control(
315 'vertical_align',
316 [
317 'label' => esc_html__( 'Vertical position', 'uicore-elements' ),
318 'type' => Controls_Manager::CHOOSE,
319 'options' => [
320 'start' => [
321 'title' => esc_html__( 'Top', 'uicore-elements' ),
322 'icon' => 'eicon-v-align-top',
323 ],
324 'center' => [
325 'title' => esc_html__( 'Center', 'uicore-elements' ),
326 'icon' => 'eicon-v-align-middle',
327 ],
328 'end' => [
329 'title' => esc_html__( 'Bottom', 'uicore-elements' ),
330 'icon' => 'eicon-v-align-bottom',
331 ],
332 ],
333 'default' => 'center',
334 'toggle' => false,
335 'selectors' => [
336 '{{WRAPPER}} > div' => 'align-items: {{VALUE}};',
337 ],
338 'condition' => [
339 'icon_position!' => ['top'],
340 'counter_text_inline!' => ['true'],
341 ],
342 ]
343 );
344
345 $this->add_control(
346 'vertical_align_inline',
347 [
348 'label' => esc_html__( 'Vertical position', 'uicore-elements' ),
349 'type' => Controls_Manager::CHOOSE,
350 'options' => [
351 'start' => [
352 'title' => esc_html__( 'Top', 'uicore-elements' ),
353 'icon' => 'eicon-v-align-top',
354 ],
355 'center' => [
356 'title' => esc_html__( 'Center', 'uicore-elements' ),
357 'icon' => 'eicon-v-align-middle',
358 ],
359 'end' => [
360 'title' => esc_html__( 'Bottom', 'uicore-elements' ),
361 'icon' => 'eicon-v-align-bottom',
362 ],
363 ],
364 'default' => 'center',
365 'toggle' => false,
366 'selectors' => [
367 '{{WRAPPER}} > div' => 'align-items: {{VALUE}};',
368 ],
369 'condition' => [
370 'counter_text_inline' => ['true'],
371 ],
372 ]
373 );
374
375 $this->add_control(
376 'text_align',
377 [
378 'label' => esc_html__( 'Text Align', 'uicore-elements' ),
379 'type' => Controls_Manager::CHOOSE,
380 'options' => [
381 'left' => [
382 'title' => esc_html__( 'Left', 'uicore-elements' ),
383 'icon' => 'eicon-text-align-left',
384 ],
385 'center' => [
386 'title' => esc_html__( 'Center', 'uicore-elements' ),
387 'icon' => 'eicon-text-align-center',
388 ],
389 'right' => [
390 'title' => esc_html__( 'Right', 'uicore-elements' ),
391 'icon' => 'eicon-text-align-right',
392 ],
393 ],
394 'toggle' => false,
395 'default' => 'center',
396 'prefix_class' => 'ui-e-align-',
397 'selectors' => [
398 '{{WRAPPER}} .ui-e-title' => 'text-align: {{VALUE}};',
399 '{{WRAPPER}} .ui-e-ico' => 'text-align: {{VALUE}};',
400 ],
401
402 ]
403 );
404
405 $this->add_control(
406 'icon_offset_toggle',
407 [
408 'label' => esc_html__( 'Icon Offset', 'uicore-elements' ),
409 'type' => Controls_Manager::POPOVER_TOGGLE,
410 'label_off' => esc_html__( 'Default', 'uicore-elements' ),
411 'label_on' => esc_html__( 'Custom', 'uicore-elements' ),
412 'return_value' => 'yes',
413 'condition' => [
414 'show_icon' => 'true',
415 'counter_text_inline!' => 'true',
416 ],
417 ]
418 );
419
420 $this->start_popover();
421
422 $this->add_responsive_control(
423 'icon_vertical_offset',
424 [
425 'label' => esc_html__( 'Vertical offset', 'uicore-elements' ),
426 'type' => Controls_Manager::SLIDER,
427 'size_units' => ['px'],
428 'range' => [
429 'px' => [
430 'min' => -100,
431 'max' => 100,
432 'step' => 1,
433 ],
434 ],
435 'default' => [
436 'unit' => 'px',
437 'size' => 0,
438 ],
439 'condition' => [
440 'counter_text_inline!' => 'true',
441 'icon_offset_toggle' => 'yes',
442 ],
443 'selectors' => [
444 '{{WRAPPER}}' => '--ui-e-ico-vertical-off: {{SIZE}}{{UNIT}};',
445 ],
446 ]
447 );
448
449 $this->add_responsive_control(
450 'icon_horizontal_offset',
451 [
452 'label' => esc_html__( 'Horizontal offset', 'uicore-elements' ),
453 'type' => Controls_Manager::SLIDER,
454 'size_units' => ['px'],
455 'range' => [
456 'px' => [
457 'min' => -100,
458 'max' => 100,
459 'step' => 1,
460 ],
461 ],
462 'default' => [
463 'unit' => 'px',
464 'size' => 0,
465 ],
466 'condition' => [
467 'counter_text_inline!' => 'true',
468 'icon_offset_toggle' => 'yes',
469 ],
470 'selectors' => [
471 '{{WRAPPER}}' => '--ui-e-ico-horizontal-off: {{SIZE}}{{UNIT}};',
472 ],
473 ]
474 );
475
476 $this->end_popover();
477
478 $this->end_controls_section();
479
480 $this->start_controls_section(
481 'add_op_section',
482 [
483 'label' => __( 'Additional Options', 'uicore-elements' ),
484 'tab' => Controls_Manager::TAB_CONTENT,
485 ]
486 );
487
488 $this->add_control(
489 'use_grouping',
490 [
491 'label' => esc_html__( 'Use Grouping', 'uicore-elements' ),
492 'type' => Controls_Manager::SWITCHER,
493 'label_on' => esc_html__( 'True', 'uicore-elements' ),
494 'label_off' => esc_html__( 'False', 'uicore-elements' ),
495 'return_value' => 'true',
496 'default' => 'true',
497 'frontend_available' => true,
498 'condition' =>[
499 'counter_animation!' => ['motion'],
500 ],
501 ]
502 );
503
504 $this->add_control(
505 'counter_separator',
506 [
507 'label' => esc_html__( 'Thousand symbol', 'uicore-elements' ),
508 'type' => Controls_Manager::TEXT,
509 'default' => esc_html__( ',', 'uicore-elements' ),
510 'condition' =>[
511 'use_grouping' => 'true',
512 'counter_animation!' => ['motion'],
513 ],
514 'frontend_available' => true,
515 ]
516 );
517
518 $this->add_control(
519 'decimal_places',
520 [
521 'label' => esc_html__( 'Decimal Places', 'uicore-elements' ),
522 'type' => Controls_Manager::NUMBER,
523 'min' => 0,
524 'max' => 4,
525 'step' => 1,
526 'default' => 0,
527 'frontend_available' => true,
528 'condition' => [
529 'counter_animation!' => ['motion'],
530 ],
531 ]
532 );
533
534 $this->add_control(
535 'decimal_symbol',
536 [
537 'label' => esc_html__( 'Decimal Symbol', 'uicore-elements' ),
538 'type' => Controls_Manager::TEXT,
539 'default' => esc_html__( '.', 'uicore-elements' ),
540 'condition' =>[
541 'counter_animation!' => ['motion'],
542 ],
543 'frontend_available' => true,
544 ]
545 );
546
547 $this->add_control(
548 'counter_prefix',
549 [
550 'label' => esc_html__( 'Counter Prefix', 'uicore-elements' ),
551 'type' => Controls_Manager::TEXT,
552 'default' => esc_html__( '', 'uicore-elements' ),
553 'placeholder' => esc_html__( '$', 'uicore-elements' ),
554 'frontend_available' => true,
555 ]
556 );
557
558 $this->add_control(
559 'counter_suffix',
560 [
561 'label' => esc_html__( 'Counter Suffix', 'uicore-elements' ),
562 'type' => Controls_Manager::TEXT,
563 'default' => esc_html__( '', 'uicore-elements' ),
564 'placeholder' => esc_html__( '+', 'uicore-elements' ),
565 'frontend_available' => true,
566 ]
567 );
568
569 $this->end_controls_section();
570
571
572 /**
573 * Style TAB
574 */
575
576 $this->start_controls_section(
577 'icon_image_section',
578 [
579 'label' => __( 'Icon/Image', 'uicore-elements' ),
580 'tab' => Controls_Manager::TAB_STYLE,
581 'condition' => [
582 'show_icon' => 'true',
583 ],
584 ]
585 );
586
587 $this->start_controls_tabs(
588 'style_tabs'
589 );
590
591 $this->start_controls_tab(
592 'icon_colors',
593 [
594 'label' => esc_html__( 'Normal', 'uicore-elements' ),
595 ]
596 );
597
598 $this->add_control(
599 'icon_color',
600 [
601 'label' => esc_html__( 'Icon color', 'uicore-elements' ),
602 'type' => Controls_Manager::COLOR,
603 'condition' => [
604 'icon_type!' => 'image',
605 ],
606 'selectors' => [
607 '{{WRAPPER}} .ui-e-offset > svg' => 'fill:{{VALUE}};',
608 '{{WRAPPER}} .ui-e-offset > i' => 'color: {{VALUE}};',
609 ],
610
611 ]
612 );
613
614 $this->add_group_control(
615 Group_Control_Background::get_type(),
616 [
617 'name' => 'icon_background',
618 'types' => [ 'classic', 'gradient', 'video' ],
619 'selector' => '{{WRAPPER}} .ui-e-ico .ui-e-offset',
620 ]
621 );
622
623 $this->end_controls_tab();
624
625 $this->start_controls_tab(
626 'icon_colors_hover',
627 [
628 'label' => esc_html__( 'Hover', 'uicore-elements' ),
629 ]
630 );
631
632 $this->add_control(
633 'icon_color_hover',
634 [
635 'label' => esc_html__( 'Icon color', 'uicore-elements' ),
636 'type' => Controls_Manager::COLOR,
637 'condition' => [
638 'icon_type!' => 'image',
639 ],
640 'selectors' => [
641 '{{WRAPPER}} > div:hover .ui-e-offset > svg' => 'fill:{{VALUE}};',
642 '{{WRAPPER}} > div:hover .ui-e-offset > i' => 'color: {{VALUE}};',
643 ],
644
645 ]
646 );
647
648 $this->add_group_control(
649 Group_Control_Background::get_type(),
650 [
651 'name' => 'icon_background_hover',
652 'types' => [ 'classic', 'gradient', 'video' ],
653 'selector' => '{{WRAPPER}} > div:hover .ui-e-offset',
654
655 ]
656 );
657
658 $this->add_control(
659 'border_color_hover',
660 [
661 'label' => esc_html__( 'Border Color', 'uicore-elements' ),
662 'type' => Controls_Manager::COLOR,
663 'selectors' => [
664 '{{WRAPPER}} > div:hover .ui-e-offset' => 'border-color: {{VALUE}}',
665 ],
666 ]
667 );
668
669 $this->end_controls_tab();
670
671 $this->end_controls_tabs();
672
673 $this->add_control(
674 'hr',
675 [
676 'type' => Controls_Manager::DIVIDER,
677 ]
678 );
679
680 $this->add_responsive_control(
681 'icon_padding',
682 [
683 'label' => esc_html__( 'Padding', 'uicore-elements' ),
684 'type' => Controls_Manager::DIMENSIONS,
685 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
686 'range' => [
687 'px' => [
688 'min' => 0,
689 'max' => 10,
690 'step' => 1,
691 ],
692 '%' => [
693 'min' => 0,
694 'max' => 20,
695 ],
696 ],
697 'default' => [
698 'unit' => 'px',
699 'size' => 25,
700 ],
701 'selectors' => [
702 '{{WRAPPER}} .ui-e-offset' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
703 ],
704
705 ]
706 );
707
708 $this->add_group_control(
709 Group_Control_Border::get_type(),
710 [
711 'name' => 'icon_border',
712 'selector' => '{{WRAPPER}} .ui-e-offset',
713
714 ]
715 );
716
717 $this->add_responsive_control(
718 'icon_radius',
719 [
720 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
721 'type' => Controls_Manager::DIMENSIONS,
722 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
723 'default' => [
724 'unit' => 'px',
725 'size' => 100,
726 ],
727 'selectors' => [
728 '{{WRAPPER}} .ui-e-offset' => 'border-top-left-radius: {{TOP}}{{UNIT}}; border-top-right-radius:{{RIGHT}}{{UNIT}}; border-bottom-right-radius:{{BOTTOM}}{{UNIT}}; border-bottom-left-radius:{{LEFT}}{{UNIT}};',
729 ],
730
731 ]
732 );
733
734 $this->add_group_control(
735 Group_Control_Box_Shadow::get_type(),
736 [
737 'name' => 'icon_shadow',
738 'selector' => '{{WRAPPER}} .ui-e-offset',
739
740 ]
741 );
742
743 $this->add_responsive_control(
744 'icon_space',
745 [
746 'label' => esc_html__( 'Icon Space', 'uicore-elements' ),
747 'type' => Controls_Manager::SLIDER,
748 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
749 'range' => [
750 'px' => [
751 'min' => 0,
752 'max' => 60,
753 'step' => 1,
754 ],
755 '%' => [
756 'min' => 0,
757 'max' => 20,
758 ],
759 ],
760 'default' => [
761 'unit' => 'px',
762 'size' => 8,
763 ],
764 'selectors' => [
765 '{{WRAPPER}}' => '--ui-e-ico-spacing: {{SIZE}}{{UNIT}}',
766 ],
767
768 ]
769 );
770
771 $this->add_control(
772 'image_fullwidth',
773 [
774 'label' => esc_html__( 'Image fullwidth', 'uicore-elements' ),
775 'type' => Controls_Manager::SWITCHER,
776 'label_on' => esc_html__( 'True', 'uicore-elements' ),
777 'label_off' => esc_html__( 'False', 'uicore-elements' ),
778 'return_value' => 'true',
779 'default' => 'false',
780 'condition' => [
781 'icon_type' => 'image',
782 ],
783 'selectors' => [
784 '{{WRAPPER}} .ui-e-offset > *' => 'width: 100%;',
785
786 ],
787 ]
788 );
789
790 $this->add_responsive_control(
791 'image_size',
792 [
793 'label' => esc_html__( 'Image Size', 'uicore-elements' ),
794 'type' => Controls_Manager::SLIDER,
795 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
796 'range' => [
797 'px' => [
798 'min' => 0,
799 'max' => 991,
800 'step' => 1,
801 ],
802 '%' => [
803 'min' => 0,
804 'max' => 100,
805 ],
806 ],
807 'default' => [
808 'unit' => 'px',
809 'size' => 120,
810 ],
811 'condition' => [
812 'icon_type' => 'image',
813 'image_fullwidth!' => 'true',
814 ],
815 'selectors' => [
816 '{{WRAPPER}} .ui-e-offset > *' => 'width: {{SIZE}}{{UNIT}};',
817
818 ],
819 ]
820 );
821
822 $this->add_responsive_control(
823 'icon_size',
824 [
825 'label' => esc_html__( 'Icon Size', 'uicore-elements' ),
826 'type' => Controls_Manager::SLIDER,
827 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
828 'range' => [
829 'px' => [
830 'min' => 8,
831 'max' => 160,
832 'step' => 1,
833 ],
834 '%' => [
835 'min' => 0,
836 'max' => 100,
837 ],
838 ],
839 'default' => [
840 'unit' => 'px',
841 'size' => 40,
842 ],
843 'condition' => [
844 'icon_type' => 'icon',
845 ],
846 'selectors' => [
847 '{{WRAPPER}}' => '--ui-e-icon-size:{{SIZE}}{{UNIT}}',
848 ],
849 ]
850 );
851
852 $this->end_controls_section();
853
854 $this->start_controls_section(
855 'counter_number_section',
856 [
857 'label' => __( 'Counter Number', 'uicore-elements' ),
858 'tab' => Controls_Manager::TAB_STYLE,
859 ]
860 );
861
862 $this->add_responsive_control(
863 'counter_number_space',
864 [
865 'label' => esc_html__( 'Number space', 'uicore-elements' ),
866 'type' => Controls_Manager::SLIDER,
867 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
868 'range' => [
869 'px' => [
870 'min' => 0,
871 'max' => 100,
872 'step' => 1,
873 ],
874 '%' => [
875 'min' => 0,
876 'max' => 100,
877 ],
878 ],
879 'default' => [
880 'unit' => 'px',
881 'size' => 0,
882 ],
883 'selectors' => [
884 '{{WRAPPER}}' => '--ui-e-num-spacing: {{SIZE}}{{UNIT}};',
885 ],
886
887 ]
888 );
889
890 $this->start_controls_tabs(
891 'counter_tabs'
892 );
893
894 $this->start_controls_tab(
895 'counter_color_normal',
896 [
897 'label' => esc_html__( 'Normal', 'uicore-elements' ),
898 ]
899 );
900
901 $this->add_control(
902 'counter_number_color',
903 [
904 'label' => esc_html__( 'Number Color', 'uicore-elements' ),
905 'type' => Controls_Manager::COLOR,
906 'selectors' => [
907 '{{WRAPPER}} .ui-e-num' => 'color: {{VALUE}}',
908 '{{WRAPPER}}' => '--ui-e-num-color: {{VALUE}}',
909 ],
910 ]
911 );
912
913 $this->end_controls_tab();
914
915 $this->start_controls_tab(
916 'counter_color_hover',
917 [
918 'label' => esc_html__( 'Hover', 'uicore-elements' ),
919 ]
920 );
921
922 $this->add_control(
923 'counter_number_color_hover',
924 [
925 'label' => esc_html__( 'Number Color', 'uicore-elements' ),
926 'type' => Controls_Manager::COLOR,
927 'selectors' => [
928 '{{WRAPPER}} > div:hover .ui-e-num' => 'color: {{VALUE}}',
929 ],
930 ]
931 );
932
933 $this->end_controls_tab();
934
935 $this->end_controls_tabs();
936
937 $this->add_group_control(
938 Group_Control_Typography::get_type(),
939 [
940 'name' => 'counter_number_typography',
941 'selector' => '{{WRAPPER}} .ui-e-num',
942 ]
943 );
944
945 $this->end_controls_section();
946
947 $this->start_controls_section(
948 'content_text_section',
949 [
950 'label' => __( 'Content Text', 'uicore-elements' ),
951 'tab' => Controls_Manager::TAB_STYLE,
952 ]
953 );
954
955 $this->start_controls_tabs(
956 'content_text_tabs'
957 );
958
959 $this->start_controls_tab(
960 'content_text_normal',
961 [
962 'label' => esc_html__( 'Normal', 'uicore-elements' ),
963 ]
964 );
965
966 $this->add_control(
967 'content_text_color',
968 [
969 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
970 'type' => Controls_Manager::COLOR,
971 'selectors' => [
972 '{{WRAPPER}} .ui-e-title' => 'color: {{VALUE}}',
973 ],
974 ]
975 );
976
977 $this->end_controls_tab();
978
979 $this->start_controls_tab(
980 'content_text_hover',
981 [
982 'label' => esc_html__( 'Hover', 'uicore-elements' ),
983 ]
984 );
985
986 $this->add_control(
987 'content_text_color_hover',
988 [
989 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
990 'type' => Controls_Manager::COLOR,
991 'selectors' => [
992 '{{WRAPPER}} > div:hover .ui-e-title' => 'color: {{VALUE}}',
993 ],
994 ]
995 );
996
997 $this->end_controls_tab();
998
999 $this->end_controls_tabs();
1000
1001 $this->add_group_control(
1002 Group_Control_Typography::get_type(),
1003 [
1004 'name' => 'content_text_typography',
1005 'selector' => '{{WRAPPER}} .ui-e-title',
1006 ]
1007 );
1008
1009 $this->end_controls_section();
1010
1011 $this->start_controls_section(
1012 'additional_section',
1013 [
1014 'label' => __( 'Additional', 'uicore-elements' ),
1015 'tab' => Controls_Manager::TAB_STYLE,
1016 ]
1017 );
1018
1019 $this->add_responsive_control(
1020 'content_padding',
1021 [
1022 'label' => esc_html__( 'Content Padding', 'uicore-elements' ),
1023 'type' => Controls_Manager::DIMENSIONS,
1024 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1025 'range' => [
1026 'px' => [
1027 'min' => 0,
1028 'max' => 80,
1029 'step' => 5,
1030 ],
1031 '%' => [
1032 'min' => 0,
1033 'max' => 100,
1034 ],
1035 ],
1036 'default' => [
1037 'unit' => 'px',
1038 'size' => 15,
1039 ],
1040 'selectors' => [
1041 '{{WRAPPER}} > div' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1042 ],
1043 ]
1044 );
1045
1046 $this->end_controls_section();
1047
1048 $this->start_controls_section(
1049 'animation_section',
1050 [
1051 'label' => __( 'Animations', 'uicore-elements' ),
1052 'tab' => Controls_Manager::TAB_STYLE,
1053 ]
1054 );
1055
1056 $this->add_control(
1057 'counter_animation',
1058 [
1059 'label' => esc_html__( 'Number animation', 'uicore-elements' ),
1060 'type' => Controls_Manager::SELECT,
1061 'default' => 'simple',
1062 'options' => [
1063 'simple' => esc_html__( 'Simple', 'uicore-elements' ),
1064 'odometer' => esc_html__( 'Odometer', 'uicore-elements' ),
1065 'motion' => esc_html__( 'Motion Blur', 'uicore-elements' ),
1066 ],
1067 'frontend_available' => true,
1068 'prefix_class' => 'ui-e-counter-',
1069 'render_type' => 'template',
1070 ]
1071 );
1072 $this->add_control(
1073 'duration',
1074 [
1075 'label' => esc_html__( 'Duration (in seconds)', 'uicore-elements' ),
1076 'type' => Controls_Manager::NUMBER,
1077 'min' => 0.1,
1078 'max' => 8.0,
1079 'step' => 0.1,
1080 'default' => 2.5,
1081 'condition' => [
1082 'counter_animation!' => 'motion',
1083 ],
1084 'frontend_available' => true,
1085 ]
1086 );
1087
1088 $this->end_controls_section();
1089
1090 }
1091 protected function render()
1092 {
1093
1094 $settings = $this->get_settings_for_display();
1095
1096 $icon_type = $settings['icon_type'];
1097 $num_tag = $settings['counter_html_tag'];
1098 $txt_tag = $settings['content_html_tag'];
1099 $media = $settings['show_icon'] ? true : false; // Check if media is enabled,
1100
1101
1102 if ($media) { // If there's media,
1103 switch($icon_type){ // get the media source
1104 case 'icon' : $icon = $settings['selected_icon']; break;
1105 case 'image' : $icon = $settings['image']; break;
1106 }
1107 $icon_width = ($icon_type == 'image' && $settings['image_fullwidth'] == 'true') ? esc_attr('large') : esc_attr('thumbnail'); // and sets the proper media size
1108 }
1109
1110 $stack = $settings['counter_text_inline'] ? false : true; // If text inline, no stack wrapper between elements is needed
1111 $title = !empty($settings['content_text']) ? '<'.esc_html($txt_tag).' class="ui-e-title">'.wp_kses_data($settings['content_text']).'</'.esc_html($txt_tag).'>' : "<!-- no title -->"; // Check if there is content for title before rendering it
1112 $number = '<'.esc_html($num_tag).' class="ui-e-num">'; // Creates $number and adds the tag opening
1113
1114 if ($settings['counter_animation'] == 'motion'){ // If animation type equals motion, we need to manually insert the numbers, prefixes and suffixes
1115 $value = $settings['count_number'];
1116 $prefix = $settings['counter_prefix'];
1117 $suffix = $settings['counter_suffix'];
1118 $numbers = str_split($value);
1119 if (!empty($prefix)) {
1120 array_unshift($numbers, $prefix);
1121 }
1122 if(!empty($suffix)){
1123 $numbers[] = $suffix;
1124 }
1125 foreach ($numbers as $n => $value) {
1126 $number .= '<span style="--index:'.esc_html($n).'">'.esc_html($value).'</span>';
1127 }
1128 }else{
1129 $number .= "0"; // Add a default value so layout is not shifted when the js add the numbers here
1130 }
1131
1132 $number .= '</'.esc_html($num_tag).'>'; // Closes the number tag
1133
1134 // Build the widget HTML
1135 if($media) : ?>
1136
1137 <div class="ui-e-ico">
1138 <div class="ui-e-offset">
1139 <?php if($icon_type == 'icon') {
1140 Icons_Manager::render_icon( $icon, [ 'aria-hidden' => 'true' ] );
1141 } else {
1142 echo wp_get_attachment_image( $icon['id'], $icon_width );
1143 } ?>
1144 </div>
1145 </div>
1146 <?php endif;
1147
1148 if($stack) { ?> <div class="ui-e-wrp"> <?php }
1149 echo wp_kses_post($number . $title);
1150 if($stack) { ?> </div> <?php }
1151 }
1152
1153 }
1154 \Elementor\Plugin::instance()->widgets_manager->register(new Counter());