Notifications UI

Summary:
- Adding hover buttons
- showing timestamp
- adjusting colors

Reviewed By: passy, priteshrnandgaonkar

Differential Revision: D10461877

fbshipit-source-id: 1a384428ab2ce5d22a0e619055b04c1afdcbcb63
This commit is contained in:
Daniel Büchele
2018-10-19 07:22:47 -07:00
committed by Facebook Github Bot
parent d89e559dbd
commit 9a43a00a80

View File

@@ -274,9 +274,10 @@ const SEVERITY_COLOR_MAP = {
error: colors.red, error: colors.red,
}; };
const NotificationBox = styled(FlexColumn)(props => ({ const NotificationBox = styled(FlexRow)(props => ({
backgroundColor: props.inactive ? 'transparent' : colors.white, backgroundColor: props.inactive ? 'transparent' : colors.white,
opacity: props.inactive ? 0.5 : 1, opacity: props.inactive ? 0.5 : 1,
alignItems: 'flex-start',
borderRadius: 5, borderRadius: 5,
padding: 10, padding: 10,
flexShrink: 0, flexShrink: 0,
@@ -302,19 +303,54 @@ const NotificationBox = styled(FlexColumn)(props => ({
}, },
})); }));
const Title = styled(FlexRow)({ const Title = styled('div')({
minWidth: 150,
color: colors.light80,
flexShrink: 0,
marginBottom: 6,
fontWeight: 500, fontWeight: 500,
marginBottom: 5, lineHeight: 1,
alignItems: 'center',
fontSize: '1.1em', fontSize: '1.1em',
}); });
const Chevron = styled(Glyph)({ const NotificationContent = styled(FlexColumn)(props => ({
position: 'absolute', marginLeft: 6,
right: 10, marginRight: 10,
top: '50%', flexGrow: 1,
transform: 'translateY(-50%)', overflow: 'hidden',
maxHeight: props.isSelected ? 'none' : 56,
lineHeight: 1.4,
color: props.isSelected ? colors.light50 : colors.light30,
}));
const Actions = styled(FlexRow)({
alignItems: 'center',
justifyContent: 'space-between',
color: colors.light20,
marginTop: 12,
borderTop: `1px solid ${colors.light05}`,
paddingTop: 8,
});
const NotificationButton = styled('div')({
border: `1px solid ${colors.light20}`,
color: colors.light50,
borderRadius: 4,
textAlign: 'center',
padding: 4,
width: 55,
marginBottom: 4,
opacity: 0,
transition: '0.15s opacity',
'[data-role="notification"]:hover &': {
opacity: 0.5, opacity: 0.5,
},
':last-child': {
marginBottom: 0,
},
'[data-role="notification"] &:hover': {
opacity: 1,
},
}); });
type ItemProps = { type ItemProps = {
@@ -355,17 +391,6 @@ class NotificationItem extends Component<ItemProps> {
contextMenuItems; contextMenuItems;
deepLinkButton = React.createRef(); deepLinkButton = React.createRef();
onClick = (e: MouseEvent) => {
if (
this.props.notification.action &&
e.target === this.deepLinkButton.current
) {
this.openDeeplink();
} else if (this.props.onClick) {
this.props.onClick();
}
};
createPaste = () => { createPaste = () => {
createPaste(this.getContent()); createPaste(this.getContent());
}; };
@@ -400,35 +425,23 @@ class NotificationItem extends Component<ItemProps> {
return ( return (
<ContextMenu <ContextMenu
data-role="notification"
component={NotificationBox} component={NotificationBox}
severity={notification.severity} severity={notification.severity}
onClick={this.onClick} onClick={this.props.onClick}
isSelected={isSelected} isSelected={isSelected}
inactive={inactive} inactive={inactive}
items={this.contextMenuItems}> items={this.contextMenuItems}>
<Title>
<Glyph name={this.plugin?.icon || 'bell'} size={12} /> <Glyph name={this.plugin?.icon || 'bell'} size={12} />
<span>&nbsp;</span> <NotificationContent isSelected={isSelected}>
{notification.title} <Title>{notification.title}</Title>
</Title>
{notification.message} {notification.message}
{action &&
!inactive &&
!isSelected && (
<Chevron
innerRef={this.deepLinkButton}
name="arrow-right-circle"
variant="outline"
size={24}
color={colors.light30}
onClick={this.onClick}
/>
)}
{!inactive && {!inactive &&
isSelected && isSelected &&
this.plugin && this.plugin &&
(action || onHide) && ( (action || onHide) && (
<FlexRow style={{marginTop: 10}}> <Actions>
<FlexRow>
{action && ( {action && (
<Button onClick={this.openDeeplink}> <Button onClick={this.openDeeplink}>
Open in {this.plugin.title} Open in {this.plugin.title}
@@ -438,6 +451,29 @@ class NotificationItem extends Component<ItemProps> {
<Button onClick={onHide}>Hide {this.plugin.title}</Button> <Button onClick={onHide}>Hide {this.plugin.title}</Button>
)} )}
</FlexRow> </FlexRow>
<span>
{notification.timestamp
? new Date(notification.timestamp).toTimeString()
: ''}
</span>
</Actions>
)}
</NotificationContent>
{action &&
!inactive &&
!isSelected && (
<FlexColumn style={{alignSelf: 'center'}}>
{action && (
<NotificationButton compact onClick={this.openDeeplink}>
Open
</NotificationButton>
)}
{onHide && (
<NotificationButton compact onClick={onHide}>
Hide
</NotificationButton>
)}
</FlexColumn>
)} )}
</ContextMenu> </ContextMenu>
); );