Summary: _typescript_

Reviewed By: priteshrnandgaonkar

Differential Revision: D16828816

fbshipit-source-id: e90852fcebd02416c3d5cfd8011bb96d2ea0d672
This commit is contained in:
Daniel Büchele
2019-08-20 03:18:32 -07:00
committed by Facebook Github Bot
parent f8e357d2c1
commit aee3ab86cf
3 changed files with 22 additions and 22 deletions

View File

@@ -5,10 +5,10 @@
* @format * @format
*/ */
import {PureComponent} from 'react'; import React, {PureComponent} from 'react';
import FlexColumn from './FlexColumn.js'; import FlexColumn from './FlexColumn.js';
import styled from '../styled/index.js'; import styled from 'react-emotion';
import {colors} from './colors.tsx'; import {colors} from './colors';
const Anchor = styled('img')({ const Anchor = styled('img')({
zIndex: 6, zIndex: 6,
@@ -18,7 +18,12 @@ const Anchor = styled('img')({
transform: 'translate(-50%, calc(100% + 2px))', 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, backgroundColor: colors.white,
borderRadius: 7, borderRadius: 7,
border: '1px solid rgba(0,0,0,0.3)', border: '1px solid rgba(0,0,0,0.3)',
@@ -48,14 +53,14 @@ const PopoverContainer = styled(FlexColumn)(props => ({
}, },
})); }));
type Props = {| type Props = {
children: React.Node, children: React.ReactNode;
onDismiss: Function, onDismiss: Function;
forceOpts?: Object, forceOpts?: Opts;
|}; };
export default class Popover extends PureComponent<Props> { export default class Popover extends PureComponent<Props> {
_ref: ?Element; _ref: Element | undefined;
componentDidMount() { componentDidMount() {
window.document.addEventListener('click', this.handleClick); window.document.addEventListener('click', this.handleClick);
@@ -67,30 +72,25 @@ export default class Popover extends PureComponent<Props> {
window.document.addEventListener('keydown', this.handleKeydown); window.document.addEventListener('keydown', this.handleKeydown);
} }
handleClick = (e: SyntheticMouseEvent<>) => { handleClick = (e: KeyboardEvent) => {
// $FlowFixMe if (this._ref && !this._ref.contains(e.target as Node)) {
if (this._ref && !this._ref.contains(e.target)) {
this.props.onDismiss(); this.props.onDismiss();
} }
}; };
handleKeydown = (e: SyntheticKeyboardEvent<>) => { handleKeydown = (e: KeyboardEvent) => {
if (e.key === 'Escape') { if (e.key === 'Escape') {
this.props.onDismiss(); this.props.onDismiss();
} }
}; };
_setRef = (ref: ?Element) => { _setRef = (ref: Element | undefined) => {
this._ref = ref; this._ref = ref;
}; };
render() { render() {
return [ return [
<Anchor <Anchor src="./anchor.svg" key="anchor" />,
src="./anchor.svg"
key="anchor"
opts={this.props.forceOpts || {}}
/>,
<PopoverContainer <PopoverContainer
innerRef={this._setRef} innerRef={this._setRef}
key="popup" key="popup"

View File

@@ -10,7 +10,7 @@ import {PureComponent} from 'react';
import styled from '../../styled/index.js'; import styled from '../../styled/index.js';
import {SketchPicker} from 'react-color'; import {SketchPicker} from 'react-color';
import {Component, Fragment} from 'react'; import {Component, Fragment} from 'react';
import Popover from '../Popover.js'; import Popover from '../Popover.tsx';
import {colors} from '../colors.tsx'; import {colors} from '../colors.tsx';
import Input from '../Input.js'; import Input from '../Input.js';

View File

@@ -24,7 +24,7 @@ export {default as Glyph} from './components/Glyph.js';
export {default as LoadingIndicator} from './components/LoadingIndicator.js'; export {default as LoadingIndicator} from './components/LoadingIndicator.js';
// //
export {default as Popover} from './components/Popover.js'; export {default as Popover} from './components/Popover.tsx';
// tables // tables
export type { export type {