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

simple-modal-module

v3.1.2

Published

This library makes it easy to implement modals.

Downloads

86

Readme

Simple-Modal-Module

Language

npm install simple-modal-module

Setup

<div className="js-modal-open" data-modal="sampleModal">OPEN</div>
<div className="js-modal-target" data-modal="sampleModal">
   <button class="js-modal-close" data-modal="sampleModal">CLOSE</button>
       <!--- You can make contents here --->
</div>
// Basic usage
import createModal from "simple-modal-module";
const modal = createModal("sampleModal");
// or when need override options
const modal = createModal("simpleModal", {
    animation: false
})

// methods
modal.openButtons // open button elements
modal.closeButtons // close button elements
modal.targetNodes // modal target elements
modal.showModal() // open modal
modal.hideModal() // close modal
modal.destroy() // remove evenr listeners.

// events
for (const target of targetNodes) {
  target.addEventListener("m-init", () => {});
  target.addEventListener("m-destroy", () => {});
  target.addEventListener("m-before-open", () => {});
  target.addEventListener("m-open", () => {});
  target.addEventListener("m-close", () => {});
}
// Other APIs
import {enableFixedPage, disableFixedPage} from "simple-modal-module";

// Fixed Page
enableFixedPage();

// Unfixed Page
disableFixedPage();
.js-modal-target {
  transition: opacity 0.4s ease;
  &.is-before-open {
    opacity: 0;
  }
  &.is-open {
    opacity: 1;
  }
  &.is-close {
    opacity: 0;
  }
}

Options

| key | required | default | node | |:--------------------:|:--------------:|----------------|------------------------------------------------------------------------------------------------------------| | target | | js-modal-target | You can specify the class name of the modal to be displayed. | | navigation.openEl | | js-modal-open | You can specify the class name of the button that opens the modal. | | navigation.closeEl | | js-modal-close | You can specify the class name of the button that closes the modal. | | hookClass.beforeOpen | | is-before-open | You can specify the name of the class just before the modal opens. | | hookClass.open | | is-open | You can specify the class name when the modal opens. | | hookClass.close | | is-close | You can specify the class name when the modal closes | | animation | | true | You can specify whether or not to open a modal when you click navigation.openEl or navigation.closeEl. | | autoFixed | | true | Specifies whether the page is fixed when the modal state is switched. | | dataName | | data-modal | You can specify a dataAttribute name that specifies the same modal group. |

return Values

| key | node | |:--------------------:|-------------------------------------------------| | showModal | Function to open the modal. | | hideModal | Function to close the modal. | | destroy | Function to remove a registered event listener. | | openButtons | Element list of buttons to open the modal. | | closeButtons | Element list of buttons to close the modal. | | targetNodes | Modal Elements. |

Target element's custom events

| key | description | |:-------------:|-------------------------------------------------| | m-init | Fired when a modal is created. | | m-destroy | Fired when the modal is destroyed. | | m-before-open | Fired when the modal starts to open. | | m-open | Fired when the modal opens. | | m-close | Fired when modal closes. |


npm install simple-modal-module

使い方

<div className="js-modal-open" data-modal="sampleModal">OPEN</div>
<div className="js-modal-target" data-modal="sampleModal">
   <button class="js-modal-close" data-modal="sampleModal">CLOSE</button>
       <!--- You can make contents here --->
</div>
// Basic usage
import createModal from "simple-modal-module";
const modal = createModal("sampleModal");
// or when need override options
const modal = createModal("simpleModal", {
    animation: false
})

// メソッド
modal.openButtons // open button elements
modal.closeButtons // close button elements
modal.targetNodes // modal target elements
modal.showModal() // open modal
modal.hideModal() // close modal
modal.destroy() // remove evenr listeners.

// イベント
for (const target of targetNodes) {
  target.addEventListener("m-init", () => {});
  target.addEventListener("m-destroy", () => {});
  target.addEventListener("m-before-open", () => {});
  target.addEventListener("m-open", () => {});
  target.addEventListener("m-close", () => {});
}
// Other APIs
import {enableFixedPage, disableFixedPage} from "simple-modal-module";

// Fixed Page
enableFixedPage();

// Unfixed Page
disableFixedPage();
.js-modal-target {
  transition: opacity 0.4s ease;
  &.is-before-open {
    opacity: 0;
  }
  &.is-open {
    opacity: 1;
  }
  &.is-close {
    opacity: 0;
  }
}

オプション

| key | required | default | node | |:--------------------:|:--------------:|-----------------|------------------------------------------------------------------| | target | | js-modal-target | 表示するモーダルのクラス名を指定できます | | navigation.openEl | | js-modal-open | モーダルを開くボタンのクラス名を指定できます | | navigation.closeEl | | js-modal-close | モーダルを閉じるボタンのクラス名を指定できます | | hookClass.beforeOpen | | is-before-open | モーダルが開く直前のクラス名を指定できます | | hookClass.open | | is-open | モーダルが開らく時のクラス名を指定できます | | hookClass.close | | is-close | モーダルが閉じる時のクラス名を指定できます | | animation | | true | navigation.openElnavigation.closeElをクリックしたときにモーダルを開くかどうかを指定できます | | autoFixed | | true | モーダルの状態が切り替わったときに、ページを固定するかを指定します | | dataName | | data-modal | 同一のモーダルグループを指定するdata属性名を指定できます |

return値

| key | node | |:--------------------:|----------------------| | showModal | モーダルを開く関数 | | hideModal | モーダルを閉じる関数 | | destroy | 登録されたイベントリスナーを解除する関数 | | openButtons | モーダルを開くためのボタンのエレメントリスト | | closeButtons | モーダルを閉じるためのボタンのエレメントリスト | | targetNodes | モーダル本体のエレメント |

Target element's custom events

| key | 説明 | |:-------------:|------------------------| | m-init | モーダルがinitされた時に発火。 | | m-destroy | モーダルがdestroyされた時に発火。 | | m-before-open | モーダルが開く直前に発火。 | | m-open | モーダルが開かれる時に発火。 | | m-close | モーダルが閉じられる時に発火。 |