๐ Modal ์ฐฝ์ด๋?
ํ์์ ์ฐ๋ฆฌ๋ "ํ์ ์ฐฝ์ด ์ฐจ๋จ๋์์ต๋๋ค" ๋ ๋ฉ์ธ์ง๋ฅผ ์ข ์ข ์ ํ๋ค.
์ฌ๊ธฐ์ ๋งํ๋ ํ์ ์ฐฝ์ ํ์ฌ ์์นํ ๋ธ๋ผ์ฐ์ ์ด์ธ์ ๋ ๋ค๋ฅธ ๋ธ๋ผ์ฐ์ ํ์ด์ง๋ฅผ ๋์ด ๊ฒ์ ๋งํ๋ค.
ํํ์ด์ง์ ์ ์ํ์ ๋ ๊ด๊ณ ๋ ๊ณต์ง ๋ฑ์ด ํ๋ฐ๋ฐ ๋ ์ฌ๋ผ์ ํด๋น ์ฐฝ์ ์ผ์ผ์ด ๋ซ์์คฌ๋ ๊ฒฝํ์ด ์์ ๊ฒ์ด๋ค.
๊ทธ์ ๋ฐํด ๊ธฐ์กด์ ๋ธ๋ผ์ฐ์ ์์ ํ๋์ ๋ ์ด์ด๋ฅผ ๊น๋ ๊ฒ์ ๋งํ๋ค. "์๋ก์ด ์ฐฝ"์ด ์๋๋ค.
ํ์ ์ฐฝ๊ณผ ๋ฌ๋ฆฌ ๋ธ๋ผ์ฐ์ ๋จ์์ ์ฐจ๋จํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฐ๋์ ํ์ํด์ผํ๋ ์ ๋ณด๋ฅผ ๋ค๋ฃจ๊ธฐ ์ข๋ค.
๊ทธ๋ฆฌ๊ณ ๊ฐ์ธ์ ์ผ๋ก UI์ ์ผ๋ก ์ ๋ฆฌ๊ฐ ์ ๋ ๋๋์ ๋ฐ์์, ์์ผ๋ก๋ ์ ์ฉํ ๊ฒ ๊ฐ๋ค.
๐ Modal ์ฐฝ์ ์ฅ๋จ์ (feat. Pop-up ์ฐฝ์ ์ฅ๋จ์ )
๊ทธ๋ ๋ค๋ฉด, Modal ์ฐฝ์ ์ฅ์ ๋ง ์๋ ? Nope.
Pop-up ์ฐฝ๊ณผ ๋น๊ตํด ์ฅ๋จ์ ์ ์ดํด๋ณด์.
โพ Pop-up ์ฐฝ
์ฅ์
โ ํ ๋ฒ ๋ง๋ค์ด ๋๋ฉด ์ฌ์ฌ์ฉ/ ์ฌํ์ฉ์ด ๊ฐ๋ฅํ๋ค
โ ํ์ด์ง๋ณ ์ด๋์ด ์์ ๋กญ๋ค. ( ์ฌ์ฉ์๋ฅผ ํ์ ์ฐฝ์ ๋ฌถ์ด๋์ง ์์ )
๋จ์
โ ํ์ ์ฐฝ์ ๋ซ๊ธฐ์ํด์๋ ์ง์ x ๋ฒํผ์ ๋๋ฌ์ผ ํ๋ค. ( ์ฌ์ฉ์ ๊ฒฝํ ์ธก๋ฉด์์ ์๋ชจ์ ์ธ ํ์์ .. )
โ ๋ธ๋ผ์ฐ์ ๋จ์์ ํ์ ์ฐฝ ์์ฒด๋ฅผ ์ฐจ๋จ๋นํ ์ ์๋ค. ( ์ํ๋ ์ด๋ฒคํธ๊ฐ ์คํ๋์ง ์์ )
โพ Modal ์ฐฝ
์ฅ์
โ ๋ ์ด์ด ์์ฒด๋ฅผ ๋ธ๋ผ์ฐ์ ์์ ๊น๊ธฐ ๋๋ฌธ์, ํด๋น ๋ ์ด์ด( ํด๋น ํ๋ฉด )๋ฅผ ๋ง์๊ป ๋์์ธํ ์ ์๋ค.
โ ๋ชจ๋ฌ์ฐฝ ์์ฒด๊ฐ ์ฐจ๋จ๋นํ๋ ๊ฒฝ์ฐ๋ ์๋ค. ( ์ํ๋ ํ๋ฆ์ ๊ตฌํํ ์ ์์ )
๋จ์
โ ๋ชจ๋ฌ์ฐฝ์ ๋์ฐ๊ณ ์ถ์ ๋จ๊ณ๋ง๋ค ์ง์ ๋ง๋ค์ด์ผ ํ๋ค.
โ ๋ชจ๋ฌ์ฐฝ์ ๋ซ๊ธฐ ์ ์๋ ํ์ด์ง๋ณ ์ด๋์ด ์์ ๋กญ์ง ์๋ค. ( ์ฌ์ฉ์๋ฅผ ๋ชจ๋ฌ์ฐฝ์ ๋ฌถ์ด ๋์ )
๐ Modal ์ฐฝ์ ๊ตฌํํด๋ณด์.
๐ ( styled-component๋ฅผ ์ฌ์ฉํ React ๊ตฌ์กฐ๋ ํ์ ํด๋ณด์. )
์ด๋ค์์ผ๋ก ๋ ๋๊ฐ ๋๋์ง ๊ถ๊ธํด์ ํ๋ํ๋ ์ฐ์ด๋ณด์๋ค.
01 ModalContainer
import { useState } from 'react';
import styled from 'styled-components';
export const ModalContainer = styled.div`
width: 100vw;
height: 100vh;
display: flex;
flex-flow: row wrep;
justify-content: center;
align-items: center;
`;
export const Modal = () => {
const [isOpen, setIsOpen] = useState(false);
const openModalHandler = () => {
setIsOpen(!isOpen);
};
return (
<>
<ModalContainer>
</ModalContainer>
</>
);
};
02 ModalBtn
export const ModalBtn = styled.button`
background-color: #4000c7;
text-decoration: none;
border: none;
padding: 20px;
color: white;
border-radius: 30px;
cursor: grab;
`;
export const Modal = () => {
const [isOpen, setIsOpen] = useState(false);
const openModalHandler = () => {
setIsOpen(!isOpen);
};
return (
<>
<ModalContainer>
<ModalBtn onClick={openModalHandler}>
{isOpen ? "Opened !" : "Open Modal"}
</ModalBtn>
</ModalContainer>
</>
);
};
03 ModalBackdrop
export const ModalBackdrop = styled.div`
width: 100%;
height: 100%;
position: fixed;
display: flex;
flex-flow: row wrep;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.5);
`;
export const Modal = () => {
const [isOpen, setIsOpen] = useState(false);
const openModalHandler = () => {
setIsOpen(!isOpen);
};
return (
<>
<ModalContainer>
<ModalBtn onClick={openModalHandler}>
{isOpen ? "Opened !" : "Open Modal"}
</ModalBtn>
{isOpen ?
<ModalBackdrop onClick={openModalHandler}>
</ModalBackdrop>
: null}
</ModalContainer>
</>
);
};
04 ModalView
export const ModalView = styled.div.attrs(props => ({
role: 'dialog'
}))`
text-align: center;
text-decoration: none;
padding: 30px 90px;
background-color: white;
border-radius: 30px;
color: #4000c7;
`;
export const Modal = () => {
const [isOpen, setIsOpen] = useState(false);
const openModalHandler = () => {
setIsOpen(!isOpen);
};
return (
<>
<ModalContainer>
<ModalBtn onClick={openModalHandler}>
{isOpen ? "Opened !" : "Open Modal"}
</ModalBtn>
{isOpen ?
<ModalBackdrop onClick={openModalHandler}>
<ModalView>
<div onClick={openModalHandler}>×</div>
<div>Hello World</div>
</ModalView>
</ModalBackdrop>
: null}
</ModalContainer>
</>
);
};
'Front-end > CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CSS ๋ฐ์ํ ๋ธ๋ผ์ฐ์ ์ ํ ์คํธ ํฌ๊ธฐ ์กฐ์ (-webkit-)text-size-adjust (0) | 2021.09.30 |
---|---|
CSS overflow ์์ฑ (1) | 2021.09.26 |
CSS font-size ์์ฑ (0) | 2021.08.09 |
CSS flex-box ์ ๋ถ๋ชจ ์์ฑ align-items (0) | 2021.08.08 |
CSS flex-box ์ ๋ถ๋ชจ ์์ฑ justify-content & align-content (0) | 2021.08.07 |
๋๊ธ