A simple iOS inspired toggle switch.
npm install --save react-toggle-switch
import React from 'react';
import {render} from 'react-dom';
import Switch from 'react-toggle-switch'
export default class MyComponent extends React.Component {
render() {
return (
<div>
<Switch onClick={() => this.setState({prop: !this.state.prop})}/>
<Switch onClick={this.toggle}>
<i class="some-icon"/>
</Switch>
<Switch enabled={false}/>
<Switch className='other-class'/>
</div>
);
}
}
onClick
- Function handler to be called any time the switch is clicked.on
- Sets the switch on or off. This can be useful if you want to update the state of the switch without actually clicking on it. Default isfalse
.enabled
- If set tofalse
, the switch cannot be toggled. Default istrue
.className
- An optional classname for the root element
@import "node_modules/react-toggle-switch/dist/css/switch.min.css"