| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- <?php
- namespace Elementor;
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Elementor icon box widget.
- *
- * Elementor widget that displays an icon, a headline and a text.
- *
- * @since 1.0.0
- */
- class Widget_Icon_Box extends Widget_Base {
- /**
- * Get widget name.
- *
- * Retrieve icon box widget name.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget name.
- */
- public function get_name() {
- return 'icon-box';
- }
- /**
- * Get widget title.
- *
- * Retrieve icon box widget title.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget title.
- */
- public function get_title() {
- return __( 'Icon Box', 'elementor' );
- }
- /**
- * Get widget icon.
- *
- * Retrieve icon box widget icon.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget icon.
- */
- public function get_icon() {
- return 'eicon-icon-box';
- }
- /**
- * Get widget keywords.
- *
- * Retrieve the list of keywords the widget belongs to.
- *
- * @since 2.1.0
- * @access public
- *
- * @return array Widget keywords.
- */
- public function get_keywords() {
- return [ 'icon box', 'icon' ];
- }
- /**
- * Register icon box widget controls.
- *
- * Adds different input fields to allow the user to change and customize the widget settings.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _register_controls() {
- $this->start_controls_section(
- 'section_icon',
- [
- 'label' => __( 'Icon Box', 'elementor' ),
- ]
- );
- $this->add_control(
- 'icon',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'type' => Controls_Manager::ICON,
- 'default' => 'fa fa-star',
- ]
- );
- $this->add_control(
- 'view',
- [
- 'label' => __( 'View', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => [
- 'default' => __( 'Default', 'elementor' ),
- 'stacked' => __( 'Stacked', 'elementor' ),
- 'framed' => __( 'Framed', 'elementor' ),
- ],
- 'default' => 'default',
- 'prefix_class' => 'elementor-view-',
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'shape',
- [
- 'label' => __( 'Shape', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => [
- 'circle' => __( 'Circle', 'elementor' ),
- 'square' => __( 'Square', 'elementor' ),
- ],
- 'default' => 'circle',
- 'condition' => [
- 'view!' => 'default',
- 'icon!' => '',
- ],
- 'prefix_class' => 'elementor-shape-',
- ]
- );
- $this->add_control(
- 'title_text',
- [
- 'label' => __( 'Title & Description', 'elementor' ),
- 'type' => Controls_Manager::TEXT,
- 'dynamic' => [
- 'active' => true,
- ],
- 'default' => __( 'This is the heading', 'elementor' ),
- 'placeholder' => __( 'Enter your title', 'elementor' ),
- 'label_block' => true,
- ]
- );
- $this->add_control(
- 'description_text',
- [
- 'label' => '',
- 'type' => Controls_Manager::TEXTAREA,
- 'dynamic' => [
- 'active' => true,
- ],
- 'default' => __( 'Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
- 'placeholder' => __( 'Enter your description', 'elementor' ),
- 'rows' => 10,
- 'separator' => 'none',
- 'show_label' => false,
- ]
- );
- $this->add_control(
- 'link',
- [
- 'label' => __( 'Link to', 'elementor' ),
- 'type' => Controls_Manager::URL,
- 'dynamic' => [
- 'active' => true,
- ],
- 'placeholder' => __( 'https://your-link.com', 'elementor' ),
- 'separator' => 'before',
- ]
- );
- $this->add_control(
- 'position',
- [
- 'label' => __( 'Icon Position', 'elementor' ),
- 'type' => Controls_Manager::CHOOSE,
- 'default' => 'top',
- 'options' => [
- 'left' => [
- 'title' => __( 'Left', 'elementor' ),
- 'icon' => 'fa fa-align-left',
- ],
- 'top' => [
- 'title' => __( 'Top', 'elementor' ),
- 'icon' => 'fa fa-align-center',
- ],
- 'right' => [
- 'title' => __( 'Right', 'elementor' ),
- 'icon' => 'fa fa-align-right',
- ],
- ],
- 'prefix_class' => 'elementor-position-',
- 'toggle' => false,
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'title_size',
- [
- 'label' => __( 'Title HTML Tag', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => [
- 'h1' => 'H1',
- 'h2' => 'H2',
- 'h3' => 'H3',
- 'h4' => 'H4',
- 'h5' => 'H5',
- 'h6' => 'H6',
- 'div' => 'div',
- 'span' => 'span',
- 'p' => 'p',
- ],
- 'default' => 'h3',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_style_icon',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->start_controls_tabs( 'icon_colors' );
- $this->start_controls_tab(
- 'icon_colors_normal',
- [
- 'label' => __( 'Normal', 'elementor' ),
- ]
- );
- $this->add_control(
- 'primary_color',
- [
- 'label' => __( 'Primary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_1,
- ],
- 'default' => '',
- 'selectors' => [
- '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
- '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'secondary_color',
- [
- 'label' => __( 'Secondary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'condition' => [
- 'view!' => 'default',
- ],
- 'selectors' => [
- '{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
- '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
- ],
- ]
- );
- $this->end_controls_tab();
- $this->start_controls_tab(
- 'icon_colors_hover',
- [
- 'label' => __( 'Hover', 'elementor' ),
- ]
- );
- $this->add_control(
- 'hover_primary_color',
- [
- 'label' => __( 'Primary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'selectors' => [
- '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
- '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'hover_secondary_color',
- [
- 'label' => __( 'Secondary Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'condition' => [
- 'view!' => 'default',
- ],
- 'selectors' => [
- '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
- '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'hover_animation',
- [
- 'label' => __( 'Hover Animation', 'elementor' ),
- 'type' => Controls_Manager::HOVER_ANIMATION,
- ]
- );
- $this->end_controls_tab();
- $this->end_controls_tabs();
- $this->add_responsive_control(
- 'icon_space',
- [
- 'label' => __( 'Spacing', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'default' => [
- 'size' => 15,
- ],
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 100,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}}.elementor-position-right .elementor-icon-box-icon' => 'margin-left: {{SIZE}}{{UNIT}};',
- '{{WRAPPER}}.elementor-position-left .elementor-icon-box-icon' => 'margin-right: {{SIZE}}{{UNIT}};',
- '{{WRAPPER}}.elementor-position-top .elementor-icon-box-icon' => 'margin-bottom: {{SIZE}}{{UNIT}};',
- '(mobile){{WRAPPER}} .elementor-icon-box-icon' => 'margin-bottom: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_responsive_control(
- 'icon_size',
- [
- 'label' => __( 'Size', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 6,
- 'max' => 300,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_control(
- 'icon_padding',
- [
- 'label' => __( 'Padding', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
- ],
- 'range' => [
- 'em' => [
- 'min' => 0,
- 'max' => 5,
- ],
- ],
- 'condition' => [
- 'view!' => 'default',
- ],
- ]
- );
- $this->add_control(
- 'rotate',
- [
- 'label' => __( 'Rotate', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'default' => [
- 'size' => 0,
- 'unit' => 'deg',
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon i' => 'transform: rotate({{SIZE}}{{UNIT}});',
- ],
- ]
- );
- $this->add_control(
- 'border_width',
- [
- 'label' => __( 'Border Width', 'elementor' ),
- 'type' => Controls_Manager::DIMENSIONS,
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
- ],
- 'condition' => [
- 'view' => 'framed',
- ],
- ]
- );
- $this->add_control(
- 'border_radius',
- [
- 'label' => __( 'Border Radius', 'elementor' ),
- 'type' => Controls_Manager::DIMENSIONS,
- 'size_units' => [ 'px', '%' ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
- ],
- 'condition' => [
- 'view!' => 'default',
- ],
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_style_content',
- [
- 'label' => __( 'Content', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_responsive_control(
- 'text_align',
- [
- 'label' => __( 'Alignment', 'elementor' ),
- 'type' => Controls_Manager::CHOOSE,
- 'options' => [
- 'left' => [
- 'title' => __( 'Left', 'elementor' ),
- 'icon' => 'fa fa-align-left',
- ],
- 'center' => [
- 'title' => __( 'Center', 'elementor' ),
- 'icon' => 'fa fa-align-center',
- ],
- 'right' => [
- 'title' => __( 'Right', 'elementor' ),
- 'icon' => 'fa fa-align-right',
- ],
- 'justify' => [
- 'title' => __( 'Justified', 'elementor' ),
- 'icon' => 'fa fa-align-justify',
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon-box-wrapper' => 'text-align: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'content_vertical_alignment',
- [
- 'label' => __( 'Vertical Alignment', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => [
- 'top' => __( 'Top', 'elementor' ),
- 'middle' => __( 'Middle', 'elementor' ),
- 'bottom' => __( 'Bottom', 'elementor' ),
- ],
- 'default' => 'top',
- 'prefix_class' => 'elementor-vertical-align-',
- ]
- );
- $this->add_control(
- 'heading_title',
- [
- 'label' => __( 'Title', 'elementor' ),
- 'type' => Controls_Manager::HEADING,
- 'separator' => 'before',
- ]
- );
- $this->add_responsive_control(
- 'title_bottom_space',
- [
- 'label' => __( 'Spacing', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 100,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_control(
- 'title_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon-box-content .elementor-icon-box-title' => 'color: {{VALUE}};',
- ],
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_1,
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Typography::get_type(),
- [
- 'name' => 'title_typography',
- 'selector' => '{{WRAPPER}} .elementor-icon-box-content .elementor-icon-box-title',
- 'scheme' => Scheme_Typography::TYPOGRAPHY_1,
- ]
- );
- $this->add_control(
- 'heading_description',
- [
- 'label' => __( 'Description', 'elementor' ),
- 'type' => Controls_Manager::HEADING,
- 'separator' => 'before',
- ]
- );
- $this->add_control(
- 'description_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'default' => '',
- 'selectors' => [
- '{{WRAPPER}} .elementor-icon-box-content .elementor-icon-box-description' => 'color: {{VALUE}};',
- ],
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_3,
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Typography::get_type(),
- [
- 'name' => 'description_typography',
- 'selector' => '{{WRAPPER}} .elementor-icon-box-content .elementor-icon-box-description',
- 'scheme' => Scheme_Typography::TYPOGRAPHY_3,
- ]
- );
- $this->end_controls_section();
- }
- /**
- * Render icon box widget output on the frontend.
- *
- * Written in PHP and used to generate the final HTML.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function render() {
- $settings = $this->get_settings_for_display();
- $this->add_render_attribute( 'icon', 'class', [ 'elementor-icon', 'elementor-animation-' . $settings['hover_animation'] ] );
- $icon_tag = 'span';
- $has_icon = ! empty( $settings['icon'] );
- if ( ! empty( $settings['link']['url'] ) ) {
- $this->add_render_attribute( 'link', 'href', $settings['link']['url'] );
- $icon_tag = 'a';
- if ( $settings['link']['is_external'] ) {
- $this->add_render_attribute( 'link', 'target', '_blank' );
- }
- if ( $settings['link']['nofollow'] ) {
- $this->add_render_attribute( 'link', 'rel', 'nofollow' );
- }
- }
- if ( $has_icon ) {
- $this->add_render_attribute( 'i', 'class', $settings['icon'] );
- $this->add_render_attribute( 'i', 'aria-hidden', 'true' );
- }
- $icon_attributes = $this->get_render_attribute_string( 'icon' );
- $link_attributes = $this->get_render_attribute_string( 'link' );
- $this->add_render_attribute( 'description_text', 'class', 'elementor-icon-box-description' );
- $this->add_inline_editing_attributes( 'title_text', 'none' );
- $this->add_inline_editing_attributes( 'description_text' );
- ?>
- <div class="elementor-icon-box-wrapper">
- <?php if ( $has_icon ) : ?>
- <div class="elementor-icon-box-icon">
- <<?php echo implode( ' ', [ $icon_tag, $icon_attributes, $link_attributes ] ); ?>>
- <i <?php echo $this->get_render_attribute_string( 'i' ); ?>></i>
- </<?php echo $icon_tag; ?>>
- </div>
- <?php endif; ?>
- <div class="elementor-icon-box-content">
- <<?php echo $settings['title_size']; ?> class="elementor-icon-box-title">
- <<?php echo implode( ' ', [ $icon_tag, $link_attributes ] ); ?><?php echo $this->get_render_attribute_string( 'title_text' ); ?>><?php echo $settings['title_text']; ?></<?php echo $icon_tag; ?>>
- </<?php echo $settings['title_size']; ?>>
- <p <?php echo $this->get_render_attribute_string( 'description_text' ); ?>><?php echo $settings['description_text']; ?></p>
- </div>
- </div>
- <?php
- }
- /**
- * Render icon box widget output in the editor.
- *
- * Written as a Backbone JavaScript template and used to generate the live preview.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _content_template() {
- ?>
- <#
- var link = settings.link.url ? 'href="' + settings.link.url + '"' : '',
- iconTag = link ? 'a' : 'span';
- view.addRenderAttribute( 'description_text', 'class', 'elementor-icon-box-description' );
- view.addInlineEditingAttributes( 'title_text', 'none' );
- view.addInlineEditingAttributes( 'description_text' );
- #>
- <div class="elementor-icon-box-wrapper">
- <# if ( settings.icon ) { #>
- <div class="elementor-icon-box-icon">
- <{{{ iconTag + ' ' + link }}} class="elementor-icon elementor-animation-{{ settings.hover_animation }}">
- <i class="{{ settings.icon }}" aria-hidden="true"></i>
- </{{{ iconTag }}}>
- </div>
- <# } #>
- <div class="elementor-icon-box-content">
- <{{{ settings.title_size }}} class="elementor-icon-box-title">
- <{{{ iconTag + ' ' + link }}} {{{ view.getRenderAttributeString( 'title_text' ) }}}>{{{ settings.title_text }}}</{{{ iconTag }}}>
- </{{{ settings.title_size }}}>
- <p {{{ view.getRenderAttributeString( 'description_text' ) }}}>{{{ settings.description_text }}}</p>
- </div>
- </div>
- <?php
- }
- }
|