zent
Version:
一套前端设计语言和基于React的实现
72 lines (71 loc) • 3.01 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { isElement } from 'react-is';
import cn from 'classnames';
import { Children } from 'react';
import isNil from '../utils/isNil';
import noop from '../utils/noop';
import LazyMount from '../utils/component/LazyMount';
import VerticalTabsNav from './components/tabs-nav/VerticalTabsNav';
import BaseTabs from './components/base/BaseTabs';
import { getTabDataFromChild } from './utils';
import TabDivide from './components/TabDivide';
import TabPanel from './components/TabPanel';
var VerticalTabs = (function (_super) {
__extends(VerticalTabs, _super);
function VerticalTabs() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(VerticalTabs.prototype, "tabsCls", {
get: function () {
var className = this.props.className;
return cn('zent-tabs', "zent-tabs-type__vertical", className);
},
enumerable: false,
configurable: true
});
VerticalTabs.prototype.getTabDataListFromTabs = function (tabs) {
var activeId = this.props.activeId;
return tabs.map(function (tab) {
if ('divide' in tab) {
return tab;
}
else {
return __assign(__assign({}, tab), { actived: tab.key === activeId });
}
});
};
VerticalTabs.prototype.getTabDataListFromChildren = function (children) {
var activeId = this.props.activeId;
return Children.map(children, function (child) {
if (!isElement(child)) {
return null;
}
if ('divide' in child.props) {
return { divide: true };
}
return getTabDataFromChild(child, activeId);
}).filter(function (v) { return !isNil(v); });
};
VerticalTabs.prototype.renderNav = function (tabDataList) {
var _a = this.props, onChange = _a.onChange, scrollHeight = _a.scrollHeight;
return (_jsx(VerticalTabsNav, { scrollHeight: scrollHeight, onChange: onChange, tabDataList: tabDataList }, void 0));
};
VerticalTabs.prototype.renderTabPanel = function (tabItem) {
if ('divide' in tabItem) {
return null;
}
var unmountPanelOnHide = this.props.unmountPanelOnHide;
return (_jsx(LazyMount, __assign({ mount: tabItem.actived }, { children: _jsx(TabPanel, __assign({ tab: tabItem.title, actived: tabItem.actived, unmountOnHide: tabItem.unmountOnHide || unmountPanelOnHide, className: tabItem.className, id: tabItem.key }, { children: tabItem.panelChildren }), void 0) }), tabItem.key));
};
VerticalTabs.TabPanel = TabPanel;
VerticalTabs.Divide = TabDivide;
VerticalTabs.defaultProps = {
activeId: '',
onChange: noop,
unmountPanelOnHide: false,
};
return VerticalTabs;
}(BaseTabs));
export { VerticalTabs };
export default VerticalTabs;