Nav Collpase Icons
Props with types
Props | Type | Description | Default |
---|---|---|---|
closeIcon | ReactElement | Close icon when breakpoint is reached | - |
lockedIcon | ReactElement | Locked icon when menu is expanded and locked | - |
unlockedIcon | ReactElement | Unlocked icon when menu is collapsed and unlocked/hovered | - |
onClick | () => void | Callback invoked when the collapse icon is clicked | - |
onClose | () => void | Callback invoked when the close icon is clicked | - |
/vertical-menu/nav-collapse-icons
Source Code
warning
The onClick={() => console.log('clicked')}
prop written below in the NavCollapseIcons
component is for demo purposes only. You should write the following instead in order to update the layout according to the collapsed state.
+ import useVerticalNav from '@menu/hooks/useVerticalNav'
+ import { useSettings } from '@core/hooks/useSettings'
+ const { isCollapsed } = useVerticalNav()
+ const { updateSettings } = useSettings()
- <NavCollapseIcons onClick={() => console.log('clicked')} />
+ <NavCollapseIcons onClick={() => updateSettings({ layout: !isCollapsed ? 'collapsed' : 'vertical' })} />
'use client'
// Component Imports
import NavHeader from '@menu/components/vertical-menu/NavHeader'
import NavCollapseIcons from '@menu/components/vertical-menu/NavCollapseIcons'
import NavToggle from '@components/layout/vertical/NavToggle'
import VerticalNav, { Menu, MenuItem, SubMenu } from '@menu/vertical-menu'
// Hook
import useHorizontalNav from '@menu/hooks/useHorizontalNav'
const NavCollapseIcon = () => {
const { isBreakpointReached } = useHorizontalNav()
return (
<div className='flex'>
<VerticalNav customBreakpoint='1100px'>
<NavHeader>
{!isBreakpointReached && 'Logo'}
<NavCollapseIcons
unlockedIcon={<>{'>'}</>}
lockedIcon={<>{'<'}</>}
closeIcon={<>X</>}
onClick={() => console.log('clicked')}
onClose={() => console.log('closed')}
/>
</NavHeader>
<Menu>
<SubMenu label='Dashboards'>
<MenuItem>Analytics</MenuItem>
<MenuItem>eCommerce</MenuItem>
</SubMenu>
<SubMenu label='User'>
<MenuItem>List</MenuItem>
<SubMenu label='View'>
<MenuItem>Overview</MenuItem>
<MenuItem>Security</MenuItem>
<MenuItem>Notifications</MenuItem>
</SubMenu>
</SubMenu>
<SubMenu label='Menu Level'>
<MenuItem>Menu Level 2.1</MenuItem>
<SubMenu label='Menu Level 2.2'>
<MenuItem>Menu Level 3.1</MenuItem>
<MenuItem>Menu Level 3.2</MenuItem>
</SubMenu>
</SubMenu>
</Menu>
</VerticalNav>
<main className='p-4 flex-grow'>
<NavToggle />
</main>
</div>
)
}
export default NavCollapseIcon