1- import { ref , computed , onMounted , onUnmounted , watchEffect } from 'vue'
1+ import { ref , computed , onMounted , onUnmounted , watch } from 'vue'
22import { usePage , useForm } from '@inertiajs/vue3'
33import {
44 LayoutGrid , House , Info , Settings , LogOut , ExternalLink , FileSearch , FolderGit2 , Lock , Users
@@ -18,40 +18,47 @@ export function useAppLayout() {
1818 // Menu items
1919 const menuItems = computed < MenuItem [ ] > ( ( ) => [
2020 {
21+ key : 'home' ,
2122 label : 'Home' ,
2223 lucideIcon : House ,
2324 route : route ( 'welcome' ) ,
2425 active : currentRoute . value == 'welcome' ,
2526 } ,
2627 {
28+ key : 'dashboard' ,
2729 label : 'Dashboard' ,
2830 lucideIcon : LayoutGrid ,
2931 route : route ( 'dashboard' ) ,
3032 active : currentRoute . value == 'dashboard' ,
3133 } ,
3234 {
35+ key : 'resources' ,
3336 label : 'Resources' ,
3437 lucideIcon : Info ,
3538 items : [
3639 {
40+ key : 'resources-laravel' ,
3741 label : 'Laravel Docs' ,
3842 url : 'https://laravel.com/docs/master' ,
3943 target : '_blank' ,
4044 lucideIcon : ExternalLink ,
4145 } ,
4246 {
47+ key : 'resources-primevue' ,
4348 label : 'PrimeVue Docs' ,
4449 url : 'https://primevue.org/' ,
4550 target : '_blank' ,
4651 lucideIcon : ExternalLink ,
4752 } ,
4853 {
54+ key : 'resources-starter-docs' ,
4955 label : 'Starter Kit Docs' ,
5056 url : 'https://connorabbas.github.io/laravel-primevue-starter-kit-docs/' ,
5157 target : '_blank' ,
5258 lucideIcon : FileSearch ,
5359 } ,
5460 {
61+ key : 'resources-starter-repo' ,
5562 label : 'Starter Kit Repo' ,
5663 url : 'https://github.com/connorabbas/laravel-primevue-starter-kit' ,
5764 target : '_blank' ,
@@ -60,17 +67,20 @@ export function useAppLayout() {
6067 ] ,
6168 } ,
6269 {
70+ key : 'admin' ,
6371 label : 'Admin' ,
6472 lucideIcon : Lock ,
6573 visible : page . props . auth . isAdmin ,
6674 items : [
6775 {
76+ key : 'admin-dashboard' ,
6877 label : 'Dashboard' ,
6978 lucideIcon : LayoutGrid ,
7079 route : route ( 'admin.dashboard' ) ,
7180 active : currentRoute . value == 'admin.dashboard' ,
7281 } ,
7382 {
83+ key : 'admin-users-index' ,
7484 label : 'Users' ,
7585 lucideIcon : Users ,
7686 route : route ( 'admin.users.index' ) ,
@@ -80,7 +90,28 @@ export function useAppLayout() {
8090 } ,
8191 ] )
8292
83- // User menu and logout functionality.
93+ // Check/set expanded PanelMenu items based on active status, for non-persistent layouts
94+ const expandedKeys = ref < Record < string , boolean > > ( { } )
95+ const updateExpandedKeys = ( ) => {
96+ const keys : Record < string , boolean > = { }
97+ const hasActiveChild = ( item : MenuItem ) : boolean => {
98+ if ( item . items ) {
99+ for ( const child of item . items ) {
100+ if ( hasActiveChild ( child ) ) {
101+ if ( item . key ) keys [ item . key ] = true
102+ return true
103+ }
104+ }
105+ }
106+ return ! ! item . active
107+ }
108+ menuItems . value . forEach ( hasActiveChild )
109+ expandedKeys . value = keys
110+ }
111+ watch ( currentRoute , ( ) => {
112+ updateExpandedKeys ( )
113+ } , { immediate : true } )
114+
84115 const logoutForm = useForm ( { } )
85116 const logout = ( ) => {
86117 logoutForm . post ( route ( 'logout' ) )
@@ -101,7 +132,7 @@ export function useAppLayout() {
101132 } ,
102133 ]
103134
104- // Mobile menu
135+ // Mobile drawer menu
105136 const mobileMenuOpen = ref ( false )
106137 if ( typeof window !== 'undefined' ) {
107138 const windowWidth = ref ( window . innerWidth )
@@ -114,8 +145,8 @@ export function useAppLayout() {
114145 onUnmounted ( ( ) => {
115146 window . removeEventListener ( 'resize' , updateWidth )
116147 } )
117- watchEffect ( ( ) => {
118- if ( windowWidth . value > 1024 ) {
148+ watch ( windowWidth , ( newWidth ) => {
149+ if ( newWidth > 1024 ) {
119150 mobileMenuOpen . value = false
120151 }
121152 } )
@@ -124,6 +155,7 @@ export function useAppLayout() {
124155 return {
125156 currentRoute,
126157 menuItems,
158+ expandedKeys,
127159 userMenuItems,
128160 mobileMenuOpen,
129161 logout,
0 commit comments