SlotFills Reference Edit

Slot and Fill are components that have been exposed to allow developers to inject items into some predefined places in the Gutenberg admin experience.
Please see the SlotFill component docs for more details.

In order to use them, we must leverage the @wordpress/plugins api to register a plugin that will inject our items.

Usage overview Usage overview

In order to access the SlotFills, we need to do four things:

  1. Import the registerPlugin method from wp.plugins.
  2. Import the SlotFill we want from wp.editPost.
  3. Define a method to render our changes. Our changes/additions will be wrapped in the SlotFill component we imported.
  4. Register the plugin.

Here is an example using the PluginPostStatusInfo slotFill:

const { registerPlugin } = wp.plugins;
const { PluginPostStatusInfo } = wp.editPost;


const PluginPostStatusInfoTest = () => {
    return(
        <PluginPostStatusInfo>
            <p>Post Status Info SlotFill</p>
        </PluginPostStatusInfo>
    )
}

registerPlugin( 'post-status-info-test', { render: PluginPostStatusInfoTest } );

Top ↑

How do they work? How do they work?

SlotFills are created using createSlotFill. This creates two components, Slot and Fill which are then used to create a new component that is exported on the wp.plugins global.

Definition of the PluginPostStatusInfo SlotFill (see core code)

/**
 * Defines as extensibility slot for the Status & Visibility panel.
 */

/**
 * WordPress dependencies
 */
import { createSlotFill, PanelRow } from '@wordpress/components';

export const { Fill, Slot } = createSlotFill( 'PluginPostStatusInfo' );

const PluginPostStatusInfo = ( { children, className } ) => (
    <Fill>
        <PanelRow className={ className }>
            { children }
        </PanelRow>
    </Fill>
);

PluginPostStatusInfo.Slot = Slot;

export default PluginPostStatusInfo;

This new Slot is then exposed in the editor. The example below is from core and represents the Status & Visibility panel.

As we can see, the <PluginPostStatusInfo.Slot> is wrapping all of the items that will appear in the panel.
Any items that have been added via the SlotFill ( see the example above ), will be included in the fills parameter and be displayed between the <PostAuthor/> and <PostTrash/> components.

See core code.

function PostStatus( { isOpened, onTogglePanel } ) {
    return (
        <PanelBody className="edit-post-post-status" title={ __( 'Status & Visibility' ) } opened={ isOpened } onToggle={ onTogglePanel }>
            <PluginPostStatusInfo.Slot>
                { ( fills ) => (
                    <Fragment>
                        <PostVisibility />
                        <PostSchedule />
                        <PostFormat />
                        <PostSticky />
                        <PostPendingStatus />
                        <PostAuthor />
                        { fills }
                        <PostTrash />
                    </Fragment>
                ) }
            </PluginPostStatusInfo.Slot>
        </PanelBody>
    );
}

Top ↑

Currently available SlotFills and examples Currently available SlotFills and examples

There are currently seven available SlotFills in the edit-post package. Please refer to the individual items below for usage and example details: