Skip to content
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

Modal창 사용법 #2

Open
tkv00 opened this issue Sep 11, 2024 · 0 comments
Open

Modal창 사용법 #2

tkv00 opened this issue Sep 11, 2024 · 0 comments
Assignees
Labels
✨feat 기능 개발

Comments

@tkv00
Copy link
Contributor

tkv00 commented Sep 11, 2024

구현 모습

스크린샷 2024-09-11 14 23 13

구현 경로

/src/components/common/Modal.jsx
/src/components/common/Header.jsx

구현 내용

import Button from "./Button";
import ReactDOM from "react-dom";
export default function Modal({
  title,
  inputText,
  onClick,
  type,
  isOpen,
  onClose,
}) {
  if (!isOpen) return null;

  return ReactDOM.createPortal(
    <div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm z-50">
      <div className="bg-white p-10 rounded-2xl shadow-global min-w-[60vw] h-80 flex flex-col gap-4 relative z-5">
        <h2 className="font-['BagelFatOne'] text-4xl">{title}</h2>
        <input
          className=" border-solid border-black border-[1px] h-14 p-3 rounded-full"
          type="text"
          placeholder={inputText}
        ></input>
        <Button text={"확인"} type={type} isValid={true} onClick={onClick} />
        <button
          className="absolute top-5 right-5 font-bold text-3xl"
          onClick={onClose}
        >
          &times;
        </button>
      </div>
    </div>,
    document.getElementById("modal")
  );
}

사용예시

 const [openModal, setOpenModal] = useState(false);
  //모달창 닫기
  const onClose = () => {
    setOpenModal(false);
  };


<Modal
        title="친구 추가"
        inputText="친구의 아이디를 입력하세요."
        onClick={onClick}
        type="submit"
        onClose={onClose}
        isOpen={openModal}
      />

title : 모달창 표시 제목
inputText : 모달창 입력창 placeholder
onClick : 확인 버튼 클릭 시 수행 함수
type : 모달창 버튼 type
onClose : 모달창 닫기
isOpen : 모달창 상태useState
onCloseisOpen은 구현할 곳에 직접 구현 후 사용

@tkv00 tkv00 added the ✨feat 기능 개발 label Sep 11, 2024
@tkv00 tkv00 self-assigned this Sep 11, 2024
@tkv00 tkv00 added this to frontend Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨feat 기능 개발
Projects
Status: No status
Development

No branches or pull requests

1 participant