Use ToggleSwitches for binary options

Summary:
We've had a bunch of different options that were all binary
switches with very different ways of displaying them.

This consolidates them all to use ToggleSwitches. I think it
may still make sense to move them all to a sidebar as it's
the case for the Analytics plugin, but that's for another diff.

Reviewed By: danielbuechele

Differential Revision: D14933392

fbshipit-source-id: 7ef286b61142a564a7cde6de875266ac8641704b
This commit is contained in:
Pascal Hartig
2019-04-17 10:21:35 -07:00
committed by Facebook Github Bot
parent c244946be3
commit 6db83a7675
2 changed files with 53 additions and 18 deletions

View File

@@ -19,7 +19,8 @@ import {
LoadingIndicator, LoadingIndicator,
styled, styled,
Select, Select,
Checkbox, ToggleButton,
Text,
} from 'flipper'; } from 'flipper';
import type {ImagesMap} from './ImagePool.js'; import type {ImagesMap} from './ImagePool.js';
import {clipboard} from 'electron'; import {clipboard} from 'electron';
@@ -33,6 +34,36 @@ function formatKB(bytes: number) {
return Math.floor(bytes / 1024) + 'KB'; return Math.floor(bytes / 1024) + 'KB';
} }
type ToggleProps = {|
label: string,
onClick?: (newValue: boolean) => void,
toggled: boolean,
|};
const ToolbarToggleButton = styled(ToggleButton)(_props => ({
alignSelf: 'center',
marginRight: 4,
minWidth: 30,
}));
const ToggleLabel = styled(Text)(_props => ({
whiteSpace: 'nowrap',
}));
function Toggle(props: ToggleProps) {
return (
<>
<ToolbarToggleButton
onClick={() => {
props.onClick && props.onClick(!props.toggled);
}}
toggled={props.toggled}
/>
<ToggleLabel>{props.label}</ToggleLabel>
</>
);
}
type ImagesCacheOverviewProps = { type ImagesCacheOverviewProps = {
onColdStartChange: (checked: boolean) => void, onColdStartChange: (checked: boolean) => void,
coldStartFilter: boolean, coldStartFilter: boolean,
@@ -61,12 +92,7 @@ const StyledSelect = styled(Select)(props => ({
marginLeft: 6, marginLeft: 6,
marginRight: 6, marginRight: 6,
height: '100%', height: '100%',
})); maxWidth: 164,
const StyledCheckbox = styled(Checkbox)(props => ({
marginLeft: 6,
marginRight: 6,
height: '100%',
})); }));
export default class ImagesCacheOverview extends PureComponent< export default class ImagesCacheOverview extends PureComponent<
@@ -137,23 +163,27 @@ export default class ImagesCacheOverview extends PureComponent<
<Button icon="cross-outline" onClick={this.props.onTrimMemory}> <Button icon="cross-outline" onClick={this.props.onTrimMemory}>
Trim Memory Trim Memory
</Button> </Button>
<Button onClick={this.onEnableDebugOverlayToggled}>
DebugOverlay {this.props.isDebugOverlayEnabled ? 'ON' : 'OFF'}
</Button>
<Button onClick={this.props.onRefresh}>Refresh</Button> <Button onClick={this.props.onRefresh}>Refresh</Button>
<Button onClick={this.onEnableAutoRefreshToggled}>
Auto Refresh {this.props.isAutoRefreshEnabled ? 'ON' : 'OFF'}
</Button>
<StyledSelect <StyledSelect
options={this.props.surfaceOptions} options={this.props.surfaceOptions}
selected={this.props.selectedSurface} selected={this.props.selectedSurface}
onChange={this.props.onChangeSurface} onChange={this.props.onChangeSurface}
/> />
<StyledCheckbox <Toggle
checked={this.props.coldStartFilter} onClick={this.onEnableAutoRefreshToggled}
onChange={this.props.onColdStartChange} toggled={this.props.isAutoRefreshEnabled}
label="Auto Refresh"
/>
<Toggle
onClick={this.onEnableDebugOverlayToggled}
toggled={this.props.isDebugOverlayEnabled}
label="Show Debug Overlay"
/>
<Toggle
toggled={this.props.coldStartFilter}
onClick={this.props.onColdStartChange}
label="Show Cold Start Images"
/> />
Show ColdStart Images
<Spacer /> <Spacer />
<input <input
type="range" type="range"

View File

@@ -40,6 +40,7 @@ type Props = {
* whether the button is toggled * whether the button is toggled
*/ */
toggled?: boolean, toggled?: boolean,
className?: string,
}; };
/** /**
@@ -55,7 +56,11 @@ type Props = {
export default class ToggleButton extends React.Component<Props> { export default class ToggleButton extends React.Component<Props> {
render() { render() {
return ( return (
<StyledButton toggled={this.props.toggled} onClick={this.props.onClick} /> <StyledButton
className={this.props.className}
toggled={this.props.toggled}
onClick={this.props.onClick}
/>
); );
} }
} }