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