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-global-portals

v1.5.0

Published

Effortless react notifications/modals

Downloads

5

Readme

React-Global-Portals

💖 React-Global-Portals takes from you all worries related to show notifications/modal etc. on top of everything 💖

❯ Instalation

$ yarn add react-global-portals

or

$ npm install react-global-portals

❯ Features

  • Painless setup
  • Effortless to use
  • Use inside or outside of components
  • Define position per portal
  • Portals can be dismissed automatically
  • Pause portal when the window losses focus
  • Display any react component
  • Can remove a portal programmatically
  • Queue portals

❯ Small usage examples

It needs <PortalContainer /> to render portals. Example setup:

export function App() {
    return (
        <div>
            <h1> React-Global-Portals </h1>
        </div>

        <PortalContainer /> // This is required
    )
}

A react component that will be used in examples listed below

function ExampleComponent() {
  return (
    <div>
      <h1>Component</h1>
    </div>
  );
}

portal.show

portal.show - it shows component as a portal, if any portal is already shown it will queue the passed one and show it when the current is dismissed.

  • It simply shows component on top.
const portalId = portal.show(<ExampleComponent />);
  • It shows component on top but with passed id
const customPortalId = 'Portal Id';
const portalId = portal.show(<ExampleComponent />, { id: customPortalId });
// portalId === customPortalId
  • We can add time in miliseconds when it should dismiss, and decide if timeout should be paused on focus loss
const portalId = portal.show(<ExampleComponent />, {
  timeout: 2000,
  pauseOnFocusLoss: true,
});
  • We can also change the position. By default, portal takes whole page but it can be easily changed
const portalId = portal.show(<ExampleComponent />, {
  position: {
    width: '100vh',
    height: '50vh',
    bottom: '0',
  },
});

portal.forceShow

portal.forceShow - allows to forcefully show portal, when any portal is already shown it will queue the current and show one thas was passed. Additionally, it can takes parameter of a type ForceAction that can be:

  • DismissNone : default action, put current portal into queue and show one that was passed

  • DismissCurrent : dismiss currently shown portal and show one that was passed

  • DismissQueue : dismiss all portals that are queued, queue the current one and show one that was passed

  • DismissAll : dismiss all portals (current and queued), and show one that was passed

  • Show passed component on top, and queue currently shown (if any)

const portalId = portal.forceShow(<ExampleComponent />);
  • Additionally, portal has custom Id and it will dismiss ALL other portals
const portalId = portal.forceShow(
  <ExampleComponent />,
  { id: 'CustomId' },
  'DismissAll'
);
  • This one will be dismissed after 5000 ms
const portalId = portal.forceShow(
  <ExampleComponent />,
  { timeout: 5000 },
  'DismissAll'
);

portal.dismiss

portal.dismiss - dismiss portal or delete it from queue.

  • Dismiss currently displayed portal
portal.dismiss();
  • Dismiss portal with identifier
portal.dismiss('myPortal');

portal.dismissAll

portal.dismissAll - it dismiss current portal and deletes all queued portals

portal.dismissAll();

Live Examples

At the moment examples are provided only inside examples folder

License

Licensed under MIT