@wordpress/components 29.5.0 → 29.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/build/query-controls/index.js +18 -16
- package/build/query-controls/index.js.map +1 -1
- package/build/query-controls/index.native.js +3 -2
- package/build/query-controls/index.native.js.map +1 -1
- package/build/query-controls/types.js.map +1 -1
- package/build-module/query-controls/index.js +18 -16
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/query-controls/index.native.js +3 -2
- package/build-module/query-controls/index.native.js.map +1 -1
- package/build-module/query-controls/types.js.map +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/build-types/query-controls/index.d.ts +2 -2
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/query-controls/types.d.ts +15 -1
- package/build-types/query-controls/types.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/button/style.scss +1 -1
- package/src/query-controls/README.md +10 -3
- package/src/query-controls/index.native.js +3 -2
- package/src/query-controls/index.tsx +25 -21
- package/src/query-controls/types.ts +16 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -14,7 +14,7 @@ import CategorySelect from './category-select';
|
|
|
14
14
|
const DEFAULT_MIN_ITEMS = 1;
|
|
15
15
|
const DEFAULT_MAX_ITEMS = 100;
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const defaultOrderByOptions = [
|
|
18
18
|
{
|
|
19
19
|
label: __( 'Newest to oldest' ),
|
|
20
20
|
value: 'date/desc',
|
|
@@ -42,6 +42,7 @@ const QueryControls = memo(
|
|
|
42
42
|
numberOfItems,
|
|
43
43
|
order,
|
|
44
44
|
orderBy,
|
|
45
|
+
orderByOptions = defaultOrderByOptions,
|
|
45
46
|
maxItems = DEFAULT_MAX_ITEMS,
|
|
46
47
|
minItems = DEFAULT_MIN_ITEMS,
|
|
47
48
|
onCategoryChange,
|
|
@@ -68,7 +69,7 @@ const QueryControls = memo(
|
|
|
68
69
|
<SelectControl
|
|
69
70
|
label={ __( 'Order by' ) }
|
|
70
71
|
value={ `${ orderBy }/${ order }` }
|
|
71
|
-
options={
|
|
72
|
+
options={ orderByOptions }
|
|
72
73
|
onChange={ onChange }
|
|
73
74
|
hideCancelButton
|
|
74
75
|
/>
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
QueryControlsProps,
|
|
17
17
|
QueryControlsWithMultipleCategorySelectionProps,
|
|
18
18
|
QueryControlsWithSingleCategorySelectionProps,
|
|
19
|
+
OrderByOption,
|
|
19
20
|
} from './types';
|
|
20
21
|
|
|
21
22
|
const DEFAULT_MIN_ITEMS = 1;
|
|
@@ -34,13 +35,34 @@ function isMultipleCategorySelection(
|
|
|
34
35
|
return 'categorySuggestions' in props;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
const defaultOrderByOptions: OrderByOption[] = [
|
|
39
|
+
{
|
|
40
|
+
label: __( 'Newest to oldest' ),
|
|
41
|
+
value: 'date/desc',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: __( 'Oldest to newest' ),
|
|
45
|
+
value: 'date/asc',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
/* translators: Label for ordering posts by title in ascending order. */
|
|
49
|
+
label: __( 'A → Z' ),
|
|
50
|
+
value: 'title/asc',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
/* translators: Label for ordering posts by title in descending order. */
|
|
54
|
+
label: __( 'Z → A' ),
|
|
55
|
+
value: 'title/desc',
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
|
|
37
59
|
/**
|
|
38
60
|
* Controls to query for posts.
|
|
39
61
|
*
|
|
40
62
|
* ```jsx
|
|
41
63
|
* const MyQueryControls = () => (
|
|
42
64
|
* <QueryControls
|
|
43
|
-
* { ...{ maxItems, minItems, numberOfItems, order, orderBy } }
|
|
65
|
+
* { ...{ maxItems, minItems, numberOfItems, order, orderBy, orderByOptions } }
|
|
44
66
|
* onOrderByChange={ ( newOrderBy ) => {
|
|
45
67
|
* updateQuery( { orderBy: newOrderBy } )
|
|
46
68
|
* }
|
|
@@ -65,6 +87,7 @@ export function QueryControls( {
|
|
|
65
87
|
numberOfItems,
|
|
66
88
|
order,
|
|
67
89
|
orderBy,
|
|
90
|
+
orderByOptions = defaultOrderByOptions,
|
|
68
91
|
maxItems = DEFAULT_MAX_ITEMS,
|
|
69
92
|
minItems = DEFAULT_MIN_ITEMS,
|
|
70
93
|
onAuthorChange,
|
|
@@ -89,26 +112,7 @@ export function QueryControls( {
|
|
|
89
112
|
? undefined
|
|
90
113
|
: `${ orderBy }/${ order }`
|
|
91
114
|
}
|
|
92
|
-
options={
|
|
93
|
-
{
|
|
94
|
-
label: __( 'Newest to oldest' ),
|
|
95
|
-
value: 'date/desc',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
label: __( 'Oldest to newest' ),
|
|
99
|
-
value: 'date/asc',
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
/* translators: Label for ordering posts by title in ascending order. */
|
|
103
|
-
label: __( 'A → Z' ),
|
|
104
|
-
value: 'title/asc',
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
/* translators: Label for ordering posts by title in descending order. */
|
|
108
|
-
label: __( 'Z → A' ),
|
|
109
|
-
value: 'title/desc',
|
|
110
|
-
},
|
|
111
|
-
] }
|
|
115
|
+
options={ orderByOptions }
|
|
112
116
|
onChange={ ( value ) => {
|
|
113
117
|
if ( typeof value !== 'string' ) {
|
|
114
118
|
return;
|
|
@@ -45,7 +45,18 @@ export type AuthorSelectProps = Pick<
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
type Order = 'asc' | 'desc';
|
|
48
|
-
type OrderBy = 'date' | 'title';
|
|
48
|
+
type OrderBy = 'date' | 'title' | 'menu_order';
|
|
49
|
+
|
|
50
|
+
export type OrderByOption = {
|
|
51
|
+
/**
|
|
52
|
+
* The label to be shown to the user.
|
|
53
|
+
*/
|
|
54
|
+
label: string;
|
|
55
|
+
/**
|
|
56
|
+
* Option value passed to `onChange` when the option is selected.
|
|
57
|
+
*/
|
|
58
|
+
value: `${ OrderBy }/${ Order }`;
|
|
59
|
+
};
|
|
49
60
|
|
|
50
61
|
type BaseQueryControlsProps = {
|
|
51
62
|
/**
|
|
@@ -99,6 +110,10 @@ type BaseQueryControlsProps = {
|
|
|
99
110
|
* The meta key by which to order posts.
|
|
100
111
|
*/
|
|
101
112
|
orderBy?: OrderBy;
|
|
113
|
+
/**
|
|
114
|
+
* List of available ordering options.
|
|
115
|
+
*/
|
|
116
|
+
orderByOptions?: OrderByOption[];
|
|
102
117
|
/**
|
|
103
118
|
* The selected author ID.
|
|
104
119
|
*/
|