first commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
{% if settings.title is not empty %}
|
||||
{% set id_attribute = settings._cssid is not empty ? 'id=' ~ settings._cssid | e('html_attr') : '' %}
|
||||
<{{ settings.tag | e('html_tag') }}
|
||||
data-interaction-id="{{ id }}"
|
||||
class="{{ settings.classes | merge( [ base_styles.base ] ) | join(' ') }}"
|
||||
{{ id_attribute }}
|
||||
{{ settings.attributes | raw }}
|
||||
{% if interactions and interactions is not empty %}
|
||||
data-interactions="{{ interactions | json_encode | e('html_attr') }}"
|
||||
{% endif %}
|
||||
>
|
||||
{% set allowed_tags = '<b><strong><sup><sub><s><em><i><u><a><del><span><br>' %}
|
||||
|
||||
{% if settings.link.href %}
|
||||
<{{ settings.link.tag | e('html_tag') }}
|
||||
{% set linkAttr = settings.link.tag == 'a' ? 'href' : 'data-action-link' %}
|
||||
{{ linkAttr }}="{{ settings.link.href | raw }}"
|
||||
target="{{ settings.link.target }}"
|
||||
class="{{ base_styles['link-base'] }}">
|
||||
{{ settings.title | striptags(allowed_tags) | raw }}
|
||||
</{{ settings.link.tag | e('html_tag') }}>
|
||||
{% else %}
|
||||
{{ settings.title | striptags(allowed_tags) | raw }}
|
||||
{% endif %}
|
||||
</{{ settings.tag | e('html_tag') }}>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Heading;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Section;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
|
||||
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
|
||||
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Atomic_Heading extends Atomic_Widget_Base {
|
||||
use Has_Template;
|
||||
|
||||
const LINK_BASE_STYLE_KEY = 'link-base';
|
||||
|
||||
public static $widget_description = 'Display a heading with customizable tag, styles, and link options.';
|
||||
|
||||
public static function get_element_type(): string {
|
||||
return 'e-heading';
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return esc_html__( 'Heading', 'elementor' );
|
||||
}
|
||||
|
||||
public function get_keywords() {
|
||||
return [ 'ato', 'atom', 'atoms', 'atomic' ];
|
||||
}
|
||||
|
||||
public function get_icon() {
|
||||
return 'eicon-e-heading';
|
||||
}
|
||||
|
||||
protected static function define_props_schema(): array {
|
||||
return [
|
||||
'classes' => Classes_Prop_Type::make()
|
||||
->default( [] ),
|
||||
|
||||
'tag' => String_Prop_Type::make()
|
||||
->enum( [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] )
|
||||
->default( 'h2' )
|
||||
->description( 'The HTML tag for the heading element. Could be h1, h2, up to h6' ),
|
||||
|
||||
'title' => Html_Prop_Type::make()
|
||||
->default( __( 'This is a title', 'elementor' ) )
|
||||
->description( 'The text content of the heading.' ),
|
||||
|
||||
'link' => Link_Prop_Type::make(),
|
||||
|
||||
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
|
||||
];
|
||||
}
|
||||
|
||||
protected function define_atomic_controls(): array {
|
||||
$content_section = Section::make()
|
||||
->set_label( __( 'Content', 'elementor' ) )
|
||||
->set_items( [
|
||||
Inline_Editing_Control::bind_to( 'title' )
|
||||
->set_placeholder( __( 'Type your title here', 'elementor' ) )
|
||||
->set_label( __( 'Title', 'elementor' ) ),
|
||||
] );
|
||||
|
||||
return [
|
||||
$content_section,
|
||||
Section::make()
|
||||
->set_label( __( 'Settings', 'elementor' ) )
|
||||
->set_id( 'settings' )
|
||||
->set_items( $this->get_settings_controls() ),
|
||||
];
|
||||
}
|
||||
|
||||
protected function get_settings_controls(): array {
|
||||
return [
|
||||
Select_Control::bind_to( 'tag' )
|
||||
->set_options([
|
||||
[
|
||||
'value' => 'h1',
|
||||
'label' => 'H1',
|
||||
],
|
||||
[
|
||||
'value' => 'h2',
|
||||
'label' => 'H2',
|
||||
],
|
||||
[
|
||||
'value' => 'h3',
|
||||
'label' => 'H3',
|
||||
],
|
||||
[
|
||||
'value' => 'h4',
|
||||
'label' => 'H4',
|
||||
],
|
||||
[
|
||||
'value' => 'h5',
|
||||
'label' => 'H5',
|
||||
],
|
||||
[
|
||||
'value' => 'h6',
|
||||
'label' => 'H6',
|
||||
],
|
||||
])
|
||||
->set_label( __( 'Tag', 'elementor' ) ),
|
||||
Link_Control::bind_to( 'link' )
|
||||
->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
|
||||
->set_label( __( 'Link', 'elementor' ) )
|
||||
->set_meta( [
|
||||
'topDivider' => true,
|
||||
] ),
|
||||
Text_Control::bind_to( '_cssid' )
|
||||
->set_label( __( 'ID', 'elementor' ) )
|
||||
->set_meta( $this->get_css_id_control_meta() ),
|
||||
];
|
||||
}
|
||||
|
||||
protected function define_base_styles(): array {
|
||||
$margin_value = Size_Prop_Type::generate( [
|
||||
'unit' => 'px',
|
||||
'size' => 0 ,
|
||||
] );
|
||||
|
||||
return [
|
||||
'base' => Style_Definition::make()
|
||||
->add_variant(
|
||||
Style_Variant::make()
|
||||
->add_prop( 'margin', $margin_value )
|
||||
),
|
||||
self::LINK_BASE_STYLE_KEY => Style_Definition::make()
|
||||
->add_variant(
|
||||
Style_Variant::make()
|
||||
->add_prop( 'all', 'unset' )
|
||||
->add_prop( 'cursor', 'pointer' )
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
protected function get_templates(): array {
|
||||
return [
|
||||
'elementor/elements/atomic-heading' => __DIR__ . '/atomic-heading.html.twig',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user