2021. 12. 26. 18:39ใWEB Dev/ToyProject
๐ท 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 ์ปดํฌ๋ํธ๊ฐ ๋ ๋ง์ ๊ฑฐ ๊ฐ๋ค.
์๋ฌดํผ ์ด๋ ๊ฒ๋ผ๋ ๋ง๋ฌด๋ฆฌํ ์ ์์ด์ ๋คํ์ด๋ค.....
'WEB Dev > ToyProject' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ToyProject-Todomate] ํฌ๋๋ฉ์ดํธ ํด๋ก ํ๋ก์ ํธ 19 (0) | 2021.12.28 |
---|---|
[ToyProject-Todomate] ํฌ๋๋ฉ์ดํธ ํด๋ก ํ๋ก์ ํธ 18 (0) | 2021.12.28 |
[ToyProject-Todomate] ํฌ๋๋ฉ์ดํธ ํด๋ก ํ๋ก์ ํธ 16 (0) | 2021.12.26 |
[ToyProject-Todomate] ํฌ๋๋ฉ์ดํธ ํด๋ก ํ๋ก์ ํธ 15 (0) | 2021.12.22 |
[ToyProject-Todomate] ํฌ๋๋ฉ์ดํธ ํด๋ก ํ๋ก์ ํธ 14 (0) | 2021.12.21 |