SlotFills Reference

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

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:

import { registerPlugin } from '@wordpress/plugins';
import { PluginPostStatusInfo } from '@wordpress/edit-post';

const PluginPostStatusInfoTest = () => (
        <p>Post Status Info SlotFill</p>

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

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 Summary panel.

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

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

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

PluginPostStatusInfo.Slot = Slot;

export default PluginPostStatusInfo;

This new Slot is then exposed in the editor. The example below is from core and represents the Summary 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.

const PostStatus = ( { isOpened, onTogglePanel } ) => (
        title={ __( 'Summary' ) }
        opened={ isOpened }
        onToggle={ onTogglePanel }
            { ( fills ) => (
                    <PostVisibility />
                    <PostSchedule />
                    <PostFormat />
                    <PostSticky />
                    <PostPendingStatus />
                    <PostAuthor />
                    { fills }
                    <PostTrash />
            ) }

Currently available SlotFills and examples

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