react-modal vs react-modal-promise
モーダルライブラリ
react-modalreact-modal-promise類似パッケージ:

モーダルライブラリ

モーダルライブラリは、ユーザーインターフェースにおいて、ユーザーが特定のアクションを完了するために必要な情報を提供するためのオーバーレイウィンドウを作成するためのツールです。これにより、ユーザーは現在のコンテキストを失うことなく、重要な情報にアクセスしたり、アクションを実行したりできます。これらのライブラリは、Reactアプリケーションにおいてモーダルの表示と管理を簡素化します。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-modal07,418188 kB2091年前MIT
react-modal-promise06858 kB17-MIT

機能比較: react-modal vs react-modal-promise

シンプルさ

  • react-modal:

    react-modalは、シンプルで直感的なAPIを提供しており、モーダルを簡単に作成できます。基本的な機能に焦点を当てているため、すぐに使い始めることができます。

  • react-modal-promise:

    react-modal-promiseもシンプルですが、Promiseを使用した非同期処理をサポートしているため、少し複雑なロジックを必要とする場合に適しています。

選び方: react-modal vs react-modal-promise

  • react-modal:

    react-modalは、シンプルで軽量なモーダルを必要とする場合に最適です。基本的なモーダル機能を提供し、カスタマイズが容易で、迅速に実装できます。特に、モーダルの表示や非表示を簡単に制御したい場合に適しています。

  • react-modal-promise:

    react-modal-promiseは、モーダルの表示をPromiseベースのアプローチで管理したい場合に選択するべきです。これにより、モーダルが表示された後の処理を簡単に管理でき、ユーザーのアクションに基づいて次のステップを決定するのに役立ちます。特に、ユーザーからの入力を待つ必要がある場合に便利です。

react-modal のREADME

react-modal

Accessible modal dialog component for React.JS

Build Status Coverage Status gzip size Join the chat at https://gitter.im/react-modal/Lobby

Table of Contents

Installation

To install, you can use npm or yarn:

$ npm install --save react-modal
$ yarn add react-modal

To install react-modal in React CDN app:

  • Add this CDN script tag after React CDN scripts and before your JS files (for example from cdnjs):

       <script src="https://cdnjs.cloudflare.com/ajax/libs/react-modal/3.14.3/react-modal.min.js"
       integrity="sha512-MY2jfK3DBnVzdS2V8MXo5lRtr0mNRroUI9hoLVv2/yL3vrJTam3VzASuKQ96fLEpyYIT4a8o7YgtUs5lPjiLVQ=="
       crossorigin="anonymous"
       referrerpolicy="no-referrer"></script>
    
  • Use <ReactModal> tag inside your React CDN app.

API documentation

The primary documentation for react-modal is the reference book, which describes the API and gives examples of its usage.

Examples

Here is a simple example of react-modal being used in an app with some custom styles and focusable input elements within the modal content:

import React from 'react';
import ReactDOM from 'react-dom';
import Modal from 'react-modal';

const customStyles = {
  content: {
    top: '50%',
    left: '50%',
    right: 'auto',
    bottom: 'auto',
    marginRight: '-50%',
    transform: 'translate(-50%, -50%)',
  },
};

// Make sure to bind modal to your appElement (https://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement');

function App() {
  let subtitle;
  const [modalIsOpen, setIsOpen] = React.useState(false);

  function openModal() {
    setIsOpen(true);
  }

  function afterOpenModal() {
    // references are now sync'd and can be accessed.
    subtitle.style.color = '#f00';
  }

  function closeModal() {
    setIsOpen(false);
  }

  return (
    <div>
      <button onClick={openModal}>Open Modal</button>
      <Modal
        isOpen={modalIsOpen}
        onAfterOpen={afterOpenModal}
        onRequestClose={closeModal}
        style={customStyles}
        contentLabel="Example Modal"
      >
        <h2 ref={(_subtitle) => (subtitle = _subtitle)}>Hello</h2>
        <button onClick={closeModal}>close</button>
        <div>I am a modal</div>
        <form>
          <input />
          <button>tab navigation</button>
          <button>stays</button>
          <button>inside</button>
          <button>the modal</button>
        </form>
      </Modal>
    </div>
  );
}

ReactDOM.render(<App />, appElement);

You can find more examples in the examples directory, which you can run in a local development server using npm start or yarn run start.

Demos

There are several demos hosted on CodePen which demonstrate various features of react-modal: