File size: 1,408 Bytes
1e92f2d |
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 |
import { ScreenReaderText, Gridicon } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { reject } from 'lodash';
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { connect } from 'react-redux';
import { selectMediaItems } from 'calypso/state/media/actions';
import getMediaLibrarySelectedItems from 'calypso/state/selectors/get-media-library-selected-items';
/* eslint-disable wpcalypso/jsx-classname-namespace */
class RemoveButton extends PureComponent {
static propTypes = {
siteId: PropTypes.number,
itemId: PropTypes.number,
};
remove = () => {
const { siteId, itemId, selectedItems } = this.props;
if ( ! siteId || ! itemId ) {
return;
}
const items = reject( selectedItems, ( item ) => item.ID === itemId );
this.props.selectMediaItems( siteId, items );
};
render() {
const { translate } = this.props;
return (
<button
onClick={ this.remove }
onMouseDown={ ( event ) => event.stopPropagation() }
className="editor-media-modal-gallery__remove"
>
<ScreenReaderText>{ translate( 'Remove' ) }</ScreenReaderText>
<Gridicon icon="cross" />
</button>
);
}
}
RemoveButton.displayName = 'RemoveButton';
export default connect(
( state, { siteId } ) => ( {
selectedItems: getMediaLibrarySelectedItems( state, siteId ),
} ),
{ selectMediaItems }
)( localize( RemoveButton ) );
|