import * as React from 'react'; import { BubbleType, Actions, BubbleOptions } from './types'; interface Props { actions: Actions; element: string; id: string[]; name: string; value: string; } export default class Attribute extends React.Component { private ref: React.RefObject; public constructor(props: Props) { super(props); this.ref = React.createRef(); this.onClickName = this.onClickName.bind(this); this.onClickValue = this.onClickValue.bind(this); } public render(): React.ReactNode { const { name, value } = this.props; return ( { name } = " { value } " ); } private onClickName(event: React.MouseEvent): void { const { actions, element, id, name, value } = this.props; const bubbleOptions: Partial = { attribute: name, element, id, show: true, type: BubbleType.MENU, value, }; if (this.ref.current) { const rect = this.ref.current.getBoundingClientRect(); bubbleOptions.left = rect.left; bubbleOptions.top = rect.top; } actions.showBubble(bubbleOptions); event.stopPropagation(); } private onClickValue(event: React.MouseEvent): void { const { actions, element, id, name, value } = this.props; const bubbleOptions: Partial = { attribute: name, element, id, show: true, type: BubbleType.ASKER, value, }; if (this.ref.current) { const rect = this.ref.current.getBoundingClientRect(); bubbleOptions.left = rect.left; bubbleOptions.top = rect.top; } actions.showBubble(bubbleOptions); event.stopPropagation(); } }