# wc-accordion

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

Latest version **0.3.3** (published 2021-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install wc-accordion
pnpm add wc-accordion
yarn add wc-accordion
bun add wc-accordion
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2021-10-27 |
| First published | 2021-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | funkeeflow |

## Links

- npm: https://www.npmjs.com/package/wc-accordion
- Repository: https://github.com/funkeeflow/wc-accordion
- Homepage: https://funkeeflow.github.io/wc-accordion/
- Issues: https://github.com/funkeeflow/wc-accordion/issues
- npm.io page: https://npm.io/package/wc-accordion

## Recent versions

- 0.3.3 (latest) — 2021-10-27
- 0.3.2 — 2021-10-27
- 0.3.1 — 2021-10-07
- 0.3.0 — 2021-10-05
- 0.2.0 — 2021-10-05
- 0.1.5 — 2021-10-05
- 0.1.4 — 2021-10-05
- 0.1.3 — 2021-10-05
- 0.1.2 — 2021-10-04
- 0.1.1 — 2021-10-04

## README

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

This is mostly inspired by [this post][link-post] from Louis Hoebregts ([@Mamboleoo](https://twitter.com/mamboleoo)).

## Demo

Check out the [demo page][link-demo]. ☀️

## Usage

```bash
npm install wc-accordion
```
in your app entry point (e.g. `app.js`)
```js
import 'wc-accordion.js'
```
or import directly from **unpkg.com**
```html

<script type="module" src="https://unpkg.com/wc-accordion"></script>
```
Then just wrap your standard [\<details\>][detials] elements. Style the `<summary>` tag as you need. Take a wrapper class for your content and thats it!

```html
  <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:

```js
import { Accordion } from 'wc-accordion'

customElement.define('my-accordion', Accordion);
```

```html
<my-accordion>
...
</my-accordion>
```

## Properties

| Property              | Type                   | Description                                      |
|-----------------------|------------------------|--------------------------------------------------|
| **close**               | `(index: any) => void` | Close a item by index |
| **closeAll**            | `() => void`           | Close all at once |
| **open**                | `(index: any) => void` | Open a item by index |
| **openAll**             | `() => void`           | Open all at once |

## Attributes
| Attributes            | Values                 | Description                                     |
|-----------------------|------------------------|-------------------------------------------------|
| **mode**                | `exclusive`, `normal`  | Exclusive 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.

| Property              | Value                  |
|-----------------------|------------------------------|
| **--animation-duration**  | Duration of the animation    |
| **--animation-duration-start**  | Duration of the open animation    |
| **--animation-duration-end**  | Duration of the closing animation    |
| **--animation-easing**    | Animation ease (e.g. `ease-in`)      |

 **@media (prefers-reduced-motion)**

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

## Development
Install dev dependencies

```bash
yarn install
```
Link local package
```bash
yarn run link
yarn link wc-accordion
```
Run dev server
```bash
yarn dev
```

[link-demo]: https://funkeeflow.github.io/wc-accordion/
[link-license]: https://github.com/funkeeflow/wc-accordion/blob/master/LICENSE
[link-post]: https://css-tricks.com/how-to-animate-the-details-element-using-waapi/

[prefers-reduce-motion]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion

[detials]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
## Lincense

[MIT][link-license]

---
_Source: https://npm.io/package/wc-accordion · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
