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

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