-
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.
Template Part: Swap block action places (#42221)
* Template Part: Swap block action places * Keep modal above dropdowns * Better name for hook file * Export useBlockDisplayTitle as experimental * Use BlockTitle and don't export title hook
- Loading branch information
Showing
7 changed files
with
134 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
.block-editor-template-part__selection-modal { | ||
z-index: z-index(".block-editor-template-part__selection-modal"); | ||
|
||
// To keep modal dimensions consistent as subsections are navigated, width | ||
// and height are used instead of max-(width/height). | ||
@include break-small() { | ||
width: calc(100% - #{ $grid-unit-20 * 2 }); | ||
height: calc(100% - #{ $header-height * 2 }); | ||
} | ||
@include break-medium() { | ||
width: $break-medium - $grid-unit-20 * 2; | ||
} | ||
@include break-large() { | ||
height: 70%; | ||
.components-modal__frame { | ||
@include break-small() { | ||
width: calc(100% - #{ $grid-unit-20 * 2 }); | ||
height: calc(100% - #{ $header-height * 2 }); | ||
} | ||
@include break-medium() { | ||
width: $break-medium - $grid-unit-20 * 2; | ||
} | ||
@include break-large() { | ||
height: 70%; | ||
} | ||
} | ||
} |
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
82 changes: 0 additions & 82 deletions
82
packages/edit-site/src/components/edit-template-part-menu-button/index.js
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
* Internal dependencies | ||
*/ | ||
import './components'; | ||
import './template-part-edit'; |
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,82 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { BlockControls } from '@wordpress/block-editor'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useLocation } from '../components/routes'; | ||
import { useLink } from '../components/routes/link'; | ||
|
||
function EditTemplatePartMenuItem( { attributes } ) { | ||
const { theme, slug } = attributes; | ||
const { params } = useLocation(); | ||
const templatePart = useSelect( | ||
( select ) => { | ||
return select( coreStore ).getEntityRecord( | ||
'postType', | ||
'wp_template_part', | ||
// Ideally this should be an official public API. | ||
`${ theme }//${ slug }` | ||
); | ||
}, | ||
[ theme, slug ] | ||
); | ||
|
||
const linkProps = useLink( | ||
{ | ||
postId: templatePart?.id, | ||
postType: templatePart?.type, | ||
}, | ||
{ | ||
fromTemplateId: params.postId, | ||
} | ||
); | ||
|
||
if ( ! templatePart ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BlockControls group="other"> | ||
<ToolbarButton | ||
{ ...linkProps } | ||
onClick={ ( event ) => { | ||
linkProps.onClick( event ); | ||
} } | ||
> | ||
{ __( 'Edit' ) } | ||
</ToolbarButton> | ||
</BlockControls> | ||
); | ||
} | ||
|
||
export const withEditBlockControls = createHigherOrderComponent( | ||
( BlockEdit ) => ( props ) => { | ||
const { attributes, name } = props; | ||
const isDisplayed = name === 'core/template-part' && attributes.slug; | ||
|
||
return ( | ||
<> | ||
<BlockEdit { ...props } /> | ||
{ isDisplayed && ( | ||
<EditTemplatePartMenuItem attributes={ attributes } /> | ||
) } | ||
</> | ||
); | ||
}, | ||
'withEditBlockControls' | ||
); | ||
|
||
addFilter( | ||
'editor.BlockEdit', | ||
'core/edit-site/template-part-edit-button', | ||
withEditBlockControls | ||
); |