| @@ -1,7 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\lists; |
| 3 | 3 | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 4 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 5 | 9 | use ABlocks\Classes\CssGenerator; |
| 6 | 10 | use ABlocks\Controls\Alignment; |
| 7 | 11 | use ABlocks\Controls\Dimensions; |
| @@ -7,16 +11,18 @@ | ||
| 7 | 11 | use ABlocks\Controls\Dimensions; |
| 8 | 12 | use ABlocks\Controls\Typography; |
| 9 | 13 | use ABlocks\Controls\Width; |
| 10 | 14 | use ABlocks\Controls\Border; |
| 15 | +use ABlocks\Classes\CssGeneratorV2; | |
| 16 | +use ABlocks\Controls\Range; | |
| 17 | +use ABlocks\Controls\Color; | |
| 11 | 18 | |
| 12 | 19 | class Block extends BlockBaseAbstract { |
| 13 | 20 | |
| 14 | 21 | protected $block_name = 'lists'; |
| 15 | 22 | |
| 16 | - public function build_css( $attributes ) { | |
| 17 | - // Generate CSS | |
| 18 | - $css_generator = new CssGenerator( $attributes ); | |
| 23 | + public function build_css_v1( $attributes ) { | |
| 24 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 19 | 25 | // Wrapper CSS |
| 20 | 26 | $css_generator->add_class_styles( |
| 21 | 27 | '{{WRAPPER}}', |
| 22 | 28 | $this->get_wrapper_css( $attributes, '' ), |
| @@ -75,15 +81,91 @@ | ||
| 75 | 81 | ); |
| 76 | 82 | |
| 77 | 83 | return $css_generator->generate_css(); |
| 78 | 84 | } |
| 85 | + public function build_css_v2( $attributes ) { | |
| 86 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 87 | + // Wrapper CSS | |
| 88 | + $css_generator->add_class_styles( | |
| 89 | + '{{WRAPPER}}', | |
| 90 | + $this->get_wrapper_css( $attributes, '' ), | |
| 91 | + $this->get_wrapper_css( $attributes, 'Tablet' ), | |
| 92 | + $this->get_wrapper_css( $attributes, 'Mobile' ), | |
| 93 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) | |
| 94 | + ); | |
| 95 | + // List CSS | |
| 96 | + $css_generator->add_class_styles( | |
| 97 | + '{{WRAPPER}} .ablocks-list', | |
| 98 | + $this->get_list_css( $attributes, '' ), | |
| 99 | + $this->get_list_css( $attributes, 'Tablet' ), | |
| 100 | + $this->get_list_css( $attributes, 'Mobile' ), | |
| 101 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_css( $attributes, $device ); } ) | |
| 102 | + ); | |
| 103 | + // List Wrapper CSS | |
| 104 | + $css_generator->add_class_styles( | |
| 105 | + '{{WRAPPER}} .ablocks-list__item-content', | |
| 106 | + $this->get_list_wrapper_css( $attributes, '' ), | |
| 107 | + $this->get_list_wrapper_css( $attributes, 'Tablet' ), | |
| 108 | + $this->get_list_wrapper_css( $attributes, 'Mobile' ), | |
| 109 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_wrapper_css( $attributes, $device ); } ) | |
| 110 | + ); | |
| 79 | 111 | |
| 112 | + $css_generator->add_class_styles( | |
| 113 | + '{{WRAPPER}} .ablocks-list_item-content-divider', | |
| 114 | + $this->get_Divider_Wrapper_css( $attributes, '' ), | |
| 115 | + $this->get_Divider_Wrapper_css( $attributes, 'Tablet' ), | |
| 116 | + $this->get_Divider_Wrapper_css( $attributes, 'Mobile' ), | |
| 117 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_Divider_Wrapper_css( $attributes, $device ); } ) | |
| 118 | + ); | |
| 119 | + // Marker CSS | |
| 120 | + $css_generator->add_class_styles( | |
| 121 | + '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-marker', | |
| 122 | + $this->get_marker_css( $attributes, '' ), | |
| 123 | + $this->get_marker_css( $attributes, 'Tablet' ), | |
| 124 | + $this->get_marker_css( $attributes, 'Mobile' ), | |
| 125 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_marker_css( $attributes, $device ); } ) | |
| 126 | + ); | |
| 127 | + // Icon CSS | |
| 128 | + $css_generator->add_class_styles( | |
| 129 | + '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon', | |
| 130 | + $this->get_icon_css( $attributes, '' ), | |
| 131 | + $this->get_icon_css( $attributes, 'Tablet' ), | |
| 132 | + $this->get_icon_css( $attributes, 'Mobile' ), | |
| 133 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_css( $attributes, $device ); } ) | |
| 134 | + ); | |
| 135 | + // Icon hover css | |
| 136 | + $css_generator->add_class_styles( | |
| 137 | + '{{WRAPPER}} .ablocks-list__item-content .ablocks-svg-icon:hover', | |
| 138 | + $this->get_icon_hover_css( $attributes, '' ), | |
| 139 | + $this->get_icon_hover_css( $attributes, 'Tablet' ), | |
| 140 | + $this->get_icon_hover_css( $attributes, 'Mobile' ), | |
| 141 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_hover_css( $attributes, $device ); } ) | |
| 142 | + ); | |
| 143 | + | |
| 144 | + // List text CSS | |
| 145 | + $css_generator->add_class_styles( | |
| 146 | + '{{WRAPPER}} .ablocks-list__item-content .ablocks-list__item-text', | |
| 147 | + $this->get_list_text_css( $attributes ), | |
| 148 | + $this->get_list_text_css( $attributes, 'Tablet' ), | |
| 149 | + $this->get_list_text_css( $attributes, 'Mobile' ), | |
| 150 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_text_css( $attributes, $device ); } ) | |
| 151 | + ); | |
| 152 | + | |
| 153 | + return $css_generator->generate_css(); | |
| 154 | + } | |
| 155 | + public function build_css( $attributes ) { | |
| 156 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 157 | + return $this->build_css_v2( $attributes ); | |
| 158 | + } | |
| 159 | + return $this->build_css_v1( $attributes ); | |
| 160 | + } | |
| 80 | 161 | public function get_wrapper_css( $attributes, $device = '' ) { |
| 81 | 162 | $typography = isset( $attributes['typography'] ) ? $attributes['typography'] : ''; |
| 82 | 163 | $alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : ''; |
| 164 | + $typographyglobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array(); | |
| 83 | 165 | return array_merge( |
| 84 | 166 | Alignment::get_css( $alignment, 'text-align', $device ), |
| 85 | - Typography::get_css( $typography, '', $device ), | |
| 167 | + Typography::get_css( $typography, '', $device, $typographyglobal ), | |
| 86 | 168 | ); |
| 87 | 169 | } |
| 88 | 170 | |
| 89 | 171 | public function get_list_css( $attributes, $device = '' ) { |
| @@ -144,35 +226,66 @@ | ||
| 144 | 226 | } |
| 145 | 227 | |
| 146 | 228 | public function get_divider_wrapper_css( $attributes, $device = '' ) { |
| 147 | 229 | $css = []; |
| 230 | + $width_css = []; | |
| 231 | + $weight_css = []; | |
| 148 | 232 | |
| 149 | 233 | if ( isset( $attributes['divider'] ) && ! empty( $attributes['divider'] ) ) { |
| 150 | - $weight_value = isset( $attributes['weight'][ 'value' . $device ] ) ? $attributes['weight'][ 'value' . $device ] : 1; | |
| 151 | - $weight_unit = isset( $attributes['weight'][ 'valueUnit' . $device ] ) ? $attributes['weight'][ 'valueUnit' . $device ] : 'px'; | |
| 152 | - | |
| 153 | - $border_color = isset( $attributes['borderColor'] ) ? $attributes['borderColor'] : 'black'; | |
| 234 | + $border_color = Color::get_css( | |
| 235 | + isset( $attributes['borderColor'] ) ? $attributes['borderColor'] : 'black'); | |
| 154 | 236 | $divider_pattern_url = isset( $attributes['dividerPatternUrl'] ) ? $attributes['dividerPatternUrl'] : ''; |
| 155 | 237 | $stack = isset( $attributes['stack'] ) ? $attributes['stack'] : ''; |
| 156 | 238 | |
| 157 | 239 | if ( ! empty( $divider_pattern_url ) ) { |
| 158 | 240 | if ( $stack === 'vertical' ) { |
| 159 | - $css['border-bottom'] = "{$weight_value}{$weight_unit} {$divider_pattern_url} {$border_color}"; | |
| 241 | + $css['border-bottom-color'] = $border_color; | |
| 242 | + $css['border-bottom-style'] = $divider_pattern_url; | |
| 243 | + $weight_css = Range::get_css([ | |
| 244 | + 'attributeValue' => $attributes['weight'], | |
| 245 | + 'attribute_object_key' => 'value', | |
| 246 | + 'isResponsive' => true, | |
| 247 | + 'defaultValue' => 5, | |
| 248 | + 'hasUnit' => true, | |
| 249 | + 'unitDefaultValue' => 'px', | |
| 250 | + 'property' => 'border-bottom-width', | |
| 251 | + 'device' => $device, | |
| 252 | + ]); | |
| 160 | 253 | } elseif ( $stack === 'horizontal' ) { |
| 161 | - $css['border-right'] = "{$weight_value}{$weight_unit} {$divider_pattern_url} {$border_color}"; | |
| 162 | - } | |
| 163 | - } | |
| 254 | + $css['border-right-color'] = $border_color; | |
| 255 | + $css['border-right-style'] = $divider_pattern_url; | |
| 256 | + $weight_css = Range::get_css([ | |
| 257 | + 'attributeValue' => $attributes['weight'], | |
| 258 | + 'attribute_object_key' => 'value', | |
| 259 | + 'isResponsive' => true, | |
| 260 | + 'defaultValue' => 5, | |
| 261 | + 'hasUnit' => true, | |
| 262 | + 'unitDefaultValue' => 'px', | |
| 263 | + 'property' => 'border-right-width', | |
| 264 | + 'device' => $device, | |
| 265 | + ]); | |
| 266 | + }//end if | |
| 267 | + }//end if | |
| 164 | 268 | |
| 165 | - if ( $stack === 'horizontal' ) { | |
| 166 | - $width_value = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : '0'; | |
| 167 | - } else { | |
| 168 | - $width_value = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : '100'; | |
| 169 | - $width_unit = isset( $attributes['width'][ 'valueUnit' . $device ] ) ? $attributes['width'][ 'valueUnit' . $device ] : '%'; | |
| 170 | - $css['width'] = "{$width_value}{$width_unit}"; | |
| 269 | + if ( $stack === 'vertical' && ! empty( $attributes['width'][ 'value' . $device ] ) ) { | |
| 270 | + $width_css = Range::get_css([ | |
| 271 | + 'attributeValue' => $attributes['width'], | |
| 272 | + 'attribute_object_key' => 'value', | |
| 273 | + 'isResponsive' => true, | |
| 274 | + 'defaultValue' => 100, | |
| 275 | + 'hasUnit' => true, | |
| 276 | + 'unitDefaultValue' => 'px', | |
| 277 | + 'property' => 'width', | |
| 278 | + 'device' => $device, | |
| 279 | + ]); | |
| 171 | 280 | } |
| 172 | 281 | }//end if |
| 173 | 282 | |
| 174 | - return $css; | |
| 283 | + return array_merge( | |
| 284 | + $css, | |
| 285 | + $weight_css, | |
| 286 | + $width_css | |
| 287 | + ); | |
| 175 | 288 | } |
| 176 | 289 | |
| 177 | 290 | |
| 178 | 291 | |
| @@ -179,9 +292,10 @@ | ||
| 179 | 292 | public function get_marker_css( $attributes, $device = '' ) { |
| 180 | 293 | $css = []; |
| 181 | 294 | $marker_size = isset( $attributes['markerSize'][ 'value' . $device ] ) ? $attributes['markerSize'][ 'value' . $device ] : ''; |
| 182 | 295 | if ( isset( $attributes['markerColor'] ) && ! empty( $attributes['markerColor'] ) ) { |
| 183 | - $css['background'] = $attributes['markerColor']; | |
| 296 | + $css['background'] = Color::get_css( | |
| 297 | + isset( $attributes['markerColor'] ) ? $attributes['markerColor'] : ''); | |
| 184 | 298 | } |
| 185 | 299 | |
| 186 | 300 | if ( $marker_size && ! empty( $marker_size ) ) { |
| 187 | 301 | $css['max-width'] = $marker_size . 'px'; |
| @@ -187,8 +301,9 @@ | ||
| 187 | 301 | $css['max-width'] = $marker_size . 'px'; |
| 188 | 302 | $css['max-height'] = $marker_size . 'px'; |
| 189 | 303 | $css['min-width'] = $marker_size . 'px'; |
| 190 | 304 | $css['min-height'] = $marker_size . 'px'; |
| 305 | + $css['margin-top'] = 'calc((1lh - ' . $marker_size . 'px) / 2)'; | |
| 191 | 306 | } |
| 192 | 307 | |
| 193 | 308 | return $css; |
| 194 | 309 | } |
| @@ -202,9 +317,10 @@ | ||
| 202 | 317 | if ( isset( $attributes['markerType'] ) && $attributes['markerType'] === 'icon' ) { |
| 203 | 318 | if ( $attributes['iconType'] === 'stacked' ) { |
| 204 | 319 | $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : '#ddd'; |
| 205 | 320 | $css['padding'] = '.2em'; |
| 206 | - $css['color'] = ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#000000'; | |
| 321 | + $css['color'] = Color::get_css( | |
| 322 | + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#000000'); | |
| 207 | 323 | |
| 208 | 324 | if ( $attributes['iconShape'] === 'circle' ) { |
| 209 | 325 | $css['border-radius'] = '50px'; |
| 210 | 326 | } |
| @@ -210,9 +326,10 @@ | ||
| 210 | 326 | } |
| 211 | 327 | } elseif ( $attributes['iconType'] === 'framed' ) { |
| 212 | 328 | $css['background'] = ! empty( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : 'transparent'; |
| 213 | 329 | $css['padding'] = '.2em'; |
| 214 | - $css['color'] = ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d'; | |
| 330 | + $css['color'] = Color::get_css( | |
| 331 | + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d'); | |
| 215 | 332 | $css['border'] = '2px solid ' . ( ! empty( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#69727d' ); |
| 216 | 333 | |
| 217 | 334 | if ( $attributes['iconShape'] === 'circle' ) { |
| 218 | 335 | $css['border-radius'] = '50px'; |
| @@ -218,30 +335,35 @@ | ||
| 218 | 335 | $css['border-radius'] = '50px'; |
| 219 | 336 | } |
| 220 | 337 | } |
| 221 | 338 | |
| 222 | - $defaultUnit = 'px'; | |
| 339 | + if ( ! empty( $attributes[ 'iconColor' . $device ] ) && isset( $attributes[ 'iconColor' . $device ] ) ) { | |
| 340 | + $css['color'] = Color::get_css( | |
| 341 | + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : ''); | |
| 342 | + $css['fill'] = Color::get_css( | |
| 343 | + isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : ''); | |
| 223 | 344 | |
| 224 | - $unit = ! empty( $attributes['iconSize'][ 'valueUnit' . $device ] ) ? $attributes['iconSize'][ 'valueUnit' . $device ] : $defaultUnit; | |
| 225 | - | |
| 226 | - if ( ! empty( $attributes['iconSize'][ 'value' . $device ] ) ) { | |
| 227 | - $css['font-size'] = $attributes['iconSize'][ 'value' . $device ] . $unit; | |
| 228 | 345 | } |
| 229 | 346 | |
| 230 | - if ( ! empty( $attributes[ 'iconColor' . $device ] ) && isset( $attributes[ 'iconColor' . $device ] ) ) { | |
| 231 | - $css['color'] = $attributes['iconColor']; | |
| 232 | - $css['fill'] = $attributes['iconColor']; | |
| 233 | - } | |
| 347 | + if ( ! empty( $attributes['iconBackgroundColor'] ) ) { | |
| 348 | + $css['background'] = Color::get_css( | |
| 349 | + isset( $attributes['iconBackgroundColor'] ) ? $attributes['iconBackgroundColor'] : ''); | |
| 234 | 350 | |
| 235 | - if ( isset( $attributes['iconBackground'] ) && $attributes['iconBackground'] ) { | |
| 236 | - if ( ! empty( $attributes['iconBackgroundColor'] ) ) { | |
| 237 | - $css['background'] = $attributes['iconBackgroundColor']; | |
| 238 | - } | |
| 239 | 351 | } |
| 240 | 352 | }//end if |
| 241 | 353 | |
| 242 | 354 | return array_merge( |
| 243 | 355 | $css, |
| 356 | + Range::get_css([ | |
| 357 | + 'attributeValue' => $attributes['iconSize'], | |
| 358 | + 'attribute_object_key' => 'value', | |
| 359 | + 'isResponsive' => true, | |
| 360 | + 'defaultValue' => 20, | |
| 361 | + 'hasUnit' => true, | |
| 362 | + 'unitDefaultValue' => 'px', | |
| 363 | + 'property' => 'font-size', | |
| 364 | + 'device' => $device, | |
| 365 | + ]), | |
| 244 | 366 | isset( $attributes['border'] ) ? Border::get_css( $attributes['border'], '', $device ) : [], |
| 245 | 367 | Dimensions::get_css( $padding, 'padding', $device ) |
| 246 | 368 | ); |
| 247 | 369 | } |
| @@ -255,11 +377,7 @@ | ||
| 255 | 377 | } |
| 256 | 378 | |
| 257 | 379 | public function get_list_text_css( $attributes, $device = '' ) { |
| 258 | 380 | $css = []; |
| 259 | - if ( isset( $attributes['textColor'] ) ) { | |
| 260 | - $css['color'] = $attributes['textColor']; | |
| 261 | - } | |
| 262 | - | |
| 263 | - return $css; | |
| 381 | + return [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ]; | |
| 264 | 382 | } |
| 265 | 383 | } |