Skip to content

Commit

Permalink
Add class for components (#4071)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuomaJuha authored Nov 14, 2024
1 parent 0171815 commit a7f0659
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 26 deletions.
12 changes: 12 additions & 0 deletions module/VuFind/src/VuFind/View/Helper/Root/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @author Juha Luoma <juha.luoma@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
Expand All @@ -37,11 +38,19 @@
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @author Juha Luoma <juha.luoma@helsinki.fi>
* @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
*
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@
$confirmAttrs['data-lightbox-ignore'] = '';
$cancelAttrs['data-lightbox-ignore'] = '';
}

$wrapperAttrs = [
'class' => 'btn-group ' . $this->_componentClass,
];
?>
<div class="btn-group">
<div<?=$this->htmlAttributes($wrapperAttrs)?>>
<?php if ($this->buttonLink): ?>
<a<?=$this->htmlAttributes($buttonAttrs)?>><?=$buttonLabelHtml?></a>
<?php else: ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
$side = $this->config()->offcanvasSide();
$buttonAttrs = [
'class' => 'close-offcanvas btn btn-link ' . $this->_componentClass,
'data-toggle' => 'vufind-offcanvas',
];
?>
<button class="close-offcanvas btn btn-link" data-toggle="vufind-offcanvas">
<button<?=$this->htmlAttributes($buttonAttrs)?>>
<?='right' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-hide-left' : 'offcanvas-hide-right') : ''?>
<span class="btn-link__label"><?=$this->transEsc('navigate_back') ?></span>
<?='left' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-hide-right' : 'offcanvas-hide-left') : ''?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
if ($this->wrapperClass ?? false) {
$wrapperClass = $this->wrapperClass . ' dropdown'; // Bootstrap class
}
$wrapperClass .= ' ' . $this->_componentClass;

$toggleTag = 'button';
$defaultAttrs = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
<?php if (null === ($side = $this->config()->offcanvasSide())): ?>
<a class="search-filter-toggle" href="#<?=$this->escapeHtmlAttr($this->targetId)?>" title="<?=$this->transEscAttr($this->title ?? 'sidebar_expand') ?>">
<?=$this->transEsc($this->linkText) ?>
</a>
<?php else: ?>
<a class="search-filter-toggle icon-link" href="#<?=$this->escapeHtmlAttr($this->targetId)?>" data-toggle="vufind-offcanvas" title="<?=$this->transEscAttr($this->title ?? 'sidebar_expand')?>">
<?='left' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-show-right' : 'offcanvas-show-left', 'icon-link__icon') : ''?>
<span class="icon-link__label"><?=$this->transEsc($this->linkText) ?></span>
<?='right' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-show-left' : 'offcanvas-show-right', 'icon-link__icon') : ''?>
</a>
<?php endif; ?>
<?php
$side = $this->config()->offcanvasSide();
$aAttrs = [
'class' => 'search-filter-toggle ' . $this->_componentClass,
'title' => $this->translate($this->title ?? 'sidebar_expand'),
'href' => '#' . $this->targetId,
];
$iconBefore = '';
$iconAfter = '';
$spanAttrs = [];
if ($side) {
$aAttrs['class'] .= ' icon-link';
$aAttrs['data-toggle'] = 'vufind-offcanvas';
if ($side === 'left') {
$iconBefore = $this->icon($this->layout()->rtl ? 'offcanvas-show-right' : 'offcanvas-show-left', 'icon-link__icon');
} else {
$iconAfter = $this->icon($this->layout()->rtl ? 'offcanvas-show-left' : 'offcanvas-show-right', 'icon-link__icon');
}
$spanAttrs = [
'class' => 'icon-link__label',
];
}
?>

<a<?=$this->htmlAttributes($aAttrs)?>>
<?php if ($spanAttrs): ?>
<?=$iconBefore?><span<?=$this->htmlAttributes($spanAttrs)?>><?=$this->transEsc($this->linkText);?></span><?=$iconAfter?>
<?php else: ?>
<?=$this->transEsc($this->linkText);?>
<?php endif; ?>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@
$confirmAttrs['data-lightbox-ignore'] = '';
$cancelAttrs['data-lightbox-ignore'] = '';
}

$wrapperAttrs = [
'class' => 'btn-group ' . $this->_componentClass,
];
?>
<div class="btn-group">
<div<?=$this->htmlAttributes($wrapperAttrs)?>>
<?php if ($this->buttonLink): ?>
<a<?=$this->htmlAttributes($buttonAttrs)?>><?=$buttonLabelHtml?></a>
<?php else: ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
$side = $this->config()->offcanvasSide();
$buttonAttrs = [
'class' => 'close-offcanvas btn btn-link ' . $this->_componentClass,
'data-toggle' => 'vufind-offcanvas',
];
?>
<button class="close-offcanvas btn btn-link" data-toggle="vufind-offcanvas">
<button<?=$this->htmlAttributes($buttonAttrs)?>>
<?='right' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-hide-left' : 'offcanvas-hide-right') : ''?>
<span class="btn-link__label"><?=$this->transEsc('navigate_back') ?></span>
<?='left' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-hide-right' : 'offcanvas-hide-left') : ''?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
if ($this->wrapperClass ?? false) {
$wrapperClass = $this->wrapperClass . ' dropdown'; // Bootstrap class
}
$wrapperClass .= ' ' . $this->_componentClass;

$toggleTag = 'button';
$defaultAttrs = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
<?php if (null === ($side = $this->config()->offcanvasSide())): ?>
<a class="search-filter-toggle" href="#<?=$this->escapeHtmlAttr($this->targetId)?>" title="<?=$this->transEscAttr($this->title ?? 'sidebar_expand') ?>">
<?=$this->transEsc($this->linkText) ?>
</a>
<?php else: ?>
<a class="search-filter-toggle icon-link" href="#<?=$this->escapeHtmlAttr($this->targetId)?>" data-toggle="vufind-offcanvas" title="<?=$this->transEscAttr($this->title ?? 'sidebar_expand')?>">
<?='left' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-show-right' : 'offcanvas-show-left', 'icon-link__icon') : ''?>
<span class="icon-link__label"><?=$this->transEsc($this->linkText) ?></span>
<?='right' === $side ? $this->icon($this->layout()->rtl ? 'offcanvas-show-left' : 'offcanvas-show-right', 'icon-link__icon') : ''?>
</a>
<?php endif; ?>
<?php
$side = $this->config()->offcanvasSide();
$aAttrs = [
'class' => 'search-filter-toggle ' . $this->_componentClass,
'title' => $this->translate($this->title ?? 'sidebar_expand'),
'href' => '#' . $this->targetId,
];
$iconBefore = '';
$iconAfter = '';
$spanAttrs = [];
if ($side) {
$aAttrs['class'] .= ' icon-link';
$aAttrs['data-toggle'] = 'vufind-offcanvas';
if ($side === 'left') {
$iconBefore = $this->icon($this->layout()->rtl ? 'offcanvas-show-right' : 'offcanvas-show-left', 'icon-link__icon');
} else {
$iconAfter = $this->icon($this->layout()->rtl ? 'offcanvas-show-left' : 'offcanvas-show-right', 'icon-link__icon');
}
$spanAttrs = [
'class' => 'icon-link__label',
];
}
?>

<a<?=$this->htmlAttributes($aAttrs)?>>
<?php if ($spanAttrs): ?>
<?=$iconBefore?><span<?=$this->htmlAttributes($spanAttrs)?>><?=$this->transEsc($this->linkText);?></span><?=$iconAfter?>
<?php else: ?>
<?=$this->transEsc($this->linkText);?>
<?php endif; ?>
</a>

0 comments on commit a7f0659

Please sign in to comment.