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

layer-pop

v0.1.11

Published

## Possible Names (must be generic enough)

Downloads

20

Readme

Layer Pop

Possible Names (must be generic enough)

  • overlay
  • layer
  • modal
  • popup

Description

A flexible popup library for tooltips, modals, and drop-down menus in React.

Layer Pop makes it easy exists because I could not find any other libraries that efficiently and simply handled all these issues that people commonly need when handling popups.

  • lightweight
  • custom position popups (above, below, right, etc.)
  • reposition popups on scroll or screen resize (always keep popup in the right position)
  • escape to close a popup: It's opt in so you can close popups that are modals or drop down menus, but not tooltips
  • modular css transitions: build and reuse custom transition
  • multiple levels of popups: support for different levels of popups in the same app. For example, modals, can have menu items which can have tooltips. All three levels can co-exist and have different behavior.
  • Restrict one popup per level: As per best practices, you don't want multiple menus to be open at once or multiple tooltips open at once. When you open another popup at the same level, the other popup will be closed.
  • Unlimited number of levels: If you have a modal popup which itself needs to have a modal popup, you can create two different levels for modals and they will co-exist. Restricting a popup per level, doesn't restrict you have more than one type of each kind of popup if nesting is required (although usually not recommended)

Minimal Example

function App() {
  const layers = useLayers()

  const alert = useCallback(() => {
    /**
     * Call `layers.open` with the `zIndex` you want to open the popup on,
     * the React Component to open, and the props to pass to the React
     * Component.
     */
    layers.open(1000, Alert, {title: "Title of Alert"})
  })

  return <div>
    <button onClick={alert}>Open Alert</button>
  </div>
}

function Alert({ title }: { title: string} ) {
  return <div style={{
    position: 'absolute',
    left: 100,
    top: 100,
    width: 640,
    border: '1px solid black',
    padding: '1em'
    }}>
    <h1>{title}</h1>
  </div>
}

function AppContainer() {
  return <LayersProvider>
    <App>
  </LayersProvider>
}

Types of Layer Pops

https://ux.stackexchange.com/questions/90336/whats-the-difference-between-a-modal-popup-popover-and-lightbox

  • Alert
  • Modal/Dialog
  • Popup
  • Notification
  • Lightbox/Theatres
  • Popover/Tooltip/Hovercard
  • Menu
  • UI Components that appear above others like date pickers

Best Practices Behaviors

https://uxplanet.org/best-practices-for-modals-overlays-dialog-windows-c00c66cddd8c

usePosition

The usePosition hook is used inside the layer (modal, alert, popup or tooltip) to position it. It includes several useful presets for positioning above, below or to the left or right.

function Alert({
  srcRef,
}: {
  srcRef: React.MutableRefObject<HTMLElement | null>
}) {
  const style = usePosition(() => {
    /**
     * Position below `srcRef`
     */
    return {
      position: "absolute",
      left: srcRef.current.left,
      top: srcRef.current.bottom,
    }
  }, [])

  return <div style={style}></div>
}