Skip to content

Commit 314160f

Browse files
committedAug 10, 2024·
Dynamic menu rendering upgrade
1 parent 8c9b514 commit 314160f

File tree

7 files changed

+85
-39
lines changed

7 files changed

+85
-39
lines changed
 

‎app/Services/MenuService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function buildMenu()
1414

1515
$menu = SpatieMenu::new()
1616
->addClass('flex items-center space-x-4')
17-
->addItemClass('px-4 py-2 rounded-md bg-green-700 text-white hover:bg-green-600 transition duration-300 ease-in-out');
17+
->addItemClass('p-2 flex items-center text-sm text-white focus:outline-none focus:text-white');
1818

1919
$this->createMenuItems($menuItems)->each(function ($item) use ($menu) {
2020
$menu->add($item);

‎database/seeders/DatabaseSeeder.php

+4
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ public function run(): void
1919
'name' => 'Test User',
2020
'email' => 'test@example.com',
2121
]);
22+
23+
$this->call([
24+
MenuSeeder::class,
25+
]);
2226
}
2327
}

‎database/seeders/MenuSeeder.php

+2-26
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,15 @@ public function run()
1515
'url' => '/',
1616
'order' => 1
1717
],
18-
[
19-
'name' => 'Properties',
20-
'url' => '/properties',
21-
'order' => 2,
22-
'children' => [
23-
['name' => 'For Sale', 'url' => '/properties/for-sale', 'order' => 1],
24-
['name' => 'For Rent', 'url' => '/properties/for-rent', 'order' => 2],
25-
]
26-
],
27-
[
28-
'name' => 'Services',
29-
'url' => '/services',
30-
'order' => 3,
31-
'children' => [
32-
['name' => 'Buying', 'url' => '/services/buying', 'order' => 1],
33-
['name' => 'Selling', 'url' => '/services/selling', 'order' => 2],
34-
['name' => 'Renting', 'url' => '/services/renting', 'order' => 3],
35-
]
36-
],
3718
[
3819
'name' => 'About',
3920
'url' => '/about',
40-
'order' => 4
21+
'order' => 2
4122
],
4223
[
4324
'name' => 'Contact',
4425
'url' => '/contact',
45-
'order' => 5
46-
],
47-
[
48-
'name' => 'Calculators',
49-
'url' => '/calculators',
50-
'order' => 6
26+
'order' => 3
5127
],
5228
];
5329

‎package-lock.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"vite": "^5.4.0"
1717
},
1818
"dependencies": {
19+
"preline": "^2.4.1",
1920
"vite-plugin-static-copy": "^1.0.6"
2021
}
2122
}
+55-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
1-
<nav class="navigation fixed top-0 w-full flex justify-between" style="background-color: #f0f0f0; padding: 1rem 0;">
2-
<div class="container" style="max-width: 1200px; margin: auto; display: flex; justify-content: space-between; align-items: center;">
3-
<a href="#" style="font-weight: bold; text-decoration: none; color: #333;">CMS ss</a>
4-
<ul style="list-style: none; display: flex; gap: 20px; margin: 0; padding: 0;">
5-
<li><a href="/" style="text-decoration: none; color: #333;">Home</a></li>
6-
<li><a href="#" style="text-decoration: none; color: #333;">About</a></li>
7-
<li><a href="#" style="text-decoration: none; color: #333;">Blog</a></li>
8-
<li><a href="#" style="text-decoration: none; color: #333;">Contact</a></li>
9-
</ul>
10-
</div>
11-
</nav>
1+
<header class="flex flex-wrap md:justify-start md:flex-nowrap z-50 w-full bg-blue-600">
2+
<nav class="relative max-w-[66rem] w-full md:flex md:items-center md:justify-between md:gap-3 mx-auto px-4 sm:px-6 lg:px-8 py-2">
3+
<div class="flex items-center justify-between">
4+
<a class="flex-none font-semibold text-xl text-white focus:outline-none focus:opacity-80" href="#" aria-label="Brand"> {{ config('app.name') }} </a>
5+
6+
<div class="md:hidden">
7+
<button type="button" class="hs-collapse-toggle relative size-9 flex justify-center items-center text-sm font-semibold rounded-lg border border-white/50 text-white hover:bg-white/10 focus:outline-none focus:bg-white/10 disabled:opacity-50 disabled:pointer-events-none" id="hs-base-header-collapse" aria-expanded="false" aria-controls="hs-base-header" aria-label="Toggle navigation" data-hs-collapse="#hs-base-header">
8+
<svg class="hs-collapse-open:hidden size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" x2="21" y1="6" y2="6"/><line x1="3" x2="21" y1="12" y2="12"/><line x1="3" x2="21" y1="18" y2="18"/></svg>
9+
<svg class="hs-collapse-open:block shrink-0 hidden size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
10+
<span class="sr-only">Toggle navigation</span>
11+
</button>
12+
</div>
13+
</div>
14+
15+
<div id="hs-base-header" class="hs-collapse hidden overflow-hidden transition-all duration-300 basis-full grow md:block" aria-labelledby="hs-base-header-collapse">
16+
<div class="overflow-hidden overflow-y-auto max-h-[75vh] [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500">
17+
<div class="py-2 md:py-0 flex flex-col md:flex-row md:items-center md:justify-end gap-0.5 md:gap-1">
18+
19+
{!! app(App\Services\MenuService::class)->buildMenu() !!}
20+
21+
<div class="relative flex flex-wrap items-center gap-x-1.5 md:ps-2.5 mt-1 md:mt-0 md:ms-1.5 before:block before:absolute before:top-1/2 before:-start-px before:w-px before:h-4 before:bg-white/30 before:-translate-y-1/2">
22+
@if (auth()->check())
23+
@php
24+
$user = auth()->user();
25+
$role = $user->getRoleNames()->first() ?? 'user';
26+
$dashboardUrl = $role === 'admin' ? '/admin' : '/' . $role;
27+
@endphp
28+
29+
<a href="{{ route('dashboard') }}"
30+
class="p-2 w-full flex items-center text-sm text-white/80 hover:text-white focus:outline-none focus:text-white">
31+
<svg class="shrink-0 size-4 me-3 md:me-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
32+
<path d="M5 3a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5Zm14 18a2 2 0 0 0 2-2v-2a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h4ZM5 11a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2H5Zm14 2a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h4Z"/>
33+
</svg>
34+
{{ ucfirst($role) }} Dashboard
35+
</a>
36+
@else
37+
<a href="{{ route('login') }}"
38+
class="p-2 flex items-center text-sm text-white/80 hover:text-white focus:outline-none focus:text-white">
39+
<svg class="shrink-0 size-4 me-3 md:me-2" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
40+
Login
41+
</a>
42+
<a href="{{ route('register') }}"
43+
class="p-2 flex items-center text-sm text-white/80 hover:text-white focus:outline-none focus:text-white">
44+
<svg class="shrink-0 size-4 me-3 md:me-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
45+
<path fill-rule="evenodd" d="M9 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8Zm-2 9a4 4 0 0 0-4 4v1a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2v-1a4 4 0 0 0-4-4H7Zm8-1a1 1 0 0 1 1-1h1v-1a1 1 0 1 1 2 0v1h1a1 1 0 1 1 0 2h-1v1a1 1 0 1 1-2 0v-1h-1a1 1 0 0 1-1-1Z" clip-rule="evenodd"/>
46+
</svg>
47+
Register
48+
</a>
49+
@endif
50+
</div>
51+
</div>
52+
</div>
53+
</div>
54+
</nav>
55+
</header>

‎tailwind.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
'./vendor/laravel/jetstream/**/*.blade.php',
1010
'./storage/framework/views/*.php',
1111
'./resources/views/**/*.blade.php',
12+
'node_modules/preline/dist/*.js',
1213
],
1314

1415
theme: {
@@ -19,5 +20,5 @@ export default {
1920
},
2021
},
2122

22-
plugins: [forms, typography],
23+
plugins: [forms, typography, require('preline/plugin'),],
2324
};

0 commit comments

Comments
 (0)
Please sign in to comment.