A simple iOS inspired toggle switch.
npm install --save react-toggle-switch
import React from 'react';
import Switch from 'react-toggle-switch'
export default class MyComponent extends React.Component {
toggle(value) {
// do something with value
}
render() {
return (
<div>
<Switch value={'some string or integer value'} on={true} onClick={this.toggle}/>
<Switch onClick={() => this.setState({prop: !this.state.prop})}/>
<Switch onClick={this.toggle}>
<i class="some-icon"/>
</Switch>
</div>
);
}
}
onClick
- Required function handler for when the switch is clicked.value
- Required value that will be passed to the onClick handler.on
- Optional prop to set switch on or off. Default is false.
@import "node_modules/react-toggle-switch/dist/css/switch.min.css"