import React from 'react'; import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import classNames from 'classnames'; import * as actions from '../../actions'; import {getSelectedEntityType, getSelectedEntityData} from '../links/entityUtils'; import {gettext} from 'core/utils'; export class LinkToolbarComponent extends React.Component { static propTypes: any; static defaultProps: any; constructor(props) { super(props); this.onRemove = this.onRemove.bind(this); } /** * @ngdoc method * @name LinkToolbar#onSubmit * @description Callback when delete link. */ onRemove(linkType) { const {suggestingMode, removeLinkSuggestion, removeLink} = this.props; suggestingMode ? removeLinkSuggestion() : removeLink(); } render() { const {editorState, onEdit} = this.props; const {link} = getSelectedEntityData(editorState); const isLink = getSelectedEntityType(editorState) === 'LINK'; const cx = classNames({ 'dropdown': true, 'link-toolbar': true, 'is-link': isLink, }); return (
{!isLink ?   : ( {gettext('Link controls:')} { link && link.href ? {gettext('Open')} : null } onEdit(link)}>{gettext('Edit')} {gettext('Delete')} )}
); } } LinkToolbarComponent.propTypes = { editorState: PropTypes.object, suggestingMode: PropTypes.bool, removeLink: PropTypes.func, removeLinkSuggestion: PropTypes.func, onEdit: PropTypes.func, }; const mapStateToProps = (state) => ({ editorState: state.editorState, suggestingMode: state.suggestingMode, }); const mapDispatchToProps = (dispatch) => ({ removeLink: () => dispatch(actions.removeLink()), removeLinkSuggestion: () => dispatch(actions.removeLinkSuggestion()), }); export const LinkToolbar = connect( mapStateToProps, mapDispatchToProps, )(LinkToolbarComponent);