| 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 |
|
| 59 |
'link' => Link_Prop_Type::make(), |
| 60 |
|
| 61 |
'tag' => String_Prop_Type::make() |
| 62 |
->default( 'button' ) |
| 63 |
->description( 'The HTML tag for the button element.' ), |
| 64 |
|
| 65 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 66 |
]; |
| 67 |
|
| 68 |
return $props; |
| 69 |
} |
| 70 |
|
| 71 |
protected function define_atomic_controls(): array { |
| 72 |
return [ |
| 73 |
Section::make() |
| 74 |
->set_label( __( 'Content', 'elementor' ) ) |
| 75 |
->set_items( [ |
| 76 |
Inline_Editing_Control::bind_to( 'text' ) |
| 77 |
->set_placeholder( __( 'Type your button text here', 'elementor' ) ) |
| 78 |
->set_label( __( 'Button text', 'elementor' ) ), |
| 79 |
] ), |
| 80 |
Section::make() |
| 81 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 82 |
->set_id( 'settings' ) |
| 83 |
->set_items( $this->get_settings_controls() ), |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
protected function get_settings_controls(): array { |
| 88 |
return [ |
| 89 |
Link_Control::bind_to( 'link' ) |
| 90 |
->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) |
| 91 |
->set_label( __( 'Link', 'elementor' ) ), |
| 92 |
Text_Control::bind_to( '_cssid' ) |
| 93 |
->set_label( __( 'ID', 'elementor' ) ) |
| 94 |
->set_meta( $this->get_css_id_control_meta() ), |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
protected function define_base_styles(): array { |
| 99 |
$background_color_value = Background_Prop_Type::generate( [ |
| 100 |
'color' => Color_Prop_Type::generate( '#375EFB' ), |
| 101 |
] ); |
| 102 |
$display_value = String_Prop_Type::generate( 'inline-block' ); |
| 103 |
$padding_value = Dimensions_Prop_Type::generate( [ |
| 104 |
'block-start' => Size_Prop_Type::generate( [ |
| 105 |
'size' => 12, |
| 106 |
'unit' => 'px', |
| 107 |
]), |
| 108 |
'inline-end' => Size_Prop_Type::generate( [ |
| 109 |
'size' => 24, |
| 110 |
'unit' => 'px', |
| 111 |
]), |
| 112 |
'block-end' => Size_Prop_Type::generate( [ |
| 113 |
'size' => 12, |
| 114 |
'unit' => 'px', |
| 115 |
]), |
| 116 |
'inline-start' => Size_Prop_Type::generate( [ |
| 117 |
'size' => 24, |
| 118 |
'unit' => 'px', |
| 119 |
]), |
| 120 |
]); |
| 121 |
$border_radius_value = Size_Prop_Type::generate( [ |
| 122 |
'size' => 2, |
| 123 |
'unit' => 'px', |
| 124 |
] ); |
| 125 |
$border_width_value = Size_Prop_Type::generate( [ |
| 126 |
'size' => 0, |
| 127 |
'unit' => 'px', |
| 128 |
] ); |
| 129 |
$align_text_value = String_Prop_Type::generate( 'center' ); |
| 130 |
|
| 131 |
return [ |
| 132 |
'base' => Style_Definition::make() |
| 133 |
->add_variant( |
| 134 |
Style_Variant::make() |
| 135 |
->add_prop( 'background', $background_color_value ) |
| 136 |
->add_prop( 'display', $display_value ) |
| 137 |
->add_prop( 'padding', $padding_value ) |
| 138 |
->add_prop( 'border-radius', $border_radius_value ) |
| 139 |
->add_prop( 'border-width', $border_width_value ) |
| 140 |
->add_prop( 'text-align', $align_text_value ) |
| 141 |
), |
| 142 |
]; |
| 143 |
} |
| 144 |
|
| 145 |
protected function get_templates(): array { |
| 146 |
return [ |
| 147 |
'elementor/elements/atomic-button' => __DIR__ . '/atomic-button.html.twig', |
| 148 |
]; |
| 149 |
} |
| 150 |
|
| 151 |
public function render_markdown(): string { |
| 152 |
$settings = $this->get_atomic_settings(); |
| 153 |
$text = wp_strip_all_tags( $settings['text'] ?? '' ); |
| 154 |
|
| 155 |
if ( empty( $text ) ) { |
| 156 |
return ''; |
| 157 |
} |
| 158 |
|
| 159 |
if ( ! empty( $settings['link']['href'] ) ) { |
| 160 |
return '[' . $text . '](' . esc_url( $settings['link']['href'] ) . ')'; |
| 161 |
} |
| 162 |
|
| 163 |
return '**' . $text . '**'; |
| 164 |
} |
| 165 |
} |
| 166 |
|