| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\ProgressTracker; |
| 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\TextShadow; |
| 12 |
use ABlocks\Controls\TextStroke; |
| 13 |
use ABlocks\Controls\Typography; |
| 14 |
use Google\Service\Slides\Shadow; |
| 15 |
use ABlocks\Controls\Border; |
| 16 |
use ABlocks\Controls\Range; |
| 17 |
|
| 18 |
class Block extends BlockBaseAbstract { |
| 19 |
protected $block_name = 'progress-tracker'; |
| 20 |
|
| 21 |
public function build_css( $attributes ) { |
| 22 |
// Generate CSS start |
| 23 |
$css_generator = new CssGenerator( $attributes ); |
| 24 |
|
| 25 |
// Generate wrapper CSS start |
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}} .ablocks-block-progress-circle', |
| 28 |
$this->get_wrapper_css( $attributes ), |
| 29 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 30 |
$this->get_wrapper_css( $attributes, 'Mobile' ) |
| 31 |
); |
| 32 |
|
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .ablocks-block-progress__text', |
| 35 |
$this->get_content_css( $attributes ), |
| 36 |
$this->get_content_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_content_css( $attributes, 'Mobile' ) |
| 38 |
); |
| 39 |
// Progress Bar Background CSS |
| 40 |
$css_generator->add_class_styles( |
| 41 |
'{{WRAPPER}} .ablocks-block-progress-bar-track', |
| 42 |
$this->get_progress_bar_track_css( $attributes ), |
| 43 |
$this->get_progress_bar_track_css( $attributes, 'Tablet' ), |
| 44 |
$this->get_progress_bar_track_css( $attributes, 'Mobile' ) |
| 45 |
); |
| 46 |
|
| 47 |
$css_generator->add_class_styles( |
| 48 |
'{{WRAPPER}} .ablocks-block-progress-bar-track:hover', |
| 49 |
$this->get_progress_bar_hover_css( $attributes ), |
| 50 |
$this->get_progress_bar_hover_css( $attributes, 'Tablet' ), |
| 51 |
$this->get_progress_bar_hover_css( $attributes, 'Mobile' ) |
| 52 |
); |
| 53 |
|
| 54 |
// Progress Bar Progress CSS |
| 55 |
$css_generator->add_class_styles( |
| 56 |
'{{WRAPPER}} .ablocks-block-progress-bar', |
| 57 |
$this->get_progress_bar_css( $attributes ) |
| 58 |
); |
| 59 |
|
| 60 |
// circle css |
| 61 |
$css_generator->add_class_styles( |
| 62 |
'{{WRAPPER}} .ablocks-block-progress-circle__svg-bar', |
| 63 |
$this->get_progress_circle_css( $attributes ), |
| 64 |
); |
| 65 |
$css_generator->add_class_styles( |
| 66 |
'{{WRAPPER}} .ablocks-block-progress-circle__svg-track', |
| 67 |
$this->get_progress_circle_bg_css( $attributes ), |
| 68 |
); |
| 69 |
|
| 70 |
return $css_generator->generate_css(); |
| 71 |
} |
| 72 |
|
| 73 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 74 |
$alignment_key = 'value' . $device; |
| 75 |
$alignment = isset( $attributes['alignment'][ $alignment_key ] ) |
| 76 |
? $attributes['alignment'][ $alignment_key ] |
| 77 |
: 'center'; |
| 78 |
switch ( $alignment ) { |
| 79 |
case 'center': |
| 80 |
$justify_content_value = 'center'; |
| 81 |
break; |
| 82 |
case 'right': |
| 83 |
$justify_content_value = 'flex-end'; |
| 84 |
break; |
| 85 |
default: |
| 86 |
$justify_content_value = 'flex-start'; |
| 87 |
break; |
| 88 |
} |
| 89 |
return array( |
| 90 |
'display' => 'flex', |
| 91 |
'justify-content' => $justify_content_value, |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
public function get_content_css( $attributes, $device = '' ) { |
| 97 |
$content_css = []; |
| 98 |
if ( ! empty( $attributes['contentColor'] ) ) { |
| 99 |
$content_css['color'] = $attributes['contentColor']; |
| 100 |
} |
| 101 |
$typography = isset( $attributes['contentTypography'] ) ? $attributes['contentTypography'] : ''; |
| 102 |
$text_stroke = isset( $attributes['contentTextStroke'] ) ? $attributes['contentTextStroke'] : ''; |
| 103 |
$text_shadow = isset( $attributes['contentTextShadow'] ) ? $attributes['contentTextShadow'] : ''; |
| 104 |
return array_merge( |
| 105 |
$content_css, |
| 106 |
Typography::get_css( $typography, '', $device ), |
| 107 |
TextStroke::get_css( $text_stroke, '', $device ), |
| 108 |
TextShadow::get_css( $text_shadow, '', $device ) |
| 109 |
); |
| 110 |
} |
| 111 |
public function get_progress_bar_track_css( $attributes, $device = '' ) { |
| 112 |
$css = []; |
| 113 |
if ( ! empty( $attributes['barBackgroundColor'] ) ) { |
| 114 |
$css['background'] = $attributes['barBackgroundColor']; |
| 115 |
} |
| 116 |
return array_merge( |
| 117 |
Range::get_css([ |
| 118 |
'attributeValue' => $attributes['barHeightSize'], |
| 119 |
'attribute_object_key' => 'value', |
| 120 |
'isResponsive' => true, |
| 121 |
'defaultValue' => 40, |
| 122 |
'hasUnit' => true, |
| 123 |
'unitDefaultValue' => 'px', |
| 124 |
'property' => 'height', |
| 125 |
'device' => $device, |
| 126 |
]), |
| 127 |
isset( $attributes['barBorder'] ) ? Border::get_css( $attributes['barBorder'], '', $device ) : [], |
| 128 |
$css, |
| 129 |
); |
| 130 |
} |
| 131 |
public function get_progress_bar_hover_css( $attributes, $device = '' ) { |
| 132 |
return array_merge( |
| 133 |
isset( $attributes['barBorder'] ) ? Border::get_hover_css( $attributes['barBorder'], '', $device ) : [] |
| 134 |
); |
| 135 |
} |
| 136 |
|
| 137 |
public function get_progress_bar_css( $attributes ) { |
| 138 |
$css = []; |
| 139 |
if ( ! empty( $attributes['barProgressColor'] ) ) { |
| 140 |
$css['background'] = $attributes['barProgressColor']; |
| 141 |
} |
| 142 |
if ( ! empty( $attributes['direction'] ) && $attributes['direction'] === 'left' ) { |
| 143 |
$css['justify-content'] = 'right'; |
| 144 |
} elseif ( ! empty( $attributes['direction'] ) && $attributes['direction'] === 'right' ) { |
| 145 |
$css['justify-content'] = 'left'; |
| 146 |
} |
| 147 |
return $css; |
| 148 |
} |
| 149 |
|
| 150 |
public function get_progress_circle_css( $attributes ) { |
| 151 |
$css = []; |
| 152 |
if ( $attributes['circleProgressColor'] ) { |
| 153 |
$css['stroke'] = $attributes['circleProgressColor']; |
| 154 |
} |
| 155 |
return $css; |
| 156 |
} |
| 157 |
|
| 158 |
public function get_progress_circle_bg_css( $attributes ) { |
| 159 |
$css = []; |
| 160 |
if ( $attributes['circleBackgroundColor'] ) { |
| 161 |
$css['stroke'] = $attributes['circleBackgroundColor']; |
| 162 |
} |
| 163 |
return array_merge( |
| 164 |
Range::get_css([ |
| 165 |
'attributeValue' => $attributes['circleStrokeSize'], |
| 166 |
'attribute_object_key' => 'value', |
| 167 |
'defaultValue' => 10, |
| 168 |
'unitDefaultValue' => 'px', |
| 169 |
'property' => 'stroke-width' |
| 170 |
]), |
| 171 |
$css, |
| 172 |
); |
| 173 |
} |
| 174 |
} |
| 175 |
|