1.0.6 • Published 5 months ago

@itkyk/accordion v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

accordion

install

$ npm i @itkyk/accordion

How to use @itkyk/accordion

<div class="js-accordion">
  <div class="js-accordion-wrap">
    <div class="js-accordion-inner">
      <!--- Your Markup Contents --->
    </div>
  </div>
</div>
import Accordion from "@itkyk/accordion";

// Initialize
const option = {};
const accordion = new Accordion(".js-accordion", option)
/* OR
const accordion = new Accordion(document.querySelector(".js-accordion"), option)
*/
// add callbacks
accordion.setOpenCallback(() => {
  // add function
  console.log("open");
})

accordion.setCloseCallback(()=>{
  // add function
  console.log("close");
})

// start acrodion
accordion.mount();

// desctoy event listener & remove height
accordion.destroy();

Option

keydefaultvaluedescription
type"toggle""toggle""divide"select button type.
button".js-accordion-button"string or HTMLElementif type is toggle, open or close torigger className of dom
buttons{open: ".js-accordion-button-open", close: ".js-accordion-button-close"}{open: string or HTMLElement, close: string or HTMLElement}if type is , open or close torigger of html elements className of each dom.
wrapper".js-accordion-wrap"string of HTMLElementaccordion wrapper hrml element or className of dom
inner".js-accordion-inner"string of HTMLElementaccordion inner html element or className of dom
initialHeightnullnull or number or className or Elementwhen be closing accordion, set height value. if setting null, .style.height = "";.

methods

keydescription
mountset accordion logics
destroyremove addEventListeners
setOpenCallbackadded function of when opening the accordion
setCloseCallbackadded function of when closing the accordion
getOpenFlagGetting open status. Return Value is true or false

vars

keydescription
targetwhen initialize, set target DOM
buttonwhen initialize, set button DOM or button DOMs
wrapwhen initialize, set wrapper DOM
innerwhen initialize, set inner DOM

Change Log

  • v1.0.6
    • Corrected to remove wrapper height when destroying.
  • v1.0.5
    • Fixed a bug when passing HTMLElement in option.
1.0.6

5 months ago

1.0.5

5 months ago

1.0.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago