1.1.5 • Published 1 year ago

web-accordion v1.1.5

Weekly downloads
14
License
BSD-2
Repository
github
Last release
1 year ago

Built With Stencil Published on webcomponents.org

web-accordion is a lightweight, dependency-free, styleable accordion web component.

Installation

Script tag

<script type="module" src="https://unpkg.com/web-accordion/dist/web-accordion/web-accordion.esm.js"></script>
<script nomodule src="https://unpkg.com/web-accordion/dist/web-accordion/web-accordion.js"></script>

Node Module

  • Install via npm: npm install web-accordion --save
  • Import web-accordion in your JavaScript and defineCustomElements:

import { defineCustomElements } from 'web-accordion';
defineCustomElements();

Framework integration

For integration with different frameworks the stencil docs should be consulted.

Using this component

Add the web-accordion component as the accordion parent to your html. For each accordion entry add a web-accrdion-item. Add a slot="title" for the respective accordion item header:

<web-accordion>
  <web-accordion-item>
    <h1 slot="title">item no 1</h1>
    <div>content of item no 1</div>
  </web-accordion-item>
  <web-accordion-item>
    <h1 slot="title">item no 2</h1>
    <div>content of item no 2</div>
  </web-accordion-item>
</web-complete>

A full example with some styling can be found here.

web-accordion API

Methods

close(index: number) => Promise<void>

close an accordion item

Returns

Type: Promise<void>

open(index: number) => Promise<void>

Open an accordion item

Returns

Type: Promise<void>

web-accordion-item API

Properties

PropertyAttributeDescriptionTypeDefault
indexindexindex of accordion item from top to bottomnumber-1
mutationObserverConfig--The mutation observer config to listen for content changes in the accordion item{ childList: boolean; subtree: boolean; }{ childList: true, subtree: true }
openopenaccordion item is open or opening (css transition)booleanfalse

Events

EventDescriptionType
contentChangedtriggered when the content of the accordion item changesCustomEvent<any>
openEventtriggered when the accordion item is openedCustomEvent<any>

Methods

closeItem() => Promise<void>

close the accordion item

Returns

Type: Promise<void>

openItem() => Promise<void>

open the accordion item

Returns

Type: Promise<void>

Developer

npm i            install dependencies
npm start        start local development 
npm run build    build component for production
npm test         run e2e tests
1.1.5

1 year ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago