File size: 2,038 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import { createRoot } from 'react-dom/client';
import { HashRouter as Router, Route, Switch, withRouter } from 'react-router-dom';
import { withStyles } from 'tss-react/mui';
import ExamplesGrid from './ExamplesGrid';
import examples from '../examples';
import Button from '@mui/material/Button';
import { createTheme, ThemeProvider } from '@mui/material/styles';

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' };

    const defaultTheme = createTheme();

    return (
      <ThemeProvider theme={defaultTheme}>
        <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>
      </ThemeProvider>
    );
  }
}

const StyledExamples = withRouter(withStyles(Examples, styles));

function App() {
  return (
    <Router hashType="noslash">
      <StyledExamples />
    </Router>
  );
}
const container = document.getElementById('app-root');
const root = createRoot(container);
root.render(<App />);