Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프론트엔드 성능 최적화 가이드
- package management
- 브라우저의 렌더링 과정
- js pattern
- 커리어
- 자바스크립트 딥다이브
- 학습내용정리
- middleware pattern
- 블로그 서비스 최적화
- 스코프
- 제너레이터와 async/await
- peerdependencies
- const
- DOM
- 진행기록
- 자바스크립트
- Babel과 Webpack
- version management
- 모던 자바스크립트 Deep Dive
- pr review
- unique identifiers
- 자바스크립트 패턴
- 이벤트
- 올림픽 통계 서비스 최적화
- mixin pattern
- 프로그래머스
- 이미지 갤러리 최적화
- 새 코드 받아오기
- 딥다이브
- js pattern
Archives
- Today
- Total
Dev Blog
20210225 9일차 모달창 본문
소셜 로그인 모달창을 구현했다.
리액트 모달 라이브러리를 사용하여 구현했는데, 처음에 모달 작동 방식이 살짝 이해가 가지 않아 시간이 걸렸다.
뿐만 아니라, 타입스크립트를 적용해야 했기에 구글링에 정성을 기울였다.
관련 코드는 다음과 같다.
signin 컴포넌트
hooks 를 이용하여 모달창 상태를 저장했고, socialSignin 컴포넌트에
modalIsOpen(: boolean) 상태와 상태변경 함수인 setIsOpen 를 props 로 전달하여
상태가 true 일 때에 모달창을 열리게 했다.
만약 뒤로가기 버튼을 누르면 setIsOpen 함수를 호출하여 상태를 false 로 바꾸어 주어 모달창이 닫히게 했다.
import { findByLabelText } from "@testing-library/react";
import React, { ReactElement } from "react";
import styled, { keyframes } from "styled-components";
import SocialModal from "../components/socialSignin";
export default function Signin(): ReactElement {
// let subtitle: any;
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
const Main = styled.div`
/* border: 10px solid yellow; */
flex-grow: 0.1;
display: flex;
justify-content: space-around;
margin-bottom: 2rem;
`;
const Input = styled.div`
/* border: 3px solid black; */
margin-right: 4rem;
display: flex;
flex-direction: column;
justify-content: center;
`;
const InputBox = styled.label`
// border: 1px solid blue;
font-size: 1rem;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
margin-top: 0.5rem;
`;
const InputInfo = styled.input`
// color: palevioletred;
font-size: 1.2rem;
border: 2px solid palevioletred;
width: 100%;
/* margin-top: 5rem; */
background-color: #dcdcdc;
`;
const Button = styled.div`
/* border: 4px solid green; */
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 9rem;
`;
const ClickButton = styled.div`
// border: 1px solid black;
width: 8rem;
height: 4rem;
display: flex;
align-items: center;
`;
const ButtonSole = styled.button`
// border: 1px solid black;
width: 5rem;
height: 3rem;
margin: 0.3rem;
overflow: hidden;
text-overflow: ellipsis;
`;
const fontstyle = {
fontSize: "1rem",
marginRight: "0.2rem",
};
const formStyle = {
display: "flex",
width: "35rem",
};
return (
<Main>
<form action="" method="" style={formStyle}>
<Input>
<InputBox>
<div style={fontstyle}>이름 쓰는곳</div>
<div>
<InputInfo className="inputInfo" type="text" id="useremail" placeholder="전자우편을 입력하세요" />
</div>
</InputBox>
<InputBox>
<div style={fontstyle}>암호 쓰는곳</div>
<div>
<InputInfo className="inputInfo" type="text" id="password" placeholder="암호를 입력하세요" />
</div>
</InputBox>
</Input>
<Button>
<ClickButton>
<ButtonSole type="submit">입장 하기</ButtonSole>
<ButtonSole type="button">입학 하기</ButtonSole>
</ClickButton>
<ClickButton>
<ButtonSole type="submit">로그 아웃</ButtonSole>
<ButtonSole type="button" onClick={openModal}>
소샬 로그인
</ButtonSole>
</ClickButton>
<SocialModal modalIsOpen={modalIsOpen} setIsOpen={setIsOpen} />
</Button>
</form>
</Main>
);
}
socialSignin 컴포넌트(모달창)
import React, { ReactElement } from "react";
import styled, { keyframes } from "styled-components";
import Modal from "react-modal";
import googleLogo from "../assets/images/socialsignin/google.png";
import kakaoLogo from "../assets/images/socialsignin/kakao.png";
import githubLogo from "../assets/images/socialsignin/github.png";
Modal.setAppElement("#root");
interface Props {
modalIsOpen: boolean;
setIsOpen: any;
}
export default function SocialModal(props: Props): ReactElement {
const { modalIsOpen, setIsOpen } = props;
function closeModal() {
setIsOpen(false);
}
const ModalStyles = {
content: {
margin: "auto",
width: "35rem",
height: "25rem",
background: "#f3f3e9",
display: "flex",
alignItems: "center",
},
};
const ModalBox = styled.div`
/* border: 10px solid yellow; */
margin: auto;
/* padding-left: 4rem; */
width: 45rem;
height: 20rem;
display: flex;
flex-direction: column;
justify-content: space-around;
`;
const Title = styled.div`
/* border: 1px solid red; */
font-size: 2rem;
font-weight: bold;
text-align: center;
`;
const Buttons = styled.div`
/* border: 1px solid red; */
display: flex;
justify-content: center;
`;
const BackBtn = styled.div`
/* border: 1px solid red; */
display: flex;
justify-content: flex-end;
padding-right: 3rem;
`;
const logoStyle = {
margin: "1rem",
width: "5rem",
};
const btnStyle = {
border: "1px solid black",
width: "5rem",
height: "3rem",
fontSize: "1rem",
};
return (
<Modal isOpen={modalIsOpen} style={ModalStyles}>
<ModalBox>
<Title>쏘샬 로그인으로 입장하기</Title>
<Buttons>
<img src={googleLogo} style={logoStyle} alt="" />
<img src={kakaoLogo} style={logoStyle} alt="" />
<img src={githubLogo} style={logoStyle} alt="" />
</Buttons>
<BackBtn>
<button onClick={closeModal} type="button" style={btnStyle}>
뒤로 가기
</button>
</BackBtn>
</ModalBox>
</Modal>
);
}
참고했던 사이트
'BootCamp_Codestates > Final Project' 카테고리의 다른 글
20210227 11일차 재충전 (0) | 2021.03.01 |
---|---|
20210226 10일차 반응형웹_미디어쿼리 (0) | 2021.02.27 |
20210224 8일차 깃 지옥. (0) | 2021.02.25 |
20210223 7일차 page, component 개발 (0) | 2021.02.24 |
20210222 6일차 Component 개발 (0) | 2021.02.23 |
Comments