Skip to content

Commit

Permalink
Control for color and Typography for table is added
Browse files Browse the repository at this point in the history
  • Loading branch information
codersaiful committed Feb 3, 2021
1 parent 7ee0ca7 commit 65bb46d
Showing 1 changed file with 190 additions and 35 deletions.
225 changes: 190 additions & 35 deletions modules/elementor-widget.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Background;
use Elementor\Repeater;


class WPT_Elementor_Widget extends \Elementor\Widget_Base{

Expand Down Expand Up @@ -68,11 +79,51 @@ public function get_categories() {
*/
protected function _register_controls() {

$this->start_controls_section(
'content_section',
//For General/Content Tab
$this->content_general();

//For Typography Section Style Tab
$this->style_table_head();

//For Typography Section Style Tab
$this->style_table_body();


}

/**
* Render oEmbed 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();
$table_id = isset( $settings['table_id'] ) && !empty( $settings['table_id'] ) ? $settings['table_id'] : false;
if( $table_id && is_numeric( $table_id ) ){
$name = get_the_title( $table_id );
$shortcode = "[Product_Table id='{$table_id}' name='{$name}']";
$shortcode = do_shortcode( shortcode_unautop( $shortcode ) );
?>
<div class="wpt-elementor-wrapper wpt-elementor-wrapper-<?php echo esc_attr( $table_id ); ?>">
<?php echo $shortcode; ?>
</div>
<?php
}else{
echo '<h2 class="wpt_elmnt_select_note">';
echo esc_html__( 'Please select a Table.', 'wpt_pro' );
echo '</h2>';
}
}

protected function content_general() {
$this->start_controls_section(
'general',
[
'label' => __( 'Content', 'wpt_pro' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
'label' => __( 'General', 'wpt_pro' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);

Expand All @@ -94,7 +145,7 @@ protected function _register_controls() {
//$table_options[''] = esc_html__( 'Please Choose a Table', 'wpt_pro' );
else:
$table_options = false;
//\Elementor\Controls_Manager::HEADING
//Controls_Manager::HEADING
endif;


Expand All @@ -105,7 +156,7 @@ protected function _register_controls() {
'table_id',
[
'label' => __( 'Table List', 'wpt_pro' ),
'type' => \Elementor\Controls_Manager::SELECT,
'type' => Controls_Manager::SELECT,
'options' => $table_options,
//'default' => '',
]
Expand All @@ -115,7 +166,7 @@ protected function _register_controls() {
'table_edit',
[
'label' => __( 'Additional Info', 'wpt_pro' ),
'type' => \Elementor\Controls_Manager::RAW_HTML,
'type' => Controls_Manager::RAW_HTML,
'raw' => sprintf(
__( 'Edit your %sTable%s.', 'wpt_pro' ),
'<a href="' . esc_attr( admin_url( 'post.php?post=' . $table_ID . '&action=edit&classic-editor' ) ) . '">',
Expand All @@ -133,7 +184,7 @@ protected function _register_controls() {
'table_notification',
[
'label' => __( 'Additional Information', 'wpt_pro' ),
'type' => \Elementor\Controls_Manager::RAW_HTML,
'type' => Controls_Manager::RAW_HTML,
'raw' => $wpt_extra_msg . sprintf(
__( 'Create %sa new table%s.', 'wpt_pro' ),
'<a href="' . admin_url( 'post-new.php?post_type=wpt_product_table' ) . '">',
Expand All @@ -145,33 +196,137 @@ protected function _register_controls() {

$this->end_controls_section();

}
}

/**
* Typography Section for Style Tab
*
* @since 1.0.0.9
*/
protected function style_table_head() {
$this->start_controls_section(
'thead',
[
'label' => esc_html__( 'Table Head', 'medilac' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);

/**
* Render oEmbed 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();
$table_id = isset( $settings['table_id'] ) && !empty( $settings['table_id'] ) ? $settings['table_id'] : false;
if( $table_id && is_numeric( $table_id ) ){
$name = get_the_title( $table_id );
$shortcode = "[Product_Table id='{$table_id}' name='{$name}']";
$shortcode = do_shortcode( shortcode_unautop( $shortcode ) );
?>
<div class="wpt-elementor-wrapper wpt-elementor-wrapper-<?php echo esc_attr( $table_id ); ?>">
<?php echo $shortcode; ?>
</div>
<?php
}else{
echo '<h2 class="wpt_elmnt_select_note">';
echo esc_html__( 'Please select a Table.', 'wpt_pro' );
echo '</h2>';
}
}
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'thead_typography',
'global' => [
'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
],
'selector' => '{{WRAPPER}} table.wpt_product_table thead tr th',
]
);

$this->add_control(
'thead-color',
[
'label' => __( 'Color', 'medilac' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} table.wpt_product_table thead tr th' => 'color: {{VALUE}}',
],
'default' => '#ffffff',
]
);

$this->add_control(
'thead-bg-color',
[
'label' => __( 'Background Color', 'medilac' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} table.wpt_product_table thead tr th' => 'background-color: {{VALUE}}',
],
'default' => '#0a7f9c',
]
);



$this->end_controls_section();
}



/**
* Typography Section for Style Tab
*
* @since 1.0.0.9
*/
protected function style_table_body() {


$this->start_controls_section(
'tbody',
[
'label' => esc_html__( 'Table Body', 'medilac' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);

$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'tbody_typography',
'global' => [
'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
],
'selectors' => [
'{{WRAPPER}} table.wpt_product_table tbody tr td',
'{{WRAPPER}} table.wpt_product_table tbody tr td a',
'{{WRAPPER}} table.wpt_product_table tbody tr td p',
'{{WRAPPER}} table.wpt_product_table tbody tr td div',
],
]
);

$this->add_control(
'tbody-text-color',
[
'label' => __( 'Text Color', 'medilac' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} table.wpt_product_table tbody tr td' => 'color: {{VALUE}}',
'{{WRAPPER}} table.wpt_product_table tbody tr td p' => 'color: {{VALUE}}',
'{{WRAPPER}} table.wpt_product_table tbody tr td div' => 'color: {{VALUE}}',
],
'default' => '#535353',
]
);

$this->add_control(
'tbody-title-color',
[
'label' => __( 'Product Title Color', 'medilac' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} table.wpt_product_table tbody tr td .product_title a' => 'color: {{VALUE}}',
],
'default' => '#000',
]
);


$this->add_control(
'tbody-bg-color',
[
'label' => __( 'Background Color', 'medilac' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} table.wpt_product_table tbody tr td' => 'background-color: {{VALUE}}',
],
//'default' => '#fff',
]
);

$this->end_controls_section();
}


}

0 comments on commit 65bb46d

Please sign in to comment.