- WIP on forms and UI widgets

This commit is contained in:
Dave Mc Nicoll committed 2020-03-17 16:14:47 -04:00
1 parent 657ceb2863
commit b1129def47
7 files changed
+31 -18

No files matched your search

+18 -13
View File
@@ -108,7 +108,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
$obj->attributes($attributes);
}
if ( $custom = static::$config["tags"][$tag] ?? false ) {
if ( false !== ( $custom = static::$config["tags"][$tag] ?? false ) ) {
if ( $custom['tag'] ?? false ) {
$obj->tag = $custom['tag'];
}
@@ -129,34 +129,39 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
{
$element = static::create($tag, $attributes);
$this->append($element);
return $element;
}
public function addClass(string $classname) : self
{
$this->attributes['class'] = $classname;
return $this;
}
public function removeClass($classname) {
if ( $key = array_search(strtolower($classname), array_map('strtolower', $this->attributes['class'])) ) {
if ( false !== $key = array_search(strtolower($classname), array_map('strtolower', $this->attributes['class'])) ) {
unset($this->attributes['class'][$key]);
}
return $this;
}
public function option(string $var, $value = 1) {
public function option(string $var, $value = 1) : self
{
$this->options[$var] = $value;
return $this;
}
public function render() {
public function render() : string
{
$attributesList = [];
foreach ( $this->attributes as $key => $value ) {
if ( is_array($value) ) {
if (empty($value)) continue;
if ( empty($value) ) continue;
if ($key === 'style') {
$style = [];
@@ -183,7 +188,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
}
$content = "";
foreach ( $this->childs as $item ) {
if ( is_object($item) ) {
$content .= $item->render();
@@ -197,22 +202,22 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
return $this->content . $content;
}
else {
$attributesstr = (count($attributesList) && ! in_array('no-attr', $this->options) ? " " . implode(" ", $attributesList) : "");
$compiledAttributes = (count($attributesList) && ! in_array('no-attr', $this->options) ? " " . implode(" ", $attributesList) : "");
# Force the node to contain a certain opening tag (php is a good example)
if ( in_array('force-tag-open', $this->options) ) {
$opentag = $this->options['force-tag-open'] . $attributesstr;
$opentag = $this->options['force-tag-open'] . $compiledAttributes;
}
else {
$opentag = $this->tag ? "<{$this->tag}" . $attributesstr . ">" : "";
$opentag = $this->tag ? "<{$this->tag}" . $compiledAttributes . ">" : "";
}
if ( $this->options['tag-type'] ?? false ) {
if ( $this->options['tag-type'] === "single" ) {
return $opentag;
return $opentag . $content;
}
}
else if ( in_array('force-tag-close', $this->options) ) {
elseif ( in_array('force-tag-close', $this->options) ) {
$closetag = $this->options['force-tag-close'];
}
else {
@@ -226,6 +231,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
public function html($set = null) {
if ($set !== null) {
$this->content = $set;
return $this;
}
@@ -235,6 +241,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
public function text(?string $set = null) {
if ($set !== null) {
$this->content = htmlspecialchars( $set, ENT_NOQUOTES );
return $this;
}
@@ -263,13 +270,11 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
case static::INSERT_MODE_PREPEND:
array_unshift($this->childs, $item);
break;
}
}
return $this;
}
public function attributes(array $attributes) : self
{