elementor
/
modules
/
atomic-widgets
/
elements
/
atomic-tabs
/
atomic-tab-content
/
atomic-tab-content.php
atomic-tab-content.php in Elementor Website Builder – more than just a page builder 4.3.2, at modules/atomic-widgets/elements/atomic-tabs/atomic-tab-content/atomic-tab-content.php
| 1 | <?php |
| 2 | namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs\Atomic_Tab_Content; |
| 3 | |
| 4 | use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 5 | use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; |
| 6 | use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer; |
| 7 | use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 9 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 10 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 11 | use Elementor\Modules\AtomicWidgets\Styles\Style_States; |
| 12 | use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 13 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 14 | use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 15 | use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context; |
| 16 | use Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs\Atomic_Tabs\Atomic_Tabs; |
| 17 | use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 18 | |
| 19 | |
| 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | exit; // Exit if accessed directly. |
| 22 | } |
| 23 | |
| 24 | class Atomic_Tab_Content extends Atomic_Element_Base { |
| 25 | use Has_Element_Template; |
| 26 | |
| 27 | const BASE_STYLE_KEY = 'base'; |
| 28 | |
| 29 | public static $widget_description = 'A tab content panel. Accepts any widget type inside. The index of this e-tab-content MUST match the index of the corresponding e-tab in the e-tabs-menu.'; |
| 30 | |
| 31 | public function __construct( $data = [], $args = null ) { |
| 32 | parent::__construct( $data, $args ); |
| 33 | $this->meta( 'permanently_locked', true ); |
| 34 | } |
| 35 | |
| 36 | public static function get_type() { |
| 37 | return 'e-tab-content'; |
| 38 | } |
| 39 | |
| 40 | public static function get_element_type(): string { |
| 41 | return 'e-tab-content'; |
| 42 | } |
| 43 | |
| 44 | public function get_title() { |
| 45 | return esc_html__( 'Tab content', 'elementor' ); |
| 46 | } |
| 47 | |
| 48 | public function get_keywords() { |
| 49 | return [ 'ato', 'atom', 'atoms', 'atomic', 'tab', 'content', 'tabs' ]; |
| 50 | } |
| 51 | |
| 52 | public function get_icon() { |
| 53 | return 'eicon-layout'; |
| 54 | } |
| 55 | |
| 56 | public function should_show_in_panel() { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | public static function get_computed_html_tag( array $settings ): string { |
| 61 | return Html_Tag_Computer::compute( $settings, 'div' ); |
| 62 | } |
| 63 | |
| 64 | protected static function define_props_schema(): array { |
| 65 | return [ |
| 66 | 'classes' => Classes_Prop_Type::make() |
| 67 | ->default( [] ), |
| 68 | 'tab-id' => String_Prop_Type::make(), |
| 69 | 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | protected function define_atomic_controls(): array { |
| 74 | return [ |
| 75 | Section::make() |
| 76 | ->set_label( __( 'Settings', 'elementor' ) ) |
| 77 | ->set_id( 'settings' ) |
| 78 | ->set_items( [] ), |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | protected function define_atomic_style_states(): array { |
| 83 | $selected_state = Style_States::get_class_states_map()['selected']; |
| 84 | |
| 85 | return [ $selected_state ]; |
| 86 | } |
| 87 | |
| 88 | protected function define_base_styles(): array { |
| 89 | $styles = [ |
| 90 | 'display' => String_Prop_Type::generate( 'block' ), |
| 91 | 'padding' => Size_Prop_Type::generate( [ |
| 92 | 'size' => 10, |
| 93 | 'unit' => 'px', |
| 94 | ] ), |
| 95 | 'min-width' => Size_Prop_Type::generate( [ |
| 96 | 'size' => 30, |
| 97 | 'unit' => 'px', |
| 98 | ] ), |
| 99 | ]; |
| 100 | |
| 101 | return [ |
| 102 | static::BASE_STYLE_KEY => Style_Definition::make() |
| 103 | ->add_variant( |
| 104 | Style_Variant::make() |
| 105 | ->add_props( $styles ) |
| 106 | ), |
| 107 | ]; |
| 108 | } |
| 109 | |
| 110 | protected function define_initial_attributes() { |
| 111 | return [ |
| 112 | 'role' => 'tabpanel', |
| 113 | ]; |
| 114 | } |
| 115 | |
| 116 | protected function get_templates(): array { |
| 117 | return [ |
| 118 | 'elementor/elements/atomic-tab-content' => __DIR__ . '/atomic-tab-content.html.twig', |
| 119 | ]; |
| 120 | } |
| 121 | |
| 122 | protected function build_template_context(): array { |
| 123 | $tabs_context = Render_Context::get( Atomic_Tabs::class ); |
| 124 | $default_active_tab = $tabs_context['default-active-tab']; |
| 125 | $get_tab_content_index = $tabs_context['get-tab-content-index']; |
| 126 | $tabs_id = $tabs_context['tabs-id']; |
| 127 | |
| 128 | $index = $get_tab_content_index( $this->get_id() ); |
| 129 | $is_active = $default_active_tab === $index; |
| 130 | |
| 131 | return array_merge( $this->build_base_template_context(), [ |
| 132 | 'is_active' => $is_active, |
| 133 | 'tab_id' => Atomic_Tabs::get_tab_id( $tabs_id, $index ), |
| 134 | 'tab_content_id' => Atomic_Tabs::get_tab_content_id( $tabs_id, $index ), |
| 135 | ] ); |
| 136 | } |
| 137 | } |
| 138 |