Skip to content

Commit

Permalink
Blocks: Add a delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 22, 2017
1 parent 3c05428 commit f8c9ce4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
40 changes: 40 additions & 0 deletions editor/block-right-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import { IconButton } from 'components';

/**
* Internal dependencies
*/
import './style.scss';

function BlockRightMenu( { onDelete } ) {
return (
<div className="editor-block-right-menu">
<IconButton
className="editor-block-right-menu__control"
onClick={ onDelete }
icon="trash"
label={ __( 'Delete the block' ) }
/>
</div>
);
}

export default connect(
undefined,
( dispatch, ownProps ) => ( {
onDelete() {
dispatch( {
type: 'REMOVE_BLOCKS',
uids: [ ownProps.uid ],
} );
},
} )
)( BlockRightMenu );
28 changes: 28 additions & 0 deletions editor/block-right-menu/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.editor-block-right-menu {
position: absolute;
top: 10px;
right: 0;
}

.editor-block-right-menu__control {
display: block;
padding: 0;
border: none;
outline: none;
background: none;
color: $dark-gray-300;
cursor: pointer;
width: 20px;
height: 20px;
border-radius: 50%;

&[aria-disabled="true"] {
cursor: default;
color: $light-gray-300;
pointer-events: none;
}

.dashicon {
display: block;
}
}
2 changes: 2 additions & 0 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getBlockType } from 'blocks';
* Internal dependencies
*/
import BlockMover from '../../block-mover';
import BlockRightMenu from '../../block-right-menu';
import BlockSwitcher from '../../block-switcher';
import {
focusBlock,
Expand Down Expand Up @@ -266,6 +267,7 @@ class VisualEditorBlock extends Component {
{ ...wrapperProps }
>
{ ( showUI || isHovered ) && <BlockMover uids={ [ block.uid ] } /> }
{ ( showUI || isHovered ) && <BlockRightMenu uid={ block.uid } /> }
{ showUI &&
<CSSTransitionGroup
transitionName={ { appear: 'is-appearing', appearActive: 'is-appearing-active' } }
Expand Down

0 comments on commit f8c9ce4

Please sign in to comment.