Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-switch

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-switch - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

15

dist/index.js

@@ -44,3 +44,3 @@ 'use strict';

_this.state = {
left: props.checked ? props.width - props.height : 1,
left: props.checked ? props.width - props.height + 1 : 1,
inTransition: false,

@@ -83,4 +83,3 @@ startX: null,

key: 'handleKeyDown',
value: function handleKeyDown(_ref) {
var keyCode = _ref.keyCode;
value: function handleKeyDown(event) {
var _props3 = this.props,

@@ -92,3 +91,4 @@ checked = _props3.checked,

if (keyCode === 32 && !isDragging) {
if (event.keyCode === 32 && !isDragging) {
event.preventDefault();
onChange(!checked);

@@ -208,5 +208,6 @@ }

position: 'relative',
WebkitTransition: 'background-color 0.2s',
MozTransition: 'background-color 0.2s',
transition: 'background-color 0.2s'
opacity: disabled ? 0.5 : 1,
WebkitTransition: 'all 0.2s',
MozTransition: 'all 0.2s',
transition: 'all 0.2s'
}

@@ -213,0 +214,0 @@ },

{
"name": "react-switch",
"version": "1.0.0",
"version": "1.1.0",
"description": "Draggable toggle-switch component for react",

@@ -9,5 +9,8 @@ "main": "dist/index.js",

"build:watch": "babel src -w -d dist",
"build-examples": "webpack -p",
"lint": "eslint --ext .js,.jsx src/",
"prepublishOnly": "npm run build",
"test": "jest --verbose"
"test": "jest --verbose",
"start": "webpack-dev-server",
"stats": "webpack --profile --json > stats.json"
},

@@ -32,5 +35,7 @@ "repository": {

"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"css-loader": "^0.28.7",
"enzyme": "^2.9.1",

@@ -42,8 +47,14 @@ "eslint": "^4.6.1",

"eslint-plugin-react": "^7.3.0",
"html-webpack-plugin": "^2.30.1",
"jest": "^21.1.0",
"react-test-renderer": "^15.6.1"
"react-test-renderer": "^15.6.1",
"style-loader": "^0.18.2",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.8.2"
},
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-draggable": "^3.0.3"
}
}
# react-switch
Draggable toggle-switch component for react
A draggable, customizable and accessible toggle-switch component for React.
## Demo
[Take a look at the demo.](https://yogaboll.github.io/react-switch/)
## Installation
```bash
npm install react-switch --save
```
## Usage
```javascript
import React, { Component } from 'react';
import Switch from 'react-switch';
class SwitchExample extends Component {
constructor() {
super();
this.state = { checked: false };
this.handleChange = this.handleChange.bind(this);
}
handleChange(checked) {
this.setState({ checked });
}
render() {
return (
<div>
<label htmlFor="example-switch">Look, an example switch!</label>
<Switch
onChange={this.handleChange}
checked={this.state.checked}
id="example-switch"
/>
</div>
);
}
}
```
## API
| Prop | Type | Default | Description |
| ---- |----- | ------- | ----------- |
| checked | bool | **Required** | If true, the switch is set to checked. If false, it is not checked. |
| onChange | func | **Required** | Invoked when the user clicks or drags the switch. It is passed one argument, *checked*, which is a boolean that describes the presumed future state of the checked prop. |
| disabled | bool | false | When disabled, the switch will no longer be interactive and its colors will be greyed out. |
| offColor | string | 'grey' | The switch will take on this color when it is *not* checked |
| onColor | string | 'green' | The switch will take on this color when it is checked. |
| handleColor | string | 'white' | The handle of the switch will take on this color when it is *not* active. If you use this prop, make sure to also change *activeHandleColor* to something appropriate. |
| activeHandleColor | string | '#ddd' | The handle of the switch will take on this color when it is active, meaning when it is dragged or clicked. |
| height | number | 28 | The height of the component, measured in pixels. |
| width | number | 56 | The width of the component, measured in pixels. |
| className | string | null | Set as the className of the outer shell of the switch. |
| id | string | null | Set as an attribute to the embedded checkbox. This is useful for the associated label, which can point to the id in its htmlFor attribute. |
| aria-labelledby | string | null | Set as an attribute of the embedded checkbox. This should be the same as the id of a label. |
| aria-label | string | null | Set as an attribute of the embedded checkbox. Its value will only be seen by screen readers. |
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc