| @@ -1,0 +1,172 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\Notice; | |
| 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\Typography; | |
| 12 | +use ABlocks\Controls\TextShadow; | |
| 13 | +use ABlocks\Controls\TextStroke; | |
| 14 | +use ABlocks\Controls\Dimensions; | |
| 15 | +use ABlocks\Controls\Icon; | |
| 16 | +use ABlocks\Classes\CssGeneratorV2; | |
| 17 | +use ABlocks\Controls\Color; | |
| 18 | + | |
| 19 | +class Block extends BlockBaseAbstract { | |
| 20 | + protected $block_name = 'notice'; | |
| 21 | + | |
| 22 | + public function build_css_v1( $attributes ) { | |
| 23 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 24 | + $css_generator->add_class_styles( | |
| 25 | + '{{WRAPPER}} .ablocks-notice-header', | |
| 26 | + $this->get_notice_header_css( $attributes ), | |
| 27 | + $this->get_notice_header_css( $attributes, 'Tablet' ), | |
| 28 | + $this->get_notice_header_css( $attributes, 'Mobile' ), | |
| 29 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_notice_header_css( $attributes, $device ); } ) | |
| 30 | + ); | |
| 31 | + $css_generator->add_class_styles( | |
| 32 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-notice-title', | |
| 33 | + $this->get_notice_header_title_css( $attributes ), | |
| 34 | + $this->get_notice_header_title_css( $attributes, 'Tablet' ), | |
| 35 | + $this->get_notice_header_title_css( $attributes, 'Mobile' ), | |
| 36 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_notice_header_title_css( $attributes, $device ); } ) | |
| 37 | + ); | |
| 38 | + | |
| 39 | + // Icon CSS | |
| 40 | + $css_generator->add_class_styles( | |
| 41 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap', | |
| 42 | + Icon::get_wrapper_css( $attributes ), | |
| 43 | + Icon::get_wrapper_css( $attributes, 'Tablet' ), | |
| 44 | + Icon::get_wrapper_css( $attributes, 'Mobile' ), | |
| 45 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } ) | |
| 46 | + ); | |
| 47 | + $css_generator->add_class_styles( | |
| 48 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap:hover', | |
| 49 | + Icon::get_wrapper_hover_css( $attributes ), | |
| 50 | + Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), | |
| 51 | + Icon::get_wrapper_hover_css( $attributes, 'Mobile' ), | |
| 52 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } ) | |
| 53 | + ); | |
| 54 | + | |
| 55 | + $css_generator->add_class_styles( | |
| 56 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap img.ablocks-image-icon', | |
| 57 | + Icon::get_element_image_css( $attributes ), | |
| 58 | + Icon::get_element_image_css( $attributes, 'Tablet' ), | |
| 59 | + Icon::get_element_image_css( $attributes, 'Mobile' ), | |
| 60 | + ); | |
| 61 | + $css_generator->add_class_styles( | |
| 62 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap img.ablocks-image-icon:hover', | |
| 63 | + Icon::get_element_image_hover_css( $attributes ), | |
| 64 | + Icon::get_element_image_hover_css( $attributes, 'Tablet' ), | |
| 65 | + Icon::get_element_image_hover_css( $attributes, 'Mobile' ), | |
| 66 | + ); | |
| 67 | + $css_generator->add_class_styles( | |
| 68 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap svg.ablocks-svg-icon', | |
| 69 | + Icon::get_element_css( $attributes ), | |
| 70 | + Icon::get_element_css( $attributes, 'Tablet' ), | |
| 71 | + Icon::get_element_css( $attributes, 'Mobile' ), | |
| 72 | + ); | |
| 73 | + $css_generator->add_class_styles( | |
| 74 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap svg.ablocks-svg-icon:hover', | |
| 75 | + Icon::get_element_image_hover_css( $attributes ), | |
| 76 | + Icon::get_element_image_hover_css( $attributes, 'Tablet' ), | |
| 77 | + Icon::get_element_image_hover_css( $attributes, 'Mobile' ), | |
| 78 | + ); | |
| 79 | + | |
| 80 | + return $css_generator->generate_css(); | |
| 81 | + } | |
| 82 | + public function build_css_v2( $attributes ) { | |
| 83 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 84 | + | |
| 85 | + $css_generator->add_class_styles( | |
| 86 | + '{{WRAPPER}} .ablocks-notice-header', | |
| 87 | + $this->get_notice_header_css( $attributes ), | |
| 88 | + $this->get_notice_header_css( $attributes, 'Tablet' ), | |
| 89 | + $this->get_notice_header_css( $attributes, 'Mobile' ), | |
| 90 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_notice_header_css( $attributes, $device ); } ) | |
| 91 | + ); | |
| 92 | + $css_generator->add_class_styles( | |
| 93 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-notice-title', | |
| 94 | + $this->get_notice_header_title_css( $attributes ), | |
| 95 | + $this->get_notice_header_title_css( $attributes, 'Tablet' ), | |
| 96 | + $this->get_notice_header_title_css( $attributes, 'Mobile' ), | |
| 97 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_notice_header_title_css( $attributes, $device ); } ) | |
| 98 | + ); | |
| 99 | + | |
| 100 | + // Icon CSS | |
| 101 | + $css_generator->add_class_styles( | |
| 102 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap', | |
| 103 | + Icon::get_wrapper_css( $attributes ), | |
| 104 | + Icon::get_wrapper_css( $attributes, 'Tablet' ), | |
| 105 | + Icon::get_wrapper_css( $attributes, 'Mobile' ), | |
| 106 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } ) | |
| 107 | + ); | |
| 108 | + $css_generator->add_class_styles( | |
| 109 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap:hover', | |
| 110 | + Icon::get_wrapper_hover_css( $attributes ), | |
| 111 | + Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), | |
| 112 | + Icon::get_wrapper_hover_css( $attributes, 'Mobile' ), | |
| 113 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } ) | |
| 114 | + ); | |
| 115 | + | |
| 116 | + $css_generator->add_class_styles( | |
| 117 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap img.ablocks-image-icon', | |
| 118 | + Icon::get_element_image_css( $attributes ), | |
| 119 | + Icon::get_element_image_css( $attributes, 'Tablet' ), | |
| 120 | + Icon::get_element_image_css( $attributes, 'Mobile' ), | |
| 121 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } ) | |
| 122 | + ); | |
| 123 | + $css_generator->add_class_styles( | |
| 124 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap img.ablocks-image-icon:hover', | |
| 125 | + Icon::get_element_image_hover_css( $attributes ), | |
| 126 | + Icon::get_element_image_hover_css( $attributes, 'Tablet' ), | |
| 127 | + Icon::get_element_image_hover_css( $attributes, 'Mobile' ), | |
| 128 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } ) | |
| 129 | + ); | |
| 130 | + $css_generator->add_class_styles( | |
| 131 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap svg.ablocks-svg-icon', | |
| 132 | + Icon::get_element_css( $attributes ), | |
| 133 | + Icon::get_element_css( $attributes, 'Tablet' ), | |
| 134 | + Icon::get_element_css( $attributes, 'Mobile' ), | |
| 135 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } ) | |
| 136 | + ); | |
| 137 | + $css_generator->add_class_styles( | |
| 138 | + '{{WRAPPER}} .ablocks-notice-header .ablocks-icon-wrap svg.ablocks-svg-icon:hover', | |
| 139 | + Icon::get_element_image_hover_css( $attributes ), | |
| 140 | + Icon::get_element_image_hover_css( $attributes, 'Tablet' ), | |
| 141 | + Icon::get_element_image_hover_css( $attributes, 'Mobile' ), | |
| 142 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } ) | |
| 143 | + ); | |
| 144 | + | |
| 145 | + return $css_generator->generate_css(); | |
| 146 | + } | |
| 147 | + | |
| 148 | + public function build_css( $attributes ) { | |
| 149 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 150 | + return $this->build_css_v2( $attributes ); | |
| 151 | + } | |
| 152 | + return $this->build_css_v1( $attributes ); | |
| 153 | + } | |
| 154 | + public function get_notice_header_css( $attributes, $device = '' ) { | |
| 155 | + return array_merge( | |
| 156 | + [ 'background' => Color::get_css( isset( $attributes['backgroundColor'] ) ? $attributes['backgroundColor'] : '' ) ], | |
| 157 | + Dimensions::get_css( $attributes['noticeHeaderPadding'], 'padding', $device ) | |
| 158 | + ); | |
| 159 | + } | |
| 160 | + | |
| 161 | + public function get_notice_header_title_css( $attributes, $device = '' ) { | |
| 162 | + $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array(); | |
| 163 | + return array_merge( | |
| 164 | + [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ], | |
| 165 | + Alignment::get_css( $attributes['alignment'], 'justify-content', $device ), | |
| 166 | + Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ), | |
| 167 | + TextShadow::get_css( $attributes['textShadow'], '', $device ), | |
| 168 | + TextStroke::get_css( $attributes['textStroke'], '', $device ), | |
| 169 | + ); | |
| 170 | + } | |
| 171 | + | |
| 172 | +} | |