-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
block-remove-button.js
54 lines (47 loc) · 1.06 KB
/
block-remove-button.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
/**
* External dependencies
*/
import { connect } from 'react-redux';
import { flow, noop } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { IconButton, withContext } from '@wordpress/components';
import { compose } from '@wordpress/element';
/**
* Internal dependencies
*/
import { removeBlocks } from '../../store/actions';
export function BlockRemoveButton( { onRemove, onClick = noop, isLocked, small = false } ) {
if ( isLocked ) {
return null;
}
const label = __( 'Remove' );
return (
<IconButton
className="editor-block-settings-menu__control"
onClick={ flow( onRemove, onClick ) }
icon="trash"
label={ small ? label : undefined }
>
{ ! small && label }
</IconButton>
);
}
export default compose(
connect(
undefined,
( dispatch, ownProps ) => ( {
onRemove() {
dispatch( removeBlocks( ownProps.uids ) );
},
} )
),
withContext( 'editor' )( ( settings ) => {
const { templateLock } = settings;
return {
isLocked: !! templateLock,
};
} ),
)( BlockRemoveButton );