<?php
namespace PHPFUI;
class ButtonGroup extends \PHPFUI\HTML5Element implements \Countable
{
protected array $buttons = [];
private bool $started = false;
public function __construct()
{
parent::__construct('div');
$this->addClass('button-group');
}
public function addButton(\PHPFUI\Button $button) : static
{
$this->buttons[] = $button;
return $this;
}
public function addButtonClass(string $class) : static
{
foreach ($this->buttons as &$button)
{
$button->addClass($class);
}
return $this;
}
public function count() : int
{
return \count($this->buttons);
}
public function setButton(int $index, \PHPFUI\Button $button) : static
{
if ($index >= 0 && $index < \count($this->buttons))
{
$this->buttons[$index] = $button;
}
else
{
$this->buttons[] = $button;
}
return $this;
}
protected function getStart() : string
{
if (! $this->started)
{
$this->started = true;
foreach ($this->buttons as $button)
{
$this->add($button);
}
}
return parent::getStart();
}
}