| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\SingleAccordion; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
use ABlocks\Controls\Typography; |
| 11 |
use ABlocks\Controls\TextShadow; |
| 12 |
use ABlocks\Controls\TextStroke; |
| 13 |
use ABlocks\Controls\Border; |
| 14 |
use ABlocks\Controls\Dimensions; |
| 15 |
use ABlocks\Controls\Range; |
| 16 |
|
| 17 |
class Block extends BlockBaseAbstract { |
| 18 |
protected $parent_block_name = 'accordion'; |
| 19 |
protected $block_name = 'single-accordion'; |
| 20 |
|
| 21 |
public function build_css( $attributes ) { |
| 22 |
$css_generator = new CssGenerator( $attributes ); |
| 23 |
$css_generator->add_class_styles( |
| 24 |
'{{WRAPPER}}.ablocks-block--single-accordion', |
| 25 |
$this->get_item_css( $attributes ), |
| 26 |
$this->get_item_css( $attributes, 'Tablet' ), |
| 27 |
$this->get_item_css( $attributes, 'Mobile' ), |
| 28 |
); |
| 29 |
$css_generator->add_class_styles( |
| 30 |
'{{WRAPPER}}.ablocks-block--single-accordion:hover', |
| 31 |
$this->get_item_hover_css( $attributes ), |
| 32 |
$this->get_item_hover_css( $attributes, 'Tablet' ), |
| 33 |
$this->get_item_hover_css( $attributes, 'Mobile' ) |
| 34 |
); |
| 35 |
$css_generator->add_class_styles( |
| 36 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading .ablocks-block-accordion-title', |
| 37 |
$this->get_title_css( $attributes ), |
| 38 |
$this->get_title_css( $attributes, 'Tablet' ), |
| 39 |
$this->get_title_css( $attributes, 'Mobile' ), |
| 40 |
); |
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover .ablocks-block-accordion-title', $this->get_title_hover_css( $attributes ), |
| 43 |
$this->get_title_hover_css( $attributes, 'Tablet' ), |
| 44 |
$this->get_title_hover_css( $attributes, 'Mobile' ) |
| 45 |
); |
| 46 |
$css_generator->add_class_styles( |
| 47 |
'{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block-accordion-title', |
| 48 |
$this->get_title_active_css( $attributes ), |
| 49 |
$this->get_title_active_css( $attributes, 'Tablet' ), |
| 50 |
$this->get_title_active_css( $attributes, 'Mobile' ) |
| 51 |
); |
| 52 |
$css_generator->add_class_styles( |
| 53 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading', |
| 54 |
$this->get_panel_css( $attributes ), |
| 55 |
$this->get_panel_css( $attributes, 'Tablet' ), |
| 56 |
$this->get_panel_css( $attributes, 'Mobile' ) |
| 57 |
); |
| 58 |
$css_generator->add_class_styles( |
| 59 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover', |
| 60 |
$this->get_panel_hover_css( $attributes ), |
| 61 |
$this->get_panel_hover_css( $attributes, 'Tablet' ), |
| 62 |
$this->get_panel_hover_css( $attributes, 'Mobile' ), |
| 63 |
); |
| 64 |
$css_generator->add_class_styles( |
| 65 |
'{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block--single-accordion__heading', |
| 66 |
$this->get_panel_active_css( $attributes ), |
| 67 |
$this->get_panel_active_css( $attributes, 'Tablet' ), |
| 68 |
$this->get_panel_active_css( $attributes, 'Mobile' ) |
| 69 |
); |
| 70 |
$css_generator->add_class_styles( |
| 71 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading svg.ablocks-svg-icon', |
| 72 |
$this->get_icon_css( $attributes ) |
| 73 |
); |
| 74 |
$css_generator->add_class_styles( |
| 75 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover svg.ablocks-svg-icon', |
| 76 |
$this->get_icon_hover_css( $attributes ) |
| 77 |
); |
| 78 |
$css_generator->add_class_styles( |
| 79 |
'{{WRAPPER}} .ablocks-block--single-accordion__body-content', |
| 80 |
$this->get_content_css( $attributes ), |
| 81 |
$this->get_content_css( $attributes, 'Tablet' ), |
| 82 |
$this->get_content_css( $attributes, 'Mobile' ) |
| 83 |
); |
| 84 |
$css_generator->add_class_styles( |
| 85 |
'{{WRAPPER}} .ablocks-block--single-accordion__body-content:hover', |
| 86 |
$this->get_content_hover_css( $attributes ), |
| 87 |
$this->get_content_hover_css( $attributes, 'Tablet' ), |
| 88 |
$this->get_content_hover_css( $attributes, 'Mobile' ) |
| 89 |
); |
| 90 |
return $css_generator->generate_css(); |
| 91 |
} |
| 92 |
public function get_item_css( $attributes, $device = '' ) { |
| 93 |
$css = []; |
| 94 |
return array_merge( |
| 95 |
Range::get_css([ |
| 96 |
'attributeValue' => $attributes['itemSpace'], |
| 97 |
'attribute_object_key' => 'value', |
| 98 |
'isResponsive' => false, |
| 99 |
'property' => 'margin-bottom', |
| 100 |
'hasUnit' => false, |
| 101 |
'unitDefaultValue' => 'px', |
| 102 |
'device' => $device, |
| 103 |
] ), |
| 104 |
$css, |
| 105 |
Border::get_css( $attributes['itemBorder'], '', $device ) |
| 106 |
); |
| 107 |
} |
| 108 |
public function get_item_hover_css( $attributes, $device = '' ) { |
| 109 |
return array_merge( |
| 110 |
Border::get_hover_css( $attributes['itemBorder'], '', $device ) |
| 111 |
); |
| 112 |
} |
| 113 |
public function get_title_css( $attributes, $device = '' ) { |
| 114 |
$css = []; |
| 115 |
if ( ! empty( $attributes['headerTextColor'] ) ) { |
| 116 |
$css['color'] = $attributes['headerTextColor']; |
| 117 |
} |
| 118 |
$typography_css = Typography::get_css( $attributes['headerTypography'], '', $device ); |
| 119 |
$textShadowCss = TextShadow::get_css( $attributes['headerTextShadow'], '', $device ); |
| 120 |
$textStrokeCss = TextStroke::get_css( $attributes['headerTextStroke'], '', $device ); |
| 121 |
return array_merge( |
| 122 |
$css, |
| 123 |
$typography_css, |
| 124 |
$textShadowCss, |
| 125 |
$textStrokeCss |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
public function get_title_hover_css( $attributes, $device = '' ) { |
| 130 |
$css = []; |
| 131 |
if ( ! empty( $attributes['headerTextColorH'] ) ) { |
| 132 |
$css['color'] = $attributes['headerTextColorH']; |
| 133 |
} |
| 134 |
return array_merge( |
| 135 |
$css, |
| 136 |
); |
| 137 |
} |
| 138 |
public function get_title_active_css( $attributes, $device = '' ) { |
| 139 |
$css = []; |
| 140 |
if ( ! empty( $attributes['headerTextActiveColor'] ) ) { |
| 141 |
$css['color'] = $attributes['headerTextActiveColor']; |
| 142 |
} |
| 143 |
return array_merge( |
| 144 |
$css, |
| 145 |
); |
| 146 |
} |
| 147 |
public function get_panel_css( $attributes, $device = '' ) { |
| 148 |
$css = []; |
| 149 |
if ( ! empty( $attributes['headerBackgroundColor'] ) ) { |
| 150 |
$css['background'] = $attributes['headerBackgroundColor']; |
| 151 |
} |
| 152 |
return array_merge( |
| 153 |
$css, |
| 154 |
Border::get_css( $attributes['headerBorder'], '', $device ), |
| 155 |
Dimensions::get_css( $attributes['headerPadding'], 'padding', $device ) |
| 156 |
); |
| 157 |
} |
| 158 |
public function get_panel_hover_css( $attributes, $device = '' ) { |
| 159 |
$css = []; |
| 160 |
if ( ! empty( $attributes['headerBackgroundColorH'] ) ) { |
| 161 |
$css['background'] = $attributes['headerBackgroundColorH']; |
| 162 |
} |
| 163 |
return array_merge( |
| 164 |
$css, |
| 165 |
Border::get_hover_css( $attributes['headerBorder'], '', $device ) |
| 166 |
); |
| 167 |
} |
| 168 |
public function get_panel_active_css( $attributes, $device = '' ) { |
| 169 |
$css = []; |
| 170 |
if ( ! empty( $attributes['headerBackgroundActiveColor'] ) ) { |
| 171 |
$css['background'] = $attributes['headerBackgroundActiveColor']; |
| 172 |
} |
| 173 |
return array_merge( |
| 174 |
$css, |
| 175 |
); |
| 176 |
} |
| 177 |
public function get_icon_css( $attributes, $device = '' ) { |
| 178 |
$css = []; |
| 179 |
if ( ! empty( $attributes['iconColor'] ) ) { |
| 180 |
$css['fill'] = $attributes['iconColor'] . ' !important'; |
| 181 |
} |
| 182 |
return array_merge( $css, |
| 183 |
Range::get_css( [ |
| 184 |
'attributeValue' => $attributes['iconSize'], |
| 185 |
'attribute_object_key' => 'value', |
| 186 |
'isResponsive' => false, |
| 187 |
'property' => 'font-size', |
| 188 |
'device' => $device, |
| 189 |
] ) |
| 190 |
); |
| 191 |
} |
| 192 |
|
| 193 |
public function get_icon_hover_css( $attributes ) { |
| 194 |
$css = []; |
| 195 |
if ( ! empty( $attributes['iconColorH'] ) ) { |
| 196 |
$css['fill'] = $attributes['iconColorH'] . ' !important'; |
| 197 |
} |
| 198 |
return array_merge( $css ); |
| 199 |
} |
| 200 |
public function get_content_css( $attributes, $device = '' ) { |
| 201 |
$css = []; |
| 202 |
if ( ! empty( $attributes['bodyBackground'] ) ) { |
| 203 |
$css['background'] = $attributes['bodyBackground']; |
| 204 |
} |
| 205 |
return array_merge( |
| 206 |
$css, |
| 207 |
Dimensions::get_css( $attributes['bodyPadding'], 'padding', $device ) |
| 208 |
); |
| 209 |
} |
| 210 |
public function get_content_hover_css( $attributes, $device = '' ) { |
| 211 |
$css = []; |
| 212 |
if ( ! empty( $attributes['bodyBackgroundH'] ) ) { |
| 213 |
$css['background'] = $attributes['bodyBackgroundH']; |
| 214 |
} |
| 215 |
return array_merge( |
| 216 |
$css, |
| 217 |
); |
| 218 |
} |
| 219 |
} |
| 220 |
|