choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
133 lines (109 loc) • 4.46 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _utils = require("./utils");
var _warning = _interopRequireDefault(require("../../_util/warning"));
var _ripple = _interopRequireDefault(require("../../ripple"));
var _default = {
getDefaultProps: function getDefaultProps() {
return {
styles: {}
};
},
onTabClick: function onTabClick(key) {
this.props.onTabClick(key);
},
getTabs: function getTabs() {
var _this = this;
var _this$props = this.props,
children = _this$props.panels,
activeKey = _this$props.activeKey,
prefixCls = _this$props.prefixCls,
tabBarGutter = _this$props.tabBarGutter;
var rst = [];
_react.Children.forEach(children, function (child, index) {
if (!child) {
return;
}
var key = (0, _utils.generateKey)(child.key, index);
var _child$props = child.props,
disabled = _child$props.disabled,
tab = _child$props.tab;
var cls = activeKey === key ? "".concat(prefixCls, "-tab-active") : '';
cls += " ".concat(prefixCls, "-tab");
var events = {};
if (disabled) {
cls += " ".concat(prefixCls, "-tab-disabled");
} else {
events = {
onClick: _this.onTabClick.bind(_this, key)
};
}
var ref = {};
if (activeKey === key) {
ref.ref = _this.saveRef('activeTab');
}
(0, _warning["default"])('tab' in child.props, 'There must be `tab` property on children of Tabs.');
rst.push(_react["default"].createElement(_ripple["default"], {
disabled: disabled,
key: key
}, _react["default"].createElement("div", (0, _extends2["default"])({
role: "tab",
"aria-disabled": disabled ? 'true' : 'false',
"aria-selected": activeKey === key ? 'true' : 'false'
}, events, {
className: cls,
style: {
marginRight: tabBarGutter && index === children.length - 1 ? 0 : tabBarGutter
}
}, ref), tab)));
});
return rst;
},
getRootNode: function getRootNode(contents) {
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
onKeyDown = _this$props2.onKeyDown,
className = _this$props2.className,
extraContent = _this$props2.extraContent,
style = _this$props2.style,
tabBarPosition = _this$props2.tabBarPosition,
restProps = (0, _objectWithoutProperties2["default"])(_this$props2, ["prefixCls", "onKeyDown", "className", "extraContent", "style", "tabBarPosition"]);
var cls = (0, _classnames2["default"])("".concat(prefixCls, "-bar"), (0, _defineProperty2["default"])({}, className, !!className));
var topOrBottom = tabBarPosition === 'top' || tabBarPosition === 'bottom';
var tabBarExtraContentStyle = topOrBottom ? {
"float": 'right'
} : {};
var extraContentStyle = extraContent && extraContent.props ? extraContent.props.style : {};
var children = contents;
if (extraContent) {
children = [(0, _react.cloneElement)(extraContent, {
key: 'extra',
style: (0, _objectSpread2["default"])({}, tabBarExtraContentStyle, {}, extraContentStyle)
}), (0, _react.cloneElement)(contents, {
key: 'content'
})];
children = topOrBottom ? children : children.reverse();
}
return _react["default"].createElement("div", (0, _extends2["default"])({
role: "tablist",
className: cls,
tabIndex: "0",
ref: this.saveRef('root'),
onKeyDown: onKeyDown,
style: style
}, (0, _utils.getDataAttr)(restProps)), children);
}
};
exports["default"] = _default;
//# sourceMappingURL=TabBarMixin.js.map