Card.js
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from "react";
import styled, { css } from "styled-components";
function Card({ question, answer, setAnswer, curIdx, setCurIdx }) {
const CardWrap = styled.div`
display: flex;
flex-direction: column;
align-items: center;
min-width: 500px;
height: 100%;
font-size: 20px;
font-weight: bold;
/* ${(props) => css`
transform: translateX(${-500 * props.curIdx}px);
transition: 0.5s;
`} */
`;
const CardQuest = styled.div`
font-size: 20px;
font-weight: bold;
margin-bottom: 60px;
`;
const CardContent = styled.div`
cursor: pointer;
width: 300px;
height: 60px;
margin: 10px;
font-size: 16px;
border-radius: 10px;
color: #ffffff;
background-color: #536349;
display: flex;
justify-content: center;
align-items: center;
`;
const onClickOne = () => {
const temp = [
...answer,
{
num: question.num,
choice: 0,
},
];
setAnswer(temp);
setCurIdx(curIdx + 1);
};
const onClickTwo = () => {
const temp = [
...answer,
{
num: question.num,
choice: 1,
},
];
setAnswer(temp);
setCurIdx(curIdx + 1);
};
return (
<>
<CardWrap curIdx={curIdx}>
<CardQuest>{question.question}</CardQuest>
<CardContent onClick={onClickOne}>{question.answer1}</CardContent>
<CardContent onClick={onClickTwo}>{question.answer2}</CardContent>
</CardWrap>
</>
);
}
// 나중에 데이터 넘어오면 넘어온 데이터로 카드 업데이트
export default Card;