lm-password-box
Version:
* 作者:zhaojianling * 邮箱:"zjling1128@gmail.com" * 版本:**`0.2.6`**
280 lines (232 loc) • 10.3 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _jsxFileName = 'src/PasswordBoxItem.js';
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var PasswordBoxItem = function (_React$PureComponent) {
_inherits(PasswordBoxItem, _React$PureComponent);
function PasswordBoxItem() {
_classCallCheck(this, PasswordBoxItem);
return _possibleConstructorReturn(this, (PasswordBoxItem.__proto__ || Object.getPrototypeOf(PasswordBoxItem)).apply(this, arguments));
}
_createClass(PasswordBoxItem, [{
key: 'render',
value: function render() {
var _props = this.props,
isEncrypt = _props.isEncrypt,
itemVal = _props.itemVal,
hasError = _props.hasError,
classConfig = _props.classConfig,
contentType = _props.contentType,
animationDuration = _props.animationDuration;
var _classConfig$usualCla = classConfig.usualClass,
usualClass = _classConfig$usualCla === undefined ? '' : _classConfig$usualCla,
_classConfig$errorCla = classConfig.errorClass,
errorClass = _classConfig$errorCla === undefined ? '' : _classConfig$errorCla;
var pwdItemContClassName = !hasError ? (0, _classnames2.default)('lm-pwd-item', '' + usualClass) : (0, _classnames2.default)('lm-pwd-item', '' + usualClass, '' + errorClass);
var compParams = {
itemVal: itemVal,
contentType: contentType,
className: pwdItemContClassName,
isEncrypt: isEncrypt,
animationDuration: animationDuration
};
return this.props.hasAnimation ? _react2.default.createElement(HasAnimation, Object.assign({}, compParams, _defineProperty({
__source: {
fileName: _jsxFileName,
lineNumber: 31
},
__self: this
}, '__self', this))) : _react2.default.createElement(NoAnimation, Object.assign({}, compParams, _defineProperty({
__source: {
fileName: _jsxFileName,
lineNumber: 33
},
__self: this
}, '__self', this)));
}
}]);
return PasswordBoxItem;
}(_react2.default.PureComponent);
// 无动画
function NoAnimation(props) {
if (props.isEncrypt && props.itemVal.length) {
return _react2.default.createElement(EncrypteIcon, _defineProperty({
encrypteType: props.contentType,
className: props.className,
__source: {
fileName: _jsxFileName,
lineNumber: 48
},
__self: this
}, '__self', this));
} else {
return _react2.default.createElement(Unencrypted, _defineProperty({
encrypteType: props.contentType,
className: props.className,
itemVal: props.itemVal,
__source: {
fileName: _jsxFileName,
lineNumber: 56
},
__self: this
}, '__self', this));
}
}
// 有动画
var HasAnimation = function (_React$PureComponent2) {
_inherits(HasAnimation, _React$PureComponent2);
// 定时器标识
function HasAnimation(props) {
_classCallCheck(this, HasAnimation);
var _this2 = _possibleConstructorReturn(this, (HasAnimation.__proto__ || Object.getPrototypeOf(HasAnimation)).call(this, props));
_this2.stTimer = null;
_this2.getPwdItemVal = function () {
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
_this2.setState({
itemVal: val
}, function () {
cb();
});
};
_this2.state = {
itemVal: ''
};
return _this2;
}
_createClass(HasAnimation, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _props$itemVal = this.props.itemVal,
itemVal = _props$itemVal === undefined ? '' : _props$itemVal;
this.setState({
itemVal: itemVal
});
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var _this3 = this;
var curVal = nextProps.itemVal;
var animationDuration = nextProps.animationDuration;
if (!nextProps.isEncrypt) {
this.getPwdItemVal(curVal);
} else if (this.props.itemVal !== nextProps.itemVal) {
var _curVal = nextProps.itemVal;
clearTimeout(this.stTimer);
this.getPwdItemVal(_curVal, function () {
if (_curVal.length > 0) {
_this3.stTimer = setTimeout(function () {
_this3.getPwdItemVal('.');
}, animationDuration);
}
});
} else {
if (curVal.length > 0) {
this.getPwdItemVal('.');
}
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
clearTimeout(this.stTimer);
}
}, {
key: 'render',
value: function render() {
var itemVal = this.state.itemVal;
if (itemVal === '.') {
return _react2.default.createElement(EncrypteIcon, _defineProperty({
encrypteType: this.props.contentType,
className: this.props.className,
__source: {
fileName: _jsxFileName,
lineNumber: 128
},
__self: this
}, '__self', this));
} else {
return _react2.default.createElement(Unencrypted, _defineProperty({
encrypteType: this.props.contentType,
className: this.props.className,
itemVal: itemVal,
__source: {
fileName: _jsxFileName,
lineNumber: 136
},
__self: this
}, '__self', this));
}
}
}]);
return HasAnimation;
}(_react2.default.PureComponent);
function Unencrypted(props) {
var itemVal = props.itemVal;
return _react2.default.createElement(
'span',
_defineProperty({ className: 'lm-pwd-item', __source: {
fileName: _jsxFileName,
lineNumber: 152
},
__self: this
}, '__self', this),
_react2.default.createElement(
'span',
_defineProperty({
className: "lm-pwd-item-num",
__source: {
fileName: _jsxFileName,
lineNumber: 153
},
__self: this
}, '__self', this),
itemVal === '' ? '' : itemVal
)
);
}
function EncrypteIcon(props) {
var encrypteType = props.encrypteType;
return _react2.default.createElement(
'span',
_defineProperty({ className: props.className, __source: {
fileName: _jsxFileName,
lineNumber: 165
},
__self: this
}, '__self', this),
encrypteType === 'star' ? _react2.default.createElement(
'span',
_defineProperty({ className: "lm-pwd-item-num", __source: {
fileName: _jsxFileName,
lineNumber: 168
},
__self: this
}, '__self', this),
'*'
) : _react2.default.createElement(
'span',
_defineProperty({ className: "lm-pwd-item-icon", __source: {
fileName: _jsxFileName,
lineNumber: 170
},
__self: this
}, '__self', this),
' '
)
);
}
exports.default = PasswordBoxItem;
module.exports = exports['default'];