Menu Item Styles
The menuItemStyles
prop allows you to customize the style of the menu items.
Propsโ
type MenuItemStyles = {
root?: ElementStyles;
button?: ElementStyles;
label?: ElementStyles;
prefix?: ElementStyles;
suffix?: ElementStyles;
icon?: ElementStyles;
subMenuContent?: ElementStyles;
subMenuExpandIcon?: ElementStyles;
};
type ElementStyles =
| CSSObject
| ((params: MenuItemStylesParams) => CSSObject | undefined);
type MenuItemStylesParams = {
level: number;
disabled: boolean;
active?: boolean;
isSubmenu: boolean;
open?: boolean;
};
The MenuItemStyles
object allows you to customize the style of various elements within the menu item. Each property corresponds to a specific element and accepts a CSSObject
that contains the styles.
Property | Description |
---|---|
root | The root element of all the menu-items and submenus. |
button | The button element of all the menu-items and submenus. |
label | The label element of all the menu-items and submenus. |
prefix | The prefix element of all the menu-items and submenus. |
suffix | The suffix element of all the menu-items and submenus. |
icon | The icon element of all the menu-items and submenus. |
subMenuContent | The content of sub menu element of all the submenus. |
subMenuExpandIcon | The expand icon of sub menu element of all the submenus. |
The MenuItemStylesParams
object contains the following properties:
Property | Description |
---|---|
level | The depth level of the menu item. |
disabled | Whether the menu item is disabled. |
active | Whether the menu item is active. |
isSubmenu | Whether the menu item is a submenu. |
open | Whether the submenu associated with the menu item is open or closed. |
You can customize these styles by providing a CSSObject
with appropriate style properties.
With Parameterโ
The menuItemStyles
prop takes a MenuItemStylesParams
object as a parameter. This allows you to apply styles based on different conditions.
By using the MenuItemStylesParams object, you can dynamically apply styles based on the provided parameters.
Exampleโ
Source Codeโ
'use client'
// Component Imports
import VerticalNav, { Menu, MenuItem, MenuSection, SubMenu } from '@menu/vertical-menu'
const MenuItemStylesWithParams = () => {
return (
<VerticalNav customBreakpoint='200px'>
<Menu
menuItemStyles={{
button: ({ disabled, open, isSubmenu, level }) => ({
...(level === 1 && { paddingInlineStart: '20px' }),
paddingBlock: '12px',
fontWeight: open ? 500 : 400,
color: disabled ? '#a19e9e' : '#000000',
backgroundColor: isSubmenu ? '#fef0ff' : '#ecfcff'
})
}}
>
<MenuSection label='Dashboards & Apps'>
<SubMenu icon={<>๐ฅ</>} label='Dashboards'>
<MenuItem>Analytics</MenuItem>
<MenuItem disabled>eCommerce</MenuItem>
</SubMenu>
<MenuItem icon={<>๐ฅ</>}>Calendar</MenuItem>
</MenuSection>
<MenuSection label='Others'>
<MenuItem icon={<>๐ฅ</>}>FAQ</MenuItem>
<SubMenu icon={<>๐ฅ</>} 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>
<MenuItem icon={<>๐ฅ</>}>Documentation</MenuItem>
</MenuSection>
</Menu>
</VerticalNav>
)
}
export default MenuItemStylesWithParams
Without Parameterโ
The menuItemStyles
prop directly returns a CSSObject
without any parameters.
Exampleโ
Source Codeโ
'use client'
// Component Imports
import VerticalNav, { Menu, MenuItem, MenuSection, SubMenu } from '@menu/vertical-menu'
const MenuItemStylesWithOutParams = () => {
return (
<VerticalNav customBreakpoint='200px'>
<Menu
menuItemStyles={{
button: {
color: '#7367F0',
backgroundColor: '#FFF5FF',
fontSize: '1rem',
paddingBlock: '12px',
fontWeight: 500
}
}}
>
<MenuSection label='Dashboards & Apps'>
<SubMenu icon={<>๐ฅ</>} label='Dashboards'>
<MenuItem>Analytics</MenuItem>
<MenuItem>eCommerce</MenuItem>
</SubMenu>
<MenuItem icon={<>๐ฅ</>}>Calendar</MenuItem>
</MenuSection>
<MenuSection label='Others'>
<MenuItem icon={<>๐ฅ</>}>FAQ</MenuItem>
<SubMenu icon={<>๐ฅ</>} 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>
<MenuItem icon={<>๐ฅ</>}>Documentation</MenuItem>
</MenuSection>
</Menu>
</VerticalNav>
)
}
export default MenuItemStylesWithOutParams