A tiny JavaScript library to easily toggle the state of any HTML element and its targets.
Dropdown, navigation button, tooltip, collapsible panel, lightbox, tabs, switch like above… UI components made in minutes without worried about JavaScript. Only set a few HTML attributes, and code the rest with your CSS skills.
A front-end developer often has to code scripts for interface components. Components such as drop-downs, navigation buttons, tooltips, expandable panels, lightboxes, tabs, etc.
The thing is… Most of these components expose a recurrent behavior: a trigger element toggles the state of one or more target elements. So why not code this behavior once and for all?
So here is a solution: a simple script to toggle the state of a trigger element with a CSS class. You can then associate this element with one or more others: let's call them targets. By adding the right HTML attributes, it can adapt to any contexts and behave like a chosen component.
Only focus on adjusting the rest with your CSS creativity.
Several quick start options are available:
- Direct download
- Choose another version: ES5, ES6 or a build for IE11 with polyfills
- Clone the repo:
git clone https://github.com/twikito/easy-toggle-state.git
- Install with npm:
npm install easy-toggle-state
Then, add the script into your page, and it's done.
Easy Toggle State's documentation is hosted on GitHub Pages at twikito.github.io/easy-toggle-state/.
- Fork repository on GitHub
- Report a bug
- Suggest a feature
- Development:
npm run build
MIT. Copyright (c) Matthieu Bué