import { observer } from "mobx-react"; import './LinkEditor.scss'; import React = require("react"); interface LinkRelationshipSearchProps { results: string[] | undefined; display: string; //callback fn to set rel + hide dropdown upon setting handleRelationshipSearchChange: (result: string) => void; toggleSearch: () => void; } @observer export class LinkRelationshipSearch extends React.Component { handleResultClick = (e: React.MouseEvent) => { const relationship = (e.target as HTMLParagraphElement).textContent; if (relationship) { this.props.handleRelationshipSearchChange(relationship); } } handleMouseEnter = () => { this.props.toggleSearch(); } handleMouseLeave = () => { this.props.toggleSearch(); } /** * Render an empty div to increase the height of LinkEditor to accommodate 2+ results */ emptyDiv = () => { if (this.props.results && this.props.results.length > 2 && this.props.display === "block") { return
; } } render() { return (
{ // return a dropdown of relationship results if there exist results this.props.results ? this.props.results.map(result => { return

{result}

; }) :

No matching relationships

}
{/*Render an empty div to increase the height of LinkEditor to accommodate 2+ results */} {this.emptyDiv()}
); } }