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-popover-portal

v0.3.5

Published

A popover that renders to <body>

Downloads

8

Readme

Build Status

react-popover-portal

A simple 'shared' popover that renders to the body. Accelerated translation between nodes.

npm install -S react-popover-portal

Demo

GIF

Example

  1. Make sure that you have installed packages in root folder and examples folder.
  2. To start webpack dev server, run npm start inside /examples folder.
  3. Navigate to localhost:8080 .

Usage

In your React component:


render(){
  return (<div>
      <p onMouseEnter={this.displayPopup} onMouseLeave={this.hidePopup} id='parent'> 
      The parent 
      </p>

      <Popover prefix='popup' parent='#parent' open={this.state.open}
          onMouseEnter={this.displayPopup} onMouseLeave={this.hidePopup}>

          <div className={'popup-content'}>
              Popup
          </div>
      </Popover>
      
  </div>);
}

Adding onMouseEnter and onMouseLeave to Popover prevents it from disappearing when hovered

In your CSS file:

// - With 'popup as prefix'
.popup {
  background: rgba(0, 0, 0, 0.7);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

.popup-content{
  // - Add padding here to the content 
  padding: 10px;
}

Do not add margins to children class .popup-content. The onMouseEnter and onMouseLeave does not work on empty space.
If you set .popup height you also need to make sure the children div is covering the whole area. See issues section below.

Props

| Prop | Description | Type | Required | Default Value | |:-------------------:|:---------------------------------------------------------------------------------------:|:---------------:|:-------------:|:-------------------------:| | parent | The DOM element to attach the popover to | document query | required | - | | open | If the popover should open or not | bool | required | - | | group | a string which is used to create independent popups | bool | not required | - | | arrowWidth | Size of your carret | number | not required | - | | popupWidth | Size of your popup, required if you animate width | number | not required | - | | prefix | A prefix used to add classes to the portal node | string | not required | rpp | | timeout | The time it takes until popover disappears (ms) | number | not required | 1000 | | animationTime | The duration of your appear and disappear animations (ms) | number | not required | 350 | | translateSpeed | The speed of how fast popover translates between parents | number | not required | 300 | | translateEase | Translate ease of when popover translates between parent | string | not required | 'ease' | | transitions | List of transitions {name: opacity , ease: 'linear'} |Array of objects | not required | {name:'all', ease:'ease'} | | offset | The offset between the parent and popover (pixels) | number | not required | 10 | | onMouseEnter | Callback for when the mouse entered the popover content. | function | not required | - | | onMouseLeave | Callback for when the mouse leaved the popup content | function | not required | - | | getArrowPosition | Callback for arrow positioning (left position) | function | not required | - |

If you are using a carret specify the width with arrowWidth prop.

Customize

You are free to customize the popup. react-popover-portal does not care on how your popup looks.
However you should use the prefix to add styles and animation as it is top level parent.

Animate

You can animate the popup when it appears or disappears. Simply add these classes to your CSS (with popup as prefix):

.popup__hidden{
  opacity: 0;
}

.popup__active{
  opacity: 1;
}

Prefixes {prefix}__active and {prefix}__hidden will be added to the portal node.
See /examples/src/styles/animated.scss and /examples/src/components/AnimatedPopover.jsx

Clear all popups

Use removeAllPopups() to clear all popups from DOM including the portal.
This will prevent popup from staying when you're navigating with react-router etc (see components/App.jsx in examples).

Known issues

  • When you set the height of the popup in your CSS file (eg. animating it from 0px to 200px) the children will still have a fixed height. Because the onMouseEnter and onMouseLeave is listening on child events, the popup will close even when the user is hovering the popup. If you need to set the height, simply add display:flex to the popup class and height:100% to the container child to force it to cover the popup.

  • Animating the width is problematic as it is used to calculate popover position before attaching it to the parent. A solution to fix this problem is by passing the final width as a prop.

Features to add

  • Possible to specify position of the popup relative to parent: 'left', 'bottom', 'top' and 'right'
  • Force the arrow to point to a specific position on the parent, eg parent's right corner.