| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use Elementor\{ |
| 10 |
Controls_Manager, |
| 11 |
Widget_Base |
| 12 |
}; |
| 13 |
|
| 14 |
class Ehp_Padding { |
| 15 |
private $context = []; |
| 16 |
private ?Widget_Base $widget = null; |
| 17 |
|
| 18 |
public function set_context( array $context ) { |
| 19 |
$this->context = $context; |
| 20 |
} |
| 21 |
|
| 22 |
public function render_selectors() { |
| 23 |
$widget_name = $this->context['widget_name']; |
| 24 |
$container_prefix = $this->context['container_prefix'] ?? ''; |
| 25 |
$type_prefix = $this->context['type_prefix'] ?? ''; |
| 26 |
|
| 27 |
$prefix = implode( '-', array_filter( [ |
| 28 |
$widget_name, |
| 29 |
$container_prefix, |
| 30 |
$type_prefix, |
| 31 |
] ) ); |
| 32 |
|
| 33 |
$is_rtl = is_rtl(); |
| 34 |
$inline_end_value = $is_rtl ? 'LEFT' : 'RIGHT'; |
| 35 |
$inline_start_value = $is_rtl ? 'RIGHT' : 'LEFT'; |
| 36 |
|
| 37 |
$properties = [ |
| 38 |
'padding-block-end' => '{{BOTTOM}}{{UNIT}}', |
| 39 |
'padding-block-start' => '{{TOP}}{{UNIT}}', |
| 40 |
'padding-inline-end' => "{{{$inline_end_value}}}{{UNIT}}", |
| 41 |
'padding-inline-start' => "{{{$inline_start_value}}}{{UNIT}}", |
| 42 |
]; |
| 43 |
|
| 44 |
$css_rules = array_map( fn( $value, $prop ) => "--{$prefix}-{$prop}: {$value};", $properties, array_keys( $properties ) ); |
| 45 |
|
| 46 |
return implode( ' ', $css_rules ); |
| 47 |
} |
| 48 |
|
| 49 |
public function add_style_controls() { |
| 50 |
$widget_name = $this->context['widget_name']; |
| 51 |
$condition = $this->context['condition'] ?? []; |
| 52 |
|
| 53 |
$container_prefix = $this->context['container_prefix'] ?? ''; |
| 54 |
$type_prefix = $this->context['type_prefix'] ?? ''; |
| 55 |
$padding_prefix = implode( '_', array_filter( [ $type_prefix, $container_prefix, 'padding' ] ) ); |
| 56 |
|
| 57 |
$this->widget->add_responsive_control( |
| 58 |
$padding_prefix, |
| 59 |
[ |
| 60 |
'label' => esc_html__( 'Padding', 'hello-plus' ), |
| 61 |
'type' => Controls_Manager::DIMENSIONS, |
| 62 |
'size_units' => [ 'px', '%', 'em', 'rem' ], |
| 63 |
'selectors' => [ |
| 64 |
'{{WRAPPER}} .ehp-' . $widget_name => $this->render_selectors(), |
| 65 |
], |
| 66 |
'default' => $this->context['default_padding'] ?? [ |
| 67 |
'top' => '60', |
| 68 |
'right' => '60', |
| 69 |
'bottom' => '60', |
| 70 |
'left' => '60', |
| 71 |
'unit' => 'px', |
| 72 |
], |
| 73 |
'tablet_default' => $this->context['tablet_default_padding'] ?? [], |
| 74 |
'mobile_default' => $this->context['mobile_default_padding'] ?? [], |
| 75 |
'separator' => $this->context['separator'] ?? 'before', |
| 76 |
'condition' => $condition, |
| 77 |
] |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
public function __construct( Widget_Base $widget, $context = [] ) { |
| 82 |
$this->widget = $widget; |
| 83 |
$this->context = $context; |
| 84 |
} |
| 85 |
} |
| 86 |
|