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 / stripe-button / block.php

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

183 lines 5.8 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\Controls\Alignment;
11 use ABlocks\Controls\Border;
12 use ABlocks\Controls\BoxShadow;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\TextShadow;
16 use ABlocks\Controls\Icon;
17 class Block extends BlockBaseAbstract {
18 protected $block_name = 'stripe-button';
19
20 public function build_css( $attributes ) {
21
22 // Generate CSS start
23 $css_generator = new CssGenerator( $attributes, $this->block_name );
24
25 // Generate wrapper CSS start
26 $css_generator->add_class_styles(
27 '{{WRAPPER}}',
28 $this->get_wrapper_css( $attributes ),
29 $this->get_wrapper_css( $attributes, 'Tablet' ),
30 $this->get_wrapper_css( $attributes, 'Mobile' )
31 );
32 // Generate wrapper CSS end
33
34 // Generate button CSS start
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button',
37 $this->get_button_css( $attributes ),
38 $this->get_button_css( $attributes, 'Tablet' ),
39 $this->get_button_css( $attributes, 'Mobile' )
40 );
41 // Generate button CSS end
42
43 // Generate button hover CSS start
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button:hover',
46 $this->get_button_hover_css( $attributes ),
47 $this->get_button_hover_css( $attributes, 'Tablet' ),
48 $this->get_button_hover_css( $attributes, 'Mobile' )
49 );
50
51 // Generate button icon hover CSS
52 $css_generator->add_class_styles(
53 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button:hover .ablocks-icon-wrap svg.ablocks-svg-icon',
54 $this->get_icon_hover_css( $attributes ),
55 $this->get_icon_hover_css( $attributes, 'Tablet' ),
56 $this->get_icon_hover_css( $attributes, 'Mobile' )
57 );
58
59 // Generate button text CSS start
60 $css_generator->add_class_styles(
61 '{{WRAPPER}} .ablocks-block-container .ablocks-stripe-button .ablocks-stripe-button__text',
62 $this->get_button_text_css( $attributes )
63 );
64
65 // Generate button icon CSS start
66 $css_generator->add_class_styles(
67 '{{WRAPPER}} .ablocks-icon-wrap',
68 Icon::get_wrapper_css( $attributes ),
69 Icon::get_wrapper_css( $attributes, 'Tablet' ),
70 Icon::get_wrapper_css( $attributes, 'Mobile' )
71 );
72
73 $css_generator->add_class_styles(
74 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
75 Icon::get_element_image_css( $attributes ),
76 Icon::get_element_image_css( $attributes, 'Tablet' ),
77 Icon::get_element_image_css( $attributes, 'Mobile' ),
78 );
79 $css_generator->add_class_styles(
80 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
81 Icon::get_element_image_hover_css( $attributes ),
82 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
83 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
84 );
85 $css_generator->add_class_styles(
86 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
87 Icon::get_element_css( $attributes ),
88 Icon::get_element_css( $attributes, 'Tablet' ),
89 Icon::get_element_css( $attributes, 'Mobile' ),
90 );
91 $css_generator->add_class_styles(
92 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
93 Icon::get_element_image_hover_css( $attributes ),
94 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
95 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
96 );
97
98 return $css_generator->generate_css();
99 }
100
101 public function get_wrapper_css( $attributes, $device = '' ) {
102 $css = [];
103 $position = isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] !== 'stretch';
104
105 if ( $position ) {
106 $css['text-align'] = $attributes['position'][ 'value' . $device ];
107 }
108
109 return $css;
110 }
111
112 public function get_button_css( $attributes, $device = '' ) {
113 $css = [];
114
115 if ( ! empty( $attributes['background'] ) ) {
116 $css['background'] = $attributes['background'];
117 } else {
118 $css['background'] = $attributes['buttonType'];
119 }
120
121 if ( isset( $attributes['alignment'][ 'value' . $device ] ) ) {
122 $css['justify-content'] = $attributes['alignment'][ 'value' . $device ];
123 }
124
125 if ( isset( $attributes['position'][ 'value' . $device ] ) && $attributes['position'][ 'value' . $device ] === 'stretch' ) {
126 $css['width'] = '100%';
127 }
128
129 $defaultUnit = 'px';
130
131 $unit = ! empty( $attributes['iconSpace'][ 'valueUnit' . $device ] ) ? $attributes['iconSpace'][ 'valueUnit' . $device ] : $defaultUnit;
132
133 if ( ! empty( $attributes['iconSpace'][ 'value' . $device ] ) ) {
134 $css['column-gap'] = $attributes['iconSpace'][ 'value' . $device ] . $unit;
135 }
136
137 return array_merge(
138 $css,
139 [ 'color' => $attributes['textColor'] ?? '#000000' ],
140 Border::get_css( $attributes['border'], '', $device ),
141 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
142 Typography::get_css( $attributes['typography'], '', $device ),
143 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
144 );
145 }
146
147 public function get_button_hover_css( $attributes, $device = '' ) {
148 $css = [];
149 if ( ! empty( $attributes['textColorH'] ) ) {
150 $css['color'] = $attributes['textColorH'];
151 }
152
153 if ( ! empty( $attributes['backgroundH'] ) ) {
154 $css['background'] = $attributes['backgroundH'];
155 }
156
157 if ( ! empty( $attributes['transition'] ) ) {
158 $css['transition-duration'] = $attributes['transition'] . 's';
159 }
160 return array_merge(
161 $css,
162 Border::get_hover_css( $attributes['border'], '', $device ),
163 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device )
164 );
165 }
166
167 public function get_button_text_css( $attributes, $device = '' ) {
168 return TextShadow::get_css( $attributes['textShadow'] );
169 }
170
171 public function get_icon_hover_css( $attributes, $device = '' ) {
172 $css = [];
173
174 if ( ! empty( $attributes['textColorH'] ) ) {
175 $css['fill'] = $attributes['textColorH'];
176 }
177
178 return $css;
179 }
180
181
182 }
183