Added theme swapping.
This commit is contained in:
parent
c3974fe5ea
commit
0dd7ce50d2
|
@ -33,6 +33,9 @@ import ExpandLess from '@material-ui/icons/ExpandLess';
|
||||||
import ExpandMore from '@material-ui/icons/ExpandMore';
|
import ExpandMore from '@material-ui/icons/ExpandMore';
|
||||||
import Collapse from '@material-ui/core/Collapse';
|
import Collapse from '@material-ui/core/Collapse';
|
||||||
import FlameLinkCollectionGallery from '../components/FlameLinkCollectionGallery';
|
import FlameLinkCollectionGallery from '../components/FlameLinkCollectionGallery';
|
||||||
|
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
|
||||||
|
import Switch from '@material-ui/core/Switch';
|
||||||
|
import indigo from '@material-ui/core/colors/indigo';
|
||||||
|
|
||||||
const drawerWidth = 240;
|
const drawerWidth = 240;
|
||||||
|
|
||||||
|
@ -77,6 +80,17 @@ class ResponsiveDrawer extends React.Component {
|
||||||
key: 'Home',
|
key: 'Home',
|
||||||
open: false,
|
open: false,
|
||||||
open2: false,
|
open2: false,
|
||||||
|
theme: createMuiTheme({
|
||||||
|
typography: {
|
||||||
|
useNextVariants: true,
|
||||||
|
},
|
||||||
|
palette: {
|
||||||
|
primary: indigo,
|
||||||
|
secondary: indigo
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
themeName: 'light',
|
||||||
|
themeChecked: true
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDrawerToggle = () => {
|
handleDrawerToggle = () => {
|
||||||
|
@ -97,8 +111,38 @@ class ResponsiveDrawer extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChange = name => event => {
|
||||||
|
this.setState({ [name]: event.target.checked });
|
||||||
|
if (this.state.themeName === 'light') {
|
||||||
|
this.setState({
|
||||||
|
themeName: 'dark',
|
||||||
|
theme: createMuiTheme({
|
||||||
|
typography: {
|
||||||
|
useNextVariants: true,
|
||||||
|
},
|
||||||
|
palette: {
|
||||||
|
type: 'dark'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
themeName: 'light',
|
||||||
|
theme: createMuiTheme({
|
||||||
|
typography: {
|
||||||
|
useNextVariants: true,
|
||||||
|
},
|
||||||
|
palette: {
|
||||||
|
primary: indigo,
|
||||||
|
secondary: indigo
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes, theme } = this.props;
|
const { classes } = this.props;
|
||||||
|
|
||||||
const drawer = (
|
const drawer = (
|
||||||
<div>
|
<div>
|
||||||
|
@ -178,9 +222,10 @@ class ResponsiveDrawer extends React.Component {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<MuiThemeProvider theme={this.state.theme}>
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<AppBar position="fixed" className={classes.appBar}>
|
<AppBar position="fixed" color="primary" className={classes.appBar}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
|
@ -193,6 +238,12 @@ class ResponsiveDrawer extends React.Component {
|
||||||
<Typography variant="title" color="inherit" noWrap>
|
<Typography variant="title" color="inherit" noWrap>
|
||||||
Marten Tracker
|
Marten Tracker
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Switch
|
||||||
|
checked={this.state.themeChecked}
|
||||||
|
onChange={this.handleChange('themeChecked')}
|
||||||
|
value="themeChecked"
|
||||||
|
color="default"
|
||||||
|
/>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
<nav className={classes.drawer}>
|
<nav className={classes.drawer}>
|
||||||
|
@ -200,7 +251,7 @@ class ResponsiveDrawer extends React.Component {
|
||||||
<Drawer
|
<Drawer
|
||||||
container={this.props.container}
|
container={this.props.container}
|
||||||
variant="temporary"
|
variant="temporary"
|
||||||
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
|
anchor={this.state.theme.direction === 'rtl' ? 'right' : 'left'}
|
||||||
open={this.state.mobileOpen}
|
open={this.state.mobileOpen}
|
||||||
onClose={this.handleDrawerToggle}
|
onClose={this.handleDrawerToggle}
|
||||||
classes={{
|
classes={{
|
||||||
|
@ -230,7 +281,7 @@ class ResponsiveDrawer extends React.Component {
|
||||||
{this.state.key === 'Home' && <Home />}
|
{this.state.key === 'Home' && <Home />}
|
||||||
{this.state.key === 'Report' && <Report />}
|
{this.state.key === 'Report' && <Report />}
|
||||||
{this.state.key === 'Map' && <ViewMap />}
|
{this.state.key === 'Map' && <ViewMap />}
|
||||||
{this.state.key === 'List' && <SightingList />}
|
{this.state.key === 'List' && <SightingList key={this.state.themeName} />}
|
||||||
{this.state.key === 'About' && <About />}
|
{this.state.key === 'About' && <About />}
|
||||||
{this.state.key === 'Contact' && <Contact />}
|
{this.state.key === 'Contact' && <Contact />}
|
||||||
{this.state.key === 'Easy-Quiz' && <Quiz difficulty='Easy' />}
|
{this.state.key === 'Easy-Quiz' && <Quiz difficulty='Easy' />}
|
||||||
|
@ -242,6 +293,7 @@ class ResponsiveDrawer extends React.Component {
|
||||||
{this.state.key === 'Gallery4' && <FlameLinkCollectionGallery galleryName={'similarSpecies'} />}
|
{this.state.key === 'Gallery4' && <FlameLinkCollectionGallery galleryName={'similarSpecies'} />}
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
</MuiThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue