Order menu items in product editor's more menu (kebab menu) (#41104)

This commit is contained in:
Matt Sherman 2023-10-31 10:45:20 -04:00 committed by GitHub
commit 17ed81c24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 27 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Support ordering of more menu items in product editor header.

View File

@ -1,37 +1,32 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import { Slot, Fill } from '@wordpress/components';
import { createElement } from '@wordpress/element';
import {
createSlotFill,
Slot as BaseSlot,
Fill as BaseFill,
} from '@wordpress/components';
import { createElement, Fragment } from '@wordpress/element';
createOrderedChildren,
sortFillsByOrder,
} from '@woocommerce/components';
type WooProductMoreMenuSlot = React.FC< BaseSlot.Props >;
export const WC_PRODUCT_MORE_MENU_SLOT_NAME = 'WooProductMenuMenuItem';
type WooProductMoreMenuFill = React.FC< BaseFill.Props > & {
Slot?: WooProductMoreMenuSlot;
export const WooProductMoreMenuItem: React.FC< {
children?: React.ReactNode;
order?: number;
} > & {
Slot: React.FC< Slot.Props >;
} = ( { children, order = 1 } ) => {
return (
<Fill name={ WC_PRODUCT_MORE_MENU_SLOT_NAME }>
{ ( fillProps: Fill.Props ) => {
return createOrderedChildren( children, order, fillProps );
} }
</Fill>
);
};
type CreateSlotFillReturn = {
Fill: WooProductMoreMenuFill;
Slot: WooProductMoreMenuSlot;
};
const { Fill, Slot }: CreateSlotFillReturn = createSlotFill(
'WooProductMoreMenuItem'
);
Fill.Slot = ( { fillProps } ) => (
<Slot fillProps={ fillProps }>
{ ( fills ) => {
return isEmpty( fills ) ? null : <>{ fills }</>;
} }
WooProductMoreMenuItem.Slot = ( { fillProps } ) => (
<Slot name={ WC_PRODUCT_MORE_MENU_SLOT_NAME } fillProps={ fillProps }>
{ sortFillsByOrder }
</Slot>
);
export const WooProductMoreMenuItem = Fill as WooProductMoreMenuFill & {
Slot: WooProductMoreMenuSlot;
};