added basic localization to theme toggle button
This commit is contained in:
parent
7fbe466036
commit
e64f26e927
1 changed files with 29 additions and 18 deletions
|
@ -1,4 +1,5 @@
|
||||||
import styled, { ThemeConsumer } from "styled-components"
|
import { useContext } from "react"
|
||||||
|
import styled from "styled-components"
|
||||||
import { isMobile } from "react-device-detect"
|
import { isMobile } from "react-device-detect"
|
||||||
import ReactTooltip from "react-tooltip"
|
import ReactTooltip from "react-tooltip"
|
||||||
|
|
||||||
|
@ -6,6 +7,7 @@ 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 theming from "../../styles/theming"
|
import theming from "../../styles/theming"
|
||||||
|
import { ActionsEnum, globalContext } from "../../globalContext"
|
||||||
|
|
||||||
const StyledThemeButton = styled.div`
|
const StyledThemeButton = styled.div`
|
||||||
${theming.styles.navbarButtonStyle}
|
${theming.styles.navbarButtonStyle}
|
||||||
|
@ -17,26 +19,35 @@ const StyledThemeButton = styled.div`
|
||||||
`
|
`
|
||||||
|
|
||||||
const ThemeToggleButton = () => {
|
const ThemeToggleButton = () => {
|
||||||
|
const { globalState, dispatch } = useContext(globalContext)
|
||||||
|
const theme = globalState.theme
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeConsumer>
|
|
||||||
{({ currentTheme, setTheme }) => (
|
|
||||||
<>
|
<>
|
||||||
<StyledThemeButton
|
<StyledThemeButton
|
||||||
data-tip
|
data-tip
|
||||||
data-for="theme"
|
data-for="theme"
|
||||||
onClick={() => setTheme(currentTheme === "dark" ? "light" : "dark")}
|
onClick={() =>
|
||||||
|
dispatch({
|
||||||
|
type: ActionsEnum.UPDATE_THEME,
|
||||||
|
payload: theme === "dark" ? "light" : "dark",
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{currentTheme == "dark" && <FontAwesomeIcon icon={faMoon} />}
|
{theme == "dark" && <FontAwesomeIcon icon={faMoon} />}
|
||||||
{currentTheme == "light" && <FontAwesomeIcon icon={faSun} />}
|
{theme == "light" && <FontAwesomeIcon icon={faSun} />}
|
||||||
</StyledThemeButton>
|
</StyledThemeButton>
|
||||||
|
|
||||||
{!isMobile && (
|
{!isMobile && (
|
||||||
<ReactTooltip id="theme" type="dark" effect="solid">
|
<ReactTooltip id="theme" type="dark" effect="solid">
|
||||||
<span>Using {currentTheme} theme</span>
|
{globalState.locale == "en" ? (
|
||||||
|
<span>Using {theme} theme</span>
|
||||||
|
) : (
|
||||||
|
<span>{theme == "dark" ? "어두운" : "밝은"} 테마 사용중</span>
|
||||||
|
)}
|
||||||
</ReactTooltip>
|
</ReactTooltip>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
|
||||||
</ThemeConsumer>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue