removed styled-theming dependency

This commit is contained in:
Kim, Jimin 2021-05-19 17:26:40 +09:00
parent 087e9fa8c8
commit c850184bc7
10 changed files with 129 additions and 115 deletions

View file

@ -42,13 +42,11 @@
"react-scripts": "^4.0.3", "react-scripts": "^4.0.3",
"react-tooltip": "^4.2.19", "react-tooltip": "^4.2.19",
"styled-components": "^5.3.0", "styled-components": "^5.3.0",
"styled-theming": "^2.2.0",
"web-vitals": "^1.1.2" "web-vitals": "^1.1.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^15.0.2", "@types/node": "^15.0.2",
"@types/styled-components": "^5.1.9", "@types/styled-components": "^5.1.9",
"@types/styled-theming": "^2.2.5",
"@typescript-eslint/eslint-plugin": "^4.23.0", "@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0", "@typescript-eslint/parser": "^4.23.0",
"eslint": "^7.26.0", "eslint": "^7.26.0",

View file

@ -3,7 +3,6 @@ import { ThemeProvider, createGlobalStyle } from "styled-components"
import { HelmetProvider } from "react-helmet-async" import { HelmetProvider } from "react-helmet-async"
import storage from "local-storage-fallback" import storage from "local-storage-fallback"
import { useState, useEffect } from "react" import { useState, useEffect } from "react"
import theme from "styled-theming"
import Spinner from "./components/Spinner" import Spinner from "./components/Spinner"
import LanguageContext from "./LanguageContext" import LanguageContext from "./LanguageContext"
import theming from "./theming" import theming from "./theming"
@ -17,7 +16,7 @@ import NotFound from "./pages/notfound"
import Portfolio from "./pages/portfolio" import Portfolio from "./pages/portfolio"
// Theme that will be used throughout the website // Theme that will be used throughout the website
const GlobalStyle = createGlobalStyle` const GlobalStyle = createGlobalStyle<{ theme: { currentTheme: string } }>`
body { body {
overflow-x: hidden; overflow-x: hidden;
overflow-y: scroll; overflow-y: scroll;
@ -28,11 +27,13 @@ html, body, #root {
margin: 0; margin: 0;
display: flex; display: flex;
flex-flow: column; flex-flow: column;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.backgroundColor1, light: theming.light.backgroundColor1,
dark: theming.dark.backgroundColor1, dark: theming.dark.backgroundColor1,
})}; })};
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.color1, light: theming.light.color1,
dark: theming.dark.color1, dark: theming.dark.color1,
})}; })};
@ -93,7 +94,8 @@ blockquote {
.card { .card {
margin: auto; margin: auto;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "white", light: "white",
dark: "#2F3136", dark: "#2F3136",
})}; })};
@ -147,14 +149,13 @@ function App() {
/** /**
* Theme * Theme
*/ */
const [currentTheme, _setTheme] = useState(() => { const [currentTheme, _setTheme] = useState(
const savedTheme = storage.getItem("theme") storage.getItem("theme") || "dark" // get theme from storage and set to "dark" mode if not set already
return savedTheme ? JSON.parse(savedTheme) : { mode: "dark" } )
})
// save theme when it is changed // save theme when it is changed
useEffect(() => { useEffect(() => {
storage.setItem("theme", JSON.stringify(currentTheme)) storage.setItem("theme", currentTheme)
}, [currentTheme]) }, [currentTheme])
/** /**
@ -184,9 +185,9 @@ function App() {
<HelmetProvider> <HelmetProvider>
<ThemeProvider <ThemeProvider
theme={{ theme={{
...currentTheme, currentTheme: currentTheme,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
setTheme: ({ setTheme, ...theme }) => _setTheme(theme), // make setTheme function available in other components setTheme: (setThemeTo) => _setTheme(setThemeTo), // make setTheme function available in other components
}} }}
> >
<LanguageContext.Provider value={languageState}> <LanguageContext.Provider value={languageState}>
@ -198,9 +199,9 @@ function App() {
<Spinner <Spinner
size={200} size={200}
color={ color={
currentTheme.mode == "light" currentTheme == "dark"
? theming.light.color1 ? theming.dark.color1
: theming.dark.color1 : theming.light.color1
} }
/> />
) : ( ) : (

View file

@ -1,7 +1,7 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faGithub } from "@fortawesome/free-brands-svg-icons" import { faGithub } from "@fortawesome/free-brands-svg-icons"
import styled from "styled-components" import styled from "styled-components"
import theme from "styled-theming" import theming from "../theming"
const StyledFooter = styled.footer` const StyledFooter = styled.footer`
display: flex; display: flex;
@ -9,11 +9,13 @@ const StyledFooter = styled.footer`
margin-bottom: 1px; /* footer goes outside the page by 1 px for some reason */ margin-bottom: 1px; /* footer goes outside the page by 1 px for some reason */
padding: 50px 10px; padding: 50px 10px;
background-color: white; background-color: white;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "white", light: "white",
dark: "black", dark: "black",
})}; })};
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "black", light: "black",
dark: "white", dark: "white",
})}; })};
@ -30,13 +32,15 @@ const StyledFooter = styled.footer`
const StyledLink = styled.a` const StyledLink = styled.a`
width: 30px; width: 30px;
font-size: 2rem; font-size: 2rem;
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "lightgrey", light: "lightgrey",
dark: "grey", dark: "grey",
})}; })};
&:hover { &:hover {
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "black", light: "black",
dark: "white", dark: "white",
})}; })};

View file

@ -1,7 +1,6 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faGithub } from "@fortawesome/free-brands-svg-icons" import { faGithub } from "@fortawesome/free-brands-svg-icons"
import styled from "styled-components" import styled from "styled-components"
import theme from "styled-theming"
import ReactTooltip from "react-tooltip" import ReactTooltip from "react-tooltip"
import NavbarData from "../data/NavbarData" import NavbarData from "../data/NavbarData"
import theming from "../theming" import theming from "../theming"
@ -18,11 +17,13 @@ const StyledNav = styled.nav`
height: 2rem; height: 2rem;
margin: 0; margin: 0;
padding: 1rem; padding: 1rem;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.backgroundColor0, light: theming.light.backgroundColor0,
dark: theming.dark.backgroundColor0, dark: theming.dark.backgroundColor0,
})}; })};
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.color0, light: theming.light.color0,
dark: theming.dark.color0, dark: theming.dark.color0,
})}; })};

View file

@ -1,23 +1,26 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faSearch } from "@fortawesome/free-solid-svg-icons" import { faSearch } from "@fortawesome/free-solid-svg-icons"
import styled from "styled-components" import styled from "styled-components"
import theme from "styled-theming" import theming from "../theming"
const StyledSearchBoxContainer = styled.div` const StyledSearchBoxContainer = styled.div`
display: flex; display: flex;
justify-content: left; justify-content: left;
align-items: center; align-items: center;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "white", light: "white",
dark: "#202225", dark: "#202225",
})}; })};
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "black", light: "black",
dark: "#CFD0D0", dark: "#CFD0D0",
})}; })};
&:hover { &:hover {
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "whitesmoke", light: "whitesmoke",
dark: "#36393F", dark: "#36393F",
})}; })};

View file

@ -1,7 +1,6 @@
import { useState } from "react" import { useState } from "react"
import styled, { css } from "styled-components" import styled, { css } from "styled-components"
import NavbarData from "../data/NavbarData" import NavbarData from "../data/NavbarData"
import theme from "styled-theming"
import ReactTooltip from "react-tooltip" import ReactTooltip from "react-tooltip"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
@ -67,11 +66,13 @@ const SidebarNav = styled.nav<StateProps>`
z-index: 30; z-index: 30;
overflow-x: hidden; overflow-x: hidden;
overflow-y: scroll; overflow-y: scroll;
background-color: ${theme("mode", { background-color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.backgroundColor0, light: theming.light.backgroundColor0,
dark: theming.dark.backgroundColor0, dark: theming.dark.backgroundColor0,
})}; })};
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: theming.light.color0, light: theming.light.color0,
dark: theming.dark.color0, dark: theming.dark.color0,
})}; })};

View file

@ -1,7 +1,6 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faMoon, faSun } from "@fortawesome/free-solid-svg-icons" import { faMoon, faSun } from "@fortawesome/free-solid-svg-icons"
import styled, { ThemeConsumer } from "styled-components" import styled, { ThemeConsumer } from "styled-components"
import theme from "styled-theming"
import ReactTooltip from "react-tooltip" import ReactTooltip from "react-tooltip"
@ -9,7 +8,8 @@ import theming from "../theming"
const StyledThemeButton = styled.div` const StyledThemeButton = styled.div`
${theming.styles.navbarButtonStyle} ${theming.styles.navbarButtonStyle}
${theme("mode", { ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "", light: "",
dark: "transform: scaleX(-1);\ dark: "transform: scaleX(-1);\
-moz-transform: scaleX(-1);\ -moz-transform: scaleX(-1);\
@ -21,29 +21,25 @@ const StyledThemeButton = styled.div`
function Navbar() { function Navbar() {
return ( return (
<ThemeConsumer> <ThemeConsumer>
{(_theme) => ( {({ currentTheme, setTheme }) => (
<> <>
<StyledThemeButton <StyledThemeButton
data-tip data-tip
data-for="theme" data-for="theme"
className="right" className="right"
onClick={() => onClick={() =>
_theme.setTheme( setTheme(currentTheme === "dark" ? "light" : "dark")
_theme.mode === "dark"
? { ..._theme, mode: "light" }
: { ..._theme, mode: "dark" }
)
} }
> >
{_theme.mode == "dark" && ( {currentTheme == "dark" && (
<FontAwesomeIcon icon={faMoon} /> <FontAwesomeIcon icon={faMoon} />
)} )}
{_theme.mode == "light" && ( {currentTheme == "light" && (
<FontAwesomeIcon icon={faSun} /> <FontAwesomeIcon icon={faSun} />
)} )}
</StyledThemeButton> </StyledThemeButton>
<ReactTooltip id="theme" type="dark" effect="solid"> <ReactTooltip id="theme" type="dark" effect="solid">
<span>Using {_theme.mode} theme</span> <span>Using {currentTheme} theme</span>
</ReactTooltip> </ReactTooltip>
</> </>
)} )}

View file

@ -1,6 +1,6 @@
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import styled from "styled-components" import styled from "styled-components"
import theme from "styled-theming" import theming from "../theming"
import marked from "marked" import marked from "marked"
import { Helmet } from "react-helmet-async" import { Helmet } from "react-helmet-async"
@ -10,7 +10,8 @@ const StyledPostList = styled.div`
padding-top: 2rem; padding-top: 2rem;
margin: auto; margin: auto;
text-align: center; text-align: center;
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "#111111", light: "#111111",
dark: "#EEEEEE", dark: "#EEEEEE",
})}; })};
@ -30,7 +31,8 @@ const StyledTitle = styled.h1`
const StyledLink = styled(Link)` const StyledLink = styled(Link)`
text-decoration: none; text-decoration: none;
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "black", light: "black",
dark: "white", dark: "white",
})}; })};

View file

@ -1,12 +1,13 @@
import styled from "styled-components" import styled from "styled-components"
import theme from "styled-theming" import theming from "../theming"
import { Helmet } from "react-helmet-async" import { Helmet } from "react-helmet-async"
const StyledNotFound = styled.div` const StyledNotFound = styled.div`
margin: auto; margin: auto;
margin-top: 2rem; margin-top: 2rem;
text-align: center; text-align: center;
color: ${theme("mode", { color: ${(props) =>
theming.theme(props.theme.currentTheme, {
light: "#111111", light: "#111111",
dark: "#EEEEEE", dark: "#EEEEEE",
})}; })};

View file

@ -3,10 +3,14 @@
* It makes changing values easier * It makes changing values easier
*/ */
import theme from "styled-theming"
import { css } from "styled-components" import { css } from "styled-components"
function theme(currentTheme, values) {
return values[currentTheme]
}
export default { export default {
theme: theme,
font: { font: {
regular: "'Noto Sans KR', sans-serif", regular: "'Noto Sans KR', sans-serif",
code: "'Source Code Pro', monospace", code: "'Source Code Pro', monospace",
@ -45,16 +49,19 @@ export default {
text-decoration: none; text-decoration: none;
margin: 0.1em; margin: 0.1em;
transition: transform 0.1s linear; transition: transform 0.1s linear;
color: ${theme("mode", { color: ${(props) =>
theme(props.theme.currentTheme, {
light: "black", light: "black",
dark: "#CFD0D0", dark: "#CFD0D0",
})}; })};
background-color: ${theme("mode", { background-color: ${(props) =>
theme(props.theme.currentTheme, {
light: "white", light: "white",
dark: "#202225", dark: "#202225",
})}; })};
&:hover { &:hover {
background-color: ${theme("mode", { background-color: ${(props) =>
theme(props.theme.currentTheme, {
light: "lightgrey", light: "lightgrey",
dark: "#36393F", dark: "#36393F",
})}; })};