diff --git a/docs/Theming.md b/docs/Theming.md index 1883f4e8856..4613a231611 100644 --- a/docs/Theming.md +++ b/docs/Theming.md @@ -471,7 +471,7 @@ const MyAppBar = props => ; ### Sidebar Customization -You can specify the `Sidebar` width by setting the `width` and `closedWidth` property on your custom material-ui them: +You can specify the `Sidebar` width by setting the `width` and `closedWidth` property on your custom material-ui theme: ```jsx import { createMuiTheme } from '@material-ui/core/styles'; @@ -490,6 +490,28 @@ const App = () => ( ); ``` +For more advanced sidebar theming, pass your own `Sidebar` component to a custom `Layout`: + +```jsx +import { Sidebar, Layout } from 'react-admin'; +import { makeStyles } from '@material-ui/core/styles'; + +const useSidebarStyles = makeStyles({ + drawerPaper: { + backgroundColor: 'red', + }, +}); + +const MySidebar = props => { + const classes = useSidebarStyles(); + return ( + + ); +}; + +const MyLayout = props => +``` + ### Layout From Scratch For more custom layouts, write a component from scratch. It must contain a `{children}` placeholder, where react-admin will render the resources. Use the [default layout](https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/layout/Layout.js) as a starting point. Here is a simplified version (with no responsive support): diff --git a/packages/ra-ui-materialui/src/layout/Sidebar.js b/packages/ra-ui-materialui/src/layout/Sidebar.js index 7a4fbacf08d..39f8ac11554 100644 --- a/packages/ra-ui-materialui/src/layout/Sidebar.js +++ b/packages/ra-ui-materialui/src/layout/Sidebar.js @@ -37,7 +37,13 @@ const useStyles = makeStyles(theme => ({ }, })); -const Sidebar = ({ children, closedSize, size, ...rest }) => { +const Sidebar = ({ + children, + closedSize, + size, + classes: classesOverride, + ...rest +}) => { const dispatch = useDispatch(); const isXSmall = useMediaQuery(theme => theme.breakpoints.down('xs')); const isSmall = useMediaQuery(theme => theme.breakpoints.down('sm')); @@ -54,7 +60,7 @@ const Sidebar = ({ children, closedSize, size, ...rest }) => { useSelector(state => state.locale); // force redraw on locale change const handleClose = () => dispatch(setSidebarVisibility(false)); const toggleSidebar = () => dispatch(setSidebarVisibility(!open)); - const classes = useStyles({ open }); + const classes = useStyles({ classes: classesOverride, open }); return isXSmall ? (