Skip to content

Commit

Permalink
Merge pull request #87 from modul-is/new-layout-divider
Browse files Browse the repository at this point in the history
New layout divider
  • Loading branch information
vodictomas authored Sep 12, 2024
2 parents 6eba2a6 + c9a779b commit 71851b0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Container extends \Nette\Forms\Container

private ?string $wrapClass = null;

private array $dividerArray = [];


public function setId(string $id): self
{
Expand Down Expand Up @@ -258,6 +260,20 @@ public function addWhisperer(string $name, $label = null, array $items = []): Co
}


public function addDivider(Html|string $content, ?string $previousControl = null): void
{
if(!$previousControl)
{
$controlArray = iterator_to_array($this->getControls());
$lastControl = end($controlArray);

$previousControl = $lastControl->getName();
}

$this->dividerArray[$previousControl] = $content;
}


public function render(): string|Html
{
$components = $this->getComponents();
Expand Down Expand Up @@ -289,6 +305,11 @@ public function render(): string|Html
foreach($inputArray as $control)
{
$inputs .= $control->render();

if(array_key_exists($control->getName(), $this->dividerArray))
{
$inputs .= $this->dividerArray[$control->getName()];
}
}

$rowDiv = Html::el('div')
Expand Down Expand Up @@ -336,6 +357,11 @@ public function render(): string|Html
{
\assert($control instanceof Control\Renderable);
$inputs .= $control->render();

if(array_key_exists($control->getName(), $this->dividerArray))
{
$inputs .= $this->dividerArray[$control->getName()];
}
}

$rowDiv = Html::el('div')
Expand Down
27 changes: 24 additions & 3 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Form extends UIForm

private string $defaultInputWrapClass = 'mb-3 col-12';

private array $dividerArray = [];


public function __construct(\Nette\ComponentModel\IContainer $parent = null, $name = null)
{
Expand Down Expand Up @@ -93,6 +95,11 @@ public function renderForm()
* Nette form hidden input
*/
$inputs .= $input instanceof \Nette\Forms\Controls\HiddenField ? $input->getControl() : $input->render();

if(array_key_exists($input->getName(), $this->dividerArray))
{
$inputs .= $this->dividerArray[$input->getName()];
}
}

if($inputs === null)
Expand All @@ -108,18 +115,18 @@ public function renderForm()
->class('card-body')
->setHtml($row);

$carHeader = null;
$cardHeader = null;

if($groupTitle || $this->getTitle())
{
$groupColor = $group->getOption('color') ? ' ' . $group->getOption('color') : null;

$carHeader = Html::el('div')
$cardHeader = Html::el('div')
->class('card-header' . $groupColor)
->setHtml($groupTitle ?: $this->getTitle());
}

$content = $carHeader . $cardBody;
$content = $cardHeader . $cardBody;

/**
* Last iteration - add footer with submitters
Expand Down Expand Up @@ -441,6 +448,20 @@ public function addMultiWhisperer(string $name, $label = null, array $items = nu
}


public function addDivider(Html|string $content, ?string $previousControl = null): void
{
if(!$previousControl)
{
$controlArray = iterator_to_array($this->getControls());
$lastControl = end($controlArray);

$previousControl = $lastControl->getName();
}

$this->dividerArray[$previousControl] = $content;
}


public function setRenderInline(bool $renderInline = true): self
{
$this->renderInline = $renderInline;
Expand Down

0 comments on commit 71851b0

Please sign in to comment.