Minor sidebar improvements

Summary:
~~Two~~ Four small improvements in the sidebar, that give a cleaner look:

1. expanding the plugin section is now a small button instead of text
2. Star / unstar buttons are only shown on hover of a plugin
3. Used all caps for application names, since we are F A C E B O O K now :-P.
4. Fixed styling of loading status of apps, so that it is consistent with a fully loaded app

Reviewed By: nikoant

Differential Revision: D19297880

fbshipit-source-id: 0fee44511965fc22351eff589d253365c1c6f774
This commit is contained in:
Michel Weststrate
2020-01-07 06:31:33 -08:00
committed by Facebook Github Bot
parent 075b0905d3
commit f8173ea8a4
2 changed files with 66 additions and 45 deletions

View File

@@ -26,6 +26,7 @@ import {
SmallText, SmallText,
Info, Info,
HBox, HBox,
LoadingIndicator,
} from 'flipper'; } from 'flipper';
import React, { import React, {
PureComponent, PureComponent,
@@ -55,9 +56,7 @@ import {
CategoryName, CategoryName,
PluginIcon, PluginIcon,
PluginSidebarListItem, PluginSidebarListItem,
ErrorIndicator,
NoClients, NoClients,
Spinner,
NoDevices, NoDevices,
getColorByApp, getColorByApp,
} from './sidebarUtils'; } from './sidebarUtils';
@@ -80,6 +79,8 @@ const SidebarSectionButton = styled('button')<{
fontSize: level === 3 ? 11 : 14, fontSize: level === 3 ? 11 : 14,
color, color,
padding: `${level === 3 ? 0 : 8}px 10px 8px 9px`, padding: `${level === 3 ? 0 : 8}px 10px 8px 9px`,
textTransform: 'capitalize',
fontVariantCaps: level === 2 ? 'all-small-caps' : 'normal',
})); }));
const SidebarSectionBody = styled('div')<{ const SidebarSectionBody = styled('div')<{
@@ -88,8 +89,10 @@ const SidebarSectionBody = styled('div')<{
}>(({collapsed}) => ({ }>(({collapsed}) => ({
flexShrink: 0, flexShrink: 0,
overflow: 'hidden', overflow: 'hidden',
maxHeight: collapsed ? 0 : 1000, // might need increase if too many plugins... maxHeight: collapsed ? 0 : 2000, // might need increase if too many plugins...
transition: 'max-height 0.5s ease', transition: collapsed
? 'max-height 0.5s ease-out'
: 'max-height 0.5s ease-in',
})); }));
const SidebarSection: React.FC<{ const SidebarSection: React.FC<{
@@ -109,7 +112,7 @@ const SidebarSection: React.FC<{
color={color}> color={color}>
<HBox grow="left"> <HBox grow="left">
{typeof title === 'function' ? title(collapsed) : title} {typeof title === 'function' ? title(collapsed) : title}
{level < 3 && ( {level < 3 && children && (
<Glyph <Glyph
name={collapsed ? 'chevron-down' : 'chevron-up'} name={collapsed ? 'chevron-down' : 'chevron-up'}
size={12} size={12}
@@ -245,16 +248,6 @@ class MainSidebar2 extends PureComponent<Props, State> {
); );
})} })}
</SidebarSection> </SidebarSection>
{uninitializedClients.map(entry => (
<ListItem key={JSON.stringify(entry.client)}>
{entry.client.appName}
{entry.errorMessage ? (
<ErrorIndicator name={'mobile-cross'} size={16} />
) : (
<Spinner size={16} />
)}
</ListItem>
))}
{clients.length === 0 ? ( {clients.length === 0 ? (
<NoClients /> <NoClients />
) : ( ) : (
@@ -272,6 +265,22 @@ class MainSidebar2 extends PureComponent<Props, State> {
/> />
)) ))
)} )}
{uninitializedClients.map(entry => (
<SidebarSection
color={getColorByApp(entry.client.appName)}
key={JSON.stringify(entry.client)}
title={
<HBox grow="left">
{entry.client.appName}
{entry.errorMessage ? (
<Glyph name={'mobile-cross'} size={16} />
) : (
<LoadingIndicator size={16} />
)}
</HBox>
}
level={2}></SidebarSection>
))}
</SidebarSection> </SidebarSection>
); );
} }
@@ -488,22 +497,18 @@ const PluginList = memo(function PluginList({
{!allPluginsStarred && ( {!allPluginsStarred && (
<SidebarSection <SidebarSection
level={3} level={3}
color={colors.light20} color={colors.macOSTitleBarIconBlur}
defaultCollapsed={ defaultCollapsed={
favoritePlugins.length > 0 && !selectedNonFavoritePlugin favoritePlugins.length > 0 && !selectedNonFavoritePlugin
} }
title={collapsed => ( title={collapsed => (
<div> <ShowMoreButton>
{collapsed ? 'All plugins…' : 'Show less'}
<Glyph <Glyph
color={colors.light20} color={colors.macOSTitleBarIconBlur}
size={8} size={8}
name={collapsed ? 'chevron-down' : 'chevron-up'} name={collapsed ? 'chevron-down' : 'chevron-up'}
style={{
marginLeft: 4,
}}
/> />
</div> </ShowMoreButton>
)}> )}>
<PluginsByCategory <PluginsByCategory
client={client} client={client}
@@ -578,3 +583,13 @@ const PluginsByCategory = memo(function PluginsByCategory({
</> </>
); );
}); });
const ShowMoreButton = styled('div')({
border: `1px solid ${colors.macOSTitleBarIconBlur}`,
width: 16,
height: 16,
borderRadius: 16,
marginLeft: 'auto',
marginRight: 'auto',
lineHeight: '12px',
});

View File

@@ -22,7 +22,7 @@ import {
Spacer, Spacer,
Heading, Heading,
} from 'flipper'; } from 'flipper';
import React, {Component} from 'react'; import React, {useState, useCallback} from 'react';
import {StaticView} from '../../reducers/connections'; import {StaticView} from '../../reducers/connections';
import {BackgroundColorProperty} from 'csstype'; import {BackgroundColorProperty} from 'csstype';
@@ -135,7 +135,7 @@ export function centerInSidebar(component: any) {
}); });
} }
export class PluginSidebarListItem extends Component<{ export const PluginSidebarListItem: React.FC<{
onClick: () => void; onClick: () => void;
isActive: boolean; isActive: boolean;
plugin: typeof FlipperBasePlugin; plugin: typeof FlipperBasePlugin;
@@ -144,27 +144,33 @@ export class PluginSidebarListItem extends Component<{
provided?: any; provided?: any;
onFavorite?: () => void; onFavorite?: () => void;
starred?: boolean; starred?: boolean;
}> { }> = function(props) {
render() { const {isActive, plugin, onFavorite, starred} = props;
const {isActive, plugin, onFavorite, starred} = this.props; const iconColor = getColorByApp(props.app);
const iconColor = getColorByApp(this.props.app); const [hovered, setHovered] = useState(false);
return ( const onEnter = useCallback(() => setHovered(true), []);
<ListItem active={isActive} onClick={this.props.onClick}> const onLeave = useCallback(() => setHovered(false), []);
<PluginIcon
isActive={isActive} return (
name={plugin.icon || 'apps'} <ListItem
backgroundColor={iconColor} active={isActive}
color={colors.white} onClick={props.onClick}
/> onMouseEnter={onEnter}
<PluginName>{plugin.title || plugin.id}</PluginName> onMouseLeave={onLeave}>
{starred !== undefined && ( <PluginIcon
<StarButton onStar={onFavorite!} starred={starred} /> isActive={isActive}
)} name={plugin.icon || 'apps'}
</ListItem> backgroundColor={iconColor}
); color={colors.white}
} />
} <PluginName>{plugin.title || plugin.id}</PluginName>
{starred !== undefined && (hovered || isActive) && (
<StarButton onStar={onFavorite!} starred={starred} />
)}
</ListItem>
);
};
export function getColorByApp(app?: string | null): string { export function getColorByApp(app?: string | null): string {
let iconColor: string | undefined = (brandColors as any)[app!]; let iconColor: string | undefined = (brandColors as any)[app!];