-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a header menu to switch between edit and select tool (#18624)
- Loading branch information
1 parent
c97ccf0
commit 2bec0e6
Showing
24 changed files
with
145 additions
and
61 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
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
76 changes: 76 additions & 0 deletions
76
packages/block-editor/src/components/tool-selector/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,76 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Dropdown, | ||
IconButton, | ||
MenuItemsChoice, | ||
SVG, | ||
Path, | ||
NavigableMenu, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { ifViewportMatches } from '@wordpress/viewport'; | ||
|
||
const editIcon = <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><Path fill="none" d="M0 0h24v24H0V0z" /><Path d="M14.06 9.02l.92.92L5.92 19H5v-.92l9.06-9.06M17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29zm-3.6 3.19L3 17.25V21h3.75L17.81 9.94l-3.75-3.75z" /></SVG>; | ||
const selectIcon = <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><Path d="M6.5 1v21.5l6-6.5H21L6.5 1zm5.1 13l-3.1 3.4V5.9l7.8 8.1h-4.7z" /></SVG>; | ||
|
||
function ToolSelector() { | ||
const isNavigationTool = useSelect( ( select ) => select( 'core/block-editor' ).isNavigationMode() ); | ||
const { setNavigationMode } = useDispatch( 'core/block-editor' ); | ||
const onSwitchMode = ( mode ) => { | ||
setNavigationMode( mode === 'edit' ? false : true ); | ||
}; | ||
|
||
return ( | ||
<Dropdown | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<IconButton | ||
icon={ isNavigationTool ? selectIcon : editIcon } | ||
aria-expanded={ isOpen } | ||
onClick={ onToggle } | ||
label={ __( 'Tools' ) } | ||
/> | ||
) } | ||
renderContent={ () => ( | ||
<> | ||
<NavigableMenu | ||
role="menu" | ||
aria-label={ __( 'Tools' ) } | ||
> | ||
<MenuItemsChoice | ||
value={ isNavigationTool ? 'select' : 'edit' } | ||
onSelect={ onSwitchMode } | ||
choices={ [ | ||
{ | ||
value: 'edit', | ||
label: ( | ||
<> | ||
{ editIcon } | ||
{ __( 'Edit' ) } | ||
</> | ||
), | ||
}, | ||
{ | ||
value: 'select', | ||
label: ( | ||
<> | ||
{ selectIcon } | ||
{ __( 'Select' ) } | ||
</> | ||
), | ||
}, | ||
] } | ||
/> | ||
</NavigableMenu> | ||
<div className="block-editor-tool-selector__help"> | ||
{ __( 'Tools offer different interactions for block selection & editing. To select, press Escape, to go back to editing, press Enter.' ) } | ||
</div> | ||
</> | ||
) } | ||
/> | ||
); | ||
} | ||
|
||
export default ifViewportMatches( 'medium' )( ToolSelector ); |
5 changes: 5 additions & 0 deletions
5
packages/block-editor/src/components/tool-selector/style.scss
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 @@ | ||
.block-editor-tool-selector__help { | ||
padding: $grid-size-large; | ||
border-top: 1px solid $light-gray-500; | ||
color: $dark-gray-300; | ||
} |
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
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 @@ | ||
.components-menu-items-choice, | ||
.components-menu-items-choice.components-icon-button { | ||
padding-left: 2rem; | ||
|
||
&.has-icon { | ||
padding-left: 0.5rem; | ||
} | ||
|
||
.dashicon { | ||
margin-right: 4px; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1 @@ | ||
/** | ||
* Triggers edit mode if not already active. | ||
* | ||
* @return {Promise} Promise resolving after enabling the keyboard edit mode. | ||
*/ | ||
export async function disableNavigationMode() { | ||
const focusedElement = await page.$( ':focus' ); | ||
await page.click( '.editor-post-title' ); | ||
if ( focusedElement ) { | ||
await focusedElement.focus(); | ||
} | ||
} | ||
|
Oops, something went wrong.