Skip to content

Commit

Permalink
[Mobile] Cover: Adds Clear media button in block settings (#23794)
Browse files Browse the repository at this point in the history
* Adds Clear media button in cover block settings
  • Loading branch information
antonis authored Jul 14, 2020
1 parent 53e65ab commit 0e2040f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ImageWithFocalPoint,
PanelBody,
RangeControl,
BottomSheet,
ToolbarButton,
ToolbarGroup,
Gradient,
Expand All @@ -35,7 +36,7 @@ import {
__experimentalUseGradient,
} from '@wordpress/block-editor';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { withSelect, withDispatch } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { cover as icon, replace } from '@wordpress/icons';
import { getProtocol } from '@wordpress/url';
Expand Down Expand Up @@ -75,6 +76,7 @@ const Cover = ( {
onFocus,
overlayColor,
setAttributes,
closeSettingsBottomSheet,
} ) => {
const {
backgroundType,
Expand Down Expand Up @@ -225,6 +227,20 @@ const Cover = ( {
style={ styles.rangeCellContainer }
/>
</PanelBody>

{ url ? (
<PanelBody title={ __( 'Media' ) }>
<BottomSheet.Cell
leftAlign
label={ __( 'Clear Media' ) }
labelStyle={ styles.clearMediaButton }
onPress={ () => {
setAttributes( { id: undefined, url: undefined } );
closeSettingsBottomSheet();
} }
/>
</PanelBody>
) : null }
</InspectorControls>
);

Expand Down Expand Up @@ -365,5 +381,13 @@ export default compose( [
isParentSelected: selectedBlockClientId === clientId,
};
} ),
withDispatch( ( dispatch ) => {
return {
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
},
};
} ),

withPreferredColorScheme,
] )( Cover );
4 changes: 4 additions & 0 deletions packages/block-library/src/cover/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@
width: 100%;
height: 100%;
}

.clearMediaButton {
color: $alert-red;
}

0 comments on commit 0e2040f

Please sign in to comment.