166 lines
5.4 KiB
PHP
166 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http;
|
|
|
|
use Nwidart\Menus\MenuItem;
|
|
use Nwidart\Menus\Presenters\Presenter;
|
|
|
|
class AdminlteCustomPresenter extends Presenter
|
|
{
|
|
public function getOpenTagWrapper()
|
|
{
|
|
return '<nav class="sidebar-nav tw-flex-1 tw-overflow-y-auto" id="side-bar">' . PHP_EOL
|
|
. '<ul class="sidebar-menu">' . PHP_EOL;
|
|
}
|
|
|
|
public function getCloseTagWrapper()
|
|
{
|
|
return '</ul>' . PHP_EOL . '</nav>' . PHP_EOL;
|
|
}
|
|
|
|
public function getMenuWithoutDropdownWrapper($item)
|
|
{
|
|
$active = $item->isActive() ? ' active' : '';
|
|
$selected = $item->isActive() ? ' selected' : '';
|
|
|
|
return '<li class="sidebar-item' . $selected . '">' .
|
|
'<a href="' . $item->getUrl() . '" title="" class="sidebar-link' . $active . '" ' . $item->getAttributes() . '>' .
|
|
$this->formatIcon($item->icon) . '<span class="hide-menu">' . $item->title . '</span>' .
|
|
'</a></li>' . PHP_EOL;
|
|
}
|
|
|
|
public function getActiveState($item, $state = ' active')
|
|
{
|
|
return $item->isActive() ? $state : null;
|
|
}
|
|
|
|
public function getActiveStateOnChild($item, $state = 'selected')
|
|
{
|
|
return $item->hasActiveOnChild() ? $state : null;
|
|
}
|
|
|
|
public function getDividerWrapper()
|
|
{
|
|
return '<li><span class="sidebar-divider"></span></li>' . PHP_EOL;
|
|
}
|
|
|
|
public function getHeaderWrapper($item)
|
|
{
|
|
$attrs = $item->attributes ?? [];
|
|
$group = $attrs['data-group'] ?? '';
|
|
$isCollapsible = strpos((string) ($attrs['class'] ?? ''), 'nav-small-cap--collapsible') !== false;
|
|
$classes = 'nav-small-cap';
|
|
|
|
if ($isCollapsible) {
|
|
$classes .= ' nav-small-cap--collapsible';
|
|
}
|
|
|
|
$dataGroup = $group ? ' data-group="' . e($group) . '"' : '';
|
|
$toggle = '';
|
|
|
|
if ($isCollapsible) {
|
|
$toggle = '<span class="nav-small-cap-marker" aria-hidden="true">«</span>' .
|
|
'<button type="button" class="nav-small-cap-toggle" aria-label="Toggle section">' .
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">' .
|
|
'<path d="M6 9l6 6l6 -6"/>' .
|
|
'</svg></button>';
|
|
}
|
|
|
|
return '<li class="' . $classes . '"' . $dataGroup . '>' . $toggle .
|
|
'<span class="hide-menu nav-small-cap-label">' . $item->title . '</span></li>' . PHP_EOL;
|
|
}
|
|
|
|
public function getMenuWithDropDownWrapper($item)
|
|
{
|
|
$selected = $item->hasActiveOnChild() ? ' selected' : '';
|
|
$activeLink = $item->hasActiveOnChild() ? ' active' : '';
|
|
|
|
$dropdownToggle = '<a href="#" title="" class="drop_down sidebar-link has-arrow' . $activeLink . '" ' . $item->getAttributes() . '>' .
|
|
$this->formatIcon($item->icon) . '<span class="hide-menu">' . $item->title . '</span>' .
|
|
'</a>';
|
|
|
|
$childItems = $this->getChildMenuItems($item);
|
|
|
|
return '<li class="sidebar-item' . $selected . '">' . $dropdownToggle . $childItems . '</li>' . PHP_EOL;
|
|
}
|
|
|
|
public function getMultiLevelDropdownWrapper($item)
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function getChildMenuItems($item)
|
|
{
|
|
$children = '';
|
|
$displayStyle = $item->hasActiveOnChild() ? 'block' : 'none';
|
|
$inClass = $item->hasActiveOnChild() ? ' in' : '';
|
|
|
|
if (count($item->getChilds()) > 0) {
|
|
$children .= '<ul class="chiled first-level collapse' . $inClass . '" style="display:' . $displayStyle . '">';
|
|
|
|
foreach ($item->getChilds() as $child) {
|
|
$children .= $this->renderChildItem($child);
|
|
}
|
|
|
|
$children .= '</ul>';
|
|
}
|
|
|
|
return $children;
|
|
}
|
|
|
|
protected function renderChildItem(MenuItem $child): string
|
|
{
|
|
if ($child->isHeader()) {
|
|
return '<li class="nav-small-cap nav-small-cap--section">' .
|
|
'<span class="nav-small-cap-marker" aria-hidden="true">«</span>' .
|
|
'<span class="hide-menu nav-small-cap-label">' . $child->title . '</span></li>' . PHP_EOL;
|
|
}
|
|
|
|
if ($child->isDivider()) {
|
|
return '<li><span class="sidebar-divider"></span></li>' . PHP_EOL;
|
|
}
|
|
|
|
$isActive = $child->isActive() ? ' active' : '';
|
|
$childSelected = $child->isActive() ? ' selected' : '';
|
|
|
|
return '<li class="sidebar-item' . $childSelected . '">' .
|
|
'<a href="' . $child->getUrl() . '" title="" class="sidebar-link' . $isActive . '" ' . $child->getAttributes() . '>' .
|
|
$this->formatChildIcon($child) . '<span class="hide-menu">' . $child->title . '</span>' .
|
|
'</a></li>' . PHP_EOL;
|
|
}
|
|
|
|
protected function formatIcon($icon)
|
|
{
|
|
if (empty($icon)) {
|
|
return '';
|
|
}
|
|
|
|
return '<span class="sidebar-icon-box">' . $this->renderIconMarkup($icon) . '</span>';
|
|
}
|
|
|
|
protected function formatChildIcon($item)
|
|
{
|
|
$icon = $item->icon ?? '';
|
|
|
|
if (! empty($icon)) {
|
|
return '<span class="sidebar-child-icon-box">' . $this->renderIconMarkup($icon) . '</span>';
|
|
}
|
|
|
|
return '<span class="icon-small"></span>';
|
|
}
|
|
|
|
protected function renderIconMarkup(string $icon): string
|
|
{
|
|
if (strpos($icon, '<svg') !== false) {
|
|
return $icon;
|
|
}
|
|
|
|
return '<i class="' . $icon . '"></i>';
|
|
}
|
|
|
|
public function getArray($item)
|
|
{
|
|
return '';
|
|
}
|
|
}
|