wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
22 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var Tabs_1 = tslib_1.__importDefault(require("../ui/Tabs"));
var TabbedView = function (props) {
var _a = react_1.default.useState(props.activeTabId || props.tabs[0]), activeTabId = _a[0], setActiveTabId = _a[1];
var handleTabClick = function (tab) {
setActiveTabId(tab.id);
};
var activeIndex = props.tabs.findIndex(function (tab) { return tab.toLowerCase() === activeTabId.toLowerCase(); });
return (react_1.default.createElement(react_1.default.Fragment, null,
props.showTabs && (react_1.default.createElement(Tabs_1.default, { activeId: activeTabId, onClick: handleTabClick, items: props.tabs.map(function (id) { return ({ title: id, id: id, dataHook: id }); }), className: props.className })),
react_1.default.Children.map(props.children, function (child, index) {
if (index === activeIndex) {
return child;
}
return null;
})));
};
exports.default = TabbedView;
//# sourceMappingURL=index.js.map