yylib-quick-mobile
Version:
yylib-quick-mobile
126 lines (97 loc) • 6.17 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _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 YYTabs = function (_React$Component) {
_inherits(YYTabs, _React$Component);
function YYTabs() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, YYTabs);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYTabs.__proto__ || Object.getPrototypeOf(YYTabs)).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)) _this.props.onChange(tab, index);
}, _this.onTabClick = function (tab, index) {
if ((0, _FunctionUtil.isFunction)(_this.props.onTabClick)) _this.props.onTabClick(tab, index);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(YYTabs, [{
key: 'render',
value: function render() {
var _props = this.props,
type = _props.type,
tabs = _props.tabs,
tabBarPosition = _props.tabBarPosition,
initialPage = _props.initialPage,
page = _props.page,
swipeable = _props.swipeable,
tabDirection = _props.tabDirection,
tabBarInactiveTextColor = _props.tabBarInactiveTextColor,
tabBarActiveTextColor = _props.tabBarActiveTextColor,
tabBarUnderlineStyle = _props.tabBarUnderlineStyle,
children = _props.children,
className = _props.className,
restProps = _objectWithoutProperties(_props, ['type', 'tabs', 'tabBarPosition', 'initialPage', 'page', 'swipeable', 'tabDirection', 'tabBarInactiveTextColor', 'tabBarActiveTextColor', 'tabBarUnderlineStyle', 'children', 'className']);
var wrapClz = (0, _classnames2.default)('yy-tabs-' + (type === 'left' ? 'left' : 'default'), className);
return _react2.default.createElement(
'div',
{ className: wrapClz },
_react2.default.createElement(
_tabs2.default,
_extends({}, restProps, {
tabs: tabs,
tabBarPosition: tabBarPosition,
initialPage: initialPage,
page: page,
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 YYTabs;
}(_react2.default.Component);
;
YYTabs.defaultProps = {
type: 'default',
tabs: [],
tabBarPosition: 'top',
swipeable: true,
onChange: null,
onTabClick: null,
tabDirection: 'horizontal',
tabBarInactiveTextColor: '#414655',
tabBarActiveTextColor: '#0091FA',
tabBarUnderlineStyle: null
};
exports.default = YYTabs;
;