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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-a-gate

v1.5.1

Published

A React library made with Portals for modals, tooltips and popovers

Downloads

62

Readme

react-a-gate

version install-size license

Overview

react-a-gate is a React library for modals, tooltips and popovers. It uses the new React feature called Portals. Basically, a portal (ehem... a gate) allows you to render an element of a child component outside the DOM hierarchy by creating another top-level tree and injecting this component inside it.

Demo

If you want to see the library in action, here are some live demos.

Requirements

  • node 12.xx.x
  • npm 6.x.x

Installation

npm install react-a-gate

or

yarn add react-a-gate

Usage

Modal

1 . Import ModalGate after the installation.

import { ModalGate } from 'react-a-gate';

2 . Add the ModalGate component into your JSX code.

const App = () => {
  const [isOpen, setIsOpen] = useState(false);

  const openModal = () => setIsOpen(true);
  const closeModal = () => setIsOpen(false);

  return (
    <>
      <button className="App-button" onClick={openModal}>
        Open modal
      </button>
      <ModalGate id="app_modal" isOpen={isOpen} onClose={closeModal}>
        <>
          <div>This is a modal</div>
          <button className="App-button" onClick={closeModal}>
            Close modal
          </button>
        </>
      </ModalGate>
    </>
  );
};

You can also use a custom React component to be rendered inside the modal, like the example below:

const Text = () => <div>This is some text</div>;

const App = () => {
  // ...
  <ModalGate id="app_modal" isOpen={isOpen} onClose={closeModal}>
    <Text />
  </ModalGate>;
  // ...
};

Props

| Property | Type | Default | Description | | --------------------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | id | String | - | Identificator for the modal.Required. | | rootId | String | portal-root | Identificator for the portal. If you already have a different root included in your HTML code, just put here the element id. If not, a new one will be created. | | className | String | - | Property used to override the default CSS styles with custom ones. | | isOpen | Boolean | false | Property used to show and hide the modal.Required. | | closeWhenClickOutside | Boolean | true | Enable or disable the closing of the modal when the user clicks outside. | | onClose | Function | - | Function that triggers the closing of the modal. It is used to close the modal when the user clicks outside the modal and when the user pressed the Escape key.Required. |

Tooltip

1 . Import TooltipGate after the installation.

import { TooltipGate } from 'react-a-gate';

2 . Add the TooltipGate component into your JSX code.

const App = () => (
  <TooltipGate content="This is some text" place="top">
    <button className="App-button">Hover me</button>
  </TooltipGate>
);

You can also use a custom React component to be rendered inside the tooltip, like the example below:

const Text = () => <div>This is some text</div>;

const App = () => {
  <TooltipGate content={<Text />} place="top">
    <button className="App-button">Hover me</button>
  </TooltipGate>;
};

Props

| Property | Type | Default | Description | | --------- | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | rootId | String | 'portal-root' | Identificator for the portal. If you already have a different root included in your HTML code, just put here the element id. If not, a new one will be created. | | className | String | - | Property used to override the default CSS styles with custom ones. It also overrides the current selected theme. | | content | String / JSX Element | - | Content that will be rendered inside the tooltip. It can be a simple string or a custom React component.Required. | | place | String | top | Property to set where the tooltip will be placed.Accepted values: top, bottom, left and right. | | theme | String | dark | Property to set an already defined theme.Accepted values: light and dark. | | offset | Number | 10 | Distance between the trigger element and the tooltip. | | children | ReactNode | - | The trigger element. It can be an HTMLElement or any custom React component. Required. |

Popover

1 . Import PopoverGate after the installation.

import { PopoverGate } from 'react-a-gate';

2 . Add the PopoverGate component into your JSX code.

const App = () => (
  <PopoverGate content="This is some text" place="top">
    <button className="App-button">Click me</button>
  </PopoverGate>
);

You can also use a custom React component to be rendered inside the popover, like the example below:

const Text = () => <div>This is some text</div>;

const App = () => {
  <PopoverGate content={<Text />} place="top">
    <button className="App-button">Click me</button>
  </PopoverGate>;
};

Props

| Property | Type | Default | Description | | --------------------- | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | rootId | String | 'portal-root' | Identificator for the portal. If you already have a different root included in your HTML code, just put here the element id. If not, a new one will be created. | | className | String | - | Property used to override the default CSS styles with custom ones. | | content | String / JSX Element | - | Content that will be rendered inside the popover. It can be a simple string or a custom React component.Required. | | place | String | top | Property to set where the popover will be placed.Accepted values: top, bottom, left and right. | | mode | String | click | Property to set the mode of the popover. 'click' mode will open and close the popover when the user clicks at the trigger element, and the 'hover' mode will open and close the popover when the user hovers in and out the trigger element.Accepted values: click and hover. | | closeWhenClickOutside | Boolean | true | Enable or disable the closing of the popover when the user clicks outside. | | theme | String | dark | Property to set an already defined theme.Accepted values: light and dark. | | offset | Number | 10 | Distance between the trigger element and the popover. | | children | ReactNode | - | The trigger element. It can be an HTMLElement or any custom React component. Required. |

How to override CSS styles

Each component has a few styles by default. In case you want to override them, here are the main classes you need to override on your project:

Modal

modal__backdrop
  >  modal__content
modal__backdrop--active
  >  modal__content

Tooltip

tooltip__container
tooltip__arrow
tooltip__arrow-border
tooltip__inner

In case you want to customize the colors of the tooltip, here's an example of what you need to do:

.red {
  .tooltip__inner {
    background-color: #ac2121;
    border: 1px solid #700404;
  }

  .tooltip__arrow {
    border-color: #ac2121;
  }

  .tooltip__arrow-border {
    border-color: #700404;
  }
}
<TooltipGate content="This is some text" className="red">
  <button className="App-button">Hover me</button>
</TooltipGate>

Popover

popover__container
popover__arrow
popover__arrow-border
popover__inner

In case you want to customize the colors of the popover, here's an example of what you need to do:

.red {
  .popover__inner {
    background-color: #ac2121;
    border: 1px solid #700404;
  }

  .popover__arrow {
    border-color: #ac2121;
  }

  .popover__arrow-border {
    border-color: #700404;
  }
}
<PopoverGate content="This is some text" className="red">
  <button className="App-button">Click me</button>
</PopoverGate>