experiments->is_feature_active( 'e_optimized_markup' ); } protected function carousel_content_container( int $index ) { return [ 'elType' => 'container', 'settings' => [ /* translators: %s: Item index */ '_title' => sprintf( __( 'Cel #%s', 'uicore-elements' ), $index ), 'content_width' => 'full', ], ]; } protected function get_default_children_elements() { return [ $this->carousel_content_container( 1 ), $this->carousel_content_container( 2 ), $this->carousel_content_container( 3 ), ]; } protected function get_default_repeater_title_setting_key() { return 'table_cels'; } protected function get_default_children_title() { /* translators: %d: Item index */ return esc_html__( 'Cel #%d', 'uicore-elements' ); } protected function get_default_children_placeholder_selector() { return '.ui-e-table'; } protected function register_controls() { if( !Plugin::$instance->experiments->is_feature_active('nested-elements') ) { $this->nesting_fallback('controls'); return; } $this->start_controls_section( 'section_content', [ 'label' => __('Items', 'uicore-elements'), 'tab' => Controls_Manager::TAB_CONTENT, ] ); //Columns $columns = new Repeater(); $columns->add_responsive_control( 'col_size', [ 'label' => __('Column Size', 'uicore-elements'), 'type' => Controls_Manager::SLIDER, 'size_units' => ['px', 'fr','custom'], 'default' => [ 'size' => 300, 'unit' => 'px', ], 'range' => [ 'px' => [ 'min' => 1, 'max' => 1200, ], 'fr' => [ 'min' => 1, 'max' => 12, ], ], 'render_type' => 'template', 'selectors' => [ '{{WRAPPER}}' => '--ui-e-last:{{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'columns', [ 'type' => Controls_Manager::REPEATER, 'fields' => $columns->get_controls(), 'title_field' => 'Column', 'render_type' => 'template', 'default' => [ [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ], [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ], [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ], ], ] ); //Cells $repeater = new Repeater(); $repeater->add_control( 'item', [ 'label' => __('Title', 'uicore-elements'), 'type' => Controls_Manager::TEXT, ] ); $this->add_control( 'cells', [ 'type' => Control_Nested_Repeater::CONTROL_TYPE, 'fields' => $repeater->get_controls(), 'title_field' => '{{{ item }}}', 'allow_empty' => false, 'default' => [ [ 'item' => __( 'Cel #1', 'uicore-elements' ) ], [ 'item' => __( 'Cel #2', 'uicore-elements' ) ], [ 'item' => __( 'Cel #3', 'uicore-elements' ) ], ], ] ); $this->end_controls_section(); //style $this->start_controls_section( 'section_table_style', [ 'label' => __('Table Style', 'uicore-elements'), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->start_controls_tabs( 'row_tabs' ); $this->start_controls_tab( 'odd_row', [ 'label' => esc_html__( 'Odd row', 'textdomain' ), ] ); $this->add_control( 'odd_row_bg_color', [ 'label' => __('Row background', 'uicore-elements'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ui-e-table > .ui-e-odd' => 'background-color: {{VALUE}};', ], ] ); $this->add_control( 'odd_row_padding', [ 'label' => esc_html__( 'Row Padding', 'uicore-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', 'rem', 'custom' ], 'selectors' => [ "{{WRAPPER}} .ui-e-table > .ui-e-odd" => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->add_control( 'odd_row_radius', [ 'label' => esc_html__( 'Row Border Radius', 'uicore-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', 'rem', 'custom' ], 'selectors' => [ "{{WRAPPER}} .ui-e-table > .ui-e-odd.ui-e-first-row-cel" => 'border-radius: {{TOP}}{{UNIT}} 0 0 {{LEFT}}{{UNIT}};', "{{WRAPPER}} .ui-e-table > .ui-e-odd.ui-e-last-row-cel" => 'border-radius: 0 {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} 0;' ], ] ); $this->end_controls_tab(); $this->start_controls_tab( 'even_row', [ 'label' => esc_html__( 'Even row', 'textdomain' ), ] ); $this->add_control( 'even_row_bg_color', [ 'label' => __('Row background', 'uicore-elements'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ui-e-table > .ui-e-even' => 'background-color: {{VALUE}};', ], ] ); $this->add_control( 'even_row_padding', [ 'label' => esc_html__( 'Row Padding', 'uicore-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', 'rem', 'custom' ], 'selectors' => [ "{{WRAPPER}} .ui-e-table > .ui-e-even" => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->add_control( 'even_row_radius', [ 'label' => esc_html__( 'Row Border Radius', 'uicore-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', 'rem', 'custom' ], 'selectors' => [ "{{WRAPPER}} .ui-e-table > .ui-e-even.ui-e-first-row-cel" => 'border-radius: {{TOP}}{{UNIT}} 0 0 {{LEFT}}{{UNIT}};', "{{WRAPPER}} .ui-e-table > .ui-e-even.ui-e-last-row-cel" => 'border-radius: 0 {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} 0;' ], ] ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); } protected function build_grid_css($cols) { // Build the grid columns css if ($cols) { $grid_css = ''; $grid_columns = []; $breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); foreach ($cols as $index => $item) { // Set desktop column size $grid_columns['desktop'][] = $this->get_option_size( 'col_size', ['size' => 2, 'unit' => 'fr'], true ); foreach ($breakpoints as $breakpoint => $object) { $size_slug = 'col_size_' . $breakpoint; // Register the current column responsive size if exists and the // value is not empty, because empty values breaks the table design $grid_columns[$breakpoint][] = isset($item[$size_slug]['size']) && isset($item[$size_slug]['unit']) ? $item[$size_slug]['size'] . $item[$size_slug]['unit'] : $grid_columns['desktop'][$index]; } } // Generate the css variables foreach ($grid_columns as $device => $values) { $breakpoint = $device === 'desktop' ? '' : '-' . $device; $grid_css .= '--ui-e-table-cols' . $breakpoint . ':' . implode(' ', $values) . ';'; } return $grid_css; } } public function render() { if(!Plugin::$instance->experiments->is_feature_active('nested-elements')) { $this->nesting_fallback(); return; } $cells = $this->get_settings_for_display('cells'); $cols = $this->get_settings_for_display('columns'); $grid_css = $this->build_grid_css($cols); // Add it to the widget wrapper $this->add_render_attribute('_wrapper', ['style' => $grid_css]); ?>