Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add desktop/mobile navigation #74

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
57 changes: 57 additions & 0 deletions resources/views/components/nav-layer.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@props(['id', 'children', 'title' => __('Menu'), 'hasParent' => false, 'tag' => 'form', 'parentUrl' => ''])
@slots(['headerbutton'])

<x-rapidez::slideover.mobile
:title="(string) $title"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the casting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise I get this error
image

:$id
:$hasParent
:$tag
>
<x-slot:headerbutton>
JimmyHoenderdaal marked this conversation as resolved.
Show resolved Hide resolved
<div class="absolute left-0 top-1/2 -translate-y-1/2 cursor-pointer text-white">
@include('rapidez-statamic::navigation.header-button')
</div>
</x-slot:headerbutton>
<div class="flex w-full flex-1 flex-col bg-inactive-100">
<ul class="mt-5 flex flex-col divide-y border-y bg-white">
@if ($hasParent && $parentUrl)
<li>
<a href="{{ $parentUrl }}" class="normal flex items-center justify-between p-5 font-semibold">
@lang('Go to :item', ['item' => strtolower($title)])
</a>
</li>
@endif
@foreach ($children ?: [] as $child)
@php
$url = $child['url'];
if (isset($child['linked_category'])) {
JimmyHoenderdaal marked this conversation as resolved.
Show resolved Hide resolved
$url = Str::start($child['linked_category']->value()['url_path'] ?? '', '/');
}
@endphp
<li class="relative">
@if ($child['title'] ?? '')
<a href="{{ $url }}" class="flex items-center justify-between p-5 font-semibold">
{{ $child['title'] }}
@if ($child['children'])
<x-heroicon-o-chevron-right class="size-4" />
@endif
</a>
@endif
@if ($child['children'])
@php($childId = uniqid(Str::snake("{$child['title']}" ?? '')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This vs unique helpers provide by Laravel? Don't we have a unique ID already which we can use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is using uniqid but it adds snake case to the title for whenever there are spaces in the title
image

I want to use the title here since it makes it more clear what id's and for's are linked to each other in your browser.
Could of course remove that part and only have uniqid but that would make the id a bit abstract and thus hard to debug if needed

<label class="absolute inset-0 cursor-pointer" for="{{ $childId }}"></label>
<x-rapidez-statamic::nav-layer
:id="$childId"
:children="$child['children'] ?? []"
:title="$child['title'] ?? ''"
:parent-url="$child['url']"
has-parent
tag="div"
></x-rapidez-statamic::nav-layer>
@endif
</li>
@endforeach
</ul>
{{ $slot }}
</div>
</x-rapidez::slideover.mobile>
2 changes: 2 additions & 0 deletions resources/views/navigation/header-button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{-- This is shown on the first slideover of the mobile menu, you can leave this empty if you don't want it. By default this is a search button --}}
<x-button.search />
JimmyHoenderdaal marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 54 additions & 0 deletions resources/views/navigation/nav.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<nav class="lg:hidden">
<x-rapidez-statamic::nav-layer
id="navigation"
is-form
:children="Statamic::tag('nav:main')->fetch()"
/>
</nav>
@php
$baseUrl = \Statamic\Facades\Site::current()->absoluteUrl();
@endphp
<nav class="relative border-y max-lg:hidden">
<ul class="flex items-center justify-center gap-8 font-semibold text-neutral [&>:not(:hover)]:hover:text-inactive text-sm">
@foreach (Statamic::tag('nav:main')->fetch() as $item)
@php
$itemUrl = isset($item['linked_category']) && ($item['linked_category']?->value()['url_path'] ?? false) ? $baseUrl . '/' . $item['linked_category']->value()['url_path'] : $item['url'] ?? '';
@endphp
<li class="group">
<a class="relative flex py-4 transition" href="{{ $itemUrl }}">
{{ $item['title'] }}
@if ($item['children'])
<div class="absolute inset-x-0 bottom-0 z-50 h-0.5 w-full origin-right translate-y-1/2 scale-x-0 bg-primary transition group-hover:origin-left group-hover:scale-x-100"></div>
@endif
</a>
@if ($item['children'])
<div class="pointer-events-none absolute inset-x-0 top-full -translate-y-1 border-t bg-white opacity-0 transition group-hover:pointer-events-auto group-hover:translate-y-0 group-hover:opacity-100">
<div class="pointer-events-none absolute inset-x-0 top-full h-screen bg-neutral/50"></div>
<div class="container relative flex overflow-hidden">
<ul class="columns-3 flex-col gap-x-12 py-10 font-bold xl:columns-4 w-full">
@foreach ($item['children'] as $item)
@php
$itemUrl = isset($item['linked_category']) && ($item['linked_category']?->value()['url_path'] ?? false) ? $baseUrl . '/' . $item['linked_category']->value()['url_path'] : $item['url'] ?? '';
JimmyHoenderdaal marked this conversation as resolved.
Show resolved Hide resolved
@endphp
<li class="flex break-inside-avoid flex-col gap-1 pb-5">
<a href="{{ $itemUrl }}">{{ $item['title'] }}</a>
<ul class="flex flex-col font-medium [&>:not(:hover)]:hover:text-inactive">
@foreach ($item['children'] as $item)
@php
$itemUrl = isset($item['linked_category']) && ($item['linked_category']?->value()['url_path'] ?? false) ? $baseUrl . '/' . $item['linked_category']->value()['url_path'] : $item['url'] ?? '';
@endphp
<li class="transition">
<a href="{{ $itemUrl }}">{{ $item['title'] }}</a>
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
</div>
</div>
@endif
</li>
@endforeach
</ul>
</nav>