@wordpress/components 29.5.1 → 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 +7 -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-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-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/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/tsconfig.tsbuildinfo +1 -1
|
@@ -52,7 +52,9 @@ describe( 'FontSizePicker', () => {
|
|
|
52
52
|
await render(
|
|
53
53
|
<FontSizePicker value={ value } onChange={ onChange } />
|
|
54
54
|
);
|
|
55
|
-
const input = screen.
|
|
55
|
+
const input = screen.getByRole( 'spinbutton', {
|
|
56
|
+
name: 'Font size',
|
|
57
|
+
} );
|
|
56
58
|
await user.clear( input );
|
|
57
59
|
await user.type( input, '80' );
|
|
58
60
|
expect( onChange ).toHaveBeenCalledTimes( 3 ); // Once for the clear, then once per keystroke.
|
|
@@ -79,7 +81,9 @@ describe( 'FontSizePicker', () => {
|
|
|
79
81
|
await user.click(
|
|
80
82
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
81
83
|
);
|
|
82
|
-
const input = screen.
|
|
84
|
+
const input = screen.getByRole( 'spinbutton', {
|
|
85
|
+
name: 'Font size',
|
|
86
|
+
} );
|
|
83
87
|
await user.type( input, '80' );
|
|
84
88
|
expect( onChange ).toHaveBeenCalledTimes( 2 ); // Once per keystroke.
|
|
85
89
|
expect( onChange ).toHaveBeenCalledWith( expectedValue );
|
|
@@ -129,28 +133,14 @@ describe( 'FontSizePicker', () => {
|
|
|
129
133
|
const options = screen.getAllByRole( 'option' );
|
|
130
134
|
expect( options ).toHaveLength( 7 );
|
|
131
135
|
expect( options[ 0 ] ).toHaveAccessibleName( 'Default' );
|
|
132
|
-
expect( options[ 1 ] ).toHaveAccessibleName( 'Tiny
|
|
133
|
-
expect( options[ 2 ] ).toHaveAccessibleName( 'Small
|
|
134
|
-
expect( options[ 3 ] ).toHaveAccessibleName( 'Medium
|
|
135
|
-
expect( options[ 4 ] ).toHaveAccessibleName( 'Large
|
|
136
|
-
expect( options[ 5 ] ).toHaveAccessibleName( 'Extra Large
|
|
137
|
-
expect( options[ 6 ] ).toHaveAccessibleName( 'xx-large
|
|
136
|
+
expect( options[ 1 ] ).toHaveAccessibleName( 'Tiny 8px' );
|
|
137
|
+
expect( options[ 2 ] ).toHaveAccessibleName( 'Small 12px' );
|
|
138
|
+
expect( options[ 3 ] ).toHaveAccessibleName( 'Medium 16px' );
|
|
139
|
+
expect( options[ 4 ] ).toHaveAccessibleName( 'Large 20px' );
|
|
140
|
+
expect( options[ 5 ] ).toHaveAccessibleName( 'Extra Large 30px' );
|
|
141
|
+
expect( options[ 6 ] ).toHaveAccessibleName( 'xx-large 40px' );
|
|
138
142
|
} );
|
|
139
143
|
|
|
140
|
-
test.each( [
|
|
141
|
-
{ value: undefined, expectedLabel: 'Size (px)' },
|
|
142
|
-
{ value: '8px', expectedLabel: 'Size (px)' },
|
|
143
|
-
{ value: '3px', expectedLabel: 'Size Custom' },
|
|
144
|
-
] )(
|
|
145
|
-
'displays $expectedLabel as label when value is $value',
|
|
146
|
-
async ( { value, expectedLabel } ) => {
|
|
147
|
-
await render(
|
|
148
|
-
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
149
|
-
);
|
|
150
|
-
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
|
|
154
144
|
test.each( [
|
|
155
145
|
{
|
|
156
146
|
option: 'Default',
|
|
@@ -158,7 +148,7 @@ describe( 'FontSizePicker', () => {
|
|
|
158
148
|
expectedArguments: [ undefined ],
|
|
159
149
|
},
|
|
160
150
|
{
|
|
161
|
-
option: 'Tiny
|
|
151
|
+
option: 'Tiny 8px',
|
|
162
152
|
value: undefined,
|
|
163
153
|
expectedArguments: [ '8px', fontSizes[ 0 ] ],
|
|
164
154
|
},
|
|
@@ -255,23 +245,6 @@ describe( 'FontSizePicker', () => {
|
|
|
255
245
|
}
|
|
256
246
|
);
|
|
257
247
|
|
|
258
|
-
test.each( [
|
|
259
|
-
{ value: undefined, expectedLabel: 'Size' },
|
|
260
|
-
{ value: '8px', expectedLabel: 'Size' },
|
|
261
|
-
{ value: '1em', expectedLabel: 'Size' },
|
|
262
|
-
{ value: '2rem', expectedLabel: 'Size' },
|
|
263
|
-
{ value: 'clamp(1.75rem, 3vw, 2.25rem)', expectedLabel: 'Size' },
|
|
264
|
-
{ value: '3px', expectedLabel: 'Size Custom' },
|
|
265
|
-
] )(
|
|
266
|
-
'displays $expectedLabel as label when value is $value',
|
|
267
|
-
async ( { value, expectedLabel } ) => {
|
|
268
|
-
await render(
|
|
269
|
-
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
270
|
-
);
|
|
271
|
-
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
272
|
-
}
|
|
273
|
-
);
|
|
274
|
-
|
|
275
248
|
test.each( [
|
|
276
249
|
{
|
|
277
250
|
option: 'Default',
|
|
@@ -372,20 +345,6 @@ describe( 'FontSizePicker', () => {
|
|
|
372
345
|
expect( options[ 4 ] ).toHaveAccessibleName( 'Gigantosaurus' );
|
|
373
346
|
} );
|
|
374
347
|
|
|
375
|
-
test.each( [
|
|
376
|
-
{ value: undefined, expectedLabel: 'Size' },
|
|
377
|
-
{ value: '12px', expectedLabel: 'Size Small' },
|
|
378
|
-
{ value: '40px', expectedLabel: 'Size Gigantosaurus' },
|
|
379
|
-
] )(
|
|
380
|
-
'displays $expectedLabel as label when value is $value',
|
|
381
|
-
async ( { value, expectedLabel } ) => {
|
|
382
|
-
await render(
|
|
383
|
-
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
384
|
-
);
|
|
385
|
-
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
386
|
-
}
|
|
387
|
-
);
|
|
388
|
-
|
|
389
348
|
it( 'calls onChange when a font size is selected', async () => {
|
|
390
349
|
const user = userEvent.setup();
|
|
391
350
|
const onChange = jest.fn();
|
|
@@ -439,25 +398,6 @@ describe( 'FontSizePicker', () => {
|
|
|
439
398
|
expect( options[ 3 ] ).toHaveAccessibleName( 'Extra Large' );
|
|
440
399
|
} );
|
|
441
400
|
|
|
442
|
-
test.each( [
|
|
443
|
-
{ value: undefined, expectedLabel: 'Size' },
|
|
444
|
-
{ value: '12px', expectedLabel: 'Size Small' },
|
|
445
|
-
{ value: '1em', expectedLabel: 'Size Medium' },
|
|
446
|
-
{ value: '2rem', expectedLabel: 'Size Large' },
|
|
447
|
-
{
|
|
448
|
-
value: 'clamp(1.75rem, 3vw, 2.25rem)',
|
|
449
|
-
expectedLabel: 'Size Extra Large',
|
|
450
|
-
},
|
|
451
|
-
] )(
|
|
452
|
-
'displays $expectedLabel as label when value is $value',
|
|
453
|
-
async ( { value, expectedLabel } ) => {
|
|
454
|
-
await render(
|
|
455
|
-
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
456
|
-
);
|
|
457
|
-
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
458
|
-
}
|
|
459
|
-
);
|
|
460
|
-
|
|
461
401
|
test.each( [
|
|
462
402
|
{ radio: 'Small', expectedArguments: [ '12px', fontSizes[ 0 ] ] },
|
|
463
403
|
{ radio: 'Medium', expectedArguments: [ '1em', fontSizes[ 1 ] ] },
|
|
@@ -524,14 +464,18 @@ describe( 'FontSizePicker', () => {
|
|
|
524
464
|
await render(
|
|
525
465
|
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
526
466
|
);
|
|
527
|
-
expect(
|
|
467
|
+
expect(
|
|
468
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } )
|
|
469
|
+
).toBeVisible();
|
|
528
470
|
} );
|
|
529
471
|
|
|
530
472
|
it( 'hides custom input when disableCustomFontSizes is set to `true` with a custom font size', async () => {
|
|
531
473
|
const { rerender } = await render(
|
|
532
474
|
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
533
475
|
);
|
|
534
|
-
expect(
|
|
476
|
+
expect(
|
|
477
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } )
|
|
478
|
+
).toBeVisible();
|
|
535
479
|
|
|
536
480
|
rerender(
|
|
537
481
|
<FontSizePicker
|
|
@@ -549,7 +493,9 @@ describe( 'FontSizePicker', () => {
|
|
|
549
493
|
const { rerender } = await render(
|
|
550
494
|
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
551
495
|
);
|
|
552
|
-
expect(
|
|
496
|
+
expect(
|
|
497
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } )
|
|
498
|
+
).toBeVisible();
|
|
553
499
|
|
|
554
500
|
rerender(
|
|
555
501
|
<FontSizePicker
|
|
@@ -557,7 +503,9 @@ describe( 'FontSizePicker', () => {
|
|
|
557
503
|
value={ fontSizes[ 0 ].size }
|
|
558
504
|
/>
|
|
559
505
|
);
|
|
560
|
-
expect(
|
|
506
|
+
expect(
|
|
507
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } )
|
|
508
|
+
).toBeVisible();
|
|
561
509
|
} );
|
|
562
510
|
|
|
563
511
|
it( 'allows custom values by default', async () => {
|
|
@@ -569,7 +517,10 @@ describe( 'FontSizePicker', () => {
|
|
|
569
517
|
await user.click(
|
|
570
518
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
571
519
|
);
|
|
572
|
-
await user.type(
|
|
520
|
+
await user.type(
|
|
521
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } ),
|
|
522
|
+
'80'
|
|
523
|
+
);
|
|
573
524
|
expect( onChange ).toHaveBeenCalledTimes( 2 ); // Once per keystroke.
|
|
574
525
|
expect( onChange ).toHaveBeenCalledWith( '80px' );
|
|
575
526
|
} );
|
|
@@ -585,7 +536,10 @@ describe( 'FontSizePicker', () => {
|
|
|
585
536
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
586
537
|
);
|
|
587
538
|
|
|
588
|
-
await user.type(
|
|
539
|
+
await user.type(
|
|
540
|
+
screen.getByRole( 'spinbutton', { name: 'Font size' } ),
|
|
541
|
+
'80'
|
|
542
|
+
);
|
|
589
543
|
|
|
590
544
|
await user.click(
|
|
591
545
|
screen.getByRole( 'button', { name: 'Use size preset' } )
|
|
@@ -632,7 +586,9 @@ describe( 'FontSizePicker', () => {
|
|
|
632
586
|
await user.click(
|
|
633
587
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
634
588
|
);
|
|
635
|
-
const sliderInput = screen.
|
|
589
|
+
const sliderInput = screen.getByRole( 'slider', {
|
|
590
|
+
name: 'Font size',
|
|
591
|
+
} );
|
|
636
592
|
fireEvent.change( sliderInput, {
|
|
637
593
|
target: { value: 80 },
|
|
638
594
|
} );
|
|
@@ -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
|
-
}
|