Skip to content

Commit

Permalink
Query Pagination: Refactor settings panel to use ToolsPanel (WordPres…
Browse files Browse the repository at this point in the history
…s#67914)


Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: akasunil <sunil25393@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
  • Loading branch information
5 people authored Dec 16, 2024
1 parent 5b7926b commit 5c8cda1
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions packages/block-library/src/query-pagination/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { PanelBody } from '@wordpress/components';
import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { QueryPaginationArrowControls } from './query-pagination-arrow-controls';
import { QueryPaginationLabelControl } from './query-pagination-label-control';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const TEMPLATE = [
[ 'core/query-pagination-previous' ],
Expand Down Expand Up @@ -56,26 +60,54 @@ export default function QueryPaginationEdit( {
setAttributes( { showLabel: true } );
}
}, [ paginationArrow, setAttributes, showLabel ] );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
return (
<>
{ hasNextPreviousBlocks && (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<QueryPaginationArrowControls
value={ paginationArrow }
onChange={ ( value ) => {
setAttributes( { paginationArrow: value } );
} }
/>
{ paginationArrow !== 'none' && (
<QueryPaginationLabelControl
value={ showLabel }
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
paginationArrow: 'none',
showLabel: true,
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => paginationArrow !== 'none' }
label={ __( 'Pagination arrow' ) }
onDeselect={ () =>
setAttributes( { paginationArrow: 'none' } )
}
isShownByDefault
>
<QueryPaginationArrowControls
value={ paginationArrow }
onChange={ ( value ) => {
setAttributes( { showLabel: value } );
setAttributes( { paginationArrow: value } );
} }
/>
</ToolsPanelItem>
{ paginationArrow !== 'none' && (
<ToolsPanelItem
hasValue={ () => ! showLabel }
label={ __( 'Show text' ) }
onDeselect={ () =>
setAttributes( { showLabel: true } )
}
isShownByDefault
>
<QueryPaginationLabelControl
value={ showLabel }
onChange={ ( value ) => {
setAttributes( { showLabel: value } );
} }
/>
</ToolsPanelItem>
) }
</PanelBody>
</ToolsPanel>
</InspectorControls>
) }
<nav { ...innerBlocksProps } />
Expand Down

0 comments on commit 5c8cda1

Please sign in to comment.