Merge branch 'master' of https://github.com/mcNdave/picea-ui
This commit is contained in:
commit
b4fc4dd37f
|
@ -178,7 +178,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
}
|
}
|
||||||
else if ( !is_numeric($key) ) {
|
else if ( !is_numeric($key) ) {
|
||||||
# will output something like <tag $key=$value></tag>
|
# will output something like <tag $key=$value></tag>
|
||||||
$attributesList[] = "$key=\"$value\"";
|
$attributesList[] = strpos($value, '"') !== false ? "$key='$value'" : "$key=\"$value\"";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# will output something like <tag $value></tag>
|
# will output something like <tag $value></tag>
|
||||||
|
@ -186,7 +186,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = "";
|
$content = "";
|
||||||
|
|
||||||
foreach ( $this->childs as $item ) {
|
foreach ( $this->childs as $item ) {
|
||||||
|
@ -198,14 +198,14 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( in_array('no-tag', $this->options) ) {
|
if ( in_array('no-tag', $this->options, true) ) {
|
||||||
return $this->content . $content;
|
return $this->content . $content;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$compiledAttributes = (count($attributesList) && ! in_array('no-attr', $this->options) ? " " . implode(" ", $attributesList) : "");
|
$compiledAttributes = (count($attributesList) && ! in_array('no-attr', $this->options, true) ? " " . implode(" ", $attributesList) : "");
|
||||||
|
|
||||||
# Force the node to contain a certain opening tag (php is a good example)
|
# Force the node to contain a certain opening tag (php is a good example)
|
||||||
if ( in_array('force-tag-open', $this->options) ) {
|
if ( in_array('force-tag-open', $this->options, true) ) {
|
||||||
$opentag = $this->options['force-tag-open'] . $compiledAttributes;
|
$opentag = $this->options['force-tag-open'] . $compiledAttributes;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -217,7 +217,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
$closetag = "";
|
$closetag = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ( in_array('force-tag-close', $this->options) ) {
|
elseif ( in_array('force-tag-close', $this->options, true) ) {
|
||||||
$closetag = $this->options['force-tag-close'];
|
$closetag = $this->options['force-tag-close'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace Picea\Ui\Form;
|
namespace Picea\Ui\Form;
|
||||||
|
|
||||||
class UiCheckbox extends UiInput {
|
class UiCheckbox extends UiRadio {
|
||||||
|
|
||||||
public string $token = "ui.checkbox";
|
public string $token = "ui.checkbox";
|
||||||
|
|
||||||
public array $attributes = [
|
public array $attributes = [
|
||||||
'class' => "ui-checkbox",
|
'class' => "ui-checkbox",
|
||||||
'type' => "checkbox",
|
'type' => "checkbox",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,29 @@ class UiInput extends UiElement implements Extension {
|
||||||
'tag-type' => "single",
|
'tag-type' => "single",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected ? string $value;
|
||||||
|
|
||||||
|
protected string $name;
|
||||||
|
|
||||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
||||||
{
|
{
|
||||||
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildHtml(string $name, ? string $value = null, array $attributes = []) : string
|
public function buildHtml(string $name, ? string $value = null, array $attributes = [], array $options = []) : string
|
||||||
{
|
{
|
||||||
$this->setValue($value);
|
$this->name = $name;
|
||||||
$this->attributes([ 'name' => $name ] + $attributes + $this->attributes);
|
|
||||||
|
if (null !== $this->value = $value) {
|
||||||
|
$this->setValue($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($options) {
|
||||||
|
$this->options += $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->attributes([ 'name' => $name ] + $attributes + $this->attributes + $this->objectAttribute());
|
||||||
|
|
||||||
return $this->render();
|
return $this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,5 +51,9 @@ class UiInput extends UiElement implements Extension {
|
||||||
{
|
{
|
||||||
$this->attributes['value'] = $value;
|
$this->attributes['value'] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function objectAttribute() : array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,21 @@ namespace Picea\Ui\Form;
|
||||||
|
|
||||||
class UiRadio extends UiInput {
|
class UiRadio extends UiInput {
|
||||||
|
|
||||||
public string $token = "ui.radio";
|
public string $token = "ui.radio";
|
||||||
|
|
||||||
public array $attributes = [
|
public array $attributes = [
|
||||||
'class' => "ui-radio",
|
'class' => "ui-radio",
|
||||||
'type' => "radio",
|
'type' => "radio",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function objectAttribute() : array
|
||||||
|
{
|
||||||
|
if ( $this->options['value'] ?? false && ( $this->options['value'] === $this->value ) ) {
|
||||||
|
return [
|
||||||
|
'checked' => "checked"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue