Skip to content

Commit

Permalink
feat: newTab and url to sidebar items
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-rahimi committed Feb 26, 2024
1 parent dee094c commit e8bd257
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@
// 'items' => [
// [
// 'item' => 'Dashboard',
// 'url' => 'http://localhost',
// 'route' => 'welcome',
// 'newTab' => false,
// 'icon' => 'fa-light fa-home-lg-alt',
// 'activeIn' => ['welcome'],
// ],
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/sidebar/item.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a class="nav-link {{ $item->active ? 'active' : '' }}" href="{{ $item->url }}">
<a class="nav-link {{ $item->active ? 'active' : '' }}" href="{{ $item->url }}" {{ $item->newTab ? 'target="_blank"' : '' }}>
<div class="nav-button">
<i class="{{ $item->icon }}"></i>
<span>{{ $item->name }}</span>
Expand Down
26 changes: 22 additions & 4 deletions src/Controllers/Makers/Maker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\View\View as ViewContracts;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use T0team\LaravelPanel\Enums\Color;
use T0team\LaravelPanel\Traits\MakerTrait;
Expand Down Expand Up @@ -86,12 +87,13 @@ private function handleSidebarGroup(array $data): ?object
];
}

private function handleSidebarItem(array $item): object
private function handleSidebarItem(array $item): ?object
{
// get route url
$url = route($item['route']);
$url = $this->getItemUrl($item);
if (is_null($url)) return null;

// check module has badge
// check item has badge
if (isset($item['badge'])) {
$badge = $this->handleBadge($item['badge']);
}
Expand All @@ -100,11 +102,27 @@ private function handleSidebarItem(array $item): object
'url' => $url,
'name' => $item['item'],
'icon' => $item['icon'],
'active' => in_array(request()->route()->getName(), [$item['route'], ...$item['activeIn'] ?? []]),
'active' => in_array(request()->route()->getName(), [$item['route'] ?? [], ...$item['activeIn'] ?? []]),
'badge' => $badge ?? false,
'newTab' => $item['newTab'] ?? false,
];
}

private function getItemUrl(array $item): ?string
{
// check route exists
if (isset($item['route']) && Route::has($item['route'])) {
return route($item['route']);
}

// check url exists
if (isset($item['url'])) {
return $item['url'];
}

return null;
}

private function handleSidebarModule(string $name): ?object
{
// check application use modules
Expand Down

0 comments on commit e8bd257

Please sign in to comment.