-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stacked/unified block toolbar #31134
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Original file line | 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', | |||
} ); | |||
|
|||
return ( | |||
<InsertionPoint __unstablePopoverSlot="block-toolbar"> | |||
<BlockPopover __unstablePopoverSlot="block-toolbar" /> | |||
{ children } | |||
</InsertionPoint> | |||
); | |||
} |
Original file line number | Original file line | 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 | * Internal dependencies | ||
*/ | */ | ||
import InsertionPoint from './insertion-point'; | import InsertionPoint from './insertion-point'; | ||
import BlockPopover from './block-popover'; | 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 } ) { | export default function BlockTools( { children } ) { | ||
const isLargeViewport = useViewportMatch( 'medium' ); | |||
const hasFixedToolbar = useSelect( | |||
( select ) => select( blockEditorStore ).getSettings().hasFixedToolbar, | |||
[] | |||
); | |||
|
|||
return ( | return ( | ||
<InsertionPoint> | <InsertionPoint> | ||
{ ( hasFixedToolbar || ! isLargeViewport ) && ( | |||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an earlier iteration this component was just implementing the two forms of the block toolbar, and I think it was good to include the viewport logic in that iteration. The But now this is bundled with some pretty key functionality for the block editor it seems fairly opinionated to say that someone implementing an editor should have a fixed toolbar on small viewports. I don't think it's a blocker, this PR still makes things much easier overall. And an implementer can still reimplement this component without the viewport code. But I think it does pose a question about whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have a prop on this component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No rush to do that right now, just some food for thought. 😄 |
|||
<BlockContextualToolbar isFixed /> | |||
) } | |||
{ /* Even if the toolbar is fixed, the block popover is still | |||
needed for navigation mode. */ } | |||
<BlockPopover /> | <BlockPopover /> | ||
{ /* Used for the inline rich text toolbar. */ } | |||
<Popover.Slot name="block-toolbar" /> | |||
{ children } | { children } | ||
{ /* Forward compatibility: a place to render block tools behind the | |||
content so it can be tabbed to properly. */ } | |||
</InsertionPoint> | </InsertionPoint> | ||
); | ); | ||
} | } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad I think you'll be happy to see this 😄