Instantly share code, notes, and snippets.
Forked from rosswintle/AppNavigationMenu.php
Created
June 11, 2021 19:22
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save cpereiraweb/89d51c1f33c7125f1d0650cc32ac7509 to your computer and use it in GitHub Desktop.
Laravel Jetstream Livewire Navigation Menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This class extends the base NavigationClass provided by Jetstream. | |
* Note that the base class includes the navigation-menu.blade.php | |
*/ | |
namespace App\Http\Livewire; | |
class AppNavigationMenu extends \Laravel\Jetstream\Http\Livewire\NavigationMenu | |
{ | |
/** | |
* Define the list of items to go in the navigation as 'Label' => 'route' | |
* @var string[] | |
*/ | |
public $items = [ | |
'Posts' => 'dashboard', | |
'Templates' => 'templates', | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- resources/views/components/desktop-menu.blade.php --> | |
<div class="flex"> | |
<!-- Logo --> | |
<div class="flex-shrink-0 flex items-center"> | |
<x-logo></x-logo> | |
</div> | |
<!-- Navigation Links --> | |
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex"> | |
@foreach ($items as $label => $route) | |
<x-jet-nav-link href="{{ route($route) }}" :active="request()->routeIs($route)"> | |
{{ $label }} | |
</x-jet-nav-link> | |
@endforeach | |
</div> | |
</div> | |
<div class="hidden sm:flex sm:items-center sm:ml-6"> | |
<!-- Settings Dropdown --> | |
<div class="ml-3 relative"> | |
<x-jet-dropdown align="right" width="48"> | |
<x-slot name="trigger"> | |
@if (Laravel\Jetstream\Jetstream::managesProfilePhotos()) | |
<button class="flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out"> | |
<img class="h-8 w-8 rounded-full object-cover" src="{{ Auth::user()->profile_photo_url }}" alt="{{ Auth::user()->name }}" /> | |
</button> | |
@else | |
<span class="inline-flex rounded-md"> | |
<button type="button" class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:text-gray-700 focus:outline-none transition ease-in-out duration-150"> | |
{{ Auth::user()->name }} | |
<svg class="ml-2 -mr-0.5 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> | |
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" /> | |
</svg> | |
</button> | |
</span> | |
@endif | |
</x-slot> | |
<x-slot name="content"> | |
<!-- Account Management --> | |
<div class="block px-4 py-2 text-xs text-gray-400"> | |
{{ __('Manage Account') }} | |
</div> | |
<x-jet-dropdown-link href="{{ route('profile.show') }}"> | |
{{ __('Profile') }} | |
</x-jet-dropdown-link> | |
@if (Laravel\Jetstream\Jetstream::hasApiFeatures()) | |
<x-jet-dropdown-link href="{{ route('api-tokens.index') }}"> | |
{{ __('API Tokens') }} | |
</x-jet-dropdown-link> | |
@endif | |
<div class="border-t border-gray-100"></div> | |
<!-- Authentication --> | |
<form method="POST" action="{{ route('logout') }}"> | |
@csrf | |
<x-jet-dropdown-link href="{{ route('logout') }}" | |
onclick="event.preventDefault(); | |
this.closest('form').submit();"> | |
{{ __('Log Out') }} | |
</x-jet-dropdown-link> | |
</form> | |
</x-slot> | |
</x-jet-dropdown> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- resources/views/components/mobile-menu.blade.php --> | |
<!-- Responsive Navigation Menu --> | |
<div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden"> | |
<div class="pt-2 pb-3 space-y-1"> | |
@foreach ($items as $label => $route) | |
<x-jet-responsive-nav-link href="{{ route($route) }}" :active="request()->routeIs($route)"> | |
{{ $label }} | |
</x-jet-responsive-nav-link> | |
@endforeach | |
</div> | |
<!-- Responsive Settings Options --> | |
<div class="pt-4 pb-1 border-t border-gray-200"> | |
<div class="flex items-center px-4"> | |
@if (Laravel\Jetstream\Jetstream::managesProfilePhotos()) | |
<div class="flex-shrink-0 mr-3"> | |
<img class="h-10 w-10 rounded-full object-cover" src="{{ Auth::user()->profile_photo_url }}" alt="{{ Auth::user()->name }}" /> | |
</div> | |
@endif | |
<div> | |
<div class="font-medium text-base text-gray-800">{{ Auth::user()->name }}</div> | |
<div class="font-medium text-sm text-gray-500">{{ Auth::user()->email }}</div> | |
</div> | |
</div> | |
<div class="mt-3 space-y-1"> | |
<!-- Account Management --> | |
<x-jet-responsive-nav-link href="{{ route('profile.show') }}" :active="request()->routeIs('profile.show')"> | |
{{ __('Profile') }} | |
</x-jet-responsive-nav-link> | |
@if (Laravel\Jetstream\Jetstream::hasApiFeatures()) | |
<x-jet-responsive-nav-link href="{{ route('api-tokens.index') }}" :active="request()->routeIs('api-tokens.index')"> | |
{{ __('API Tokens') }} | |
</x-jet-responsive-nav-link> | |
@endif | |
<!-- Authentication --> | |
<form method="POST" action="{{ route('logout') }}"> | |
@csrf | |
<x-jet-responsive-nav-link href="{{ route('logout') }}" | |
onclick="event.preventDefault(); | |
this.closest('form').submit();"> | |
{{ __('Log Out') }} | |
</x-jet-responsive-nav-link> | |
</form> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- resources/views/navigation-menu.blade.php --> | |
<nav x-data="{ open: false }" class="bg-white border-b border-gray-100"> | |
<!-- Primary Navigation Menu --> | |
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | |
<div class="flex justify-between h-16"> | |
<x-desktop-menu :items="$items"></x-desktop-menu> | |
<x-hamburger></x-hamburger> | |
</div> | |
<x-mobile-menu :items="$items"></x-mobile-menu> | |
</div> | |
</nav> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment