| 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 |
use ABlocks\Controls\Color; |
| 17 |
|
| 18 |
|
| 19 |
class Block extends BlockBaseAbstract { |
| 20 |
protected $parent_block_name = 'accordion'; |
| 21 |
protected $block_name = 'single-accordion'; |
| 22 |
|
| 23 |
public function build_css( $attributes ) { |
| 24 |
$css_generator = new CssGenerator( $attributes ); |
| 25 |
$css_generator->add_class_styles( |
| 26 |
'{{WRAPPER}}.ablocks-block--single-accordion', |
| 27 |
$this->get_item_css( $attributes ), |
| 28 |
$this->get_item_css( $attributes, 'Tablet' ), |
| 29 |
$this->get_item_css( $attributes, 'Mobile' ), |
| 30 |
); |
| 31 |
$css_generator->add_class_styles( |
| 32 |
'{{WRAPPER}}.ablocks-block--single-accordion:hover', |
| 33 |
$this->get_item_hover_css( $attributes ), |
| 34 |
$this->get_item_hover_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_item_hover_css( $attributes, 'Mobile' ) |
| 36 |
); |
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading .ablocks-block-accordion-title', |
| 39 |
$this->get_title_css( $attributes ), |
| 40 |
$this->get_title_css( $attributes, 'Tablet' ), |
| 41 |
$this->get_title_css( $attributes, 'Mobile' ), |
| 42 |
); |
| 43 |
$css_generator->add_class_styles( |
| 44 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover .ablocks-block-accordion-title', $this->get_title_hover_css( $attributes ), |
| 45 |
$this->get_title_hover_css( $attributes, 'Tablet' ), |
| 46 |
$this->get_title_hover_css( $attributes, 'Mobile' ) |
| 47 |
); |
| 48 |
$css_generator->add_class_styles( |
| 49 |
'{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block-accordion-title', |
| 50 |
$this->get_title_active_css( $attributes ), |
| 51 |
$this->get_title_active_css( $attributes, 'Tablet' ), |
| 52 |
$this->get_title_active_css( $attributes, 'Mobile' ) |
| 53 |
); |
| 54 |
$css_generator->add_class_styles( |
| 55 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading', |
| 56 |
$this->get_panel_css( $attributes ), |
| 57 |
$this->get_panel_css( $attributes, 'Tablet' ), |
| 58 |
$this->get_panel_css( $attributes, 'Mobile' ) |
| 59 |
); |
| 60 |
$css_generator->add_class_styles( |
| 61 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover', |
| 62 |
$this->get_panel_hover_css( $attributes ), |
| 63 |
$this->get_panel_hover_css( $attributes, 'Tablet' ), |
| 64 |
$this->get_panel_hover_css( $attributes, 'Mobile' ), |
| 65 |
); |
| 66 |
$css_generator->add_class_styles( |
| 67 |
'{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block--single-accordion__heading', |
| 68 |
$this->get_panel_active_css( $attributes ), |
| 69 |
$this->get_panel_active_css( $attributes, 'Tablet' ), |
| 70 |
$this->get_panel_active_css( $attributes, 'Mobile' ) |
| 71 |
); |
| 72 |
$css_generator->add_class_styles( |
| 73 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading svg.ablocks-svg-icon', |
| 74 |
$this->get_icon_css( $attributes ) |
| 75 |
); |
| 76 |
$css_generator->add_class_styles( |
| 77 |
'{{WRAPPER}} .ablocks-block--single-accordion__heading:hover svg.ablocks-svg-icon', |
| 78 |
$this->get_icon_hover_css( $attributes ) |
| 79 |
); |
| 80 |
$css_generator->add_class_styles( |
| 81 |
'{{WRAPPER}} .ablocks-block--single-accordion__body-content', |
| 82 |
$this->get_content_css( $attributes ), |
| 83 |
$this->get_content_css( $attributes, 'Tablet' ), |
| 84 |
$this->get_content_css( $attributes, 'Mobile' ) |
| 85 |
); |
| 86 |
$css_generator->add_class_styles( |
| 87 |
'{{WRAPPER}} .ablocks-block--single-accordion__body-content:hover', |
| 88 |
$this->get_content_hover_css( $attributes ), |
| 89 |
$this->get_content_hover_css( $attributes, 'Tablet' ), |
| 90 |
$this->get_content_hover_css( $attributes, 'Mobile' ) |
| 91 |
); |
| 92 |
return $css_generator->generate_css(); |
| 93 |
} |
| 94 |
public function get_item_css( $attributes, $device = '' ) { |
| 95 |
$css = []; |
| 96 |
return array_merge( |
| 97 |
Range::get_css([ |
| 98 |
'attributeValue' => $attributes['itemSpace'], |
| 99 |
'attribute_object_key' => 'value', |
| 100 |
'isResponsive' => false, |
| 101 |
'property' => 'margin-bottom', |
| 102 |
'hasUnit' => false, |
| 103 |
'unitDefaultValue' => 'px', |
| 104 |
'device' => $device, |
| 105 |
] ), |
| 106 |
$css, |
| 107 |
Border::get_css( $attributes['itemBorder'], '', $device ) |
| 108 |
); |
| 109 |
} |
| 110 |
public function get_item_hover_css( $attributes, $device = '' ) { |
| 111 |
return array_merge( |
| 112 |
Border::get_hover_css( $attributes['itemBorder'], '', $device ) |
| 113 |
); |
| 114 |
} |
| 115 |
public function get_title_css( $attributes, $device = '' ) { |
| 116 |
$typographyValueGlobal = ! empty( $attributes['headerTypographyGlobal'] ) ? $attributes['headerTypographyGlobal'] : array(); |
| 117 |
$typography_css = Typography::get_css( $attributes['headerTypography'], '', $device, $typographyValueGlobal ); |
| 118 |
$textShadowCss = TextShadow::get_css( $attributes['headerTextShadow'], '', $device ); |
| 119 |
$textStrokeCss = TextStroke::get_css( $attributes['headerTextStroke'], '', $device ); |
| 120 |
return array_merge( |
| 121 |
[ 'color' => Color::get_css( isset( $attributes['headerTextColor'] ) ? $attributes['headerTextColor'] : '' ) ], |
| 122 |
$typography_css, |
| 123 |
$textShadowCss, |
| 124 |
$textStrokeCss |
| 125 |
); |
| 126 |
} |
| 127 |
|
| 128 |
public function get_title_hover_css( $attributes, $device = '' ) { |
| 129 |
return [ 'color' => Color::get_css( isset( $attributes['headerTextColorH'] ) ? $attributes['headerTextColorH'] : '' ) ]; |
| 130 |
} |
| 131 |
public function get_title_active_css( $attributes, $device = '' ) { |
| 132 |
return [ 'color' => Color::get_css( isset( $attributes['headerTextActiveColor'] ) ? $attributes['headerTextActiveColor'] : '' ) ]; |
| 133 |
} |
| 134 |
public function get_panel_css( $attributes, $device = '' ) { |
| 135 |
return array_merge( |
| 136 |
[ 'background' => Color::get_css( isset( $attributes['headerBackgroundColor'] ) ? $attributes['headerBackgroundColor'] : '' ) ], |
| 137 |
Border::get_css( $attributes['headerBorder'], '', $device ), |
| 138 |
Dimensions::get_css( $attributes['headerPadding'], 'padding', $device ) |
| 139 |
); |
| 140 |
} |
| 141 |
public function get_panel_hover_css( $attributes, $device = '' ) { |
| 142 |
return array_merge( |
| 143 |
[ 'background' => Color::get_css( isset( $attributes['headerBackgroundColorH'] ) ? $attributes['headerBackgroundColorH'] : '' ) ], |
| 144 |
Border::get_hover_css( $attributes['headerBorder'], '', $device ) |
| 145 |
); |
| 146 |
} |
| 147 |
public function get_panel_active_css( $attributes, $device = '' ) { |
| 148 |
return [ 'background' => Color::get_css( isset( $attributes['headerBackgroundActiveColor'] ) ? $attributes['headerBackgroundActiveColor'] : '' ) ]; |
| 149 |
} |
| 150 |
public function get_icon_css( $attributes, $device = '' ) { |
| 151 |
return array_merge( |
| 152 |
[ 'fill' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '' ) . ' !important' ], |
| 153 |
Range::get_css( [ |
| 154 |
'attributeValue' => $attributes['iconSize'], |
| 155 |
'attribute_object_key' => 'value', |
| 156 |
'isResponsive' => false, |
| 157 |
'property' => 'font-size', |
| 158 |
'device' => $device, |
| 159 |
] ) |
| 160 |
); |
| 161 |
} |
| 162 |
|
| 163 |
public function get_icon_hover_css( $attributes ) { |
| 164 |
return [ 'fill' => Color::get_css( isset( $attributes['iconColorH'] ) ? $attributes['iconColorH'] : '' ) . ' !important' ]; |
| 165 |
|
| 166 |
} |
| 167 |
public function get_content_css( $attributes, $device = '' ) { |
| 168 |
return array_merge( |
| 169 |
[ 'background' => Color::get_css( isset( $attributes['bodyBackground'] ) ? $attributes['bodyBackground'] : '' ) ], |
| 170 |
Dimensions::get_css( $attributes['bodyPadding'], 'padding', $device ) |
| 171 |
); |
| 172 |
} |
| 173 |
public function get_content_hover_css( $attributes, $device = '' ) { |
| 174 |
return [ 'background' => Color::get_css( isset( $attributes['bodyBackgroundH'] ) ? $attributes['bodyBackgroundH'] : '' ) ]; |
| 175 |
} |
| 176 |
} |
| 177 |
|