import { useEffect, useRef, useState } from '@wordpress/element'; import classnames from 'classnames'; import React from 'react'; import './editor.scss'; interface PropsType { hasIcon?: boolean; className?: string; label?: string; children?: any[]; } const TabPanel: React.FC = (props) => { const { children: tabs, hasIcon = false, className, label } = props; const firstTab = tabs && tabs?.length > 0 ? tabs[0] : null; const [isActive, setIsActive] = useState(firstTab?.props?.tabTitle); const tabPanelRef = useRef(); useEffect(() => { if (!tabs) { return; } if ( !tabs.some(({ props }) => ['Layout', 'Settings', 'Advanced'].includes(props?.tabTitle + ''), ) ) { return; } const sidebarPanel = tabPanelRef.current.closest('.components-panel'); sidebarPanel?.setAttribute('data-masteriyo-inspector-controls', true); return () => { sidebarPanel?.removeAttribute('data-masteriyo-inspector-controls'); }; }, [isActive, tabs]); if (!tabs) { return null; } return (
{label && }
{tabs.map((tab) => { const tabTitle = tab.props ? tab.props.tabTitle : ''; return ( ); })}
{tabs.map((tab) => (tab.props?.tabTitle === isActive ? tab : ''))}
); }; export default TabPanel;