| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\Divider; |
| 4 |
|
| 5 |
use ABlocks\Classes\BlockBaseAbstract; |
| 6 |
use ABlocks\Classes\CssGenerator; |
| 7 |
use ABlocks\Controls\Alignment; |
| 8 |
use ABlocks\Controls\TextStroke; |
| 9 |
use ABlocks\Controls\Typography; |
| 10 |
use ABlocks\Controls\Icon; |
| 11 |
use ABlocks\Controls\Range; |
| 12 |
|
| 13 |
class Block extends BlockBaseAbstract { |
| 14 |
|
| 15 |
protected $block_name = 'divider'; |
| 16 |
|
| 17 |
public function build_css( $attributes ) { |
| 18 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 19 |
$css_generator->add_class_styles( |
| 20 |
'{{WRAPPER}}', |
| 21 |
$this->get_wrapper_css( $attributes ), |
| 22 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 23 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 24 |
); |
| 25 |
|
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}} .ablocks-block-container', |
| 28 |
$this->get_divider_container_css( $attributes ), |
| 29 |
$this->get_divider_container_css( $attributes, 'Tablet' ), |
| 30 |
$this->get_divider_container_css( $attributes, 'Mobile' ), |
| 31 |
); |
| 32 |
|
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .ablocks-divider', |
| 35 |
$this->get_divider_css( $attributes ), |
| 36 |
$this->get_divider_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_divider_css( $attributes, 'Mobile' ), |
| 38 |
); |
| 39 |
// element text |
| 40 |
|
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .ablocks-divider__element-text', |
| 43 |
$this->get_divider_element_text_css( $attributes ), |
| 44 |
$this->get_divider_element_text_css( $attributes, 'Tablet' ), |
| 45 |
$this->get_divider_element_text_css( $attributes, 'Mobile' ), |
| 46 |
); |
| 47 |
// Icon Style |
| 48 |
$css_generator->add_class_styles( |
| 49 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 50 |
Icon::get_wrapper_css( $attributes ), |
| 51 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 52 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 53 |
); |
| 54 |
$css_generator->add_class_styles( |
| 55 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 56 |
array_merge( Icon::get_wrapper_css( $attributes ), $this->get_icon_spacing_margins( $attributes, '' ) ), |
| 57 |
array_merge( Icon::get_wrapper_css( $attributes, 'Tablet' ), $this->get_icon_spacing_margins( $attributes, 'Tablet' ) ), |
| 58 |
array_merge( Icon::get_wrapper_css( $attributes, 'Mobile' ), $this->get_icon_spacing_margins( $attributes, 'Mobile' ) ) |
| 59 |
); |
| 60 |
$css_generator->add_class_styles( |
| 61 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon', |
| 62 |
Icon::get_element_image_css( $attributes ), |
| 63 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 64 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 65 |
); |
| 66 |
$css_generator->add_class_styles( |
| 67 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 68 |
Icon::get_element_image_hover_css( $attributes ), |
| 69 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 70 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 71 |
); |
| 72 |
$css_generator->add_class_styles( |
| 73 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 74 |
Icon::get_element_css( $attributes ), |
| 75 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 76 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 77 |
); |
| 78 |
$css_generator->add_class_styles( |
| 79 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 80 |
Icon::get_element_image_hover_css( $attributes ), |
| 81 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 82 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 83 |
); |
| 84 |
return $css_generator->generate_css(); |
| 85 |
} |
| 86 |
|
| 87 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 88 |
if ( isset( $attributes['alignment'] ) ) { |
| 89 |
return Alignment::get_css( $attributes['alignment'], 'text-align', $device ); |
| 90 |
} |
| 91 |
return []; |
| 92 |
} |
| 93 |
|
| 94 |
public function get_divider_element_text_css( $attributes, $device = '' ) { |
| 95 |
$divider_text_styles = []; |
| 96 |
if ( isset( $attributes['elementTextColor'] ) ) { |
| 97 |
$divider_text_styles['color'] = $attributes['elementTextColor']; |
| 98 |
} |
| 99 |
return array_merge( |
| 100 |
$divider_text_styles, |
| 101 |
Range::get_css([ |
| 102 |
'attributeValue' => $attributes['elementTextSpacing'], |
| 103 |
'attributeObjectKey' => 'value', |
| 104 |
'isResponsive' => true, |
| 105 |
'defaultValue' => 0, |
| 106 |
'hasUnit' => true, |
| 107 |
'unitDefaultValue' => 'px', |
| 108 |
'property' => 'padding-right', |
| 109 |
'device' => $device, |
| 110 |
]), |
| 111 |
Range::get_css([ |
| 112 |
'attributeValue' => $attributes['elementTextSpacing'], |
| 113 |
'attributeObjectKey' => 'value', |
| 114 |
'isResponsive' => true, |
| 115 |
'defaultValue' => 0, |
| 116 |
'hasUnit' => true, |
| 117 |
'unitDefaultValue' => 'px', |
| 118 |
'property' => 'padding-left', |
| 119 |
'device' => $device, |
| 120 |
]), |
| 121 |
Typography::get_css( $attributes['elementTextTypography'], '', $device ), |
| 122 |
TextStroke::get_css( $attributes['elementTextStroke'], '', $device ), |
| 123 |
); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
public function get_divider_container_css( $attributes, $device = '' ) { |
| 128 |
$divider_container_css = []; |
| 129 |
if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 130 |
$divider_container_css['justify-content'] = $attributes['alignment'][ 'value' . $device ]; |
| 131 |
} |
| 132 |
return array_merge( |
| 133 |
Range::get_css([ |
| 134 |
'attributeValue' => $attributes['gap'], |
| 135 |
'attributeObjectKey' => 'value', |
| 136 |
'isResponsive' => true, |
| 137 |
'defaultValue' => 10, |
| 138 |
'unitDefaultValue' => 'px', |
| 139 |
'property' => 'padding-block-start', |
| 140 |
'device' => $device, |
| 141 |
]), |
| 142 |
Range::get_css([ |
| 143 |
'attributeValue' => $attributes['gap'], |
| 144 |
'attributeObjectKey' => 'value', |
| 145 |
'isResponsive' => true, |
| 146 |
'defaultValue' => 10, |
| 147 |
'unitDefaultValue' => 'px', |
| 148 |
'property' => 'padding-block-end', |
| 149 |
'device' => $device, |
| 150 |
]), |
| 151 |
$divider_container_css |
| 152 |
); |
| 153 |
} |
| 154 |
|
| 155 |
public function get_divider_css( $attributes, $device = '' ) { |
| 156 |
$css = []; |
| 157 |
|
| 158 |
$prepared_container = Range::get_css([ |
| 159 |
'attributeValue' => $attributes['width'], |
| 160 |
'attributeObjectKey' => 'value', |
| 161 |
'isResponsive' => true, |
| 162 |
'defaultValue' => 100, |
| 163 |
'hasUnit' => true, |
| 164 |
'unitDefaultValue' => '%', |
| 165 |
'property' => 'value', |
| 166 |
'device' => $device, |
| 167 |
]); |
| 168 |
if ( ! empty( $prepared_container['value'] ) && ( '100%' !== $prepared_container['value'] . $prepared_container['valueUnit'] || $device !== '' ) ) { |
| 169 |
$css['max-width'] = "min(100%, {$prepared_container['value']}{$prepared_container['valueUnit']})"; |
| 170 |
} |
| 171 |
return array_merge( |
| 172 |
$css |
| 173 |
); |
| 174 |
} |
| 175 |
|
| 176 |
public function get_icon_spacing_margins( $attributes, $device = '' ) { |
| 177 |
$marginLeft = Range::get_css([ |
| 178 |
'attributeValue' => $attributes['elementIconSpacing'], |
| 179 |
'attributeObjectKey' => 'value', |
| 180 |
'isResponsive' => true, |
| 181 |
'defaultValue' => 0, |
| 182 |
'hasUnit' => true, |
| 183 |
'unitDefaultValue' => 'px', |
| 184 |
'property' => 'margin-left', |
| 185 |
'device' => $device, |
| 186 |
]); |
| 187 |
$marginRight = Range::get_css([ |
| 188 |
'attributeValue' => $attributes['elementIconSpacing'], |
| 189 |
'attributeObjectKey' => 'value', |
| 190 |
'isResponsive' => true, |
| 191 |
'defaultValue' => 0, |
| 192 |
'hasUnit' => true, |
| 193 |
'unitDefaultValue' => 'px', |
| 194 |
'property' => 'margin-right', |
| 195 |
'device' => $device, |
| 196 |
]); |
| 197 |
return [ |
| 198 |
...$marginLeft, |
| 199 |
...$marginRight |
| 200 |
]; |
| 201 |
} |
| 202 |
} |
| 203 |
|