2024-05-28 23:32:10 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { TabPanel } from '@wordpress/components';
|
2024-05-29 00:47:56 +00:00
|
|
|
import { getNewPath, navigateTo } from '@woocommerce/navigation';
|
2024-05-28 23:32:10 +00:00
|
|
|
|
2024-05-29 00:47:56 +00:00
|
|
|
export const Tabs = ( { data, page, children } ) => {
|
2024-05-28 23:32:10 +00:00
|
|
|
const onSelect = ( tabName ) => {
|
2024-05-29 00:47:56 +00:00
|
|
|
const url = getNewPath( {}, `/settings/${ tabName }` );
|
|
|
|
navigateTo( { url } );
|
2024-05-28 23:32:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<TabPanel
|
2024-05-29 00:17:39 +00:00
|
|
|
className="woocommerce-settings-tabs"
|
2024-05-28 23:32:10 +00:00
|
|
|
activeClass="active-tab"
|
|
|
|
onSelect={ onSelect }
|
|
|
|
initialTabName={ page }
|
|
|
|
tabs={ Object.keys( data ).map( ( key ) => ( {
|
|
|
|
name: key,
|
|
|
|
title: data[ key ].label,
|
|
|
|
} ) ) }
|
|
|
|
>
|
2024-05-29 00:47:56 +00:00
|
|
|
{ () => <div>{ children }</div> }
|
2024-05-28 23:32:10 +00:00
|
|
|
</TabPanel>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|