@wordpress/components 29.5.1 → 29.7.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 +21 -0
- package/build/angle-picker-control/index.js +1 -1
- package/build/angle-picker-control/index.js.map +1 -1
- package/build/autocomplete/index.js +5 -30
- package/build/autocomplete/index.js.map +1 -1
- package/build/custom-select-control-v2/styles.js +9 -9
- package/build/custom-select-control-v2/styles.js.map +1 -1
- 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/number-control/index.js +6 -4
- package/build/number-control/index.js.map +1 -1
- package/build/range-control/index.js +6 -5
- package/build/range-control/index.js.map +1 -1
- package/build/toolbar/toolbar-dropdown-menu/index.js +4 -3
- package/build/toolbar/toolbar-dropdown-menu/index.js.map +1 -1
- package/build/toolbar/toolbar-item/index.js +4 -3
- package/build/toolbar/toolbar-item/index.js.map +1 -1
- package/build/utils/get-node-text.js +30 -0
- package/build/utils/get-node-text.js.map +1 -0
- package/build/utils/math.js +18 -15
- package/build/utils/math.js.map +1 -1
- package/build-module/angle-picker-control/index.js +1 -1
- package/build-module/angle-picker-control/index.js.map +1 -1
- package/build-module/autocomplete/index.js +3 -28
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/custom-select-control-v2/styles.js +9 -9
- package/build-module/custom-select-control-v2/styles.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/number-control/index.js +7 -5
- package/build-module/number-control/index.js.map +1 -1
- package/build-module/range-control/index.js +6 -5
- package/build-module/range-control/index.js.map +1 -1
- package/build-module/toolbar/toolbar-dropdown-menu/index.js +3 -2
- package/build-module/toolbar/toolbar-dropdown-menu/index.js.map +1 -1
- package/build-module/toolbar/toolbar-item/index.js +3 -2
- package/build-module/toolbar/toolbar-item/index.js.map +1 -1
- package/build-module/utils/get-node-text.js +24 -0
- package/build-module/utils/get-node-text.js.map +1 -0
- package/build-module/utils/math.js +17 -14
- package/build-module/utils/math.js.map +1 -1
- package/build-style/style-rtl.css +1 -3
- package/build-style/style.css +1 -3
- package/build-types/angle-picker-control/index.d.ts +1 -1
- package/build-types/autocomplete/index.d.ts +2 -2
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/styles.d.ts.map +1 -1
- 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/number-control/index.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts +6 -5
- package/build-types/range-control/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-dropdown-menu/index.d.ts +2 -2
- package/build-types/toolbar/toolbar-dropdown-menu/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-item/index.d.ts +2 -2
- package/build-types/toolbar/toolbar-item/index.d.ts.map +1 -1
- package/build-types/utils/get-node-text.d.ts +3 -0
- package/build-types/utils/get-node-text.d.ts.map +1 -0
- package/build-types/utils/math.d.ts +10 -11
- package/build-types/utils/math.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/angle-picker-control/README.md +1 -1
- package/src/angle-picker-control/index.tsx +1 -1
- package/src/autocomplete/index.tsx +3 -30
- package/src/button/style.scss +0 -2
- package/src/custom-select-control-v2/styles.ts +1 -0
- 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/form-token-field/style.scss +1 -1
- package/src/number-control/index.tsx +8 -7
- package/src/number-control/test/index.tsx +15 -2
- package/src/range-control/index.tsx +6 -5
- package/src/toolbar/toolbar-dropdown-menu/index.tsx +3 -2
- package/src/toolbar/toolbar-item/index.tsx +3 -2
- package/src/utils/get-node-text.ts +24 -0
- package/src/utils/math.js +17 -22
- package/src/utils/test/get-node-text.js +37 -0
- package/src/utils/test/math.js +28 -32
- package/src/utils/theme-variables.scss +0 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -40,8 +40,21 @@ describe( 'NumberControl', () => {
|
|
|
40
40
|
} );
|
|
41
41
|
|
|
42
42
|
it( 'should render custom className', () => {
|
|
43
|
-
render( <NumberControl
|
|
44
|
-
|
|
43
|
+
const { container: withoutClassName } = render( <NumberControl /> );
|
|
44
|
+
|
|
45
|
+
const { container: withClassName } = render(
|
|
46
|
+
<NumberControl className="hello" />
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(
|
|
50
|
+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
|
51
|
+
withoutClassName.querySelector( '.components-number-control' )
|
|
52
|
+
).not.toHaveClass( 'hello' );
|
|
53
|
+
|
|
54
|
+
expect(
|
|
55
|
+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
|
56
|
+
withClassName.querySelector( '.components-number-control' )
|
|
57
|
+
).toHaveClass( 'hello' );
|
|
45
58
|
} );
|
|
46
59
|
} );
|
|
47
60
|
|
|
@@ -391,17 +391,18 @@ function UnforwardedRangeControl(
|
|
|
391
391
|
* import { useState } from '@wordpress/element';
|
|
392
392
|
*
|
|
393
393
|
* const MyRangeControl = () => {
|
|
394
|
-
* const [
|
|
394
|
+
* const [ value, setValue ] = useState();
|
|
395
395
|
* return (
|
|
396
396
|
* <RangeControl
|
|
397
397
|
* __nextHasNoMarginBottom
|
|
398
398
|
* __next40pxDefaultSize
|
|
399
399
|
* help="Please select how transparent you would like this."
|
|
400
|
-
* initialPosition={50}
|
|
400
|
+
* initialPosition={ 50 }
|
|
401
401
|
* label="Opacity"
|
|
402
|
-
* max={100}
|
|
403
|
-
* min={0}
|
|
404
|
-
*
|
|
402
|
+
* max={ 100 }
|
|
403
|
+
* min={ 0 }
|
|
404
|
+
* value={ value }
|
|
405
|
+
* onChange={ setValue }
|
|
405
406
|
* />
|
|
406
407
|
* );
|
|
407
408
|
* };
|
|
@@ -16,7 +16,7 @@ import ToolbarContext from '../toolbar-context';
|
|
|
16
16
|
import DropdownMenu from '../../dropdown-menu';
|
|
17
17
|
import type { DropdownMenuProps } from '../../dropdown-menu/types';
|
|
18
18
|
|
|
19
|
-
function
|
|
19
|
+
function UnforwardedToolbarDropdownMenu(
|
|
20
20
|
props: DropdownMenuProps,
|
|
21
21
|
ref: ForwardedRef< any >
|
|
22
22
|
) {
|
|
@@ -44,4 +44,5 @@ function ToolbarDropdownMenu(
|
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export
|
|
47
|
+
export const ToolbarDropdownMenu = forwardRef( UnforwardedToolbarDropdownMenu );
|
|
48
|
+
export default ToolbarDropdownMenu;
|
|
@@ -16,7 +16,7 @@ import warning from '@wordpress/warning';
|
|
|
16
16
|
import ToolbarContext from '../toolbar-context';
|
|
17
17
|
import type { ToolbarItemProps } from './types';
|
|
18
18
|
|
|
19
|
-
function
|
|
19
|
+
function UnforwardedToolbarItem(
|
|
20
20
|
{ children, as: Component, ...props }: ToolbarItemProps,
|
|
21
21
|
ref: ForwardedRef< any >
|
|
22
22
|
) {
|
|
@@ -57,4 +57,5 @@ function ToolbarItem(
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export
|
|
60
|
+
export const ToolbarItem = forwardRef( UnforwardedToolbarItem );
|
|
61
|
+
export default ToolbarItem;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const getNodeText = ( node: React.ReactNode ): string => {
|
|
2
|
+
if ( node === null ) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
switch ( typeof node ) {
|
|
7
|
+
case 'string':
|
|
8
|
+
case 'number':
|
|
9
|
+
return node.toString();
|
|
10
|
+
case 'object': {
|
|
11
|
+
if ( node instanceof Array ) {
|
|
12
|
+
return node.map( getNodeText ).join( '' );
|
|
13
|
+
}
|
|
14
|
+
if ( 'props' in node ) {
|
|
15
|
+
return getNodeText( node.props.children );
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
default:
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default getNodeText;
|
package/src/utils/math.js
CHANGED
|
@@ -59,9 +59,9 @@ function getPrecision( value ) {
|
|
|
59
59
|
/**
|
|
60
60
|
* Clamps a value based on a min/max range.
|
|
61
61
|
*
|
|
62
|
-
* @param {number} value The value.
|
|
63
|
-
* @param {number}
|
|
64
|
-
* @param {number}
|
|
62
|
+
* @param {number|string} value The value.
|
|
63
|
+
* @param {number} min The minimum range.
|
|
64
|
+
* @param {number} max The maximum range.
|
|
65
65
|
*
|
|
66
66
|
* @return {number} The clamped value.
|
|
67
67
|
*/
|
|
@@ -71,28 +71,23 @@ export function clamp( value, min, max ) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Rounds a value to the nearest step offset by a minimum.
|
|
75
75
|
*
|
|
76
|
-
* @param {number
|
|
77
|
-
* @param {number}
|
|
78
|
-
* @param {number}
|
|
79
|
-
* @param {number} step A multiplier for the value.
|
|
76
|
+
* @param {number|string} value The value.
|
|
77
|
+
* @param {number} min The minimum range.
|
|
78
|
+
* @param {number} step The increment for the value.
|
|
80
79
|
*
|
|
81
|
-
* @return {number} The
|
|
80
|
+
* @return {number} The value as a valid step.
|
|
82
81
|
*/
|
|
83
|
-
export function
|
|
84
|
-
value = 0,
|
|
85
|
-
min = Infinity,
|
|
86
|
-
max = Infinity,
|
|
87
|
-
step = 1
|
|
88
|
-
) {
|
|
82
|
+
export function ensureValidStep( value, min, step ) {
|
|
89
83
|
const baseValue = getNumber( value );
|
|
90
84
|
const stepValue = getNumber( step );
|
|
91
|
-
const precision = getPrecision( step );
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
const precision = Math.max( getPrecision( step ), getPrecision( min ) );
|
|
86
|
+
const realMin = Math.abs( min ) === Infinity ? 0 : min;
|
|
87
|
+
// If the step is not a factor of the minimum then the step must be
|
|
88
|
+
// offset by the minimum.
|
|
89
|
+
const tare = realMin % stepValue ? realMin : 0;
|
|
90
|
+
const rounded = Math.round( ( baseValue - tare ) / stepValue ) * stepValue;
|
|
91
|
+
const fromMin = rounded + tare;
|
|
92
|
+
return precision ? getNumber( fromMin.toFixed( precision ) ) : fromMin;
|
|
98
93
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import getNodeText from '../get-node-text';
|
|
5
|
+
|
|
6
|
+
describe( 'getNodeText', () => {
|
|
7
|
+
it( 'should return an empty string for null', () => {
|
|
8
|
+
expect( getNodeText( null ) ).toBe( '' );
|
|
9
|
+
} );
|
|
10
|
+
|
|
11
|
+
it( 'should return the string representation of a string node', () => {
|
|
12
|
+
expect( getNodeText( 'Hello' ) ).toBe( 'Hello' );
|
|
13
|
+
} );
|
|
14
|
+
|
|
15
|
+
it( 'should return the string representation of a number node', () => {
|
|
16
|
+
expect( getNodeText( 123 ) ).toBe( '123' );
|
|
17
|
+
} );
|
|
18
|
+
|
|
19
|
+
it( 'should return an empty string for a boolean node', () => {
|
|
20
|
+
expect( getNodeText( true ) ).toBe( '' );
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
it( 'should concatenate text from an array of nodes', () => {
|
|
24
|
+
expect( getNodeText( [ 'Hello', ' ', 'World' ] ) ).toBe(
|
|
25
|
+
'Hello World'
|
|
26
|
+
);
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
it( 'should return text from a React element with children', () => {
|
|
30
|
+
const element = (
|
|
31
|
+
<div>
|
|
32
|
+
Hello <span>World</span>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
expect( getNodeText( element ) ).toBe( 'Hello World' );
|
|
36
|
+
} );
|
|
37
|
+
} );
|
package/src/utils/test/math.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import { add, subtract, clamp, ensureValidStep } from '../math';
|
|
5
6
|
|
|
6
7
|
describe( 'add', () => {
|
|
7
8
|
it( 'should add string and number values', () => {
|
|
@@ -58,44 +59,39 @@ describe( 'clamp', () => {
|
|
|
58
59
|
} );
|
|
59
60
|
} );
|
|
60
61
|
|
|
61
|
-
describe( '
|
|
62
|
-
it( 'should
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
65
|
-
expect(
|
|
62
|
+
describe( 'ensureValidStep', () => {
|
|
63
|
+
it( 'should work with number or string values', () => {
|
|
64
|
+
expect( ensureValidStep( '49', 0, 10 ) ).toBe( 50 );
|
|
65
|
+
expect( ensureValidStep( 49, '0', 10 ) ).toBe( 50 );
|
|
66
|
+
expect( ensureValidStep( 49, 0, '10' ) ).toBe( 50 );
|
|
67
|
+
} );
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
expect(
|
|
69
|
-
expect(
|
|
69
|
+
it( 'should round to step', () => {
|
|
70
|
+
expect( ensureValidStep( 40, 0, 10 ) ).toBe( 40 );
|
|
71
|
+
expect( ensureValidStep( 42, 0, 10 ) ).toBe( 40 );
|
|
72
|
+
expect( ensureValidStep( 45, 0, 10 ) ).toBe( 50 );
|
|
73
|
+
expect( ensureValidStep( 49, 0, 10 ) ).toBe( 50 );
|
|
70
74
|
|
|
71
|
-
expect(
|
|
72
|
-
expect(
|
|
73
|
-
expect( roundClamp( -50, -10, '10' ) ).toBe( -10 );
|
|
75
|
+
expect( ensureValidStep( 50, 0, 15 ) ).toBe( 45 );
|
|
76
|
+
expect( ensureValidStep( 50, 0, 11 ) ).toBe( 55 );
|
|
74
77
|
} );
|
|
75
78
|
|
|
76
|
-
it( 'should
|
|
77
|
-
expect(
|
|
78
|
-
expect(
|
|
79
|
-
expect(
|
|
79
|
+
it( 'should round with float in step', () => {
|
|
80
|
+
expect( ensureValidStep( 40.5, 1, 0.1 ) ).toBe( 40.5 );
|
|
81
|
+
expect( ensureValidStep( 40.05, 1, 0.01 ) ).toBe( 40.05 );
|
|
82
|
+
expect( ensureValidStep( 40.06, 1, 0.1 ) ).toBe( 40.1 );
|
|
83
|
+
expect( ensureValidStep( 40.123005, 1, 0.001 ) ).toBe( 40.123 );
|
|
80
84
|
} );
|
|
81
85
|
|
|
82
|
-
it( 'should
|
|
83
|
-
expect(
|
|
84
|
-
expect(
|
|
85
|
-
expect(
|
|
86
|
-
expect(
|
|
87
|
-
expect( roundClamp( 50, 1, 100, 10 ) ).toBe( 50 );
|
|
88
|
-
|
|
89
|
-
expect( roundClamp( 50, 1, 100, 15 ) ).toBe( 45 );
|
|
90
|
-
expect( roundClamp( 50, 1, 100, '15' ) ).toBe( 45 );
|
|
91
|
-
expect( roundClamp( 50, 1, 100, 11 ) ).toBe( 55 );
|
|
86
|
+
it( 'should round to steps starting from min', () => {
|
|
87
|
+
expect( ensureValidStep( 10, 0.25, 1 ) ).toBe( 10.25 );
|
|
88
|
+
expect( ensureValidStep( 10, -20.25, 1 ) ).toBe( 9.75 );
|
|
89
|
+
expect( ensureValidStep( 10.5, 0.05, 0.1 ) ).toBe( 10.45 );
|
|
90
|
+
expect( ensureValidStep( 10.51, 0.05, 0.1 ) ).toBe( 10.55 );
|
|
92
91
|
} );
|
|
93
92
|
|
|
94
|
-
it( 'should
|
|
95
|
-
expect(
|
|
96
|
-
expect(
|
|
97
|
-
expect( roundClamp( 40.05, 1, 100, 0.01 ) ).toBe( 40.05 );
|
|
98
|
-
expect( roundClamp( 40.06, 1, 100, 0.1 ) ).toBe( 40.1 );
|
|
99
|
-
expect( roundClamp( 40.123005, 1, 100, 0.001 ) ).toBe( 40.123 );
|
|
93
|
+
it( 'should round with a precision that’s the greater of min and step', () => {
|
|
94
|
+
expect( ensureValidStep( 10.061, 0.01, 0.1 ) ).toBe( 10.11 );
|
|
95
|
+
expect( ensureValidStep( 10.105, 0.1, 0.01 ) ).toBe( 10.11 );
|
|
100
96
|
} );
|
|
101
97
|
} );
|
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
// `--wp-admin-theme-color`. If the `--wp-admin-theme-color` variable is not
|
|
5
5
|
// defined, fallback to the default theme color (WP blueberry).
|
|
6
6
|
$components-color-accent: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
|
|
7
|
-
|
|
8
|
-
// Define accent color transparent variants.
|
|
9
|
-
$components-color-accent-transparent-40: rgba(var(--wp-components-color-accent--rgb, var(--wp-admin-theme-color--rgb)), 0.04);
|
|
10
|
-
|
|
11
7
|
$components-color-accent-darker-10: var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6));
|
|
12
8
|
$components-color-accent-darker-20: var(--wp-components-color-accent-darker-20, var(--wp-admin-theme-color-darker-20, #183ad6));
|
|
13
9
|
|