-
Notifications
You must be signed in to change notification settings - Fork 4
✨ Feat: 토스트 컴포넌트 구현 #15
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,16 @@ | ||
| import { useRouter } from 'next/router'; | ||
|
|
||
| interface FrameProps { | ||
| title: string; | ||
| content: string; | ||
| buttonText: string; | ||
| address: string; | ||
| } | ||
|
|
||
| const Frame = ({ title, content, buttonText, address }: FrameProps) => { | ||
| const router = useRouter(); | ||
| const Frame = ({ title, content }: FrameProps) => { | ||
| return ( | ||
| <> | ||
| <section className='flex flex-col gap-4 px-3 py-10 tablet:px-8 tablet:py-[60px] desktop:px-[237px] desktop:py-[60px]'> | ||
| <h1 className='text-xl font-bold text-black tablet:text-[28px]'>{title}</h1> | ||
|
||
| <div className='flex flex-col items-center justify-center gap-4 rounded-xl border border-solid border-gray-200 px-6 py-[60px]'> | ||
| <h2 className='text-sm font-normal text-black tablet:text-base'>{content}</h2> | ||
|
||
| <button | ||
| onClick={() => router.push(`/${address}`)} | ||
| className='rounded-md bg-[#ea3c12] px-5 py-[10px] text-sm font-bold text-white tablet:px-[136px] tablet:py-[14px] tablet:text-base' | ||
| > | ||
| {buttonText} | ||
| </button> | ||
| {/* 버튼 컴포넌트 넣을 자리 */} | ||
| </div> | ||
| </section> | ||
| </> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { createContext, ReactNode, useContext, useState } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
|
|
||
| interface ToastContextType { | ||
| showToast: (message: string) => void; | ||
| } | ||
|
|
||
| const ToastContext = createContext<ToastContextType | null>(null); | ||
|
|
||
| export const useToast = () => { | ||
| const ctx = useContext(ToastContext); | ||
| if (!ctx) throw new Error('useToast 는 Provider 안에서 사용해주세요'); | ||
| return ctx; | ||
| }; | ||
|
|
||
| const ToastProvider = ({ children }: { children: ReactNode }) => { | ||
| const [message, setMessage] = useState<string | null>(null); | ||
|
|
||
| const showToast = (msg: string) => { | ||
| setMessage(msg); | ||
| setTimeout(() => setMessage(null), 3000); | ||
|
||
| }; | ||
|
|
||
| const toastRoot = typeof window !== 'undefined' ? document.getElementById('toast-root') : null; | ||
|
|
||
| return ( | ||
| <> | ||
| <ToastContext.Provider value={{ showToast }}> | ||
| {children} | ||
| {toastRoot && | ||
| createPortal( | ||
| message ? ( | ||
| <div className='fixed bottom-28 right-[38%] rounded-[5px] bg-red-300 px-4 py-[10px] text-white tablet:right-2/4'> | ||
|
||
| {message} | ||
| </div> | ||
| ) : null, | ||
| toastRoot | ||
| )} | ||
| </ToastContext.Provider> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default ToastProvider; | ||
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.
desktop:px-[237px] 이부분은 container로 만들면 될것같습니다 !
container 아예 유동적으로 사용할 수 있도록 조금 변경해둘게요!
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.
네 알겠습니다~!