From b89257f8077ac469f4605946d9919e7826ebede6 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 14 Oct 2022 09:57:50 +0200 Subject: [PATCH 1/3] SearchControls: Wrap the search bar with `.search-controls` Such a container is nearly always required for a good looking layout, so why shouldn't it be there by default? --- asset/css/controls.less | 13 +++++++++++++ src/Compat/SearchControls.php | 2 ++ src/Control/SearchBar.php | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/asset/css/controls.less b/asset/css/controls.less index fbabe1c9..f0e88c0a 100644 --- a/asset/css/controls.less +++ b/asset/css/controls.less @@ -93,3 +93,16 @@ } } +.search-controls { + display: flex; + min-width: 100%; + + .search-bar { + flex: 1 1 auto; + + & ~ .control-button { + margin-left: .5em; + } + } +} + diff --git a/src/Compat/SearchControls.php b/src/Compat/SearchControls.php index 4621776b..412e97a8 100644 --- a/src/Compat/SearchControls.php +++ b/src/Compat/SearchControls.php @@ -3,6 +3,7 @@ namespace ipl\Web\Compat; use GuzzleHttp\Psr7\ServerRequest; +use ipl\Html\Html; use ipl\Orm\Exception\InvalidRelationException; use ipl\Orm\Query; use ipl\Stdlib\Seq; @@ -74,6 +75,7 @@ public function createSearchBar(Query $query, ...$params): SearchBar $searchBar->setRedirectUrl($redirectUrl); $searchBar->setAction($redirectUrl->getAbsoluteUrl()); $searchBar->setIdProtector([$this->getRequest(), 'protectId']); + $searchBar->addWrapper(Html::tag('div', ['class' => 'search-controls'])); $moduleName = $this->getRequest()->getModuleName(); $controllerName = $this->getRequest()->getControllerName(); diff --git a/src/Control/SearchBar.php b/src/Control/SearchBar.php index 2b18a834..fa3f4f34 100644 --- a/src/Control/SearchBar.php +++ b/src/Control/SearchBar.php @@ -516,7 +516,7 @@ protected function assemble() // Render the editor container outside of this form. It will contain a form as well later on // loaded by XHR and HTML prohibits nested forms. It's style-wise also better... $doc = new HtmlDocument(); - $this->setWrapper($doc); + $this->prependWrapper($doc); $doc->addHtml($this, ...($editorOpener ? [$editorOpener] : [])); } } From 2370a7cb8489a4739474679e1ab9b93db3cb46e3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 14 Oct 2022 09:59:04 +0200 Subject: [PATCH 2/3] css: Provide default list control rules They include all layout and a bit of style rules to replicate the default control layout that is used by Icinga DB Web and various other modules. --- asset/css/controls.less | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/asset/css/controls.less b/asset/css/controls.less index f0e88c0a..9da43a1b 100644 --- a/asset/css/controls.less +++ b/asset/css/controls.less @@ -106,3 +106,46 @@ } } +/** + The default layout of list controls in Icinga Web + + ┌────────────────────────────────────────────────────────────────┐ + │ .pagination-control .limit-control .sort-control │ + │ <-------------------- .search-controls ----------------------> │ + └────────────────────────────────────────────────────────────────┘ + */ +.controls.default-layout { + .box-shadow(0, 0, 0, 1px, @gray-lighter); + z-index: 1; // The content may clip, this ensures the separator is always visible + + > .pagination-control { + float: left; + } + + > .sort-control, + > .limit-control { + float: right; + } + + > .limit-control { + margin-right: .5em; + } + + > .search-controls { + clear: both; + } + + > :not(:only-child) { + margin-bottom: 0.5em; + } + + > .sort-control, + > .search-controls > .control-button:last-child { + margin-right: -.5em; + } + + > .search-controls > .search-bar .search-suggestions { + // Suggestions should be kept at a distance from the bottom of the page + margin-bottom: 2.5em; + } +} From e58a61e6a6b7ec4ce7e83d7f9112bc974448002e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 14 Oct 2022 14:01:25 +0200 Subject: [PATCH 3/3] CompatController: Automatically apply default list control layout --- src/Compat/CompatController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Compat/CompatController.php b/src/Compat/CompatController.php index 5ff6e3b1..e05e9d33 100644 --- a/src/Compat/CompatController.php +++ b/src/Compat/CompatController.php @@ -132,6 +132,18 @@ protected function addControl(ValidHtml $control) { $this->controls->add($control); + if ( + $control instanceof PaginationControl + || $control instanceof LimitControl + || $control instanceof SortControl + || $control instanceof SearchBar + ) { + $this->controls->getAttributes() + ->get('class') + ->removeValue('default-layout') + ->addValue('default-layout'); + } + return $this; }