From e75d997b02185fd35fcf9448a3f76f0368493af4 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 1 Mar 2021 16:35:57 +0000 Subject: [PATCH] - Added a new UiImage element. - Inputs can now have a class array OR a simple string as 'class' param. --- src/Form/UiImage.php | 50 +++++++++++++++++++++++++++++++++++++++++++ src/Form/UiInput.php | 2 +- src/Form/UiSelect.php | 5 +++++ src/Ui.php | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Form/UiImage.php diff --git a/src/Form/UiImage.php b/src/Form/UiImage.php new file mode 100644 index 0000000..27768b0 --- /dev/null +++ b/src/Form/UiImage.php @@ -0,0 +1,50 @@ + 'ui-image', + ]; + + public array $options = [ + 'tag-type' => "single", + ]; + + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string + { + return "buildHtml($arguments) ?>"; + } + + public function buildHtml(string $source, array $attributes = [], array $options = []) : string + { + if ($options) { + $this->options += $options; + } + + if ($attributes['class'] ?? false) { + $attributes['class'] .= " {$this->attributes['class']}"; + + unset($this->attributes['class']); + } + + $this->attributes([ 'src' => $source ] + $attributes + $this->attributes + $this->objectAttribute()); + + return $this->render(); + } + + protected function objectAttribute() : array + { + return []; + } +} diff --git a/src/Form/UiInput.php b/src/Form/UiInput.php index d3812ff..78b507b 100644 --- a/src/Form/UiInput.php +++ b/src/Form/UiInput.php @@ -43,7 +43,7 @@ class UiInput extends UiElement implements Extension { } if ($attributes['class'] ?? false) { - $attributes['class'] .= " {$this->attributes['class']}"; + $attributes['class'] = implode(" ", array_merge((array) $attributes['class'], (array) $this->attributes['class'])); unset($this->attributes['class']); } diff --git a/src/Form/UiSelect.php b/src/Form/UiSelect.php index 5ca08a4..499fc4b 100644 --- a/src/Form/UiSelect.php +++ b/src/Form/UiSelect.php @@ -24,6 +24,11 @@ class UiSelect extends UiElement implements Extension { public function buildHtml(string $name, array $list, $value = null, array $attributes = [], bool $strictComparison = true) : string { + if ($attributes['class'] ?? false) { + $attributes['class'] = implode(" ", array_merge((array) $attributes['class'], (array) $this->attributes['class'])); + unset($this->attributes['class']); + } + $this->attributes([ 'name' => $name ] + $attributes + $this->attributes); $this->setList($list, $value, $strictComparison); diff --git a/src/Ui.php b/src/Ui.php index 1a94207..0712b71 100644 --- a/src/Ui.php +++ b/src/Ui.php @@ -29,6 +29,7 @@ class Ui { $compiler->registerExtension(new Form\UiUrl()); $compiler->registerExtension(new Form\UiWeek()); $compiler->registerExtension(new Form\UiSelect()); + $compiler->registerExtension(new Form\UiImage()); $compiler->registerExtension(new Component\UiPopup());