@wordpress/components 19.9.0 → 19.10.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 +30 -0
- package/CONTRIBUTING.md +80 -7
- package/build/angle-picker-control/angle-circle.js +5 -7
- package/build/angle-picker-control/angle-circle.js.map +1 -1
- package/build/box-control/index.js +0 -21
- package/build/box-control/index.js.map +1 -1
- package/build/box-control/utils.js +1 -8
- package/build/box-control/utils.js.map +1 -1
- package/build/button/index.js +3 -5
- package/build/button/index.js.map +1 -1
- package/build/circular-option-picker/index.js +1 -2
- package/build/circular-option-picker/index.js.map +1 -1
- package/build/disabled/index.js +4 -76
- package/build/disabled/index.js.map +1 -1
- package/build/input-control/index.js +3 -2
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/styles/input-control-styles.js +42 -30
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/build/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
- package/build/popover/index.js +6 -52
- package/build/popover/index.js.map +1 -1
- package/build/select-control/index.js +31 -4
- package/build/select-control/index.js.map +1 -1
- package/build/select-control/styles/select-control-styles.js +8 -8
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/text-control/index.js +35 -28
- package/build/text-control/index.js.map +1 -1
- package/build/text-control/types.js +6 -0
- package/build/text-control/types.js.map +1 -0
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js +6 -4
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build/tools-panel/tools-panel-header/component.js +52 -36
- package/build/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build/unit-control/index.js +3 -3
- package/build/unit-control/index.js.map +1 -1
- package/build/unit-control/styles/unit-control-styles.js +11 -20
- package/build/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build/unit-control/utils.js.map +1 -1
- package/build-module/angle-picker-control/angle-circle.js +5 -7
- package/build-module/angle-picker-control/angle-circle.js.map +1 -1
- package/build-module/box-control/index.js +1 -20
- package/build-module/box-control/index.js.map +1 -1
- package/build-module/box-control/utils.js +0 -6
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/button/index.js +3 -4
- package/build-module/button/index.js.map +1 -1
- package/build-module/circular-option-picker/index.js +1 -2
- package/build-module/circular-option-picker/index.js.map +1 -1
- package/build-module/disabled/index.js +5 -76
- package/build-module/disabled/index.js.map +1 -1
- package/build-module/input-control/index.js +3 -2
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/styles/input-control-styles.js +42 -30
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/build-module/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
- package/build-module/popover/index.js +6 -52
- package/build-module/popover/index.js.map +1 -1
- package/build-module/select-control/index.js +29 -3
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/select-control/styles/select-control-styles.js +8 -8
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/text-control/index.js +35 -27
- package/build-module/text-control/index.js.map +1 -1
- package/build-module/text-control/types.js +2 -0
- package/build-module/text-control/types.js.map +1 -0
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +1 -5
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js +51 -36
- package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build-module/unit-control/index.js +3 -3
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/unit-control/styles/unit-control-styles.js +11 -20
- package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build-module/unit-control/utils.js.map +1 -1
- package/build-style/style-rtl.css +7 -0
- package/build-style/style.css +7 -0
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/circular-option-picker/index.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +3 -3
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts +4 -3
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/stories/index.d.ts +5 -5
- package/build-types/input-control/stories/index.d.ts.map +1 -1
- package/build-types/input-control/styles/input-control-styles.d.ts +1 -0
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/input-control/types.d.ts +6 -0
- package/build-types/input-control/types.d.ts.map +1 -1
- package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
- package/build-types/popover/index.d.ts +0 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts +30 -26
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/stories/index.d.ts +23 -0
- package/build-types/select-control/stories/index.d.ts.map +1 -0
- package/build-types/select-control/styles/select-control-styles.d.ts +3 -4
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/select-control/test/select-control.d.ts +2 -0
- package/build-types/select-control/test/select-control.d.ts.map +1 -0
- package/build-types/select-control/types.d.ts +52 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +32 -0
- package/build-types/text-control/index.d.ts.map +1 -0
- package/build-types/text-control/stories/index.d.ts +13 -0
- package/build-types/text-control/stories/index.d.ts.map +1 -0
- package/build-types/text-control/types.d.ts +25 -0
- package/build-types/text-control/types.d.ts.map +1 -0
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +0 -1
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts +2 -2
- package/build-types/unit-control/index.d.ts.map +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
- package/build-types/unit-control/test/index.d.ts +2 -0
- package/build-types/unit-control/test/index.d.ts.map +1 -0
- package/build-types/unit-control/test/utils.d.ts +2 -0
- package/build-types/unit-control/test/utils.d.ts.map +1 -0
- package/build-types/unit-control/types.d.ts +1 -1
- package/build-types/unit-control/types.d.ts.map +1 -1
- package/build-types/unit-control/utils.d.ts +3 -3
- package/build-types/unit-control/utils.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/angle-picker-control/angle-circle.js +3 -3
- package/src/box-control/README.md +0 -74
- package/src/box-control/index.js +0 -15
- package/src/box-control/stories/index.js +0 -29
- package/src/box-control/utils.js +0 -7
- package/src/button/index.js +2 -4
- package/src/button/test/index.js +16 -1
- package/src/circular-option-picker/index.js +1 -2
- package/src/color-palette/README.md +0 -1
- package/src/color-palette/test/__snapshots__/index.js.snap +2 -3
- package/src/confirm-dialog/stories/index.js +87 -99
- package/src/date-time/stories/index.js +19 -0
- package/src/date-time/test/date.js +107 -78
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
- package/src/disabled/index.js +5 -90
- package/src/form-file-upload/test/index.js +15 -12
- package/src/input-control/README.md +1 -1
- package/src/input-control/index.tsx +3 -2
- package/src/input-control/stories/index.tsx +1 -1
- package/src/input-control/styles/input-control-styles.tsx +19 -5
- package/src/input-control/types.ts +6 -0
- package/src/menu-item/style.scss +10 -0
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +8 -1
- package/src/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/src/mobile/html-text-input/style.android.scss +1 -0
- package/src/mobile/html-text-input/style.ios.scss +1 -0
- package/src/mobile/link-settings/test/link-settings-navigation.native.js +9 -1
- package/src/popover/index.js +5 -51
- package/src/select-control/README.md +2 -2
- package/src/select-control/index.tsx +30 -29
- package/src/select-control/stories/index.tsx +90 -0
- package/src/select-control/styles/select-control-styles.ts +9 -8
- package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
- package/src/select-control/types.ts +66 -1
- package/src/text-control/index.tsx +84 -0
- package/src/text-control/stories/index.tsx +66 -0
- package/src/text-control/types.ts +29 -0
- package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +1 -5
- package/src/tools-panel/test/__snapshots__/index.js.snap +1 -1
- package/src/tools-panel/test/index.js +71 -18
- package/src/tools-panel/tools-panel-header/component.tsx +75 -33
- package/src/tools-panel/types.ts +0 -1
- package/src/tooltip/test/index.js +6 -0
- package/src/unit-control/index.tsx +2 -5
- package/src/unit-control/styles/unit-control-styles.ts +3 -13
- package/src/unit-control/test/__snapshots__/index.tsx.snap +33 -0
- package/src/unit-control/test/{index.js → index.tsx} +214 -165
- package/src/unit-control/test/{utils.js → utils.ts} +38 -19
- package/src/unit-control/types.ts +4 -1
- package/src/unit-control/utils.ts +5 -3
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/box-control/visualizer.js +0 -165
- package/build/box-control/visualizer.js.map +0 -1
- package/build-module/box-control/visualizer.js +0 -154
- package/build-module/box-control/visualizer.js.map +0 -1
- package/src/box-control/visualizer.js +0 -116
- package/src/select-control/stories/index.js +0 -104
- package/src/text-control/index.js +0 -72
- package/src/text-control/stories/index.js +0 -46
|
@@ -7,21 +7,28 @@ import {
|
|
|
7
7
|
getValidParsedQuantityAndUnit,
|
|
8
8
|
getUnitsWithCurrentUnit,
|
|
9
9
|
} from '../utils';
|
|
10
|
+
import type { WPUnitControlUnit } from '../types';
|
|
10
11
|
|
|
11
12
|
describe( 'UnitControl utils', () => {
|
|
12
13
|
describe( 'useCustomUnits', () => {
|
|
13
14
|
it( 'should return filtered css units', () => {
|
|
14
|
-
const cssUnits = [
|
|
15
|
+
const cssUnits = [
|
|
16
|
+
{ value: 'px', label: 'pixel' },
|
|
17
|
+
{ value: '%', label: 'percent' },
|
|
18
|
+
];
|
|
15
19
|
const units = useCustomUnits( {
|
|
16
20
|
availableUnits: [ 'em', 'px' ],
|
|
17
21
|
units: cssUnits,
|
|
18
22
|
} );
|
|
19
23
|
|
|
20
|
-
expect( units ).toEqual( [ { value: 'px' } ] );
|
|
24
|
+
expect( units ).toEqual( [ { value: 'px', label: 'pixel' } ] );
|
|
21
25
|
} );
|
|
22
26
|
|
|
23
27
|
it( 'should add default values to available units', () => {
|
|
24
|
-
const cssUnits = [
|
|
28
|
+
const cssUnits = [
|
|
29
|
+
{ value: 'px', label: 'pixel' },
|
|
30
|
+
{ value: '%', label: 'percent' },
|
|
31
|
+
];
|
|
25
32
|
const units = useCustomUnits( {
|
|
26
33
|
availableUnits: [ '%', 'px' ],
|
|
27
34
|
defaultValues: { '%': 10, px: 10 },
|
|
@@ -29,8 +36,8 @@ describe( 'UnitControl utils', () => {
|
|
|
29
36
|
} );
|
|
30
37
|
|
|
31
38
|
expect( units ).toEqual( [
|
|
32
|
-
{ value: 'px', default: 10 },
|
|
33
|
-
{ value: '%', default: 10 },
|
|
39
|
+
{ value: 'px', label: 'pixel', default: 10 },
|
|
40
|
+
{ value: '%', label: 'percent', default: 10 },
|
|
34
41
|
] );
|
|
35
42
|
} );
|
|
36
43
|
|
|
@@ -38,24 +45,32 @@ describe( 'UnitControl utils', () => {
|
|
|
38
45
|
// Although the public APIs of the component expect a `number` as the type of the
|
|
39
46
|
// default values, it's still good to test for strings (as it can happen in un-typed
|
|
40
47
|
// environments)
|
|
41
|
-
const cssUnits = [
|
|
48
|
+
const cssUnits = [
|
|
49
|
+
{ value: 'px', label: 'pixel' },
|
|
50
|
+
{ value: '%', label: 'percent' },
|
|
51
|
+
];
|
|
42
52
|
const units = useCustomUnits( {
|
|
43
53
|
availableUnits: [ '%', 'px' ],
|
|
44
54
|
defaultValues: {
|
|
55
|
+
// @ts-expect-error (passing a string instead of a number is the point of the test)
|
|
45
56
|
'%': '14',
|
|
57
|
+
// @ts-expect-error (passing a string instead of a number is the point of the test)
|
|
46
58
|
px: 'not a valid numeric quantity',
|
|
47
59
|
},
|
|
48
60
|
units: cssUnits,
|
|
49
61
|
} );
|
|
50
62
|
|
|
51
63
|
expect( units ).toEqual( [
|
|
52
|
-
{ value: 'px', default: undefined },
|
|
53
|
-
{ value: '%', default: 14 },
|
|
64
|
+
{ value: 'px', label: 'pixel', default: undefined },
|
|
65
|
+
{ value: '%', label: 'percent', default: 14 },
|
|
54
66
|
] );
|
|
55
67
|
} );
|
|
56
68
|
|
|
57
69
|
it( 'should return an empty array where availableUnits match no preferred css units', () => {
|
|
58
|
-
const cssUnits = [
|
|
70
|
+
const cssUnits = [
|
|
71
|
+
{ value: 'em', label: 'em' },
|
|
72
|
+
{ value: 'vh', label: 'vh' },
|
|
73
|
+
];
|
|
59
74
|
const units = useCustomUnits( {
|
|
60
75
|
availableUnits: [ '%', 'px' ],
|
|
61
76
|
defaultValues: { '%': 10, px: 10 },
|
|
@@ -69,16 +84,19 @@ describe( 'UnitControl utils', () => {
|
|
|
69
84
|
describe( 'filterUnitsWithSettings', () => {
|
|
70
85
|
it( 'should return filtered units array', () => {
|
|
71
86
|
const preferredUnits = [ '%', 'px' ];
|
|
72
|
-
const availableUnits = [
|
|
87
|
+
const availableUnits = [
|
|
88
|
+
{ value: 'px', label: 'pixel' },
|
|
89
|
+
{ value: 'em', label: 'em' },
|
|
90
|
+
];
|
|
73
91
|
|
|
74
92
|
expect(
|
|
75
93
|
filterUnitsWithSettings( preferredUnits, availableUnits )
|
|
76
|
-
).toEqual( [ { value: 'px' } ] );
|
|
94
|
+
).toEqual( [ { value: 'px', label: 'pixel' } ] );
|
|
77
95
|
} );
|
|
78
96
|
|
|
79
97
|
it( 'should return empty array where preferred units match no available css unit', () => {
|
|
80
98
|
const preferredUnits = [ '%', 'px' ];
|
|
81
|
-
const availableUnits = [ { value: 'em' } ];
|
|
99
|
+
const availableUnits = [ { value: 'em', label: 'em' } ];
|
|
82
100
|
|
|
83
101
|
expect(
|
|
84
102
|
filterUnitsWithSettings( preferredUnits, availableUnits )
|
|
@@ -92,13 +110,14 @@ describe( 'UnitControl utils', () => {
|
|
|
92
110
|
const availableUnits = false;
|
|
93
111
|
|
|
94
112
|
expect(
|
|
113
|
+
// @ts-expect-error (passing `false` instead of a valid array of units is the point of the test)
|
|
95
114
|
filterUnitsWithSettings( preferredUnits, availableUnits )
|
|
96
115
|
).toEqual( [] );
|
|
97
116
|
} );
|
|
98
117
|
|
|
99
118
|
it( 'should return empty array where available units is set to an empty array', () => {
|
|
100
119
|
const preferredUnits = [ '%', 'px' ];
|
|
101
|
-
const availableUnits = [];
|
|
120
|
+
const availableUnits: WPUnitControlUnit[] = [];
|
|
102
121
|
|
|
103
122
|
expect(
|
|
104
123
|
filterUnitsWithSettings( preferredUnits, availableUnits )
|
|
@@ -127,7 +146,7 @@ describe( 'UnitControl utils', () => {
|
|
|
127
146
|
|
|
128
147
|
it( 'should return fallback value', () => {
|
|
129
148
|
const nextValue = 'thirteen';
|
|
130
|
-
const preferredUnits = [ { value: 'em' } ];
|
|
149
|
+
const preferredUnits = [ { value: 'em', label: 'em' } ];
|
|
131
150
|
const fallbackValue = 13;
|
|
132
151
|
|
|
133
152
|
expect(
|
|
@@ -155,7 +174,7 @@ describe( 'UnitControl utils', () => {
|
|
|
155
174
|
|
|
156
175
|
it( 'should return first unit in preferred units collection as second fallback unit', () => {
|
|
157
176
|
const nextValue = 101;
|
|
158
|
-
const preferredUnits = [ { value: 'px' } ];
|
|
177
|
+
const preferredUnits = [ { value: 'px', label: 'pixel' } ];
|
|
159
178
|
|
|
160
179
|
expect(
|
|
161
180
|
getValidParsedQuantityAndUnit( nextValue, preferredUnits )
|
|
@@ -185,8 +204,8 @@ describe( 'UnitControl utils', () => {
|
|
|
185
204
|
expect( result ).toHaveLength( 3 );
|
|
186
205
|
|
|
187
206
|
const currentUnit = result.shift();
|
|
188
|
-
expect( currentUnit
|
|
189
|
-
expect( currentUnit
|
|
207
|
+
expect( currentUnit?.value ).toBe( '%' );
|
|
208
|
+
expect( currentUnit?.label ).toBe( '%' );
|
|
190
209
|
expect( result ).toEqual( limitedUnits );
|
|
191
210
|
} );
|
|
192
211
|
|
|
@@ -196,8 +215,8 @@ describe( 'UnitControl utils', () => {
|
|
|
196
215
|
expect( result ).toHaveLength( 3 );
|
|
197
216
|
|
|
198
217
|
const currentUnit = result.shift();
|
|
199
|
-
expect( currentUnit
|
|
200
|
-
expect( currentUnit
|
|
218
|
+
expect( currentUnit?.value ).toBe( '%' );
|
|
219
|
+
expect( currentUnit?.label ).toBe( '%' );
|
|
201
220
|
expect( result ).toEqual( limitedUnits );
|
|
202
221
|
} );
|
|
203
222
|
|
|
@@ -74,7 +74,10 @@ export type UnitSelectControlProps = {
|
|
|
74
74
|
|
|
75
75
|
// TODO: when available, should (partially) extend `NumberControl` props.
|
|
76
76
|
export type UnitControlProps = Omit< UnitSelectControlProps, 'unit' > &
|
|
77
|
-
Pick<
|
|
77
|
+
Pick<
|
|
78
|
+
InputControlProps,
|
|
79
|
+
'hideLabelFromVision' | '__next36pxDefaultSize'
|
|
80
|
+
> & {
|
|
78
81
|
__unstableStateReducer?: StateReducer;
|
|
79
82
|
__unstableInputWidth?: CSSProperties[ 'width' ];
|
|
80
83
|
/**
|
|
@@ -155,7 +155,9 @@ export function getParsedQuantityAndUnit(
|
|
|
155
155
|
* @param units List of units.
|
|
156
156
|
* @return Whether the list actually contains any units.
|
|
157
157
|
*/
|
|
158
|
-
export function hasUnits(
|
|
158
|
+
export function hasUnits(
|
|
159
|
+
units?: WPUnitControlUnit[]
|
|
160
|
+
): units is WPUnitControlUnit[] {
|
|
159
161
|
// Although the `isArray` check shouldn't be necessary (given the signature of
|
|
160
162
|
// this typed function), it's better to stay on the side of caution, since
|
|
161
163
|
// this function may be called from un-typed environments.
|
|
@@ -218,7 +220,7 @@ export function parseQuantityAndUnitFromRawValue(
|
|
|
218
220
|
*/
|
|
219
221
|
export function getValidParsedQuantityAndUnit(
|
|
220
222
|
rawValue: string | number,
|
|
221
|
-
allowedUnits
|
|
223
|
+
allowedUnits?: WPUnitControlUnit[],
|
|
222
224
|
fallbackQuantity?: number,
|
|
223
225
|
fallbackUnit?: string
|
|
224
226
|
): [ number | undefined, string | undefined ] {
|
|
@@ -295,7 +297,7 @@ export const useCustomUnits = ( {
|
|
|
295
297
|
}: {
|
|
296
298
|
units?: WPUnitControlUnit[];
|
|
297
299
|
availableUnits?: string[];
|
|
298
|
-
defaultValues
|
|
300
|
+
defaultValues?: Record< string, number >;
|
|
299
301
|
} ): WPUnitControlUnit[] => {
|
|
300
302
|
const customUnitsToReturn = filterUnitsWithSettings(
|
|
301
303
|
availableUnits,
|
package/tsconfig.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"gutenberg-test-env",
|
|
9
9
|
"jest",
|
|
10
10
|
"@testing-library/jest-dom",
|
|
11
|
-
"snapshot-diff"
|
|
11
|
+
"snapshot-diff"
|
|
12
12
|
],
|
|
13
13
|
// Some errors in Reakit types with TypeScript 4.3
|
|
14
14
|
// Remove the following line when they've been addressed.
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"src/spinner/**/*",
|
|
78
78
|
"src/surface/**/*",
|
|
79
79
|
"src/text/**/*",
|
|
80
|
+
"src/text-control/**/*",
|
|
80
81
|
"src/tip/**/*",
|
|
81
82
|
"src/toggle-group-control/**/*",
|
|
82
83
|
"src/tools-panel/**/*",
|