PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0-beta2
Elementor Website Builder – more than just a page builder v4.2.0-beta2
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 4.0.7 All 451 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.2.0-beta2, at modules/atomic-widgets/elements/atomic-button/atomic-button.php

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