From d5fb0330175e50eae508f236c2e0ff2ade63f81f Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Tue, 24 Aug 2021 17:53:08 +0300 Subject: [PATCH] feat: desktop & mobile navigation --- package-lock.json | 21 ++++++++ package.json | 1 + src/components/Header/AppName.tsx | 9 ++-- src/components/Header/Header.tsx | 14 +++++- src/components/Layout/Layout.tsx | 19 +++++-- src/components/Nav/Desktop/Nav.tsx | 32 ++++++++++++ src/components/Nav/{ => Desktop}/NavLink.tsx | 46 +++++++---------- src/components/Nav/Mobile/Nav.tsx | 32 ++++++++++++ src/components/Nav/Nav.tsx | 52 -------------------- src/config.ts | 4 ++ src/hooks/useWindowDimensions.ts | 28 +++++++++++ src/interfaces/index.ts | 4 ++ src/pages/auth.tsx | 2 +- src/stores/UserStore.ts | 4 +- 14 files changed, 176 insertions(+), 92 deletions(-) create mode 100644 src/components/Nav/Desktop/Nav.tsx rename src/components/Nav/{ => Desktop}/NavLink.tsx (56%) create mode 100644 src/components/Nav/Mobile/Nav.tsx delete mode 100644 src/components/Nav/Nav.tsx create mode 100644 src/hooks/useWindowDimensions.ts diff --git a/package-lock.json b/package-lock.json index b8e1f4e..aebfe43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1408,6 +1408,27 @@ "@chakra-ui/utils": "1.8.2" } }, + "@chakra-ui/icons": { + "version": "1.0.15", + "resolved": "https://registry.npmjs.org/@chakra-ui/icons/-/icons-1.0.15.tgz", + "integrity": "sha512-MMuPwmeCil9vAXceIN/Fxn6CNHbhkLofFQaKUfs+UaBsviiU2tvS0nqGaxm/9FNzLr5ithPVWpbz3uV7DXc77g==", + "requires": { + "@chakra-ui/icon": "1.1.11", + "@types/react": "^17.0.0" + }, + "dependencies": { + "@types/react": { + "version": "17.0.19", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.19.tgz", + "integrity": "sha512-sX1HisdB1/ZESixMTGnMxH9TDe8Sk709734fEQZzCV/4lSu9kJCPbo2PbTRoZM+53Pp0P10hYVyReUueGwUi4A==", + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + } + } + }, "@chakra-ui/image": { "version": "1.0.18", "resolved": "https://registry.npmjs.org/@chakra-ui/image/-/image-1.0.18.tgz", diff --git a/package.json b/package.json index b3bd5d6..5ac4519 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "@chakra-ui/icons": "^1.0.15", "@chakra-ui/react": "^1.0.0", "@emotion/react": "^11.0.0", "@emotion/styled": "^11.0.0", diff --git a/src/components/Header/AppName.tsx b/src/components/Header/AppName.tsx index c255273..b4bf84e 100644 --- a/src/components/Header/AppName.tsx +++ b/src/components/Header/AppName.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Flex, Box, Text, Heading } from '@chakra-ui/react'; import { MdSchool } from 'react-icons/md'; +import config from '../../config'; const AppName: React.FC = () => { return ( @@ -8,11 +9,11 @@ const AppName: React.FC = () => { - - - App name + + + {config.metaData.appName} - App description + {config.metaData.appDescription} ); diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index e2a3214..da9fbfe 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -3,8 +3,12 @@ import { Flex, Box } from '@chakra-ui/react'; import AppName from './AppName'; import UserInfo from './User/UserInfo'; import UserNotifications from './User/UserNotifications'; +import useWindowDimensions from '../../hooks/useWindowDimensions'; +import NavMobile from '../Nav/Mobile/Nav'; const Header: React.FC = () => { + const { isDesktop } = useWindowDimensions(); + return ( { > - - + {isDesktop ? ( + <> + + + + ) : ( + + )} diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index d19b26e..b82619e 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -1,11 +1,12 @@ import React from 'react'; import { Flex, Box } from '@chakra-ui/react'; import Header from '../Header/Header'; -import Nav from '../Nav/Nav'; +import NavDesktop from '../Nav/Desktop/Nav'; import { observer } from 'mobx-react'; import { useRootStore } from '../../hooks/useRootStore'; import { useErrorHandler } from 'react-error-boundary'; import { ColorModeSwitcher } from '../ColorModeSwitcher/ColorModeSwitcher'; +import useWindowDimensions from '../../hooks/useWindowDimensions'; /** * @@ -13,6 +14,7 @@ import { ColorModeSwitcher } from '../ColorModeSwitcher/ColorModeSwitcher'; * Сomponent for rendering the current page. */ const Layout: React.FC = ({ children }) => { + const { isDesktop } = useWindowDimensions(); const { authStore, userStore } = useRootStore(); const handleError = useErrorHandler(); @@ -27,10 +29,19 @@ const Layout: React.FC = ({ children }) => { return ( <>
-