Migrate Popover from js to ts

Summary: Migrated Popover.js to Popover.tsx

Reviewed By: passy

Differential Revision: D16732630

fbshipit-source-id: a7d44c7191972cd15ecb9530f6a146e7118c2b15
This commit is contained in:
Benjamin Elo
2019-08-12 05:49:44 -07:00
committed by Facebook Github Bot
parent e4b071e867
commit afe8ba65f0

View File

@@ -6,7 +6,6 @@
*/ */
import { import {
PureComponent,
FlexColumn, FlexColumn,
FlexRow, FlexRow,
FlexBox, FlexBox,
@@ -15,6 +14,7 @@ import {
styled, styled,
colors, colors,
} from 'flipper'; } from 'flipper';
import React, {PureComponent} from 'react';
const Anchor = styled('img')({ const Anchor = styled('img')({
zIndex: 6, zIndex: 6,
@@ -126,21 +126,21 @@ const Action = styled(Button)({
}, },
}); });
type Props = {| type Props = {
sections: Array<{ sections: Array<{
title: string, title: string;
items: Array<{ items: Array<{
title: string, title: string;
subtitle: string, subtitle: string;
onClick?: Function, onClick: (() => void) | null | undefined;
icon?: React.Element<*>, icon: Element | null | undefined;
}>, }>;
}>, }>;
onDismiss: Function, onDismiss: Function;
|}; };
export default class Popover extends PureComponent<Props> { export default class Popover extends PureComponent<Props> {
_ref: ?Element; _ref: Element | null | undefined;
componentDidMount() { componentDidMount() {
window.document.addEventListener('click', this.handleClick); window.document.addEventListener('click', this.handleClick);
@@ -150,14 +150,13 @@ export default class Popover extends PureComponent<Props> {
window.document.addEventListener('click', this.handleClick); window.document.addEventListener('click', this.handleClick);
} }
handleClick = (e: SyntheticMouseEvent<>) => { handleClick = (e: MouseEvent) => {
// $FlowFixMe if (this._ref && !this._ref.contains(e.target as HTMLElement)) {
if (this._ref && !this._ref.contains(e.target)) {
this.props.onDismiss(); this.props.onDismiss();
} }
}; };
_setRef = (ref: ?Element) => { _setRef = (ref?: Element) => {
this._ref = ref; this._ref = ref;
}; };