npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-modal-es

v3.0.0

Published

Easy to control the Modal everywhere.

Downloads

55

Readme

react-modal-es

Easy to control the Modal everywhere.

Build Status npm version

Note: Version 2.x is require React 16.8.x

Migrating from 1.x

1.x docs

Table of Contents

Installation

To install, you can use npm or yarn:

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

Usage

Step1:

Create modal

Create file modal.js and import createModal to create modal functions:

  • openModal(modalName) to show the Modal
  • closeModal(modalName) to hide the Modal
  • closeAllModal() to hide all Modals
  • ModalProvider makes the Modal state available to any nested components Example Usage
import { createModal } from 'react-modal-es';

const modal = createModal();
export const openModal = modal.openModal;
export const closeModal = modal.closeModal;
export const closeAllModal = modal.closeAllModal;
export const ModalProvider = modal.ModalProvider;

Step2:

Modal Provider

import ModalProvider from modal.js and connect modal at root app.

...
import { ModalProvider } from './modal';

const App = () => {
  return (
    <ModalProvider>
      ...
    </ModalProvider>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));

Step3:

Modal Component

The Modal has one required prop Demo:

  • name to switch show and hide.
import Modal from 'react-modal-es';
import { openModal, closeModal, closeAllModal } from './modal';

const Page = () => {
  return (
    <div>
      <Modal name='myModal' title='Title Modal'>
        Content
      </Modal>
      <button onClick={() => openModal('myModal')}>Open Modal</button>
    </div>
  );
};

Open multiple Modals

Support open multilple modal demo

Use prop zIndex to make a layer of Modal

import Modal from 'react-modal-es';
import { openModal, closeModal, closeAllModal } from './modal';

const Page = () => {
  const onOpenModal = () => {
    openModal('modal1');
    openModal('modal2');
  };

  return (
    <div>
      <Modal name='modal1' title='Title Modal 1' zIndex={1}>
        Content 1
      </Modal>
      <Modal name='modal2' title='Title Modal 2' zIndex={2}>
        Content 2
      </Modal>
      <button onClick={onOpenModal}>Open Modal</button>
    </div>
  );
};

Props

<Modal
  name='myModal'
  title='Modal Title'
  zIndex={1}
  className='your-classname'
  maxWidth='600px'
  overlayColor='rgba(0, 0, 0, 0.7)'
  center={false}
  closeOverlayDisabled={false}
  didOpen={() => null}
  willUnmount={() => null}
  willClose={() => null}
>
  ...
</Modal>

Config options

Custom UI

Building your own custom UI and Style demo

3 parameters of customUI

  • title type string
  • children type node
  • onClose type function
import React from 'react'
import { createModal } from 'react-modal-es'

const customStyles = {
  body: {
    fontFamily: 'arial',
    background: '#222',
    color: '#eee',
    padding: '40px',
    textAlign: 'center'
  },
 ...
}

const customUIComponent = (title, children, onClose) => (
  <div style={customStyles.body}>
    <div style={customStyles.title}>{title}</div>
    <div style={customStyles.content}>{children}</div>
    <button style={customStyles.button} onClick={onClose}>
      close
    </button>
  </div>
)

const configs = {
  customUI: customUIComponent
}

const modal = createModal(configs)
...