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
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<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);
```
38 changes: 24 additions & 14 deletions src/jojoe77777/FormAPI/CustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -95,66 +100,72 @@ 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;
}
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;
}

/**
* @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;
}

/**
* @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;
}

/**
* @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;
}

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

}
19 changes: 19 additions & 0 deletions src/jojoe77777/FormAPI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down