Skip to content

Commit

Permalink
added: working dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTeida committed Jan 26, 2024
1 parent e6c6b9b commit bdb5377
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import './styles/App.scss'
import {Outlet} from "react-router-dom";
import {Box} from "@mui/joy";
import {Sheet} from "@mui/joy";
import Header from "./components/Header.jsx";

function App() {

return (
<>
<Header />
<Box component="main" className="MainContent">
<Outlet/>
</Box>
<Header/>
<Sheet component="main" className="MainContent">
<Outlet/>
</Sheet>
</>
)
}
Expand Down
Binary file added src/assets/logo NeuraChatAi 100x100 white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/logo NeuraChatAi white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Chat() {
flex: 1,
minHeight: 0,
overflowY: 'scroll',
backgroundColor: 'primary.50',
backgroundColor: 'background.level1',
pl: {xs: 1, md: 2}
}}>
{messages.map((el, index) => {
Expand Down
20 changes: 16 additions & 4 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import {Box, GlobalStyles, Sheet, Stack} from "@mui/joy";
import {Box, GlobalStyles, Sheet, Stack, Typography} from "@mui/joy";
import {Link as RouterLink} from "react-router-dom";
import logoNeuraChatAi from "../assets/logo NeuraChatAi.png"
import logoNeuraChatAiWhite from "../assets/logo NeuraChatAi white.png"
import ModeToggle from "./ModeToggle.jsx";
import {useEffect, useState} from "react";
import { useColorScheme } from '@mui/joy/styles';

function Header() {
const {mode} = useColorScheme();
const [logoHeader, setLogoHeader] = useState(mode)

useEffect(() => {
mode === 'light' ? setLogoHeader(logoNeuraChatAi) : setLogoHeader(logoNeuraChatAiWhite)
},[mode])

return (
<Sheet component="header"
sx={{
Expand All @@ -28,18 +39,19 @@ function Header() {
justifyContent="center"
alignItems="center"
spacing={2}>
<Box component="img" src={logoNeuraChatAi} alt={"Logo NeuraChatAi"} sx={{
<Box component="img" src={logoHeader} alt={"Logo NeuraChatAi"} sx={{
maxWidth: {xs: 100, md: 100},
}}/>
<RouterLink to="/NeuraChatAi/">Homepage</RouterLink>
<RouterLink to="/NeuraChatAi/about">About</RouterLink>
<RouterLink to="/NeuraChatAi/"><Typography>Homepage</Typography></RouterLink>
<RouterLink to="/NeuraChatAi/about"><Typography>About</Typography></RouterLink>
</Stack>
<Stack direction="row"
justifyContent="center"
alignItems="center"
spacing={1}>

</Stack>
<ModeToggle />
</Sheet>
)
}
Expand Down
30 changes: 30 additions & 0 deletions src/components/ModeToggle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {useEffect, useState} from 'react'
import {Button, useColorScheme} from '@mui/joy';


function ModeToggle() {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = useState(false);

// necessary for server-side rendering
// because mode is undefined on the server
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}

return (
<Button
variant="outlined"
onClick={() => {
setMode(mode === 'light' ? 'dark' : 'light');
}}
>
{mode === 'light' ? 'Turn dark' : 'Turn light'}
</Button>
);
}

export default ModeToggle

0 comments on commit bdb5377

Please sign in to comment.