Comparing version 1.8.0 to 1.9.0
240
es/Switch.js
@@ -1,31 +0,92 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _defineProperty from 'babel-runtime/helpers/defineProperty'; | ||
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties'; | ||
import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; | ||
import _createClass from 'babel-runtime/helpers/createClass'; | ||
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; | ||
import _inherits from 'babel-runtime/helpers/inherits'; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { polyfill } from 'react-lifecycles-compat'; | ||
var classNames = require('classnames'); | ||
function noop() {} | ||
var Switch = function (_Component) { | ||
var Switch = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(Switch, _Component); | ||
function Switch(props) { | ||
var _this; | ||
_classCallCheck(this, Switch); | ||
var _this = _possibleConstructorReturn(this, (Switch.__proto__ || Object.getPrototypeOf(Switch)).call(this, props)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Switch).call(this, props)); | ||
_initialiseProps.call(_this); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleClick", function (e) { | ||
var checked = _this.state.checked; | ||
var onClick = _this.props.onClick; | ||
var newChecked = !checked; | ||
var checked = false; | ||
_this.setChecked(newChecked, e); | ||
if (onClick) { | ||
onClick(newChecked, e); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleKeyDown", function (e) { | ||
if (e.keyCode === 37) { | ||
// Left | ||
_this.setChecked(false, e); | ||
} else if (e.keyCode === 39) { | ||
// Right | ||
_this.setChecked(true, e); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleMouseUp", function (e) { | ||
var onMouseUp = _this.props.onMouseUp; | ||
if (_this.node) { | ||
_this.node.blur(); | ||
} | ||
if (onMouseUp) { | ||
onMouseUp(e); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "saveNode", function (node) { | ||
_this.node = node; | ||
}); | ||
var _checked = false; | ||
if ('checked' in props) { | ||
checked = !!props.checked; | ||
_checked = !!props.checked; | ||
} else { | ||
checked = !!props.defaultChecked; | ||
_checked = !!props.defaultChecked; | ||
} | ||
_this.state = { checked: checked }; | ||
_this.state = { | ||
checked: _checked | ||
}; | ||
return _this; | ||
@@ -35,7 +96,7 @@ } | ||
_createClass(Switch, [{ | ||
key: 'componentDidMount', | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
autoFocus = _props.autoFocus, | ||
disabled = _props.disabled; | ||
var _this$props = this.props, | ||
autoFocus = _this$props.autoFocus, | ||
disabled = _this$props.disabled; | ||
@@ -47,16 +108,12 @@ if (autoFocus && !disabled) { | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
if ('checked' in nextProps) { | ||
this.setState({ | ||
checked: !!nextProps.checked | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'setChecked', | ||
value: function setChecked(checked) { | ||
if (this.props.disabled) { | ||
key: "setChecked", | ||
value: function setChecked(checked, e) { | ||
var _this$props2 = this.props, | ||
disabled = _this$props2.disabled, | ||
onChange = _this$props2.onChange; | ||
if (disabled) { | ||
return; | ||
} | ||
if (!('checked' in this.props)) { | ||
@@ -67,9 +124,9 @@ this.setState({ | ||
} | ||
this.props.onChange(checked); | ||
if (onChange) { | ||
onChange(checked, e); | ||
} | ||
} | ||
// Handle auto focus when click switch in Chrome | ||
}, { | ||
key: 'focus', | ||
key: "focus", | ||
value: function focus() { | ||
@@ -79,3 +136,3 @@ this.node.focus(); | ||
}, { | ||
key: 'blur', | ||
key: "blur", | ||
value: function blur() { | ||
@@ -85,38 +142,43 @@ this.node.blur(); | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _classNames; | ||
var _props2 = this.props, | ||
className = _props2.className, | ||
prefixCls = _props2.prefixCls, | ||
disabled = _props2.disabled, | ||
loadingIcon = _props2.loadingIcon, | ||
checkedChildren = _props2.checkedChildren, | ||
unCheckedChildren = _props2.unCheckedChildren, | ||
restProps = _objectWithoutProperties(_props2, ['className', 'prefixCls', 'disabled', 'loadingIcon', 'checkedChildren', 'unCheckedChildren']); | ||
var _this$props3 = this.props, | ||
className = _this$props3.className, | ||
prefixCls = _this$props3.prefixCls, | ||
disabled = _this$props3.disabled, | ||
loadingIcon = _this$props3.loadingIcon, | ||
checkedChildren = _this$props3.checkedChildren, | ||
unCheckedChildren = _this$props3.unCheckedChildren, | ||
restProps = _objectWithoutProperties(_this$props3, ["className", "prefixCls", "disabled", "loadingIcon", "checkedChildren", "unCheckedChildren"]); | ||
var checked = this.state.checked; | ||
var switchClassName = classNames((_classNames = {}, _defineProperty(_classNames, className, !!className), _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, prefixCls + '-checked', checked), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _classNames)); | ||
return React.createElement( | ||
'button', | ||
_extends({}, restProps, { | ||
type: 'button', | ||
role: 'switch', | ||
'aria-checked': checked, | ||
disabled: disabled, | ||
className: switchClassName, | ||
ref: this.saveNode, | ||
onKeyDown: this.handleKeyDown, | ||
onClick: this.toggle, | ||
onMouseUp: this.handleMouseUp | ||
}), | ||
loadingIcon, | ||
React.createElement( | ||
'span', | ||
{ className: prefixCls + '-inner' }, | ||
checked ? checkedChildren : unCheckedChildren | ||
) | ||
); | ||
var switchClassName = classNames((_classNames = {}, _defineProperty(_classNames, className, !!className), _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames)); | ||
return React.createElement("button", _extends({}, restProps, { | ||
type: "button", | ||
role: "switch", | ||
"aria-checked": checked, | ||
disabled: disabled, | ||
className: switchClassName, | ||
ref: this.saveNode, | ||
onKeyDown: this.handleKeyDown, | ||
onClick: this.handleClick, | ||
onMouseUp: this.handleMouseUp | ||
}), loadingIcon, React.createElement("span", { | ||
className: "".concat(prefixCls, "-inner") | ||
}, checked ? checkedChildren : unCheckedChildren)); | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps) { | ||
var newState = {}; | ||
var checked = nextProps.checked; | ||
if ('checked' in nextProps) { | ||
newState.checked = !!checked; | ||
} | ||
return newState; | ||
} | ||
}]); | ||
@@ -127,37 +189,2 @@ | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.toggle = function () { | ||
var onClick = _this2.props.onClick; | ||
var checked = !_this2.state.checked; | ||
_this2.setChecked(checked); | ||
onClick(checked); | ||
}; | ||
this.handleKeyDown = function (e) { | ||
if (e.keyCode === 37) { | ||
// Left | ||
_this2.setChecked(false); | ||
} else if (e.keyCode === 39) { | ||
// Right | ||
_this2.setChecked(true); | ||
} | ||
}; | ||
this.handleMouseUp = function (e) { | ||
if (_this2.node) { | ||
_this2.node.blur(); | ||
} | ||
if (_this2.props.onMouseUp) { | ||
_this2.props.onMouseUp(e); | ||
} | ||
}; | ||
this.saveNode = function (node) { | ||
_this2.node = node; | ||
}; | ||
}; | ||
Switch.propTypes = { | ||
@@ -178,3 +205,2 @@ className: PropTypes.string, | ||
}; | ||
Switch.defaultProps = { | ||
@@ -185,7 +211,5 @@ prefixCls: 'rc-switch', | ||
className: '', | ||
defaultChecked: false, | ||
onChange: noop, | ||
onClick: noop | ||
defaultChecked: false | ||
}; | ||
polyfill(Switch); | ||
export default Switch; |
@@ -0,1 +1,5 @@ | ||
## 1.9.0 | ||
- onChange and onClick support pass event as argument. | ||
## 1.7.0 | ||
@@ -2,0 +6,0 @@ |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = require('./Switch'); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,71 +6,110 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports["default"] = void 0; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _reactLifecyclesCompat = require("react-lifecycles-compat"); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } } | ||
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var _react = require('react'); | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var _react2 = _interopRequireDefault(_react); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var _propTypes = require('prop-types'); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var classNames = require('classnames'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var Switch = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(Switch, _Component); | ||
var classNames = require('classnames'); | ||
function Switch(props) { | ||
var _this; | ||
function noop() {} | ||
_classCallCheck(this, Switch); | ||
var Switch = function (_Component) { | ||
(0, _inherits3['default'])(Switch, _Component); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Switch).call(this, props)); | ||
function Switch(props) { | ||
(0, _classCallCheck3['default'])(this, Switch); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleClick", function (e) { | ||
var checked = _this.state.checked; | ||
var onClick = _this.props.onClick; | ||
var newChecked = !checked; | ||
var _this = (0, _possibleConstructorReturn3['default'])(this, (Switch.__proto__ || Object.getPrototypeOf(Switch)).call(this, props)); | ||
_this.setChecked(newChecked, e); | ||
_initialiseProps.call(_this); | ||
if (onClick) { | ||
onClick(newChecked, e); | ||
} | ||
}); | ||
var checked = false; | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleKeyDown", function (e) { | ||
if (e.keyCode === 37) { | ||
// Left | ||
_this.setChecked(false, e); | ||
} else if (e.keyCode === 39) { | ||
// Right | ||
_this.setChecked(true, e); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleMouseUp", function (e) { | ||
var onMouseUp = _this.props.onMouseUp; | ||
if (_this.node) { | ||
_this.node.blur(); | ||
} | ||
if (onMouseUp) { | ||
onMouseUp(e); | ||
} | ||
}); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "saveNode", function (node) { | ||
_this.node = node; | ||
}); | ||
var _checked = false; | ||
if ('checked' in props) { | ||
checked = !!props.checked; | ||
_checked = !!props.checked; | ||
} else { | ||
checked = !!props.defaultChecked; | ||
_checked = !!props.defaultChecked; | ||
} | ||
_this.state = { checked: checked }; | ||
_this.state = { | ||
checked: _checked | ||
}; | ||
return _this; | ||
} | ||
(0, _createClass3['default'])(Switch, [{ | ||
key: 'componentDidMount', | ||
_createClass(Switch, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
autoFocus = _props.autoFocus, | ||
disabled = _props.disabled; | ||
var _this$props = this.props, | ||
autoFocus = _this$props.autoFocus, | ||
disabled = _this$props.disabled; | ||
@@ -82,16 +121,12 @@ if (autoFocus && !disabled) { | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
if ('checked' in nextProps) { | ||
this.setState({ | ||
checked: !!nextProps.checked | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'setChecked', | ||
value: function setChecked(checked) { | ||
if (this.props.disabled) { | ||
key: "setChecked", | ||
value: function setChecked(checked, e) { | ||
var _this$props2 = this.props, | ||
disabled = _this$props2.disabled, | ||
onChange = _this$props2.onChange; | ||
if (disabled) { | ||
return; | ||
} | ||
if (!('checked' in this.props)) { | ||
@@ -102,9 +137,9 @@ this.setState({ | ||
} | ||
this.props.onChange(checked); | ||
if (onChange) { | ||
onChange(checked, e); | ||
} | ||
} | ||
// Handle auto focus when click switch in Chrome | ||
}, { | ||
key: 'focus', | ||
key: "focus", | ||
value: function focus() { | ||
@@ -114,3 +149,3 @@ this.node.focus(); | ||
}, { | ||
key: 'blur', | ||
key: "blur", | ||
value: function blur() { | ||
@@ -120,93 +155,63 @@ this.node.blur(); | ||
}, { | ||
key: 'render', | ||
key: "render", | ||
value: function render() { | ||
var _classNames; | ||
var _props2 = this.props, | ||
className = _props2.className, | ||
prefixCls = _props2.prefixCls, | ||
disabled = _props2.disabled, | ||
loadingIcon = _props2.loadingIcon, | ||
checkedChildren = _props2.checkedChildren, | ||
unCheckedChildren = _props2.unCheckedChildren, | ||
restProps = (0, _objectWithoutProperties3['default'])(_props2, ['className', 'prefixCls', 'disabled', 'loadingIcon', 'checkedChildren', 'unCheckedChildren']); | ||
var _this$props3 = this.props, | ||
className = _this$props3.className, | ||
prefixCls = _this$props3.prefixCls, | ||
disabled = _this$props3.disabled, | ||
loadingIcon = _this$props3.loadingIcon, | ||
checkedChildren = _this$props3.checkedChildren, | ||
unCheckedChildren = _this$props3.unCheckedChildren, | ||
restProps = _objectWithoutProperties(_this$props3, ["className", "prefixCls", "disabled", "loadingIcon", "checkedChildren", "unCheckedChildren"]); | ||
var checked = this.state.checked; | ||
var switchClassName = classNames((_classNames = {}, (0, _defineProperty3['default'])(_classNames, className, !!className), (0, _defineProperty3['default'])(_classNames, prefixCls, true), (0, _defineProperty3['default'])(_classNames, prefixCls + '-checked', checked), (0, _defineProperty3['default'])(_classNames, prefixCls + '-disabled', disabled), _classNames)); | ||
return _react2['default'].createElement( | ||
'button', | ||
(0, _extends3['default'])({}, restProps, { | ||
type: 'button', | ||
role: 'switch', | ||
'aria-checked': checked, | ||
disabled: disabled, | ||
className: switchClassName, | ||
ref: this.saveNode, | ||
onKeyDown: this.handleKeyDown, | ||
onClick: this.toggle, | ||
onMouseUp: this.handleMouseUp | ||
}), | ||
loadingIcon, | ||
_react2['default'].createElement( | ||
'span', | ||
{ className: prefixCls + '-inner' }, | ||
checked ? checkedChildren : unCheckedChildren | ||
) | ||
); | ||
var switchClassName = classNames((_classNames = {}, _defineProperty(_classNames, className, !!className), _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames)); | ||
return _react["default"].createElement("button", _extends({}, restProps, { | ||
type: "button", | ||
role: "switch", | ||
"aria-checked": checked, | ||
disabled: disabled, | ||
className: switchClassName, | ||
ref: this.saveNode, | ||
onKeyDown: this.handleKeyDown, | ||
onClick: this.handleClick, | ||
onMouseUp: this.handleMouseUp | ||
}), loadingIcon, _react["default"].createElement("span", { | ||
className: "".concat(prefixCls, "-inner") | ||
}, checked ? checkedChildren : unCheckedChildren)); | ||
} | ||
}]); | ||
return Switch; | ||
}(_react.Component); | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps) { | ||
var newState = {}; | ||
var checked = nextProps.checked; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
if ('checked' in nextProps) { | ||
newState.checked = !!checked; | ||
} | ||
this.toggle = function () { | ||
var onClick = _this2.props.onClick; | ||
var checked = !_this2.state.checked; | ||
_this2.setChecked(checked); | ||
onClick(checked); | ||
}; | ||
this.handleKeyDown = function (e) { | ||
if (e.keyCode === 37) { | ||
// Left | ||
_this2.setChecked(false); | ||
} else if (e.keyCode === 39) { | ||
// Right | ||
_this2.setChecked(true); | ||
return newState; | ||
} | ||
}; | ||
}]); | ||
this.handleMouseUp = function (e) { | ||
if (_this2.node) { | ||
_this2.node.blur(); | ||
} | ||
if (_this2.props.onMouseUp) { | ||
_this2.props.onMouseUp(e); | ||
} | ||
}; | ||
return Switch; | ||
}(_react.Component); | ||
this.saveNode = function (node) { | ||
_this2.node = node; | ||
}; | ||
}; | ||
Switch.propTypes = { | ||
className: _propTypes2['default'].string, | ||
prefixCls: _propTypes2['default'].string, | ||
disabled: _propTypes2['default'].bool, | ||
checkedChildren: _propTypes2['default'].any, | ||
unCheckedChildren: _propTypes2['default'].any, | ||
onChange: _propTypes2['default'].func, | ||
onMouseUp: _propTypes2['default'].func, | ||
onClick: _propTypes2['default'].func, | ||
tabIndex: _propTypes2['default'].number, | ||
checked: _propTypes2['default'].bool, | ||
defaultChecked: _propTypes2['default'].bool, | ||
autoFocus: _propTypes2['default'].bool, | ||
loadingIcon: _propTypes2['default'].node | ||
className: _propTypes["default"].string, | ||
prefixCls: _propTypes["default"].string, | ||
disabled: _propTypes["default"].bool, | ||
checkedChildren: _propTypes["default"].any, | ||
unCheckedChildren: _propTypes["default"].any, | ||
onChange: _propTypes["default"].func, | ||
onMouseUp: _propTypes["default"].func, | ||
onClick: _propTypes["default"].func, | ||
tabIndex: _propTypes["default"].number, | ||
checked: _propTypes["default"].bool, | ||
defaultChecked: _propTypes["default"].bool, | ||
autoFocus: _propTypes["default"].bool, | ||
loadingIcon: _propTypes["default"].node | ||
}; | ||
Switch.defaultProps = { | ||
@@ -217,8 +222,6 @@ prefixCls: 'rc-switch', | ||
className: '', | ||
defaultChecked: false, | ||
onChange: noop, | ||
onClick: noop | ||
defaultChecked: false | ||
}; | ||
exports['default'] = Switch; | ||
module.exports = exports['default']; | ||
(0, _reactLifecyclesCompat.polyfill)(Switch); | ||
var _default = Switch; | ||
exports["default"] = _default; |
{ | ||
"name": "rc-switch", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "switch ui component for react", | ||
@@ -37,18 +37,8 @@ "keywords": [ | ||
"lint": "rc-tools run lint", | ||
"test": "jest", | ||
"test": "rc-tools run test", | ||
"prepublish": "rc-tools run guard", | ||
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls" | ||
"coverage": "rc-tools run test --coverage", | ||
"pre-commit": "rc-tools run pre-commit", | ||
"lint-staged": "lint-staged" | ||
}, | ||
"jest": { | ||
"setupFiles": ["./tests/setup.js"], | ||
"collectCoverageFrom": [ | ||
"src/**/*" | ||
], | ||
"snapshotSerializers": [ | ||
"enzyme-to-json/serializer" | ||
], | ||
"transform": { | ||
"\\.jsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js" | ||
} | ||
}, | ||
"devDependencies": { | ||
@@ -59,5 +49,5 @@ "coveralls": "^2.11.15", | ||
"enzyme-to-json": "^3.0.0", | ||
"jest": "^19.0.2", | ||
"lint-staged": "^8.1.0", | ||
"pre-commit": "1.x", | ||
"rc-tools": "6.x", | ||
"rc-tools": "^9.3.4", | ||
"react": "^16.0.0", | ||
@@ -72,9 +62,15 @@ "react-dom": "^16.0.0", | ||
"pre-commit": [ | ||
"lint" | ||
"lint-staged" | ||
], | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx}": [ | ||
"npm run pre-commit", | ||
"git add" | ||
] | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.23.0", | ||
"classnames": "^2.2.1", | ||
"prop-types": "^15.5.6" | ||
"prop-types": "^15.5.6", | ||
"react-lifecycles-compat": "^3.0.4" | ||
} | ||
} |
@@ -82,3 +82,3 @@ # rc-switch | ||
<td>onChange</td> | ||
<td>Function</td> | ||
<td>Function(checked, event)</td> | ||
<td></td> | ||
@@ -95,3 +95,3 @@ <td>called when switch is checked or unchecked</td> | ||
<td>onClick</td> | ||
<td>Function(checked)</td> | ||
<td>Function(checked, event)</td> | ||
<td></td> | ||
@@ -98,0 +98,0 @@ <td>called when switch is clicked</td> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27007
497
+ Addedreact-lifecycles-compat@3.0.4(transitive)
- Removedbabel-runtime@^6.23.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)