A toggle UI element.
JavaScript CSS
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib added toggle label class Sep 26, 2013
test merged Sep 26, 2013
.gitignore
History.md Release 0.1.1 Aug 26, 2014
Makefile
Readme.md
component.json Release 0.1.1 Aug 26, 2014
index.css add duo support Aug 26, 2014

Readme.md

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