diff --git a/src/components/Header.tsx b/src/components/Header.tsx index f2c0e38..57d27c2 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,8 +1,12 @@ import "@styles/Header.scss"; +import ThemeSwitch from "@components/ThemeSwitch"; + export default function Header() { return (
-
brandname
+
+

Meister

+
Link1 Link2 @@ -10,7 +14,7 @@ export default function Header() { Link4
-
Theme
+
Language
diff --git a/src/components/ThemeSwitch.tsx b/src/components/ThemeSwitch.tsx new file mode 100644 index 0000000..6e4d23b --- /dev/null +++ b/src/components/ThemeSwitch.tsx @@ -0,0 +1,63 @@ +import "@styles/ThemeSwitch.scss"; +import { useEffect, useRef } from "react"; + +export default function ThemeSwitch() { + const svgRef = useRef(null); + + function switchTheme(theme: string) { + const bodyElement = document.getElementsByTagName("body")[0]; + + if (theme == "dark") { + bodyElement.classList.add("theme-dark"); + } else { + bodyElement.classList.remove("theme-dark"); + localStorage.setItem("theme", "light"); + } + } + + function toggleTheme() { + if (svgRef.current) { + if (localStorage.getItem("theme") == "light") { + svgRef.current.style.animationDirection = "normal"; + svgRef.current.style.animationName = "spinThemeSwitch"; + } else { + svgRef.current.style.animationDirection = "reverse"; + svgRef.current.style.animationName = "spinThemeSwitch"; + } + + setTimeout(() => { + if (localStorage.getItem("theme") == "light") { + localStorage.setItem("theme", "dark"); + switchTheme("dark"); + } else { + localStorage.setItem("theme", "light"); + switchTheme("light"); + } + + if (svgRef.current) { + svgRef.current.style.animationName = ""; + } + }, 150); + } + } + + useEffect(() => { + if (localStorage.getItem("theme") == "dark") { + switchTheme("dark"); + } else { + switchTheme("light"); + } + }, []); + + return ( +
+ + + +
+ ); +} diff --git a/src/styles/App.scss b/src/styles/App.scss index b73be33..5fa4bc9 100644 --- a/src/styles/App.scss +++ b/src/styles/App.scss @@ -1,4 +1,7 @@ #app { display: flex; flex-direction: column; + background-color: var(--color-background-body); + min-height: auto; + flex: 1; } diff --git a/src/styles/Header.scss b/src/styles/Header.scss index 51b3d3a..dfcaf3b 100644 --- a/src/styles/Header.scss +++ b/src/styles/Header.scss @@ -20,15 +20,15 @@ a { margin-left: 1rem; text-decoration: none; - color: #323232; + color: var(--color-font-link-header); font-weight: 600; font-size: 1.2rem; transition: all 0.1s ease-in-out; - border-bottom: 3px solid transparent; + border-bottom: 3px solid var(--color-font-link-header); &:hover { - color: #000000; - border-color: #000000; + color: var(--color-font-link-header-hover); + border-color: var(--color-font-link-header-hover); } } } diff --git a/src/styles/ThemeSwitch.scss b/src/styles/ThemeSwitch.scss new file mode 100644 index 0000000..e4cf946 --- /dev/null +++ b/src/styles/ThemeSwitch.scss @@ -0,0 +1,26 @@ +.themeSwitch { + svg { + aspect-ratio: 1; + height: 2rem; + cursor: pointer; + animation-duration: 150ms; + animation-timing-function: linear; + animation-iteration-count: 1; + animation-direction: normal; + fill: var(--color-font-nav); + transition: all 50ms linear; + + &:hover { + fill: var(--color-font); + } + } + + @keyframes spinThemeSwitch { + from { + transform: rotate(0deg); + } + to { + transform: rotate(-180deg); + } + } +} diff --git a/src/styles/index.scss b/src/styles/index.scss index 91a1c7a..dc32c63 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -1,11 +1,13 @@ +@import "variables_colors.scss"; + :root { font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; line-height: 1.5; font-weight: 400; color-scheme: light dark; - color: rgba(0, 0, 0, 0.87); - background-color: #ffffff; + color: var(--color-font); + background-color: var(--color-background-body); font-synthesis: none; text-rendering: optimizeLegibility; @@ -19,3 +21,15 @@ margin: 0; padding: 0; } + +html { + scroll-behavior: smooth; +} + +body, +#root { + display: flex; + flex-direction: column; + height: 100vh; + width: 100vw; +}