1.0.1 • Published 5 years ago
js-toggle-switch v1.0.1
js-toggle-switch
A toggle switch on native Javascript.
Install
Via NPM:
$ npm install js-toggle-switchUsage
Include:
// include style and script
<link href="dist/toggle-switch.min.css" rel="stylesheet">
<script type="text/javascript" src="dist/toggle-switch.min.js"></script>Add checkbox:
<input type="checkbox" name="some_chekbox_name">Initialize toggle switch:
<script type="text/javascript">
var toggleSwitch = new ToggleSwitch('input[name="some_chekbox_name"]');
</script>Build
Using Docker
Run dev environment:
$ docker-compose upLogin, install packages and build:
$ docker-compose run ext bash
$ npm install
$ npm run buildUsing locale dev environment
$ npm install
$ npm run buildOptions
The options inject to the second argument of ToggleSwitch. Options is object.
new ToggleSwitch('.some-checkbox', {
onLabel: 'Yes', // [string] - Label for `true` value of checkbox.
offLabel: 'No' // [string] - Label for `false` value of checkbox.
})ToggleSwitch.defaultOptionsobject - Default options for everything new instances.
Methods
- getValue() string - Returns current value of the checkbox.
- turnOn() - Set to "true" the checkbox value.
- turnOff() - Set to "false" the checkbox value.
- toggle() - Set to "false"/"true" the checkbox value.
- destroy() - Destroy the toggle switch and restore the orginal checkbox.
Run tests
Using Docker
$ docker-compose run --rm ext npm run test:run-without-coverageUsing locale dev environment
$ npm run test:run-without-coverageLicense
js-toggle-switch is released under the BSD-3-Clause License.