react-pro-sidebar provides two complementary styling primitives for theming:
rootStyles: An Emotion CSSObject applied to each component's root element. Use this for high-level styling or to target inner nodes by combining it with the exported sidebarClasses or menuClasses registries.menuItemStyles (on Menu): A structured slot system for theming MenuItem, SubMenu, and their children.
Available slots for menuItemStyles include:
rootbuttonlabeliconprefixsuffixsubMenuContentSubMenuExpandIcon
Each slot accepts a CSSObject or a function that receives the item's state: { level, active, disabled, isSubmenu, open }.
import { Sidebar, Menu, MenuItem, SubMenu, menuClasses, type MenuItemStyles } from 'react-pro-sidebar';
const themes = {
light: { bg: '#ffffff', text: '#0d3b66', icon: '#0098e5', hoverBg: '#cfe7ff', hoverText: '#0d3b66' },
dark: { bg: '#0b2948', text: '#cbd5e1', icon: '#59d0ff', hoverBg: '#00458b', hoverText: '#fff' },
brand: { bg: '#1b1035', text: '#e9e1ff', icon: '#c084fc', hoverBg: '#4c1d95', hoverText: '#fff' },
};
export default function ThemedSidebar({ theme = 'light' }) {
const t = themes[theme];
const menuItemStyles: MenuItemStyles = {
button: {
color: t.text,
[`&.${menuClasses.active}`]: {
color: t.hoverText,
backgroundColor: t.hoverBg,
},
'&:hover': {
backgroundColor: t.hoverBg,
color: t.hoverText,
},
},
icon: { color: t.icon },
};
return (
<Sidebar
backgroundColor={t.bg}
rootStyles={{ color: t.text, border: 'none' }}
>
<Menu menuItemStyles={menuItemStyles}>
<MenuItem active>Dashboard</MenuItem>
<SubMenu label="Charts">
<MenuItem>Pie</MenuItem>
<MenuItem>Line</MenuItem>
</SubMenu>
</Menu>
</Sidebar>
);
}