Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 85 additions & 36 deletions resources/views/partials/nav-main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,90 @@
use function Statamic\trans as __;
@endphp

@section('nav-main')
<nav class="nav-main">
@foreach ($nav as $section)
<div>
@if ($section['display'] !== 'Top Level')
<div class="section-title">{{ __($section['display']) }}</div>
@endif
<ul>
@foreach ($section['items'] as $item)
@unless ($item->view())
<li v-pre>
<a @class(['active' => $item->isActive()]) href="{{ $item->url() }}" {{ $item->attributes() }}>
{!! $item->svg() !!}
<span>{{ __($item->name()) }}</span>
</a>
@if ($item->children() && $item->isActive())
<ul>
@foreach ($item->children() as $child)
<li>
<a href="{{ $child->url() }}" {{ $item->attributes() }} @class(['active' => $child->isActive()])>
{{ __($child->name()) }}
</a>
</li>
@endforeach
</ul>
@endif
</li>
@else
@include($item->view())
@endunless
@endforeach
</ul>
</div>
@endforeach
</nav>
@section("nav-main")
<nav class="nav-main">
@foreach ($nav as $section)
<div>
@if ($section["display"] !== "Top Level")
<div class="section-title">{{ __($section["display"]) }}</div>
@endif

<ul>
@foreach ($section["items"] as $item)
@unless ($item->view())
<li
v-pre
class="group relative"
@if (! $item->isActive())
x-data="{ open: false, shift: false, mouse: false }"
x-on:keydown.shift.window="shift = true"
x-on:keyup.shift.window="shift = false"
x-on:mouseenter="mouse = true"
x-on:mouseleave="mouse = false"
x-effect="if (shift) open = mouse"
@endif
>
<a
@class([
"active" => $item->isActive(),
"!pr-7 peer" => $item->children() && ! $item->isActive(),
])
href="{{ $item->url() }}"
{{ $item->attributes() }}
>
{!! $item->svg() !!}
<span class="flex-grow">
{{ __($item->name()) }}
</span>
</a>
@if ($item->children() && ! $item->isActive())
<button
class="cursor-pointer opacity-0 group-hover:opacity-100 peer-focus:opacity-100 focus:opacity-100 transition h-7 aspect-square absolute top-0 right-0 z-10"
x-on:click.stop.prevent="open = !open"
:aria-expanded="open ? 'true' : 'false'"
aria-controls="{{ $submenu_id = Str::random(4) }}-submenu"
aria-label="{{ __("Toggle Submenu") }}"
>
<div
class="transform flex items-center w-full h-full justify-center"
x-bind:class="{ 'rotate-180': open }"
>
@cp_svg("ui/chevron-down", "h-5")
</div>
</button>
@endif

@if ($item->children())
<ul
@if (! $item->isActive())
id="{{ $submenu_id }}-submenu"
x-show="open"
x-on:click.outside="open = false"
style="display: none;"
@endif
>
@foreach ($item->children() as $child)
<li>
<a
href="{{ $child->url() }}"
{{ $item->attributes() }}
@class(["active" => $child->isActive()])
>
{{ __($child->name()) }}
</a>
</li>
@endforeach
</ul>
@endif
</li>
@else
@include($item->view())
@endunless
@endforeach
</ul>
</div>
@endforeach
</nav>
@stop

@yield('nav-main')
@yield("nav-main")
1 change: 0 additions & 1 deletion src/CP/Navigation/NavBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ protected function trackChildrenClosures()
protected function resolveChildrenClosures()
{
collect($this->items)
->filter(fn ($item) => $item->isActive() || $this->withHidden)
->each(fn ($item) => $item->resolveChildren());

return $this;
Expand Down
9 changes: 4 additions & 5 deletions tests/CP/Navigation/ActiveNavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\CP\Navigation;

use Closure;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Request;
Expand Down Expand Up @@ -81,8 +80,8 @@ public function it_resolves_all_children_only_once_to_build_caches_for_is_active
$this->assertTrue(Blink::has(NavBuilder::UNRESOLVED_CHILDREN_URLS_CACHE_KEY));
$this->assertTrue(Cache::has(NavBuilder::ALL_URLS_CACHE_KEY));
$this->assertTrue(Blink::has(NavBuilder::ALL_URLS_CACHE_KEY));
$this->assertInstanceOf(Closure::class, $this->getItemByDisplay($nav->get('Content'), 'Collections')->children());
$this->assertInstanceOf(Closure::class, $this->getItemByDisplay($nav->get('Content'), 'Taxonomies')->children());
$this->assertInstanceOf(Collection::class, $this->getItemByDisplay($nav->get('Content'), 'Collections')->children());
$this->assertInstanceOf(Collection::class, $this->getItemByDisplay($nav->get('Content'), 'Taxonomies')->children());
}

#[Test]
Expand Down Expand Up @@ -155,7 +154,7 @@ public function it_builds_core_children_closure_when_not_active()
$collections = $this->buildAndGetItem('Content', 'Collections');

$this->assertFalse($collections->isActive());
$this->assertInstanceOf(Closure::class, $collections->children());
$this->assertInstanceOf(Collection::class, $collections->children());
}

#[Test]
Expand Down Expand Up @@ -332,7 +331,7 @@ public function it_builds_extension_children_closure_when_not_active()
$seoPro = $this->buildAndGetItem('Tools', 'SEO Pro');

$this->assertFalse($seoPro->isActive());
$this->assertInstanceOf(Closure::class, $seoPro->children());
$this->assertInstanceOf(Collection::class, $seoPro->children());
}

#[Test]
Expand Down
Loading