| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs\Atomic_Tab; |
| 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\PropTypes\Primitives\String_Prop_Type; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 8 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 9 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 10 |
use Elementor\Modules\AtomicWidgets\Styles\Style_States; |
| 11 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Html_V3_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph; |
| 15 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 16 |
use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; |
| 17 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context; |
| 18 |
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Prop_Type; |
| 19 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs\Atomic_Tabs\Atomic_Tabs; |
| 20 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 21 |
|
| 22 |
if ( ! defined( 'ABSPATH' ) ) { |
| 23 |
exit; // Exit if accessed directly. |
| 24 |
} |
| 25 |
|
| 26 |
class Atomic_Tab extends Atomic_Element_Base { |
| 27 |
use Has_Element_Template; |
| 28 |
|
| 29 |
const BASE_STYLE_KEY = 'base'; |
| 30 |
|
| 31 |
public function __construct( $data = [], $args = null ) { |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
$this->meta( 'llm_support', false ); |
| 34 |
} |
| 35 |
|
| 36 |
public static function get_type() { |
| 37 |
return 'e-tab'; |
| 38 |
} |
| 39 |
|
| 40 |
public static function get_element_type(): string { |
| 41 |
return 'e-tab'; |
| 42 |
} |
| 43 |
|
| 44 |
public function get_title() { |
| 45 |
return esc_html__( 'Tab trigger', 'elementor' ); |
| 46 |
} |
| 47 |
|
| 48 |
public function get_keywords() { |
| 49 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 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 |
protected static function define_props_schema(): array { |
| 61 |
return [ |
| 62 |
'classes' => Classes_Prop_Type::make() |
| 63 |
->default( [] ), |
| 64 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 65 |
]; |
| 66 |
} |
| 67 |
|
| 68 |
protected function define_atomic_controls(): array { |
| 69 |
return [ |
| 70 |
Section::make() |
| 71 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 72 |
->set_id( 'settings' ) |
| 73 |
->set_items( [] ), |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
protected function define_atomic_style_states(): array { |
| 78 |
$selected_state = Style_States::get_class_states_map()['selected']; |
| 79 |
|
| 80 |
return [ $selected_state ]; |
| 81 |
} |
| 82 |
|
| 83 |
protected function define_base_styles(): array { |
| 84 |
$styles = [ |
| 85 |
'display' => String_Prop_Type::generate( 'block' ), |
| 86 |
'cursor' => String_Prop_Type::generate( 'pointer' ), |
| 87 |
'color' => Color_Prop_Type::generate( '#0C0D0E' ), |
| 88 |
'border-style' => String_Prop_Type::generate( 'solid' ), |
| 89 |
'border-color' => Color_Prop_Type::generate( '#E0E0E0' ), |
| 90 |
'border-width' => Size_Prop_Type::generate( [ |
| 91 |
'size' => 2, |
| 92 |
'unit' => 'px', |
| 93 |
]), |
| 94 |
'padding' => Size_Prop_Type::generate( [ |
| 95 |
'size' => 8, |
| 96 |
'unit' => 'px', |
| 97 |
]), |
| 98 |
'width' => Size_Prop_Type::generate( [ |
| 99 |
'size' => 160, |
| 100 |
'unit' => 'px', |
| 101 |
]), |
| 102 |
'background' => Background_Prop_Type::generate( [ |
| 103 |
'color' => Color_Prop_Type::generate( '#FFFFFF' ), |
| 104 |
]), |
| 105 |
]; |
| 106 |
|
| 107 |
$selected_styles = [ |
| 108 |
'outline-width' => Size_Prop_Type::generate( [ |
| 109 |
'size' => 0, |
| 110 |
'unit' => 'px', |
| 111 |
]), |
| 112 |
'border-color' => Color_Prop_Type::generate( '#0C0D0E' ), |
| 113 |
]; |
| 114 |
|
| 115 |
$hover_styles = [ |
| 116 |
'background' => Background_Prop_Type::generate( [ |
| 117 |
'color' => Color_Prop_Type::generate( '#E0E0E0' ), |
| 118 |
]), |
| 119 |
]; |
| 120 |
|
| 121 |
return [ |
| 122 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 123 |
->add_variant( |
| 124 |
Style_Variant::make() |
| 125 |
->add_props( $styles ) |
| 126 |
) |
| 127 |
->add_variant( |
| 128 |
Style_Variant::make() |
| 129 |
->set_state( Style_States::SELECTED ) |
| 130 |
->add_props( $selected_styles ) |
| 131 |
) |
| 132 |
->add_variant( |
| 133 |
Style_Variant::make() |
| 134 |
->set_state( Style_States::FOCUS ) |
| 135 |
->add_props( $selected_styles ) |
| 136 |
) |
| 137 |
->add_variant( |
| 138 |
Style_Variant::make() |
| 139 |
->set_state( Style_States::HOVER ) |
| 140 |
->add_props( $hover_styles ) |
| 141 |
), |
| 142 |
]; |
| 143 |
} |
| 144 |
|
| 145 |
protected function define_initial_attributes() { |
| 146 |
return [ |
| 147 |
'role' => 'tab', |
| 148 |
'tabindex' => '-1', |
| 149 |
]; |
| 150 |
} |
| 151 |
|
| 152 |
protected function define_default_html_tag() { |
| 153 |
return 'button'; |
| 154 |
} |
| 155 |
|
| 156 |
protected function define_default_children() { |
| 157 |
return [ |
| 158 |
Atomic_Paragraph::generate() |
| 159 |
->settings( [ |
| 160 |
'paragraph' => Html_V3_Prop_Type::generate( [ |
| 161 |
'content' => String_Prop_Type::generate( 'Tab' ), |
| 162 |
'children' => [], |
| 163 |
] ), |
| 164 |
'tag' => String_Prop_Type::generate( 'span' ), |
| 165 |
] ) |
| 166 |
->build(), |
| 167 |
]; |
| 168 |
} |
| 169 |
|
| 170 |
protected function get_templates(): array { |
| 171 |
return [ |
| 172 |
'elementor/elements/atomic-tab' => __DIR__ . '/atomic-tab.html.twig', |
| 173 |
]; |
| 174 |
} |
| 175 |
|
| 176 |
protected function build_template_context(): array { |
| 177 |
$tabs_context = Render_Context::get( Atomic_Tabs::class ); |
| 178 |
$default_active_tab = $tabs_context['default-active-tab']; |
| 179 |
$get_tab_index = $tabs_context['get-tab-index']; |
| 180 |
$tabs_id = $tabs_context['tabs-id']; |
| 181 |
|
| 182 |
$index = $get_tab_index( $this->get_id() ); |
| 183 |
$is_active = $default_active_tab === $index; |
| 184 |
|
| 185 |
return array_merge( $this->build_base_template_context(), [ |
| 186 |
'is_active' => $is_active, |
| 187 |
'tab_id' => Atomic_Tabs::get_tab_id( $tabs_id, $index ), |
| 188 |
'tab_content_id' => Atomic_Tabs::get_tab_content_id( $tabs_id, $index ), |
| 189 |
] ); |
| 190 |
} |
| 191 |
} |
| 192 |
|