From aee3ab86cfb0b9c10e7dbdfa8beaa6abc6f33b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Tue, 20 Aug 2019 03:18:32 -0700 Subject: [PATCH] Popover Summary: _typescript_ Reviewed By: priteshrnandgaonkar Differential Revision: D16828816 fbshipit-source-id: e90852fcebd02416c3d5cfd8011bb96d2ea0d672 --- src/ui/components/{Popover.js => Popover.tsx} | 40 +++++++++---------- .../data-inspector/DataDescription.js | 2 +- src/ui/index.js | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) rename src/ui/components/{Popover.js => Popover.tsx} (75%) diff --git a/src/ui/components/Popover.js b/src/ui/components/Popover.tsx similarity index 75% rename from src/ui/components/Popover.js rename to src/ui/components/Popover.tsx index a70f61c88..f326354ca 100644 --- a/src/ui/components/Popover.js +++ b/src/ui/components/Popover.tsx @@ -5,10 +5,10 @@ * @format */ -import {PureComponent} from 'react'; +import React, {PureComponent} from 'react'; import FlexColumn from './FlexColumn.js'; -import styled from '../styled/index.js'; -import {colors} from './colors.tsx'; +import styled from 'react-emotion'; +import {colors} from './colors'; const Anchor = styled('img')({ zIndex: 6, @@ -18,7 +18,12 @@ const Anchor = styled('img')({ transform: 'translate(-50%, calc(100% + 2px))', }); -const PopoverContainer = styled(FlexColumn)(props => ({ +type Opts = { + minWidth?: number; + skewLeft?: boolean; +}; + +const PopoverContainer = styled(FlexColumn)((props: {opts?: Opts}) => ({ backgroundColor: colors.white, borderRadius: 7, border: '1px solid rgba(0,0,0,0.3)', @@ -48,14 +53,14 @@ const PopoverContainer = styled(FlexColumn)(props => ({ }, })); -type Props = {| - children: React.Node, - onDismiss: Function, - forceOpts?: Object, -|}; +type Props = { + children: React.ReactNode; + onDismiss: Function; + forceOpts?: Opts; +}; export default class Popover extends PureComponent { - _ref: ?Element; + _ref: Element | undefined; componentDidMount() { window.document.addEventListener('click', this.handleClick); @@ -67,30 +72,25 @@ export default class Popover extends PureComponent { window.document.addEventListener('keydown', this.handleKeydown); } - handleClick = (e: SyntheticMouseEvent<>) => { - // $FlowFixMe - if (this._ref && !this._ref.contains(e.target)) { + handleClick = (e: KeyboardEvent) => { + if (this._ref && !this._ref.contains(e.target as Node)) { this.props.onDismiss(); } }; - handleKeydown = (e: SyntheticKeyboardEvent<>) => { + handleKeydown = (e: KeyboardEvent) => { if (e.key === 'Escape') { this.props.onDismiss(); } }; - _setRef = (ref: ?Element) => { + _setRef = (ref: Element | undefined) => { this._ref = ref; }; render() { return [ - , + ,