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

legend-modal

v1.1.4

Published

A modal class to make life easier

Downloads

4

Readme

LegendModal

An ES6 modal class designed to make your life easier.

Features:
  • Modal fades in using fancy CSS transitions
  • Automatically disables page scrolling while modal is open
  • Ridiculously simple to use

Getting Started:

Begin with a basic HTML file.

Your modal content can contained within DOM elements on the page or provided by a React.Component. LegendModal isn't picky.

<!DOCTYPE HTML>
<html>
<head>
    <title>Legend Modal Test Page</title>
    <meta charset="UTF-8">
    <script type="application/ecmascript" src="src/js/index.js"></script>
</head>
<body>
    <div id="content-main">
        <h2>Modal test!</h2>
        <button id="test1">Basic Usage</button><br/>
        <button id="test2">Invisible Overlay</button><br/>
        <button id="test3">Limited Close Options</button>
        
        <div id="test1-div" style="display:none">
            I'm just a bunch of text! You can close this modal by pressing escape, clicking
            the overlay, or clicking the X button in the upper right.
        </div>
        
        <div id="test2-div" style="display:none">
            This modal can be closed the same as the others, but the overlay behind it 
            is invisible!
        </div>
                
        <div id="test3-div" style="display:none">
            This modal can be closed by pressing the button!<br/>
            <button class="legend-modal-close">Close me!</button>
        </div>
        
        <div id="test4-div" style="display:none">
            This modal can be closed only by pressing the X in the upper right corner!
        </div>
        
        <div id="test5-div" style="display:none">
            Options for this modal were set using <em>setOptions</em>.
        </div>
    </div>
</body>
</html>

Basic Usage

Constructor:

The constructor for LegendModal takes two optional arguments:
new LegendModal(content,options)

  • content: A DOM element to be used as the content of the modal. The display property of content will be overwritten with block before it is displayed to the user.

  • options: An object containing up to four boolean options which control how the modal will behave:

    • visibleOverlay: If false, the overlay behind the modal will not be visible to the user, though it will still be present. Defaults to true.

    • closeOnOverlayClick: If false, the modal will not close if the user clicks outside of the modal. Defaults to true.

    • closeOnEscape: If false, pressing the Escape key will not close the modal. This option is always false on Internet Explorer and Edge. Defaults to true.

    • showCloseButton: If true, an X will be shown in the upper-right corner of the modal. Clicking this X will close the modal. Defaults to true.

Methods:

  • setContent(content): Define the content of the modal.

    • content: A DOM element to be used as the new content.
  • setoptions(options): Set or alter modal options.

    • options: An object containing any of the options described above.
  • showModal(): Create a copy of content and display a modal containing it.

  • closeModal(): Close the modal and remove it from the DOM.

Note: closeModal is invoked automatically when a click event is fired on a DOM element with the class legend-modal-close if that DOM element is present in the modal body.

Code Examples

Import the class:

import LegendModal from './LegendModal';

To create and display a simple modal:

let modalOne = new LegendModal(document.getElementById('test1-div'));
modalOne.showModal();

Modal with an invisible overlay:

let modalTwo = new LegendModal(document.getElementById('test2-div'),{
    visibleOverlay: false
});

Manually close the modal:

let modalThree = new LegendModal(document.getElementById('test3-modal'));
setTimeout(() => {
	modalThree.closeModal();
}, 5000);

Specifying a DOM element to close the modal:

<button class="legend-modal-close">Close Modal</button>

Define options before modal content:

let modalFour = new LegendModal(null,{
    closeOnEscape: false,
    closeOnOverlayClick: false
});
modalFour.setContent(document.getElementById('test4-div'));

Alter options after modal instantiation:

let modalFive = new LegendModal();
modalFive.setContent(document.getElementById('test5-div'));
modalFive.setOptions({
    closeOnOverlayClick: true,
    closeOnEscape: false,
    visibleOverlay: true,
    showCloseButton: false
});