0.3.3 • Published 3 years ago

wc-accordion v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

wc-accordion 🏖

A vanilla, a11y ready web component for your basic accordion needs. Small, simple, nothing more.

This is mostly inspired by this post from Louis Hoebregts (@Mamboleoo).

Demo

Check out the demo page. ☀️

Usage

npm install wc-accordion

in your app entry point (e.g. app.js)

import 'wc-accordion.js'

or import directly from unpkg.com

<script type="module" src="https://unpkg.com/wc-accordion"></script>

Then just wrap your standard \<details> elements. Style the <summary> tag as you need. Take a wrapper class for your content and thats it!

  <wc-accordion class="accordion">
    <details>
      <summary>Some details</summary>
      <div class="wrapper">
        <p>
          Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
        </p>
      </div>
    </details>
    <details>
      <summary>Some details</summary>
      <div class="wrapper">
        <p>
          Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
        </p>
      </div>
    </details>
    <details>
      <summary>Some details</summary>
      <div class="wrapper">
        <p>
          Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
        </p>
      </div>
    </details>
  </wc-accordion>

How to use a custom component name

To use a custom name for the element, import the default class and define the element yourself like so:

import { Accordion } from 'wc-accordion'

customElement.define('my-accordion', Accordion);
<my-accordion>
...
</my-accordion>

Properties

PropertyTypeDescription
close(index: any) => voidClose a item by index
closeAll() => voidClose all at once
open(index: any) => voidOpen a item by index
openAll() => voidOpen all at once

Attributes

AttributesValuesDescription
modeexclusive, normalExclusive will limit to only one open item at a time

CSS Custom Properties

Use the following custom properties on the your <detials> elements to set animation timings and easing.

PropertyValue
--animation-durationDuration of the animation
--animation-duration-startDuration of the open animation
--animation-duration-endDuration of the closing animation
--animation-easingAnimation ease (e.g. ease-in)

@media (prefers-reduced-motion)

The component queries the CSS Media feature prefers-reduced-motion and if set it will skip open and close animation all together.

Development

Install dev dependencies

yarn install

Link local package

yarn run link
yarn link wc-accordion

Run dev server

yarn dev

Lincense

MIT

0.3.2

3 years ago

0.3.3

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago