PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / filterable-cards / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/filterable-cards/block.php

339 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\FilterableCards;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Typography;
11 use ABlocks\Controls\Border;
12 use ABlocks\Controls\Dimensions;
13 use ABlocks\Controls\Range;
14 use ABlocks\Controls\Alignment;
15 use ABlocks\Controls\BoxShadow;
16
17
18 class Block extends BlockBaseAbstract {
19 protected $block_name = 'filterable-cards';
20
21 public function build_css( $attributes ) {
22
23 // Generate CSS start
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .filterable-cards_filter , {{WRAPPER}} .filterable-cards-filter-wrap',
28 $this->get_filter_wrap_CSS( $attributes ),
29 $this->get_filter_wrap_CSS( $attributes, 'Tablet' ),
30 $this->get_filter_wrap_CSS( $attributes, 'Mobile' )
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .filterable-cards_filter .filterable-filter-button',
34 $this->get_filter_CSS( $attributes ),
35 $this->get_filter_CSS( $attributes, 'Tablet' ),
36 $this->get_filter_CSS( $attributes, 'Mobile' )
37 );
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .filterable-cards_filter .filterable-filter-button:hover',
40 $this->get_filter_hover_CSS( $attributes ),
41 $this->get_filter_hover_CSS( $attributes, 'Tablet' ),
42 $this->get_filter_hover_CSS( $attributes, 'Mobile' )
43 );
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .filterable-cards-filter-wrap .filterable-cards_filter .filterable-search-toggle-btn , {{WRAPPER}} .filterable-cards-filter-wrap .filterable-searchInput',
46 $this->get_search_menu_CSS( $attributes ),
47 $this->get_search_menu_CSS( $attributes, 'Tablet' ),
48 $this->get_search_menu_CSS( $attributes, 'Mobile' )
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .filterable-cards_filter .filterable-search-toggle-btn:hover , {{WRAPPER}} .filterable-cards-filter-wrap .filterable-searchInput:hover',
52 $this->get_search_menu_hover_CSS( $attributes ),
53 $this->get_search_menu_hover_CSS( $attributes, 'Tablet' ),
54 $this->get_search_menu_hover_CSS( $attributes, 'Mobile' )
55 );
56 $css_generator->add_class_styles(
57 '{{WRAPPER}} .filterable-cards-filter-wrap .filterable-searchInput::placeholder ',
58 $this->get_search_input_placeholder_CSS( $attributes ),
59 );
60 $css_generator->add_class_styles(
61 '{{WRAPPER}} .filterable-cards_filter .filterable-filter-button.filterable-filter-button-active',
62 $this->get_Filter_active_class_CSS( $attributes ),
63 $this->get_Filter_active_class_CSS( $attributes, 'Tablet' ),
64 $this->get_Filter_active_class_CSS( $attributes, 'Mobile' ),
65 );
66 $css_generator->add_class_styles(
67 '{{WRAPPER}} .filterable-cards_filter .filterable-filter-button.filterable-filter-button-active:hover',
68 $this->get_Filter_active_class_hover_CSS( $attributes ),
69 $this->get_Filter_active_class_hover_CSS( $attributes, 'Tablet' ),
70 $this->get_Filter_active_class_hover_CSS( $attributes, 'Mobile' ),
71 );
72 $css_generator->add_class_styles(
73 '{{WRAPPER}} .filterable-cards-wrap',
74 $this->filterable_cards_WrapCSS( $attributes ),
75 $this->filterable_cards_WrapCSS( $attributes, 'Tablet' ),
76 $this->filterable_cards_WrapCSS( $attributes, 'Mobile' )
77 );
78 $css_generator->add_class_styles(
79 '{{WRAPPER}} .filterable-cards-wrap > .ablocks-block--filterable-cards-item',
80 $this->filterable_cards_items( $attributes ),
81 $this->filterable_cards_items( $attributes, 'Tablet' ),
82 $this->filterable_cards_items( $attributes, 'Mobile' ),
83 );
84 // button style
85 $css_generator->add_class_styles(
86 '{{WRAPPER}} .filterable-cards-load-more-wrapper',
87 $this->filterable_Cards_More_Wrapper( $attributes ),
88 $this->filterable_Cards_More_Wrapper( $attributes, 'Tablet' ),
89 $this->filterable_Cards_More_Wrapper( $attributes, 'Mobile' ),
90 );
91 $css_generator->add_class_styles(
92 '{{WRAPPER}} .filterable-cards-showMore-button',
93 $this->filterable_loadMore_button( $attributes ),
94 $this->filterable_loadMore_button( $attributes, 'Tablet' ),
95 $this->filterable_loadMore_button( $attributes, 'Mobile' )
96 );
97 $css_generator->add_class_styles(
98 '{{WRAPPER}} .filterable-cards-showMore-button:hover',
99 $this->filterable_loadMore_button_hover( $attributes ),
100 $this->filterable_loadMore_button_hover( $attributes, 'Tablet' ),
101 $this->filterable_loadMore_button_hover( $attributes, 'Mobile' )
102 );
103 return $css_generator->generate_css();
104 }
105 private function get_filter_wrap_CSS( $attributes, $device = '' ) {
106 $css = [];
107 if ( ! empty( $horizontal_alignment ) ) {
108 $css['justify-content'] = $horizontal_alignment;
109 }
110 $alignment_css = isset( $attributes['filterAlignment'] ) ? Alignment::get_css( $attributes['filterAlignment'], 'justify-content', $device )
111 : [];
112 $css = array_merge( $css, $alignment_css );
113 return array_merge(
114 $css,
115 Range::get_css([
116 'attributeValue' => $attributes['filterButtonGap'],
117 'attribute_object_key' => 'value',
118 'isResponsive' => true,
119 'hasUnit' => false,
120 'defaultValue' => 8,
121 'unitDefaultValue' => 'px',
122 'property' => 'gap',
123 'device' => $device,
124 ])
125 );
126 }
127 private function get_filter_CSS( $attributes, $device = '' ) {
128 $filter_border_css = ! empty( $attributes['filterButtonBorder'] )
129 ? Border::get_css( $attributes['filterButtonBorder'], '', $device )
130 : array();
131 $css = array_merge(
132 $filter_border_css,
133 Typography::get_css( isset( $attributes['filterButtonTypography'] ) ? $attributes['filterButtonTypography'] : [], $device ),
134 Dimensions::get_css( isset( $attributes['filterButtonPadding'] ) ? $attributes['filterButtonPadding'] : [], 'padding', $device ),
135 Dimensions::get_css( isset( $attributes['filterButtonMargin'] ) ? $attributes['filterButtonMargin'] : [], 'margin', $device ),
136 );
137
138 if ( ! empty( $attributes['filterButtonColor'] ) ) {
139 $css['color'] = $attributes['filterButtonColor'];
140 }
141
142 if ( ! empty( $attributes['filterButtonBackground'] ) ) {
143 $css['background'] = $attributes['filterButtonBackground'];
144 }
145
146 return $css;
147 }
148 private function get_filter_hover_CSS( $attributes, $device = '' ) {
149 $css = array_merge(
150 Border::get_hover_css( isset( $attributes['filterButtonBorder'] ) ? $attributes['filterButtonBorder'] : [], $device )
151 );
152
153 if ( ! empty( $attributes['filterButtonColorH'] ) ) {
154 $css['color'] = $attributes['filterButtonColorH'];
155 }
156 if ( ! empty( $attributes['filterButtonBackgroundH'] ) ) {
157 $css['background'] = $attributes['filterButtonBackgroundH'];
158 }
159 if ( ! empty( $attributes['filterButtonTransition'] ) ) {
160 $css['transition'] = $attributes['filterButtonTransition'];
161 }
162
163 return $css;
164 }
165 private function get_search_menu_CSS( $attributes, $device = '' ) {
166 $searchMenu_menu_border_css = ! empty( $attributes['searchMenuBorder'] )
167 ? Border::get_css( $attributes['searchMenuBorder'], '', $device )
168 : array();
169 $css = array_merge(
170 $searchMenu_menu_border_css,
171 Dimensions::get_css( isset( $attributes['searchMenuPadding'] ) ? $attributes['searchMenuPadding'] : [], 'padding', $device ),
172 Dimensions::get_css( isset( $attributes['searchMenuMargin'] ) ? $attributes['searchMenuMargin'] : [], 'margin', $device )
173 );
174
175 if ( ! empty( $attributes['searchMenuColor'] ) ) {
176 $css['color'] = $attributes['searchMenuColor'];
177 }
178 if ( ! empty( $attributes['searchMenuBackground'] ) ) {
179 $css['background'] = $attributes['searchMenuBackground'];
180 }
181
182 return $css;
183 }
184
185 private function get_search_menu_hover_CSS( $attributes, $device = '' ) {
186 $css = array_merge(
187 Border::get_hover_css( isset( $attributes['searchMenuBorder'] ) ? $attributes['searchMenuBorder'] : [], $device )
188 );
189 if ( ! empty( $attributes['searchMenuColorH'] ) ) {
190 $css['color'] = $attributes['searchMenuColorH'];
191 }
192 if ( ! empty( $attributes['searchMenuBackgroundH'] ) ) {
193 $css['background'] = $attributes['searchMenuBackgroundH'];
194 }
195 if ( ! empty( $attributes['searchMenuTransition'] ) ) {
196 $css['transition'] = $attributes['searchMenuTransition'];
197 }
198
199 return $css;
200 }
201 private function get_search_input_placeholder_CSS( $attributes ) {
202 $css = [];
203 if ( ! empty( $attributes['searchMenuColor'] ) ) {
204 $css['color'] = $attributes['searchMenuColor'];
205 }
206 return $css;
207 }
208 private function get_filter_active_class_CSS( $attributes, $device = '' ) {
209 $css = array_merge(
210 Border::get_css( isset( $attributes['activeClassBorder'] ) ? $attributes['activeClassBorder'] : [], $device )
211 );
212 if ( ! empty( $attributes['activeClassColor'] ) ) {
213 $css['color'] = $attributes['activeClassColor'];
214 }
215 if ( ! empty( $attributes['activeClassBackground'] ) ) {
216 $css['background'] = $attributes['activeClassBackground'];
217 }
218
219 return $css;
220 }
221 private function get_Filter_active_class_hover_CSS( $attributes, $device = '' ) {
222 $hover_border = Border::get_hover_css( isset( $attributes['activeClassBorder'] ) ? $attributes['activeClassBorder'] : [], $device );
223 return $hover_border;
224 }
225 private function filterable_cards_wrapCSS( $attributes, $device = '' ) {
226 $css = [];
227 if ( $attributes['gridStyle'] === 'grid' ) {
228 $css['display'] = 'grid';
229 if ( $device === 'Tablet' ) {
230 $css['grid-template-columns'] = 'repeat(2, 1fr)';
231 } elseif ( $device === 'Mobile' ) {
232 $css['grid-template-columns'] = 'repeat(1, 1fr)';
233 } elseif ( ! empty( $attributes['gridColumns'] ) ) {
234 $css['grid-template-columns'] = 'repeat(' . $attributes['gridColumns'] . ', 1fr)';
235 }
236 }
237 if ( $attributes['gridStyle'] === 'masonry' ) {
238 if ( $device === 'Tablet' ) {
239 $css['column-count'] = '2';
240 } elseif ( $device === 'Mobile' ) {
241 $css['column-count'] = '1';
242 } elseif ( ! empty( $attributes['gridColumns'] ) ) {
243 $css['column-count'] = $attributes['gridColumns'];
244 }
245 }
246
247 return array_merge(
248 $css,
249 Range::get_css([
250 'attributeValue' => $attributes['itemGap'],
251 'attribute_object_key' => 'value',
252 'isResponsive' => true,
253 'hasUnit' => false,
254 'unitDefaultValue' => 'px',
255 'defaultValue' => 10,
256 'property' => 'gap',
257 'device' => $device,
258 ])
259 );
260 }
261
262 private function filterable_cards_items( $attributes, $device = '' ) {
263 $css = [];
264
265 if ( ! empty( $attributes['cardHeight'] ) && $attributes['gridStyle'] === 'grid' ) {
266 $css['height'] = $attributes['cardHeight'] . 'px';
267 }
268 if ( $attributes['gridStyle'] === 'masonry' ) {
269 $css['break-inside'] = 'avoid';
270 $css['width'] = '100%';
271 $css = array_merge($css, Range::get_css([
272 'attributeValue' => $attributes['itemGap'] ?? null,
273 'attribute_object_key' => 'value',
274 'isResponsive' => true,
275 'hasUnit' => false,
276 'unitDefaultValue' => 'px',
277 'defaultValue' => 10,
278 'property' => 'margin-bottom',
279 'device' => $device,
280 ]));
281 }
282 return $css;
283 }
284 private function filterable_Cards_More_Wrapper( $attributes, $device = '' ) {
285 $css = [];
286 if ( isset( $attributes['moreButtonAlignment'] ) ) {
287 $css['justify-content'] = $attributes['moreButtonAlignment'];
288 }
289 $css = array_merge($css, Range::get_css([
290 'attributeValue' => $attributes['loadMoreButtonGap'] ?? null,
291 'attribute_object_key' => 'value',
292 'isResponsive' => true,
293 'hasUnit' => false,
294 'unitDefaultValue' => 'px',
295 'defaultValue' => '',
296 'property' => 'margin-top',
297 'device' => $device,
298 ]));
299 return $css;
300 }
301 private function filterable_loadMore_button( $attributes, $device = '' ) {
302 $css = [];
303
304 if ( ! empty( $attributes['loadMoreButtonBackground'] ) ) {
305 $css['background'] = $attributes['loadMoreButtonBackground'];
306 }
307 if ( ! empty( $attributes['loadMoreButtonTextColor'] ) ) {
308 $css['color'] = $attributes['loadMoreButtonTextColor'];
309 }
310
311 return array_merge(
312 $css,
313 Border::get_css( $attributes['moreButtonBorder'], '', $device ),
314 BoxShadow::get_css( $attributes['moreButtonboxShadow'], '', $device ),
315 Typography::get_css( $attributes['moreButtonTypography'], $device ),
316 Dimensions::get_css( $attributes['moreButtonPadding'], 'padding', $device ),
317 );
318 }
319 private function filterable_loadMore_button_hover( $attributes, $device = '' ) {
320 $css = [];
321 if ( ! empty( $attributes['loadMoreButtonTextColorH'] ) ) {
322 $css['color'] = $attributes['loadMoreButtonTextColorH'];
323 }
324
325 if ( ! empty( $attributes['loadMoreButtonBackgroundH'] ) ) {
326 $css['background'] = $attributes['loadMoreButtonBackgroundH'];
327 }
328
329 if ( ! empty( $attributes['loadMoreButtonTransition'] ) ) {
330 $css['transition-duration'] = $attributes['loadMoreButtonTransition'] . 's';
331 }
332 return array_merge(
333 $css,
334 Border::get_hover_css( $attributes['moreButtonBorder'], '', $device ),
335 BoxShadow::get_hover_css( $attributes['moreButtonboxShadow'], '', $device )
336 );
337 }
338 }
339