diff --git a/README.md b/README.md index 9054fe1..8b9d341 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,38 @@ projects: - src: jojoe77777/FormAPI/libFormAPI version: ^2.1.1 ``` + +## Add Features +### HEADER +![HEADER](https://i.ibb.co/834GHpV/IMG-20250824-232401.jpg) +
+For Developers: +```php +$form->addHeader(string $text); +``` + +### TOOLTIP +![TOOLTIP](https://i.ibb.co/3nQhkV0/IMG-20250824-232426.jpg) +
+For Developers: +```php +$form->addToggle("input", "", "", "this is tooltip"); +$form->addDropDown("select", ["1", "2", "3"], 0, "this is tooltip dropdown"); +..... +``` + +### DIVIDER +![DIVIDER](https://i.ibb.co/n8wKXgys/IMG-20250824-232552.jpg) +
+For Developers: +```php +$form->addDivider(); +``` + +### SET CUSTOM SUBMIT BUTTON +![Set Custom Submit Button](https://i.ibb.co/JjhNXk2g/IMG-20250824-232446.jpg) +
+For Developers: +```php +$form->setSubmitButton(string $text); +``` diff --git a/src/jojoe77777/FormAPI/CustomForm.php b/src/jojoe77777/FormAPI/CustomForm.php index 8ae6171..5b86efa 100755 --- a/src/jojoe77777/FormAPI/CustomForm.php +++ b/src/jojoe77777/FormAPI/CustomForm.php @@ -68,24 +68,29 @@ public function getTitle() : string { public function addLabel(string $text, ?string $label = null) : self { $this->addContent(["type" => "label", "text" => $text]); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => $v === null; + // $this->validationMethods[] = static fn($v) => $v === null; return $this; } /** * @param string $text * @param bool|null $default + * @param string $tooltip * @param string|null $label * @return $this */ - public function addToggle(string $text, bool $default = null, ?string $label = null) : self { + public function addToggle(string $text, bool $default = null, string $tooltip = null, ?string $label = null) : self { $content = ["type" => "toggle", "text" => $text]; if($default !== null) { $content["default"] = $default; } + + if($tooltip !== null){ + $content["tooltip"] = $tooltip; + } + $this->addContent($content); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_bool($v); return $this; } @@ -95,10 +100,11 @@ public function addToggle(string $text, bool $default = null, ?string $label = n * @param int $max * @param int $step * @param int $default + * @param string $tooltip * @param string|null $label * @return $this */ - public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self { + public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, string $tooltip = null, ?string $label = null) : self { $content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max]; if($step !== -1) { $content["step"] = $step; @@ -106,9 +112,11 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int if($default !== -1) { $content["default"] = $default; } + if($tooltip !== null){ + $content["tooltip"] = $tooltip; + } $this->addContent($content); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max; return $this; } @@ -116,17 +124,20 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int * @param string $text * @param array $steps * @param int $defaultIndex + * @param string $tooltip * @param string|null $label * @return $this */ - public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self { + public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, string $tooltip = null, ?string $label = null) : self { $content = ["type" => "step_slider", "text" => $text, "steps" => $steps]; if($defaultIndex !== -1) { $content["default"] = $defaultIndex; } + if($tooltip !== null){ + $content["tooltip"] = $tooltip; + } $this->addContent($content); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]); return $this; } @@ -134,13 +145,13 @@ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1 * @param string $text * @param array $options * @param int|null $default + * @param string $tooltip * @param string|null $label * @return $this */ - public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self { - $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]); + public function addDropdown(string $text, array $options, int $default = null, string $tooltip = null, ?string $label = null) : self { + $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default, "tooltip" => $tooltip]); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]); return $this; } @@ -148,13 +159,13 @@ public function addDropdown(string $text, array $options, int $default = null, ? * @param string $text * @param string $placeholder * @param string|null $default + * @param string $tooltip * @param string|null $label * @return $this */ - public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self { - $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]); + public function addInput(string $text, string $placeholder = "", string $default = null, string $tooltip = null, ?string $label = null) : self { + $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default, "tooltip" => $tooltip]); $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_string($v); return $this; } @@ -166,5 +177,4 @@ private function addContent(array $content) : self { $this->data["content"][] = $content; return $this; } - } diff --git a/src/jojoe77777/FormAPI/Form.php b/src/jojoe77777/FormAPI/Form.php index 12e248a..f5e0720 100755 --- a/src/jojoe77777/FormAPI/Form.php +++ b/src/jojoe77777/FormAPI/Form.php @@ -31,6 +31,25 @@ public function __construct(?callable $callable) { public function sendToPlayer(Player $player) : void { $player->sendForm($this); } + + /** + * @param string $text + */ + public function addHeader(string $text) : void{ + $this->data["content"][] = ["type" => "header", "text" => $text]; + } + + public function addDivider() : void{ + $this->data["content"][] = ["type" => "divider", "text" => ""]; + } + + /** + * @param string $texr + * @return $this + */ + public function setSubmitButton(string $text) : void{ + $this->data["submit"] = $text; + } public function getCallable() : ?callable { return $this->callable;