chore: additional theming implementation

This commit is contained in:
Kyle Gill
2019-03-27 22:30:07 -06:00
parent 49bb678bfa
commit b2ad7d544d
7 changed files with 79 additions and 56 deletions

View File

@@ -1,25 +0,0 @@
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}
.App-header {
background-color: #282c34;
min-height: 10vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@@ -3,7 +3,6 @@ import { BrowserRouter as Router, Route } from "react-router-dom";
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { ThemeProvider } from "emotion-theming"; import { ThemeProvider } from "emotion-theming";
import "./App.css";
import theme from "./styles/theme"; import theme from "./styles/theme";
import Navbar from "./components/Navbar"; import Navbar from "./components/Navbar";
import Day from "./components/screens/Day"; import Day from "./components/screens/Day";
@@ -18,6 +17,8 @@ import { withAuthentication } from "./components/session";
const RouteLayout = styled.div` const RouteLayout = styled.div`
margin: 0 auto; margin: 0 auto;
max-width: 720px; max-width: 720px;
min-height: calc(100vh - 60px);
background-color: ${props => props.theme.colors.bodyBackground};
`; `;
class App extends Component { class App extends Component {
@@ -26,6 +27,20 @@ class App extends Component {
selectedTheme: "LIGHT" selectedTheme: "LIGHT"
}; };
onChangeTheme = () => {
const { selectedTheme } = this.state;
const root = document.documentElement;
console.log(root);
const newTheme = selectedTheme === "LIGHT" ? "DARK" : "LIGHT";
root.style.setProperty(
"background-color",
theme[newTheme].colors.bodyBackground
);
this.setState(prevState => ({
selectedTheme: newTheme
}));
};
render() { render() {
const { authUser, selectedTheme } = this.state; const { authUser, selectedTheme } = this.state;
@@ -33,7 +48,7 @@ class App extends Component {
return ( return (
<ThemeProvider theme={currentTheme}> <ThemeProvider theme={currentTheme}>
<Router> <Router>
<Navbar /> <Navbar toggleTheme={this.onChangeTheme} />
<RouteLayout> <RouteLayout>
<Route path="/:year(\d+)" component={Year} /> <Route path="/:year(\d+)" component={Year} />
<Route path="/:year(\d+)/:month(\d+)" component={Month} /> <Route path="/:year(\d+)/:month(\d+)" component={Month} />

View File

@@ -1,6 +1,15 @@
import React from "react"; import React from "react";
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { Book, Calendar, Circle, User } from "react-feather"; import {
Book,
Calendar,
ChevronLeft,
ChevronRight,
Circle,
Moon,
User
} from "react-feather";
import { withTheme } from "emotion-theming";
const IconBase = styled.div` const IconBase = styled.div`
display: flex; display: flex;
@@ -10,18 +19,23 @@ const IconBase = styled.div`
border-radius: 12px; border-radius: 12px;
padding: 5px; padding: 5px;
transition: 0.1s all ease-in-out; transition: 0.1s all ease-in-out;
color: ${props => props.theme.colors.secondary};
&:hover { &:hover {
background-color: yellow; background-color: ${props => props.theme.colors.hover};
cursor: pointer;
} }
`; `;
const Icon = ({ name }) => ( const Icon = ({ name, ...rest }) => (
<IconBase> <IconBase {...rest}>
{name === "Book" && <Book />} {name === "Book" && <Book />}
{name === "Calendar" && <Calendar />} {name === "Calendar" && <Calendar />}
{name === "ChevronLeft" && <ChevronLeft />}
{name === "ChevronRight" && <ChevronRight />}
{name === "Circle" && <Circle />} {name === "Circle" && <Circle />}
{name === "Moon" && <Moon />}
{name === "User" && <User />} {name === "User" && <User />}
</IconBase> </IconBase>
); );
export default Icon; export default withTheme(Icon);

View File

@@ -11,12 +11,15 @@ import SignOut from "../SignOut";
import { withAuthentication } from "../session"; import { withAuthentication } from "../session";
const Header = styled.div` const Header = styled.div`
background-color: ${props => props.theme.colors.background}; background-color: ${props => props.theme.colors.headerBackground};
height: 60px; height: 60px;
display: grid; display: grid;
grid-template-areas: "... nav ..."; grid-template-areas: "... nav ...";
grid-template-columns: 1fr minmax(240px, 720px) 1fr; grid-template-columns: 1fr minmax(240px, 720px) 1fr;
align-items: center; align-items: center;
border-width: 1px;
border-color: ${props => props.theme.colors.quarternary};
border-style: solid;
`; `;
const Nav = styled.div` const Nav = styled.div`
grid-area: nav; grid-area: nav;
@@ -35,17 +38,24 @@ const NavIcons = styled.div`
} }
`; `;
const Navbar = ({ authUser, theme }) => ( const Navbar = ({ authUser, theme, toggleTheme }) => (
<Header> <Header>
<Nav> <Nav>
<Logo>Logo</Logo> <Logo>Logo</Logo>
<NavIcons> <NavIcons>
<Icon onClick={() => toggleTheme()} name="Moon" />
{authUser ? ( {authUser ? (
<React.Fragment> <React.Fragment>
<Link to={yearUrl()}>Year</Link> <Link to={yearUrl()}>
<Link to={todayUrl()}>Today</Link> <Icon name="Calendar" />
<Link to={"/user"}>Account</Link> </Link>
<Icon name="Book" /> <Link to={todayUrl()}>
<Icon name="Book" />
</Link>
<Link to={"/user"}>
<Icon name="User" />
</Link>
<SignOut /> <SignOut />
</React.Fragment> </React.Fragment>
) : ( ) : (

View File

@@ -1,31 +1,38 @@
import React from "react"; import React from "react";
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { withTheme } from "emotion-theming";
import { SIZES } from "../../styles/constants"; import { SIZES } from "../../styles/constants";
import Icon from "../Icon";
const SeekHeader = styled.header` const SeekHeader = styled.header`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
border-bottom-width: 1px;
border-bottom-style: solid;
border-color: ${props => props.theme.colors.quarternary};
`; `;
const SeekH1 = styled.h1` const SeekH1 = styled.h1`
display: block; display: block;
font-size: ${SIZES.normal}; font-size: ${SIZES.normal};
color: ${props => props.theme.colors.secondary};
`; `;
const SeekArrows = styled.div``; const SeekArrows = styled.div`
const SeekHr = styled.hr` display: grid;
margin: 0; grid-template-columns: auto auto;
grid-gap: 10px;
`; `;
const Seek = ({ title = "", prev = "", next = "" }) => ( const Seek = ({ title = "", prev = "", next = "" }) => (
<React.Fragment> <SeekHeader>
<SeekHeader> <SeekH1>{title}</SeekH1>
<SeekH1>{title}</SeekH1> <SeekArrows>
<SeekArrows>asdf</SeekArrows> <Icon name="ChevronLeft" />
</SeekHeader> <Icon name="ChevronRight" />
<SeekHr /> </SeekArrows>
</React.Fragment> </SeekHeader>
); );
export default Seek; export default withTheme(Seek);

View File

@@ -1,3 +1,6 @@
* {
transition: 0.2s all ease-in-out;
}
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
@@ -7,8 +10,3 @@ body {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}

View File

@@ -5,7 +5,9 @@ const theme = {
secondary: "#999", secondary: "#999",
tertiary: "#C4C4C4", tertiary: "#C4C4C4",
quarternary: "#EAEAEA", quarternary: "#EAEAEA",
background: "#FAFBFC" headerBackground: "#FAFBFC",
bodyBackground: "#FFF",
hover: "hsla(233, 5%, 31%, 0.12)"
} }
}, },
DARK: { DARK: {
@@ -14,7 +16,9 @@ const theme = {
secondary: "#9Ba3B0", secondary: "#9Ba3B0",
tertiary: "#6F7682", tertiary: "#6F7682",
quarternary: "#3E4B62", quarternary: "#3E4B62",
background: "#2E3136" headerBackground: "#272f3d",
bodyBackground: "#262B34",
hover: "hsla(233, 100%, 96%, 0.12)"
} }
} }
}; };