PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.0
UiCore Elements – Free widgets and templates for Elementor v1.2.0
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / widgets / custom-table.php

custom-table.php in UiCore Elements – Free widgets and templates for Elementor 1.2.0, at includes/widgets/custom-table.php

336 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3
4 use Elementor\Plugin;
5 use Elementor\Controls_Manager;
6 use Elementor\Repeater;
7 use Elementor\Modules\NestedElements\Controls\Control_Nested_Repeater;
8 use UiCoreElements\Utils\Animation_Trait;
9
10 defined('ABSPATH') || exit();
11
12 class CustomTable extends UiCoreNestedWidget {
13
14 use Animation_Trait;
15
16 public function get_name()
17 {
18 return 'uicore-custom-table';
19 }
20 public function get_title()
21 {
22 return esc_html__('Custom Table', 'uicore-elements');
23 }
24 public function get_icon()
25 {
26 return 'eicon-table ui-e-widget';
27 }
28 public function get_categories()
29 {
30 return ['uicore'];
31 }
32 public function get_keywords()
33 {
34 return ['slide', 'table', 'nested'];
35 }
36 public function get_styles()
37 {
38 return ['custom-table'];
39 }
40 public function get_scripts()
41 {
42 return [];
43 }
44
45 protected function carousel_content_container( int $index ) {
46 return [
47 'elType' => 'container',
48 'settings' => [
49 /* translators: %s: Item index */
50 '_title' => sprintf( __( 'Cel #%s', 'uicore-elements' ), $index ),
51 'content_width' => 'full',
52 // 'flex_justify_content' => 'center',
53 // 'flex_align_items' => 'center',
54 // the settings work only ofr first default items
55 ],
56 ];
57 }
58
59 protected function get_default_children_elements() {
60 return [
61 $this->carousel_content_container( 1 ),
62 $this->carousel_content_container( 2 ),
63 $this->carousel_content_container( 3 ),
64 ];
65 }
66
67 protected function get_default_repeater_title_setting_key() {
68 return 'table_cels';
69 }
70
71 protected function get_default_children_title() {
72 /* translators: %d: Item index */
73 return esc_html__( 'Cell #%d', 'uicore-elements' );
74 }
75 protected function get_default_children_placeholder_selector() {
76 return '.ui-e-table';
77 }
78
79 protected function register_controls()
80 {
81 if( !Plugin::$instance->experiments->is_feature_active('nested-elements') ) {
82 $this->nesting_fallback('controls');
83 return;
84 }
85
86 $this->start_controls_section(
87 'section_content',
88 [
89 'label' => __('Items', 'uicore-elements'),
90 'tab' => Controls_Manager::TAB_CONTENT,
91 ]
92 );
93
94
95 //Columns
96 $columns = new Repeater();
97 $columns->add_responsive_control(
98 'col_size',
99 [
100 'label' => __('Column Size', 'uicore-elements'),
101 'type' => Controls_Manager::SLIDER,
102 'size_units' => ['px', 'fr','custom'],
103 'default' => [
104 'size' => 300,
105 'unit' => 'px',
106 ],
107 'range' => [
108 'px' => [
109 'min' => 1,
110 'max' => 1200,
111 ],
112 'fr' => [
113 'min' => 1,
114 'max' => 12,
115 ],
116 ],
117 'selectors' => [
118 '{{WRAPPER}}' => '--ui-e-last:{{SIZE}}{{UNIT}};',
119 ],
120 ]
121 );
122
123 $this->add_control(
124 'columns',
125 [
126 'type' => Controls_Manager::REPEATER,
127 'fields' => $columns->get_controls(),
128 'title_field' => 'Column',
129 'render_type' => 'template',
130 'default' => [
131 [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ],
132 [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ],
133 [ 'col_size' => [ 'size' => 1, 'unit' => 'fr' ] ],
134 ],
135 ]
136 );
137
138
139
140 //Cells
141 $repeater = new Repeater();
142 $repeater->add_control(
143 'item',
144 [
145 'label' => __('Title', 'uicore-elements'),
146 'type' => Controls_Manager::TEXT,
147 ]
148 );
149
150 $this->add_control(
151 'cells',
152 [
153 'type' => Control_Nested_Repeater::CONTROL_TYPE,
154 'fields' => $repeater->get_controls(),
155 'allow_empty' => false,
156 'default' => [
157 [ 'item' => __( 'Cel #1', 'uicore-elements' ) ],
158 [ 'item' => __( 'Cel #2', 'uicore-elements' ) ],
159 [ 'item' => __( 'Cel #3', 'uicore-elements' ) ],
160 ],
161 ]
162 );
163
164 $this->end_controls_section();
165
166
167 //style
168 $this->start_controls_section(
169 'section_table_style',
170 [
171 'label' => __('Table Style', 'uicore-elements'),
172 'tab' => Controls_Manager::TAB_STYLE,
173 ]
174 );
175
176 //even rows background color
177 $this->add_control(
178 'even_row_bg_color',
179 [
180 'label' => __('Even Rows Background', 'uicore-elements'),
181 'type' => Controls_Manager::COLOR,
182 'selectors' => [
183 '{{WRAPPER}} .ui-e-table .ui-e-even' => 'background-color: {{VALUE}};',
184 ],
185 ]
186 );
187
188
189 $this->end_controls_section();
190 }
191
192 public function render()
193 {
194 if(!Plugin::$instance->experiments->is_feature_active('nested-elements')) {
195 $this->nesting_fallback();
196 return;
197 }
198
199 $cells = $this->get_settings_for_display('cells');
200 $cols = $this->get_settings_for_display('columns');
201
202 // Build the grid columns css
203 if ($cols) {
204 $grid_css = '';
205 $grid_columns = [];
206 $breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
207
208 $fallback = [
209 'size' => 2,
210 'unit' => 'fr',
211 ];
212
213 // Columns loop
214 foreach ($cols as $index => $item) {
215 // Set desktop column size if we have both size and unit
216 if (isset($item['col_size']['size']) && isset($item['col_size']['unit'])) {
217 $grid_columns['desktop'][] = $item['col_size']['size'] . $item['col_size']['unit'];
218 } else {
219 $grid_columns['desktop'][] = $fallback['size'] . $fallback['unit'];
220 }
221
222 // Check for the current column responsive sizes
223 foreach ($breakpoints as $breakpoint => $object) {
224 $size_slug = 'col_size_' . $breakpoint;
225
226 // Register the current column responsive size if it exists and
227 // the value is not empty, because empty values will break the table design
228 if (isset($item[$size_slug]['size']) && isset($item[$size_slug]['unit'])) {
229 $grid_columns[$breakpoint][] = $item[$size_slug]['size'] . $item[$size_slug]['unit'];
230 } else {
231 $grid_columns[$breakpoint][] = $grid_columns['desktop'][$index];
232 }
233 }
234 }
235
236 // Generate the css variables
237 foreach ($grid_columns as $device => $values) {
238 $breakpoint = $device === 'desktop' ? '' : '-' . $device;
239 $grid_css .= '--ui-e-table-cols' . $breakpoint . ':' . implode(' ', $values) . ';';
240 }
241
242 // Add it to the widget wrapper
243 $this->add_render_attribute('_wrapper', [
244 'style' => $grid_css,
245 ]);
246 }
247
248 ?>
249 <div class="ui-e-table">
250 <?php
251
252 $columns = count($cols);
253
254 foreach ($cells as $index => $item) {
255 $is_even = floor($index / $columns) % 2 !== 0;
256
257 // TODO: maybe there's a way of adding the class to the child wrapper instead of printing an extra element
258 if ($is_even) {
259 ?>
260 <div class="ui-e-even">
261 <?php $this->print_child($index); ?>
262 </div>
263 <?php
264 } else {
265 $this->print_child($index);
266 }
267 }
268 ?>
269 </div>
270 <?php
271 }
272
273
274 protected function get_initial_config(): array {
275 if (Plugin::$instance->experiments->is_feature_active('e_nested_atomic_repeaters')) {
276 return array_merge(parent::get_initial_config(), [
277 'support_improved_repeaters' => true,
278 'node' => '.ui-e-table'
279 ]);
280 }
281
282 return parent::get_initial_config();
283 }
284
285
286 protected function content_template() {
287 ?>
288 <#
289 const cols = settings.columns;
290 const cols_qty = '--ui-e-cols-qty:' + settings.columns.length;
291
292 if ( cols ) {
293 let gridCss = '';
294 const gridColumns = {};
295 const breakpoints = elementorFrontend.config.breakpoints.activeBreakpoints;
296
297 _.each( cols, function( item, index ) {
298
299 if ( ! gridColumns.desktop ) {
300 gridColumns.desktop = [];
301 }
302
303 gridColumns.desktop.push( item.col_size.size + item.col_size.unit );
304
305 _.each( breakpoints, function( object, breakpoint ) {
306 const sizeSlug = 'col_size_' + breakpoint;
307
308 if ( item[sizeSlug] && item[sizeSlug].size ) {
309 if ( ! gridColumns[breakpoint] ) {
310 gridColumns[breakpoint] = [];
311 }
312 gridColumns[breakpoint].push( item[sizeSlug].size + item[sizeSlug].unit );
313 } else {
314 if ( ! gridColumns[breakpoint] ) {
315 gridColumns[breakpoint] = [];
316 }
317 gridColumns[breakpoint].push( item.col_size.size + item.col_size.unit );
318 }
319 });
320 });
321
322 _.each( gridColumns, function( values, device ) {
323 const breakpoint = device === 'desktop' ? '' : '-' + device;
324 gridCss += '--ui-e-table-cols' + breakpoint + ':' + values.join(' ') + ';';
325 });
326
327 view.addRenderAttribute('table', 'style', [gridCss, cols_qty].join(' '));
328 }
329 #>
330 <div class="ui-e-table" {{{ view.getRenderAttributeString('table') }}}>
331
332 </div>
333 <?php
334 }
335 }
336 \Elementor\Plugin::instance()->widgets_manager->register(new CustomTable());