PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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-button / atomic-button.php

atomic-button.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/atomic-widgets/elements/atomic-button/atomic-button.php

170 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Button;
4
5 use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control;
6 use Elementor\Modules\AtomicWidgets\Controls\Types\Inline_Editing_Control;
7 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
8 use Elementor\Modules\AtomicWidgets\Controls\Section;
9 use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control;
10 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template;
11 use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
12 use Elementor\Modules\AtomicWidgets\PropTypes\Background_Prop_Type;
13 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
14 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Escaped_Html_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type;
17 use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type;
18 use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type;
19 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
20 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
21 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
22 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
23 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit;
27 }
28
29 class Atomic_Button extends Atomic_Widget_Base {
30 use Has_Template;
31
32 public static function get_element_type(): string {
33 return 'e-button';
34 }
35
36 public function get_title() {
37 return esc_html__( 'Button', 'elementor' );
38 }
39
40 public function get_keywords() {
41 return [ 'ato', 'atom', 'atoms', 'atomic', 'button', 'cta', 'link', 'click' ];
42 }
43
44 public function get_icon() {
45 return 'eicon-e-button';
46 }
47
48 public static function get_computed_html_tag( array $settings ): string {
49 return Html_Tag_Computer::compute( $settings, 'button' );
50 }
51
52 protected static function define_props_schema(): array {
53 $props = [
54 'classes' => Classes_Prop_Type::make()
55 ->default( [] ),
56
57 'text' => Escaped_Html_Prop_Type::make()
58 ->default( __( 'Click here', 'elementor' ) )
59 ->description( 'The text displayed on the button.' )
60 ->alias( 'content', 'label' ),
61
62 'link' => Link_Prop_Type::make(),
63
64 'tag' => String_Prop_Type::make()
65 ->default( 'button' )
66 ->description( 'The HTML tag for the button element.' ),
67
68 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ),
69 ];
70
71 return $props;
72 }
73
74 protected function define_atomic_controls(): array {
75 return [
76 Section::make()
77 ->set_label( __( 'Content', 'elementor' ) )
78 ->set_id( 'content' )
79 ->set_items( [
80 Inline_Editing_Control::bind_to( 'text' )
81 ->set_placeholder( __( 'Type your button text here', 'elementor' ) )
82 ->set_label( __( 'Button text', 'elementor' ) ),
83 ] ),
84 Section::make()
85 ->set_label( __( 'Settings', 'elementor' ) )
86 ->set_id( 'settings' )
87 ->set_items( $this->get_settings_controls() ),
88 ];
89 }
90
91 protected function get_settings_controls(): array {
92 return [
93 Link_Control::bind_to( 'link' )
94 ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) )
95 ->set_label( __( 'Link', 'elementor' ) ),
96 Text_Control::bind_to( '_cssid' )
97 ->set_label( __( 'ID', 'elementor' ) )
98 ->set_meta( $this->get_css_id_control_meta() ),
99 ];
100 }
101
102 protected function define_base_styles(): array {
103 $background_color_value = Background_Prop_Type::generate( [
104 'color' => Color_Prop_Type::generate( '#375EFB' ),
105 ] );
106 $display_value = String_Prop_Type::generate( 'inline-block' );
107 $padding_value = Dimensions_Prop_Type::generate( [
108 'block-start' => Size_Prop_Type::generate( [
109 'size' => 12,
110 'unit' => 'px',
111 ]),
112 'inline-end' => Size_Prop_Type::generate( [
113 'size' => 24,
114 'unit' => 'px',
115 ]),
116 'block-end' => Size_Prop_Type::generate( [
117 'size' => 12,
118 'unit' => 'px',
119 ]),
120 'inline-start' => Size_Prop_Type::generate( [
121 'size' => 24,
122 'unit' => 'px',
123 ]),
124 ]);
125 $border_radius_value = Size_Prop_Type::generate( [
126 'size' => 2,
127 'unit' => 'px',
128 ] );
129 $border_width_value = Size_Prop_Type::generate( [
130 'size' => 0,
131 'unit' => 'px',
132 ] );
133 $align_text_value = String_Prop_Type::generate( 'center' );
134
135 return [
136 'base' => Style_Definition::make()
137 ->add_variant(
138 Style_Variant::make()
139 ->add_prop( 'background', $background_color_value )
140 ->add_prop( 'display', $display_value )
141 ->add_prop( 'padding', $padding_value )
142 ->add_prop( 'border-radius', $border_radius_value )
143 ->add_prop( 'border-width', $border_width_value )
144 ->add_prop( 'text-align', $align_text_value )
145 ),
146 ];
147 }
148
149 protected function get_templates(): array {
150 return [
151 'elementor/elements/atomic-button' => __DIR__ . '/atomic-button.html.twig',
152 ];
153 }
154
155 public function render_markdown(): string {
156 $settings = $this->get_atomic_settings();
157 $text = wp_strip_all_tags( $settings['text'] ?? '' );
158
159 if ( empty( $text ) ) {
160 return '';
161 }
162
163 if ( ! empty( $settings['link']['href'] ) ) {
164 return '[' . $text . '](' . esc_url( $settings['link']['href'] ) . ')';
165 }
166
167 return '**' . $text . '**';
168 }
169 }
170