2021-12-14 16:56:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Slot, Fill } from '@wordpress/components';
|
|
|
|
|
|
|
|
/**
|
2022-08-04 13:15:30 +00:00
|
|
|
* Internal dependencies
|
2022-04-20 08:48:36 +00:00
|
|
|
*/
|
2022-08-04 13:15:30 +00:00
|
|
|
import { createOrderedChildren, sortFillsByOrder } from '~/utils';
|
2021-12-14 16:56:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Fill for extensions to add items to the WooCommerce Admin header.
|
|
|
|
*
|
|
|
|
* @slotFill WooHeaderItem
|
2022-02-11 14:38:38 +00:00
|
|
|
* @scope woocommerce-admin
|
2021-12-14 16:56:42 +00:00
|
|
|
* @example
|
|
|
|
* const MyHeaderItem = () => (
|
|
|
|
* <WooHeaderItem>My header item</WooHeaderItem>
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* registerPlugin( 'my-extension', {
|
|
|
|
* render: MyHeaderItem,
|
|
|
|
* scope: 'woocommerce-admin',
|
|
|
|
* } );
|
|
|
|
* @param {Object} param0
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Array} param0.children - Node children.
|
|
|
|
* @param {Array} param0.order - Node order.
|
2021-12-14 16:56:42 +00:00
|
|
|
*/
|
2022-04-20 08:48:36 +00:00
|
|
|
export const WooHeaderItem: React.FC< { order?: number } > & {
|
|
|
|
Slot: React.FC< Slot.Props >;
|
|
|
|
} = ( { children, order = 1 } ) => {
|
2021-12-14 16:56:42 +00:00
|
|
|
return (
|
|
|
|
<Fill name={ 'woocommerce_header_item' }>
|
2022-04-20 08:48:36 +00:00
|
|
|
{ ( fillProps: Fill.Props ) => {
|
2021-12-14 16:56:42 +00:00
|
|
|
return createOrderedChildren( children, order, fillProps );
|
|
|
|
} }
|
|
|
|
</Fill>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
WooHeaderItem.Slot = ( { fillProps } ) => (
|
|
|
|
<Slot name={ 'woocommerce_header_item' } fillProps={ fillProps }>
|
2022-04-20 08:48:36 +00:00
|
|
|
{ sortFillsByOrder }
|
2021-12-14 16:56:42 +00:00
|
|
|
</Slot>
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Fill for extensions to add items to the WooCommerce Admin
|
|
|
|
* navigation area left of the page title.
|
|
|
|
*
|
|
|
|
* @slotFill WooHeaderNavigationItem
|
2022-02-11 14:38:38 +00:00
|
|
|
* @scope woocommerce-admin
|
2021-12-14 16:56:42 +00:00
|
|
|
* @example
|
|
|
|
* const MyNavigationItem = () => (
|
|
|
|
* <WooHeaderNavigationItem>My nav item</WooHeaderNavigationItem>
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* registerPlugin( 'my-extension', {
|
|
|
|
* render: MyNavigationItem,
|
|
|
|
* scope: 'woocommerce-admin',
|
|
|
|
* } );
|
|
|
|
* @param {Object} param0
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Array} param0.children - Node children.
|
|
|
|
* @param {Array} param0.order - Node order.
|
2021-12-14 16:56:42 +00:00
|
|
|
*/
|
2022-04-20 08:48:36 +00:00
|
|
|
export const WooHeaderNavigationItem: React.FC< { order?: number } > & {
|
|
|
|
Slot: React.FC< Slot.Props >;
|
|
|
|
} = ( { children, order = 1 } ) => {
|
2021-12-14 16:56:42 +00:00
|
|
|
return (
|
|
|
|
<Fill name={ 'woocommerce_header_navigation_item' }>
|
2022-04-20 08:48:36 +00:00
|
|
|
{ ( fillProps: Fill.Props ) => {
|
2021-12-14 16:56:42 +00:00
|
|
|
return createOrderedChildren( children, order, fillProps );
|
|
|
|
} }
|
|
|
|
</Fill>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-20 08:48:36 +00:00
|
|
|
WooHeaderNavigationItem.Slot = ( { fillProps }: Slot.Props ) => (
|
2021-12-14 16:56:42 +00:00
|
|
|
<Slot name={ 'woocommerce_header_navigation_item' } fillProps={ fillProps }>
|
2022-04-20 08:48:36 +00:00
|
|
|
{ sortFillsByOrder }
|
2021-12-14 16:56:42 +00:00
|
|
|
</Slot>
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Fill for extensions to add custom page titles.
|
|
|
|
*
|
|
|
|
* @slotFill WooHeaderPageTitle
|
2022-02-11 14:38:38 +00:00
|
|
|
* @scope woocommerce-admin
|
2021-12-14 16:56:42 +00:00
|
|
|
* @example
|
|
|
|
* const MyPageTitle = () => (
|
|
|
|
* <WooHeaderPageTitle>My page title</WooHeaderPageTitle>
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* registerPlugin( 'my-page-title', {
|
|
|
|
* render: MyPageTitle,
|
|
|
|
* scope: 'woocommerce-admin',
|
|
|
|
* } );
|
|
|
|
* @param {Object} param0
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Array} param0.children - Node children.
|
2021-12-14 16:56:42 +00:00
|
|
|
*/
|
2022-04-20 08:48:36 +00:00
|
|
|
export const WooHeaderPageTitle: React.FC & {
|
|
|
|
Slot: React.FC< Slot.Props >;
|
|
|
|
} = ( { children } ) => {
|
2021-12-14 16:56:42 +00:00
|
|
|
return <Fill name={ 'woocommerce_header_page_title' }>{ children }</Fill>;
|
|
|
|
};
|
|
|
|
|
|
|
|
WooHeaderPageTitle.Slot = ( { fillProps } ) => (
|
|
|
|
<Slot name={ 'woocommerce_header_page_title' } fillProps={ fillProps }>
|
|
|
|
{ ( fills ) => {
|
2022-04-21 03:07:25 +00:00
|
|
|
return <>{ [ ...fills ].pop() }</>;
|
2021-12-14 16:56:42 +00:00
|
|
|
} }
|
|
|
|
</Slot>
|
|
|
|
);
|