[ToyProject-Todomate] ํˆฌ๋‘๋ฉ”์ดํŠธ ํด๋ก  ํ”„๋กœ์ ํŠธ 12

2021. 12. 19. 19:49ใ†WEB Dev/ToyProject

728x90


๐Ÿ”ท CloneTodo โ˜‘ - Todomate Clone Project  |  Team CloneMate

 

CloneTodo : ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ์‚ฌ๋ž‘ํ•˜๋Š” ํˆฌ๋‘๋ฉ”์ดํŠธ๋ฅผ ํด๋ก ํ•˜์—ฌ ์›น ์„œ๋น„์Šค๋ฅผ ๋ฐฐํฌํ•ด๋ณด๋Š” ํ”„๋กœ์ ํŠธ

 


 

๊ทธ๋Ÿผ ๊ณ„์† ์ง„ํ–‰ํ•ด๋ณด๊ธฐ!

 

์˜ค๋Š˜์˜ todo

 

โ˜‘ ๊ฐ€์ž…ํ•˜๊ธฐ ์ปดํฌ๋„ŒํŠธ

โ–ก ๊ธฐ๋ณธ NavBar ์ปดํฌ๋„ŒํŠธ

โ–ก ๋ฉ”์ธ NavBar ์ปดํฌ๋„ŒํŠธ

โ–ก ๋ฉ”์ธ Feed ์ปดํฌ๋„ŒํŠธ

 

โž• ๊ฐ€๋Šฅํ•˜๋ฉด ๊นƒํ—™ ํ˜ธ์ŠคํŒ…์œผ๋กœ ๋ฐฐํฌ๊นŒ์ง€

 

 

2. ๊ธฐ๋ณธ NavBar ์ปดํฌ๋„ŒํŠธ

 

NavBar๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์ƒˆ๋กœ์šด MUI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐพ์•„๋ณธ๋‹ค!

๊ธฐ๋ณธ NavBar๋Š” ๊ฐ ํŽ˜์ด์ง€์˜ ์ œ๋ชฉ์ด ํ‘œ์‹œ๋˜๊ณ , ๋’ค๋กœ๊ฐ€๊ธฐ๊ฐ€ ์žˆ์œผ๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํŠน๋ณ„ํ•œ ๊ธฐ๋Šฅ์€ ํ•„์š”์—†์ง€๋งŒ

๋ฉ”์ธ NavBar์˜ ๊ฒฝ์šฐ ์˜ค๋ฅธ์ชฝ์— ํŒ์—…๋˜๋Š” ๋ฉ”๋‰ด๊ฐ€ ๋“ฑ์žฅํ•ด์•ผ ํ•œ๋‹ค.

 

MUI์—์„œ Bottom Navigation์ด๋ž‘ App Bar๊ฐ€ ์ œ์ผ ๋น„์Šทํ•œ๊ฑฐ ๊ฐ™์€๋ฐ

๊ธฐ๋ณธ NavBar ์ปดํฌ๋„ŒํŠธ์—๋Š” App Bar ๋งŒ, ๋ฉ”์ธ NavBar์—๋Š” App Bar์™€ Drawer์„ ๊ฒฐํ•ฉํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค.

 

 

App Bar ๋””์ž์ธ ์ค‘์—๋Š” Basic์„ ๊ณจ๋ž๋Š”๋ฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์ƒ๊ฒผ๋‹ค.

 

์ด ์ปดํฌ๋„ŒํŠธ๋Š” ์—„์ฒญ๋‚˜๊ฒŒ ใ…‹ใ…‹ ๋งŽ์€ ํŒจํ‚ค์ง€๋ฅผ import ํ•ด์•ผํ•˜๋Š”๋ฐ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';

export default function ButtonAppBar() {
  return (
    <Box sx={{ flexGrow: 1 }}>
      <AppBar position="static">
        <Toolbar>
          <IconButton
            size="large"
            edge="start"
            color="inherit"
            aria-label="menu"
            sx={{ mr: 2 }}
          >
            <MenuIcon />
          </IconButton>
          <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
            News
          </Typography>
          <Button color="inherit">Login</Button>
        </Toolbar>
      </AppBar>
    </Box>
  );
}

 

์ด ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด BasicNavBar.js ๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์œ„์˜ ์ฝ”๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์ค€๋‹ค.

ButtonAppBar๋ผ๊ณ  ์ง€์ •๋œ ํ•จ์ˆ˜๋ช…์„ BasicNavBar๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ  ํŽ˜์ด์ง€ ์ƒ๋‹จ์— ๋“ค์–ด๊ฐˆ๊ฑฐ๊ธฐ ๋•Œ๋ฌธ์— BasicNavBar๋ฅผ App.js์˜ ์ƒ๋‹จ์— ๋„ฃ์–ด์ค€๋‹ค.

 

import React from "react";
import "../stylesheets/App.css";
import { Button  } from "@mui/material";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { Switch, Route, useHistory } from "react-router-dom";

import Signin from "./Signin";
import Join from "./Join";
import BasicNavBar from "./BasicNavBar";

const theme = createTheme({
  status: {
    danger: "#e53e3e",
  },
  palette: {
    primary: {
      main: "#0971f1",
      darker: "#053e85",
    },
    neutral: {
      main: "#64748B",
      contrastText: "#fff",
    },
    btn: {
      main: "#f2f2f2",
      contrastText: "#111",
    },
  },
});

function App() {
  let history = useHistory();

  return (
    <ThemeProvider theme={theme}>
      <BasicNavBar/>
      <Switch>
        <Route exact path="/">
          <div className="App">
            <div className="header">
              <img className="main_img" src="images/todomate.jpg" />
              <h1>todo mate</h1>
              <h3>ํ•  ์ผ์„ ์ž‘์„ฑ, ๊ณ„ํš, ๊ด€๋ฆฌํ•˜์„ธ์š”.</h3>
            </div>
            <div className="start_btn">
              <Button 
                className="join_btn" 
                color="btn"
                variant="contained" 
                onClick={() => {
                  history.push("/join");
                }}
              >
                ๊ฐ€์ž…ํ•˜๊ธฐ
              </Button>
              <Button
                className="signin_btn"
                color="btn"
                variant="contained"
                onClick={() => {
                  history.push("/signin");
                }}
              >
                ๋กœ๊ทธ์ธ
              </Button>
            </div>
          </div>
        </Route>

        <Route exact path="/join">
          <Join />
        </Route>
        <Route exact path="/signin">
          <Signin />
        </Route>
        </Switch>

    </ThemeProvider>
  );
}

export default App;

 

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด import ๋Š” ๋˜์—ˆ๋Š”๋ฐ, BasicNavBar์™€ ๊ด€๋ จ๋œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋œฌ๋‹ค.

์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋Š” ./src/components/BasicNavBar.js  Module not found: Can't resolve '@mui/icons-material/Menu' in ...

์ด๊ฑฐ๋Š” @mui/icons-material/Menu ์™€ ๊ฐ™์€ ์•„์ด์ฝ˜ ํŒจํ‚ค์ง€๋“ค์ด npm ์„ ํ†ตํ•ด ์„ค์น˜๋˜์ง€ ์•Š์•„์„œ ๊ทธ๋Ÿด ์ˆ˜ ์žˆ๋‹ค.

 

npm i @material-ui/core
npm i @material-ui/icons

์œ„์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋“ค์„ ํ†ตํ•ด ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์ค€๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ์„ค์น˜ํ–ˆ์œผ๋‚˜ ์—ฌ์ „ํžˆ ๋˜‘๊ฐ™์€ ์ƒํ™ฉ์ธ ๊ฒฝ์šฐ, ํ•ด๋‹น ์•„์ด์ฝ˜์ด ์ง€๊ธˆ MUI์˜ ๋ฒ„์ „๊ณผ ๋งž์ง€ ์•Š์•„์„œ ๊ทธ๋Ÿด ์ˆ˜ ์žˆ๋‹ค.

(MUI์˜ ๋ฒ„์ „์€ v4์ด๋‚˜ ์•„์ด์ฝ˜์€ v5์ธ ๊ฒฝ์šฐ)

๊ทธ๋Ÿผ ๊ทธ ์•„์ด์ฝ˜์„ ์ด์ „ ๋ฒ„์ „์—์„œ ์ฐพ์•„์„œ ๋Œ€์ฒดํ•ด์•ผ ํ•œ๋‹ค!

๋‚˜์˜ ๊ฒฝ์šฐ MenuIcon ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ญ์ œํ•˜๋‹ˆ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ–ˆ๋‹ค.

๊ทธ๋ž˜์„œ MenuIcon ๋Œ€์‹  ์•„๋ž˜์˜ DehazeIcon์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ๋‹ค.

import DehazeIcon from '@material-ui/icons/Dehaze';

 

โ€ป MUI v4 ๋ฒ„์ „ Meterial-ui icons

 

Material Icons - Material-UI

1,100+ React Material icons ready to use from the official website.

v4.mui.com

 

 

๊ทธ๋Ÿฌ๋ฉด ์ด๋ ‡๊ฒŒ ์˜ˆ์œ Navbar ์™„์„ฑ๐Ÿ’™

 

 

์˜ˆ์˜๊ตฌ๋งŒ!

 

 

ํ•„์š”ํ•œ ๊ฒƒ๋“ค์„ ๋‚จ๊ธฐ๊ณ  ์ขŒ์ธก์— < ์™€ ๊ฐ™์€ ๋’ค๋กœ๊ฐ€๊ธฐ ์•„์ด์ฝ˜์„ ๋„ฃ๋Š” ๋“ฑ ์ƒ‰์ƒ๊ณผ ๋ชจ์–‘ ์ปค์Šคํ…€์„ ์ง„ํ–‰ํ•œ๋‹ค.

 

 

import React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import NavigateBeforeIcon from '@material-ui/icons/NavigateBefore';

export default function BasicNavBar () {
  return (
    <Box sx={{ flexGrow: 1 }}>
      <AppBar position="static" color="nav" sx={{ boxShadow:"none" }}>
        <Toolbar>
        <IconButton
            size="large"
            edge="start"
            color="inherit"
            aria-label="back"
            sx={{ mr: 2 }}
          >
         <NavigateBeforeIcon />
          </IconButton>
          <Typography className="navbar_title" variant="h6" component="div" color="inherit" fontSize={16} fontWeight={600} sx={{ margin: "auto", transform: "translateX(-50%)" }}>
            ์ œ๋ชฉ
          </Typography>

        </Toolbar>
      </AppBar>
    </Box>
  );
}

 

BasicNavBar ์ปดํฌ๋„ŒํŠธ์˜ CSS๋Š” props์— ๋„ฃ์–ด์„œ ๋งŒ๋“ค์–ด๋ดค๋‹ค. color๋Š” App.js ์˜ ThemeProvider์— palette์— nav ๋ผ๋Š” ์ƒ‰์ƒ๊ฐ’์„ ์คฌ๊ณ (์‚ฌ์‹ค ํฐ์ƒ‰์ด๋ฉด์„œ), sx ๋ผ๋Š” props์—์„œ ๋Œ€๋ถ€๋ถ„์˜ CSS๋ฅผ ์†๋ณผ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๊ธฐ์กด AppBar ์ปดํฌ๋„ŒํŠธ์— ์žˆ๋˜ ๋ฐฐ๊ฒฝ์ƒ‰ ๊ฐ’๊ณผ ๊ทธ๋ฆผ์ž, ํฐํŠธ ์‚ฌ์ด์ฆˆ ๋“ฑ์„ ์ˆ˜์ •ํ•˜๊ณ  margin auto๋ฅผ ์ด์šฉํ•ด ๊ธ€์ž๊ฐ€ ๊ฐ€์šด๋ฐ๋กœ ์˜ค๋„๋ก ํ•œ ๋’ค ์•ฝ๊ฐ„ ์น˜์šฐ์นœ ๊ฒƒ์€ transform์œผ๋กœ ์ˆ˜์ •ํ•˜๋Š” ๊ณ ์ „์ ์ธ CSS ์ˆ˜์ • ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

 

๊ฒฐ๊ณผ๋ฌผ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 

 

728x90