PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.0
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 / stripe-button / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.13.0, at includes/blocks/stripe-button/block.php

276 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\StripeButton;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Classes\CssGeneratorV2;
11 use ABlocks\Controls\Alignment;
12 use ABlocks\Controls\Border;
13 use ABlocks\Controls\BoxShadow;
14 use ABlocks\Controls\Typography;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\TextShadow;
17 use ABlocks\Controls\Icon;
18 use ABlocks\Controls\Range;
19 use ABlocks\Controls\Color;
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'stripe-button';
22
23 public function build_css_v1( $attributes ) {
24
25 // Generate CSS start
26 $css_generator = new CssGenerator( $attributes, $this->block_name );
27
28 // Generate wrapper CSS start
29 $css_generator->add_class_styles(
30 '{{WRAPPER}}',
31 $this->get_wrapper_css( $attributes ),
32 $this->get_wrapper_css( $attributes, 'Tablet' ),
33 $this->get_wrapper_css( $attributes, 'Mobile' )
34 );
35 // Generate wrapper CSS end
36
37 // Generate button CSS start
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button',
40 $this->get_button_css( $attributes ),
41 $this->get_button_css( $attributes, 'Tablet' ),
42 $this->get_button_css( $attributes, 'Mobile' )
43 );
44 // Generate button CSS end
45
46 // Generate button hover CSS start
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button:hover',
49 $this->get_button_hover_css( $attributes ),
50 $this->get_button_hover_css( $attributes, 'Tablet' ),
51 $this->get_button_hover_css( $attributes, 'Mobile' )
52 );
53
54 // Generate button icon hover CSS
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
57 $this->get_icon_hover_css( $attributes ),
58 $this->get_icon_hover_css( $attributes, 'Tablet' ),
59 $this->get_icon_hover_css( $attributes, 'Mobile' )
60 );
61
62 // Generate button text CSS start
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button .ablocks-stripe-button__text',
65 $this->get_button_text_css( $attributes )
66 );
67
68 // Generate button icon CSS start
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-icon-wrap',
71 Icon::get_wrapper_css( $attributes ),
72 Icon::get_wrapper_css( $attributes, 'Tablet' ),
73 Icon::get_wrapper_css( $attributes, 'Mobile' )
74 );
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .ablocks-icon-wrap:hover',
77 Icon::get_wrapper_hover_css( $attributes ),
78 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
79 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
80 );
81
82 $css_generator->add_class_styles(
83 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
84 Icon::get_element_image_css( $attributes ),
85 Icon::get_element_image_css( $attributes, 'Tablet' ),
86 Icon::get_element_image_css( $attributes, 'Mobile' ),
87 );
88 $css_generator->add_class_styles(
89 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
90 Icon::get_element_image_hover_css( $attributes ),
91 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
92 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
93 );
94 $css_generator->add_class_styles(
95 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
96 Icon::get_element_css( $attributes ),
97 Icon::get_element_css( $attributes, 'Tablet' ),
98 Icon::get_element_css( $attributes, 'Mobile' ),
99 );
100 $css_generator->add_class_styles(
101 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
102 Icon::get_element_image_hover_css( $attributes ),
103 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
104 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
105 );
106
107 return $css_generator->generate_css();
108 }
109
110 public function build_css_v2( $attributes ) {
111
112 // Generate CSS start
113 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
114
115 // Generate wrapper CSS start
116 $css_generator->add_class_styles(
117 '{{WRAPPER}}',
118 $this->get_wrapper_css( $attributes ),
119 $this->get_wrapper_css( $attributes, 'Tablet' ),
120 $this->get_wrapper_css( $attributes, 'Mobile' )
121 );
122 // Generate wrapper CSS end
123
124 // Generate button CSS start
125 $css_generator->add_class_styles(
126 '{{WRAPPER}} .ablocks-stripe-button',
127 $this->get_button_css( $attributes ),
128 $this->get_button_css( $attributes, 'Tablet' ),
129 $this->get_button_css( $attributes, 'Mobile' )
130 );
131 // Generate button CSS end
132
133 // Generate button hover CSS start
134 $css_generator->add_class_styles(
135 '{{WRAPPER}} .ablocks-stripe-button:hover',
136 $this->get_button_hover_css( $attributes ),
137 $this->get_button_hover_css( $attributes, 'Tablet' ),
138 $this->get_button_hover_css( $attributes, 'Mobile' )
139 );
140
141 // Generate button icon hover CSS
142 $css_generator->add_class_styles(
143 '{{WRAPPER}} .ablocks-stripe-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
144 $this->get_icon_hover_css( $attributes ),
145 $this->get_icon_hover_css( $attributes, 'Tablet' ),
146 $this->get_icon_hover_css( $attributes, 'Mobile' )
147 );
148
149 // Generate button text CSS start
150 $css_generator->add_class_styles(
151 '{{WRAPPER}} .ablocks-stripe-button .ablocks-stripe-button__text',
152 $this->get_button_text_css( $attributes )
153 );
154
155 // Generate button icon CSS start
156 $css_generator->add_class_styles(
157 '{{WRAPPER}} .ablocks-icon-wrap',
158 Icon::get_wrapper_css( $attributes ),
159 Icon::get_wrapper_css( $attributes, 'Tablet' ),
160 Icon::get_wrapper_css( $attributes, 'Mobile' )
161 );
162 $css_generator->add_class_styles(
163 '{{WRAPPER}} .ablocks-icon-wrap:hover',
164 Icon::get_wrapper_hover_css( $attributes ),
165 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
166 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
167 );
168
169 $css_generator->add_class_styles(
170 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
171 Icon::get_element_image_css( $attributes ),
172 Icon::get_element_image_css( $attributes, 'Tablet' ),
173 Icon::get_element_image_css( $attributes, 'Mobile' ),
174 );
175 $css_generator->add_class_styles(
176 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
177 Icon::get_element_image_hover_css( $attributes ),
178 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
179 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
180 );
181 $css_generator->add_class_styles(
182 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
183 Icon::get_element_css( $attributes ),
184 Icon::get_element_css( $attributes, 'Tablet' ),
185 Icon::get_element_css( $attributes, 'Mobile' ),
186 );
187 $css_generator->add_class_styles(
188 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
189 Icon::get_element_image_hover_css( $attributes ),
190 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
191 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
192 );
193
194 return $css_generator->generate_css();
195 }
196
197 public function build_css( $attributes ) {
198 if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
199 return $this->build_css_v2( $attributes );
200 }
201 return $this->build_css_v1( $attributes );
202 }
203
204 public function get_wrapper_css( $attributes, $device = '' ) {
205 $css = [];
206 $position = isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] !== 'stretch';
207
208 if ( $position ) {
209 $css['text-align'] = $attributes['position'][ 'value' . $device ];
210 }
211
212 return $css;
213 }
214
215 public function get_button_css( $attributes, $device = '' ) {
216 $css = [];
217
218 if ( ! empty( $attributes['background'] ) ) {
219 $css['background'] = Color::get_css( isset( $attributes['background'] ) ? $attributes['background'] : '' );
220 } else {
221 $css['background'] = $attributes['buttonType'];
222 }
223
224 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
225 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
226 }
227
228 if ( isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] === 'stretch' ) {
229 $css['width'] = '100%';
230 }
231 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
232 return array_merge(
233 $css,
234 [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ],
235 Range::get_css([
236 'attributeValue' => $attributes['iconSpace'],
237 'attribute_object_key' => 'value',
238 'isResponsive' => true,
239 'defaultValue' => 10,
240 'hasUnit' => true,
241 'unitDefaultValue' => 'px',
242 'property' => 'column-gap',
243 'device' => $device,
244 ]),
245 Border::get_css( $attributes['border'], '', $device ),
246 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
247 Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ),
248 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
249 );
250 }
251
252 public function get_button_hover_css( $attributes, $device = '' ) {
253 $css = [];
254 if ( ! empty( $attributes['transition'] ) ) {
255 $css['transition-duration'] = $attributes['transition'] . 's';
256 }
257 return array_merge(
258 $css,
259 [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ],
260 [ 'background' => Color::get_css( isset( $attributes['backgroundH'] ) ? $attributes['backgroundH'] : '' ) ],
261 Border::get_hover_css( $attributes['border'], '', $device ),
262 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device )
263 );
264 }
265
266 public function get_button_text_css( $attributes, $device = '' ) {
267 return TextShadow::get_css( $attributes['textShadow'] );
268 }
269
270 public function get_icon_hover_css( $attributes, $device = '' ) {
271 return [ 'color' => Color::get_css( isset( $attributes['textColorH'] ) ? $attributes['textColorH'] : '' ) ];
272 }
273
274
275 }
276