To install the module run: npm install --save lego-toggle
To use the toggle library, import like so:
import * as toggle from 'lego-toggle';
The first argument of each constructor is a HTMLElement, the second is an object of settings.
A Panel
requires the group
option to be populated with an instance of Group
.
A Trigger
requires the panel
options to be populated with an instance of Panel
.
- Can have many panels.
- Has one activePanel.
- Has one state associated.
String, default: 'active' The class that will be applied to the active panel and that panels triggers
String, default: null A callback method that will be invoked after a state change.
- activePanel: Panel instance [required] Sets the provided panel state to active and sets all other panels associated with this group to inactive. Also calls on the afterStateChange callback if provided.
Turns all panels associated with this group to false.
- options: object [required] Override exsisting options with provided object of settings.
- Belongs to one group.
- Can have many triggers.
Group instance, default: null The group that this panel belongs to.
Boolean, default: true If false, a panel can only be turned off by another panel being turned on.
- trigger: Trigger instance [required] Disassociates trigger with current panel.
- options: object [required] Override exsisting options with provided object of settings.
- active: Boolean [optional] Sets this panel state to active and sets all other panels associated with this panel's group to inactive. Also calls on the group's afterStateChange callback if provided.
- Belongs to one panel.
- State is bound to panel's state.
Panel instance, default: null The panel that this trigger belongs to.
String, default: 'click' The event attached to the trigger that sets the panel to active.
####inactiveEvent [optional]
String, default: 'click' The event attached to the trigger that sets the panel to inactive.
Disassociates trigger with it's panel.
Removes trigger element from the DOM.