add tabPanel

This commit is contained in:
paul sealock 2024-05-29 11:32:10 +12:00
parent cf896732bc
commit 20a4cab4c6
3 changed files with 52 additions and 3 deletions

View File

@ -350,7 +350,7 @@ export const getPages = () => {
}`,
__( 'Settings', 'woocommerce' ),
],
page,
page.label,
];
},
wpOpenMenu: 'toplevel_page_woocommerce',

View File

@ -1,3 +1,25 @@
export default ( {} ) => {
return <div>Settings page</div>;
/**
* External dependencies
*/
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { Tabs } from './tabs';
const Settings = ( { params } ) => {
const settingsData = window.wcSettings?.admin?.settingsPages;
if ( ! settingsData ) {
return <div>Error getting data</div>;
}
return (
<>
<Tabs data={ settingsData } page={ params.page } />
</>
);
};
export default Settings;

View File

@ -0,0 +1,27 @@
/**
* External dependencies
*/
import { TabPanel } from '@wordpress/components';
export const Tabs = ( { data, page } ) => {
const onSelect = ( tabName ) => {
console.log( 'Selecting tab', tabName );
};
return (
<>
<TabPanel
className="my-tab-panel"
activeClass="active-tab"
onSelect={ onSelect }
initialTabName={ page }
tabs={ Object.keys( data ).map( ( key ) => ( {
name: key,
title: data[ key ].label,
} ) ) }
>
{ ( tab ) => <p>{ tab.title }</p> }
</TabPanel>
</>
);
};