3.1.2 • Published 23 days ago

simple-modal-module v3.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
23 days ago

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

keyrequireddefaultnode
targetjs-modal-targetYou can specify the class name of the modal to be displayed.
navigation.openEljs-modal-openYou can specify the class name of the button that opens the modal.
navigation.closeEljs-modal-closeYou can specify the class name of the button that closes the modal.
hookClass.beforeOpenis-before-openYou can specify the name of the class just before the modal opens.
hookClass.openis-openYou can specify the class name when the modal opens.
hookClass.closeis-closeYou can specify the class name when the modal closes
animationtrueYou can specify whether or not to open a modal when you click navigation.openEl or navigation.closeEl.
autoFixedtrueSpecifies whether the page is fixed when the modal state is switched.
dataNamedata-modalYou can specify a dataAttribute name that specifies the same modal group.

return Values

keynode
showModalFunction to open the modal.
hideModalFunction to close the modal.
destroyFunction to remove a registered event listener.
openButtonsElement list of buttons to open the modal.
closeButtonsElement list of buttons to close the modal.
targetNodesModal Elements.

Target element's custom events

keydescription
m-initFired when a modal is created.
m-destroyFired when the modal is destroyed.
m-before-openFired when the modal starts to open.
m-openFired when the modal opens.
m-closeFired 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;
  }
}

オプション

keyrequireddefaultnode
targetjs-modal-target表示するモーダルのクラス名を指定できます
navigation.openEljs-modal-openモーダルを開くボタンのクラス名を指定できます
navigation.closeEljs-modal-closeモーダルを閉じるボタンのクラス名を指定できます
hookClass.beforeOpenis-before-openモーダルが開く直前のクラス名を指定できます
hookClass.openis-openモーダルが開らく時のクラス名を指定できます
hookClass.closeis-closeモーダルが閉じる時のクラス名を指定できます
animationtruenavigation.openElnavigation.closeElをクリックしたときにモーダルを開くかどうかを指定できます
autoFixedtrueモーダルの状態が切り替わったときに、ページを固定するかを指定します
dataNamedata-modal同一のモーダルグループを指定するdata属性名を指定できます

return値

keynode
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モーダルが閉じられる時に発火。
3.1.2

23 days ago

3.1.1

23 days ago

3.1.0

23 days ago

3.0.1

9 months ago

3.0.0

9 months ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.9

2 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.3

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.2

3 years ago

1.0.2

3 years ago

2.0.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago