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

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

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