-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06a4383
commit d61de8c
Showing
21 changed files
with
1,025 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI; | ||
|
||
use pocketmine\form\Form as PmForm; | ||
|
||
abstract class Form implements PmForm { | ||
private string $title; | ||
|
||
public const TYPE_SIMPLE_FORM = "form"; | ||
public const TYPE_CUSTOM_FORM = "custom_form"; | ||
public const TYPE_MODAL_FORM = "modal"; | ||
|
||
public function __construct(string $title) { | ||
$this->title = $title; | ||
$this->onCreation(); | ||
} | ||
|
||
public function getTitle(): string { | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title): void { | ||
$this->title = $title; | ||
} | ||
|
||
abstract protected function getType(): string; | ||
|
||
abstract protected function serializeBody(): array; | ||
|
||
public function jsonSerialize(): array { | ||
$body = $this->serializeBody(); | ||
$body["title"] = $this->title; | ||
$body["type"] = $this->getType(); | ||
return $body; | ||
} | ||
|
||
protected function onCreation(): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
use Closure; | ||
use brokiem\snpc\libs\EasyUI\icon\ButtonIcon; | ||
use brokiem\snpc\libs\EasyUI\utils\Submittable; | ||
use JsonSerializable; | ||
|
||
class Button implements JsonSerializable { | ||
use Submittable; | ||
|
||
private string $text; | ||
private ?ButtonIcon $icon; | ||
|
||
public function __construct(string $text, ?ButtonIcon $icon = null, ?Closure $listener = null) { | ||
$this->text = $text; | ||
$this->icon = $icon; | ||
$this->setSubmitListener($listener); | ||
} | ||
|
||
public function hasIcon(): bool { | ||
return $this->icon !== null; | ||
} | ||
|
||
public function getIcon(): ?ButtonIcon { | ||
return $this->icon; | ||
} | ||
|
||
public function setIcon(?ButtonIcon $icon): void { | ||
$this->icon = $icon; | ||
} | ||
|
||
public function jsonSerialize(): array { | ||
$data = [ | ||
"text" => $this->text | ||
]; | ||
|
||
if($this->hasIcon()) { | ||
$data["image"] = $this->icon->jsonSerialize(); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
class Dropdown extends Selector { | ||
|
||
public function getType(): string { | ||
return Element::TYPE_DROPDOWN; | ||
} | ||
|
||
public function serializeBody(): array { | ||
return [ | ||
"options" => $this->getOptionsTexts(), | ||
"default" => $this->getDefaultIndex() | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
use JsonSerializable; | ||
|
||
/** | ||
* Element is exclusive for the elements of CustomForms | ||
*/ | ||
abstract class Element implements JsonSerializable { | ||
|
||
private ?string $headerText; | ||
|
||
public const TYPE_DROPDOWN = "dropdown"; | ||
public const TYPE_INPUT = "input"; | ||
public const TYPE_LABEL = "label"; | ||
public const TYPE_SLIDER = "slider"; | ||
public const TYPE_STEP_SLIDER = "step_slider"; | ||
public const TYPE_TOGGLE = "toggle"; | ||
|
||
public function __construct(?string $headerText) { | ||
$this->headerText = $headerText; | ||
} | ||
|
||
public function getHeaderText(): ?string { | ||
return $this->headerText; | ||
} | ||
|
||
public function setHeaderText(?string $headerText): void { | ||
$this->headerText = $headerText; | ||
} | ||
|
||
abstract public function getType(): string; | ||
|
||
abstract public function serializeBody(): array; | ||
|
||
abstract public function assignResult($result): void; | ||
|
||
public function jsonSerialize(): array { | ||
return array_merge($this->serializeBody(), [ | ||
"type" => $this->getType(), | ||
"text" => $this->headerText ?? "" | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
|
||
class Input extends Element { | ||
private ?string $defaultText; | ||
private ?string $placeholder; | ||
private ?string $submittedText = null; | ||
|
||
public function __construct(?string $headerText, ?string $defaultText = null, ?string $placeholder = null) { | ||
$this->defaultText = $defaultText; | ||
$this->placeholder = $placeholder; | ||
parent::__construct($headerText); | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getSubmittedText(): ?string { | ||
return $this->submittedText; | ||
} | ||
|
||
public function getType(): string { | ||
return Element::TYPE_INPUT; | ||
} | ||
|
||
public function assignResult($result): void { | ||
$this->submittedText = $result; | ||
} | ||
|
||
public function serializeBody(): array { | ||
return [ | ||
"default" => $this->defaultText ?? "", | ||
"placeholder" => $this->placeholder ?? "" | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
class Label extends Element { | ||
|
||
public function __construct(string $headerText) { | ||
parent::__construct($headerText); | ||
} | ||
|
||
public function getType(): string { | ||
return Element::TYPE_LABEL; | ||
} | ||
|
||
public function assignResult($result): void { | ||
return; | ||
} | ||
|
||
public function serializeBody(): array { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
use brokiem\snpc\libs\EasyUI\utils\Submittable; | ||
|
||
class ModalOption { | ||
use Submittable; | ||
|
||
private string $text; | ||
|
||
public function __construct(string $text) { | ||
$this->text = $text; | ||
} | ||
|
||
public function getText(): string { | ||
return $this->text; | ||
} | ||
|
||
public function setText(string $text): void { | ||
$this->text = $text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace brokiem\snpc\libs\EasyUI\element; | ||
|
||
class Option { | ||
|
||
private string $id; | ||
private string $text; | ||
|
||
public function __construct(string $id, string $text) { | ||
$this->id = $id; | ||
$this->text = $text; | ||
} | ||
|
||
public function getId(): string { | ||
return $this->id; | ||
} | ||
|
||
public function getText(): string { | ||
return $this->text; | ||
} | ||
|
||
public function setText(string $text): void { | ||
$this->text = $text; | ||
} | ||
} |
Oops, something went wrong.