add base theme switcher that uses the component state

This commit is contained in:
Jonathan Rainville 2018-10-15 16:13:33 -04:00 committed by Pascal Precht
parent 21cd0a71e4
commit 7c910a571d
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
8 changed files with 102 additions and 81 deletions

View File

@ -76,7 +76,7 @@
"scripts": { "scripts": {
"react-start": "node scripts/start.js", "react-start": "node scripts/start.js",
"start": "npm-run-all --parallel css-compile react-start watch-css", "start": "npm-run-all --parallel css-compile react-start watch-css",
"build": "node scripts/build.js", "build": "npm run css-compile && node scripts/build.js",
"test": "node scripts/test.js --env=jsdom", "test": "node scripts/test.js --env=jsdom",
"css-compile": "node-sass --output-style expanded --source-map true --source-map-contents true --precision 6 src/dark-theme/coreui.scss src/css/coreui.css", "css-compile": "node-sass --output-style expanded --source-map true --source-map-contents true --precision 6 src/dark-theme/coreui.scss src/css/coreui.css",
"watch-css": "nodemon --ignore dist/ -e scss -x \"npm run css-compile\"" "watch-css": "nodemon --ignore dist/ -e scss -x \"npm run css-compile\""

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { DropdownItem, DropdownMenu, DropdownToggle, Nav, Container } from 'reactstrap'; import { UncontrolledDropdown, DropdownItem, DropdownMenu, DropdownToggle, Nav, Container } from 'reactstrap';
import { import {
AppAside, AppAside,
@ -38,7 +38,7 @@ const sidebarNavItems = {items: [
]}, ]},
]}; ]};
const Layout = ({children, logout, credentials, location}) => ( const Layout = ({children, logout, credentials, location, changeTheme}) => (
<div className="app"> <div className="app">
<AppHeader fixed> <AppHeader fixed>
<AppSidebarToggler className="d-lg-none" display="md" mobile /> <AppSidebarToggler className="d-lg-none" display="md" mobile />
@ -75,6 +75,16 @@ const Layout = ({children, logout, credentials, location}) => (
</AppAside> </AppAside>
</div> </div>
<AppFooter> <AppFooter>
<UncontrolledDropdown direction="up">
<DropdownToggle caret>
Theme
</DropdownToggle>
<DropdownMenu>
<DropdownItem onClick={() => changeTheme('dark')}>Dark</DropdownItem>
<DropdownItem onClick={() => changeTheme('light')}>Light</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
<span className="ml-auto"> <span className="ml-auto">
Embark&nbsp; Embark&nbsp;
<a href="https://embark.status.im" title="Documentation" rel="noopener noreferrer" target="_blank">Documentation</a> <a href="https://embark.status.im" title="Documentation" rel="noopener noreferrer" target="_blank">Documentation</a>
@ -89,7 +99,9 @@ Layout.propTypes = {
children: PropTypes.element, children: PropTypes.element,
tabs: PropTypes.arrayOf(PropTypes.object), tabs: PropTypes.arrayOf(PropTypes.object),
credentials: PropTypes.object, credentials: PropTypes.object,
logout: PropTypes.func location: PropTypes.object,
logout: PropTypes.func,
changeTheme: PropTypes.func
}; };
export default Layout; export default Layout;

View File

@ -22,6 +22,10 @@ class AppContainer extends Component {
super(props); super(props);
this.queryStringAuthenticate(); this.queryStringAuthenticate();
this.state = {
theme: 'dark'
};
} }
queryStringAuthenticate() { queryStringAuthenticate() {
@ -59,18 +63,22 @@ class AppContainer extends Component {
return this.props.authenticationError || !this.props.credentials.authenticated; return this.props.authenticationError || !this.props.credentials.authenticated;
} }
changeTheme(theme) {
this.setState({theme});
}
render() { render() {
return ( return (
<React.Fragment> <div className={this.state.theme + "-theme"}>
{this.shouldRenderLogin() ? {this.shouldRenderLogin() ?
<Login credentials={this.props.credentials} authenticate={this.props.authenticate} error={this.props.authenticationError} /> <Login credentials={this.props.credentials} authenticate={this.props.authenticate} error={this.props.authenticationError} />
: :
<Layout location={this.props.location} logout={this.props.logout} credentials={this.props.credentials}> <Layout location={this.props.location} logout={this.props.logout} credentials={this.props.credentials} changeTheme={(v) => this.changeTheme(v)}>
<React.Fragment>{routes}</React.Fragment> <React.Fragment>{routes}</React.Fragment>
</Layout> </Layout>
} }
</React.Fragment> </div>
) );
} }
} }

View File

@ -29,6 +29,7 @@ app-root {
flex-direction: row; flex-direction: row;
flex-grow: 1; flex-grow: 1;
overflow-x: hidden; overflow-x: hidden;
margin-top: 0;
.main { .main {
flex: 1; flex: 1;

View File

@ -54,7 +54,7 @@ article, aside, figcaption, figure, footer, header, hgroup, main, nav, section {
// 3. Set an explicit initial text-align value so that we can later use the // 3. Set an explicit initial text-align value so that we can later use the
// the `inherit` value on things like `<th>` elements. // the `inherit` value on things like `<th>` elements.
body { .dark-theme {
margin: 0; // 1 margin: 0; // 1
font-family: $font-family-base; font-family: $font-family-base;
font-size: $font-size-base; font-size: $font-size-base;

View File

@ -10,33 +10,36 @@
@import "mixins"; @import "mixins";
@import "root"; @import "root";
@import "reboot"; @import "reboot";
@import "type";
@import "images"; .dark-theme {
@import "code"; @import "type";
@import "grid"; @import "images";
@import "tables"; @import "code";
@import "forms"; @import "grid";
@import "buttons"; @import "tables";
@import "transitions"; @import "forms";
@import "dropdown"; @import "buttons";
@import "button-group"; @import "transitions";
@import "input-group"; @import "dropdown";
@import "custom-forms"; @import "button-group";
@import "nav"; @import "input-group";
@import "navbar"; @import "custom-forms";
@import "card"; @import "nav";
@import "breadcrumb"; @import "navbar";
@import "pagination"; @import "card";
@import "badge"; @import "breadcrumb";
@import "jumbotron"; @import "pagination";
@import "alert"; @import "badge";
@import "progress"; @import "jumbotron";
@import "media"; @import "alert";
@import "list-group"; @import "progress";
@import "close"; @import "media";
@import "modal"; @import "list-group";
@import "tooltip"; @import "close";
@import "popover"; @import "modal";
@import "carousel"; @import "tooltip";
@import "utilities"; @import "popover";
@import "print"; @import "carousel";
@import "utilities";
@import "print";
}

View File

@ -5,60 +5,57 @@
* Copyright (c) 2018 creativeLabs Łukasz Holeczek * Copyright (c) 2018 creativeLabs Łukasz Holeczek
* Licensed under MIT (https://coreui.io/license) * Licensed under MIT (https://coreui.io/license)
*/ */
// Override Boostrap variables // Override Boostrap variables
@import "variables"; @import "variables";
// Import Bootstrap source files // Import Bootstrap source files
@import "./bootstrap.scss"; @import "./bootstrap.scss";
// Mixins // Mixins
@import "mixins"; @import "mixins";
// Animations // Animations
@import "animate"; @import "animate";
// Vendors // Vendors
@import "vendors"; @import "vendors";
// Components .dark-theme {
@import "aside"; // Components
@import "avatars"; @import "aside";
@import "badge"; @import "avatars";
@import "breadcrumb-menu"; @import "badge";
@import "breadcrumb"; @import "breadcrumb-menu";
@import "brand-card"; @import "breadcrumb";
@import "brand-buttons"; @import "brand-card";
@import "buttons"; @import "brand-buttons";
@import "callout"; @import "buttons";
@import "card"; @import "callout";
@import "charts"; @import "card";
@import "dropdown"; @import "charts";
@import "footer"; @import "dropdown";
@import "grid"; @import "footer";
@import "header"; @import "grid";
@import "input-group"; @import "header";
@import "images"; @import "input-group";
@import "list-group"; @import "images";
@import "modal"; @import "list-group";
@import "nav"; @import "modal";
@import "progress"; @import "nav";
@import "progress-group"; @import "progress";
@import "sidebar"; @import "progress-group";
@import "switches"; @import "sidebar";
@import "tables"; @import "switches";
@import "widgets"; @import "tables";
@import "widgets";
// Layout Options // Layout Options
@import "layout"; @import "layout";
@import "others"; @import "others";
// Utility classes // Utility classes
@import "utilities"; @import "utilities";
// Right-to-left // Right-to-left
@import "rtl"; @import "rtl";
// Custom Properties support for Internet Explorer // Custom Properties support for Internet Explorer
@import "ie-custom-properties"; @import "ie-custom-properties";
}

View File

@ -4,8 +4,8 @@ import ReactDOM from 'react-dom';
import {Provider} from 'react-redux'; import {Provider} from 'react-redux';
import 'font-awesome/css/font-awesome.min.css'; import 'font-awesome/css/font-awesome.min.css';
import '@coreui/coreui/dist/css/coreui.min.css';
import './css/coreui.css'; import './css/coreui.css';
// import '@coreui/coreui/dist/css/coreui.min.css';
import './index.css'; import './index.css';
import AppContainer from './containers/AppContainer'; import AppContainer from './containers/AppContainer';