@up-group-ui/react-controls
Version:
Up shared react controls
28 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var UpNavTabHead_1 = require("./UpNavTabHead");
var UpNavTabContent_1 = require("./UpNavTabContent");
var UpNavTab = function (_a) {
var _b = _a.loadType, loadType = _b === void 0 ? 'onLoad' : _b, _c = _a.tabs, tabs = _c === void 0 ? [] : _c, onSelectedTabChanged = _a.onSelectedTabChanged, _d = _a.selectedTabOnLoad, selectedTabOnLoad = _d === void 0 ? null : _d;
var _e = react_1.default.useState(tabs.length !== 0 ? selectedTabOnLoad || 0 : -1), selectedTabKey = _e[0], selectTabKey = _e[1];
react_1.default.useEffect(function () {
if (onSelectedTabChanged) {
var tab = tabs.find(function (v, i) { return i === selectedTabKey; });
onSelectedTabChanged(selectedTabKey, tab);
}
}, [selectedTabKey]);
var tabsToDisplay = tabs;
var tabKeyToDisplay = selectedTabKey;
if (loadType === 'onShow') {
tabsToDisplay = tabs.filter(function (v, i) {
return i === selectedTabKey;
});
tabKeyToDisplay = 0;
}
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(UpNavTabHead_1.TabHeads, { selectTabKey: selectTabKey, heads: tabs, selectedTabKey: selectedTabKey }, void 0), (0, jsx_runtime_1.jsx)(UpNavTabContent_1.TabContentWrapper, { loadType: loadType, selectedTabKey: tabKeyToDisplay, contents: tabsToDisplay }, void 0)] }, void 0));
};
exports.default = UpNavTab;
//# sourceMappingURL=UpNavTab.js.map