| @@ -1,10 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\DualButton; |
| 3 | 3 | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 4 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 9 | +use ABlocks\Controls\Typography; | |
| 5 | 10 | use ABlocks\Controls\Alignment; |
| 6 | 11 | use ABlocks\Classes\CssGenerator; |
| 12 | +use ABlocks\Classes\CssGeneratorV2; | |
| 7 | 13 | use ABlocks\Controls\Range; |
| 8 | 14 | |
| 9 | 15 | |
| 10 | 16 | class Block extends BlockBaseAbstract { |
| @@ -9,9 +15,9 @@ | ||
| 9 | 15 | |
| 10 | 16 | class Block extends BlockBaseAbstract { |
| 11 | 17 | protected $block_name = 'dual-button'; |
| 12 | 18 | |
| 13 | - public function build_css( $attributes ) { | |
| 19 | + public function build_css_v1( $attributes ) { | |
| 14 | 20 | |
| 15 | 21 | $css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 16 | 22 | |
| 17 | 23 | $css_generator->add_class_styles( |
| @@ -17,14 +23,49 @@ | ||
| 17 | 23 | $css_generator->add_class_styles( |
| 18 | 24 | '{{WRAPPER}}.ablocks-block--dual-button > .ablocks-block-container', |
| 19 | 25 | $this->getDualButtonCss( $attributes ), |
| 20 | 26 | $this->getDualButtonCss( $attributes, 'Tablet' ), |
| 21 | - $this->getDualButtonCss( $attributes, 'Mobile' ) | |
| 27 | + $this->getDualButtonCss( $attributes, 'Mobile' ), | |
| 28 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getDualButtonCss( $attributes, $device ); } ) | |
| 22 | 29 | ); |
| 30 | + $css_generator->add_class_styles( | |
| 31 | + '{{WRAPPER}} .ablocks-button', | |
| 32 | + $this->get_button_css( $attributes ), | |
| 33 | + $this->get_button_css( $attributes, 'Tablet' ), | |
| 34 | + $this->get_button_css( $attributes, 'Mobile' ), | |
| 35 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } ) | |
| 36 | + ); | |
| 23 | 37 | |
| 24 | 38 | return $css_generator->generate_css(); |
| 25 | 39 | } |
| 40 | + public function build_css_v2( $attributes ) { | |
| 26 | 41 | |
| 42 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 43 | + | |
| 44 | + $css_generator->add_class_styles( | |
| 45 | + '{{WRAPPER}}:not(.ablocks-has-block-container), {{WRAPPER}}.ablocks-block--dual-button > .ablocks-block-container', | |
| 46 | + $this->getDualButtonCss( $attributes ), | |
| 47 | + $this->getDualButtonCss( $attributes, 'Tablet' ), | |
| 48 | + $this->getDualButtonCss( $attributes, 'Mobile' ), | |
| 49 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getDualButtonCss( $attributes, $device ); } ) | |
| 50 | + ); | |
| 51 | + $css_generator->add_class_styles( | |
| 52 | + '{{WRAPPER}} .ablocks-button', | |
| 53 | + $this->get_button_css( $attributes ), | |
| 54 | + $this->get_button_css( $attributes, 'Tablet' ), | |
| 55 | + $this->get_button_css( $attributes, 'Mobile' ), | |
| 56 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } ) | |
| 57 | + ); | |
| 58 | + | |
| 59 | + return $css_generator->generate_css(); | |
| 60 | + } | |
| 61 | + public function build_css( $attributes ) { | |
| 62 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 63 | + return $this->build_css_v2( $attributes ); | |
| 64 | + } | |
| 65 | + return $this->build_css_v1( $attributes ); | |
| 66 | + } | |
| 67 | + | |
| 27 | 68 | public function getDualButtonCss( $attributes, $device = '' ) { |
| 28 | 69 | $css = []; |
| 29 | 70 | $stack = isset( $attributes['stack'] ) ? $attributes['stack'] : ''; |
| 30 | 71 | |
| @@ -50,7 +91,15 @@ | ||
| 50 | 91 | 'device' => $device, |
| 51 | 92 | ]), |
| 52 | 93 | $css, |
| 53 | 94 | isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], $attributes['stack'] === 'horizontal' ? 'justify-content' : 'align-items', $device ) : [], |
| 95 | + ); | |
| 96 | + } | |
| 97 | + public function get_button_css( $attributes, $device = '' ) { | |
| 98 | + $css = []; | |
| 99 | + $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : ''; | |
| 100 | + return array_merge( | |
| 101 | + $css, | |
| 102 | + Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ), | |
| 54 | 103 | ); |
| 55 | 104 | } |
| 56 | 105 | } |