-
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
- Loading branch information
1 parent
7a393af
commit b60f2fc
Showing
9 changed files
with
147 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTitle from '../block-title'; | ||
|
||
/** | ||
* Block breadcrumb component, displaying the label of the block. If the block | ||
* descends from a root block, a button is displayed enabling the user to select | ||
* the root block. | ||
* | ||
* @param {string} props.clientId Client ID of block. | ||
* @return {WPElement} Block Breadcrumb. | ||
*/ | ||
const BlockBreadcrumb = function() { | ||
const { selectBlock } = useDispatch( 'core/block-editor' ); | ||
const { clientId, parents } = useSelect( ( select ) => { | ||
const selectedBlockClientId = select( 'core/block-editor' ).getSelectedBlockClientId(); | ||
return { | ||
parents: select( 'core/block-editor' ).getBlockParents( selectedBlockClientId ), | ||
clientId: selectedBlockClientId, | ||
}; | ||
}, [] ); | ||
|
||
return ( | ||
<ul className="block-editor-block-breadcrumb"> | ||
{ parents.map( ( parent ) => ( | ||
<li key={ parent }> | ||
<Button | ||
className="block-editor-block-breadcrumb__button" | ||
isTertiary | ||
onClick={ () => selectBlock( parent ) } | ||
> | ||
<BlockTitle clientId={ parent } /> | ||
</Button> | ||
</li> | ||
) ) } | ||
{ !! clientId && ( | ||
<li className="block-editor-block-breadcrumb__current"> | ||
<BlockTitle clientId={ clientId } /> | ||
</li> | ||
) } | ||
</ul> | ||
); | ||
}; | ||
|
||
export default BlockBreadcrumb; |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
.block-editor-block-breadcrumb { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
|
||
li { | ||
display: inline-block; | ||
margin: 0; | ||
|
||
&:not(.block-editor-block-breadcrumb__current)::after { | ||
content: "▸"; | ||
} | ||
} | ||
} | ||
|
||
.block-editor-block-breadcrumb__button.components-button { | ||
color: inherit; | ||
font-size: inherit; | ||
} | ||
|
||
.block-editor-block-breadcrumb__current { | ||
padding: 0 10px; | ||
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