- Added a new UiImage element.

- Inputs can now have a class array OR a simple string as 'class' param.
This commit is contained in:
Dave M. 2021-03-01 16:35:57 +00:00
parent 34828f642c
commit e75d997b02
4 changed files with 57 additions and 1 deletions

50
src/Form/UiImage.php Normal file
View File

@ -0,0 +1,50 @@
<?php
namespace Picea\Ui\Form;
use Picea\Ui\Common\UiElement;
use Picea\Extension\Extension;
use Picea\Extension\ExtensionTrait;
class UiImage extends UiElement implements Extension {
use ExtensionTrait;
public string $token = "ui.img";
public string $tag = "img";
public array $attributes = [
'class' => 'ui-image',
];
public array $options = [
'tag-type' => "single",
];
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
{
return "<?php echo ( new \\" . static::class . "() )->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 [];
}
}

View File

@ -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']);
}

View File

@ -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);

View File

@ -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());