PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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 / grid / grid.php

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

226 lines 6.9 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\Grid;
3
4 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
5 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
6 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template;
7 use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
8 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
9 use Elementor\Modules\AtomicWidgets\PropTypes\Grid_Track_Size_Prop_Type;
10 use Elementor\Modules\AtomicWidgets\PropTypes\Layout_Direction_Prop_Type;
11 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type;
12 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
13 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
14 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
15 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
16 use Elementor\Modules\AtomicWidgets\Controls\Section;
17 use Elementor\Modules\AtomicWidgets\Controls\Types\Html_Tag_Control;
18 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
19 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
20 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
21 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
22 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
23 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit; // Exit if accessed directly.
27 }
28
29 class Grid extends Atomic_Element_Base {
30 use Has_Element_Template;
31
32 const BASE_STYLE_KEY = 'base';
33
34 public static $widget_description = 'CSS grid layout. Always set grid-template-rows to match the actual number of rows the children fill. Empty fr row tracks do not collapse and render as an equal-height empty band below the content.';
35
36 public function __construct( $data = [], $args = null ) {
37 parent::__construct( $data, $args );
38 $this->meta( 'is_container', true );
39 }
40
41 public static function get_type() {
42 return 'e-grid';
43 }
44
45 public static function get_element_type(): string {
46 return 'e-grid';
47 }
48
49 public function get_title() {
50 return esc_html__( 'Grid', 'elementor' );
51 }
52
53 public function get_keywords() {
54 return [ 'ato', 'atom', 'atoms', 'atomic', 'container', 'wrapper', 'section', 'row', 'column', 'grid', 'columns', 'gallery', 'layout' ];
55 }
56
57 public function get_icon() {
58 return 'eicon-library-grid';
59 }
60
61 public static function get_computed_html_tag( array $settings ): string {
62 return Html_Tag_Computer::compute( $settings, 'div' );
63 }
64
65 protected static function define_props_schema(): array {
66 $tag_dependencies = Dependency_Manager::make( Dependency_Manager::RELATION_AND )
67 ->where( [
68 'operator' => 'ne',
69 'path' => [ 'link', 'destination' ],
70 'nestedPath' => [ 'group' ],
71 'value' => 'action',
72 'newValue' => [
73 '$$type' => 'string',
74 'value' => 'button',
75 ],
76 ] )->where( [
77 'operator' => 'not_exist',
78 'path' => [ 'link', 'destination' ],
79 'newValue' => [
80 '$$type' => 'string',
81 'value' => 'a',
82 ],
83 ] )->get();
84
85 return [
86 'classes' => Classes_Prop_Type::make()
87 ->default( [] ),
88 'tag' => String_Prop_Type::make()
89 ->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button' ] )
90 ->default( 'div' )
91 ->description( 'The HTML tag for the grid container. One of: div, header, section, article, aside, footer, a (link), or button.' )
92 ->set_dependencies( $tag_dependencies ),
93 'link' => Link_Prop_Type::make(),
94 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
95 ];
96 }
97
98 protected function define_atomic_controls(): array {
99 return [
100 Section::make()
101 ->set_label( __( 'Settings', 'elementor' ) )
102 ->set_id( 'settings' )
103 ->set_items( [
104 Html_Tag_Control::bind_to( 'tag' )
105 ->set_options( [
106 [
107 'value' => 'div',
108 'label' => 'Div',
109 ],
110 [
111 'value' => 'header',
112 'label' => 'Header',
113 ],
114 [
115 'value' => 'section',
116 'label' => 'Section',
117 ],
118 [
119 'value' => 'article',
120 'label' => 'Article',
121 ],
122 [
123 'value' => 'aside',
124 'label' => 'Aside',
125 ],
126 [
127 'value' => 'footer',
128 'label' => 'Footer',
129 ],
130 ])
131 ->set_label( esc_html__( 'HTML Tag', 'elementor' ) )
132 ->set_fallback_labels( [
133 'a' => 'a (link)',
134 ] ),
135 Link_Control::bind_to( 'link' )
136 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
137 ->set_label( __( 'Link', 'elementor' ) )
138 ->set_meta( [
139 'topDivider' => true,
140 ] ),
141 Text_Control::bind_to( '_cssid' )
142 ->set_label( __( 'ID', 'elementor' ) )
143 ->set_meta( $this->get_css_id_control_meta() ),
144 ] ),
145 ];
146 }
147
148 protected function define_base_styles(): array {
149 return [
150 static::BASE_STYLE_KEY => Style_Definition::make()
151 ->add_variant(
152 Style_Variant::make()
153 ->set_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP )
154 ->add_prop( 'display', String_Prop_Type::generate( 'grid' ) )
155 ->add_prop( 'padding', $this->get_base_padding() )
156 ->add_prop( 'grid-template-columns', Grid_Track_Size_Prop_Type::generate( [
157 'size' => 3,
158 'unit' => 'fr',
159 ] ) )
160 ->add_prop( 'grid-template-rows', Grid_Track_Size_Prop_Type::generate( [
161 'size' => 2,
162 'unit' => 'fr',
163 ] ) )
164 ->add_prop( 'gap', Layout_Direction_Prop_Type::generate( [
165 'column' => Size_Prop_Type::generate( [
166 'size' => 20,
167 'unit' => 'px',
168 ] ),
169 'row' => Size_Prop_Type::generate( [
170 'size' => 20,
171 'unit' => 'px',
172 ] ),
173 ] ) )
174 )
175 ->add_variant(
176 Style_Variant::make()
177 ->set_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_MOBILE )
178 ->add_prop( 'grid-template-columns', Grid_Track_Size_Prop_Type::generate( [
179 'size' => 1,
180 'unit' => 'fr',
181 ] ) )
182 ),
183 ];
184 }
185
186 protected function get_base_padding(): array {
187 return Size_Prop_Type::generate( [
188 'size' => 10,
189 'unit' => 'px',
190 ] );
191 }
192
193 protected function add_render_attributes() {
194 parent::add_render_attributes();
195 $settings = $this->get_atomic_settings();
196 $base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ];
197 $initial_attributes = $this->define_initial_attributes();
198
199 $attributes = [
200 'class' => [
201 'e-con',
202 'e-atomic-element',
203 $base_style_class,
204 ...( $settings['classes'] ?? [] ),
205 ],
206 ];
207
208 if ( ! empty( $settings['_cssid'] ) ) {
209 $attributes['id'] = esc_attr( $settings['_cssid'] );
210 }
211
212 if ( ! empty( $settings['link']['href'] ) ) {
213 $link_attributes = $this->get_link_attributes( $settings['link'] );
214 $attributes = array_merge( $attributes, $link_attributes );
215 }
216
217 $this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) );
218 }
219
220 protected function get_templates(): array {
221 return [
222 'elementor/elements/grid' => __DIR__ . '/grid.html.twig',
223 ];
224 }
225 }
226