0.1.11 • Published 10 months ago

react-modal-hp v0.1.11

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

React Modal HP

Modal Component with React and Typescript.

리액트와 타입스크립트를 사용한 모달 컴포넌트.

Installation

In React App

# use npm
npm install react-modal-hp

#use yarn
yarn add react-modal-hp

Before Use

Before use, create a root div for the modal in public/index.html.

사용 전 public/index.html에 모달의 root div를 생성해주세요.

<!-- public/index.html -->
<head>
  <title>Your React Project</title>
</head>

<body>
  <noscript>You need to enable JavaScript to run this app.</noscript>
  <div id="root"></div>
  <!-- Add the following code to create a root div for the modal. -->
  <!-- 이 부분에 아래와 같이 작성해주세요. -->
  <div id="modal-root"></div>
</body>

Modal && useModal

Import

import Modal from 'react-modal-hp';
import { useModal } from 'react-modal-hp';

Example

import Modal, { useModal } from 'react-modal-hp';

// Get the portal element using the ID of the root div you created earlier.
// 위에서 생성한 root div의 id 값으로 portal을 가져옵니다.
const portal = document.getElementById('modal-root') as HTMLDivElement;

function App() {
  // The useModal hook is used to manipulate the modal.
  // 모달을 조작할 수 있는 hook 입니다.
  const { isOpen, openModal, closeModal } = useModal();

  return (
    <>
      <button onClick={openModal}>open</button>
      <Modal open={isOpen} onClose={closeModal} portal={portal}>
        Write Your Modal Content Here
      </Modal>
    </>
  );
}

Modal Props

AttributeTypeDescriptionDefault
openbooleanIndicates whether the modal is open or closed모달이 열고 닫힌 상태
onClose() => voidA function to close the modal모달을 닫는 함수
positionModalPosition ('bottom')The position of the modal모달의 위치'bottom'
animationboolean | undefinedWhether the modal should have an animation모달 애니메이션 유무
portalElementThe root element of the modal모달의 root가 되는 엘리먼트
childrenReact.ReactNodeThe contents of the modal모달 내부의 컨텐츠
type ModalPosition = 'bottom';

useModal Type

PropertyTypeDescriptionInitial
isOpenbooleanIndicates whether the modal is open or closed모달의 열고 닫힌 상태false
openModal() => voidA function to update isOpen to trueisOpen을 true로 업데이트
closeModal() => voidA function to update isOpen to falseisOpen을 false로 업데이트

useModalContext

A hook used in the modal content.

모달 컨텐츠에서 사용하는 hook.

The close function can be used inside.

내부에서 모달 닫기 메서드를 사용할 수 있다.

Import

import { useModalContext } from 'react-modal-hp';

Example

import { useModalContext } from 'react-modal-hp';

function ModalContent() {
  const { close } = useModalContext();

  const onClose = () => {
    // Perform the desired logic before closing.
    // 모달이 닫히기 전 로직을 작성해서 사용.
    close();
  };

  return (
    <div>
      <button onClick={onClose}>close</button>
      <p>Hi. This is Modal</p>
    </div>
  );
}

Types

PropertyTypeDescription
close() => voidA function to close the modal.모달을 닫는 함수
0.1.10

10 months ago

0.1.11

10 months ago

0.1.8

10 months ago

0.1.9

10 months ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago