Skip to content
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
79 changes: 67 additions & 12 deletions src/Ease/TWB5/FormGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,77 @@
namespace Ease\TWB5;

/**
* Description of FormGroup.
* Bootstrap 5 form group.
*
* @author vitex
* Wraps a label, a form control and optional helper text using Bootstrap 5
* markup (.mb-3 wrapper, .form-label label, .form-text helper). Replaces the
* Bootstrap 4 .form-group based widget.
*
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
*/
class FormGroup extends \Ease\Html\DivTag
{
public function __construct($label, \Ease\Html\Input $input, $desc = '')
{
$id = $input->setTagID();
parent::__construct(new \Ease\Html\LabelTag($id, $label));
$input->addTagClass('form-control');
$input->setTagProperties(['aria-describedby' => 'desc'.$id]);
$this->addItem($input);

if ($desc) {
$this->addItem(new DivTag($desc, ['id' => 'desc'.$id, 'class' => 'form-text']));
/**
* Bootstrap 5 form group.
*
* @param mixed $label field label (string, Tag or array)
* @param mixed $content form control widget (or any renderable content)
* @param string $placeholder placeholder text put into the control
* @param mixed $helptext helper text rendered below the control
* @param string $addTagClass CSS class applied to the control (Bootstrap: form-control)
*/
public function __construct(
$label = null,
$content = null,
$placeholder = null,
$helptext = null,
$addTagClass = 'form-control',
) {
parent::__construct(null, ['class' => 'mb-3']);

// Resolve an id used to bind the label to the control.
$id = null;

if (\is_object($content) && method_exists($content, 'getTagID')) {
$id = $content->getTagID();
}

if (empty($id) && \is_string($label) && $label !== '') {
$id = \Ease\Functions::lettersOnly($label);
}

if (empty($id)) {
$id = 'formgroup_'.\Ease\Functions::randomString();
}

if ($label !== null && $label !== '') {
$this->addItem(new \Ease\Html\LabelTag((string) $id, $label, ['class' => 'form-label']));
}

if (\is_object($content)) {
if ($addTagClass && method_exists($content, 'addTagClass')) {
$content->addTagClass($addTagClass);
}

if ($placeholder && method_exists($content, 'setTagProperties')) {
$content->setTagProperties(['placeholder' => $placeholder]);
}

if (method_exists($content, 'setTagID')) {
$content->setTagID((string) $id);
}

if ($helptext && method_exists($content, 'setTagProperties')) {
$content->setTagProperties(['aria-describedby' => 'desc'.$id]);
}

$this->addItem($content);
} elseif ($content !== null) {
$this->addItem($content);
}

if ($helptext) {
$this->addItem(new \Ease\Html\DivTag($helptext, ['id' => 'desc'.$id, 'class' => 'form-text']));
}
}
}
4 changes: 2 additions & 2 deletions src/Ease/TWB5/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function __construct($brand = null, $name = 'navbar', $properties = [])
parent::__construct(null, $properties);
Part::twBootstrapize();

$this->leftContent = new UlTag(null, ['class' => 'navbar-nav ms-auto flex-nowrap navbar-expand mb-2 mb-lg-0', 'style' => '--bs-scroll-height: 100px;']);
$this->rightContent = new UlTag(null, ['class' => 'navbar-nav ml-auto']); // TODO
$this->leftContent = new UlTag(null, ['class' => 'navbar-nav flex-nowrap mb-2 mb-lg-0', 'style' => '--bs-scroll-height: 100px;']);
$this->rightContent = new UlTag(null, ['class' => 'navbar-nav ms-auto flex-nowrap mb-2 mb-lg-0']);

$this->containerFluid = $this->addItem(new \Ease\Html\DivTag([new ATag($this->mainpage, $brand, ['class' => 'navbar-brand']), $this->navBarToggler()], ['class' => 'container-fluid']));
}
Expand Down
Loading