Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active May 13, 2018 18:36
Show Gist options
  • Save gladchinda/d713a57766553bdd8d5d220bd9b193f5 to your computer and use it in GitHub Desktop.
Save gladchinda/d713a57766553bdd8d5d220bd9b193f5 to your computer and use it in GitHub Desktop.
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