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": {
"react-start": "node scripts/start.js",
"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",
"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\""

View File

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

View File

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

View File

@ -29,6 +29,7 @@ app-root {
flex-direction: row;
flex-grow: 1;
overflow-x: hidden;
margin-top: 0;
.main {
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
// the `inherit` value on things like `<th>` elements.
body {
.dark-theme {
margin: 0; // 1
font-family: $font-family-base;
font-size: $font-size-base;

View File

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

View File

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

View File

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