choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
109 lines (99 loc) • 3.53 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useCallback, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import noop from 'lodash/noop';
import { getConfig, getCustomizable } from '../configure';
import { TabsPosition, TabsType } from './enum';
import TabPane from './TabPane';
import TabGroup from './TabGroup';
import TabsWithContext from './TabsWithContext';
var Tabs = function Tabs(props) {
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 ? React.createElement(TabsWithContext, _extends({}, props, {
customized: customized,
setCustomized: setCustomized,
customizable: $customizable
})) : null;
};
Tabs.displayName = 'Tabs';
Tabs.propTypes = {
destroyInactiveTabPane: PropTypes.bool,
onChange: PropTypes.func,
children: PropTypes.any,
prefixCls: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
activeKey: PropTypes.string,
defaultActiveKey: PropTypes.string,
keyboard: PropTypes.bool,
hideAdd: PropTypes.bool,
tabPosition: PropTypes.oneOf([TabsPosition.top, TabsPosition.right, TabsPosition.bottom, TabsPosition.left]),
type: PropTypes.oneOf([TabsType.card, TabsType.line, TabsType['editable-card']])
};
Tabs.defaultProps = {
hideAdd: 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