UNPKG

wix-storybook-utils

Version:

Utilities for automated component documentation within Storybook

19 lines 938 B
import React from 'react'; import Tabs from '../ui/Tabs'; var TabbedView = function (props) { var _a = React.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.createElement(React.Fragment, null, props.showTabs && (React.createElement(Tabs, { activeId: activeTabId, onClick: handleTabClick, items: props.tabs.map(function (id) { return ({ title: id, id: id, dataHook: id }); }), className: props.className })), React.Children.map(props.children, function (child, index) { if (index === activeIndex) { return child; } return null; }))); }; export default TabbedView; //# sourceMappingURL=index.js.map