| @@ -9,20 +9,22 @@ | ||
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | use ABlocks\Classes\BlockBaseAbstract; |
| 12 | 12 | use ABlocks\Classes\CssGenerator; |
| 13 | +use ABlocks\Classes\CssGeneratorV2; | |
| 13 | 14 | use ABlocks\Controls\Alignment; |
| 14 | 15 | |
| 15 | 16 | class Block extends BlockBaseAbstract { |
| 16 | 17 | protected $block_name = 'chart'; |
| 17 | 18 | protected $script_depends = [ 'ablocks-chart.js-script' ]; |
| 18 | - public function build_css( $attributes ) { | |
| 19 | + public function build_css_v1( $attributes ) { | |
| 19 | 20 | $css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 20 | 21 | $css_generator->add_class_styles( |
| 21 | 22 | '{{WRAPPER}}', |
| 22 | 23 | $this->get_wrapper_css( $attributes ), |
| 23 | 24 | $this->get_wrapper_css( $attributes, 'Tablet' ), |
| 24 | - $this->get_wrapper_css( $attributes, 'Mobile' ) | |
| 25 | + $this->get_wrapper_css( $attributes, 'Mobile' ), | |
| 26 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) | |
| 25 | 27 | ); |
| 26 | 28 | |
| 27 | 29 | $css_generator->add_class_styles( |
| 28 | 30 | '{{WRAPPER}} .ablocks-chart-canvas', |
| @@ -27,12 +29,39 @@ | ||
| 27 | 29 | $css_generator->add_class_styles( |
| 28 | 30 | '{{WRAPPER}} .ablocks-chart-canvas', |
| 29 | 31 | $this->get_chart_css( $attributes ), |
| 30 | 32 | $this->get_chart_css( $attributes, 'Tablet' ), |
| 31 | - $this->get_chart_css( $attributes, 'Mobile' ) | |
| 33 | + $this->get_chart_css( $attributes, 'Mobile' ), | |
| 34 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_chart_css( $attributes, $device ); } ) | |
| 32 | 35 | ); |
| 33 | 36 | |
| 34 | 37 | return $css_generator->generate_css(); |
| 38 | + } | |
| 39 | + public function build_css_v2( $attributes ) { | |
| 40 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 41 | + $css_generator->add_class_styles( | |
| 42 | + '{{WRAPPER}}', | |
| 43 | + $this->get_wrapper_css( $attributes ), | |
| 44 | + $this->get_wrapper_css( $attributes, 'Tablet' ), | |
| 45 | + $this->get_wrapper_css( $attributes, 'Mobile' ), | |
| 46 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) | |
| 47 | + ); | |
| 48 | + | |
| 49 | + $css_generator->add_class_styles( | |
| 50 | + '{{WRAPPER}} .ablocks-chart-canvas', | |
| 51 | + $this->get_chart_css( $attributes ), | |
| 52 | + $this->get_chart_css( $attributes, 'Tablet' ), | |
| 53 | + $this->get_chart_css( $attributes, 'Mobile' ), | |
| 54 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_chart_css( $attributes, $device ); } ) | |
| 55 | + ); | |
| 56 | + | |
| 57 | + return $css_generator->generate_css(); | |
| 58 | + } | |
| 59 | + public function build_css( $attributes ) { | |
| 60 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 61 | + return $this->build_css_v2( $attributes ); | |
| 62 | + } | |
| 63 | + return $this->build_css_v1( $attributes ); | |
| 35 | 64 | } |
| 36 | 65 | |
| 37 | 66 | public function get_wrapper_css( $attributes, $device = '' ) { |
| 38 | 67 | return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : []; |