| 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\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\Escaped_Html_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph; |
| 16 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 17 |
use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; |
| 18 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context; |
| 19 |
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Prop_Type; |
| 20 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs\Atomic_Tabs\Atomic_Tabs; |
| 21 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 22 |
|
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; // Exit if accessed directly. |
| 25 |
} |
| 26 |
|
| 27 |
class Atomic_Tab extends Atomic_Element_Base { |
| 28 |
use Has_Element_Template; |
| 29 |
|
| 30 |
const BASE_STYLE_KEY = 'base'; |
| 31 |
|
| 32 |
public static $widget_description = 'A tab trigger element. Contains a single heading or paragraph that serves as the tab label. The index of this e-tab MUST match the index of the corresponding e-tab-content in the e-tabs-content-area.'; |
| 33 |
|
| 34 |
public function __construct( $data = [], $args = null ) { |
| 35 |
parent::__construct( $data, $args ); |
| 36 |
$this->meta( 'permanently_locked', true ); |
| 37 |
} |
| 38 |
|
| 39 |
public static function get_type() { |
| 40 |
return 'e-tab'; |
| 41 |
} |
| 42 |
|
| 43 |
public static function get_element_type(): string { |
| 44 |
return 'e-tab'; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_title() { |
| 48 |
return esc_html__( 'Tab trigger', 'elementor' ); |
| 49 |
} |
| 50 |
|
| 51 |
public function get_keywords() { |
| 52 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 53 |
} |
| 54 |
|
| 55 |
public function get_icon() { |
| 56 |
return 'eicon-layout'; |
| 57 |
} |
| 58 |
|
| 59 |
public function should_show_in_panel() { |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
public static function get_computed_html_tag( array $settings ): string { |
| 64 |
return Html_Tag_Computer::compute( $settings, 'button' ); |
| 65 |
} |
| 66 |
|
| 67 |
protected static function define_props_schema(): array { |
| 68 |
return [ |
| 69 |
'classes' => Classes_Prop_Type::make() |
| 70 |
->default( [] ), |
| 71 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
protected function define_atomic_controls(): array { |
| 76 |
return [ |
| 77 |
Section::make() |
| 78 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 79 |
->set_id( 'settings' ) |
| 80 |
->set_items( [] ), |
| 81 |
]; |
| 82 |
} |
| 83 |
|
| 84 |
protected function define_atomic_style_states(): array { |
| 85 |
$selected_state = Style_States::get_class_states_map()['selected']; |
| 86 |
|
| 87 |
return [ $selected_state ]; |
| 88 |
} |
| 89 |
|
| 90 |
protected function define_base_styles(): array { |
| 91 |
$styles = [ |
| 92 |
'display' => String_Prop_Type::generate( 'block' ), |
| 93 |
'cursor' => String_Prop_Type::generate( 'pointer' ), |
| 94 |
'color' => Color_Prop_Type::generate( '#0C0D0E' ), |
| 95 |
'border-style' => String_Prop_Type::generate( 'solid' ), |
| 96 |
'border-color' => Color_Prop_Type::generate( '#E0E0E0' ), |
| 97 |
'border-width' => Size_Prop_Type::generate( [ |
| 98 |
'size' => 2, |
| 99 |
'unit' => 'px', |
| 100 |
]), |
| 101 |
'padding' => Size_Prop_Type::generate( [ |
| 102 |
'size' => 8, |
| 103 |
'unit' => 'px', |
| 104 |
]), |
| 105 |
'width' => Size_Prop_Type::generate( [ |
| 106 |
'size' => 160, |
| 107 |
'unit' => 'px', |
| 108 |
]), |
| 109 |
'background' => Background_Prop_Type::generate( [ |
| 110 |
'color' => Color_Prop_Type::generate( '#FFFFFF' ), |
| 111 |
]), |
| 112 |
]; |
| 113 |
|
| 114 |
$selected_styles = [ |
| 115 |
'outline-width' => Size_Prop_Type::generate( [ |
| 116 |
'size' => 0, |
| 117 |
'unit' => 'px', |
| 118 |
]), |
| 119 |
'border-color' => Color_Prop_Type::generate( '#0C0D0E' ), |
| 120 |
]; |
| 121 |
|
| 122 |
$hover_styles = [ |
| 123 |
'background' => Background_Prop_Type::generate( [ |
| 124 |
'color' => Color_Prop_Type::generate( '#E0E0E0' ), |
| 125 |
]), |
| 126 |
]; |
| 127 |
|
| 128 |
return [ |
| 129 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 130 |
->add_variant( |
| 131 |
Style_Variant::make() |
| 132 |
->add_props( $styles ) |
| 133 |
) |
| 134 |
->add_variant( |
| 135 |
Style_Variant::make() |
| 136 |
->set_state( Style_States::SELECTED ) |
| 137 |
->add_props( $selected_styles ) |
| 138 |
) |
| 139 |
->add_variant( |
| 140 |
Style_Variant::make() |
| 141 |
->set_state( Style_States::FOCUS ) |
| 142 |
->add_props( $selected_styles ) |
| 143 |
) |
| 144 |
->add_variant( |
| 145 |
Style_Variant::make() |
| 146 |
->set_state( Style_States::HOVER ) |
| 147 |
->add_props( $hover_styles ) |
| 148 |
), |
| 149 |
]; |
| 150 |
} |
| 151 |
|
| 152 |
protected function define_initial_attributes() { |
| 153 |
return [ |
| 154 |
'role' => 'tab', |
| 155 |
'tabindex' => '-1', |
| 156 |
]; |
| 157 |
} |
| 158 |
|
| 159 |
protected function define_default_children() { |
| 160 |
return [ |
| 161 |
Atomic_Paragraph::generate() |
| 162 |
->settings( [ |
| 163 |
'paragraph' => Escaped_Html_Prop_Type::generate( 'Tab' ), |
| 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 |
|