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

modal-relay

v2.2.0

Published

Display modals from anywhere in your app easily. React Router not required!

Downloads

4

Readme

Modal Relay

NPM JavaScript Style Guide Build Size

Display modals from anywhere in your app easily. React Router not required! Most modal libraries are reliant on routing in React. However, not every react project is going to be using routing. That's where Modal Relay comes in handy!

Install

NPM:

npm install --save modal-relay

YARN:

yarn add modal-relay

Examples

API

Docs for each component are co-located with the components. Check out the /src directory for the most accurate listing of components/core functionality and documentation. I'm going to try to keep a list updated here but it may be out of sync at times.

<Modal/>

  • A11y First
  • Built with <FocusLock/> from react-focus-lock
  • Automatically returns focus to activating element when the modal is closed.

<ModalRelay/>

  • Uses React Portals to escape the react tree and render your modal above your application.
  • Register all your modals for a particular page as its children.
  • Listens for activated Modals and surfaces them for user interaction.

useModalStore

  • Use this hook anywhere you want to activate or deactivate your modals.
  • V minimal allowing for flexibility in creating modal flows. Wrap the function with whatever logic you want before calling activate(id) or deactivate(id).
  • No context layers required.

<ModalLink/>

  • Open any modal by passing this component it's ID.

No CSS Included 🚫

There isn't any css included in this library and that is intentional. All components will take className or style props making them perfect complements for libraries like styled-components or really any style system.

You will find a bare bones css starter below. This will show you all the css classes that are available on the modal. Take these ugly styles and turn it into your own beautiful modal! 😃

/* Modal dialog element */
.modal {
  display: block;
}

/* Inside the modal */
.modal__window {
  display: inline-block;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid black;
  padding: 18px;
  z-index: 101;
}


/* Element Behind The Modal */
.modal__mask {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
}

Common Mistakes

There are two ways that you could mess this up right out of the box.

  1. You didn't create a portal element:
  • You'll need access to the HTML markup where your React app is being rendered. If you're using something like Create React App that will be the index.html located within your ./public folder. If you're not using CRA you will likely have to figure out how to modify the HTML template created by your build system. Most frameworks provide documentation about how to do this but if you're confused just open an issue! :)
  1. No ID Set At Modal Router Level:
  • I think this is better to show an example of what works and what doesn't:
Works
<ModalRelay modalRoot={modalRoot}>
  <YourCustomModal id="custom-modal-one"/>
  <YourOtherModal id="other-modal"/>
</ModalRelay>
Doesn't Work
<ModalRelay modalRoot={modalRoot}>
  <YourCustomModal/>
  <YourOtherModal/>
</ModalRelay>

Even if you pass an ID to the <Modal/> component within your custom modal, the <ModalRelay/> won't be able to detect it. A good rule of thumb is to create your ID as a variable and export it from your custom modal. Then when you want to activate that modal you just import that variable and pass it to activate() or <ModalLink/>.

License

MIT © freddiemixell