choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
99 lines (88 loc) • 3.25 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React, { useCallback, useContext, useEffect, useState } from 'react';
import noop from 'lodash/noop';
import { TabsPosition, TabsType } from './enum';
import TabPane from './TabPane';
import TabGroup from './TabGroup';
import TabsWithContext from './TabsWithContext';
import ConfigContext from '../config-provider/ConfigContext';
var Tabs = function Tabs(props) {
var _useContext = useContext(ConfigContext),
getConfig = _useContext.getConfig,
getCustomizable = _useContext.getCustomizable;
var customizedCode = props.customizedCode,
_props$customizable = props.customizable,
customizable = _props$customizable === void 0 ? customizedCode ? getCustomizable('Tabs') : undefined : _props$customizable;
var $customizable = customizedCode ? customizable : false;
var _useState = useState(!$customizable),
_useState2 = _slicedToArray(_useState, 2),
loaded = _useState2[0],
setLoaded = _useState2[1];
var _useState3 = useState(),
_useState4 = _slicedToArray(_useState3, 2),
customized = _useState4[0],
setCustomized = _useState4[1];
var loadCustomized = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var customizedLoad, remoteCustomized;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!customizedCode) {
_context.next = 11;
break;
}
setLoaded(false);
customizedLoad = getConfig('customizedLoad');
_context.prev = 3;
_context.next = 6;
return customizedLoad(customizedCode, 'Tabs');
case 6:
remoteCustomized = _context.sent;
setCustomized(_objectSpread({
panes: {}
}, remoteCustomized));
case 8:
_context.prev = 8;
setLoaded(true);
return _context.finish(8);
case 11:
case "end":
return _context.stop();
}
}
}, _callee, null, [[3,, 8, 11]]);
})), [customizedCode]);
useEffect(function () {
if ($customizable) {
loadCustomized();
}
}, [$customizable, loadCustomized]);
return loaded ? /*#__PURE__*/React.createElement(TabsWithContext, _extends({}, props, {
customized: customized,
setCustomized: setCustomized,
customizable: $customizable
})) : null;
};
Tabs.displayName = 'Tabs';
Tabs.defaultProps = {
restoreDefault: true,
tabCountHideable: true,
tabTitleEditable: true,
tabDraggable: true,
hideAdd: false,
showMore: false,
destroyInactiveTabPane: false,
onChange: noop,
keyboard: true,
tabPosition: TabsPosition.top,
type: TabsType.line
};
Tabs.TabPane = TabPane;
Tabs.TabGroup = TabGroup;
export default Tabs;
//# sourceMappingURL=Tabs.js.map