| @@ -4,11 +4,15 @@ | ||
| 4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | 5 | exit; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | -use ABlocks\Classes\ControlBaseAbstract; | |
| 8 | + | |
| 9 | 9 | use ABlocks\Controls\Dimensions; |
| 10 | 10 | use ABlocks\Controls\Range; |
| 11 | +use ABlocks\Helper; | |
| 12 | +use ABlocks\Controls\Color; | |
| 13 | +use ABlocks\Controls\Border; | |
| 14 | +use ABlocks\Controls\BoxShadow; | |
| 11 | 15 | |
| 12 | 16 | class Icon { |
| 13 | 17 | public static function get_attribute_default_value( $is_responsive = false ) { |
| 14 | 18 | return []; |
| @@ -22,8 +26,9 @@ | ||
| 22 | 26 | 'hasNoSelectorOrSource' => false, |
| 23 | 27 | 'size' => 55, |
| 24 | 28 | 'color' => '#69727d', |
| 25 | 29 | 'BgColor' => '', |
| 30 | + 'hoverColor' => '', | |
| 26 | 31 | 'iconType' => 'default', |
| 27 | 32 | 'iconShape' => 'circle', |
| 28 | 33 | ]); |
| 29 | 34 | |
| @@ -66,8 +71,16 @@ | ||
| 66 | 71 | $attribute_prefix . 'BgColor' => [ |
| 67 | 72 | 'type' => 'string', |
| 68 | 73 | 'default' => $default_args['BgColor'], |
| 69 | 74 | ], |
| 75 | + $attribute_prefix . 'HoverColor' => [ | |
| 76 | + 'type' => 'string', | |
| 77 | + 'default' => $default_args['hoverColor'], | |
| 78 | + ], | |
| 79 | + $attribute_prefix . 'HoverBgColor' => [ | |
| 80 | + 'type' => 'string', | |
| 81 | + 'default' => $default_args['BgColor'], | |
| 82 | + ], | |
| 70 | 83 | $attribute_prefix . 'Type' => [ |
| 71 | 84 | 'type' => 'string', |
| 72 | 85 | 'default' => $default_args['iconType'], |
| 73 | 86 | ], |
| @@ -90,10 +103,10 @@ | ||
| 90 | 103 | |
| 91 | 104 | $attribute = array_merge( |
| 92 | 105 | $attribute, |
| 93 | 106 | Dimensions::get_attribute( $attribute_prefix . 'Padding', false ), |
| 94 | - Dimensions::get_attribute( $attribute_prefix . 'BorderRadius', false ), | |
| 95 | - Dimensions::get_attribute( $attribute_prefix . 'BorderWidth', false ), | |
| 107 | + Border::get_attribute( $attribute_prefix . 'Border', false ), | |
| 108 | + BoxShadow::get_attribute( $attribute_prefix . 'BoxShadow', true ), | |
| 96 | 109 | Range::get_attribute([ |
| 97 | 110 | 'attributeName' => $attribute_prefix . 'Size', |
| 98 | 111 | 'isResponsive' => false, |
| 99 | 112 | 'defaultValue' => $default_args['size'], |
| @@ -151,10 +164,10 @@ | ||
| 151 | 164 | |
| 152 | 165 | public static function get_wrapper_css( $attributes, $device = '', $attributePrefix = 'icon' ) { |
| 153 | 166 | $iconType = $attributes[ $attributePrefix . 'Type' ]; |
| 154 | 167 | $iconShape = $attributes[ $attributePrefix . 'Shape' ]; |
| 155 | - $backgroundColor = $attributes[ $attributePrefix . 'BgColor' ]; | |
| 156 | - $primaryColor = $attributes[ $attributePrefix . 'Color' ]; | |
| 168 | + $backgroundColor = Color::get_css( $attributes[ $attributePrefix . 'BgColor' ] ); | |
| 169 | + $primaryColor = Color::get_css( $attributes[ $attributePrefix . 'Color' ] ); | |
| 157 | 170 | $iconViewCSS = []; |
| 158 | 171 | |
| 159 | 172 | if ( $iconType !== 'default' ) { |
| 160 | 173 | if ( $iconType === 'stacked' ) { |
| @@ -175,15 +188,15 @@ | ||
| 175 | 188 | $iconViewCSS = [ |
| 176 | 189 | 'background' => $backgroundColor ? $backgroundColor : 'transparent', |
| 177 | 190 | 'padding' => '.5em', |
| 178 | 191 | 'border-radius' => '50%', |
| 179 | - 'border' => '2px solid ' . ( $primaryColor ? $primaryColor : '#69727d' ), | |
| 192 | + 'border' => '2px solid ' . ( Color::get_css( $primaryColor ? $primaryColor : '#69727d' ) ), | |
| 180 | 193 | ]; |
| 181 | 194 | } elseif ( $iconShape === 'square' ) { |
| 182 | 195 | $iconViewCSS = [ |
| 183 | 196 | 'background' => $backgroundColor ? $backgroundColor : 'transparent', |
| 184 | 197 | 'padding' => '.5em', |
| 185 | - 'border' => '2px solid ' . ( $primaryColor ? $primaryColor : '#69727d' ), | |
| 198 | + 'border' => '2px solid ' . ( Color::get_css( $primaryColor ? $primaryColor : '#69727d' ) ), | |
| 186 | 199 | ]; |
| 187 | 200 | } |
| 188 | 201 | }//end if |
| 189 | 202 | }//end if |
| @@ -189,13 +202,15 @@ | ||
| 189 | 202 | }//end if |
| 190 | 203 | |
| 191 | 204 | if ( ! empty( $attributes[ $attributePrefix . 'Sizing' ] ) && empty( $attributes[ $attributePrefix . 'ImageUrl' ] ) ) { |
| 192 | 205 | $sizeValue = isset( $attributes[ $attributePrefix . 'Sizing' ][ 'value' . $device ] ) ? $attributes[ $attributePrefix . 'Sizing' ][ 'value' . $device ] : $attributes[ $attributePrefix . 'Sizing' ]['value']; |
| 193 | - $sizeUnit = isset( $attributes[ $attributePrefix . 'Sizing' ][ 'valueUnit' . $device ] ) ? $attributes[ $attributePrefix . 'Sizing' ][ 'valueUnit' . $device ] : ( isset( $attributes[ $attributePrefix . 'Sizing' ]['valueUnit'] ) ? $attributes[ $attributePrefix . 'Sizing' ]['valueUnit'] : '' ); | |
| 194 | 206 | |
| 195 | - if ( empty( $sizeUnit ) ) { | |
| 196 | - $sizeUnit = 'px'; | |
| 197 | - } | |
| 207 | + $sizeUnit = self::get_unit( [ | |
| 208 | + 'attributeValue' => $attributes[ $attributePrefix . 'Sizing' ], | |
| 209 | + 'attributeObjectKey' => 'value', | |
| 210 | + 'unitDefaultValue' => 'px', | |
| 211 | + 'device' => $device, | |
| 212 | + ] ); | |
| 198 | 213 | |
| 199 | 214 | $iconViewCSS['font-size'] = $sizeValue . $sizeUnit; |
| 200 | 215 | } |
| 201 | 216 | // Remove font size for fixing |
| @@ -207,18 +222,33 @@ | ||
| 207 | 222 | [ 'background' => $backgroundColor ], |
| 208 | 223 | $iconViewCSS, |
| 209 | 224 | 'default' !== $iconType ? array_merge( |
| 210 | 225 | Dimensions::get_css( $attributes[ $attributePrefix . 'Padding' ], 'padding', $device ), |
| 211 | - Dimensions::get_css( $attributes[ $attributePrefix . 'BorderRadius' ], 'border-radius', $device ), | |
| 212 | - Dimensions::get_css( $attributes[ $attributePrefix . 'BorderWidth' ], 'border-width', $device ) | |
| 226 | + Border::get_css( $attributes[ $attributePrefix . 'Border' ], 'border', $device ), | |
| 227 | + BoxShadow::get_css( $attributes[ $attributePrefix . 'BoxShadow' ], '', $device ) | |
| 213 | 228 | ) : [] |
| 214 | 229 | ); |
| 215 | 230 | } |
| 216 | 231 | |
| 232 | + public static function get_wrapper_hover_css( $attributes, $device = '', $attributePrefix = 'icon' ) { | |
| 233 | + $primaryHoverColor = Color::get_css( $attributes[ $attributePrefix . 'HoverBgColor' ] ?? '' ); | |
| 234 | + $iconViewHoverCSS = []; | |
| 235 | + | |
| 236 | + if ( $primaryHoverColor ) { | |
| 237 | + $iconViewHoverCSS['background'] = $primaryHoverColor; | |
| 238 | + } | |
| 239 | + | |
| 240 | + return array_merge( | |
| 241 | + Border::get_hover_css( $attributes[ $attributePrefix . 'Border' ], 'border', $device ), | |
| 242 | + BoxShadow::get_hover_css( $attributes[ $attributePrefix . 'BoxShadow' ], '', $device ), | |
| 243 | + $iconViewHoverCSS | |
| 244 | + ); | |
| 245 | + } | |
| 246 | + | |
| 217 | 247 | public static function get_element_css( $attributes, $device = '', $attributePrefix = 'icon' ) { |
| 218 | 248 | $iconType = $attributes[ $attributePrefix . 'Type' ] ?? 'default'; |
| 219 | 249 | $iconShape = $attributes[ $attributePrefix . 'Shape' ] ?? ''; |
| 220 | - $primaryColor = $attributes[ $attributePrefix . 'Color' ] ?? '#69727d'; | |
| 250 | + $primaryColor = Color::get_css( $attributes[ $attributePrefix . 'Color' ] ?? '#69727d' ); | |
| 221 | 251 | $rotate = ! empty( $attributes[ $attributePrefix . 'Rotated' ][ 'value' . $device ] ) ?? 0; |
| 222 | 252 | $iconViewCSS = []; |
| 223 | 253 | |
| 224 | 254 | if ( ! empty( $attributes[ $attributePrefix . 'Rotated' ][ 'value' . $device ] ) ) { |
| @@ -278,8 +308,9 @@ | ||
| 278 | 308 | |
| 279 | 309 | public static function get_element_image_hover_css( $attributes, $device = '', $attributePrefix = 'icon' ) { |
| 280 | 310 | $rotateHover = $attributes[ $attributePrefix . 'RotateHover' ][ 'value' . $device ] ?? 0; |
| 281 | 311 | $transitionHover = $attributes[ $attributePrefix . 'transitionDuration' ] ?? 0; |
| 312 | + $HoverColor = Color::get_css( $attributes[ $attributePrefix . 'HoverColor' ] ?? '' ); | |
| 282 | 313 | $iconViewCSS = []; |
| 283 | 314 | if ( isset( $attributes[ $attributePrefix . 'RotateHover' ][ 'value' . $device ] ) ) { |
| 284 | 315 | $rotateHover = $attributes[ $attributePrefix . 'RotateHover' ][ 'value' . $device ]; |
| 285 | 316 | } |
| @@ -289,9 +320,40 @@ | ||
| 289 | 320 | if ( $transitionHover ) { |
| 290 | 321 | $iconViewCSS['transition'] = $transitionHover . 's'; |
| 291 | 322 | } |
| 292 | 323 | |
| 324 | + if ( $HoverColor ) { | |
| 325 | + $iconViewCSS['fill'] = $HoverColor; | |
| 326 | + } | |
| 293 | 327 | return array_merge( |
| 294 | 328 | $iconViewCSS |
| 295 | 329 | ); |
| 330 | + } | |
| 331 | + | |
| 332 | + // copy from control-base-abstract-two.php | |
| 333 | + public static function get_unit( $args ) { | |
| 334 | + $defaultUnit = $args['unitDefaultValue']; | |
| 335 | + $value = $args['attributeValue']; | |
| 336 | + $device = $args['device']; | |
| 337 | + $keyPrefix = $args['attributeObjectKey'] . 'Unit'; | |
| 338 | + | |
| 339 | + // Retrieve units with fallback to default | |
| 340 | + $unitDesktop = Helper::get_array_value( $value, $keyPrefix, $defaultUnit ); // Desktop | |
| 341 | + $unitTablet = Helper::get_array_value( $value, $keyPrefix . 'Tablet', $unitDesktop ); // Tablet inherits from Desktop | |
| 342 | + $unitMobile = Helper::get_array_value( $value, $keyPrefix . 'Mobile', $unitTablet ); // Mobile inherits from Tablet | |
| 343 | + | |
| 344 | + // Return the appropriate unit based on the device | |
| 345 | + if ( '' === $device ) { | |
| 346 | + return $unitDesktop; // Desktop | |
| 347 | + } | |
| 348 | + | |
| 349 | + if ( 'Tablet' === $device ) { | |
| 350 | + return $unitTablet; // Tablet | |
| 351 | + } | |
| 352 | + | |
| 353 | + if ( 'Mobile' === $device ) { | |
| 354 | + return $unitMobile; // Mobile | |
| 355 | + } | |
| 356 | + | |
| 357 | + return $defaultUnit; // Default fallback | |
| 296 | 358 | } |
| 297 | 359 | } |