-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathedit.js
69 lines (64 loc) · 1.59 KB
/
edit.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
61
62
63
64
65
66
67
68
69
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
BlockControls,
useBlockProps,
__experimentalUseInnerBlocksProps as useInnerBlocksProps,
} from '@wordpress/block-editor';
import { ToolbarGroup, ToolbarItem } from '@wordpress/components';
/**
* Internal dependencies
*/
import { name as buttonBlockName } from '../button';
import ContentJustificationDropdown from './content-justification-dropdown';
const ALLOWED_BLOCKS = [ buttonBlockName ];
const BUTTONS_TEMPLATE = [ [ 'core/button' ] ];
function ButtonsEdit( {
attributes: { contentJustification, orientation },
setAttributes,
} ) {
const blockProps = useBlockProps( {
className: classnames( {
[ `is-content-justification-${ contentJustification }` ]: contentJustification,
'is-vertical': orientation === 'vertical',
} ),
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
allowedBlocks: ALLOWED_BLOCKS,
template: BUTTONS_TEMPLATE,
orientation,
__experimentalLayout: {
type: 'default',
alignments: [],
},
templateInsertUpdatesSelection: true,
} );
return (
<>
<BlockControls>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<ContentJustificationDropdown
toggleProps={ toggleProps }
value={ contentJustification }
onChange={ ( updatedValue ) => {
setAttributes( {
contentJustification: updatedValue,
} );
} }
/>
) }
</ToolbarItem>
</ToolbarGroup>
</BlockControls>
<div { ...innerBlocksProps } />
</>
);
}
export default ButtonsEdit;