Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Team23] Tab section 구현, 컴포넌트 트리 구조 추가 #17

Merged
merged 12 commits into from
Apr 23, 2021
8 changes: 6 additions & 2 deletions banchan/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import "./App.css";
import StateProvider from "./components/StateProvider";
import { createGlobalStyle } from "styled-components";
import { ThemeProvider } from "styled-components";
import theme from "./components/utils/styles/theme";

export const GlobalStyle = createGlobalStyle`
*{
padding:0;
margin:0;
}
body{
font-family: 'Noto Sans KR';
box-sizing:border-box;

}
ol, ul {
list-style: none;
Expand All @@ -17,10 +21,10 @@ export const GlobalStyle = createGlobalStyle`

function App() {
return (
<>
<ThemeProvider theme={theme}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p5] 테마 활용 좋네요. 👍

<GlobalStyle />
<StateProvider />
</>
</ThemeProvider>
);
}

Expand Down
7 changes: 4 additions & 3 deletions banchan/src/components/StateProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { useState } from "react";
import Header from "./header/Header";
import MainPage from "./main/MainPage";
import styled, { injectGlobal } from "styled-components";
import Test from "./Test";

const StateProvider = (props) => {
const [loginState, setLoginState] = useState(false);
const StateProvider = () => {
// const [loginState, setLoginState] = useState(false);
// login해서 상태값 받아와야 함

return (
<>
<Header />
<MainPage />
<Test />
</>
);
};
Expand Down
12 changes: 6 additions & 6 deletions banchan/src/components/header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import HeaderLeft from "./headerLeft/HeaderLeft";
import HeaderRight from "./headerRight/HeaderRight";
import styled from "styled-components";

const HeaderContainer = styled.div`
display: flex;
justify-content: space-between;
margin: 32px 80px 20px 80px;
`;
import { CenterContainer } from "../utils/styles/common";

const Header = () => {
return (
Expand All @@ -17,4 +12,9 @@ const Header = () => {
);
};

const HeaderContainer = styled(CenterContainer)`
justify-content: space-between;
margin: 32px 80px 20px 80px;
`;

export default Header;
30 changes: 12 additions & 18 deletions banchan/src/components/header/headerLeft/HeaderLeft.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import styled, { ThemeProvider } from "styled-components";
import theme from "../../utils/constant.js";
import styled from "styled-components";
import HeaderNavbar from "./HeaderNavbar.jsx";
import { CenterContainer } from "../../utils/styles/common.jsx";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p4] path를 편리하게 관리하기 위해 alias를 활용하면 좋을 것 같아요. eject 후 빌드 설정을 수정하는 방법이 있고, craco 와 같은 라이브러리를 활용하는 방법도 있습니다! 😀


const HeaderLeftDiv = styled.div`
display: flex;
align-items: center;
font-family: Noto Sans KR;
`;
const HeaderLeft = () => {
return (
<HeaderLeftDiv>
<BanchanTitle>BANCHAN</BanchanTitle>
<HeaderNavbar />
</HeaderLeftDiv>
);
};

const HeaderLeftDiv = styled(CenterContainer)``;

const BanchanTitle = styled.div`
color: ${(props) => props.theme.colors.darkGray};
Expand All @@ -15,15 +20,4 @@ const BanchanTitle = styled.div`
margin-right: 12px;
`;

const HeaderLeft = () => {
return (
<ThemeProvider theme={theme}>
<HeaderLeftDiv>
<BanchanTitle>BANCHAN</BanchanTitle>
<HeaderNavbar />
</HeaderLeftDiv>
</ThemeProvider>
);
};

export default HeaderLeft;
20 changes: 7 additions & 13 deletions banchan/src/components/header/headerLeft/HeaderNavbar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import styled, { ThemeProvider } from "styled-components";
import theme from "../../utils/constant";
import styled from "styled-components";
import NavListItems from "./NavListItems";

const HeaderNavbar = (props) => {
Expand All @@ -19,21 +18,16 @@ const HeaderNavbar = (props) => {
},
];

const NavUL = styled.ul`
display: flex;
color: ${(props) => props.theme.colors.darkGray};
font-size: ${(props) => props.theme.fontSizes.S};
`;

const navbarList = navLists.map((list, i) => (
<NavListItems key={i} list={list} />
));

return (
<NavUL>
<ThemeProvider theme={theme}>{navbarList}</ThemeProvider>
</NavUL>
);
return <NavUL>{navbarList}</NavUL>;
};
const NavUL = styled.ul`
display: flex;
color: ${(props) => props.theme.colors.darkGray};
font-size: ${(props) => props.theme.fontSizes.S};
`;

export default HeaderNavbar;
79 changes: 39 additions & 40 deletions banchan/src/components/header/headerLeft/NavListItems.jsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import React, { useState } from "react";
import styled, { ThemeProvider } from "styled-components";
import theme from "../../utils/constant";
import styled from "styled-components";

const NavListItems = ({ list }) => {
const NavLITitle = styled.span`
&:hover {
font-weight: bold;
}
`;
const [isMouseOver, setIsMouseOver] = useState(false);
const NavLI = styled.li`
margin: 0 12px;
`;

const NavLIBox = styled.ul`
padding: 5px 7px;
display: flex;
flex-direction: column;
min-width: 100px;
min-height: 86px;
background: #ffffff;
box-shadow: 0px 0px 4px rgba(204, 204, 204, 0.5),
0px 2px 4px rgba(0, 0, 0, 0.25);
position: absolute;
top: 65px;
`;

const SubElementsLI = styled.li`
margin: 3px 0;
&:first-child {
font-weight: bold;
text-decoration: underline;
color: ${(props) => props.theme.colors.darkGray};
}
color: ${(props) => props.theme.colors.gray};
font-weight: "400";
`;

const handleMouseEnter = () => {
setIsMouseOver((isMouseOver) => (isMouseOver = true));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p5] setIsMouseOver(true);로 바로 설정해도 되지 않나요? 혹시 이렇게 작성하신 이유가 있을까요? 🧐

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 그러네요? 당시엔 잘 안보였던 것 같습니다.. 감사합니다 :)

Expand All @@ -50,13 +17,45 @@ const NavListItems = ({ list }) => {
));

return (
<ThemeProvider theme={theme}>
<NavLI onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
<NavLITitle>{list.title}</NavLITitle>
{isMouseOver && <NavLIBox>{listSubElements}</NavLIBox>}
</NavLI>
</ThemeProvider>
<NavLI onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
<NavLITitle>{list.title}</NavLITitle>
{isMouseOver && <NavLIBox>{listSubElements}</NavLIBox>}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p5] 개인적으로는 현재 마우스 오버 이벤트가 컴포넌트를 보여주고, 숨기기 위한 처리라면 css hover로 처리하는 것도 좋지 않을까 싶습니다! (혹 다른 이벤트나 동작을 추가할 경우가 아니라면요!) 😀. 성능적인 면에서도 css로 조절이 가능한 부분은 최대한 css를 활용하시는 것을 추천합니다.

</NavLI>
);
};

const NavLITitle = styled.span`
&:hover {
font-weight: bold;
}
`;

const NavLI = styled.li`
margin: 0 12px;
`;

const NavLIBox = styled.ul`
padding: 5px 7px;
display: flex;
flex-direction: column;
min-width: 100px;
min-height: 86px;
background: #ffffff;
box-shadow: 0px 0px 4px rgba(204, 204, 204, 0.5),
0px 2px 4px rgba(0, 0, 0, 0.25);
position: absolute;
top: 65px;
`;

const SubElementsLI = styled.li`
margin: 3px 0;
&:first-child {
font-weight: bold;
text-decoration: underline;
color: ${(props) => props.theme.colors.darkGray};
}
color: ${(props) => props.theme.colors.gray};
font-weight: "400";
`;

export default NavListItems;
55 changes: 34 additions & 21 deletions banchan/src/components/header/headerRight/HeaderRight.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import styled, { ThemeProvider } from "styled-components";
import theme from "../../utils/constant";
import styled from "styled-components";
import IconButton from "../../utils/button/IconButton";
import { CenterContainer } from "../../utils/styles/common";

const HeaderRight = (props) => {
const HeaderRightDiv = styled.div`
display: flex;
align-items: center;
`;

const StyledSpan = styled.span`
margin: 0 12px;
font-size: ${(props) => props.theme.fontSizes.S};
font-family: "Noto Sans KR";
cursor: pointer;
&:hover {
font-weight: bold;
}
`;

const tempFn = () => {
console.log("hello");
};
return (
<HeaderRightDiv>
<ThemeProvider theme={theme}>
<SearchBox>
<input />
<StyledSpan>로그인</StyledSpan>
<StyledSpan>장바구니</StyledSpan>
</ThemeProvider>
<IconButton type="SEARCH" fn={tempFn} />
</SearchBox>
<StyledSpan>로그인</StyledSpan>
<StyledSpan>장바구니</StyledSpan>
</HeaderRightDiv>
);
};

const HeaderRightDiv = styled(CenterContainer)`
justify-content: start;
`;

const StyledSpan = styled.span`
margin: 0 12px;
font-size: ${(props) => props.theme.fontSizes.S};
cursor: pointer;
&:hover {
font-weight: bold;
}
`;
const SearchBox = styled(CenterContainer)`
justify-content: space-between;
border-radius: ${(props) => props.theme.borders.radius};
background: ${(props) => props.theme.colors.lightGrayBG};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p5] css를 styled components의 장점을 활용해서 사용하시는 부분이 좋네요. 👍

width: 248px;
height: 40px;
padding: 0 10px 0 15px;
input {
all: unset;
}
`;
export default HeaderRight;
3 changes: 0 additions & 3 deletions banchan/src/components/main/BestSidedish.jsx

This file was deleted.

10 changes: 5 additions & 5 deletions banchan/src/components/main/CarouselSection.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useEffect, useState } from 'react';
import Card from '../utils/Card';
import theme from '../utils/constant';
import { useEffect, useState } from "react";
import Card from "../utils/Card";
import theme from "../utils/styles/theme";

const CarouselSection = (props) => {
const [products, setProducts] = useState([]);

useEffect(() => {
fetch(
'https://h3rb9c0ugl.execute-api.ap-northeast-2.amazonaws.com/develop/baminchan/main'
"https://h3rb9c0ugl.execute-api.ap-northeast-2.amazonaws.com/develop/baminchan/main"
)
.then((response) => response.json())
.then((result) => setProducts(result.body))
.then((error) => console.log('error', error));
.then((error) => console.log("error", error));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[p4] fetch api를 편리하게 사용하기 위한 custom hook을 만들어보시는 것도 추천합니다.

}, []);

return (
Expand Down
12 changes: 10 additions & 2 deletions banchan/src/components/main/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import CarouselSection from './CarouselSection';
import CarouselSection from "./CarouselSection";
import TabSection from "./tab/TabSection";

const MainPage = (props) => <CarouselSection />;
const MainPage = (props) => {
return (
<>
<TabSection />
<CarouselSection />
</>
);
};

export default MainPage;
Loading