PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-dev1
Elementor Website Builder – more than just a page builder v3.33.0-dev1
4.3.0-beta3 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 All 452 releases
elementor / modules / atomic-widgets / elements / flexbox / flexbox.php

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

167 lines 4.5 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 'link' => Link_Prop_Type::make(),
65 'attributes' => Attributes_Prop_Type::make(),
66 ];
67 }
68
69 protected function define_atomic_controls(): array {
70 return [
71 Section::make()
72 ->set_label( __( 'Settings', 'elementor' ) )
73 ->set_id( 'settings' )
74 ->set_items( [
75 Html_Tag_Control::bind_to( 'tag' )
76 ->set_options( [
77 [
78 'value' => 'div',
79 'label' => 'Div',
80 ],
81 [
82 'value' => 'header',
83 'label' => 'Header',
84 ],
85 [
86 'value' => 'section',
87 'label' => 'Section',
88 ],
89 [
90 'value' => 'article',
91 'label' => 'Article',
92 ],
93 [
94 'value' => 'aside',
95 'label' => 'Aside',
96 ],
97 [
98 'value' => 'footer',
99 'label' => 'Footer',
100 ],
101 ])
102 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
103 ->set_fallback_labels( [
104 'a' => 'a (link)',
105 ] ),
106 Link_Control::bind_to( 'link' )
107 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
108 ->set_label( __( 'Link', 'elementor' ) )
109 ->set_meta( [
110 'topDivider' => true,
111 ] ),
112 Text_Control::bind_to( '_cssid' )
113 ->set_label( __( 'ID', 'elementor' ) )
114 ->set_meta( $this->get_css_id_control_meta() ),
115 ] ),
116 ];
117 }
118
119 protected function define_base_styles(): array {
120 $display = String_Prop_Type::generate( 'flex' );
121 $flex_direction = String_Prop_Type::generate( 'row' );
122
123 return [
124 static::BASE_STYLE_KEY => Style_Definition::make()
125 ->add_variant(
126 Style_Variant::make()
127 ->add_prop( 'display', $display )
128 ->add_prop( 'flex-direction', $flex_direction )
129 ->add_prop( 'padding', $this->get_base_padding() )
130 ),
131 ];
132 }
133
134 protected function get_base_padding(): array {
135 return Size_Prop_Type::generate( [
136 'size' => 10,
137 'unit' => 'px',
138 ] );
139 }
140
141 protected function add_render_attributes() {
142 parent::add_render_attributes();
143 $settings = $this->get_atomic_settings();
144 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
145 $initial_attributes = $this->define_initial_attributes();
146
147 $attributes = [
148 'class' => [
149 'e-con',
150 'e-atomic-element',
151 $base_style_class,
152 ...( $settings['classes'] ?? [] ),
153 ],
154 ];
155
156 if ( ! empty( $settings['_cssid'] ) ) {
157 $attributes['id'] = esc_attr( $settings['_cssid'] );
158 }
159
160 if ( ! empty( $settings['link']['href'] ) ) {
161 $attributes = array_merge( $attributes, $settings['link'] );
162 }
163
164 $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
165 }
166 }
167