diff options
| author | bobzel <zzzman@gmail.com> | 2020-07-07 10:01:33 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-07 10:01:33 -0400 | 
| commit | 06ef30846b8014d6701caa86b264612ceabc27d1 (patch) | |
| tree | 69e1699c41688ffa984c3acc267f5ef2e77d62e2 /src/client/views/nodes/LinkDescriptionPopup.tsx | |
| parent | 0438137cd435c47ce334b15a4ad00cbd70d80662 (diff) | |
| parent | 915f35e6d6c0b0f7bdb18c0c2a6aa88ee5df5eed (diff) | |
Merge pull request #433 from browngraphicslab/anika_linking
Pull Request for Andy
Diffstat (limited to 'src/client/views/nodes/LinkDescriptionPopup.tsx')
| -rw-r--r-- | src/client/views/nodes/LinkDescriptionPopup.tsx | 73 | 
1 files changed, 73 insertions, 0 deletions
| diff --git a/src/client/views/nodes/LinkDescriptionPopup.tsx b/src/client/views/nodes/LinkDescriptionPopup.tsx new file mode 100644 index 000000000..3bb52d9fb --- /dev/null +++ b/src/client/views/nodes/LinkDescriptionPopup.tsx @@ -0,0 +1,73 @@ +import React = require("react"); +import { observer } from "mobx-react"; +import "./LinkDescriptionPopup.scss"; +import { observable, action } from "mobx"; +import { EditableView } from "../EditableView"; +import { LinkManager } from "../../util/LinkManager"; +import { LinkCreatedBox } from "./LinkCreatedBox"; + + +@observer +export class LinkDescriptionPopup extends React.Component<{}> { + +    @observable public static descriptionPopup: boolean = false; +    @observable public static showDescriptions: string = "ON"; +    @observable public static popupX: number = 700; +    @observable public static popupY: number = 350; +    @observable description: string = ""; +    @observable popupRef = React.createRef<HTMLDivElement>(); + +    @action +    descriptionChanged = (e: React.ChangeEvent<HTMLInputElement>) => { +        this.description = e.currentTarget.value; +    } + +    @action +    setDescription = () => { +        if (LinkManager.currentLink) { +            LinkManager.currentLink.description = this.description; +        } +        LinkDescriptionPopup.descriptionPopup = false; +    } + +    @action +    onDismiss = () => { +        LinkDescriptionPopup.descriptionPopup = false; +    } + +    @action +    onClick = (e: PointerEvent) => { +        if (this.popupRef && !!!this.popupRef.current?.contains(e.target as any)) { +            LinkDescriptionPopup.descriptionPopup = false; +            LinkCreatedBox.linkCreated = false; +        } +    } + +    @action +    componentDidMount() { +        document.addEventListener("pointerdown", this.onClick); +    } + +    componentWillUnmount() { +        document.removeEventListener("pointerdown", this.onClick); +    } + +    render() { +        return <div className="linkDescriptionPopup" ref={this.popupRef} +            style={{ +                left: LinkDescriptionPopup.popupX ? LinkDescriptionPopup.popupX : 700, +                top: LinkDescriptionPopup.popupY ? LinkDescriptionPopup.popupY : 350, +            }}> +            <input className="linkDescriptionPopup-input" +                placeholder={"(optional) enter link label..."} +                onChange={(e) => this.descriptionChanged(e)}> +            </input> +            <div className="linkDescriptionPopup-btn"> +                <div className="linkDescriptionPopup-btn-dismiss" +                    onPointerDown={this.onDismiss}> Dismiss </div> +                <div className="linkDescriptionPopup-btn-add" +                    onPointerDown={this.setDescription}> Add </div> +            </div> +        </div>; +    } +} 
\ No newline at end of file | 
