I did it, I did this.
Interface and Navigation Modifications
Step 1: Modification of the NavItem Interface
Modified file: c:\sistemas\aseosoft\resources\js\types\index.ts
Added the property children?: NavItem[] to the NavItem interface.
This allows each navigation item to have child elements (submenus).
Step 2: Creation of the SidebarSubMenu Component
Created file: c:\sistemas\aseosoft\resources\js\components\ui\sidebar\SidebarSubMenu.vue
Created this new component to display submenu items. The component has an indented style and a vertical line on the left to indicate hierarchy.
Added Code:
<script setup lang="ts">
import { cn } from '@/lib/utils';
defineProps<{ className?: string }>();
</script>
<template>
<div :class="cn('ml-4 pl-4 border-l space-y-1', className)">
<slot />
</div>
</template>
Step 3: Update of the Component Export File
Modified file: c:\sistemas\aseosoft\resources\js\components\ui\sidebar\index.ts
Added the export of the new SidebarSubMenu component so it can be imported from other files.
Added Line:
export { default as SidebarSubMenu } from './SidebarSubMenu.vue';
Step 4: Modification of the NavMain Component
Modified file: c:\sistemas\aseosoft\resources\js\components\NavMain.vue
Changes Made:
- Imported the
SidebarSubMenucomponent and theChevronDownicon. - Created a reactive state
openSubMenusto control which submenus are open. - Implemented
toggleSubMenufunction to show/hide submenus. - Implemented
isCurrentRoutefunction to detect active routes, including nested ones. - Added conditional logic in the template to display regular items or items with submenus.
- Added animation for the arrow icon when opening/closing a submenu.
Step 5: Update of the AppSidebar Component
Modified file: c:\sistemas\aseosoft\resources\js\components\AppSidebar.vue
Changes Made:
- Added new icons:
UserPlusandUserCogfor submenu items. - Modified the "Users" navigation item to include child elements.
Added Code:
{
title: 'Users',
href: route('users.index'),
icon: Users,
children: [
{
title: 'User List',
href: route('users.index'),
icon: Users,
},
{
title: 'Create User',
href: route('users.create'),
icon: UserPlus,
},
{
title: 'Roles and Permissions',
href: '/users/roles',
icon: UserCog,
},
],
}