-
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.
Widget editor: Add toolbar button to move between widget areas (#30826)
* Add moveTo icon * Add first draft of move to widget area dropdown menu * Reorganise editor filters * Use callback for child of DropdownMenu * Add filter for showing move to widget area menu * Fix __internalWidgetId prop being part of the attributes not block props * Use toolbar item for dropdown menu toggle * Move button to end of toolbar and place in own toolbar group * Add moveBlockToWidgetArea action and implement for toolbar button * Open widget area for moving before moving * Handle scrolling when block moves into new parent * Use store variable instead of string * Improve naming conventions * Add e2e test
- Loading branch information
Showing
11 changed files
with
258 additions
and
12 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
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/edit-widgets/src/components/move-to-widget-area/index.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 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
DropdownMenu, | ||
MenuGroup, | ||
MenuItemsChoice, | ||
ToolbarGroup, | ||
ToolbarItem, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { moveTo } from '@wordpress/icons'; | ||
|
||
export default function MoveToWidgetArea( { | ||
currentWidgetArea, | ||
widgetAreas, | ||
onSelect, | ||
} ) { | ||
return ( | ||
<ToolbarGroup> | ||
<ToolbarItem> | ||
{ ( toggleProps ) => ( | ||
<DropdownMenu | ||
icon={ moveTo } | ||
label={ __( 'Move to widget area' ) } | ||
toggleProps={ toggleProps } | ||
> | ||
{ ( { onClose } ) => ( | ||
<MenuGroup label={ __( 'Move to' ) }> | ||
<MenuItemsChoice | ||
choices={ widgetAreas.map( | ||
( widgetArea ) => ( { | ||
value: widgetArea.id, | ||
label: widgetArea.name, | ||
info: widgetArea.description, | ||
} ) | ||
) } | ||
value={ currentWidgetArea?.id } | ||
onSelect={ ( value ) => { | ||
onSelect( value ); | ||
onClose(); | ||
} } | ||
/> | ||
</MenuGroup> | ||
) } | ||
</DropdownMenu> | ||
) } | ||
</ToolbarItem> | ||
</ToolbarGroup> | ||
); | ||
} |
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,5 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './move-to-widget-area'; | ||
import './replace-media-upload'; |
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,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
import { BlockControls } from '@wordpress/block-editor'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import MoveToWidgetArea from '../components/move-to-widget-area'; | ||
import { store as editWidgetsStore } from '../store'; | ||
|
||
const withMoveToWidgetAreaToolbarItem = createHigherOrderComponent( | ||
( BlockEdit ) => ( props ) => { | ||
const { __internalWidgetId } = props.attributes; | ||
const { widgetAreas, currentWidgetArea } = useSelect( | ||
( select ) => { | ||
const selectors = select( editWidgetsStore ); | ||
return { | ||
widgetAreas: selectors.getWidgetAreas(), | ||
currentWidgetArea: __internalWidgetId | ||
? selectors.getWidgetAreaForWidgetId( | ||
__internalWidgetId | ||
) | ||
: undefined, | ||
}; | ||
}, | ||
[ __internalWidgetId ] | ||
); | ||
|
||
const { moveBlockToWidgetArea } = useDispatch( editWidgetsStore ); | ||
|
||
return ( | ||
<> | ||
<BlockEdit { ...props } /> | ||
{ props.name !== 'core/widget-area' && ( | ||
<BlockControls> | ||
<MoveToWidgetArea | ||
widgetAreas={ widgetAreas } | ||
currentWidgetArea={ currentWidgetArea } | ||
onSelect={ ( widgetAreaId ) => { | ||
moveBlockToWidgetArea( | ||
props.clientId, | ||
widgetAreaId | ||
); | ||
} } | ||
/> | ||
</BlockControls> | ||
) } | ||
</> | ||
); | ||
}, | ||
'withMoveToWidgetAreaToolbarItem' | ||
); | ||
|
||
addFilter( | ||
'editor.BlockEdit', | ||
'core/edit-widgets/block-edit', | ||
withMoveToWidgetAreaToolbarItem | ||
); |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Path, SVG } from '@wordpress/primitives'; | ||
|
||
const moveTo = ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<Path d="M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z" /> | ||
</SVG> | ||
); | ||
|
||
export default moveTo; |