Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

DemocracyOS/toggle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 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

About

A toggle UI element.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 95.0%
  • CSS 4.3%
  • Other 0.7%