-
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.
Stacked/unified block toolbar (#31134)
* Stacked/unified block toolbar * Fix compat layer in disabled context * Adjust stacked toolbar in template editor
- Loading branch information
Showing
31 changed files
with
269 additions
and
420 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
33 changes: 33 additions & 0 deletions
33
packages/block-editor/src/components/block-tools/back-compat.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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useContext } from '@wordpress/element'; | ||
import { Disabled } from '@wordpress/components'; | ||
import deprecated from '@wordpress/deprecated'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InsertionPoint, { InsertionPointOpenRef } from './insertion-point'; | ||
import BlockPopover from './block-popover'; | ||
|
||
export default function BlockToolsBackCompat( { children } ) { | ||
const openRef = useContext( InsertionPointOpenRef ); | ||
const isDisabled = useContext( Disabled.Context ); | ||
|
||
// If context is set, `BlockTools` is a parent component. | ||
if ( openRef || isDisabled ) { | ||
return children; | ||
} | ||
|
||
deprecated( 'wp.components.Popover.Slot name="block-toolbar"', { | ||
alternative: 'wp.blockEditor.BlockTools', | ||
} ); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return ( | ||
<InsertionPoint __unstablePopoverSlot="block-toolbar"> | ||
<BlockPopover __unstablePopoverSlot="block-toolbar" /> | ||
{ children } | ||
</InsertionPoint> | ||
); | ||
} |
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,14 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { Popover } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InsertionPoint from './insertion-point'; | ||
import BlockPopover from './block-popover'; | ||
import { store as blockEditorStore } from '../../store'; | ||
import BlockContextualToolbar from './block-contextual-toolbar'; | ||
|
||
/** | ||
* Renders block tools (the block toolbar, select/navigation mode toolbar, the | ||
* insertion point and a slot for the inline rich text toolbar). Must be wrapped | ||
* around the block content and editor styles wrapper or iframe. | ||
* | ||
* @param {Object} $0 Props. | ||
* @param {Object} $0.children The block content and style container. | ||
*/ | ||
export default function BlockTools( { children } ) { | ||
const isLargeViewport = useViewportMatch( 'medium' ); | ||
const hasFixedToolbar = useSelect( | ||
( select ) => select( blockEditorStore ).getSettings().hasFixedToolbar, | ||
[] | ||
); | ||
|
||
return ( | ||
<InsertionPoint> | ||
{ ( hasFixedToolbar || ! isLargeViewport ) && ( | ||
<BlockContextualToolbar isFixed /> | ||
) } | ||
{ /* Even if the toolbar is fixed, the block popover is still | ||
needed for navigation mode. */ } | ||
<BlockPopover /> | ||
{ /* Used for the inline rich text toolbar. */ } | ||
<Popover.Slot name="block-toolbar" /> | ||
{ children } | ||
{ /* Forward compatibility: a place to render block tools behind the | ||
content so it can be tabbed to properly. */ } | ||
</InsertionPoint> | ||
); | ||
} |
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.
This is marked for removal for WP 6.3. Is it time to remove this API or else consider updating the version.