PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev1
Elementor Website Builder – more than just a page builder v3.35.0-dev1
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / atomic-widgets / elements / atomic-heading / atomic-heading.php

atomic-heading.php in Elementor Website Builder – more than just a page builder 3.35.0-dev1, at modules/atomic-widgets/elements/atomic-heading/atomic-heading.php

170 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Controls\Types\Inline_Editing_Control;
9 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
10 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template;
11 use Elementor\Modules\AtomicWidgets\Module as Atomic_Widgets_Module;
12 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
13 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
14 use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
17 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
18 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
19 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
20 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
21 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
22 use Elementor\Plugin;
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit; // Exit if accessed directly.
26 }
27
28 class Atomic_Heading extends Atomic_Widget_Base {
29 use Has_Template;
30
31 const LINK_BASE_STYLE_KEY = 'link-base';
32
33 public static $widget_description = 'Display a heading with customizable tag, styles, and link options.';
34
35 public static function get_element_type(): string {
36 return 'e-heading';
37 }
38
39 public function get_title() {
40 return esc_html__( 'Heading', 'elementor' );
41 }
42
43 public function get_keywords() {
44 return [ 'ato', 'atom', 'atoms', 'atomic' ];
45 }
46
47 public function get_icon() {
48 return 'eicon-e-heading';
49 }
50
51 protected static function define_props_schema(): array {
52 $is_feature_active = Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_INLINE_EDITING );
53
54 $title_prop = $is_feature_active
55 ? Html_Prop_Type::make()->default( __( 'This is a title', 'elementor' ) )
56 : String_Prop_Type::make()->default( __( 'This is a title', 'elementor' ) );
57
58 $props = [
59 'classes' => Classes_Prop_Type::make()
60 ->default( [] ),
61
62 'tag' => String_Prop_Type::make()
63 ->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] )
64 ->default( 'h2' )
65 ->description( 'The HTML tag for the heading element. Could be h1, h2, up to h6' ),
66
67 'title' => $title_prop
68 ->description( 'The text content of the heading.' ),
69
70 'link' => Link_Prop_Type::make(),
71
72 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
73 ];
74
75 return $props;
76 }
77
78 protected function define_atomic_controls(): array {
79 $is_feature_active = Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_INLINE_EDITING );
80
81 $control = $is_feature_active
82 ? Inline_Editing_Control::bind_to( 'title' )
83 ->set_placeholder( __( 'Type your title here', 'elementor' ) )
84 ->set_label( __( 'Title', 'elementor' ) )
85 : Textarea_Control::bind_to( 'title' )
86 ->set_placeholder( __( 'Type your title here', 'elementor' ) )
87 ->set_label( __( 'Title', 'elementor' ) );
88
89 $content_section = Section::make()
90 ->set_label( __( 'Content', 'elementor' ) )
91 ->set_items( [ $control ] );
92 return [
93 $content_section,
94 Section::make()
95 ->set_label( __( 'Settings', 'elementor' ) )
96 ->set_id( 'settings' )
97 ->set_items( $this->get_settings_controls() ),
98 ];
99 }
100
101 protected function get_settings_controls(): array {
102 return [
103 Select_Control::bind_to( 'tag' )
104 ->set_options([
105 [
106 'value' => 'h1',
107 'label' => 'H1',
108 ],
109 [
110 'value' => 'h2',
111 'label' => 'H2',
112 ],
113 [
114 'value' => 'h3',
115 'label' => 'H3',
116 ],
117 [
118 'value' => 'h4',
119 'label' => 'H4',
120 ],
121 [
122 'value' => 'h5',
123 'label' => 'H5',
124 ],
125 [
126 'value' => 'h6',
127 'label' => 'H6',
128 ],
129 ])
130 ->set_label( __( 'Tag', 'elementor' ) ),
131 Link_Control::bind_to( 'link' )
132 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
133 ->set_label( __( 'Link', 'elementor' ) )
134 ->set_meta( [
135 'topDivider' => true,
136 ] ),
137 Text_Control::bind_to( '_cssid' )
138 ->set_label( __( 'ID', 'elementor' ) )
139 ->set_meta( $this->get_css_id_control_meta() ),
140 ];
141 }
142
143 protected function define_base_styles(): array {
144 $margin_value = Size_Prop_Type::generate( [
145 'unit' => 'px',
146 'size' => 0 ,
147 ] );
148
149 return [
150 'base' => Style_Definition::make()
151 ->add_variant(
152 Style_Variant::make()
153 ->add_prop( 'margin', $margin_value )
154 ),
155 self::LINK_BASE_STYLE_KEY => Style_Definition::make()
156 ->add_variant(
157 Style_Variant::make()
158 ->add_prop( 'all', 'unset' )
159 ->add_prop( 'cursor', 'pointer' )
160 ),
161 ];
162 }
163
164 protected function get_templates(): array {
165 return [
166 'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig',
167 ];
168 }
169 }
170