-
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 block selection breadcrumb to the bottom of the editor (#17838)
- Loading branch information
1 parent
ac6dc61
commit 775d003
Showing
15 changed files
with
275 additions
and
80 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
77 changes: 77 additions & 0 deletions
77
packages/block-editor/src/components/block-breadcrumb/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,77 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTitle from '../block-title'; | ||
|
||
/** | ||
* Block breadcrumb component, displaying the hierarchy of the current block selection as a breadcrumb. | ||
* | ||
* @return {WPElement} Block Breadcrumb. | ||
*/ | ||
const BlockBreadcrumb = function() { | ||
const { selectBlock, clearSelectedBlock } = useDispatch( 'core/block-editor' ); | ||
const { clientId, parents, hasSelection } = useSelect( ( select ) => { | ||
const { | ||
getSelectionStart, | ||
getSelectedBlockClientId, | ||
getBlockParents, | ||
} = select( 'core/block-editor' ); | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
return { | ||
parents: getBlockParents( selectedBlockClientId ), | ||
clientId: selectedBlockClientId, | ||
hasSelection: !! getSelectionStart().clientId, | ||
}; | ||
}, [] ); | ||
|
||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
* Safari+VoiceOver won't announce the list otherwise. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ | ||
return ( | ||
<ul className="block-editor-block-breadcrumb" role="list" aria-label={ __( 'Block breadcrumb' ) }> | ||
<li | ||
className={ ! hasSelection ? 'block-editor-block-breadcrumb__current' : undefined } | ||
aria-current={ ! hasSelection ? 'true' : undefined } | ||
> | ||
{ hasSelection && ( | ||
<Button | ||
className="block-editor-block-breadcrumb__button" | ||
isTertiary | ||
onClick={ clearSelectedBlock } | ||
> | ||
{ __( 'Document' ) } | ||
</Button> | ||
) } | ||
{ ! hasSelection && __( 'Document' ) } | ||
</li> | ||
{ parents.map( ( parentClientId ) => ( | ||
<li key={ parentClientId }> | ||
<Button | ||
className="block-editor-block-breadcrumb__button" | ||
isTertiary | ||
onClick={ () => selectBlock( parentClientId ) } | ||
> | ||
<BlockTitle clientId={ parentClientId } /> | ||
</Button> | ||
</li> | ||
) ) } | ||
{ !! clientId && ( | ||
<li className="block-editor-block-breadcrumb__current" aria-current="true"> | ||
<BlockTitle clientId={ clientId } /> | ||
</li> | ||
) } | ||
</ul> | ||
/* eslint-enable jsx-a11y/no-redundant-roles */ | ||
); | ||
}; | ||
|
||
export default BlockBreadcrumb; |
41 changes: 41 additions & 0 deletions
41
packages/block-editor/src/components/block-breadcrumb/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,41 @@ | ||
.block-editor-block-breadcrumb { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
|
||
li { | ||
display: inline-block; | ||
margin: 0; | ||
|
||
&:not(:last-child)::after { | ||
content: "\2192"; // This becomes →. | ||
} | ||
} | ||
} | ||
|
||
.block-editor-block-breadcrumb__button.components-button { | ||
height: $icon-button-size-small; | ||
line-height: $icon-button-size-small; | ||
padding: 0; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
&:focus { | ||
@include square-style__focus(); | ||
outline-offset: -2px; | ||
box-shadow: none; | ||
} | ||
} | ||
|
||
.block-editor-block-breadcrumb__current { | ||
cursor: default; | ||
} | ||
|
||
.block-editor-block-breadcrumb__button.components-button, | ||
.block-editor-block-breadcrumb__current { | ||
color: $dark-gray-500; | ||
padding: 0 $grid-size; | ||
font-size: inherit; | ||
} |
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
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
Oops, something went wrong.