| import { Box } from "@mui/material"; | import { Box } from "@mui/material"; | ||||
| import { themeToUse2 } from "hooks/useToggleColorMode"; | |||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| export const HeaderContainer = styled(Box)` | export const HeaderContainer = styled(Box)` | ||||
| padding: 0 24px; | padding: 0 24px; | ||||
| width: 100%; | width: 100%; | ||||
| height: 72px; | height: 72px; | ||||
| background-color: ${themeToUse2.palette.primaryDark}; | |||||
| background-color: ${(props) => props?.theme.colors.primaryDark}; | |||||
| `; | `; | ||||
| export const HeaderSideContainer = styled(Box)` | export const HeaderSideContainer = styled(Box)` | ||||
| display: flex; | display: flex; |
| import { Box } from "@mui/material"; | import { Box } from "@mui/material"; | ||||
| import { NavLink } from "react-router-dom"; | import { NavLink } from "react-router-dom"; | ||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| import selectedTheme from "themes"; | |||||
| export const HeaderNavigationItemIconContainer = styled(Box)``; | export const HeaderNavigationItemIconContainer = styled(Box)``; | ||||
| export const HeaderNavigationItemIconTitle = styled(Box)` | export const HeaderNavigationItemIconTitle = styled(Box)` | ||||
| height: 100%; | height: 100%; | ||||
| transition-duration: 0.1s; | transition-duration: 0.1s; | ||||
| &:hover { | &:hover { | ||||
| background-color: ${selectedTheme.colors.primaryLighter}; | |||||
| background-color: ${(props) => props?.theme.colors.primaryLighter}; | |||||
| } | } | ||||
| &[aria-checked="true"] ${HeaderNavigationItemIconTitle} { | &[aria-checked="true"] ${HeaderNavigationItemIconTitle} { | ||||
| font-weight: 700; | font-weight: 700; |
| import React from "react"; | |||||
| import React, { useContext } from "react"; | |||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { HeaderThemeChooserContainer } from "./HeaderThemeChooser.styled"; | import { HeaderThemeChooserContainer } from "./HeaderThemeChooser.styled"; | ||||
| import DarkModeIcon from "@mui/icons-material/DarkMode"; | import DarkModeIcon from "@mui/icons-material/DarkMode"; | ||||
| import useToggleColorMode, { themeToUse2 } from "hooks/useToggleColorMode"; | |||||
| import LightModeIcon from "@mui/icons-material/LightMode"; | |||||
| import { ColorModeContext } from "context/ColorModeContext"; | |||||
| import { DARK_THEME } from "constants/themeConstants"; | |||||
| const HeaderThemeChooser = () => { | const HeaderThemeChooser = () => { | ||||
| const [toggleColorMode] = useToggleColorMode(); | |||||
| console.log(themeToUse2); | |||||
| const themeCtx = useContext(ColorModeContext); | |||||
| const handleChangeTheme = () => { | const handleChangeTheme = () => { | ||||
| toggleColorMode(); | |||||
| } | |||||
| themeCtx?.changeTheme?.(); | |||||
| }; | |||||
| console.log(themeCtx) | |||||
| return ( | return ( | ||||
| <HeaderThemeChooserContainer onClick={handleChangeTheme}> | <HeaderThemeChooserContainer onClick={handleChangeTheme}> | ||||
| <DarkModeIcon /> | |||||
| {themeCtx?.currentTheme === DARK_THEME ? <LightModeIcon /> : <DarkModeIcon />} | |||||
| </HeaderThemeChooserContainer> | </HeaderThemeChooserContainer> | ||||
| ); | ); | ||||
| }; | }; |
| import { Box } from "@mui/material"; | |||||
| import { IconButton } from "@mui/material"; | |||||
| import styled from "styled-components"; | import styled from "styled-components"; | ||||
| export const HeaderThemeChooserContainer = styled(Box)`` | |||||
| export const HeaderThemeChooserContainer = styled(IconButton)` | |||||
| cursor: pointer; | |||||
| min-width: 0; | |||||
| border-radius: 100%; | |||||
| `; |
| export const DARK_THEME = "dark"; | |||||
| export const LIGHT_THEME = "light"; | |||||
| export const themes = [DARK_THEME, LIGHT_THEME]; | |||||
| export const getNextTheme = (currentTheme) => { | |||||
| const currentThemeIndex = | |||||
| themes?.findIndex?.((singleTheme) => singleTheme === currentTheme) || 0; | |||||
| const nextThemeIndex = | |||||
| currentThemeIndex === themes?.length - 1 ? 0 : currentThemeIndex + 1; | |||||
| return themes[nextThemeIndex]; | |||||
| }; | |||||
| export const themeStorageKey = "colorMode"; |
| import React, { createContext } from "react"; | import React, { createContext } from "react"; | ||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { ThemeProvider } from "@mui/material/styles"; | |||||
| import useToggleColorMode from "hooks/useToggleColorMode"; | |||||
| // import { ThemeProvider } from "@mui/material/styles"; | |||||
| import useTheme from "hooks/useTheme"; | |||||
| import { ThemeProvider } from "styled-components"; | |||||
| export const ColorModeContext = createContext(); | export const ColorModeContext = createContext(); | ||||
| const ColorModeProvider = ({ children }) => { | const ColorModeProvider = ({ children }) => { | ||||
| const [toggleColorMode, theme] = useToggleColorMode(); | |||||
| const [changeTheme, theme, currentTheme] = useTheme(); | |||||
| return ( | return ( | ||||
| <ColorModeContext.Provider value={toggleColorMode}> | |||||
| <ColorModeContext.Provider value={{ changeTheme, theme, currentTheme }}> | |||||
| <ThemeProvider theme={theme}>{children}</ThemeProvider> | <ThemeProvider theme={theme}>{children}</ThemeProvider> | ||||
| </ColorModeContext.Provider> | </ColorModeContext.Provider> | ||||
| ); | ); |
| import { useState, useMemo } from "react"; | |||||
| import { | |||||
| authScopeSetHelper, | |||||
| authScopeStringGetHelper, | |||||
| } from "util/authScopeHelpers"; | |||||
| import { getTheme } from "themes"; | |||||
| import { | |||||
| getNextTheme, | |||||
| themeStorageKey, | |||||
| themes, | |||||
| } from "constants/themeConstants"; | |||||
| const useTheme = () => { | |||||
| const currentColorMode = | |||||
| authScopeStringGetHelper(themeStorageKey) || themes[0]; | |||||
| const [currentTheme, setCurrentTheme] = useState(currentColorMode); | |||||
| const changeTheme = (newTheme) => { | |||||
| const nextMode = newTheme || getNextTheme(currentTheme); | |||||
| authScopeSetHelper(themeStorageKey, nextMode); | |||||
| setCurrentTheme(nextMode); | |||||
| }; | |||||
| const theme = useMemo(() => getTheme(), [currentTheme]); | |||||
| return [changeTheme, theme, currentTheme]; | |||||
| }; | |||||
| export default useTheme; |
| import { useState, useMemo } from "react"; | |||||
| import { createTheme } from "@mui/material/styles"; | |||||
| import { | |||||
| authScopeSetHelper, | |||||
| authScopeStringGetHelper, | |||||
| } from "util/authScopeHelpers"; | |||||
| import selectedTheme, { reinitializeTheme } from "themes"; | |||||
| import { primaryThemeColors } from "themes/primaryTheme/primaryThemeColors"; | |||||
| import { secondaryThemeColors } from "themes/secondaryTheme/secondaryThemeColors"; | |||||
| var themeToUse = { | |||||
| palette: { | |||||
| primary: "white", | |||||
| }, | |||||
| }; | |||||
| const useToggleColorMode = () => { | |||||
| const currentColorMode = authScopeStringGetHelper("colorMode") || "light"; | |||||
| const [mode, setMode] = useState(currentColorMode); | |||||
| const toggleColorMode = () => { | |||||
| const nextMode = mode === "light" ? "dark" : "light"; | |||||
| setMode(nextMode); | |||||
| authScopeSetHelper("colorMode", nextMode); | |||||
| }; | |||||
| const theme = useMemo(() => { | |||||
| reinitializeTheme(); | |||||
| themeToUse = createTheme({ | |||||
| palette: { | |||||
| mode, | |||||
| ...(mode === "light" ? primaryThemeColors : secondaryThemeColors), | |||||
| }, | |||||
| }); | |||||
| return themeToUse; | |||||
| }, [mode]); | |||||
| console.log(selectedTheme); | |||||
| return [toggleColorMode, theme]; | |||||
| }; | |||||
| export const themeToUse2 = getTheme; | |||||
| export default useToggleColorMode; |
| import { Provider } from "react-redux"; | import { Provider } from "react-redux"; | ||||
| import { PersistGate } from "redux-persist/integration/react"; | import { PersistGate } from "redux-persist/integration/react"; | ||||
| import ColorModeProvider from "context/ColorModeContext"; | import ColorModeProvider from "context/ColorModeContext"; | ||||
| import { CssBaseline } from "@mui/material"; | |||||
| // import { CssBaseline } from "@mui/material"; | |||||
| const root = ReactDOM.createRoot(document.getElementById("root")); | const root = ReactDOM.createRoot(document.getElementById("root")); | ||||
| root.render( | root.render( | ||||
| <React.StrictMode> | <React.StrictMode> | ||||
| <Provider store={store}> | <Provider store={store}> | ||||
| <ColorModeProvider> | <ColorModeProvider> | ||||
| <CssBaseline /> | |||||
| {/* <CssBaseline /> */} | |||||
| <PersistGate loading={null} persistor={persistor}> | <PersistGate loading={null} persistor={persistor}> | ||||
| <BrowserRouter> | <BrowserRouter> | ||||
| <Routes> | <Routes> |
| import { authScopeStringGetHelper } from "util/authScopeHelpers"; | import { authScopeStringGetHelper } from "util/authScopeHelpers"; | ||||
| import primary from "./primaryTheme/primaryTheme"; | import primary from "./primaryTheme/primaryTheme"; | ||||
| import secondary from "./secondaryTheme/secondaryTheme"; | import secondary from "./secondaryTheme/secondaryTheme"; | ||||
| import { LIGHT_THEME } from "constants/themeConstants"; | |||||
| export const getTheme = () => { | |||||
| export let getTheme = () => { | |||||
| let selectedThemeStorage = authScopeStringGetHelper("colorMode"); | let selectedThemeStorage = authScopeStringGetHelper("colorMode"); | ||||
| console.log(selectedThemeStorage); | |||||
| if (selectedThemeStorage === "light") { | |||||
| if (selectedThemeStorage === LIGHT_THEME) { | |||||
| return { ...primary }; | return { ...primary }; | ||||
| } | } | ||||
| if (selectedThemeStorage === "dark") { | |||||
| return { ...secondary }; | |||||
| } | |||||
| return { ...secondary }; | |||||
| }; | }; | ||||
| let selectedTheme = getTheme(); | let selectedTheme = getTheme(); | ||||
| export const reinitializeTheme = () => { | |||||
| selectedTheme = getTheme(); | |||||
| } | |||||
| export default selectedTheme; | export default selectedTheme; | ||||
| npm i @ckeditor/ckeditor5-dev-utils @ckeditor/ckeditor5-theme-lark @ckeditor/ckeditor5-react @ckeditor/ckeditor5-editor-classic @ckeditor/ckeditor5-essentials @ckeditor/ckeditor5-paragraph @ckeditor/ckeditor5-basic-styles |