forked from gregnb/mui-datatables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react';
import ReactDOM from 'react-dom';
import {HashRouter as Router, Route, Switch} from 'react-router-dom';
import {withStyles} from "@material-ui/core/styles/index";
import ExamplesGrid from "./ExamplesGrid";
import examples from "../examples";
import Button from "@material-ui/core/Button";
import {withRouter} from 'react-router-dom';
const styles = {
root: {
display: 'flex',
justifyContent: 'center',
},
contentWrapper: {
width: '100%',
},
};
class Examples extends React.Component {
returnHome = () => {
this.props.history.push('/');
};
render() {
const {classes} = this.props;
var returnHomeStyle = {padding:'0px', margin:'20px 0 20px 0'};
return <main className={classes.root}>
<div className={classes.contentWrapper}>
<Switch>
<Route path="/" exact render={() => <ExamplesGrid examples={examples}/>}/>
{Object.keys(examples).map((label, index) => (
<Route key={index} path={`/${label.replace(/\s+/g, '-').toLowerCase()}`} exact component={examples[label]}/>
))}
</Switch>
<div>
{this.props.location.pathname !== '/' && (
<div style={returnHomeStyle}>
<Button color="primary" onClick={this.returnHome}>Back to Example Index</Button>
</div>
)}
</div>
</div>
</main>;
}
}
const StyledExamples = withRouter( withStyles(styles)(Examples) );
function App() {
return (
<Router hashType="noslash">
<StyledExamples />
</Router>
);
}
ReactDOM.render(<App/>, document.getElementById('app-root'));