| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Heading; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 5 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; |
| 7 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Textarea_Control; |
| 8 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base; |
| 9 |
use Elementor\Modules\AtomicWidgets\Elements\Has_Template; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Key_Value_Array_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 16 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 17 |
|
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; // Exit if accessed directly. |
| 20 |
} |
| 21 |
|
| 22 |
class Atomic_Heading extends Atomic_Widget_Base { |
| 23 |
use Has_Template; |
| 24 |
|
| 25 |
const LINK_BASE_STYLE_KEY = 'link-base'; |
| 26 |
|
| 27 |
public static function get_element_type(): string { |
| 28 |
return 'e-heading'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_title() { |
| 32 |
return esc_html__( 'Heading', 'elementor' ); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_keywords() { |
| 36 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_icon() { |
| 40 |
return 'eicon-e-heading'; |
| 41 |
} |
| 42 |
|
| 43 |
protected static function define_props_schema(): array { |
| 44 |
$props = [ |
| 45 |
'classes' => Classes_Prop_Type::make() |
| 46 |
->default( [] ), |
| 47 |
|
| 48 |
'tag' => String_Prop_Type::make() |
| 49 |
->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] ) |
| 50 |
->default( 'h2' ), |
| 51 |
|
| 52 |
'title' => String_Prop_Type::make() |
| 53 |
->default( __( 'This is a title', 'elementor' ) ), |
| 54 |
|
| 55 |
'link' => Link_Prop_Type::make(), |
| 56 |
|
| 57 |
'attributes' => Key_Value_Array_Prop_Type::make(), |
| 58 |
]; |
| 59 |
|
| 60 |
return $props; |
| 61 |
} |
| 62 |
|
| 63 |
protected function define_atomic_controls(): array { |
| 64 |
$content_section = Section::make() |
| 65 |
->set_label( __( 'Content', 'elementor' ) ) |
| 66 |
->set_items( [ |
| 67 |
Textarea_Control::bind_to( 'title' ) |
| 68 |
->set_label( __( 'Title', 'elementor' ) ) |
| 69 |
->set_placeholder( __( 'Type your title here', 'elementor' ) ), |
| 70 |
] ); |
| 71 |
|
| 72 |
return [ |
| 73 |
$content_section, |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
protected function get_settings_controls(): array { |
| 78 |
return [ |
| 79 |
Select_Control::bind_to( 'tag' ) |
| 80 |
->set_label( esc_html__( 'Tag', 'elementor' ) ) |
| 81 |
->set_options([ |
| 82 |
[ |
| 83 |
'value' => 'h1', |
| 84 |
'label' => 'H1', |
| 85 |
], |
| 86 |
[ |
| 87 |
'value' => 'h2', |
| 88 |
'label' => 'H2', |
| 89 |
], |
| 90 |
[ |
| 91 |
'value' => 'h3', |
| 92 |
'label' => 'H3', |
| 93 |
], |
| 94 |
[ |
| 95 |
'value' => 'h4', |
| 96 |
'label' => 'H4', |
| 97 |
], |
| 98 |
[ |
| 99 |
'value' => 'h5', |
| 100 |
'label' => 'H5', |
| 101 |
], |
| 102 |
[ |
| 103 |
'value' => 'h6', |
| 104 |
'label' => 'H6', |
| 105 |
], |
| 106 |
]), |
| 107 |
Link_Control::bind_to( 'link' ) |
| 108 |
->set_label( __( 'Link', 'elementor' ) ) |
| 109 |
->set_meta( [ |
| 110 |
'topDivider' => true, |
| 111 |
] ), |
| 112 |
]; |
| 113 |
} |
| 114 |
|
| 115 |
protected function define_base_styles(): array { |
| 116 |
$margin_value = Size_Prop_Type::generate( [ |
| 117 |
'unit' => 'px', |
| 118 |
'size' => 0 , |
| 119 |
] ); |
| 120 |
|
| 121 |
return [ |
| 122 |
'base' => Style_Definition::make() |
| 123 |
->add_variant( |
| 124 |
Style_Variant::make() |
| 125 |
->add_prop( 'margin', $margin_value ) |
| 126 |
), |
| 127 |
self::LINK_BASE_STYLE_KEY => Style_Definition::make() |
| 128 |
->add_variant( |
| 129 |
Style_Variant::make() |
| 130 |
->add_prop( 'all', 'unset' ) |
| 131 |
->add_prop( 'cursor', 'pointer' ) |
| 132 |
), |
| 133 |
]; |
| 134 |
} |
| 135 |
|
| 136 |
protected function get_templates(): array { |
| 137 |
return [ |
| 138 |
'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig', |
| 139 |
]; |
| 140 |
} |
| 141 |
} |
| 142 |
|