-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly specify additional ellipsis menu options
- Loading branch information
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/block-editor/src/components/block-navigation/ellipsis-menu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useContext } from '@wordpress/element'; | ||
import { | ||
__experimentalToolbarContext as ToolbarContext, | ||
createSlotFill, | ||
ToolbarGroup, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ifBlockEditSelected } from '../block-edit/context'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'EllipsisMenu' ); | ||
|
||
function EllipsisMenuSlot( props ) { | ||
const accessibleToolbarState = useContext( ToolbarContext ); | ||
return <Slot { ...props } fillProps={ accessibleToolbarState } />; | ||
} | ||
|
||
function EllipsisMenuFill( { controls, children } ) { | ||
return ( | ||
<Fill> | ||
{ ( fillProps ) => { | ||
// Children passed to EllipsisMenuFill will not have access to any | ||
// React Context whose Provider is part of the EllipsisMenuSlot tree. | ||
// So we re-create the Provider in this subtree. | ||
const value = ! isEmpty( fillProps ) ? fillProps : null; | ||
return ( | ||
<ToolbarContext.Provider value={ value }> | ||
<ToolbarGroup controls={ controls } /> | ||
{ children } | ||
</ToolbarContext.Provider> | ||
); | ||
} } | ||
</Fill> | ||
); | ||
} | ||
|
||
const EllipsisMenu = ifBlockEditSelected( EllipsisMenuFill ); | ||
|
||
EllipsisMenu.Slot = EllipsisMenuSlot; | ||
|
||
export default EllipsisMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters