From 285c5b04e8ce6b2e409568219241c64900f172b1 Mon Sep 17 00:00:00 2001 From: izawartka <59137928+izawartka@users.noreply.github.com> Date: Fri, 15 Aug 2025 21:23:46 +0200 Subject: [PATCH] Added theme toggle +Added dark-mode and light-mode component icons +Added ThemeToggle in the toolbar +Added ThemeManager and ThemeContext --- src/components/App.js | 25 ++++++++++++++----------- src/components/ThemeManager.js | 20 ++++++++++++++++++++ src/components/toolbar/ThemeToggle.js | 19 +++++++++++++++++++ src/components/toolbar/Toolbar.css | 2 ++ src/components/toolbar/Toolbar.js | 2 ++ src/contexts/ThemeContext.js | 4 ++++ src/icons/index.js | 2 ++ src/icons/toolbar/dark-mode.js | 7 +++++++ src/icons/toolbar/light-mode.js | 18 ++++++++++++++++++ 9 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 src/components/ThemeManager.js create mode 100644 src/components/toolbar/ThemeToggle.js create mode 100644 src/contexts/ThemeContext.js create mode 100644 src/icons/toolbar/dark-mode.js create mode 100644 src/icons/toolbar/light-mode.js diff --git a/src/components/App.js b/src/components/App.js index 19862f9..1f367e9 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -10,23 +10,26 @@ import DistanceMeterContext from '../contexts/DistanceMeterContext'; import {GradientsManager} from "./GradientsManager"; import SideMenuContext from '../contexts/SideMenuContext'; import SceneryManager from './SceneryManager'; +import ThemeManager from './ThemeManager'; function App() { const [sideMenuOpen, setSideMenuOpen] = useState(false); const [distancePoints, setDistancePoints] = useState(null); return ( - - - - - - - - - - - + + + + + + + + + + + + + ); } diff --git a/src/components/ThemeManager.js b/src/components/ThemeManager.js new file mode 100644 index 0000000..2d98164 --- /dev/null +++ b/src/components/ThemeManager.js @@ -0,0 +1,20 @@ +import { useState } from "react"; +import ThemeContext from "../contexts/ThemeContext"; + +export default function ThemeManager(props) { + const [ lightMode, setLightMode ] = useState(false); + + if(lightMode === true) { + document.body.classList.add('light-mode'); + } else { + document.body.classList.remove('light-mode'); + } + + return ( + + { props.children } + + ); +} diff --git a/src/components/toolbar/ThemeToggle.js b/src/components/toolbar/ThemeToggle.js new file mode 100644 index 0000000..62ad0c6 --- /dev/null +++ b/src/components/toolbar/ThemeToggle.js @@ -0,0 +1,19 @@ +import { useContext } from 'react'; +import { LightModeIcon, DarkModeIcon } from '../../icons'; +import ThemeContext from '../../contexts/ThemeContext'; + +export default function ThemeToggle() { + const { setLightMode, lightMode } = useContext(ThemeContext); + + const toggleLightMode = () => { + setLightMode((prev) => !prev); + } + + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/components/toolbar/Toolbar.css b/src/components/toolbar/Toolbar.css index 0deb054..debf6c7 100644 --- a/src/components/toolbar/Toolbar.css +++ b/src/components/toolbar/Toolbar.css @@ -54,10 +54,12 @@ width: 2rem; } +.theme-toggle g, .side-menu-toggle g { stroke: #aaa; } +.theme-toggle:hover g, .side-menu-toggle:hover g { stroke: #fff; } diff --git a/src/components/toolbar/Toolbar.js b/src/components/toolbar/Toolbar.js index b1a346e..b625437 100644 --- a/src/components/toolbar/Toolbar.js +++ b/src/components/toolbar/Toolbar.js @@ -4,6 +4,7 @@ import CustomFileSelect from './CustomFileSelect'; import SideMenuToggle from './SideMenuToggle'; import SceneryList from './SceneryList'; import ElectrificationStepMode from './ElectrificationStepMode'; +import ThemeToggle from './ThemeToggle'; export default function Toolbar() { return ( @@ -14,6 +15,7 @@ export default function Toolbar() {
+
diff --git a/src/contexts/ThemeContext.js b/src/contexts/ThemeContext.js new file mode 100644 index 0000000..1c69777 --- /dev/null +++ b/src/contexts/ThemeContext.js @@ -0,0 +1,4 @@ +import { createContext } from 'react'; + +const ThemeContext = createContext(); +export default ThemeContext; diff --git a/src/icons/index.js b/src/icons/index.js index a501b68..db5bc9b 100644 --- a/src/icons/index.js +++ b/src/icons/index.js @@ -1,4 +1,6 @@ /* Toolbar Icons */ +export { DarkModeIcon } from "./toolbar/dark-mode"; +export { LightModeIcon } from "./toolbar/light-mode"; export { SideMenuIcon } from "./toolbar/side-menu"; /* TrackHoverInfo Icons */ diff --git a/src/icons/toolbar/dark-mode.js b/src/icons/toolbar/dark-mode.js new file mode 100644 index 0000000..29e2bea --- /dev/null +++ b/src/icons/toolbar/dark-mode.js @@ -0,0 +1,7 @@ +export const DarkModeIcon = ({color = '#aaa', strokeWidth = 9}) => ( + + + + + +); diff --git a/src/icons/toolbar/light-mode.js b/src/icons/toolbar/light-mode.js new file mode 100644 index 0000000..1ab6f8f --- /dev/null +++ b/src/icons/toolbar/light-mode.js @@ -0,0 +1,18 @@ +export const LightModeIcon = ({color = '#aaa', strokeWidth = 10}) => ( + + + + + + + + + + + + + + + + +); \ No newline at end of file