Skip to content

Commit

Permalink
We want to be able to set the type of these
Browse files Browse the repository at this point in the history
  • Loading branch information
darrencoutts118 committed Sep 10, 2024
1 parent cbbf91d commit af65c17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Components/BaseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function withAttributes(array $attributes)
// check if it it's an instance of an element attribute bag
if ($dataElement instanceof ElementAttributeBag) {
// if it is, pull out the attributes and set everything we need to
$this->{$dataName} = $dataElement->run($this->componentBuilder);
$this->{$dataName} = $dataElement->setComponentBuilder($this->componentBuilder);

$this->elements[$dataName] = $this->{$dataName};
}
Expand Down
9 changes: 5 additions & 4 deletions src/Components/FieldGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ class FieldGroup extends BaseComponent
*
* @var ElementAttributeBag
*/
public $labelAttributes;
public ElementAttributeBag $labelAttributes;

/**
* Attributes to be applied around the field
*
* @var ElementAttributeBag
*/
public $fieldAttributes;
public ElementAttributeBag $fieldAttributes;

/**
* Attributes to be applied to the error message
*
* @var ElementAttributeBag
*/
public $errorAttributes;
public ElementAttributeBag $errorAttributes;

/**
* Attributes to be applied to the help text
*
* @var ElementAttributeBag
*/
public $helpAttributes;
public ElementAttributeBag $helpAttributes;

public function __construct(
public ?string $name = '',
public ?string $label = '',
public ?string $help = '',
public ?string $error = '',
) {
// register the attribute builder elements
$this->labelAttributes = $this->registerAttributeBuilderElement('label');
$this->fieldAttributes = $this->registerAttributeBuilderElement('field');
$this->errorAttributes = $this->registerAttributeBuilderElement('error');
Expand Down
14 changes: 8 additions & 6 deletions src/ElementAttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@

class ElementAttributeBag implements Htmlable
{
private $elements;
private ComponentBuilder $componentBuilder;

public function __construct(protected string $element)
{

}

public function run(ComponentBuilder $componentBuilder)
public function setComponentBuilder(ComponentBuilder $componentBuilder): self
{
$this->elements = $componentBuilder->getAttributeBag($this->element);
$this->componentBuilder = $componentBuilder;

return $this;
}

public function __toString()
public function __toString(): string
{
return $this->elements->__toString();
return $this->componentBuilder->getAttributeBag($this->element)->__toString();
}

public function toHtml()
public function toHtml(): string
{
return $this->__toString();
}
Expand Down

0 comments on commit af65c17

Please sign in to comment.