get slotfill_placeholder type working

This commit is contained in:
paul sealock 2024-05-30 14:28:29 +12:00
parent 884f00cf73
commit 63e751a3a2
3 changed files with 59 additions and 10 deletions

View File

@ -26,6 +26,14 @@ export const Content = ( { data } ) => {
return ( return (
<SettingsCheckbox setting={ setting } key={ key } /> <SettingsCheckbox setting={ setting } key={ key } />
); );
case 'slotfill_placeholder':
return (
<div
key={ key }
id={ setting.id }
className={ setting.class }
></div>
);
default: default:
return null; return null;
} }

View File

@ -2,6 +2,7 @@
* External dependencies * External dependencies
*/ */
import { getQuery } from '@woocommerce/navigation'; import { getQuery } from '@woocommerce/navigation';
import { useEffect } from '@wordpress/element';
/** /**
* Internal dependencies * Internal dependencies
@ -9,12 +10,26 @@ import { getQuery } from '@woocommerce/navigation';
import { Tabs } from './tabs'; import { Tabs } from './tabs';
import { SectionNav } from './section-nav'; import { SectionNav } from './section-nav';
import { Content } from './content'; import { Content } from './content';
import { possiblyRenderSettingsSlots } from './settings-slots';
import { registerTaxSettingsConflictErrorFill } from './conflict-error-slotfill';
import { registerPaymentsSettingsBannerFill } from '../payments/payments-settings-banner-slotfill';
import { registerSiteVisibilitySlotFill } from '../launch-your-store';
import './style.scss'; import './style.scss';
const Settings = ( { params } ) => { const Settings = ( { params } ) => {
const settingsData = window.wcSettings?.admin?.settingsPages; const settingsData = window.wcSettings?.admin?.settingsPages;
const { section } = getQuery(); const { section } = getQuery();
useEffect( () => {
possiblyRenderSettingsSlots();
}, [ params ] );
useEffect( () => {
registerTaxSettingsConflictErrorFill();
registerPaymentsSettingsBannerFill();
registerSiteVisibilitySlotFill();
}, [] );
if ( ! settingsData ) { if ( ! settingsData ) {
return <div>Error getting data</div>; return <div>Error getting data</div>;
} }

View File

@ -1,7 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { render } from '@wordpress/element'; import { render, createRoot } from '@wordpress/element';
import { createSlotFill, SlotFillProvider } from '@wordpress/components'; import { createSlotFill, SlotFillProvider } from '@wordpress/components';
import { PluginArea } from '@wordpress/plugins'; import { PluginArea } from '@wordpress/plugins';
@ -10,6 +10,8 @@ export const SETTINGS_SLOT_FILL_CONSTANT =
const { Slot } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT ); const { Slot } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
const roots = {};
export const possiblyRenderSettingsSlots = () => { export const possiblyRenderSettingsSlots = () => {
const slots = [ const slots = [
{ {
@ -28,15 +30,39 @@ export const possiblyRenderSettingsSlots = () => {
const slotDomElement = document.getElementById( slot.id ); const slotDomElement = document.getElementById( slot.id );
if ( slotDomElement ) { if ( slotDomElement ) {
render( if ( createRoot ) {
<> if ( roots[ slot.id ] ) {
<SlotFillProvider> roots[ slot.id ].render(
<Slot /> <>
<PluginArea scope={ slot.scope } /> <SlotFillProvider>
</SlotFillProvider> <Slot />
</>, <PluginArea scope={ slot.scope } />
slotDomElement </SlotFillProvider>
); </>
);
} else {
const root = createRoot( slotDomElement );
root.render(
<>
<SlotFillProvider>
<Slot />
<PluginArea scope={ slot.scope } />
</SlotFillProvider>
</>
);
roots[ slot.id ] = root;
}
} else {
render(
<>
<SlotFillProvider>
<Slot />
<PluginArea scope={ slot.scope } />
</SlotFillProvider>
</>,
slotDomElement
);
}
} }
} ); } );
}; };