Skip to content

Commit

Permalink
Add container attributes to HasContainer trait and update render test…
Browse files Browse the repository at this point in the history
…s. (#184)
  • Loading branch information
terabytesoftw committed Dec 31, 2023
1 parent 9362547 commit 0fee41b
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 102 deletions.
2 changes: 2 additions & 0 deletions src/Attribute/Custom/HasContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
trait HasContainer
{
protected array $containerAttributes = [];
protected bool $container = false;
protected string $containerTemplate = '';
protected string $containerTag = 'div';

/**
* Enable or disable the container tag.
Expand Down
9 changes: 7 additions & 2 deletions src/Input/Base/AbstractButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ abstract class AbstractButton extends Element implements LabelInterface, InputIn
use Attribute\Input\HasValue;

protected array $attributes = [];
protected bool $container = true;
protected string $containerTag = 'div';
protected string $template = '{prefix}\n{label}\n{tag}\n{suffix}';
protected string $type = 'button';

public function loadDefaultDefinitions(): array
{
return [
'container()' => [true],
];
}

protected function run(): string
{
$this->validateStringValue($this->getValue());
Expand Down
9 changes: 7 additions & 2 deletions src/Input/Base/AbstractButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ abstract class AbstractButtonGroup extends Element
* @psalm-var Button[]
*/
protected array $buttons = [];
protected bool $container = true;
protected string $containerTag = 'div';
protected bool $individualContainer = false;

/**
Expand Down Expand Up @@ -50,6 +48,13 @@ public function individualContainer(bool $value): static
return $new;
}

public function loadDefaultDefinitions(): array
{
return [
'container()' => [true],
];
}

protected function run(): string
{
return $this->renderContainerTag(null, $this->renderButtons());
Expand Down
9 changes: 7 additions & 2 deletions src/Input/Base/AbstractChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ abstract class AbstractChoiceList extends Element implements InputInterface, Lab
use Attribute\Input\HasValue;

protected array $attributes = [];
protected bool $container = true;
protected string $containerTag = 'div';
/**
* @psalm-var Checkbox[]|Radio[] $items
*/
protected array $items = [];
protected string $separator = '';

public function loadDefaultDefinitions(): array
{
return [
'container()' => [true],
];
}

public function items(Checkbox|Radio ...$items): static
{
$new = clone $this;
Expand Down
9 changes: 0 additions & 9 deletions tests/Attribute/Custom/HasContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public function testClass(): void
$instance = new class () {
use HasContainer;

protected bool $container = true;
protected string $containerTag = 'div';

public function getContainerClass(): string
{
return $this->containerAttributes['class'] ?? '';
Expand All @@ -43,9 +40,6 @@ public function testException(): void
{
$instance = new class () {
use HasContainer;

protected bool $container = true;
protected string $containerTag = '';
};

$this->expectException(InvalidArgumentException::class);
Expand All @@ -58,9 +52,6 @@ public function testContainerGetId(): void
{
$instance = new class () {
use HasContainer;

protected bool $container = true;
protected string $containerTag = 'div';
};

$this->assertNull($instance->getContainerId());
Expand Down

0 comments on commit 0fee41b

Please sign in to comment.