@jdcfe/yep-react
Version:
一套移动端的React组件库
117 lines (102 loc) • 4.25 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 Badge from '../badge';
import noop from '../_utils/noop';
var Tab = /*#__PURE__*/function (_React$PureComponent) {
_inherits(Tab, _React$PureComponent);
var _super = _createSuper(Tab);
function Tab(props) {
var _this;
_classCallCheck(this, Tab);
_this = _super.call(this, props);
_this.onClick = _this.onClick.bind(_assertThisInitialized(_this));
_this.renderIcon = _this.renderIcon.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(Tab, [{
key: "onClick",
value: function onClick() {
var onClick = this.props.onClick;
if (onClick) {
onClick();
}
}
}, {
key: "renderIcon",
value: function renderIcon() {
var _this$props = this.props,
selected = _this$props.selected,
selectedIcon = _this$props.selectedIcon,
icon = _this$props.icon,
title = _this$props.title,
prefixCls = _this$props.prefixCls,
badge = _this$props.badge,
dot = _this$props.dot;
var iconVal = selected ? selectedIcon : icon;
var iconDom = /*#__PURE__*/React.isValidElement(iconVal) ? iconVal : /*#__PURE__*/React.createElement("img", {
className: "".concat(prefixCls, "-image"),
src: iconVal,
alt: title
});
if (badge) {
return /*#__PURE__*/React.createElement(Badge, {
text: badge,
className: "".concat(prefixCls, "-badge tab-badge")
}, ' ', iconDom, ' ');
}
if (dot) {
return /*#__PURE__*/React.createElement(Badge, {
dot: true,
className: "".concat(prefixCls, "-badge tab-dot")
}, iconDom);
}
return iconDom;
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
title = _this$props2.title,
prefixCls = _this$props2.prefixCls,
selected = _this$props2.selected,
unselectedTintColor = _this$props2.unselectedTintColor,
tintColor = _this$props2.tintColor,
style = _this$props2.style,
className = _this$props2.className;
var iconColor = selected ? tintColor : unselectedTintColor;
return /*#__PURE__*/React.createElement("div", {
className: classNames(prefixCls, className),
style: style,
onClick: this.onClick
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-icon"),
style: {
color: iconColor
}
}, this.renderIcon()), /*#__PURE__*/React.createElement("p", {
className: "".concat(prefixCls, "-title"),
style: {
color: selected ? tintColor : unselectedTintColor
}
}, title));
}
}]);
return Tab;
}(React.PureComponent);
export { Tab as default };
Tab.defaultProps = {
prefixCls: 'Yep-tab-bar-tab',
tintColor: '#ec3838',
unselectedTintColor: '#6C707D',
selected: false,
dot: false,
onClick: noop
};