Skip to content

Commit

Permalink
Merge pull request #4038 from marmelab/fix-sidebar-classesoverride
Browse files Browse the repository at this point in the history
Fix sidebar classes can't be overridden
  • Loading branch information
djhi authored Nov 25, 2019
2 parents e7aed21 + 42dc8c3 commit 43d60c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
24 changes: 23 additions & 1 deletion docs/Theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ const MyAppBar = props => <AppBar {...props} userMenu={MyUserMenu} />;

### 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';
Expand All @@ -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 (
<Sidebar classes={classes} {...props} />
);
};

const MyLayout = props => <Layout {...props} sidebar={MySidebar} />
```

### 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):
Expand Down
10 changes: 8 additions & 2 deletions packages/ra-ui-materialui/src/layout/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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 ? (
<Drawer
Expand Down

0 comments on commit 43d60c7

Please sign in to comment.