Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sidebar classes can't be overridden #4038

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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