Skip to content

segment-boneyard/toggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toggle

A toggle UI element.

on off

Installation

$ component install segmentio/toggle

Example

var Toggle = require('toggle');

var toggle = new Toggle();
document.body.appendChild(toggle.el);

toggle.value(); // false

toggle.value(true);
toggle.value(); // true

toggle.toggle();
toggle.value(); // false

API

Toggle(value, el)

Create a new toggle with an optional starting value and optional el to use instead of creating one.

#el

The toggle's DOM element.

<div class="toggle">
  <label class="toggle-on-label"></label>
  <div class="toggle-switch">
    <input class="toggle-checkbox" type="checkbox">
  </div>
  <label class="toggle-off-label"></label>
</div>

#value(val)

Get or set the value of the toggle.

#name(name)

Set the toggle's internal checkbox's name, so forms can be submitted properly.

#toggle()

Toggle the value of the toggle.

#label(on, off)

Set the on and off labels's HTML.

#addClass(name)

Add a class to the toggle's element.

#removeClass(name)

Remove a class from the toggle's element.

License

MIT