| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Elements\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\Controls\Section; |
| 10 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Elements\Tabs_Control; |
| 14 |
|
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Exit if accessed directly. |
| 18 |
} |
| 19 |
|
| 20 |
class Atomic_Tabs extends Atomic_Element_Base { |
| 21 |
const BASE_STYLE_KEY = 'base'; |
| 22 |
|
| 23 |
public static function get_type() { |
| 24 |
return 'e-tabs'; |
| 25 |
} |
| 26 |
|
| 27 |
public static function get_element_type(): string { |
| 28 |
return 'e-tabs'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_title() { |
| 32 |
return esc_html__( 'Atomic Tabs', 'elementor' ); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_keywords() { |
| 36 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_icon() { |
| 40 |
return 'eicon-tabs'; |
| 41 |
} |
| 42 |
|
| 43 |
protected static function define_props_schema(): array { |
| 44 |
return [ |
| 45 |
'classes' => Classes_Prop_Type::make() |
| 46 |
->default( [] ), |
| 47 |
'default-active-tab' => String_Prop_Type::make(), |
| 48 |
'attributes' => Attributes_Prop_Type::make(), |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
protected function define_atomic_controls(): array { |
| 53 |
return [ |
| 54 |
Section::make() |
| 55 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 56 |
->set_id( 'settings' ) |
| 57 |
->set_items( [ |
| 58 |
Text_Control::bind_to( '_cssid' ) |
| 59 |
->set_label( __( 'ID', 'elementor' ) ) |
| 60 |
->set_meta( $this->get_css_id_control_meta() ), |
| 61 |
Tabs_Control::make() |
| 62 |
->set_label( __( 'Menu items', 'elementor' ) ) |
| 63 |
->set_meta( [ |
| 64 |
'topDivider' => true, |
| 65 |
'layout' => 'custom', |
| 66 |
] ), |
| 67 |
] ), |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
protected function define_base_styles(): array { |
| 72 |
$display = String_Prop_Type::generate( 'block' ); |
| 73 |
|
| 74 |
return [ |
| 75 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 76 |
->add_variant( |
| 77 |
Style_Variant::make() |
| 78 |
->add_prop( 'display', $display ) |
| 79 |
->add_prop( 'padding', $this->get_base_padding() ) |
| 80 |
->add_prop( 'min-width', $this->get_base_min_width() ) |
| 81 |
), |
| 82 |
]; |
| 83 |
} |
| 84 |
|
| 85 |
protected function get_base_padding(): array { |
| 86 |
return Size_Prop_Type::generate( [ |
| 87 |
'size' => 10, |
| 88 |
'unit' => 'px', |
| 89 |
] ); |
| 90 |
} |
| 91 |
|
| 92 |
protected function get_base_min_width(): array { |
| 93 |
return Size_Prop_Type::generate( [ |
| 94 |
'size' => 30, |
| 95 |
'unit' => 'px', |
| 96 |
] ); |
| 97 |
} |
| 98 |
|
| 99 |
protected function define_default_children() { |
| 100 |
$default_tab_count = 3; |
| 101 |
$tab_elements = []; |
| 102 |
$tab_panel_elements = []; |
| 103 |
|
| 104 |
foreach ( range( 1, $default_tab_count ) as $i ) { |
| 105 |
$tab_elements[] = Atomic_Tab::generate() |
| 106 |
->editor_settings( [ |
| 107 |
'title' => "Tab {$i}", |
| 108 |
] ) |
| 109 |
->is_locked( true ) |
| 110 |
->build(); |
| 111 |
|
| 112 |
$tab_panel_elements[] = Atomic_Tab_Panel::generate() |
| 113 |
->is_locked( true ) |
| 114 |
->editor_settings( [ |
| 115 |
'title' => "Tab {$i} panel", |
| 116 |
] ) |
| 117 |
->build(); |
| 118 |
} |
| 119 |
|
| 120 |
$tabs_list = Atomic_Tabs_List::generate() |
| 121 |
->children( $tab_elements ) |
| 122 |
->is_locked( true ) |
| 123 |
->build(); |
| 124 |
|
| 125 |
$tabs_content = Atomic_Tabs_Content::generate() |
| 126 |
->children( $tab_panel_elements ) |
| 127 |
->is_locked( true ) |
| 128 |
->build(); |
| 129 |
|
| 130 |
return [ |
| 131 |
$tabs_list, |
| 132 |
$tabs_content, |
| 133 |
]; |
| 134 |
} |
| 135 |
|
| 136 |
public function define_initial_attributes() { |
| 137 |
return [ |
| 138 |
'data-e-type' => $this->get_type(), |
| 139 |
]; |
| 140 |
} |
| 141 |
|
| 142 |
public function get_script_depends() { |
| 143 |
return [ 'elementor-tabs-handler' ]; |
| 144 |
} |
| 145 |
|
| 146 |
protected function add_render_attributes() { |
| 147 |
parent::add_render_attributes(); |
| 148 |
$settings = $this->get_atomic_settings(); |
| 149 |
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ]; |
| 150 |
$initial_attributes = $this->define_initial_attributes(); |
| 151 |
|
| 152 |
$attributes = [ |
| 153 |
'class' => [ |
| 154 |
'e-con', |
| 155 |
'e-atomic-element', |
| 156 |
$base_style_class, |
| 157 |
...( $settings['classes'] ?? [] ), |
| 158 |
], |
| 159 |
]; |
| 160 |
|
| 161 |
if ( ! empty( $settings['default-active-tab'] ) ) { |
| 162 |
$attributes['data-active-tab'] = esc_attr( $settings['default-active-tab'] ); |
| 163 |
} |
| 164 |
|
| 165 |
if ( ! empty( $settings['_cssid'] ) ) { |
| 166 |
$attributes['id'] = esc_attr( $settings['_cssid'] ); |
| 167 |
} |
| 168 |
|
| 169 |
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) ); |
| 170 |
} |
| 171 |
} |
| 172 |
|