diff --git a/src/main/webapp/src/App.jsx b/src/main/webapp/src/App.jsx index 04b7a97..382e70e 100644 --- a/src/main/webapp/src/App.jsx +++ b/src/main/webapp/src/App.jsx @@ -10,6 +10,7 @@ import {ToastContainer} from "react-toastify"; import './App.css' import 'react-toastify/dist/ReactToastify.css'; +import {ThemeProvider} from "./hooks/useTheme.jsx"; const router = createBrowserRouter([ { @@ -82,7 +83,9 @@ function App() { console.log('render') return - + + + ; } diff --git a/src/main/webapp/src/components/Nav.jsx b/src/main/webapp/src/components/Nav.jsx index 3b95604..d49c009 100644 --- a/src/main/webapp/src/components/Nav.jsx +++ b/src/main/webapp/src/components/Nav.jsx @@ -1,38 +1,53 @@ import LogoIcon from '../assets/FFSSAF-bord-blanc-fond-transparent.webp' -import './Nav.css' +// import './Nav.css' import {NavLink} from "react-router-dom"; import {useAuth} from "../hooks/useAuth.jsx"; import {login, logout} from "../utils/auth.js"; +import {ThemeCss, useTheme} from "../hooks/useTheme.jsx"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {faMoon, faSun} from "@fortawesome/free-regular-svg-icons"; + +const themeSwitcherVariant = { + light: "outline-primary bg-light", + dark: "outline-light bg-dark" +}; export function Nav() { + const {theme} = useTheme(); - return - - - - FFSAF Intra - + return <> + + + + + + FFSAF Intra + - - - - - - - Accueil - - - + + + + + + + Accueil + + + + + - - + + > } function AdminMenu() { const {is_authenticated, userinfo} = useAuth() + const {theme} = useTheme(); if (!is_authenticated || !userinfo?.roles?.includes("federation_admin")) return <>> @@ -41,7 +56,7 @@ function AdminMenu() { Administration - + Member B @@ -58,4 +73,10 @@ function LoginMenu() { logout()}>Déconnexion )} +} + +function ThemeSwitcher() { + const {isLight, toggleTheme} = useTheme() + return {isLight ? : + } } \ No newline at end of file diff --git a/src/main/webapp/src/hooks/useTheme.jsx b/src/main/webapp/src/hooks/useTheme.jsx new file mode 100644 index 0000000..0e9f7d3 --- /dev/null +++ b/src/main/webapp/src/hooks/useTheme.jsx @@ -0,0 +1,42 @@ +import React, {createContext, useContext, useLayoutEffect, useState} from "react"; + +export const ThemeContext = createContext({ + theme: 'light', + toggleTheme: () => { + } +}); + +export function useTheme() { + const {theme, toggleTheme} = useContext(ThemeContext); + return { + isLight: theme === 'light', + isDark: theme === 'dark', + theme, + toggleTheme + }; +} + +export function ThemeCss({path}) { + const {theme} = useTheme(); + + const Light = React.lazy(() => import(path + ".css")); + const Dark = React.lazy(() => import(path + ".dark.css")); + + return <> + >}> + {theme === "light" && } + {theme === "dark" && } + + > +} + +export function ThemeProvider({children}) { + const [theme, setTheme] = useState('light'); + const toggleTheme = () => { + setTheme(theme === 'light' ? 'dark' : 'light'); + } + + return + {children} + +} \ No newline at end of file