| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 5 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 6 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 7 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 8 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 9 |
use Elementor\Modules\AtomicWidgets\Styles\Style_States; |
| 10 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context; |
| 14 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 15 |
|
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; // Exit if accessed directly. |
| 19 |
} |
| 20 |
|
| 21 |
class Atomic_Tab_Content extends Atomic_Element_Base { |
| 22 |
const BASE_STYLE_KEY = 'base'; |
| 23 |
|
| 24 |
public function __construct( $data = [], $args = null ) { |
| 25 |
parent::__construct( $data, $args ); |
| 26 |
$this->meta( 'llm_support', false ); |
| 27 |
} |
| 28 |
|
| 29 |
public static function get_type() { |
| 30 |
return 'e-tab-content'; |
| 31 |
} |
| 32 |
|
| 33 |
public static function get_element_type(): string { |
| 34 |
return 'e-tab-content'; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_title() { |
| 38 |
return esc_html__( 'Tab content', 'elementor' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_keywords() { |
| 42 |
return [ 'ato', 'atom', 'atoms', 'atomic', 'tab', 'content', 'tabs' ]; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_icon() { |
| 46 |
return 'eicon-layout'; |
| 47 |
} |
| 48 |
|
| 49 |
public function should_show_in_panel() { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
protected static function define_props_schema(): array { |
| 54 |
return [ |
| 55 |
'classes' => Classes_Prop_Type::make() |
| 56 |
->default( [] ), |
| 57 |
'tab-id' => String_Prop_Type::make(), |
| 58 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
protected function define_atomic_controls(): array { |
| 63 |
return [ |
| 64 |
Section::make() |
| 65 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 66 |
->set_id( 'settings' ) |
| 67 |
->set_items( [] ), |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
protected function define_atomic_style_states(): array { |
| 72 |
$selected_state = Style_States::get_class_states_map()['selected']; |
| 73 |
|
| 74 |
return [ $selected_state ]; |
| 75 |
} |
| 76 |
|
| 77 |
protected function define_base_styles(): array { |
| 78 |
$styles = [ |
| 79 |
'display' => String_Prop_Type::generate( 'block' ), |
| 80 |
'padding' => Size_Prop_Type::generate( [ |
| 81 |
'size' => 10, |
| 82 |
'unit' => 'px', |
| 83 |
] ), |
| 84 |
'min-width' => Size_Prop_Type::generate( [ |
| 85 |
'size' => 30, |
| 86 |
'unit' => 'px', |
| 87 |
] ), |
| 88 |
]; |
| 89 |
|
| 90 |
return [ |
| 91 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 92 |
->add_variant( |
| 93 |
Style_Variant::make() |
| 94 |
->add_props( $styles ) |
| 95 |
), |
| 96 |
]; |
| 97 |
} |
| 98 |
|
| 99 |
protected function define_initial_attributes() { |
| 100 |
return [ |
| 101 |
'role' => 'tabpanel', |
| 102 |
]; |
| 103 |
} |
| 104 |
|
| 105 |
protected function add_render_attributes() { |
| 106 |
parent::add_render_attributes(); |
| 107 |
$settings = $this->get_atomic_settings(); |
| 108 |
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ]; |
| 109 |
$initial_attributes = $this->define_initial_attributes(); |
| 110 |
|
| 111 |
$tabs_context = Render_Context::get( Atomic_Tabs::class ); |
| 112 |
$default_active_tab = $tabs_context['default-active-tab']; |
| 113 |
$get_tab_content_index = $tabs_context['get-tab-content-index']; |
| 114 |
$tabs_id = $tabs_context['tabs-id']; |
| 115 |
|
| 116 |
$index = $get_tab_content_index( $this->get_id() ); |
| 117 |
$is_active = $default_active_tab === $index; |
| 118 |
|
| 119 |
$attributes = [ |
| 120 |
'class' => [ |
| 121 |
'e-con', |
| 122 |
'e-atomic-element', |
| 123 |
$base_style_class, |
| 124 |
...( $settings['classes'] ?? [] ), |
| 125 |
], |
| 126 |
'x-bind' => 'tabContent', |
| 127 |
'id' => Atomic_Tabs::get_tab_content_id( $tabs_id, $index ), |
| 128 |
'aria-labelledby' => Atomic_Tabs::get_tab_id( $tabs_id, $index ), |
| 129 |
]; |
| 130 |
|
| 131 |
if ( ! $is_active ) { |
| 132 |
$attributes['hidden'] = 'true'; |
| 133 |
$attributes['style'] = 'display: none;'; |
| 134 |
} |
| 135 |
|
| 136 |
if ( ! empty( $settings['_cssid'] ) ) { |
| 137 |
$attributes['id'] = esc_attr( $settings['_cssid'] ); |
| 138 |
} |
| 139 |
|
| 140 |
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) ); |
| 141 |
} |
| 142 |
} |
| 143 |
|