-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query block: move patterns modal to dropdown on block toolbar (#66993)
* Reinstate modal. * Delete unused component * showTitlesAsTooltip prop * Remove redundant style-edit route * Revert slot for navigation mode. * First attempt at moving the designs in a dropdone popover. * Tweaking widths. Ensure expansion on mobile Unlinked contributors: jarekmorawski. Co-authored-by: ramonjd <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: draganescu <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: jasmussen <[email protected]> Co-authored-by: annezazu <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: richtabor <[email protected]> Co-authored-by: fabiankaegy <[email protected]>
- Loading branch information
1 parent
8f429de
commit 1d85714
Showing
6 changed files
with
131 additions
and
75 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
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