9+ on icons

pull/1022/head
Vincent 5 years ago
parent 71caa49a84
commit 0a26e09217

@ -459,13 +459,14 @@ $session_message-container-border-radius: 5px;
} }
.notification-count { .notification-count {
display: flex;
align-items: center;
justify-content: center;
position: absolute; position: absolute;
font-size: $session-font-xs; font-size: $session-font-xs;
font-family: $session-font-family; font-family: $session-font-family;
top: 20px; top: 20px;
right: 20px; right: 20px;
width: 20px;
height: 20px;
padding: 3px; padding: 3px;
border-radius: 50%; border-radius: 50%;
font-weight: 700; font-weight: 700;
@ -473,7 +474,15 @@ $session_message-container-border-radius: 5px;
color: $session-color-white; color: $session-color-white;
text-align: center; text-align: center;
opacity: 1; opacity: 1;
sup {
font-size: 130%;
margin-top: 1px;
margin-left: -1px;
}
} }
} }
.session-icon { .session-icon {

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { SessionButton } from './SessionButton'; import { SessionButton } from './SessionButton';
import { SessionNotificationCount } from './SessionNotificationCount';
const Tab = ({ const Tab = ({
isSelected, isSelected,
@ -89,8 +90,6 @@ export class LeftPaneSectionHeader extends React.Component<Props, State> {
/> />
); );
} else if (buttonLabel && notificationCount && notificationCount > 0) { } else if (buttonLabel && notificationCount && notificationCount > 0) {
const shortenedNotificationCount =
notificationCount > 9 ? 9 : notificationCount;
children.push( children.push(
<div className="contact-notification-section"> <div className="contact-notification-section">
<SessionButton <SessionButton
@ -99,26 +98,18 @@ export class LeftPaneSectionHeader extends React.Component<Props, State> {
key="compose" key="compose"
disabled={false} disabled={false}
/> />
<div <SessionNotificationCount
className="contact-notification-count-bubble" count={notificationCount}
onClick={this.props.buttonClicked} onClick={this.props.buttonClicked}
role="button" />
>
{shortenedNotificationCount}
</div>
</div> </div>
); );
} else if (notificationCount && notificationCount > 0) { } else if (notificationCount && notificationCount > 0) {
const shortenedNotificationCount =
notificationCount > 9 ? 9 : notificationCount;
children.push( children.push(
<div <SessionNotificationCount
className="contact-notification-count-bubble" count={notificationCount}
onClick={this.props.buttonClicked} onClick={this.props.buttonClicked}
role="button" />
>
{shortenedNotificationCount}
</div>
); );
} }

@ -0,0 +1,57 @@
import React from 'react';
interface Props {
count?: number;
// Size in px
size?: number;
onClick?: any;
}
export class SessionNotificationCount extends React.Component<Props> {
public static defaultProps = {
size: 20,
};
constructor(props: any) {
super(props);
}
public render() {
const { count, size, onClick } = this.props;
const MAX_SINGLE_DIGIT = 9;
const overflow = count > MAX_SINGLE_DIGIT;
const countElement: JSX.Element = overflow
? <>{MAX_SINGLE_DIGIT}<sup>+</sup></>
: <>{count}</>;
const bubbleStyle = {
width: `${size}px`,
height: `${size}px`,
};
const countStyle = {
marginTop: overflow ? '-4px' : '0px',
marginLeft: overflow ? '2px' : '0px',
};
const shouldRender = typeof count === 'number' && count > 0;
return (
<>
{shouldRender && (
<div
className="notification-count"
onClick={onClick}
style={bubbleStyle}
role="button"
>
<span style={countStyle}>
{countElement}
</span>
</div>
)}
</>
);
}
}

@ -1,11 +1,12 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { Props, SessionIcon } from '../icon'; import { Props, SessionIcon } from '../icon';
import { SessionNotificationCount } from '../SessionNotificationCount';
interface SProps extends Props { interface SProps extends Props {
onClick: any; onClick: any;
notificationCount: number | undefined; notificationCount?: number;
isSelected: boolean; isSelected: boolean;
} }
@ -35,13 +36,7 @@ export class SessionIconButton extends React.PureComponent<SProps> {
isSelected, isSelected,
} = this.props; } = this.props;
let { notificationCount } = this.props; const { notificationCount } = this.props;
if (notificationCount === 0) {
notificationCount = undefined;
} else if (notificationCount !== undefined && notificationCount > 9) {
notificationCount = 9;
}
return ( return (
<div <div
@ -62,9 +57,9 @@ export class SessionIconButton extends React.PureComponent<SProps> {
iconColor={iconColor} iconColor={iconColor}
iconRotation={iconRotation} iconRotation={iconRotation}
/> />
{notificationCount !== undefined && ( <SessionNotificationCount
<span className="notification-count">{notificationCount}</span> count={notificationCount}
)} />
</div> </div>
); );
} }

Loading…
Cancel
Save