Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- npm install
- 이미지반응형
- MediaQuery
- npm start
- 그누보드반응형
- maxwidth
- legacy-peer
- owlcarousel
- minwidth
- 웹아이콘
- fontawesome
- XEIcon
- Git clone
- node 오류
- slickslider
- 아이콘사용법
- 단어단위로떨어지기
- npm install 문제
- 동적객체
- 정적객체
- vscode git clone
- 플러그인
- node설치
- react npm install
- window 정책변경
- 글자들여쓰기
- package.json
- googleicon
- git lab clone
- 의존성문제
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
토스트 팝업 컴포넌트 본문
728x90
export enum PopupPosition{
Top = 'top',
Bottom = 'bottom',
Left = 'left',
Right = 'right',
Center = 'center'
}
interface ToastPopupProps{
message: string;
duration: number;
position: PopupPosition;
btnText: string;
isOpen: boolean;
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
}
const ToastPopup = ({
message = '토스트 팝업입니다.',
duration = 3000,
position,
btnText = 'x',
isOpen,
setIsOpen
}: ToastPopupProps) => {
useEffect(() => {
if(!isOpen) return;
if(duration <= 0) return; // duration이 0이면 자동 닫힘 안함
const timer = setTimeout(() => {
setIsOpen(false);
}, duration);
return () => clearTimeout(timer);
}, [duration, isOpen]);
return(
<>
<Button
text={btnText}
onClick={() => {
setIsOpen(true)
}}
className="btn_pop"
/>
{isOpen && (
<div className={`
toast_popup
${position ? position.toLowerCase() : ''}
`}>
<div className="txt">{message}</div>
<Button
text={'x'}
onClick={() => setIsOpen(false)}
/>
</div>
)}
</>
)
}
사용방법
<ToastPopup
message="3초후 없어집니다."
position={PopupPosition.Top}
btnText="토스트 팝업"
isOpen={isOpen3}
setIsOpen={setIsOpen3}
duration={3000}
/>
css
/* 토스트 팝업 */
.toast_popup{
z-index:100;
position:fixed;
left:0;
top:0;
display:flex;
align-items:center;
padding:5px 10px 5px 15px;
border-radius:10px;
background:#c0d1f3;
}
.toast_popup .btn{
padding:5px;
background:#c0d1f3;
}
728x90
'개발 > 🔵 React-TypeScript' 카테고리의 다른 글
| 팝업 컴포넌트 5차 (position 개선_유니온 / enum 방법) (0) | 2025.09.19 |
|---|---|
| 팝업 컴포넌트 4차 (외부 감지 + 버튼에 토글 동작 겹치는 이슈 해결하기) (0) | 2025.09.19 |
| 팝업 컴포넌트 3차 (버튼 props로 받기) (0) | 2025.09.18 |
| 팝업 컴포넌트 2차 (외부 클릭시, esc 닫힘_useRef 사용) (0) | 2025.09.18 |
| 팝업 컴포넌트 1차 (0) | 2025.09.18 |
Comments
