이준호

[ADD] MainPage 반응형 구현 준비 및 일부 구현

1 import React, { useEffect } from "react"; 1 import React, { useEffect } from "react";
2 import { getQuestionThunk } from "../store/action/survey"; 2 import { getQuestionThunk } from "../store/action/survey";
3 import { useDispatch } from "react-redux"; 3 import { useDispatch } from "react-redux";
4 -import soldier from '../assets/soldier.png'; 4 +import soldier from "../assets/soldier.png";
5 -import styled from "styled-components"; 5 +import styled, { css } from "styled-components";
6 -import pattern from '../assets/mainPattern.jpeg'; 6 +import pattern from "../assets/mainPattern.jpeg";
7 7
8 -const Wrapper = styled.div` 8 +const sizes = {
9 + desktop: 102.4,
10 + tablet: 76.8,
11 + phone: 36,
12 +};
13 +
14 +const media = Object.keys(sizes).reduce((acc, label) => {
15 + acc[label] = (...args) => css`
16 + @media (max-width: ${sizes[label]}rem) {
17 + ${css(...args)}
18 + }
19 + `;
20 + return acc;
21 +}, {});
22 +
23 +const WrapperContainer = styled.div`
9 width: 100%; 24 width: 100%;
10 height: 100vh; 25 height: 100vh;
26 +`;
27 +
28 +const Wrapper = styled.div`
29 + width: 100%;
30 + height: 100%;
11 background-image: url(${pattern}); 31 background-image: url(${pattern});
12 background-repeat: no-repeat; // background-image가 컨테이너를 가득 채우지 못할 경우에도 반복하지 않는다. 32 background-repeat: no-repeat; // background-image가 컨테이너를 가득 채우지 못할 경우에도 반복하지 않는다.
13 background-size: cover; // 사이즈가 container에 맞지 않아도 꽉 차도록 채운다. 33 background-size: cover; // 사이즈가 container에 맞지 않아도 꽉 차도록 채운다.
14 - background-position: center; // background-image가 컨테이너에 가운데로 오도록 한다. 34 + background-position: center; // background-image가 컨테이너에 가운데로 오도록 한다.
15 `; 35 `;
16 36
17 const Container = styled.div` 37 const Container = styled.div`
...@@ -22,40 +42,64 @@ const Container = styled.div` ...@@ -22,40 +42,64 @@ const Container = styled.div`
22 color: #ffffff; 42 color: #ffffff;
23 `; 43 `;
24 44
45 +// 반응형
25 const MainImg = styled.img` 46 const MainImg = styled.img`
26 - height: 50vh; 47 + width: 30rem;
48 + height: auto;
49 + ${media.tablet`
50 + width: 20rem;
51 + `}
27 `; 52 `;
28 53
29 const MainTitle = styled.div` 54 const MainTitle = styled.div`
30 - margin-top: 5rem; 55 + margin-top: 3rem;
31 text-align: center; 56 text-align: center;
32 font-size: 5rem; 57 font-size: 5rem;
33 font-weight: bold; 58 font-weight: bold;
59 + ${media.tablet`
60 + font-size: 4rem;
61 + `}
34 `; 62 `;
35 63
36 const MainDesc = styled.div` 64 const MainDesc = styled.div`
37 margin-top: 2rem; 65 margin-top: 2rem;
38 margin-bottom: 2rem; 66 margin-bottom: 2rem;
39 font-size: 1.5rem; 67 font-size: 1.5rem;
68 + ${media.tablet`
69 + font-size: 1.1rem;
70 + `}
71 +`;
72 +
73 +const MainBtnWrapper = styled.div`
74 + display: flex;
75 + justify-content: center;
76 + align-items: center;
77 + ${media.tablet`
78 +
79 + `}
40 `; 80 `;
41 81
42 const MainBtn = styled.div` 82 const MainBtn = styled.div`
43 - cursor: pointer; 83 + cursor: pointer;
44 - display: flex; 84 + display: flex;
45 - justify-content: center; 85 + justify-content: center;
46 - align-items: center; 86 + align-items: center;
47 - margin-top: 1rem; 87 + margin-top: 1rem;
48 - width: 25rem; 88 + margin-bottom: 2rem;
49 - height: 5rem; 89 + width: 25rem;
50 - font-size: 1.6rem; 90 + height: 5rem;
51 - font-weight: bold; 91 + font-size: 1.6rem;
52 - border-radius: 1rem; 92 + font-weight: bold;
53 - border: 1px solid #010101; 93 + border-radius: 1rem;
54 - background-color: #3c441d; 94 + border: 1px solid #010101;
55 - &:hover{ 95 + color: #ffffff;
56 - background-color: #ffffff; 96 + background-color: #3c441d;
57 - color: #010101; 97 + transform: background-color;
58 - } 98 + transition: ease-out 0.3s;
99 + &:hover {
100 + background-color: #ffffff;
101 + color: #010101;
102 + }
59 `; 103 `;
60 104
61 function MainPage({ history }) { 105 function MainPage({ history }) {
...@@ -70,17 +114,21 @@ function MainPage({ history }) { ...@@ -70,17 +114,21 @@ function MainPage({ history }) {
70 114
71 return ( 115 return (
72 <> 116 <>
73 - <Wrapper> 117 + <WrapperContainer>
74 - <Container> 118 + <Wrapper>
75 - <MainTitle>KHUSAT</MainTitle> 119 + <Container>
76 - <MainDesc> 120 + <MainTitle>KHUSAT</MainTitle>
77 - KHUSAT 특별과정, <br></br> 121 + <MainDesc>
78 - 여러분의 보직을 추천드립니다. 122 + KHUSAT 특별과정, <br></br>
79 - </MainDesc> 123 + 여러분의 보직을 추천드립니다.
80 - <MainImg src={soldier} /> 124 + </MainDesc>
81 - <MainBtn onClick={onClick}>시작하기</MainBtn> 125 + <MainImg src={soldier} />
82 - </Container> 126 + </Container>
83 - </Wrapper> 127 + <MainBtnWrapper>
128 + <MainBtn onClick={onClick}>시작하기</MainBtn>
129 + </MainBtnWrapper>
130 + </Wrapper>
131 + </WrapperContainer>
84 </> 132 </>
85 ); 133 );
86 } 134 }
......
...@@ -6,7 +6,7 @@ const Container = styled.div` ...@@ -6,7 +6,7 @@ const Container = styled.div`
6 flex-direction: column; 6 flex-direction: column;
7 justify-content: center; 7 justify-content: center;
8 align-items: center; 8 align-items: center;
9 - margin-top: 100px; 9 + margin-top: 10rem;
10 `; 10 `;
11 11
12 const Title = styled.div` 12 const Title = styled.div`
......
...@@ -3,14 +3,13 @@ import Card from "../components/card/Card"; ...@@ -3,14 +3,13 @@ import Card from "../components/card/Card";
3 import {useDispatch} from 'react-redux'; 3 import {useDispatch} from 'react-redux';
4 import {getResultThunk} from "../store/action/result"; 4 import {getResultThunk} from "../store/action/result";
5 import "antd/dist/antd.css"; 5 import "antd/dist/antd.css";
6 -import mainPattern from "../assets/mainPattern.jpeg";
7 6
8 import styled, { css } from "styled-components"; 7 import styled, { css } from "styled-components";
9 8
10 const SurveyContainer = styled.div` 9 const SurveyContainer = styled.div`
11 display: flex; 10 display: flex;
12 justify-content: center; 11 justify-content: center;
13 - background-image: url(${mainPattern}); 12 + // 얘도 배경 고려해보기
14 `; 13 `;
15 14
16 const Container = styled.div` 15 const Container = styled.div`
......