// @flow import React, { Component } from 'react'; import invariant from 'invariant'; import { observable } from 'mobx'; import { observer } from 'mobx-react'; import styled from 'styled-components'; import { PortalWithState } from 'react-portal'; import Flex from 'shared/components/Flex'; import { color } from 'shared/styles/constants'; import { fadeAndScaleIn } from 'shared/styles/animations'; type Props = { label: React.Element<*>, onOpen?: () => void, onClose?: () => void, children?: React.Element<*>, style?: Object, }; @observer class DropdownMenu extends Component { props: Props; @observable top: number; @observable left: number; @observable right: number; handleOpen = (openPortal: SyntheticEvent => void) => { return (ev: SyntheticMouseEvent) => { ev.preventDefault(); ev.stopPropagation(); const currentTarget = ev.currentTarget; invariant(document.body, 'why you not here'); if (currentTarget instanceof HTMLDivElement) { const bodyRect = document.body.getBoundingClientRect(); const targetRect = currentTarget.getBoundingClientRect(); this.top = targetRect.bottom - bodyRect.top; this.right = bodyRect.width - targetRect.left - targetRect.width; openPortal(ev); } }; }; render() { return (