Skip to content

Commit

Permalink
First attempt at moving the designs in a dropdone popover.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Nov 26, 2024
1 parent ae96856 commit 74a4423
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import StickyControl from './sticky-control';
import PerPageControl from './per-page-control';
import OffsetControl from './offset-controls';
import PagesControl from './pages-control';
import PatternSelection, { useBlockPatterns } from '../pattern-selection';
import { unlock } from '../../../lock-unlock';
import {
usePostTypes,
Expand All @@ -42,8 +41,7 @@ import {
import { useToolsPanelDropdownMenuProps } from '../../../utils/hooks';

export default function QueryInspectorControls( props ) {
const { attributes, setQuery, setDisplayLayout, isSingular, clientId } =
props;
const { attributes, setQuery, setDisplayLayout, isSingular } = props;
const { query, displayLayout } = attributes;
const {
order,
Expand Down Expand Up @@ -176,7 +174,6 @@ export default function QueryInspectorControls( props ) {
showParentControl ||
showFormatControl;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const hasPatterns = !! useBlockPatterns( clientId, attributes ).length;
const showPostCountControl = isControlAllowed(
allowedControls,
'postCount'
Expand All @@ -188,20 +185,6 @@ export default function QueryInspectorControls( props ) {

return (
<>
{ hasPatterns && (
<PanelBody
title={ __( 'Design' ) }
initialOpen={ false }
className="block-library-query-toolspanel__design"
>
<PatternSelection
attributes={ attributes }
clientId={ clientId }
showTitlesAsTooltip
showSearch={ false }
/>
</PanelBody>
) }
{ !! postType && (
<BlockInfo>
<CreateNewPostLink postType={ postType } />
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/query/edit/query-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
import { useEffect, useCallback } from '@wordpress/element';
import {
BlockControls,
InspectorControls,
useBlockProps,
store as blockEditorStore,
Expand All @@ -21,6 +22,7 @@ import EnhancedPaginationControl from './inspector-controls/enhanced-pagination-
import QueryInspectorControls from './inspector-controls';
import EnhancedPaginationModal from './enhanced-pagination-modal';
import { getQueryContextFromTemplate } from '../utils';
import QueryToolbar from './query-toolbar';

const DEFAULTS_POSTS_PER_PAGE = 3;

Expand Down Expand Up @@ -160,6 +162,9 @@ export default function QueryContent( {
isSingular={ isSingular }
/>
</InspectorControls>
<BlockControls>
<QueryToolbar attributes={ attributes } clientId={ clientId } />
</BlockControls>
<InspectorControls group="advanced">
<SelectControl
__nextHasNoMarginBottom
Expand Down
49 changes: 49 additions & 0 deletions packages/block-library/src/query/edit/query-toolbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* WordPress dependencies
*/
import {
ToolbarGroup,
ToolbarButton,
Dropdown,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import PatternSelection, { useBlockPatterns } from './pattern-selection';

export default function QueryToolbar( { clientId, attributes } ) {
const hasPatterns = useBlockPatterns( clientId, attributes ).length;
if ( ! hasPatterns ) {
return null;
}

return (
<ToolbarGroup className="wp-block-template-part__block-control-group">
<DropdownContentWrapper>
<Dropdown
contentClassName="block-editor-block-settings-menu__popover"
focusOnMount="firstElement"
renderToggle={ ( { isOpen, onToggle } ) => (
<ToolbarButton
aria-haspopup="true"
aria-expanded={ isOpen }
onClick={ onToggle }
>
{ __( 'Change design' ) }
</ToolbarButton>
) }
renderContent={ () => (
<PatternSelection
clientId={ clientId }
attributes={ attributes }
showSearch={ false }
/>
) }
/>
</DropdownContentWrapper>
</ToolbarGroup>
);
}
4 changes: 4 additions & 0 deletions packages/block-library/src/query/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
.wp-block-query__enhanced-pagination-notice {
margin: 0;
}

.block-editor-block-settings-menu__popover {
min-width: 500px;
}

0 comments on commit 74a4423

Please sign in to comment.