3.0.4 • Published 7 years ago
react-toggle-switch v3.0.4
react-toggle-switch
A simple iOS inspired toggle switch.
Install
npm install --save react-toggle-switch
Demo
https://patrickgrimard.io/react-toggle-switch/
Usage
import React, {Component} from 'react';
import {render} from 'react-dom';
import Switch from 'react-toggle-switch'
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
switched: false
};
}
toggleSwitch = () => {
this.setState(prevState => {
return {
switched: !prevState.switched
};
});
};
render() {
return (
<div>
{/* Basic Switch */}
<Switch onClick={this.toggleSwitch} on={this.state.switched}/>
{/* With children */}
<Switch onClick={this.toggleSwitch} on={this.state.switched}>
<i class="some-icon"/>
</Switch>
{/* Disabled */}
<Switch onClick={this.toggleSwitch} on={this.state.switched} enabled={false}/>
{/* Custom classnames */}
<Switch onClick={this.toggleSwitch} on={this.state.switched} className='other-class'/>
</div>
);
}
}
export default MyComponent;
Upgrading to version 3.0.0
Please take note that as of version 3.0.0, a Switch
no longer maintains an internal state. Using this component
requires that you pass both an onClick
method and an on
value to set the current state of the Switch
. More
details about why this was changed can be found here.
Props
onClick
- Function handler to be called any time the switch is clicked.on
- Sets the switch on or off.enabled
- If set tofalse
, the switch cannot be toggled. Default istrue
.className
- Optional CSS classes for the root element.
Import Styling
@import "node_modules/react-toggle-switch/dist/css/switch.min.css"
3.0.4
7 years ago
3.0.3
7 years ago
3.0.2
7 years ago
3.0.1
7 years ago
3.0.0
7 years ago
2.1.4
8 years ago
2.1.3
8 years ago
2.1.2
9 years ago
2.1.1
9 years ago
2.1.0
9 years ago
2.0.1
9 years ago
2.0.0
9 years ago
1.1.2
9 years ago
1.1.1
9 years ago
1.1.0
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago
0.1.3
9 years ago
0.1.2
9 years ago
0.1.1
9 years ago
0.1.0
9 years ago