import { TabPanel } from '@wordpress/components'; import { useState, useCallback } from '@wordpress/element'; import type { TabPanelProps, Tab } from './consts'; import { updateActiveTabURL } from '@admin/utilities'; export default function Tabs(props: TabPanelProps) { const { tabs, onTabSelect = () => { }, defaultTab = '', updateURL = false, ...rest } = props; const tabKeys = tabs.map((tab) => tab.name); const [activeTab, setActiveTab] = useState(() => { return tabKeys.indexOf(defaultTab) !== -1 ? defaultTab : tabKeys[0]; }); const handleTabSelect = useCallback((tabName: Tab['name']) => { setActiveTab(tabName); onTabSelect(tabName, tabKeys); if (updateURL) { updateActiveTabURL(tabName, tabKeys); } }, [onTabSelect, tabKeys, updateURL]); return ( <> {(tab) => <>}
{tabs.map((el) => { return (
{el.renderingEl}
); })}
); }