@jdcfe/yep-react
Version:
一套移动端的React组件库
106 lines (88 loc) • 4.19 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
import classNames from 'classnames';
import noop from '../_utils/noop';
var TabBar = /*#__PURE__*/function (_React$PureComponent) {
_inherits(TabBar, _React$PureComponent);
var _super = _createSuper(TabBar);
function TabBar(props) {
var _this;
_classCallCheck(this, TabBar);
_this = _super.call(this, props);
_this.onClick = function (index) {
var _this$props = _this.props,
goToTab = _this$props.goToTab,
onTabClick = _this$props.onTabClick,
tabs = _this$props.tabs;
onTabClick && onTabClick(tabs[index], index);
goToTab && goToTab(index);
};
_this.renderTab = function (t, i) {
var _this$props2 = _this.props,
prefixCls = _this$props2.prefixCls,
renderTab = _this$props2.renderTab,
activeTab = _this$props2.activeTab,
tabBarTextStyle = _this$props2.tabBarTextStyle,
tabBarActiveTextColor = _this$props2.tabBarActiveTextColor,
tabBarInactiveTextColor = _this$props2.tabBarInactiveTextColor;
var textStyle = Object.assign({}, tabBarTextStyle);
var cls = "".concat(prefixCls, "-tab");
if (activeTab === i) {
cls += " ".concat(cls, "-active");
if (tabBarActiveTextColor) {
textStyle.color = tabBarActiveTextColor;
}
} else if (tabBarInactiveTextColor) {
textStyle.color = tabBarInactiveTextColor;
}
return /*#__PURE__*/React.createElement("div", {
key: "t_".concat(i),
style: Object.assign({}, textStyle),
className: cls,
onClick: function onClick() {
return _this.onClick(i);
}
}, renderTab ? renderTab(t) : t.title, activeTab === i && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-underline")
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-underline-bar")
})));
};
_this.renderTab = _this.renderTab.bind(_assertThisInitialized(_this));
_this.onClick = _this.onClick.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(TabBar, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props3 = this.props,
prefixCls = _this$props3.prefixCls,
_this$props3$tabs = _this$props3.tabs,
tabs = _this$props3$tabs === void 0 ? [] : _this$props3$tabs;
var cls = classNames(prefixCls, "".concat(prefixCls, "-top"));
var Tabs = tabs.map(function (t, i) {
return _this2.renderTab(t, i);
});
return /*#__PURE__*/React.createElement("div", {
className: cls
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-content")
}, Tabs));
}
}]);
return TabBar;
}(React.PureComponent);
export { TabBar as default };
TabBar.defaultProps = {
prefixCls: 'Yep-area-picker-tabs-bar',
onTabClick: noop,
activeTab: 0
};