-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] Toast 컴포넌트 구현 #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for thejulge1 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 넵 링크 참고해서 코드 다시 수정해보도록 하겠습니다!👍👍
cozy-ito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <div | ||
| key={toast.id} | ||
| className={`transition-opacity duration-500 ${ | ||
| toast.isVisible ? "opacity-100" : "opacity-0" | ||
| }`} | ||
| > | ||
| <Toast label={toast.label} /> | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toast 컴포넌트에 className prop을 하나 추가해서 아래처럼 적용하면
불필요한 div 태그를 제거할 수 있을 것 같아요!
| <div | |
| key={toast.id} | |
| className={`transition-opacity duration-500 ${ | |
| toast.isVisible ? "opacity-100" : "opacity-0" | |
| }`} | |
| > | |
| <Toast label={toast.label} /> | |
| </div> | |
| <Toast | |
| key={toast.id} | |
| label={toast.label} | |
| className={cn( | |
| "transition-opacity duration-500", | |
| toast.isVisible ? "opacity-100" : "opacity-0", | |
| )} | |
| /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 말씀해주신 부분들 반영하여 코드 수정해보겠습니다!!😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/comopnents/Toast/Toast.tsx가 있고
src/components/Toast.tsx 두 가지 파일이 존재해보입니다!
필요하지 않은 하나는 제거 해주세요! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 넵 수정하겠습니다!
almighty55555
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다~!!
src/components/Toast/Toast.tsx
Outdated
| return ( | ||
| <div className="relative inline-block rounded-md bg-red-30 px-4 py-[10px] text-white body1-regular"> | ||
| {label} | ||
| {onClose && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피그마 상으로 닫는 버튼을 쓸 일이 없는 것 같은데 구현하신 이유가 궁금합니당
어차피 아래 ToastContainer 코드에서 핸들러로 onClose를 누락시키는 것 같기도 하구요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 나중에 필요할까 싶어 남겨두긴 했는데 없어도 괜찮을 것 같네요ㅎㅎ😊 해당 부분 수정하겠습니다!
src/hooks/useToast.tsx
Outdated
| showToast: (label) => { | ||
| const id = Date.now(); | ||
| set((state) => ({ | ||
| toasts: [...state.toasts, { id, label, isVisible: true }], | ||
| })); | ||
|
|
||
| setTimeout(() => { | ||
| set((state) => ({ | ||
| toasts: state.toasts.map((toast) => | ||
| toast.id === id ? { ...toast, isVisible: false } : toast, | ||
| ), | ||
| })); | ||
|
|
||
| setTimeout(() => { | ||
| set((state) => ({ | ||
| toasts: state.toasts.filter((toast) => toast.id !== id), | ||
| })); | ||
| }, 500); | ||
| }, 1000); | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제 생각이지만 .. 중첩 setTimeout은 async/await으로 개선이 가능해보여요. 아래처럼 작성하면 구조가 간결화되어서 가독성이 좋아지지 않을까 합니당. Just 제안입니다!!
| showToast: (label) => { | |
| const id = Date.now(); | |
| set((state) => ({ | |
| toasts: [...state.toasts, { id, label, isVisible: true }], | |
| })); | |
| setTimeout(() => { | |
| set((state) => ({ | |
| toasts: state.toasts.map((toast) => | |
| toast.id === id ? { ...toast, isVisible: false } : toast, | |
| ), | |
| })); | |
| setTimeout(() => { | |
| set((state) => ({ | |
| toasts: state.toasts.filter((toast) => toast.id !== id), | |
| })); | |
| }, 500); | |
| }, 1000); | |
| }, | |
| showToast: async (label) => { | |
| const id = Date.now(); | |
| set((state) => ({ | |
| toasts: [...state.toasts, { id, label, isVisible: true }], | |
| })); | |
| await new Promise((r) => setTimeout(r, 1000)); | |
| set((state) => ({ | |
| toasts: state.toasts.map((t) => | |
| t.id === id ? { ...t, isVisible: false } : t | |
| ), | |
| })); | |
| await new Promise((r) => setTimeout(r, 500)); | |
| set((state) => ({ | |
| toasts: state.toasts.filter((t) => t.id !== id), | |
| })); | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀해주신 부분들 반영하여 코드 수정하도록 하겠습니다!!😊

#️⃣연관된 이슈
📝 PR 유형
📝작업 내용
Toast공통 컴포넌트 구현Toast컴포넌트 페이지 작성스크린샷 (선택)
💬리뷰 요구사항(선택)