first commit

This commit is contained in:
2026-03-26 13:48:22 +01:00
commit 6af83e92ed
7795 changed files with 2766332 additions and 0 deletions

View File

@@ -0,0 +1,142 @@
<?php
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs;
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
use Elementor\Modules\AtomicWidgets\Styles\Style_States;
use Elementor\Modules\AtomicWidgets\Controls\Section;
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context;
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Atomic_Tab_Content extends Atomic_Element_Base {
const BASE_STYLE_KEY = 'base';
public function __construct( $data = [], $args = null ) {
parent::__construct( $data, $args );
$this->meta( 'llm_support', false );
}
public static function get_type() {
return 'e-tab-content';
}
public static function get_element_type(): string {
return 'e-tab-content';
}
public function get_title() {
return esc_html__( 'Tab content', 'elementor' );
}
public function get_keywords() {
return [ 'ato', 'atom', 'atoms', 'atomic', 'tab', 'content', 'tabs' ];
}
public function get_icon() {
return 'eicon-layout';
}
public function should_show_in_panel() {
return false;
}
protected static function define_props_schema(): array {
return [
'classes' => Classes_Prop_Type::make()
->default( [] ),
'tab-id' => String_Prop_Type::make(),
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
];
}
protected function define_atomic_controls(): array {
return [
Section::make()
->set_label( __( 'Settings', 'elementor' ) )
->set_id( 'settings' )
->set_items( [] ),
];
}
protected function define_atomic_style_states(): array {
$selected_state = Style_States::get_class_states_map()['selected'];
return [ $selected_state ];
}
protected function define_base_styles(): array {
$styles = [
'display' => String_Prop_Type::generate( 'block' ),
'padding' => Size_Prop_Type::generate( [
'size' => 10,
'unit' => 'px',
] ),
'min-width' => Size_Prop_Type::generate( [
'size' => 30,
'unit' => 'px',
] ),
];
return [
static::BASE_STYLE_KEY => Style_Definition::make()
->add_variant(
Style_Variant::make()
->add_props( $styles )
),
];
}
protected function define_initial_attributes() {
return [
'role' => 'tabpanel',
];
}
protected function add_render_attributes() {
parent::add_render_attributes();
$settings = $this->get_atomic_settings();
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
$initial_attributes = $this->define_initial_attributes();
$tabs_context = Render_Context::get( Atomic_Tabs::class );
$default_active_tab = $tabs_context['default-active-tab'];
$get_tab_content_index = $tabs_context['get-tab-content-index'];
$tabs_id = $tabs_context['tabs-id'];
$index = $get_tab_content_index( $this->get_id() );
$is_active = $default_active_tab === $index;
$attributes = [
'class' => [
'e-con',
'e-atomic-element',
$base_style_class,
...( $settings['classes'] ?? [] ),
],
'x-bind' => 'tabContent',
'id' => Atomic_Tabs::get_tab_content_id( $tabs_id, $index ),
'aria-labelledby' => Atomic_Tabs::get_tab_id( $tabs_id, $index ),
];
if ( ! $is_active ) {
$attributes['hidden'] = 'true';
$attributes['style'] = 'display: none;';
}
if ( ! empty( $settings['_cssid'] ) ) {
$attributes['id'] = esc_attr( $settings['_cssid'] );
}
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
}
}

View File

@@ -0,0 +1,198 @@
<?php
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs;
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
use Elementor\Modules\AtomicWidgets\Styles\Style_States;
use Elementor\Modules\AtomicWidgets\Controls\Section;
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type;
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph;
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type;
use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context;
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Prop_Type;
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Atomic_Tab extends Atomic_Element_Base {
const BASE_STYLE_KEY = 'base';
public function __construct( $data = [], $args = null ) {
parent::__construct( $data, $args );
$this->meta( 'llm_support', false );
}
public static function get_type() {
return 'e-tab';
}
public static function get_element_type(): string {
return 'e-tab';
}
public function get_title() {
return esc_html__( 'Tab trigger', 'elementor' );
}
public function get_keywords() {
return [ 'ato', 'atom', 'atoms', 'atomic' ];
}
public function get_icon() {
return 'eicon-layout';
}
public function should_show_in_panel() {
return false;
}
protected static function define_props_schema(): array {
return [
'classes' => Classes_Prop_Type::make()
->default( [] ),
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
];
}
protected function define_atomic_controls(): array {
return [
Section::make()
->set_label( __( 'Settings', 'elementor' ) )
->set_id( 'settings' )
->set_items( [] ),
];
}
protected function define_atomic_style_states(): array {
$selected_state = Style_States::get_class_states_map()['selected'];
return [ $selected_state ];
}
protected function define_base_styles(): array {
$styles = [
'display' => String_Prop_Type::generate( 'block' ),
'cursor' => String_Prop_Type::generate( 'pointer' ),
'color' => Color_Prop_Type::generate( '#0C0D0E' ),
'border-style' => String_Prop_Type::generate( 'solid' ),
'border-color' => Color_Prop_Type::generate( '#E0E0E0' ),
'border-width' => Size_Prop_Type::generate( [
'size' => 2,
'unit' => 'px',
]),
'padding' => Size_Prop_Type::generate( [
'size' => 8,
'unit' => 'px',
]),
'width' => Size_Prop_Type::generate( [
'size' => 160,
'unit' => 'px',
]),
'background' => Background_Prop_Type::generate( [
'color' => Color_Prop_Type::generate( '#FFFFFF' ),
]),
];
$selected_styles = [
'outline-width' => Size_Prop_Type::generate( [
'size' => 0,
'unit' => 'px',
]),
'border-color' => Color_Prop_Type::generate( '#0C0D0E' ),
];
$hover_styles = [
'background' => Background_Prop_Type::generate( [
'color' => Color_Prop_Type::generate( '#E0E0E0' ),
]),
];
return [
static::BASE_STYLE_KEY => Style_Definition::make()
->add_variant(
Style_Variant::make()
->add_props( $styles )
)
->add_variant(
Style_Variant::make()
->set_state( Style_States::SELECTED )
->add_props( $selected_styles )
)
->add_variant(
Style_Variant::make()
->set_state( Style_States::FOCUS )
->add_props( $selected_styles )
)
->add_variant(
Style_Variant::make()
->set_state( Style_States::HOVER )
->add_props( $hover_styles )
),
];
}
protected function define_initial_attributes() {
return [
'role' => 'tab',
'tabindex' => '-1',
];
}
protected function define_default_html_tag() {
return 'button';
}
protected function define_default_children() {
return [
Atomic_Paragraph::generate()
->settings( [
'paragraph' => Html_Prop_Type::generate( 'Tab' ),
'tag' => String_Prop_Type::generate( 'span' ),
] )
->build(),
];
}
protected function add_render_attributes() {
parent::add_render_attributes();
$settings = $this->get_atomic_settings();
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
$initial_attributes = $this->define_initial_attributes();
$tabs_context = Render_Context::get( Atomic_Tabs::class );
$default_active_tab = $tabs_context['default-active-tab'];
$get_tab_index = $tabs_context['get-tab-index'];
$tabs_id = $tabs_context['tabs-id'];
$index = $get_tab_index( $this->get_id() );
$is_active = $default_active_tab === $index;
$attributes = [
'class' => [
'e-con',
'e-atomic-element',
$base_style_class,
...( $settings['classes'] ?? [] ),
],
'tabindex' => $is_active ? '0' : '-1',
'aria-selected' => $is_active ? 'true' : 'false',
'x-bind' => 'tab',
'x-ref' => $this->get_id(),
'id' => Atomic_Tabs::get_tab_id( $tabs_id, $index ),
'aria-controls' => Atomic_Tabs::get_tab_content_id( $tabs_id, $index ),
];
if ( ! empty( $settings['_cssid'] ) ) {
$attributes['id'] = esc_attr( $settings['_cssid'] );
}
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs;
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
use Elementor\Modules\AtomicWidgets\Controls\Section;
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Atomic_Tabs_Content_Area extends Atomic_Element_Base {
const BASE_STYLE_KEY = 'base';
public function __construct( $data = [], $args = null ) {
parent::__construct( $data, $args );
$this->meta( 'llm_support', false );
}
public static function get_type() {
return 'e-tabs-content-area';
}
public static function get_element_type(): string {
return 'e-tabs-content-area';
}
public function get_title() {
return esc_html__( 'Tabs content area', 'elementor' );
}
public function get_keywords() {
return [ 'ato', 'atom', 'atoms', 'atomic' ];
}
public function get_icon() {
return 'eicon-tab-content';
}
public function should_show_in_panel() {
return false;
}
protected static function define_props_schema(): array {
return [
'classes' => Classes_Prop_Type::make()
->default( [] ),
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
];
}
protected function define_atomic_controls(): array {
return [
Section::make()
->set_label( __( 'Settings', 'elementor' ) )
->set_id( 'settings' )
->set_items( [
Text_Control::bind_to( '_cssid' )
->set_label( __( 'ID', 'elementor' ) )
->set_meta( [
'layout' => 'two-columns',
] ),
] ),
];
}
protected function define_base_styles(): array {
$styles = [
'display' => String_Prop_Type::generate( 'block' ),
];
return [
static::BASE_STYLE_KEY => Style_Definition::make()
->add_variant(
Style_Variant::make()
->add_props( $styles )
),
];
}
protected function add_render_attributes() {
parent::add_render_attributes();
$settings = $this->get_atomic_settings();
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
$initial_attributes = $this->define_initial_attributes();
$attributes = [
'class' => [
'e-con',
'e-atomic-element',
$base_style_class,
...( $settings['classes'] ?? [] ),
],
];
if ( ! empty( $settings['_cssid'] ) ) {
$attributes['id'] = esc_attr( $settings['_cssid'] );
}
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs;
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
use Elementor\Modules\AtomicWidgets\Controls\Section;
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Atomic_Tabs_Menu extends Atomic_Element_Base {
const BASE_STYLE_KEY = 'base';
public function __construct( $data = [], $args = null ) {
parent::__construct( $data, $args );
$this->meta( 'llm_support', false );
}
public static function get_type() {
return 'e-tabs-menu';
}
public static function get_element_type(): string {
return 'e-tabs-menu';
}
public function get_title() {
return esc_html__( 'Tabs menu', 'elementor' );
}
public function get_keywords() {
return [ 'ato', 'atom', 'atoms', 'atomic' ];
}
public function get_icon() {
return 'eicon-tab-menu';
}
public function should_show_in_panel() {
return false;
}
public function define_initial_attributes(): array {
return [
'role' => 'tablist',
];
}
protected static function define_props_schema(): array {
return [
'classes' => Classes_Prop_Type::make()
->default( [] ),
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
];
}
protected function define_atomic_controls(): array {
return [
Section::make()
->set_label( __( 'Settings', 'elementor' ) )
->set_id( 'settings' )
->set_items( [
Text_Control::bind_to( '_cssid' )
->set_label( __( 'ID', 'elementor' ) )
->set_meta( [
'layout' => 'two-columns',
] ),
] ),
];
}
protected function define_base_styles(): array {
$styles = [
'display' => String_Prop_Type::generate( 'flex' ),
'justify-content' => String_Prop_Type::generate( 'center' ),
];
return [
static::BASE_STYLE_KEY => Style_Definition::make()
->add_variant(
Style_Variant::make()
->add_props( $styles )
),
];
}
protected function add_render_attributes() {
parent::add_render_attributes();
$settings = $this->get_atomic_settings();
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
$initial_attributes = $this->define_initial_attributes();
$attributes = [
'class' => [
'e-con',
'e-atomic-element',
$base_style_class,
...( $settings['classes'] ?? [] ),
],
];
if ( ! empty( $settings['_cssid'] ) ) {
$attributes['id'] = esc_attr( $settings['_cssid'] );
}
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
}
}

View File

@@ -0,0 +1,268 @@
<?php
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Tabs;
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
use Elementor\Modules\AtomicWidgets\Controls\Section;
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type;
use Elementor\Modules\AtomicWidgets\Controls\Types\Elements\Tabs_Control;
use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader;
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
use Elementor\Core\Utils\Collection;
use Elementor\Utils;
use Elementor\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Atomic_Tabs extends Atomic_Element_Base {
const BASE_STYLE_KEY = 'base';
const ELEMENT_TYPE_TABS_MENU = 'e-tabs-menu';
const ELEMENT_TYPE_TABS_CONTENT_AREA = 'e-tabs-content-area';
const ELEMENT_TYPE_TAB = 'e-tab';
const ELEMENT_TYPE_TAB_CONTENT = 'e-tab-content';
public static $widget_description = 'Create a tabbed interface with customizable tabs and content areas. LLM support: Each child element will be represented as a tab, the menu auto-generates based on the children';
public function __construct( $data = [], $args = null ) {
parent::__construct( $data, $args );
$this->meta( 'is_container', true );
}
public static function get_type() {
return 'e-tabs';
}
public static function get_element_type(): string {
return 'e-tabs';
}
public function get_title() {
return esc_html__( 'Tabs', 'elementor' );
}
public function get_keywords() {
return [ 'ato', 'atom', 'atoms', 'atomic' ];
}
public function get_icon() {
return 'eicon-tabs';
}
protected static function define_props_schema(): array {
return [
'classes' => Classes_Prop_Type::make()
->default( [] ),
'default-active-tab' => Number_Prop_Type::make()
->default( 0 )
->meta( Overridable_Prop_Type::ignore() ),
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
];
}
protected function define_atomic_controls(): array {
return [
Section::make()
->set_label( __( 'Content', 'elementor' ) )
->set_id( 'content' )
->set_items( [
Tabs_Control::make()
->set_label( __( 'Menu items', 'elementor' ) )
->set_meta( [
'layout' => 'custom',
] ),
] ),
Section::make()
->set_label( __( 'Settings', 'elementor' ) )
->set_id( 'settings' )
->set_items( [
Text_Control::bind_to( '_cssid' )
->set_label( __( 'ID', 'elementor' ) )
->set_meta( [
'layout' => 'two-columns',
] ),
] ),
];
}
protected function define_base_styles(): array {
$styles = [
'display' => String_Prop_Type::generate( 'flex' ),
'flex-direction' => String_Prop_Type::generate( 'column' ),
'gap' => Size_Prop_Type::generate( [
'size' => 30,
'unit' => 'px',
]),
'padding' => Dimensions_Prop_Type::generate( [
'block-start' => Size_Prop_Type::generate( [
'size' => 0,
'unit' => 'px',
]),
] ),
];
return [
static::BASE_STYLE_KEY => Style_Definition::make()
->add_variant(
Style_Variant::make()
->add_props( $styles )
),
];
}
protected function define_default_children() {
$default_tab_count = 3;
$tab_elements = [];
$tab_content_elements = [];
foreach ( range( 1, $default_tab_count ) as $i ) {
$tab_elements[] = Atomic_Tab::generate()
->editor_settings( [
'title' => "Tab {$i} trigger",
'initial_position' => $i,
] )
->is_locked( true )
->build();
$tab_content_elements[] = Atomic_Tab_Content::generate()
->is_locked( true )
->editor_settings( [
'title' => "Tab {$i} content",
'initial_position' => $i,
] )
->build();
}
$tabs_menu = Atomic_Tabs_Menu::generate()
->children( $tab_elements )
->is_locked( true )
->build();
$tabs_content_area = Atomic_Tabs_Content_Area::generate()
->children( $tab_content_elements )
->is_locked( true )
->build();
return [
$tabs_menu,
$tabs_content_area,
];
}
public function get_script_depends() {
$global_depends = parent::get_script_depends();
if ( Plugin::$instance->preview->is_preview_mode() ) {
return array_merge( $global_depends, [ 'elementor-tabs-handler', 'elementor-tabs-preview-handler' ] );
}
return array_merge( $global_depends, [ 'elementor-tabs-handler' ] );
}
public function register_frontend_handlers() {
$assets_url = ELEMENTOR_ASSETS_URL;
$min_suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min';
wp_register_script(
'elementor-tabs-handler',
"{$assets_url}js/tabs-handler{$min_suffix}.js",
[ Frontend_Assets_Loader::FRONTEND_HANDLERS_HANDLE, Frontend_Assets_Loader::ALPINEJS_HANDLE ],
ELEMENTOR_VERSION,
true
);
wp_register_script(
'elementor-tabs-preview-handler',
"{$assets_url}js/tabs-preview-handler{$min_suffix}.js",
[ Frontend_Assets_Loader::FRONTEND_HANDLERS_HANDLE, Frontend_Assets_Loader::ALPINEJS_HANDLE ],
ELEMENTOR_VERSION,
true
);
}
private function get_filtered_children_ids( $parent_element, $child_type ) {
if ( ! $parent_element ) {
return [];
}
return Collection::make( $parent_element->get_children() )
->filter( fn( $element ) => $element->get_type() === $child_type )
->map( fn( $element ) => $element->get_id() )
->flip()
->all();
}
private function get_tab_index( $tab_id ) {
$direct_children = Collection::make( $this->get_children() );
$tabs_menu = $direct_children->filter( fn( $child ) => $child->get_type() === self::ELEMENT_TYPE_TABS_MENU )->first();
$tab_ids = $this->get_filtered_children_ids( $tabs_menu, self::ELEMENT_TYPE_TAB );
return $tab_ids[ $tab_id ];
}
private function get_tab_content_index( $tab_content_id ) {
$direct_children = Collection::make( $this->get_children() );
$tabs_content_area = $direct_children->filter( fn( $child ) => $child->get_type() === self::ELEMENT_TYPE_TABS_CONTENT_AREA )->first();
$tab_content_ids = $this->get_filtered_children_ids( $tabs_content_area, self::ELEMENT_TYPE_TAB_CONTENT );
return $tab_content_ids[ $tab_content_id ];
}
protected function define_render_context(): array {
$default_active_tab = $this->get_atomic_setting( 'default-active-tab' );
return [
'context' => [
'default-active-tab' => $default_active_tab,
'get-tab-index' => fn( $tab_id ) => $this->get_tab_index( $tab_id ),
'get-tab-content-index' => fn( $tab_content_id ) => $this->get_tab_content_index( $tab_content_id ),
'tabs-id' => $this->get_id(),
],
];
}
protected function add_render_attributes() {
parent::add_render_attributes();
$settings = $this->get_atomic_settings();
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
$initial_attributes = $this->define_initial_attributes();
$default_active_tab = $settings['default-active-tab'] ?? 0;
$default_active_tab_id = static::get_tab_id( $this->get_id(), $default_active_tab );
$attributes = [
'class' => [
'e-con',
'e-atomic-element',
$base_style_class,
...( $settings['classes'] ?? [] ),
],
'x-data' => 'eTabs' . $this->get_id(),
'data-e-settings' => json_encode( [ 'default-active-tab' => esc_js( $default_active_tab_id ) ] ),
];
if ( ! empty( $settings['_cssid'] ) ) {
$attributes['id'] = esc_attr( $settings['_cssid'] );
}
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
}
public static function get_tab_id( $tabs_id, $index ) {
return "{$tabs_id}-tab-{$index}";
}
public static function get_tab_content_id( $tabs_id, $index ) {
return "{$tabs_id}-tab-content-{$index}";
}
}

View File

@@ -0,0 +1,87 @@
import { register } from '@elementor/frontend-handlers';
import { Alpine } from '@elementor/alpinejs';
import { TAB_ELEMENT_TYPE, TAB_CONTENT_ELEMENT_TYPE, getTabId, getTabContentId, getIndex, getNextTab } from './utils';
const SELECTED_CLASS = 'e--selected';
register( {
elementType: 'e-tabs',
id: 'e-tabs-handler',
callback: ( { element, settings } ) => {
const tabsId = element.dataset.id;
Alpine.data( `eTabs${ tabsId }`, () => ( {
activeTab: settings[ 'default-active-tab' ],
navigateTabs( { key, target: tab } ) {
const nextTab = getNextTab( key, tab );
nextTab.focus();
},
tab: {
':id'() {
const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
return getTabId( tabsId, index );
},
'@click'() {
const id = this.$el.id;
this.activeTab = id;
},
'@keydown.arrow-right.prevent'( event ) {
this.navigateTabs( event );
},
'@keydown.arrow-left.prevent'( event ) {
this.navigateTabs( event );
},
':class'() {
const id = this.$el.id;
return this.activeTab === id ? SELECTED_CLASS : '';
},
':aria-selected'() {
const id = this.$el.id;
return this.activeTab === id ? 'true' : 'false';
},
':tabindex'() {
const id = this.$el.id;
return this.activeTab === id ? '0' : '-1';
},
':aria-controls'() {
const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
return getTabContentId( tabsId, index );
},
},
tabContent: {
':aria-labelledby'() {
const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
return getTabId( tabsId, index );
},
'x-show'() {
const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
const tabId = getTabId( tabsId, index );
const isActive = this.activeTab === tabId;
this.$nextTick( () => {
this.$el.classList.toggle( SELECTED_CLASS, isActive );
} );
return isActive;
},
':id'() {
const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
return getTabContentId( tabsId, index );
},
},
} ) );
},
} );

View File

@@ -0,0 +1,30 @@
import { register } from '@elementor/frontend-handlers';
import { Alpine, refreshTree } from '@elementor/alpinejs';
import { TAB_ELEMENT_TYPE, TAB_CONTENT_ELEMENT_TYPE, getTabId, getIndex } from './utils';
register( {
elementType: 'e-tabs',
id: 'e-tabs-preview-handler',
callback: ( { element, signal, listenToChildren } ) => {
window?.parent.addEventListener( 'elementor/navigator/item/click', ( event ) => {
const { id, type } = event.detail;
if ( type !== TAB_ELEMENT_TYPE && type !== TAB_CONTENT_ELEMENT_TYPE ) {
return;
}
const targetElement = Alpine.$data( element ).$refs[ id ];
if ( ! targetElement ) {
return;
}
const targetIndex = getIndex( targetElement, type );
Alpine.$data( element ).activeTab = getTabId( element.dataset.id, targetIndex );
}, { signal } );
// Re-initialize Alpine to sync with editor DOM manipulations that bypass Alpine's reactivity.
listenToChildren( [ TAB_ELEMENT_TYPE, TAB_CONTENT_ELEMENT_TYPE ] )
.render( () => refreshTree( element ) );
},
} );

View File

@@ -0,0 +1,44 @@
export const TAB_ELEMENT_TYPE = 'e-tab';
export const TAB_CONTENT_ELEMENT_TYPE = 'e-tab-content';
export const TABS_CONTENT_AREA_ELEMENT_TYPE = 'e-tabs-content-area';
export const TABS_MENU_ELEMENT_TYPE = 'e-tabs-menu';
const NAVIGATE_UP_KEYS = [ 'ArrowUp', 'ArrowLeft' ];
const NAVIGATE_DOWN_KEYS = [ 'ArrowDown', 'ArrowRight' ];
export const getTabId = ( tabsId, tabIndex ) => {
return `${ tabsId }-tab-${ tabIndex }`;
};
export const getTabContentId = ( tabsId, tabIndex ) => {
return `${ tabsId }-tab-content-${ tabIndex }`;
};
export const getChildren = ( el, elementType ) => {
const parent = el.parentElement;
return Array.from( parent.children ).filter( ( child ) => {
return child.dataset.element_type === elementType;
} );
};
export const getIndex = ( el, elementType ) => {
const children = getChildren( el, elementType );
return children.indexOf( el );
};
export const getNextTab = ( key, tab ) => {
const tabs = getChildren( tab, TAB_ELEMENT_TYPE );
const tabsLength = tabs.length;
const currentIndex = getIndex( tab, TAB_ELEMENT_TYPE );
if ( NAVIGATE_DOWN_KEYS.includes( key ) ) {
return tabs[ ( currentIndex + 1 ) % tabsLength ];
}
if ( NAVIGATE_UP_KEYS.includes( key ) ) {
return tabs[ ( currentIndex - 1 + tabsLength ) % tabsLength ];
}
};