| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 7 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; |
| 8 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Select_Control; |
| 9 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Html_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 16 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 17 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 18 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 19 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control; |
| 20 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 21 |
|
| 22 |
if ( ! defined( 'ABSPATH' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
class Atomic_Paragraph extends Atomic_Widget_Base { |
| 27 |
use Has_Template; |
| 28 |
|
| 29 |
const LINK_BASE_STYLE_KEY = 'link-base'; |
| 30 |
|
| 31 |
public static $widget_description = 'Display a paragraph with customizable tag, styles, and link options.'; |
| 32 |
|
| 33 |
public static function get_element_type(): string { |
| 34 |
return 'e-paragraph'; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_title() { |
| 38 |
return esc_html__( 'Paragraph', 'elementor' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_keywords() { |
| 42 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_icon() { |
| 46 |
return 'eicon-paragraph'; |
| 47 |
} |
| 48 |
|
| 49 |
protected static function define_props_schema(): array { |
| 50 |
return [ |
| 51 |
'classes' => Classes_Prop_Type::make() |
| 52 |
->default( [] ), |
| 53 |
|
| 54 |
'paragraph' => Html_Prop_Type::make() |
| 55 |
->default( __( 'Type your paragraph here', 'elementor' ) ) |
| 56 |
->description( 'The text content of the paragraph.' ), |
| 57 |
|
| 58 |
'tag' => String_Prop_Type::make() |
| 59 |
->enum( [ 'p', 'span' ] ) |
| 60 |
->default( 'p' ), |
| 61 |
|
| 62 |
'link' => Link_Prop_Type::make(), |
| 63 |
|
| 64 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 65 |
]; |
| 66 |
} |
| 67 |
|
| 68 |
protected function define_atomic_controls(): array { |
| 69 |
return [ |
| 70 |
Section::make() |
| 71 |
->set_label( __( 'Content', 'elementor' ) ) |
| 72 |
->set_items( [ |
| 73 |
Inline_Editing_Control::bind_to( 'paragraph' ) |
| 74 |
->set_placeholder( __( 'Type your paragraph here', 'elementor' ) ) |
| 75 |
->set_label( __( 'Paragraph', 'elementor' ) ), |
| 76 |
] ), |
| 77 |
Section::make() |
| 78 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 79 |
->set_id( 'settings' ) |
| 80 |
->set_items( $this->get_settings_controls() ), |
| 81 |
]; |
| 82 |
} |
| 83 |
|
| 84 |
protected function get_settings_controls(): array { |
| 85 |
return [ |
| 86 |
Select_Control::bind_to( 'tag' ) |
| 87 |
->set_options([ |
| 88 |
[ |
| 89 |
'value' => 'p', |
| 90 |
'label' => 'p', |
| 91 |
], |
| 92 |
[ |
| 93 |
'value' => 'span', |
| 94 |
'label' => 'span', |
| 95 |
], |
| 96 |
]) |
| 97 |
->set_label( __( 'Tag', 'elementor' ) ), |
| 98 |
Link_Control::bind_to( 'link' ) |
| 99 |
->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) |
| 100 |
->set_label( __( 'Link', 'elementor' ) ) |
| 101 |
->set_meta( [ |
| 102 |
'topDivider' => true, |
| 103 |
] ), |
| 104 |
Text_Control::bind_to( '_cssid' ) |
| 105 |
->set_label( __( 'ID', 'elementor' ) ) |
| 106 |
->set_meta( $this->get_css_id_control_meta() ), |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
protected function define_base_styles(): array { |
| 111 |
$margin_value = Size_Prop_Type::generate( [ |
| 112 |
'unit' => 'px', |
| 113 |
'size' => 0 , |
| 114 |
] ); |
| 115 |
|
| 116 |
return [ |
| 117 |
'base' => Style_Definition::make() |
| 118 |
->add_variant( |
| 119 |
Style_Variant::make() |
| 120 |
->add_prop( 'margin', $margin_value ) |
| 121 |
), |
| 122 |
self::LINK_BASE_STYLE_KEY => Style_Definition::make() |
| 123 |
->add_variant( |
| 124 |
Style_Variant::make() |
| 125 |
->add_prop( 'all', 'unset' ) |
| 126 |
->add_prop( 'cursor', 'pointer' ) |
| 127 |
), |
| 128 |
]; |
| 129 |
} |
| 130 |
|
| 131 |
protected function get_templates(): array { |
| 132 |
return [ |
| 133 |
'elementor/elements/atomic-paragraph' => __DIR__ . '/atomic-paragraph.html.twig', |
| 134 |
]; |
| 135 |
} |
| 136 |
} |
| 137 |
|