# storm-toggle

> Toggle UI state accessibly

Latest version **1.3.1** (published 2018-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install storm-toggle
pnpm add storm-toggle
yarn add storm-toggle
bun add storm-toggle
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2018-08-09 |
| First published | 2016-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | stormid |
| Maintainers | eikeco, jon-turnbull, mjbp, stormid-admin |
| Keywords | stormid, component, ui, toggle |

## Links

- npm: https://www.npmjs.com/package/storm-toggle
- Repository: https://github.com/stormid/storm-toggle
- Homepage: https://github.com/stormid/storm-toggle#readme
- Issues: https://github.com/stormid/storm-toggle/issues
- npm.io page: https://npm.io/package/storm-toggle

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.3.1 (latest) — 2018-08-09
- 1.3.0 — 2018-08-02
- 1.2.5 — 2018-06-29
- 1.2.4 — 2018-03-09
- 1.2.3 — 2018-02-14
- 1.2.2 — 2018-02-14
- 1.2.1 — 2018-01-12
- 1.2.0 — 2018-01-11
- 1.1.0 — 2018-01-10
- 1.0.2 — 2018-01-05
- 1.0.1 — 2017-11-17
- 1.0.0 — 2017-11-17
- 0.6.0 — 2017-11-16
- 0.4.1 — 2017-03-18
- 0.5.0 — 2016-07-21
- … 8 more at https://npm.io/package/storm-toggle/versions

## README

# Storm Toggle

[![npm version](https://badge.fury.io/js/storm-toggle.svg)](https://badge.fury.io/js/storm-toggle)

Accessible DOM state toggling for off-canvas and show/hide UI patterns.

## Usage

HTML
```
<button class="js-toggle-btn">Menu</button>
<nav class="js-toggle" data-toggle="js-toggle-btn">...</nav>
```

JS
```
npm i -S storm-toggle
```
either using es6 import
```
import Toggle from 'storm-toggle';

Toggle.init('.js-toggle');
```
aynchronous browser loading (use the .standalone version in the /dist folder)
```
import Load from 'storm-load';

Load('/content/js/async/storm-toggle.standalone.js')
    .then(() => {
        StormToggle.init('.js-toggle');
    });
```

### Local toggle
To encapsulate a toggle state within part of the document

HTML
```
<div class="parent">
    <button class="js-toggle__btn"></a>
    <div class="js-toggle__local" data-toggle="js-toggle__btn"></div>
</div>
```

CSS
```
.child {
    max-height:0;
    overflow:hidden;
    transition: max-width 160ms ease;
}
.parent.active .child {
    max-height:1000px;
}
```

## Options
```
{
	delay: 0, //duration of animating out of toggled state
	startOpen: false,  //initial toggle state
	local: false, // encapsulate in small part of document
	prehook: false, //function to fire before each toggle
	callback: false, //function to fire after each toggle
	focus: false, //focus on first focusable child node of the target element
	trapTab: false //trap tab in the target element
	closeOnBlur: false //close the target node on losing focus from the target node and any of the toggles
}
```
e.g.
```
Toggle.init('.js-toggle', {
    startOpen: true
});
```

## Tests
```
npm run test
```

## Browser support
This is module has both es6 and es5 distributions. The es6 version should be used in a workflow that transpiles.

The es5 version depends upon Object.assign so all evergreen browsers are supported out of the box, ie9+ is supported with polyfills. ie8+ will work with even more polyfils for Array functions and eventListeners.

## Dependencies
None

## License
MIT

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