Skip to content

Repository files navigation

Bootstrap Switch

Dependency StatusdevDependency StatusNPM Version

This project is a port of bootstrap-switch for use in React.js

Compatability

Verion 3.4.x is built for React.js 0.14. It will not work with earlier versions of React.js.

NOTE: The CSS from the original version is not fully compatible. There is CSS and LESS included in this repo, or any 3rd party themes can likely be made compatible with the changes shown in this commit.

Usage

Installation

npm install react-bootstrap-switch

Then

var Switch = require('react-bootstrap-switch');
...
render: function() {
return <Switch />;
}

API

Properties

These should be defined on the JSX node, many cannot be changed once they have been set without recreating the node.

NameTypeDefaultValuesDescription
statebooleantruetrue, falseInitial starting state of the switch
sizestringnullnull, 'mini', 'small', 'normal', 'large'The checkbox size
animatebooleantruetrue, falseAnimate the switch
disabledbooleanfalsetrue, falseDisable state
readonlybooleanfalsetrue, falseReadonly state
indeterminatebooleanfalsetrue, falseIndeterminate state
inversebooleanfalsetrue, falseInverse switch direction
onColorstring'primary''primary', 'info', 'success', 'warning', 'danger', 'default'Color of the on state of the switch
offColorstring'default''primary', 'info', 'success', 'warning', 'danger', 'default'Color of the off state of the switch
onTextstring'ON'Text of the on state of the switch
offTextstring'OFF'Text of the off state of the switch
labelTextstring''Text of the center handle of the switch
handleWidthstring or number'auto''auto' or NumberWidth of the left and right sides in pixels
labelWidthstring or number'auto''auto' or NumberWidth of the center handle in pixels
baseClassstring'bootstrap-switch'Global class prefix
wrapperClassstring'wrapper'Container element class(es)
onChangefunctionundefinedfunction(elm, state){} or function(state){}

Methods

NameParametersDescription
valuebooleanGet or set the switch state
valueStatebooleanGet or set the switch state
toggleValueToggle the switch state
toggleStateToggle the switch state
disabledbooleanGet or set the disabled state
toggleDisabledToggle the disabled state
readonlybooleanGet or set the readonly state
toggleReadonlyToggle the readonly state
handleWidthstring or numberSet the width of the left and right sides in pixels
labelWidthstring or numberSet the width of the center handle in pixels

Supported browsers

IE9+ and all the other modern browsers.

LESS

Import src/less/bootstrap2/bootstrap-switch.less for bootstrap 2 or src/less/bootstrap3/bootstrap-switch.less for bootstrap 3 in your compilation stack.

NOTE: The LESS files from the original switch are not fully compatible, updated versions are included in this repo.

License

Licensed under the MIT License

About

Turn checkboxes in toggle switches.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages