@wordpress/components 29.5.0 → 29.6.0
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 +11 -0
- package/build/font-size-picker/font-size-picker-select.js +1 -8
- package/build/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build/font-size-picker/index.js +12 -34
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/styles.js +12 -19
- package/build/font-size-picker/styles.js.map +1 -1
- package/build/font-size-picker/utils.js +0 -22
- package/build/font-size-picker/utils.js.map +1 -1
- 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/font-size-picker/font-size-picker-select.js +2 -9
- package/build-module/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build-module/font-size-picker/index.js +14 -36
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/styles.js +11 -18
- package/build-module/font-size-picker/styles.js.map +1 -1
- package/build-module/font-size-picker/utils.js +0 -22
- package/build-module/font-size-picker/utils.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 +0 -2
- package/build-style/style.css +0 -2
- package/build-types/font-size-picker/font-size-picker-select.d.ts.map +1 -1
- package/build-types/font-size-picker/index.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +0 -4
- package/build-types/font-size-picker/styles.d.ts.map +1 -1
- package/build-types/font-size-picker/utils.d.ts +1 -9
- package/build-types/font-size-picker/utils.d.ts.map +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 +0 -2
- package/src/font-size-picker/font-size-picker-select.tsx +2 -12
- package/src/font-size-picker/index.tsx +18 -47
- package/src/font-size-picker/styles.ts +0 -5
- package/src/font-size-picker/test/index.tsx +36 -80
- package/src/font-size-picker/test/utils.ts +1 -37
- package/src/font-size-picker/utils.ts +1 -24
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { isSimpleCssValue
|
|
4
|
+
import { isSimpleCssValue } from '../utils';
|
|
5
5
|
|
|
6
6
|
describe( 'isSimpleCssValue', () => {
|
|
7
7
|
test.each( [
|
|
@@ -31,39 +31,3 @@ describe( 'isSimpleCssValue', () => {
|
|
|
31
31
|
expect( isSimpleCssValue( cssValue ) ).toBe( result );
|
|
32
32
|
} );
|
|
33
33
|
} );
|
|
34
|
-
|
|
35
|
-
describe( 'getCommonSizeUnit', () => {
|
|
36
|
-
it( 'returns null when fontSizes is empty', () => {
|
|
37
|
-
expect( getCommonSizeUnit( [] ) ).toBe( null );
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
it( 'returns px when all sizes are px', () => {
|
|
41
|
-
expect(
|
|
42
|
-
getCommonSizeUnit( [
|
|
43
|
-
{ slug: 'small', size: '10px' },
|
|
44
|
-
{ slug: 'medium', size: '20px' },
|
|
45
|
-
{ slug: 'large', size: '30px' },
|
|
46
|
-
] )
|
|
47
|
-
).toBe( 'px' );
|
|
48
|
-
} );
|
|
49
|
-
|
|
50
|
-
it( 'returns em when all sizes are em', () => {
|
|
51
|
-
expect(
|
|
52
|
-
getCommonSizeUnit( [
|
|
53
|
-
{ slug: 'small', size: '1em' },
|
|
54
|
-
{ slug: 'medium', size: '2em' },
|
|
55
|
-
{ slug: 'large', size: '3em' },
|
|
56
|
-
] )
|
|
57
|
-
).toBe( 'em' );
|
|
58
|
-
} );
|
|
59
|
-
|
|
60
|
-
it( 'returns null when sizes are heterogeneous', () => {
|
|
61
|
-
expect(
|
|
62
|
-
getCommonSizeUnit( [
|
|
63
|
-
{ slug: 'small', size: '10px' },
|
|
64
|
-
{ slug: 'medium', size: '2em' },
|
|
65
|
-
{ slug: 'large', size: '3rem' },
|
|
66
|
-
] )
|
|
67
|
-
).toBe( null );
|
|
68
|
-
} );
|
|
69
|
-
} );
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { FontSizePickerProps
|
|
5
|
-
import { parseQuantityAndUnitFromRawValue } from '../unit-control';
|
|
4
|
+
import type { FontSizePickerProps } from './types';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Some themes use css vars for their font sizes, so until we
|
|
@@ -18,25 +17,3 @@ export function isSimpleCssValue(
|
|
|
18
17
|
/^[\d\.]+(px|em|rem|vw|vh|%|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)?$/i;
|
|
19
18
|
return sizeRegex.test( String( value ) );
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* If all of the given font sizes have the same unit (e.g. 'px'), return that
|
|
24
|
-
* unit. Otherwise return null.
|
|
25
|
-
*
|
|
26
|
-
* @param fontSizes List of font sizes.
|
|
27
|
-
* @return The common unit, or null.
|
|
28
|
-
*/
|
|
29
|
-
export function getCommonSizeUnit( fontSizes: FontSize[] ) {
|
|
30
|
-
const [ firstFontSize, ...otherFontSizes ] = fontSizes;
|
|
31
|
-
if ( ! firstFontSize ) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
const [ , firstUnit ] = parseQuantityAndUnitFromRawValue(
|
|
35
|
-
firstFontSize.size
|
|
36
|
-
);
|
|
37
|
-
const areAllSizesSameUnit = otherFontSizes.every( ( fontSize ) => {
|
|
38
|
-
const [ , unit ] = parseQuantityAndUnitFromRawValue( fontSize.size );
|
|
39
|
-
return unit === firstUnit;
|
|
40
|
-
} );
|
|
41
|
-
return areAllSizesSameUnit ? firstUnit : null;
|
|
42
|
-
}
|
|
@@ -36,7 +36,7 @@ const QUERY_DEFAULTS = {
|
|
|
36
36
|
|
|
37
37
|
const MyQueryControls = () => {
|
|
38
38
|
const [ query, setQuery ] = useState( QUERY_DEFAULTS );
|
|
39
|
-
const { category, categories, maxItems, minItems, numberOfItems, order, orderBy
|
|
39
|
+
const { category, categories, maxItems, minItems, numberOfItems, order, orderBy } = query;
|
|
40
40
|
|
|
41
41
|
const updateQuery = ( newQuery ) => {
|
|
42
42
|
setQuery( { ...query, ...newQuery } );
|
|
@@ -213,7 +213,14 @@ The order in which to retrieve posts.
|
|
|
213
213
|
- Required: No
|
|
214
214
|
- Platform: Web
|
|
215
215
|
|
|
216
|
-
#### `orderBy`: `'date' | 'title'`
|
|
216
|
+
#### `orderBy`: `'date' | 'title' | 'menu_order'`
|
|
217
|
+
|
|
218
|
+
The meta key by which to order posts.
|
|
219
|
+
|
|
220
|
+
- Required: No
|
|
221
|
+
- Platform: Web
|
|
222
|
+
|
|
223
|
+
#### `orderByOptions`: `OrderByOption[]`
|
|
217
224
|
|
|
218
225
|
The meta key by which to order posts.
|
|
219
226
|
|
|
@@ -246,4 +253,4 @@ The selected category for the `categoriesList` prop.
|
|
|
246
253
|
Start opting into the larger default height that will become the default size in a future version.
|
|
247
254
|
|
|
248
255
|
- Required: No
|
|
249
|
-
- Default: `false`
|
|
256
|
+
- Default: `false`
|
|
@@ -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
|
*/
|