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

@joinbox/overlay

v2.1.0

Published

Overlay component that can be opened and closed via OverlayButtons

Downloads

91

Readme

Overlay

Overlay component that can be opened and closed via OverlayButtons. Supports:

  • close when user presses esc (optional)
  • close when user clicks outside (optional)
  • disable body scroll
  • any number of open/close/toggle buttons that control the overlay
  • the use of any background element through a selector and any class on that background element to make it visible

Important

Load <overlay-component> before <overlay-button-component> as the button needs the overlay to exist before it is setup (setModel will not be called if <overlay-component> does not exist).

If you want to disable scroll when the overlay is open, use Body Scroll Lock:

import { disableBodyScroll, enableBodyScroll } from '/body-scroll-lock/lib/bodyScrollLock.es6.js';
const overlay = document.querySelector('#my-overlay-identifier');
overlay.addEventListener('openOverlay', disableBodyScroll);
overlay.addEventListener('closeOverlay', enableBodyScroll);

Example

<overlay-button-component data-overlay-name="myOverlay" data-type="open">
    Open Restricted
</overlay-button-component>

<overlay-component
    data-name="myOverlay"
    data-background-selector=".overlay-background"
    data-background-visible-class-name="visible"
    data-visible-class-name="visible"
    data-disable-esc="true"
    data-disable-click-outside="true"
>
    <overlay-button-component data-overlay-name="myOverlay" data-type="close">
        ×
    </overlay-button-component>
</overlay-component>

<!-- Import all components you use -->
<script src="@joinbox/overlay/OverlayElement.js"></script>
<script src="@joinbox/overlay/OverlayButtonElement.js"></script>

Components

Overlay

Exposed Element

<overlay-component></overlay-component>

Attributes

  • data-name (required, String): Names the overlay; the name must exactly match attribute data-overlay-name on overlay-button-component to be opened/closed by it.
  • data-visible-class-name (required, String): Contains the class name that will be added to the overlay when it is opened and removed when it is closed.
  • data-background-selector (optional, String): Takes any CSS selector and defines the element that will receive data-background-visible-class-name when the overlay opens.
  • data-background-visible-class-name (optional, String). Defines the class that will be added to the background element when the overlay is opened and removed when the overlay is closed.
  • data-disable-esc (optional, Boolean i.e. can be set without attribute or not at all): Prevents the overlay from being closed when users press the ESC key. Defaults to false.
  • data-disable-click-outside (optional, Boolean i.e. can be set without attribute or not at all): Prevents the overlay from being closed when users click with their mouse outside of the overlay. Defaults to false.

Events

The overlay emits the following events:

  • overlayOpened: Dispatched after an overlay is opened; bubbles and has a detail object with a name property that corresponds to the overlay's data-name attribute value.
  • overlayClosed: Dispatched after an overlay is closed; bubbles and has a detail object with a name property that corresponds to the overlay's data-name attribute value.

The overlay listens to the following events (on window):

  • openOverlay: Open an overlay; must contain a detail object with a name property that corresponds to the overlay's name.
  • closeOverlay: Close an overlay; must contain a detail object with a name property that corresponds to the overlay's name.

Overlay Button

Exposed Element

<overlay-button-component></overlay-button-component>

Attributes

  • data-overlay-name (required, String): Contains the name of the overlay that should be opened or closed. Make sure it exactly matches the attribute data-name on overlay-component.
  • data-type (required, String): Is either close, if the button shall only close the overlay, open if the button shall only open the overlay or toggle if the button shall toggle the overlay. Defaults to toggle.
  • data-open-class-name (optional, String): Class name that will be added to the button when the overlay is opened.
  • data-closed-class-name (optional, String): Class name that will be added to the button when the overlay is closed.

Migration

From v1 to v2

  • Events openOverlay and closeOverlay (emitted after the overlay is opened or closed) are renamed to overlayOpened and overlayClosed (because the original events are now used to open or close the overlay, not to communicate its state change retrospectively)