Browse Source

create block header

Alex 2 years ago
parent
commit
03175221f4
11 changed files with 3864 additions and 111 deletions
  1. 1 0
      .gitignore
  2. 3527 27
      package-lock.json
  3. 6 0
      package.json
  4. BIN
      public/favicon.ico
  5. 9 24
      public/index.html
  6. 0 38
      src/App.css
  7. 11 19
      src/App.js
  8. 1 0
      src/App.scss
  9. 201 0
      src/components/Header.jsx
  10. 0 3
      src/index.js
  11. 108 0
      src/scss/Header.scss

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@
 /node_modules
 /.pnp
 .pnp.js
+/.idea
 
 # testing
 /coverage

File diff suppressed because it is too large
+ 3527 - 27
package-lock.json


+ 6 - 0
package.json

@@ -3,11 +3,17 @@
   "version": "0.1.0",
   "private": true,
   "dependencies": {
+    "@emotion/react": "^11.7.1",
+    "@emotion/styled": "^11.6.0",
+    "@mui/icons-material": "^5.2.5",
+    "@mui/material": "^5.2.5",
     "@testing-library/jest-dom": "^5.16.1",
     "@testing-library/react": "^12.1.2",
     "@testing-library/user-event": "^13.5.0",
+    "node-sass": "^7.0.0",
     "react": "^17.0.2",
     "react-dom": "^17.0.2",
+    "react-router-dom": "^5.3.0",
     "react-scripts": "5.0.0",
     "web-vitals": "^2.1.2"
   },

BIN
public/favicon.ico


+ 9 - 24
public/index.html

@@ -10,34 +10,19 @@
       content="Web site created using create-react-app"
     />
     <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
-    <!--
-      manifest.json provides metadata used when your web app is installed on a
-      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-    -->
     <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
-    <!--
-      Notice the use of %PUBLIC_URL% in the tags above.
-      It will be replaced with the URL of the `public` folder during the build.
-      Only files inside the `public` folder can be referenced from the HTML.
-
-      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
-      work correctly both with client-side routing and a non-root public URL.
-      Learn how to configure a non-root public URL by running `npm run build`.
-    -->
-    <title>React App</title>
+    <link
+            rel="stylesheet"
+            href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
+    />
+    <link
+            rel="stylesheet"
+            href="https://fonts.googleapis.com/icon?family=Material+Icons"
+    />
+    <title>ABRAXAS</title>
   </head>
   <body>
     <noscript>You need to enable JavaScript to run this app.</noscript>
     <div id="root"></div>
-    <!--
-      This HTML file is a template.
-      If you open it directly in the browser, you will see an empty page.
-
-      You can add webfonts, meta tags, or analytics to this file.
-      The build step will place the bundled scripts into the <body> tag.
-
-      To begin the development, run `npm start` or `yarn start`.
-      To create a production bundle, use `npm run build` or `yarn build`.
-    -->
   </body>
 </html>

+ 0 - 38
src/App.css

@@ -1,38 +0,0 @@
-.App {
-  text-align: center;
-}
-
-.App-logo {
-  height: 40vmin;
-  pointer-events: none;
-}
-
-@media (prefers-reduced-motion: no-preference) {
-  .App-logo {
-    animation: App-logo-spin infinite 20s linear;
-  }
-}
-
-.App-header {
-  background-color: #282c34;
-  min-height: 100vh;
-  display: flex;
-  flex-direction: column;
-  align-items: center;
-  justify-content: center;
-  font-size: calc(10px + 2vmin);
-  color: white;
-}
-
-.App-link {
-  color: #61dafb;
-}
-
-@keyframes App-logo-spin {
-  from {
-    transform: rotate(0deg);
-  }
-  to {
-    transform: rotate(360deg);
-  }
-}

+ 11 - 19
src/App.js

@@ -1,25 +1,17 @@
-import logo from './logo.svg';
-import './App.css';
+import './App.scss';
+import {Router, Route, Link, Redirect} from 'react-router-dom';
+import createHistory from "history/createBrowserHistory";
+import Header from "./components/Header";
+
+
+const history = createHistory();
 
 function App() {
   return (
-    <div className="App">
-      <header className="App-header">
-        <img src={logo} className="App-logo" alt="logo" />
-        <p>
-          Edit <code>src/App.js</code> and save to reload.
-        </p>
-        <a
-          className="App-link"
-          href="https://reactjs.org"
-          target="_blank"
-          rel="noopener noreferrer"
-        >
-          Learn React
-        </a>
-      </header>
-    </div>
-  );
+      <Router history={history}>
+       <Header/>
+      </Router>
+  )
 }
 
 export default App;

+ 1 - 0
src/App.scss

@@ -0,0 +1 @@
+

+ 201 - 0
src/components/Header.jsx

@@ -0,0 +1,201 @@
+import * as React from 'react';
+import AppBar from '@mui/material/AppBar';
+import Box from '@mui/material/Box';
+import Toolbar from '@mui/material/Toolbar';
+import IconButton from '@mui/material/IconButton';
+import Typography from '@mui/material/Typography';
+import Menu from '@mui/material/Menu';
+import MenuIcon from '@mui/icons-material/Menu';
+import Container from '@mui/material/Container';
+import Avatar from '@mui/material/Avatar';
+import Button from '@mui/material/Button';
+import Tooltip from '@mui/material/Tooltip';
+import MenuItem from '@mui/material/MenuItem';
+import SearchIcon from '@mui/icons-material/Search';
+import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
+import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
+import ManageSearchIcon from '@mui/icons-material/ManageSearch';
+import Link from "react-router-dom/es/Link";
+import '../scss/Header.scss';
+import {useState} from "react";
+
+const pages = ['catalog', 'about us', 'our team', 'faq', 'contact'];
+const settings = ['Profile', 'Account', 'Dashboard', 'Logout'];
+
+const Header = () => {
+    const [anchorElNav, setAnchorElNav] = useState(null);
+    const [anchorElUser, setAnchorElUser] = useState(null);
+
+    const handleOpenNavMenu = (event) => {
+        setAnchorElNav(event.currentTarget);
+    };
+    const handleOpenUserMenu = (event) => {
+        setAnchorElUser(event.currentTarget);
+    };
+
+    const handleCloseNavMenu = () => {
+        setAnchorElNav(null);
+    };
+    const handleCloseUserMenu = () => {
+        setAnchorElUser(null);
+    };
+
+    const LogoItem = () => {
+        return (
+            <Link to='/' className="Header__Logo"> ABRAXAS </Link>
+        )
+    }
+    const LinkItem = ({page, color='white'}) => {
+        return (
+            <Button
+                key={page}
+                onClick={handleCloseNavMenu}
+                sx={{ my: 2, color: color, display: 'block'}}
+            >
+                <Link
+                    to={`/${Array.from(page.toLowerCase()).map(i => i === ' ' ? '-' : i).join('')}`}
+                    className="Header__Link"> {page}
+                </Link>
+            </Button>
+        )
+    }
+    const IconItems = ({size="large", color='default'}) => {
+        return (
+            <>
+                <Link to='/search'>
+                    <IconButton size={size} aria-label="search" color={color}>
+                        <SearchIcon />
+                    </IconButton>
+                </Link>
+                <Link to='/my-orders'>
+                    <IconButton size={size} aria-label="my-orders" color={color}>
+                        <ManageSearchIcon />
+                    </IconButton>
+                </Link>
+                <Link to='/wish-list'>
+                    <IconButton size={size} aria-label="wish-list" color={color}>
+                        <FavoriteBorderIcon />
+                    </IconButton>
+                </Link>
+                <Link to='/basket'>
+                    <IconButton size={size} aria-label="basket" color={color}>
+                        <ShoppingCartIcon />
+                    </IconButton>
+                </Link>
+            </>
+        )
+    }
+
+    return (
+        <AppBar className='Header' position="fixed">
+            <Container maxWidth="xl">
+                <Toolbar disableGutters>
+                    {/*Основной логотип*/}
+                    <Typography
+                        variant="h6"
+                        noWrap
+                        component="div"
+                        sx={{ mr: 2, display: { xs: 'none', md: 'flex' } }}
+                    >
+                        <LogoItem/>
+                    </Typography>
+
+                    {/*Меню бургер*/}
+                    <Box sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}>
+                        <IconButton
+                            size="large"
+                            aria-label="account of current user"
+                            aria-controls="menu-appbar"
+                            aria-haspopup="true"
+                            onClick={handleOpenNavMenu}
+                            color="inherit"
+                        >
+                            <MenuIcon />
+                        </IconButton>
+                        <Menu className='Header__Burger'
+                            id="menu-appbar"
+                            anchorEl={anchorElNav}
+                            anchorOrigin={{
+                                vertical: 'bottom',
+                                horizontal: 'left',
+                            }}
+                            keepMounted
+                            transformOrigin={{
+                                vertical: 'top',
+                                horizontal: 'left',
+                            }}
+                            open={Boolean(anchorElNav)}
+                            onClose={handleCloseNavMenu}
+                            sx={{
+                                display: { xs: 'block', md: 'none' },
+                            }}
+                        >
+                            {pages.map((page) => (
+                                <MenuItem key={page} onClick={handleCloseNavMenu}>
+                                    <LinkItem page={page} color={'#fff'}/>
+                                </MenuItem>
+                            ))}
+                            <MenuItem onClick={handleCloseNavMenu}>
+                                <IconItems size={'large'} color={'inherit'}/>
+                            </MenuItem>
+                        </Menu>
+                    </Box>
+
+                    {/*Логитип для смартфонов*/}
+                    <Typography
+                        variant="h6"
+                        noWrap
+                        component="div"
+                        sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}
+                    >
+                        <LogoItem />
+                    </Typography>
+
+                    {/*Основные ссылки для декстопа*/}
+                    <Box className='Header__Links' sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
+                        {pages.map((page) => (
+                            <LinkItem page={page} color={'#fff'}/>
+                        ))}
+                    </Box>
+
+                    {/*Иконки для декстопа*/}
+                    <Box className='Header__Icons' sx={{ flexGrow: 0, display: { xs: 'none', md: 'flex' } }}>
+                        <IconItems size={'large'}/>
+                    </Box>
+
+                    {/*Пользователь*/}
+                    <Box sx={{ flexGrow: 0 }}>
+                        <Tooltip title="Open settings">
+                            <IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
+                                <Avatar alt="User" src="/static/images/avatar/2.jpg" />
+                            </IconButton>
+                        </Tooltip>
+                        <Menu
+                            sx={{ mt: '45px' }}
+                            id="menu-appbar"
+                            anchorEl={anchorElUser}
+                            anchorOrigin={{
+                                vertical: 'top',
+                                horizontal: 'right',
+                            }}
+                            keepMounted
+                            transformOrigin={{
+                                vertical: 'top',
+                                horizontal: 'right',
+                            }}
+                            open={Boolean(anchorElUser)}
+                            onClose={handleCloseUserMenu}
+                        >
+                            {settings.map((setting) => (
+                                <MenuItem key={setting} onClick={handleCloseNavMenu}>
+                                    <Typography textAlign="center">{setting}</Typography>
+                                </MenuItem>
+                            ))}
+                        </Menu>
+                    </Box>
+                </Toolbar>
+            </Container>
+        </AppBar>
+    );
+};
+export default Header;

+ 0 - 3
src/index.js

@@ -11,7 +11,4 @@ ReactDOM.render(
   document.getElementById('root')
 );
 
-// If you want to start measuring performance in your app, pass a function
-// to log results (for example: reportWebVitals(console.log))
-// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
 reportWebVitals();

+ 108 - 0
src/scss/Header.scss

@@ -0,0 +1,108 @@
+.Header {
+  padding: 10px 0;
+  &__Logo {
+    font-family: inherit;
+    text-decoration: none;
+    font-size: 27px;
+    letter-spacing: 13px;
+    font-weight: 400;
+    color: rgba(0, 0, 0, 0.54);
+    user-select: none;
+    text-transform: uppercase;
+    @media (max-width: 1100px) {
+      &{
+        font-size: 24px;
+        letter-spacing: 10px;
+      }
+    }
+    @media (max-width: 425px) {
+      &{
+        font-size: 22px;
+        letter-spacing: 7px;
+      }
+    }
+  }
+  &__Icons {
+    margin-right: 30px;
+    @media (max-width: 1100px) {
+      &{
+        margin-right: 20px;
+      }
+    }
+    button {
+      @media (max-width: 1100px) {
+        &{
+          padding: 5px;
+        }
+      }
+      &:hover{
+        transform: scale(1.2);
+        background-color: transparent;
+        transition: all 0.3s;
+      }
+    }
+  }
+  &__Links {
+    display: flex;
+    flex-direction: row;
+    justify-content: center;
+    align-items: center;
+  }
+  &__Link {
+    margin: 0 10px;
+    font-weight: 500;
+    font-size: 13px;
+    letter-spacing: 2px;
+    text-decoration: none;
+    color: inherit;
+    text-align: center;
+    text-transform: uppercase;
+    position: relative;
+    @media (max-width: 1100px) {
+      &{
+        margin: 0 5px;
+        letter-spacing: 1px;
+      }
+    }
+    &:after {
+      content: '';
+      display: block;
+      position: absolute;
+      width: 100%;
+      left: 0;
+      bottom: -10px;
+      height: 2px;
+      background-color: #fff;
+      opacity: 0;
+      visibility: hidden;
+      transition: opacity 0.3s linear, visibility 0.3s linear, color 0.15s linear, border-color 0.15s linear, background-color 0.15s linear, box-shadow 0.15s linear;
+    }
+    &:hover:after {
+      opacity: 1;
+      visibility: visible;
+    }
+  }
+  &__Burger {
+    background-color: rgba(0, 0, 0, 0.2);
+    .MuiPaper-root {
+      width: 100%;
+      background-color: rgba(0, 0, 0, 0.8);
+      a {
+        color: #fff;
+      }
+      li {
+        display: flex;
+        justify-content: center;
+        max-height: 40px;
+        width: 100%;
+        button {
+          text-align: center;
+        }
+        &:last-child{
+          display: flex;
+          justify-content: space-around;
+        }
+      }
+    }
+  }
+}