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

rc-global-modal

v0.1.22

Published

global modal for react

Downloads

28

Readme

rc global modal

manage modal using global state in react project
Try it out with Storybook

npm version
npm bundle size
npm total downloads npm downloads

Table of Contents

Installation

npm i rc-global-modal

Features

  1. Open and close modal from anywhere in the app(inside ModalProvider)
  2. Custom CSS style for modal and overlay
  3. Ref for modal container and overlay
  4. Choose animation type and duration for modal

Props

| Props | Types | Required | Default | Description | | :-: | :-: | :-: | :-: | :-: | | children | React.FC | ✅ | | component that will be displayed inside modal | | id | string \| number | ✅ | | unique id for modal | | closeOnOverlayClick | boolean | ❌ | true | close modal when overlay is clicked | | modalContainerClassName | string | ❌ | | class name for modal container | | overlayClassName | string | ❌ | | class name for overlay | | modalContainerStyle | React.CSSProperties | ❌ | | custom style for modal container | | overlayStyle | React.CSSProperties | ❌ | | custom style for overlay | | closeOnEsc | boolean | ❌ | true | close modal when esc key is pressed | | modalContainerRef | React.RefObject | ❌ | | ref for modal container | | overlayRef | React.RefObject | ❌ | | ref for overlay | | animationType | 'fade' \| 'slideUp' \| 'slideDown' \| 'slideLeft' \| 'slideRight' \| 'zoom' | ❌ | fade | animation type for modal | animationDuration | number | ❌ | 300 | animation duration for modal |

Usage

  1. Wrap your app with ModalProvider component
import { ModalProvider } from 'rc-global-modal';

function App() {
  return (
    <ModalProvider>
      <Home />
    </ModalProvider>
  );
}
  1. Use Modal component to display modal(must be inside ModalProvider)
import { Modal } from 'rc-global-modal';

const Home = () => {
  return (
      <Modal id={1}>
        <h1>IdOneModal</h1>
      </Modal>
  );
};
  1. Use openModal and closeModal function to open and close modal(must be inside ModalProvider)
import { Modal, useModal } from 'rc-global-modal';

const Home = () => {
  const { openModal, closeModal } = useModal();
  return (
    <div>
      <button onClick={() => openModal(1)}>open Id One modal</button>
      <Modal id={1}>
        <h1>IdOneModal</h1>
        <button onClick={closeModal}>close modal</button>
      </Modal>
    </div>
  );
};

Examples

import { Modal, useModal } from 'rc-global-modal';

const Home = () => {
  const { openModal, closeModal } = useModal();
  return (
    <div>
      <button onClick={() => openModal(1)}>open Id One modal</button>

      <button onClick={() => openModal(2)}>open Id Two modal</button>

      <Modal id={1}>
        <h1>IdOneModal</h1>
        <button onClick={closeModal}>close modal</button>
      </Modal>

      <Modal id={2}>
        <h1>IdTwoModal</h1>
        <button onClick={closeModal}>close modal</button>
      </Modal>
    </div>
  );
};

export default Home;

License

MIT