ukelli-ui
Version:
ukelli-ui 是基于 React 的 UI 库,提供简约和功能齐全的组件,可高度定制的组件接口,灵活的配置,提供给开发者另一种开发思路,也致力于尝试不同的组件使用和开发方向。
216 lines (175 loc) • 8.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Ball = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _animateBall = _interopRequireDefault(require("./animate-ball"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return 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 _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 splitStr = ',';
var Ball =
/*#__PURE__*/
function (_Component) {
_inherits(Ball, _Component);
function Ball(props) {
var _this;
_classCallCheck(this, Ball);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Ball).call(this, props));
var openCode = props.openCode;
var openArr = _this.getOpenCodeArr(openCode);
_this.state = {
openCodeLen: openArr.length,
openedInfo: {}
};
_this.animateBallRefs = {};
return _this;
}
_createClass(Ball, [{
key: "hasSplit",
value: function hasSplit(str) {
return str.indexOf(splitStr) !== -1;
}
}, {
key: "getOpenCodeArr",
value: function getOpenCodeArr(openCode) {
return this.hasSplit(openCode) ? openCode.split(splitStr) : openCode.split('');
} // TODO:
// componentWillReceiveProps(nextProps) {
// if(this.props.isOpening != nextProps.isOpening || (!/\?+/.test(nextProps.openCode) && nextProps.openCode !== this.props.openCode)) {
// this.openCodeAnimate(!nextProps.isOpening, nextProps);
// }
// }
}, {
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
if (this.props.isOpening != nextProps.isOpening || !/\?+/.test(nextProps.openCode) && nextProps.openCode !== this.props.openCode) {
this.openCodeAnimate(!nextProps.isOpening, nextProps);
}
return true;
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearTimeout();
}
}, {
key: "clearTimeout",
value: function (_clearTimeout) {
function clearTimeout() {
return _clearTimeout.apply(this, arguments);
}
clearTimeout.toString = function () {
return _clearTimeout.toString();
};
return clearTimeout;
}(function () {
this.timer && clearTimeout(this.timer);
this.timer = null;
})
}, {
key: "openCodeAnimate",
value: function openCodeAnimate(isOpened, props) {
var _this2 = this;
var _ref = props || this.props,
openCode = _ref.openCode,
animateTimer = _ref.animateTimer;
var openedInfo = this.state.openedInfo;
var openCodeArr = this.getOpenCodeArr(openCode);
var openIdx = 0;
var setOpenCodeIdx = function setOpenCodeIdx(idx) {
openedInfo[idx] = isOpened;
_this2.setState({
openedInfo: openedInfo
});
_this2.clearTimeout();
_this2.timer = setTimeout(function () {
if (openIdx >= openCodeArr.length) return;
setOpenCodeIdx(openIdx);
}, animateTimer);
openIdx++;
};
setOpenCodeIdx(openIdx);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
openCode = _this$props.openCode,
size = _this$props.size,
_this$props$animate = _this$props.animate,
animate = _this$props$animate === void 0 ? false : _this$props$animate,
_this$props$activeFil = _this$props.activeFilter,
activeFilter = _this$props$activeFil === void 0 ? '' : _this$props$activeFil,
_this$props$extendTxt = _this$props.extendTxt,
extendTxt = _this$props$extendTxt === void 0 ? '' : _this$props$extendTxt,
numberRange = _this$props.numberRange;
var extendTxtArr = this.hasSplit(extendTxt) ? extendTxt.split(splitStr) : extendTxt;
var _this$state = this.state,
openCodeLen = _this$state.openCodeLen,
openedInfo = _this$state.openedInfo;
var openCodeArr = this.getOpenCodeArr(openCode);
var ballClass = size ? size + ' ball' : 'ball';
var activeFilterArr = activeFilter.split('');
var ballGroup = openCodeArr.map(function (_ball, _idx) {
var isOpening = !openedInfo[_idx];
var currFilter = activeFilterArr[_idx] || '';
var isActive = currFilter == 'o';
var ballID = "ball-".concat(_ball);
var extendTxtDOM = _react["default"].createElement("div", {
key: _idx,
className: "extend-txt"
}, extendTxtArr[_idx]);
if (animate) {
return _react["default"].createElement("div", {
id: ballID,
key: _idx,
className: ballClass + '' + (isActive ? ' s' : '')
}, _react["default"].createElement(_animateBall["default"], {
activeNumb: openCodeArr[_idx],
index: _idx,
numberRange: numberRange,
animating: isOpening
}), extendTxtDOM);
} else {
return _react["default"].createElement("div", {
id: ballID,
className: ballClass + ' b' + (isActive ? ' s' : ''),
key: _idx
}, _ball);
}
});
return _react["default"].createElement("div", {
className: "ball-group"
}, ballGroup);
}
}]);
return Ball;
}(_react.Component);
exports.Ball = Ball;
_defineProperty(Ball, "propTypes", {
openCode: _propTypes["default"].string,
animate: _propTypes["default"].bool,
numberRange: _propTypes["default"].arrayOf(_propTypes["default"].number),
animateTimer: _propTypes["default"].number,
activeFilter: _propTypes["default"].string,
extendTxt: _propTypes["default"].string,
isOpening: _propTypes["default"].bool,
size: _propTypes["default"].string
});
_defineProperty(Ball, "defaultProps", {
openCode: '?????',
animateTimer: 300,
numberRange: [0, 9]
});