import { COLORS, Dropdown, DropdownItemButton, DropdownSeparator, MeatballMenu, MeatballMenuApi, Tag as TagComponent, LocationLink, LocationDescriptor, HumanTitle } from "@heydovetail/ui-components"; import * as React from "react"; import { styled } from "typestyle-react"; import { Tag } from "../HighlightWidgetPlugin"; import { HighlightRange } from "../../range/types"; interface Props { highlight: HighlightRange; tag: Tag; generateTagURL: (tagId: string) => LocationDescriptor; onRemoveTag?: (options: { from: number; to: number; tagId: string }) => void; onCopyHighlightURL?: (rangeId: string) => void; onFocusRange: (rangeId: string | null) => void; tagQuickEditRenderer?: (tagId: string, menuApi: MeatballMenuApi) => React.ReactNode; } interface State { hover: boolean; open: boolean; } export class HighlightSidebarItem extends React.PureComponent { state = { hover: false, open: false }; public render() { const { highlight, tag, onRemoveTag, onCopyHighlightURL, tagQuickEditRenderer, generateTagURL, onFocusRange } = this.props; const { hover, open } = this.state; return ( { this.setState({ open }); if (open) { onFocusRange(null); } }} > {menuApi => ( {onCopyHighlightURL !== undefined ? ( onCopyHighlightURL(highlight.id)} /> ) : null} {tagQuickEditRenderer !== undefined ? ( menuApi.push(tagQuickEditRenderer(tag.id, menuApi))} /> ) : null} {onRemoveTag !== undefined ? ( <> onRemoveTag({ from: highlight.from, to: highlight.to, tagId: tag.id })} /> ) : null} )} ); } private readonly onMouseEnter = () => { this.setState({ hover: true }); this.props.onFocusRange(this.props.highlight.id); }; private readonly onMouseLeave = () => { this.setState({ hover: false }); if (!this.state.open) { this.props.onFocusRange(null); } }; } const Actions = styled("div", { color: COLORS.i60, marginLeft: "4px" }); const Container = styled("div", { display: "flex", marginBottom: 4, cursor: "pointer" });