From a7f065901f819a6fa74c15144a1638a2edd0f294 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:37:58 +0200 Subject: [PATCH] Add class for components (#4071) --- .../src/VuFind/View/Helper/Root/Component.php | 12 ++++++ .../_ui/components/confirm-button.phtml | 6 ++- .../components/hide-offcanvas-button.phtml | 6 ++- .../_ui/components/menu-button.phtml | 1 + .../_ui/components/show-sidebar-button.phtml | 42 ++++++++++++++----- .../_ui/components/confirm-button.phtml | 6 ++- .../components/hide-offcanvas-button.phtml | 6 ++- .../_ui/components/menu-button.phtml | 1 + .../_ui/components/show-sidebar-button.phtml | 42 ++++++++++++++----- 9 files changed, 96 insertions(+), 26 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Component.php b/module/VuFind/src/VuFind/View/Helper/Root/Component.php index 49b80a90c5d..3c2e005adb9 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Component.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Component.php @@ -23,6 +23,7 @@ * @category VuFind * @package View_Helpers * @author Demian Katz + * @author Juha Luoma * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development Wiki */ @@ -37,11 +38,19 @@ * @category VuFind * @package View_Helpers * @author Demian Katz + * @author Juha Luoma * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development Wiki */ class Component extends AbstractHelper { + /** + * Local cache of CSS class names for components (component name => class name). + * + * @var array + */ + protected array $cssClassCache = []; + /** * Expand path and render template * @@ -67,6 +76,9 @@ public function __invoke(string $name, $params = []): string ++$invocation; $params['_invocation'] = $invocation; + // Prefix normalized component name with vc- (VuFind component) to avoid accidental style assignments + $this->cssClassCache[$name] ??= 'vc-' . preg_replace('/[^-_A-Za-z0-9]/', '-', $name); + $params['_componentClass'] = $this->cssClassCache[$name]; return $this->view->render("_ui/$path/" . $name, $params); } diff --git a/themes/bootstrap3/templates/_ui/components/confirm-button.phtml b/themes/bootstrap3/templates/_ui/components/confirm-button.phtml index 593d144d4b3..518c9d86e22 100644 --- a/themes/bootstrap3/templates/_ui/components/confirm-button.phtml +++ b/themes/bootstrap3/templates/_ui/components/confirm-button.phtml @@ -79,8 +79,12 @@ $confirmAttrs['data-lightbox-ignore'] = ''; $cancelAttrs['data-lightbox-ignore'] = ''; } + + $wrapperAttrs = [ + 'class' => 'btn-group ' . $this->_componentClass, + ]; ?> -
+htmlAttributes($wrapperAttrs)?>> buttonLink): ?> htmlAttributes($buttonAttrs)?>> diff --git a/themes/bootstrap3/templates/_ui/components/hide-offcanvas-button.phtml b/themes/bootstrap3/templates/_ui/components/hide-offcanvas-button.phtml index 3740e235a61..608bba566c5 100644 --- a/themes/bootstrap3/templates/_ui/components/hide-offcanvas-button.phtml +++ b/themes/bootstrap3/templates/_ui/components/hide-offcanvas-button.phtml @@ -1,7 +1,11 @@ config()->offcanvasSide(); + $buttonAttrs = [ + 'class' => 'close-offcanvas btn btn-link ' . $this->_componentClass, + 'data-toggle' => 'vufind-offcanvas', + ]; ?> -