PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.7
Elementor Website Builder – more than just a page builder v4.0.7
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 4.0.7, at modules/atomic-widgets/elements/flexbox/flexbox.php

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