Last active
May 13, 2018 18:36
-
-
Save gladchinda/d713a57766553bdd8d5d220bd9b193f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class ThemeSwitcher extends Component { | |
state = { theme: null } | |
resetTheme = evt => { | |
evt.preventDefault(); | |
this.setState({ theme: null }); | |
} | |
chooseTheme = (theme, evt) => { | |
evt.preventDefault(); | |
this.setState({ theme }); | |
} | |
render() { | |
const { theme } = this.state; | |
const themeClass = theme ? theme.toLowerCase() : 'secondary'; | |
return ( | |
<div className="d-flex flex-wrap justify-content-center position-absolute w-100 h-100 align-items-center align-content-center"> | |
<span className={`h1 mb-4 w-100 text-center text-${themeClass}`}>{ theme || 'Default' }</span> | |
<div className="btn-group"> | |
<button type="button" className={`btn btn-${themeClass} btn-lg`}>{ theme || 'Choose' } Theme</button> | |
<button type="button" className={`btn btn-${themeClass} btn-lg dropdown-toggle dropdown-toggle-split`} data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
<span className="sr-only">Toggle Theme Dropdown</span> | |
</button> | |
<div className="dropdown-menu"> | |
<a className="dropdown-item" href="#" onClick={e => this.chooseTheme('Primary', e)}>Primary Theme</a> | |
<a className="dropdown-item" href="#" onClick={e => this.chooseTheme('Danger', e)}>Danger Theme</a> | |
<a class="dropdown-item" href="#" onClick={e => this.chooseTheme('Success', e)}>Success Theme</a> | |
<div className="dropdown-divider"></div> | |
<a className="dropdown-item" href="#" onClick={this.resetTheme}>Default Theme</a> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default ThemeSwitcher; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment