-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Move Posts Per Page, Offset, and Pages controls from the block toolbar into Inspector Controls #58207
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
Move Posts Per Page, Offset, and Pages controls from the block toolbar into Inspector Controls #58207
Changes from 8 commits
b9daa7b
b75431f
9395aca
728d3ed
5b36598
402acb3
b1eaf83
44c61da
fe9857e
d6b5f8a
f5b43e2
02c4579
1dd54df
af64535
7b6e79c
49ff394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __experimentalNumberControl as NumberControl } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| export const OffsetControl = ( { offset = 0, onChange } ) => { | ||
| return ( | ||
| <NumberControl | ||
| label={ __( 'Offset' ) } | ||
| value={ offset } | ||
| min={ 0 } | ||
| onChange={ ( newOffset ) => { | ||
| onChange( { offset: newOffset } ); | ||
| } } | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default OffsetControl; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __experimentalNumberControl as NumberControl } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| export const PagesControl = ( { pages, onChange } ) => { | ||
| return ( | ||
| <NumberControl | ||
| label={ __( 'Max Pages to Show' ) } | ||
| value={ pages } | ||
| min={ 0 } | ||
| onChange={ ( newPages ) => { | ||
| onChange( { pages: newPages } ); | ||
| } } | ||
| help={ __( | ||
| 'Limit the pages you want to show, even if the query has more results. To show all pages use 0 (zero).' | ||
| ) } | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default PagesControl; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { RangeControl } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| const MIN_POSTS_PER_PAGE = 1; | ||
| const MAX_POSTS_PER_PAGE = 100; | ||
|
|
||
| const PerPageControl = ( { perPage, offset = 0, onChange } ) => { | ||
| return ( | ||
| <RangeControl | ||
| label={ __( 'Posts Per Page' ) } | ||
| min={ MIN_POSTS_PER_PAGE } | ||
| max={ MAX_POSTS_PER_PAGE } | ||
| onChange={ ( newPerPage ) => { | ||
| onChange( { perPage: newPerPage, offset } ); | ||
| } } | ||
| value={ parseInt( perPage, 10 ) } | ||
|
Member
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. I think the
Contributor
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.
Yes, I noticed in the current implementation on trunk these values do have checks for More work for next week 🍹
Contributor
Author
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. I've added these back now. |
||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default PerPageControl; | ||
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.
Nit (non-blocking): There is probably no need to create wrappers for simple components like -
PerPageControl,OffsetControlandPagesControl.This is mostly my personal preference. Feel free to ignore it :)
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 went with wrappers to reduce the size of the
index.jsfor this section. I guess its number of files vs lines of code. I'm happy either way, but if these components get more complicated, it would be nice to abstract that out of the main file.