/**
* External dependencies
*/
import { Slot, Fill } from '@wordpress/components';
/**
* Internal dependencies
*/
import { createOrderedChildren, sortFillsByOrder } from '~/utils';
/**
* Create a Fill for extensions to add items to the WooCommerce Admin header.
*
* @slotFill WooHeaderItem
* @scope woocommerce-admin
* @example
* const MyHeaderItem = () => (
* My header item
* );
*
* registerPlugin( 'my-extension', {
* render: MyHeaderItem,
* scope: 'woocommerce-admin',
* } );
* @param {Object} param0
* @param {Array} param0.children - Node children.
* @param {Array} param0.order - Node order.
*/
export const WooHeaderItem: React.FC< { order?: number } > & {
Slot: React.FC< Slot.Props >;
} = ( { children, order = 1 } ) => {
return (
{ ( fillProps: Fill.Props ) => {
return createOrderedChildren( children, order, fillProps );
} }
);
};
WooHeaderItem.Slot = ( { fillProps } ) => (
{ sortFillsByOrder }
);
/**
* Create a Fill for extensions to add items to the WooCommerce Admin
* navigation area left of the page title.
*
* @slotFill WooHeaderNavigationItem
* @scope woocommerce-admin
* @example
* const MyNavigationItem = () => (
* My nav item
* );
*
* registerPlugin( 'my-extension', {
* render: MyNavigationItem,
* scope: 'woocommerce-admin',
* } );
* @param {Object} param0
* @param {Array} param0.children - Node children.
* @param {Array} param0.order - Node order.
*/
export const WooHeaderNavigationItem: React.FC< { order?: number } > & {
Slot: React.FC< Slot.Props >;
} = ( { children, order = 1 } ) => {
return (
{ ( fillProps: Fill.Props ) => {
return createOrderedChildren( children, order, fillProps );
} }
);
};
WooHeaderNavigationItem.Slot = ( { fillProps }: Slot.Props ) => (
{ sortFillsByOrder }
);
/**
* Create a Fill for extensions to add custom page titles.
*
* @slotFill WooHeaderPageTitle
* @scope woocommerce-admin
* @example
* const MyPageTitle = () => (
* My page title
* );
*
* registerPlugin( 'my-page-title', {
* render: MyPageTitle,
* scope: 'woocommerce-admin',
* } );
* @param {Object} param0
* @param {Array} param0.children - Node children.
*/
export const WooHeaderPageTitle: React.FC & {
Slot: React.FC< Slot.Props >;
} = ( { children } ) => {
return { children };
};
WooHeaderPageTitle.Slot = ( { fillProps } ) => (
{ ( fills ) => {
return <>{ [ ...fills ].pop() }>;
} }
);