PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.3
Elementor Website Builder – more than just a page builder v3.34.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / atomic-widgets / elements / flexbox / flexbox.php

flexbox.php in Elementor Website Builder – more than just a page builder 3.34.3, at modules/atomic-widgets/elements/flexbox/flexbox.php

168 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AtomicWidgets\Elements\Flexbox;
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\Html_Tag_Control;
11 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
12 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
13 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
14 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 class Flexbox extends Atomic_Element_Base {
23 const BASE_STYLE_KEY = 'base';
24
25 public static function get_type() {
26 return 'e-flexbox';
27 }
28
29 public static function get_element_type(): string {
30 return 'e-flexbox';
31 }
32
33 public function get_title() {
34 return esc_html__( 'Flexbox', 'elementor' );
35 }
36
37 public function get_keywords() {
38 return [ 'ato', 'atom', 'atoms', 'atomic' ];
39 }
40
41 public function get_icon() {
42 return 'eicon-flexbox';
43 }
44
45 protected static function define_props_schema(): array {
46 $tag_dependencies = Dependency_Manager::make()
47 ->where( [
48 'operator' => 'not_exist',
49 'path' => [ 'link', 'destination' ],
50 'newValue' => [
51 '$$type' => 'string',
52 'value' => 'a',
53 ],
54 ] )
55 ->get();
56
57 return [
58 'classes' => Classes_Prop_Type::make()
59 ->default( [] ),
60 'tag' => String_Prop_Type::make()
61 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a' ] )
62 ->default( 'div' )
63 ->set_dependencies( $tag_dependencies )
64 ->description( 'The HTML tag for the flexbox container. Could be div, header, section, article, aside, footer, or a (link).' ),
65 'link' => Link_Prop_Type::make(),
66 'attributes' => Attributes_Prop_Type::make(),
67 ];
68 }
69
70 protected function define_atomic_controls(): array {
71 return [
72 Section::make()
73 ->set_label( __( 'Settings', 'elementor' ) )
74 ->set_id( 'settings' )
75 ->set_items( [
76 Html_Tag_Control::bind_to( 'tag' )
77 ->set_options( [
78 [
79 'value' => 'div',
80 'label' => 'Div',
81 ],
82 [
83 'value' => 'header',
84 'label' => 'Header',
85 ],
86 [
87 'value' => 'section',
88 'label' => 'Section',
89 ],
90 [
91 'value' => 'article',
92 'label' => 'Article',
93 ],
94 [
95 'value' => 'aside',
96 'label' => 'Aside',
97 ],
98 [
99 'value' => 'footer',
100 'label' => 'Footer',
101 ],
102 ])
103 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
104 ->set_fallback_labels( [
105 'a' => 'a (link)',
106 ] ),
107 Link_Control::bind_to( 'link' )
108 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
109 ->set_label( __( 'Link', 'elementor' ) )
110 ->set_meta( [
111 'topDivider' => true,
112 ] ),
113 Text_Control::bind_to( '_cssid' )
114 ->set_label( __( 'ID', 'elementor' ) )
115 ->set_meta( $this->get_css_id_control_meta() ),
116 ] ),
117 ];
118 }
119
120 protected function define_base_styles(): array {
121 $display = String_Prop_Type::generate( 'flex' );
122 $flex_direction = String_Prop_Type::generate( 'row' );
123
124 return [
125 static::BASE_STYLE_KEY => Style_Definition::make()
126 ->add_variant(
127 Style_Variant::make()
128 ->add_prop( 'display', $display )
129 ->add_prop( 'flex-direction', $flex_direction )
130 ->add_prop( 'padding', $this->get_base_padding() )
131 ),
132 ];
133 }
134
135 protected function get_base_padding(): array {
136 return Size_Prop_Type::generate( [
137 'size' => 10,
138 'unit' => 'px',
139 ] );
140 }
141
142 protected function add_render_attributes() {
143 parent::add_render_attributes();
144 $settings = $this->get_atomic_settings();
145 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
146 $initial_attributes = $this->define_initial_attributes();
147
148 $attributes = [
149 'class' => [
150 'e-con',
151 'e-atomic-element',
152 $base_style_class,
153 ...( $settings['classes'] ?? [] ),
154 ],
155 ];
156
157 if ( ! empty( $settings['_cssid'] ) ) {
158 $attributes['id'] = esc_attr( $settings['_cssid'] );
159 }
160
161 if ( ! empty( $settings['link']['href'] ) ) {
162 $attributes = array_merge( $attributes, $settings['link'] );
163 }
164
165 $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
166 }
167 }
168