-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Query block: move patterns modal to dropdown on block toolbar #66993
Merged
ramonjd
merged 7 commits into
trunk
from
update/query-block-add-design-to-inspector-tools
Nov 28, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d56c06
Reinstate modal.
ramonjd 806aaf1
Delete unused component
ramonjd 0a228d6
showTitlesAsTooltip prop
ramonjd 607360a
Remove redundant style-edit route
ramonjd ae96856
Revert slot for navigation mode.
ramonjd 74a4423
First attempt at moving the designs in a dropdone popover.
ramonjd 5797f50
Tweaking widths. Ensure expansion on mobile
ramonjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,30 +1,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; | ||
import { | ||
ToolbarGroup, | ||
ToolbarButton, | ||
Dropdown, | ||
__experimentalDropdownContentWrapper as DropdownContentWrapper, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { usePatterns } from '../utils'; | ||
import PatternSelection, { useBlockPatterns } from './pattern-selection'; | ||
|
||
export default function QueryToolbar( { | ||
openPatternSelectionModal, | ||
name, | ||
clientId, | ||
} ) { | ||
const hasPatterns = !! usePatterns( clientId, name ).length; | ||
export default function QueryToolbar( { clientId, attributes } ) { | ||
const hasPatterns = useBlockPatterns( clientId, attributes ).length; | ||
if ( ! hasPatterns ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{ hasPatterns && ( | ||
<ToolbarGroup className="wp-block-template-part__block-control-group"> | ||
<ToolbarButton onClick={ openPatternSelectionModal }> | ||
{ __( 'Replace' ) } | ||
</ToolbarButton> | ||
</ToolbarGroup> | ||
) } | ||
</> | ||
<ToolbarGroup className="wp-block-template-part__block-control-group"> | ||
<DropdownContentWrapper> | ||
<Dropdown | ||
contentClassName="block-editor-block-settings-menu__popover" | ||
focusOnMount="firstElement" | ||
expandOnMobile | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<ToolbarButton | ||
aria-haspopup="true" | ||
aria-expanded={ isOpen } | ||
onClick={ onToggle } | ||
> | ||
{ __( 'Change design' ) } | ||
</ToolbarButton> | ||
) } | ||
renderContent={ () => ( | ||
<PatternSelection | ||
clientId={ clientId } | ||
attributes={ attributes } | ||
showSearch={ false } | ||
showTitlesAsTooltip | ||
/> | ||
) } | ||
/> | ||
</DropdownContentWrapper> | ||
</ToolbarGroup> | ||
); | ||
} |
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 |
---|---|---|
|
@@ -45,6 +45,12 @@ | |
} | ||
} | ||
|
||
.block-library-query-toolspanel__design { | ||
.block-library-query-pattern__selection-content { | ||
margin-top: $grid-unit-10; | ||
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. Is this an override of sorts? 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. It's to compensate for the removal of the search component in the patterns view. |
||
} | ||
} | ||
|
||
.wp-block-query__enhanced-pagination-modal { | ||
@include break-small() { | ||
max-width: $break-mobile; | ||
|
@@ -54,3 +60,27 @@ | |
.wp-block-query__enhanced-pagination-notice { | ||
margin: 0; | ||
} | ||
|
||
.block-editor-block-settings-menu__popover { | ||
&.is-expanded { | ||
overflow-y: scroll; | ||
} | ||
.block-library-query-pattern__selection-content { | ||
height: 100%; | ||
} | ||
.block-editor-block-patterns-list { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
@include break-small() { | ||
grid-template-columns: 1fr 1fr; | ||
} | ||
grid-gap: $grid-unit-15; | ||
min-width: $break-zoomed-in; | ||
@include break-small() { | ||
min-width: $break-mobile; | ||
} | ||
} | ||
.block-editor-block-patterns-list__list-item { | ||
margin-bottom: 0; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not for this PR but how much of this toolbar control can be made generic and absorbed automatically for all blocks in "block-editor"? (just asking whether that's even possible)
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.
I had a poke around and I think it could be genericized in the block-editor package.
For example the align hook displays a block control.
As far as I can tell the
hasPatterns
check the query block uses relies only on the blocks and block-editor stores. So no core data.