fix: improving theme jank

This commit is contained in:
Kyle Gill
2019-05-29 23:09:15 -06:00
parent abfa052fa0
commit a1928a80fb
4 changed files with 19 additions and 11 deletions

View File

@@ -17,11 +17,21 @@ class ThemeToggler extends React.Component {
: "DARK",
}
toggle = () => {
componentDidMount() {
// set the body style property on mount so routes don't flash between transitions
const { themeName } = this.state
this.toggle(themeName)
}
toggle = newThemeName => {
const { themeName } = this.state
const body = document.body
let newTheme
newTheme = themeName === "LIGHT" ? "DARK" : "LIGHT"
if (newThemeName) {
newTheme = newThemeName
} else {
newTheme = themeName === "LIGHT" ? "DARK" : "LIGHT"
}
body.style.setProperty(
"background-color",
theme[newTheme].colors.bodyBackground