woocommerce/plugins/woocommerce-admin/client/settings/settings-view-example.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-06-10 02:02:35 +00:00
/**
* External dependencies
*/
2024-06-10 05:14:38 +00:00
import { createSlotFill, Button } from '@wordpress/components';
2024-06-10 02:02:35 +00:00
import { registerPlugin } from '@wordpress/plugins';
/**
* Internal dependencies
*/
import { SETTINGS_SLOT_FILL_CONSTANT } from './settings-slots';
const { Fill } = createSlotFill( SETTINGS_SLOT_FILL_CONSTANT );
2024-06-10 19:38:22 +00:00
const SidebarContent = () => {
return (
<div>
<h2>This is content created by the Fill</h2>
</div>
);
};
2024-06-10 02:02:35 +00:00
const ExampleSettingsViewSlotFill = () => {
const style = { margin: '36px 0px' };
return (
<Fill>
2024-06-10 05:14:38 +00:00
{ ( { toggleSidebar, setSidebarContent } ) => {
return (
<div style={ style }>
<h1>Example Settings View</h1>
<p>This is the main content using a SlotFill</p>
<Button
variant="secondary"
onClick={ () => {
toggleSidebar();
2024-06-10 19:38:22 +00:00
setSidebarContent( SidebarContent );
2024-06-10 05:14:38 +00:00
} }
>
Show Sidebar
</Button>
</div>
);
} }
2024-06-10 02:02:35 +00:00
</Fill>
);
};
export const registerExampleSettingsView = () => {
registerPlugin( 'woocommerce-exampple-settings-view-slotfill', {
scope: 'woocommerce-settings',
render: ExampleSettingsViewSlotFill,
} );
};