-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (79 loc) · 1.99 KB
/
index.js
File metadata and controls
83 lines (79 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button, Placeholder } from '@wordpress/components';
import { layout } from '@wordpress/icons';
import { Text } from '@wordpress/ui';
function BlockVariationPicker( {
icon = layout,
label = __( 'Choose variation' ),
instructions = __( 'Select a variation to start with:' ),
variations,
onSelect,
allowSkip,
} ) {
const classes = clsx( 'block-editor-block-variation-picker', {
'has-many-variations': variations.length > 4,
} );
return (
<Placeholder
icon={ icon }
label={ label }
instructions={ instructions }
className={ classes }
>
{ /*
* Disable reason: The `list` ARIA role is redundant but
* Safari+VoiceOver won't announce the list otherwise.
*/
/* eslint-disable jsx-a11y/no-redundant-roles */ }
<ul
className="block-editor-block-variation-picker__variations"
role="list"
aria-label={ __( 'Block variations' ) }
>
{ variations.map( ( variation ) => (
<li key={ variation.name }>
<Button
__next40pxDefaultSize
variant="tertiary"
icon={
variation.icon && variation.icon.src
? variation.icon.src
: variation.icon
}
iconSize={ 48 }
onClick={ () => onSelect( variation ) }
className="block-editor-block-variation-picker__variation"
label={ variation.description || variation.title }
/>
<Text
variant="body-sm"
className="block-editor-block-variation-picker__variation-label"
>
{ variation.title }
</Text>
</li>
) ) }
</ul>
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
{ allowSkip && (
<div className="block-editor-block-variation-picker__skip">
<Button
__next40pxDefaultSize
variant="link"
onClick={ () => onSelect() }
>
{ __( 'Skip' ) }
</Button>
</div>
) }
</Placeholder>
);
}
export default BlockVariationPicker;