import React from 'react'; import {connect} from 'react-redux'; import * as actions from '../../actions'; import {StickElementsWithTracking} from 'core/helpers/dom/stickElementsWithTracking'; import { ISpellcheckWarning, ISpellchecker, ISpellcheckerSuggestion, } from './interfaces'; import {reloadSpellcheckerWarnings} from '../../actions'; import {gettext} from 'core/utils'; interface IProps { warning: ISpellcheckWarning; targetElement: any; spellchecker: ISpellchecker; dispatch: any; } export class SpellcheckerContextMenuComponent extends React.Component { stickyElementTracker: any; dropdownElement: any; componentDidMount() { this.stickyElementTracker = new StickElementsWithTracking(this.props.targetElement, this.dropdownElement); } componentWillUnmount() { this.stickyElementTracker.destroy(); } onSuggestionClick(suggestion: ISpellcheckerSuggestion) { this.props.dispatch( actions.replaceWord({ word: { text: this.props.warning.text, offset: this.props.warning.startOffset, }, newWord: suggestion.text, }), ); } render() { const {suggestions, message} = this.props.warning; const {spellchecker} = this.props; // If the message exists, and suggestion is whitespace suggestion // use message as the button text instead of the suggestion const messageExists = Boolean(message); const whitespaceSuggestionExists = suggestions.filter( (suggestion) => suggestion.text.trim().length === 0).length > 0; return (
this.dropdownElement = el} style={{zIndex: 999, border: 'solid transparent', borderWidth: '6px 0'}} data-test-id="spellchecker-menu" >
); } } export const SpellcheckerContextMenu = connect()(SpellcheckerContextMenuComponent);