Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions components/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

namespace Tutor\Components;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
defined( 'ABSPATH' ) || exit;

/**
* Accordion Component Class.
Expand Down Expand Up @@ -274,4 +272,4 @@ class="tutor-accordion-content"
);
}

}
}
3 changes: 1 addition & 2 deletions components/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Tutor\Components;

use Tutor\Components\Constants\Size;
use Tutor\Components\Contracts\ComponentInterface;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -41,7 +40,7 @@
*
* @since 4.0.0
*/
class Avatar extends BaseComponent implements ComponentInterface {
class Avatar extends BaseComponent {

/**
* Avatar size (20, 24, etc).
Expand Down
27 changes: 20 additions & 7 deletions components/BaseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Tutor\Components;

use Tutor\Components\Contracts\ComponentInterface;

defined( 'ABSPATH' ) || exit;

/**
Expand All @@ -24,7 +22,7 @@
*
* @since 4.0.0
*/
abstract class BaseComponent implements ComponentInterface {
abstract class BaseComponent {

/**
* Keep the component as string
Expand All @@ -36,13 +34,13 @@ abstract class BaseComponent implements ComponentInterface {
protected $component_string = '';

/**
* Create a new Button instance.
* Create a new component instance.
*
* @since 4.0.0
*
* @return ComponentInterface
* @return static
*/
public static function make(): ComponentInterface {
public static function make() {
return new static();
}

Expand All @@ -56,6 +54,7 @@ public static function make(): ComponentInterface {
* ]
*
* @since 4.0.0
*
* @var array
*/
protected $attributes = array();
Expand All @@ -69,6 +68,7 @@ public static function make(): ComponentInterface {
* @since 4.0.0
*
* @param array $attrs Key–value pairs of HTML attributes.
*
* @return self
*/
public function attrs( array $attrs ): self {
Expand Down Expand Up @@ -115,6 +115,18 @@ protected function esc( $value, $esc_fn = 'esc_html' ): string {
return call_user_func( $esc_fn, $value );
}

/**
* Get the component output as an HTML string.
*
* Note: Child classes must implement this method and are responsible
* for preparing and properly sanitizing the component’s HTML output.
*
* @since 4.0.0
*
* @return string The component HTML output.
*/
abstract public function get(): string;

/**
* Render the component
*
Expand All @@ -123,7 +135,8 @@ protected function esc( $value, $esc_fn = 'esc_html' ): string {
* @return void
*/
public function render(): void {
echo $this->get(); // phpcs:ignore.
// phpcs:ignore -- Sanitization is performed within each child class’s `get` method implementation.
echo $this->get();
}

}
54 changes: 0 additions & 54 deletions components/Contracts/ComponentInterface.php

This file was deleted.

13 changes: 8 additions & 5 deletions components/InputField.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class InputField extends BaseComponent {
*
* @var string
*/
protected $searchPlaceholder = '';
protected $search_placeholder = '';

/**
* Help text below input.
Expand Down Expand Up @@ -457,7 +457,7 @@ public function label( $label ) {
*/
public function placeholder( $placeholder, $search = false ) {
if ( $search ) {
$this->searchPlaceholder = $placeholder;
$this->search_placeholder = $placeholder;
} else {
$this->placeholder = $placeholder;
}
Expand Down Expand Up @@ -738,7 +738,8 @@ public function loading_message( $loading_message = '' ): self {
* 'description' => '',
* )
* );
* ```
* ```.
*
* @return self
*/
public function options( $options = array() ): self {
Expand Down Expand Up @@ -768,6 +769,7 @@ public function max_selections( $max_selections = 3 ): self {
* @param array $groups the options for input field.
*
* Example format for $groups:
*
* ```
* $groups = array(
* array(
Expand All @@ -788,7 +790,8 @@ public function max_selections( $max_selections = 3 ): self {
* ),
* ),
* );
* ```
* ```.
*
* @return self
*/
public function groups( $groups = array() ): self {
Expand Down Expand Up @@ -1080,7 +1083,7 @@ protected function render_select_input(): string {
'required' => $this->required,

'placeholder' => $this->placeholder,
'searchPlaceholder' => $this->searchPlaceholder,
'searchPlaceholder' => $this->search_placeholder,
'emptyMessage' => $this->empty_message,
'loadingMessage' => $this->loading_message,
'maxHeight' => $this->max_height,
Expand Down
14 changes: 13 additions & 1 deletion templates/demo-components/dynamic-components.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<?php
/**
* Dynamic component examples.
*
* @package Tutor\Templates
* @author Themeum <[email protected]>
* @link https://themeum.com
* @since 4.0.0
*/

defined( 'ABSPATH' ) || exit;
?>
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -255,7 +267,7 @@
Button::make()->label( 'Another Modal' )->variant( 'destructive' )->attr( 'onclick', 'TutorCore.modal.showModal("another-modal")' )->render();
Button::make()->label( 'Headless Modal' )->variant( 'primary-soft' )->attr( 'onclick', 'TutorCore.modal.showModal("headless-modal")' )->render();
?>

</div>
<?php
Modal::make()
Expand Down
Loading