47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
/**
|
|
* External dependencies
|
|
*/
|
|
import { Slot, Fill } from '@wordpress/components';
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
import { createOrderedChildren, sortFillsByOrder } from '~/utils';
|
|
|
|
export const WC_FOOTER_SLOT_NAME = 'woocommerce_footer_item';
|
|
/**
|
|
* Create a Fill for extensions to add items to the WooCommerce Admin footer.
|
|
*
|
|
* @slotFill WooFooterItem
|
|
* @scope woocommerce-admin
|
|
* @example
|
|
* const MyFooterItem = () => (
|
|
* <WooFooterItem>My header item</WooFooterItem>
|
|
* );
|
|
*
|
|
* registerPlugin( 'my-extension', {
|
|
* render: MyFooterItem,
|
|
* scope: 'woocommerce-admin',
|
|
* } );
|
|
* @param {Object} param0
|
|
* @param {Array} param0.children - Node children.
|
|
* @param {Array} param0.order - Node order.
|
|
*/
|
|
export const WooFooterItem: React.FC< { order?: number } > & {
|
|
Slot: React.FC< Slot.Props >;
|
|
} = ( { children, order = 1 } ) => {
|
|
return (
|
|
<Fill name={ WC_FOOTER_SLOT_NAME }>
|
|
{ ( fillProps: Fill.Props ) => {
|
|
return createOrderedChildren( children, order, fillProps );
|
|
} }
|
|
</Fill>
|
|
);
|
|
};
|
|
|
|
WooFooterItem.Slot = ( { fillProps } ) => (
|
|
<Slot name={ WC_FOOTER_SLOT_NAME } fillProps={ fillProps }>
|
|
{ sortFillsByOrder }
|
|
</Slot>
|
|
);
|