-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
60 lines (54 loc) · 1.24 KB
/
index.js
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
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { DOWN } from '@wordpress/keycodes';
import {
ToolbarButton,
Dropdown,
__experimentalAlignmentMatrixControl as AlignmentMatrixControl,
} from '@wordpress/components';
const noop = () => {};
function BlockAlignmentMatrixControl( props ) {
const {
label = __( 'Change matrix alignment' ),
onChange = noop,
value = 'center',
isDisabled,
} = props;
const icon = <AlignmentMatrixControl.Icon value={ value } />;
return (
<Dropdown
position="bottom right"
popoverProps={ { isAlternate: true } }
renderToggle={ ( { onToggle, isOpen } ) => {
const openOnArrowDown = ( event ) => {
if ( ! isOpen && event.keyCode === DOWN ) {
event.preventDefault();
onToggle();
}
};
return (
<ToolbarButton
onClick={ onToggle }
aria-haspopup="true"
aria-expanded={ isOpen }
onKeyDown={ openOnArrowDown }
label={ label }
icon={ icon }
showTooltip
disabled={ isDisabled }
/>
);
} }
renderContent={ () => (
<AlignmentMatrixControl
hasFocusBorder={ false }
onChange={ onChange }
value={ value }
/>
) }
/>
);
}
export default BlockAlignmentMatrixControl;