You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/components/icon/SessionNotificationCount.tsx

56 lines
1.3 KiB
TypeScript

import React from 'react';
import styled from 'styled-components';
type Props = {
count?: number;
};
const StyledCountContainer = styled.div<{ shouldRender: boolean }>`
position: absolute;
width: 24px;
height: 12px;
font-size: 18px;
top: 27px;
right: 8px;
padding: 3px;
opacity: 1;
display: flex;
align-items: center;
justify-content: center;
font-family: var(--font-default);
border-radius: 58px;
font-weight: 700;
background: var(--unread-messages-alert-background-color);
transition: var(--default-duration);
opacity: ${props => (props.shouldRender ? 1 : 0)};
text-align: center;
color: var(--unread-messages-alert-text-color);
`;
const StyledCount = styled.div`
position: relative;
font-size: 0.6em;
`;
export const SessionNotificationCount = (props: Props) => {
const { count } = props;
const overflow = Boolean(count && count > 9);
const shouldRender = Boolean(count && count > 0);
if (overflow) {
return (
<StyledCountContainer shouldRender={shouldRender}>
<StyledCount>
{9}
<span>+</span>
</StyledCount>
</StyledCountContainer>
);
}
return (
<StyledCountContainer shouldRender={shouldRender}>
<StyledCount>{count}</StyledCount>
</StyledCountContainer>
);
};