ukelli-ui
Version:
[](https://travis-ci.org/ukelli/ukelli-ui) [](https://packagephobia.now.sh/result?p=ukelli-ui)
209 lines (177 loc) • 8.86 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); }
// import RandomDisplayNember from './random.ball';
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 _props$openCode = props.openCode,
openCode = _props$openCode === void 0 ? '?????' : _props$openCode;
var openArr = _this.getOpenCodeArr(openCode);
_this.state = {
openCodeLen: openArr.length,
openedInfo: {}
};
_this.animateBallRefs = {};
return _this;
}
_createClass(Ball, [{
key: "getOpenCodeArr",
value: function getOpenCodeArr(openCode) {
return /\,/.test(openCode) ? openCode.split(',') : openCode.split('');
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
if (this.props.isOpening != nextProps.isOpening || !/\?+/.test(nextProps.openCode) && nextProps.openCode !== this.props.openCode) {
this.openCodeAnimate(!nextProps.isOpening, nextProps);
}
}
}, {
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 _ref = props || this.props,
openCode = _ref.openCode,
_ref$animateTimer = _ref.animateTimer,
animateTimer = _ref$animateTimer === void 0 ? 300 : _ref$animateTimer;
var openedInfo = this.state.openedInfo;
var self = this;
var openCodeArr = this.getOpenCodeArr(openCode);
var openIdx = 0;
function setOpenCodeIdx(idx) {
openedInfo[idx] = isOpened;
self.setState({
openedInfo: openedInfo
});
self.clearTimeout();
self.timer = setTimeout(function () {
if (openIdx >= openCodeArr.length) return;
setOpenCodeIdx(openIdx);
}, animateTimer);
openIdx++;
}
setOpenCodeIdx(openIdx);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
_this$props$openCode = _this$props.openCode,
openCode = _this$props$openCode === void 0 ? '?????' : _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,
_this$props$numberRan = _this$props.numberRange,
numberRange = _this$props$numberRan === void 0 ? [0, 9] : _this$props$numberRan;
var extendTxtArr = /\,/.test(extendTxt) ? extendTxt.split(',') : 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]);
{
/* <div className={ballClass + ' flip-container' + (isOpening ? '' : ' flipper active') + (isActive ? ' s' : '')} key={_idx}>
<div className="front">
<RandomDisplayNember
ref={animateBall => {
if(!!animateBall && !this.animateBallRefs[_idx]) this.animateBallRefs[_idx] = animateBall;
}}
index={_idx}
numberRange={numberRange}
isStart={isOpening}/>
</div>
<div className="back">{_ball}</div>
{extendTxtDOM}
</div> */
}
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;
Ball.propTypes = {
openCode: _propTypes.default.string.isRequired,
animate: _propTypes.default.bool,
numberRange: _propTypes.default.array,
animateTimer: _propTypes.default.number,
activeFilter: _propTypes.default.string,
extendTxt: _propTypes.default.string,
isOpening: _propTypes.default.bool,
size: _propTypes.default.string
};