Skip to content

Commit

Permalink
feat: Adding colorMode button and first configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorodriguezgarcia committed Apr 22, 2024
1 parent 0b46730 commit 0a6b8b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions webapp/src/components/menu/LateralMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Box, Drawer, DrawerOverlay, DrawerContent, DrawerCloseButton, DrawerHeader, DrawerBody, DrawerFooter, Select, Button, Text, IconButton, Flex, Image } from '@chakra-ui/react';
import { Box, Drawer, DrawerOverlay, DrawerContent, DrawerCloseButton, DrawerHeader, DrawerBody, DrawerFooter, Select, Button, Text, IconButton, Flex, Image, useColorMode } from '@chakra-ui/react';
import { FaChartBar, FaBook, FaTachometerAlt } from 'react-icons/fa';
import { InfoIcon, SettingsIcon } from '@chakra-ui/icons';
import { InfoIcon, SettingsIcon, SunIcon, MoonIcon } from '@chakra-ui/icons';

import AuthManager from "components/auth/AuthManager";

Expand All @@ -13,6 +13,7 @@ const LateralMenu = ({ isOpen, onClose, changeLanguage, isDashboard }) => {
const [selectedLanguage, setSelectedLanguage] = useState('');
const [isLoggedIn, setIsLoggedIn] = useState(false);
const { t, i18n } = useTranslation();
const { colorMode, toggleColorMode } = useColorMode();

useEffect(() => {
checkIsLoggedIn();
Expand Down Expand Up @@ -55,6 +56,9 @@ const LateralMenu = ({ isOpen, onClose, changeLanguage, isDashboard }) => {
<Flex align="center">
<Image src="/kiwiq-icon.ico" alt="App icon" width="80px" height="80px"/>
<DrawerHeader color={"forest_green.500"}>KIWIQ</DrawerHeader>
{
colorMode === "light" ? <IconButton colorScheme={"forest_green"} onClick={toggleColorMode} icon={<MoonIcon />} aria-label={'DarkMode'} /> : <IconButton colorScheme={"forest_green"} onClick={toggleColorMode} icon={<SunIcon />} aria-label={'LightMode'} />
}
</Flex>
<DrawerBody>
<Box flexDirection="column">
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './index.css';
import reportWebVitals from './reportWebVitals';
import {createBrowserRouter, RouterProvider} from 'react-router-dom';
import router from 'components/Router';
import { ChakraProvider } from '@chakra-ui/react';
import { ChakraProvider, ColorModeScript } from '@chakra-ui/react';
import "./i18n";
import theme from "./styles/theme";

Expand All @@ -13,6 +13,7 @@ const browserRouter = createBrowserRouter(router);

root.render(
<ChakraProvider theme={theme}>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
<RouterProvider router={browserRouter} />
</ChakraProvider>
);
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/styles/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ const theme = extendTheme({
}
},
},
initialColorMode: 'system',
useSystemColorMode: true,
});
export default theme;

0 comments on commit 0a6b8b2

Please sign in to comment.