Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New layout divider #87

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading