Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Introduce PluginPostExcerpt slot #55200

Merged
merged 14 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Defines as extensibility slot for the Excerpt panel.
*/

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

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

/**
* Renders a post excerpt panel in the post sidebar.
*
* @param {Object} props Component properties.
* @param {string} [props.className] An optional class name added to the row.
* @param {Element} props.children Children to be rendered.
*
* @example
* ```js
* // Using ES5 syntax
* var __ = wp.i18n.__;
* var PluginPostExcerpt = wp.editPost.PluginPostExcerpt;
*
* function MyPluginPostExcerpt() {
* return React.createElement(
* PluginPostExcerpt,
* {
* className: 'my-plugin-post-excerpt',
* },
* __( 'Post excerpt custom content' )
* )
* }
* ```
*
* @example
* ```jsx
* // Using ESNext syntax
* import { __ } from '@wordpress/i18n';
* import { PluginPostExcerpt } from '@wordpress/edit-post';
*
* const MyPluginPostExcerpt = () => (
* <PluginPostExcerpt className="my-plugin-post-excerpt">
* { __( 'Post excerpt custom content' ) }
* </PluginPostExcerpt>
* );
* ```
*
* @return {Component} The component to be rendered.
*/
const PluginPostExcerpt = ( { children, className } ) => {
return (
<Fill>
<PanelRow className={ className }>{ children }</PanelRow>
</Fill>
);
};

PluginPostExcerpt.Slot = Slot;

export default PluginPostExcerpt;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';

/**
* WordPress dependencies
*/
import { SlotFillProvider } from '@wordpress/components';

/**
* Internal dependencies
*/
import PluginPostExcerptPanel from '../';

describe( 'PluginPostExcerptPanel', () => {
test( 'renders fill properly', () => {
render(
<SlotFillProvider>
<PluginPostExcerptPanel className="my-plugin-post-excerpt-custom-content">
Post Excerpt - Custom content
</PluginPostExcerptPanel>
<div role="tabpanel">
<PluginPostExcerptPanel.Slot />
</div>
</SlotFillProvider>
);

expect( screen.getByRole( 'tabpanel' ) ).toHaveTextContent(
'Post Excerpt - Custom content'
);
expect(
screen.getByText( 'Post Excerpt - Custom content' )
).toHaveClass( 'my-plugin-post-excerpt-custom-content' );
} );
} );
10 changes: 9 additions & 1 deletion packages/edit-post/src/components/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
import PluginPostExcerpt from '../plugin-post-excerpt';

/**
* Module Constants
Expand Down Expand Up @@ -44,7 +45,14 @@ export default function PostExcerpt() {
opened={ isOpened }
onToggle={ toggleExcerptPanel }
>
<PostExcerptForm />
<PluginPostExcerpt.Slot>
{ ( fills ) => (
<>
<PostExcerptForm />
{ fills }
</>
) }
</PluginPostExcerpt.Slot>
</PanelBody>
</PostExcerptCheck>
);
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
export { default as __experimentalFullscreenModeClose } from './components/header/fullscreen-mode-close';
export { default as __experimentalMainDashboardButton } from './components/header/main-dashboard-button';
export { default as __experimentalPluginPostExcerpt } from './components/sidebar/plugin-post-excerpt';
export { store } from './store';
Loading