yylib-quick-mobile
Version:
yylib-quick-mobile
150 lines (119 loc) • 7.22 kB
JavaScript
var _tabs = require('antd-mobile/lib/tabs');
var _tabs2 = _interopRequireDefault(_tabs);
var _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; };
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; }; }();
require('antd-mobile/lib/tabs/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
require('./YYTabs.less');
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _FunctionUtil = require('../../utils/FunctionUtil');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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 YYTabsDev = function (_React$Component) {
_inherits(YYTabsDev, _React$Component);
function YYTabsDev() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, YYTabsDev);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYTabsDev.__proto__ || Object.getPrototypeOf(YYTabsDev)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
tabBarUnderlineLeft: (_this.props.initialPage ? 5 + _this.props.initialPage * 20 : 5) + '%'
}, _this.onChange = function (tab, index) {
_this.setState({
tabBarUnderlineLeft: 5 + index * 20 + "%"
});
if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) {
setTimeout(function () {
_this.props.onChange(tab, index);
}, 300);
}
}, _this.onTabClick = function (tab, index) {
if ((0, _FunctionUtil.isFunction)(_this.props.onTabClick)) _this.props.onTabClick(tab, index);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(YYTabsDev, [{
key: 'getTabs',
value: function getTabs() {
var children = this.props.children;
if (children) {
Array.prototype.slice.call(children);
children = children && children.constructor == Array ? children : [children];
return children.map(function (item, index) {
return { title: item.props.uititle };
});
}
return [];
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
pageSize = _props.pageSize,
usePaged = _props.usePaged,
height = _props.height,
type = _props.type,
tabBarPosition = _props.tabBarPosition,
swipeable = _props.swipeable,
tabDirection = _props.tabDirection,
tabBarInactiveTextColor = _props.tabBarInactiveTextColor,
tabBarActiveTextColor = _props.tabBarActiveTextColor,
tabBarUnderlineStyle = _props.tabBarUnderlineStyle,
children = _props.children,
className = _props.className,
visible = _props.visible,
restProps = _objectWithoutProperties(_props, ['pageSize', 'usePaged', 'height', 'type', 'tabBarPosition', 'swipeable', 'tabDirection', 'tabBarInactiveTextColor', 'tabBarActiveTextColor', 'tabBarUnderlineStyle', 'children', 'className', 'visible']);
var wrapClz = (0, _classnames2.default)('yy-tabs-' + (type === 'left' ? 'left' : 'default'), !visible && 'hidden', className);
var tabs = this.getTabs();
var defaultStyle = { height: height };
return _react2.default.createElement(
'div',
{ className: wrapClz, style: defaultStyle },
_react2.default.createElement(
_tabs2.default,
_extends({}, restProps, {
usePaged: usePaged,
tabs: tabs,
tabBarPosition: tabBarPosition,
renderTabBar: function renderTabBar(props) {
return _react2.default.createElement(_tabs2.default.DefaultTabBar, _extends({}, props, { page: pageSize }));
},
swipeable: swipeable,
onChange: this.onChange,
onTabClick: this.onTabClick,
tabDirection: tabDirection,
tabBarInactiveTextColor: tabBarInactiveTextColor,
tabBarActiveTextColor: tabBarActiveTextColor,
tabBarUnderlineStyle: !tabBarUnderlineStyle && type === 'left' ? { "width": "10%", "left": this.state.tabBarUnderlineLeft } : tabBarUnderlineStyle
}),
children
)
);
}
}]);
return YYTabsDev;
}(_react2.default.Component);
;
YYTabsDev.defaultProps = {
type: 'default',
tabs: [],
tabBarPosition: 'top',
swipeable: true,
onChange: null,
onTabClick: null,
tabDirection: 'horizontal',
tabBarInactiveTextColor: '#414655',
tabBarActiveTextColor: '#0091FA',
tabBarUnderlineStyle: null,
visible: true
};
module.exports = YYTabsDev;
;