Skip to content
Open
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
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,39 @@ projects:
- src: jojoe77777/FormAPI/libFormAPI
version: ^2.1.1
```

## Add Features
### HEADER
![HEADER](https://i.ibb.co/834GHpV/IMG-20250824-232401.jpg)
<br>
For Developers:
```php
$form->addHeader(string $text);
```

### TOOLTIP
![TOOLTIP](https://i.ibb.co/3nQhkV0/IMG-20250824-232426.jpg)
<br>
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)
<br>
For Developers:
```php
$form->addDivider();
```

### SET CUSTOM SUBMIT BUTTON
![Set Custom Submit Button](https://i.ibb.co/JjhNXk2g/IMG-20250824-232446.jpg)
<br>
For Developers:
```php
$form->setSubmitButton(string $text);
```
[![Click to watch feature video](https://youtu.be/_3Co5TVxnbo?si=RVbIQQNvk6XUtkx5)
52 changes: 44 additions & 8 deletions src/jojoe77777/FormAPI/CustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ public function addLabel(string $text, ?string $label = null) : self {
/**
* @param string $text
* @param bool|null $default
* @parm string|null $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);
Expand All @@ -95,17 +101,21 @@ public function addToggle(string $text, bool $default = null, ?string $label = n
* @param int $max
* @param int $step
* @param int $default
* @param string|null $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;
}
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;
Expand All @@ -116,14 +126,18 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
* @param string $text
* @param array $steps
* @param int $defaultIndex
* @param string|null $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]);
Expand All @@ -134,11 +148,12 @@ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1
* @param string $text
* @param array $options
* @param int|null $default
* @param string|null $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;
Expand All @@ -148,15 +163,37 @@ public function addDropdown(string $text, array $options, int $default = null, ?
* @param string $text
* @param string $placeholder
* @param string|null $default
* @param string|null $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;
}

/**
* @param string $text
* @return $this
*/
public function addHeader(string $text, ?string $label = null) : self{
$this->addContent(["type" => "header", "text" => $text]);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => $v === null;
return $this;
}

/**
* @return $this
*/
public function addDivider(?string $label = null) : self{
$this->addContent(["type" => "divider", "text" => ""]);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => $v === null;
return $this;
}

/**
* @param array $content
Expand All @@ -166,5 +203,4 @@ private function addContent(array $content) : self {
$this->data["content"][] = $content;
return $this;
}

}
7 changes: 7 additions & 0 deletions src/jojoe77777/FormAPI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public function sendToPlayer(Player $player) : void {
$player->sendForm($this);
}

/**
* @param string $text
*/
public function setSubmitButton(string $text) : void{
$this->data["submit"] = $text;
}

public function getCallable() : ?callable {
return $this->callable;
}
Expand Down