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

2021. 12. 26. 18:39ใ†WEB Dev/ToyProject

728x90


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

 

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

 


 

๋‚ด๊ฐ€ ํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ์€ MainNavBar ์ปดํฌ๋„ŒํŠธ ์•ˆ์— ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด DrawerMenu๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์ด๋‹ค.

๋”ฐ๋ผ์„œ 

 

Main > MainNavBar > DrawerMenu๊ฐ€ ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํƒœ๊ทธ์˜ ์œ„์น˜๋ฅผ ๊ทธ๋ ‡๊ฒŒ ๋ฐ”๊ฟ”์ค€๋‹ค.

 

 

Main.js

 

 

import React from 'react';
import Box from '@mui/material/Box';

import MainNavBar from './MainNavBar';
import Content from './Content';

export default function Main() {
    return (
        <Box className='main-wrap' backgroundColor='#e4f2b4' sx={{ position: 'relative', width: '100vw', height: '100vh' }}>
        <MainNavBar />
        <Content />
        </Box>
    );
}

 

MainNavBar.js

 

์—ฌ๊ธฐ์„œ <React.Fragment> ๋Š” ๋นˆ <> ํƒœ๊ทธ์ฒ˜๋Ÿผ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ๊ฐ์‹ธ๋Š” ์ตœ์ƒ๋‹จ ํƒœ๊ทธ์˜ ์—ญํ• ์„ ํ•ด์ค€๋‹ค.

 

import 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 DehazeIcon from '@material-ui/icons/Dehaze';
import DrawerMenu from './DrawerMenu';

export default function MainNavBar () {
  return (
    <React.Fragment>
    <Box>
      <AppBar position="static" color="mainnav" sx={{ boxShadow:"none", flexDirection:"row-reverse", height: '90px', borderTop: '1px solid #CCCDCD', boxSizing:'border-box' }}>
        <Toolbar>
        <IconButton
            size="large"
            edge="start"
            color="inherit"
            aria-label="back"
            sx={{ mr: 2 }}
          >
         <DehazeIcon />
          </IconButton>
        </Toolbar>
      </AppBar>
    </Box>
    <DrawerMenu anchor={'right'} />
    </React.Fragment>
  );
}

 

 

๊ทธ๋ฆฌ๊ณ  DrawerMenu.js๋ฅผ ๋‹ค์‹œ ๋งŒ๋“ค์–ด์ฃผ๋Š”๋ฐ, ๋‚˜์ค‘์— ๋‚ด๋ถ€์˜ List๋“ค์„ SNB.js ๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„๋ฆฌํ•  ๊ณ„ํš์ด๋ผ์„œ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„๋งŒ ์‚ด๋ ค๋‘์—ˆ๋‹ค.

์˜ค๋ฅธ์ชฝ์—์„œ ๋‚˜์˜ค๋Š” ๋ฐฉ์‹์˜ Drawer๊ฐ€ ํ•„์š”ํ•ด์„œ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ์œผ๋กœ ์ž‘๋™ํ•˜๋Š” ๊ธฐ๋Šฅ๋“ค์„ ๋นผ๊ณ  ์˜ˆ์‹œ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ฝ”๋“œ๋Š” ์ „๋ถ€ ์ง€์›Œ๋ฒ„๋ ธ๋‹ค.

 

import React, { useState } from "react";
import Box from "@mui/material/Box";
import Drawer from "@mui/material/Drawer";
import List from "@mui/material/List";
import Divider from "@mui/material/Divider";
import Button from "@mui/material/Button";
import ListItem from "@mui/material/ListItem";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemText from "@mui/material/ListItemText";


//ํ•˜์œ„
export default function DrawerMenu() {
  const [state, setState] = useState({ right: false });

  const toggleDrawer = (anchor, open) => (event) => {
    if (
      event.type === "keydown" &&
      (event.key === "Tab" || event.key === "Shift")
    ) {
      return;
    }

    setState({ ...state, [anchor]: open });
  };

  //list ํ‘œ์‹œ
  const list = (anchor) => (
    <Box
      sx={{ width: anchor === "top" || anchor === "bottom" ? "auto" : 200 }} //๊ฐ€๋กœ ๊ธธ์ด
      role="presentation"
      onClick={toggleDrawer(anchor, false)}
      onKeyDown={toggleDrawer(anchor, false)}
    >
      <List>
        <ListItem>
          <ListItemIcon></ListItemIcon>
          <ListItemText />
        </ListItem>
      </List>
      <Divider />
    </Box>
  );


  //๋ฒ„ํŠผ ํ‘œ์‹œ (์ƒ์œ„)
  return (
    <div>
      {["right"].map((anchor) => (
        <React.Fragment key={anchor}>
          <Button onClick={toggleDrawer(anchor, true)}>{anchor}</Button>
          <Drawer
            anchor={anchor}
            open={state[anchor]}
            onClose={toggleDrawer(anchor, false)}
          >
            {list(anchor)}
          </Drawer>
        </React.Fragment>
      ))}
    </div>
  );
}

 

 

๋‚˜๋Š” Drawer๋ฅผ ๋ณ„๋„์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“ค๊ณ  ์žˆ๋Š”๋ฐ, ์—ฌ๊ธฐ๋Š” ์ด ์ „์ฒด๊ฐ€ ๋ฒ„ํŠผ + Drawer ํ‘œ์‹œ๊ฐ€ ํ•œ๋ฒˆ์— ์žˆ๋‹ค. 

์ด๊ฑธ ๋‚˜๋ˆ„๋Š”๊ฒŒ ๋„ˆ๋ฌด ์–ด๋ ค์›Œ์„œ ์—„์ฒญ ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๊ณ  ์žˆ๋‹ค.

 

์šฐ์„  ์‹œ๊ฐ„์„ ๋‹จ์ถ•ํ•˜๊ธฐ ์œ„ํ•ด ํ•œ ์ปดํฌ๋„ŒํŠธ์— ๋‹ค ๋„ฃ๊ณ , ํด๋ฆญ ๋ฒ„ํŠผ๋งŒ ํ–„๋ฒ„๊ฑฐ๋กœ ๋ฐ”๊ฟ”๋ณธ๋‹ค.

 

 

import React, { useState } 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 DehazeIcon from '@material-ui/icons/Dehaze';
import Drawer from "@mui/material/Drawer";
import List from "@mui/material/List";
import Divider from "@mui/material/Divider";
import ListItem from "@mui/material/ListItem";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemText from "@mui/material/ListItemText";

export default function MainNavBar() {
  //ํ•˜์œ„
  const [state, setState] = useState({ right: false });

  const toggleDrawer = (anchor, open) => (event) => {
    if (
      event.type === "keydown" &&
      (event.key === "Tab" || event.key === "Shift")
    ) {
      return;
    }

    setState({ ...state, [anchor]: open });
  };

  //list ํ‘œ์‹œ
  const SNB = (anchor) => (
    <Box
      sx={{ width: anchor === "top" || anchor === "bottom" ? "auto" : 228 }} //๊ฐ€๋กœ ๊ธธ์ด
      role="presentation"
      onClick={toggleDrawer(anchor, false)}
      onKeyDown={toggleDrawer(anchor, false)}
    >
      <Box sx={{padding: "10px"}}>
        <h3>Me</h3>
        <p>todo mate</p>
        <button>๊ฐ€์ž…ํ•˜๊ธฐ</button>
      </Box>
      <List>
        <ListItem>
          <ListItemIcon></ListItemIcon>
          <ListItemText />
        </ListItem>
      </List>
      <Divider />
    </Box>
  );

  return (
    <>
      {["right"].map((anchor) => (
        <React.Fragment key={anchor}>
          <Box>
            <AppBar
              position="static"
              color="mainnav"
              sx={{
                boxShadow: "none",
                flexDirection: "row-reverse",
                height: "90px",
                borderTop: "1px solid #CCCDCD",
                boxSizing: "border-box",
              }}
            >
              <Toolbar>
                <IconButton
                  size="large"
                  edge="start"
                  color="inherit"
                  aria-label="back"
                  sx={{ mr: 2 }}
                  onClick={toggleDrawer(anchor, true)}
                >
                  <DehazeIcon />
                </IconButton>
              </Toolbar>
            </AppBar>
          </Box>
          <Drawer
            anchor={anchor}
            open={state[anchor]}
            onClose={toggleDrawer(anchor, false)}
          >
            {SNB(anchor)}
          </Drawer>
        </React.Fragment>
      ))}
    </>
  );
}

 

 

์ด๋ ‡๊ฒŒ ํ•ด์„œ ์ผ์ฃผ์ผ๋™์•ˆ ๋จธ๋ฆฌ๋ฅผ ์‹ธ๋งธ๋˜ Drawer ๋ฉ”๋‰ด๊ฐ€ ์–ด์ •์ฉกํ•˜๊ฒŒ ๋๋‚ฌ๋‹ค ใ…  ์‚ฌ์‹ค Drawer๋งŒ ๋„ฃ๊ณ  ๋‚˜๋จธ์ง€ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ ์˜คํžˆ๋ ค SNB์— ์žˆ๋Š” List ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋” ๋งŽ์„ ๊ฑฐ ๊ฐ™๋‹ค. 

์•„๋ฌดํŠผ ์ด๋ ‡๊ฒŒ๋ผ๋„ ๋งˆ๋ฌด๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด์„œ ๋‹คํ–‰์ด๋‹ค.....

 

 

 

728x90