Skip to content

Instantly share code, notes, and snippets.

@stevemu
Last active May 4, 2019 21:34
Show Gist options
  • Save stevemu/e0c5922cafe7e3cadc769b6d5cae2604 to your computer and use it in GitHub Desktop.
Save stevemu/e0c5922cafe7e3cadc769b6d5cae2604 to your computer and use it in GitHub Desktop.
a master-detail view for react
import React from 'react';
import {withStyles} from '@material-ui/core/styles';
import withResizeAware from '../../../core/withResizeAware';
const styles = {
root: {
flex: 1,
padding: 10
},
container: {
display: "grid",
gridTemplateColumns: "1fr",
overflow: "hidden",
},
left: {
overflow: "scroll",
marginRight: 5,
paddingBottom: 150
},
right: {
// overflow: "scroll",
}
};
class MasterDetail extends React.Component {
render() {
const {classes} = this.props;
let containerHeight = this.props.height - 120;
return (
<div className={classes.root}>
<div className={classes.container} style={{
height: containerHeight,
gridTemplateColumns: this.props.width >= 600 ? "200px 1fr" : "1fr",
}}>
<div className={classes.left}>
{this.props.master()}
</div>
{
this.props.width >= 600 &&
<div className={classes.right}>
{this.props.detail()}
</div>
}
</div>
</div>
)
}
}
export default withResizeAware(withStyles(styles)(MasterDetail));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment