Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/segment-boneyard/toggle

A toggle UI element.
https://github.com/segment-boneyard/toggle

Last synced: about 5 hours ago
JSON representation

A toggle UI element.

Awesome Lists containing this project

README

        

# toggle

A toggle UI element.

![on](https://i.cloudup.com/kjeyaT5oFH.png)
![off](https://i.cloudup.com/hEd5319GKt.png)

## Installation

$ component install segmentio/toggle

## Example

```js
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.

```html








```

### #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