Skip to content

Commit

Permalink
Query Loop block: Convert the post content type setting to a ToggleGr…
Browse files Browse the repository at this point in the history
…oupControl if there are few items (#63375)

Co-authored-by: priethor <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
5 people authored Jul 15, 2024
1 parent 34cadb6 commit 294b98e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function AuthorControl( { value, onChange } ) {
suggestions={ authorsInfo.names }
onChange={ onAuthorChange }
__experimentalShowHowTo={ false }
__next40pxDefaultSize
/>
);
}
Expand Down
51 changes: 39 additions & 12 deletions packages/block-library/src/query/edit/inspector-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
SelectControl,
RangeControl,
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
Notice,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
Expand Down Expand Up @@ -101,6 +103,10 @@ export default function QueryInspectorControls( props ) {
const showInheritControl = isControlAllowed( allowedControls, 'inherit' );
const showPostTypeControl =
! inherit && isControlAllowed( allowedControls, 'postType' );
const postTypeControlLabel = __( 'Content type' );
const postTypeControlHelp = __(
'WordPress contains different types of content you can filter by. Posts and pages are the default types, but plugins could add more.'
);
const showColumnsControl = false;
const showOrderControl =
! inherit && isControlAllowed( allowedControls, 'order' );
Expand Down Expand Up @@ -152,22 +158,42 @@ export default function QueryInspectorControls( props ) {
}
/>
) }
{ showPostTypeControl && (
<SelectControl
__nextHasNoMarginBottom
options={ postTypesSelectOptions }
value={ postType }
label={ __( 'Post type' ) }
onChange={ onPostTypeChange }
help={ __(
'WordPress contains different types of content and they are divided into collections called “Post types”. By default there are a few different ones such as blog posts and pages, but plugins could add more.'
) }
/>
) }
{ showPostTypeControl &&
( postTypesSelectOptions.length > 2 ? (
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
options={ postTypesSelectOptions }
value={ postType }
label={ postTypeControlLabel }
onChange={ onPostTypeChange }
help={ postTypeControlHelp }
/>
) : (
<ToggleGroupControl
__nextHasNoMarginBottom
__next40pxDefaultSize
isBlock
value={ postType }
label={ postTypeControlLabel }
onChange={ onPostTypeChange }
help={ postTypeControlHelp }
>
{ postTypesSelectOptions.map( ( option ) => (
<ToggleGroupControlOption
key={ option.value }
value={ option.value }
label={ option.label }
/>
) ) }
</ToggleGroupControl>
) ) }

{ showColumnsControl && (
<>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Columns' ) }
value={ displayLayout.columns }
onChange={ ( value ) =>
Expand Down Expand Up @@ -262,6 +288,7 @@ export default function QueryInspectorControls( props ) {
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Keyword' ) }
value={ querySearch }
onChange={ setQuerySearch }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function OrderControl( { order, orderBy, onChange } ) {
return (
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Order by' ) }
value={ `${ orderBy }/${ order }` }
options={ orderOptions }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function StickyControl( { value, onChange } ) {
return (
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Sticky posts' ) }
options={ stickyOptions }
value={ value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function TaxonomyItem( { taxonomy, termIds, onChange } ) {
displayTransform={ decodeEntities }
onChange={ onTermsChange }
__experimentalShowHowTo={ false }
__next40pxDefaultSize
/>
</div>
);
Expand Down

0 comments on commit 294b98e

Please sign in to comment.