UNPKG

antd

Version:

An enterprise-class UI design language and React-based implementation

73 lines (63 loc) 2.51 kB
import _extends from 'babel-runtime/helpers/extends'; import _defineProperty from 'babel-runtime/helpers/defineProperty'; 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'; import * as React from 'react'; import * as PropTypes from 'prop-types'; import RcSwitch from 'rc-switch'; import classNames from 'classnames'; import omit from 'omit.js'; import Wave from '../_util/wave'; var Switch = function (_React$Component) { _inherits(Switch, _React$Component); function Switch() { _classCallCheck(this, Switch); var _this = _possibleConstructorReturn(this, (Switch.__proto__ || Object.getPrototypeOf(Switch)).apply(this, arguments)); _this.saveSwitch = function (node) { _this.rcSwitch = node; }; return _this; } _createClass(Switch, [{ key: 'focus', value: function focus() { this.rcSwitch.focus(); } }, { key: 'blur', value: function blur() { this.rcSwitch.blur(); } }, { key: 'render', value: function render() { var _classNames; var _props = this.props, prefixCls = _props.prefixCls, size = _props.size, loading = _props.loading, _props$className = _props.className, className = _props$className === undefined ? '' : _props$className; var classes = classNames(className, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-small', size === 'small'), _defineProperty(_classNames, prefixCls + '-loading', loading), _classNames)); return React.createElement( Wave, { insertExtraNode: true }, React.createElement(RcSwitch, _extends({}, omit(this.props, ['loading']), { className: classes, ref: this.saveSwitch })) ); } }]); return Switch; }(React.Component); export default Switch; Switch.defaultProps = { prefixCls: 'ant-switch' }; Switch.propTypes = { prefixCls: PropTypes.string, // HACK: https://github.com/ant-design/ant-design/issues/5368 // size=default and size=large are the same size: PropTypes.oneOf(['small', 'default', 'large']), className: PropTypes.string };