- Corrected inputs handling from view to compiled states
- Added UiSelect widget - Fixed UiForm widget - Fixed UiInput widget - Added mocks of UiMessage and UiPopup. Not even a WIP at this stage.
This commit is contained in:
1 parent
4bf08def27
commit
f28ace745d
7 files changed
+153
-27
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Ui\Form;
|
||||
|
||||
use Picea\Ui\Common\UiElement;
|
||||
use Picea\Extension\Extension;
|
||||
use Picea\Extension\ExtensionTrait;
|
||||
|
||||
class UiSelect extends UiElement implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public string $token = "ui.select";
|
||||
|
||||
public string $tag = "select";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => 'ui-select',
|
||||
];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
||||
{
|
||||
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
||||
}
|
||||
|
||||
public function buildHtml(string $name, array $list, $value, array $attributes = [], bool $strictComparison = true) : string
|
||||
{
|
||||
$this->attributes([ 'name' => $name ] + $attributes + $this->attributes);
|
||||
$this->setList($list, $value, $strictComparison);
|
||||
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
protected function setValue($value) : void
|
||||
{
|
||||
$this->attributes['value'] = $value;
|
||||
}
|
||||
|
||||
protected function setList(array $list, $selected, bool $strict = true) : void
|
||||
{
|
||||
foreach($list as $key => $item) {
|
||||
if ($item instanceof UiElement) {
|
||||
$this->append($item);
|
||||
}
|
||||
elseif ( is_array($item) ) {
|
||||
$obj = new UiElement("optgroup");
|
||||
$obj->text($key);
|
||||
|
||||
foreach($item as $subKey => $subItem) {
|
||||
$obj->append($this->createOption($subItem, $subKey, $strict ? $subKey === $selected : $subKey == $selected));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$obj = $this->createOption($item, $key, $strict ? $key === $selected : $key == $selected);
|
||||
}
|
||||
|
||||
$this->append($obj);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createOption(string $name, string $value, bool $selected, array $attributes = []) : UiElement
|
||||
{
|
||||
$option = new UiElement("option");
|
||||
$option->text($name);
|
||||
$option->attributes($attributes + [ 'value' => $value ]);
|
||||
|
||||
return $option;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user