generic Sheet component
Summary: this moves the `Sheet` into its own component, so it can be reused for other places than the bug reporter. Reviewed By: passy Differential Revision: D13468275 fbshipit-source-id: 5f6d07a54dda078bd08a4c4cd31a41c61b58a76f
This commit is contained in:
committed by
Facebook Github Bot
parent
ade6eabdb0
commit
20e636865c
10
src/App.js
10
src/App.js
@@ -14,6 +14,7 @@ import MainSidebar from './chrome/MainSidebar.js';
|
|||||||
import BugReporterDialog from './chrome/BugReporterDialog.js';
|
import BugReporterDialog from './chrome/BugReporterDialog.js';
|
||||||
import ErrorBar from './chrome/ErrorBar.js';
|
import ErrorBar from './chrome/ErrorBar.js';
|
||||||
import PluginContainer from './PluginContainer.js';
|
import PluginContainer from './PluginContainer.js';
|
||||||
|
import Sheet from './chrome/Sheet.js';
|
||||||
import {ipcRenderer} from 'electron';
|
import {ipcRenderer} from 'electron';
|
||||||
|
|
||||||
import type Logger from './fb-stubs/Logger.js';
|
import type Logger from './fb-stubs/Logger.js';
|
||||||
@@ -48,7 +49,14 @@ export class App extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<FlexColumn grow={true}>
|
<FlexColumn grow={true}>
|
||||||
<TitleBar />
|
<TitleBar />
|
||||||
<BugReporterDialog bugReporter={this.props.bugReporter} />
|
<Sheet>
|
||||||
|
{onHide => (
|
||||||
|
<BugReporterDialog
|
||||||
|
bugReporter={this.props.bugReporter}
|
||||||
|
onHide={onHide}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Sheet>
|
||||||
<FlexRow grow={true}>
|
<FlexRow grow={true}>
|
||||||
{this.props.leftSidebarVisible && <MainSidebar />}
|
{this.props.leftSidebarVisible && <MainSidebar />}
|
||||||
{this.props.selectedDevice ? (
|
{this.props.selectedDevice ? (
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
|
|
||||||
import type BugReporter from '../fb-stubs/BugReporter.js';
|
import type BugReporter from '../fb-stubs/BugReporter.js';
|
||||||
import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin';
|
import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin';
|
||||||
import {toggleBugDialogVisible} from '../reducers/application.js';
|
import {Fragment, Component} from 'react';
|
||||||
import {Component} from 'react';
|
|
||||||
import {Transition} from 'react-transition-group';
|
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -18,15 +16,17 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
FlexColumn,
|
FlexColumn,
|
||||||
FlexRow,
|
FlexRow,
|
||||||
|
FlexCenter,
|
||||||
Textarea,
|
Textarea,
|
||||||
Text,
|
Text,
|
||||||
Glyph,
|
Glyph,
|
||||||
FlexCenter,
|
|
||||||
styled,
|
styled,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
|
|
||||||
const Container = styled(FlexColumn)({
|
const Container = styled(FlexColumn)({
|
||||||
padding: 10,
|
padding: 10,
|
||||||
|
width: 400,
|
||||||
|
height: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
const Icon = styled(Glyph)({
|
const Icon = styled(Glyph)({
|
||||||
@@ -53,26 +53,6 @@ const textareaStyle = {
|
|||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DialogContainer = styled('div')(({state}) => ({
|
|
||||||
transform: `translateY(${
|
|
||||||
state === 'entering' || state === 'exiting' ? '-110' : ''
|
|
||||||
}%)`,
|
|
||||||
transition: '.3s transform',
|
|
||||||
width: 400,
|
|
||||||
height: 300,
|
|
||||||
position: 'absolute',
|
|
||||||
left: '50%',
|
|
||||||
marginLeft: -200,
|
|
||||||
top: 38,
|
|
||||||
zIndex: 2,
|
|
||||||
backgroundColor: '#EFEEEF',
|
|
||||||
border: '1px solid #C6C6C6',
|
|
||||||
borderTop: 'none',
|
|
||||||
borderBottomLeftRadius: 2,
|
|
||||||
borderBottomRightRadius: 2,
|
|
||||||
boxShadow: '0 5px 13px rgba(0, 0, 0, 0.2)',
|
|
||||||
}));
|
|
||||||
|
|
||||||
const TitleInput = styled(Input)({
|
const TitleInput = styled(Input)({
|
||||||
...textareaStyle,
|
...textareaStyle,
|
||||||
height: 30,
|
height: 30,
|
||||||
@@ -112,9 +92,8 @@ type State = {|
|
|||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
bugReporter: BugReporter,
|
bugReporter: BugReporter,
|
||||||
toggleBugDialogVisible: (visible: boolean) => mixed,
|
|
||||||
activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
|
activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
|
||||||
bugDialogVisible: boolean,
|
onHide: () => mixed,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
class BugReporterDialog extends Component<Props, State> {
|
class BugReporterDialog extends Component<Props, State> {
|
||||||
@@ -129,19 +108,6 @@ class BugReporterDialog extends Component<Props, State> {
|
|||||||
titleRef: HTMLElement;
|
titleRef: HTMLElement;
|
||||||
descriptionRef: HTMLElement;
|
descriptionRef: HTMLElement;
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
document.addEventListener('keydown', this.onKeyDown);
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
|
||||||
document.removeEventListener('keydown', this.onKeyDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyDown = (e: KeyboardEvent) => {
|
|
||||||
if (this.props.bugDialogVisible && e.key === 'Escape') {
|
|
||||||
this.onCancel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onDescriptionChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
onDescriptionChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
||||||
this.setState({description: e.target.value});
|
this.setState({description: e.target.value});
|
||||||
};
|
};
|
||||||
@@ -215,7 +181,7 @@ class BugReporterDialog extends Component<Props, State> {
|
|||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
});
|
});
|
||||||
this.props.toggleBugDialogVisible(false);
|
this.props.onHide();
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -251,7 +217,7 @@ class BugReporterDialog extends Component<Props, State> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
content = (
|
content = (
|
||||||
<Container grow={true}>
|
<Fragment>
|
||||||
<Title>Report a bug...</Title>
|
<Title>Report a bug...</Title>
|
||||||
<TitleInput
|
<TitleInput
|
||||||
placeholder="Title..."
|
placeholder="Title..."
|
||||||
@@ -322,15 +288,11 @@ class BugReporterDialog extends Component<Props, State> {
|
|||||||
</Button>
|
</Button>
|
||||||
</SubmitButtonContainer>
|
</SubmitButtonContainer>
|
||||||
</Footer>
|
</Footer>
|
||||||
</Container>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <Container>{content}</Container>;
|
||||||
<Transition in={this.props.bugDialogVisible} timeout={300} unmountOnExit>
|
|
||||||
{state => <DialogContainer state={state}>{content}</DialogContainer>}
|
|
||||||
</Transition>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,13 +301,8 @@ export default connect(
|
|||||||
({
|
({
|
||||||
plugins: {devicePlugins, clientPlugins},
|
plugins: {devicePlugins, clientPlugins},
|
||||||
connections: {selectedPlugin},
|
connections: {selectedPlugin},
|
||||||
application: {bugDialogVisible},
|
|
||||||
}) => ({
|
}) => ({
|
||||||
bugDialogVisible,
|
|
||||||
activePlugin:
|
activePlugin:
|
||||||
devicePlugins.get(selectedPlugin) || clientPlugins.get(selectedPlugin),
|
devicePlugins.get(selectedPlugin) || clientPlugins.get(selectedPlugin),
|
||||||
}),
|
}),
|
||||||
{
|
|
||||||
toggleBugDialogVisible,
|
|
||||||
},
|
|
||||||
)(BugReporterDialog);
|
)(BugReporterDialog);
|
||||||
|
|||||||
79
src/chrome/Sheet.js
Normal file
79
src/chrome/Sheet.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Component} from 'react';
|
||||||
|
import {Transition} from 'react-transition-group';
|
||||||
|
import {toggleBugDialogVisible} from '../reducers/application.js';
|
||||||
|
import {connect} from 'react-redux';
|
||||||
|
import {styled} from 'flipper';
|
||||||
|
|
||||||
|
const DialogContainer = styled('div')(({state}) => ({
|
||||||
|
transform: `translateY(${
|
||||||
|
state === 'entering' || state === 'exiting' ? '-110' : ''
|
||||||
|
}%)`,
|
||||||
|
transition: '.3s transform',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '50%',
|
||||||
|
marginLeft: -200,
|
||||||
|
top: 38,
|
||||||
|
zIndex: 2,
|
||||||
|
backgroundColor: '#EFEEEF',
|
||||||
|
border: '1px solid #C6C6C6',
|
||||||
|
borderTop: 'none',
|
||||||
|
borderBottomLeftRadius: 2,
|
||||||
|
borderBottomRightRadius: 2,
|
||||||
|
boxShadow: '0 5px 13px rgba(0, 0, 0, 0.2)',
|
||||||
|
}));
|
||||||
|
|
||||||
|
type Props = {|
|
||||||
|
sheetVisible: boolean,
|
||||||
|
onHideSheet: () => mixed,
|
||||||
|
children: (onHide: () => mixed) => any,
|
||||||
|
|};
|
||||||
|
|
||||||
|
class Sheet extends Component<Props> {
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('keydown', this.onKeyDown);
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('keydown', this.onKeyDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
this.onHide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onHide = () => {
|
||||||
|
this.props.onHideSheet();
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Transition in={this.props.sheetVisible} timeout={300} unmountOnExit>
|
||||||
|
{state => (
|
||||||
|
<DialogContainer state={state}>
|
||||||
|
{this.props.children(this.onHide)}
|
||||||
|
</DialogContainer>
|
||||||
|
)}
|
||||||
|
</Transition>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* $FlowFixMe(>=0.86.0) This
|
||||||
|
* comment suppresses an error found when Flow v0.86 was
|
||||||
|
* deployed. To see the error, delete this comment and
|
||||||
|
* run Flow. */
|
||||||
|
export default connect(
|
||||||
|
({application: {bugDialogVisible}}) => ({
|
||||||
|
sheetVisible: bugDialogVisible,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
onHideSheet: () => toggleBugDialogVisible(false),
|
||||||
|
},
|
||||||
|
)(Sheet);
|
||||||
Reference in New Issue
Block a user