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 { LayoutGrid , House , Info , Settings , LogOut , ExternalLink , FileSearch , FolderGit2 } from 'lucide-vue-next'
44import { MenuItem } from '@/types'
@@ -16,40 +16,47 @@ export function useAppLayout() {
1616 // Menu items
1717 const menuItems = computed < MenuItem [ ] > ( ( ) => [
1818 {
19+ key : 'home' ,
1920 label : 'Home' ,
2021 lucideIcon : House ,
2122 route : route ( 'welcome' ) ,
2223 active : currentRoute . value == 'welcome' ,
2324 } ,
2425 {
26+ key : 'dashboard' ,
2527 label : 'Dashboard' ,
2628 lucideIcon : LayoutGrid ,
2729 route : route ( 'dashboard' ) ,
2830 active : currentRoute . value == 'dashboard' ,
2931 } ,
3032 {
33+ key : 'resources' ,
3134 label : 'Resources' ,
3235 lucideIcon : Info ,
3336 items : [
3437 {
38+ key : 'resources-laravel' ,
3539 label : 'Laravel Docs' ,
3640 url : 'https://laravel.com/docs/master' ,
3741 target : '_blank' ,
3842 lucideIcon : ExternalLink ,
3943 } ,
4044 {
45+ key : 'resources-primevue' ,
4146 label : 'PrimeVue Docs' ,
4247 url : 'https://primevue.org/' ,
4348 target : '_blank' ,
4449 lucideIcon : ExternalLink ,
4550 } ,
4651 {
52+ key : 'resources-starter-docs' ,
4753 label : 'Starter Kit Docs' ,
4854 url : 'https://connorabbas.github.io/laravel-primevue-starter-kit-docs/' ,
4955 target : '_blank' ,
5056 lucideIcon : FileSearch ,
5157 } ,
5258 {
59+ key : 'resources-starter-repo' ,
5360 label : 'Starter Kit Repo' ,
5461 url : 'https://github.com/connorabbas/laravel-primevue-starter-kit' ,
5562 target : '_blank' ,
@@ -59,7 +66,28 @@ export function useAppLayout() {
5966 } ,
6067 ] )
6168
62- // User menu and logout functionality.
69+ // Check/set expanded PanelMenu items based on active status, for non-persistent layouts
70+ const expandedKeys = ref < Record < string , boolean > > ( { } )
71+ const updateExpandedKeys = ( ) => {
72+ const keys : Record < string , boolean > = { }
73+ const hasActiveChild = ( item : MenuItem ) : boolean => {
74+ if ( item . items ) {
75+ for ( const child of item . items ) {
76+ if ( hasActiveChild ( child ) ) {
77+ if ( item . key ) keys [ item . key ] = true
78+ return true
79+ }
80+ }
81+ }
82+ return ! ! item . active
83+ }
84+ menuItems . value . forEach ( hasActiveChild )
85+ expandedKeys . value = keys
86+ }
87+ watch ( currentRoute , ( ) => {
88+ updateExpandedKeys ( )
89+ } , { immediate : true } )
90+
6391 const logoutForm = useForm ( { } )
6492 const logout = ( ) => {
6593 logoutForm . post ( route ( 'logout' ) )
@@ -80,7 +108,7 @@ export function useAppLayout() {
80108 } ,
81109 ]
82110
83- // Mobile menu
111+ // Mobile drawer menu
84112 const mobileMenuOpen = ref ( false )
85113 if ( typeof window !== 'undefined' ) {
86114 const windowWidth = ref ( window . innerWidth )
@@ -93,8 +121,8 @@ export function useAppLayout() {
93121 onUnmounted ( ( ) => {
94122 window . removeEventListener ( 'resize' , updateWidth )
95123 } )
96- watchEffect ( ( ) => {
97- if ( windowWidth . value > 1024 ) {
124+ watch ( windowWidth , ( newWidth ) => {
125+ if ( newWidth > 1024 ) {
98126 mobileMenuOpen . value = false
99127 }
100128 } )
@@ -103,6 +131,7 @@ export function useAppLayout() {
103131 return {
104132 currentRoute,
105133 menuItems,
134+ expandedKeys,
106135 userMenuItems,
107136 mobileMenuOpen,
108137 logout,
0 commit comments