Change user icons to match design (#161)

This commit is contained in:
Szymon Szlachtowicz 2021-12-22 15:55:03 +01:00 committed by GitHub
parent 2e91024490
commit 047e9d77eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 15 deletions

View File

@ -5,9 +5,10 @@ import { useMessengerContext } from "../../contexts/messengerProvider";
import { Contact } from "../../models/Contact"; import { Contact } from "../../models/Contact";
import { ContactMenu } from "../Form/ContactMenu"; import { ContactMenu } from "../Form/ContactMenu";
import { Icon } from "../Icons/Icon"; import { Icon } from "../Icons/Icon";
import { UserIcon } from "../Icons/UserIcon";
import { UserAddress } from "../Messages/Styles"; import { UserAddress } from "../Messages/Styles";
import { UserLogo } from "./UserLogo";
interface MemberProps { interface MemberProps {
contact: Contact; contact: Contact;
isOnline?: boolean; isOnline?: boolean;
@ -46,7 +47,15 @@ export function Member({
onClick={() => setShowMenu((e) => !e)} onClick={() => setShowMenu((e) => !e)}
> >
{showMenu && <ContactMenu id={contact.id} setShowMenu={setShowMenu} />} {showMenu && <ContactMenu id={contact.id} setShowMenu={setShowMenu} />}
<UserIcon memberView={true} /> <UserLogo
contact={contact}
radius={30}
colorWheel={[
["red", 150],
["blue", 250],
["green", 360],
]}
/>
</MemberIcon> </MemberIcon>
<MemberName>{contact?.customName ?? contact.trueName}</MemberName> <MemberName>{contact?.customName ?? contact.trueName}</MemberName>
<UserAddress> <UserAddress>
@ -77,8 +86,8 @@ export const MemberName = styled.p`
`; `;
export const MemberIcon = styled(Icon)` export const MemberIcon = styled(Icon)`
width: 24px; width: 29px;
height: 24px; height: 29px;
position: relative; position: relative;
background-size: contain; background-size: contain;
background-position: center; background-position: center;

View File

@ -1,14 +1,23 @@
import React, { useMemo } from "react"; import React, { useMemo } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { Contact } from "../../models/Contact";
type UserLogoProps = { type UserLogoProps = {
radius: number; radius: number;
colorWheel: [string, number][]; colorWheel: [string, number][];
contact: Contact;
showOnlineStatus?: boolean;
icon?: string; icon?: string;
text?: string;
}; };
export function UserLogo({ icon, text, radius, colorWheel }: UserLogoProps) { export function UserLogo({
icon,
contact,
radius,
colorWheel,
showOnlineStatus,
}: UserLogoProps) {
const conicGradient = useMemo(() => { const conicGradient = useMemo(() => {
const colors = colorWheel const colors = colorWheel
.map((color, idx) => { .map((color, idx) => {
@ -18,21 +27,41 @@ export function UserLogo({ icon, text, radius, colorWheel }: UserLogoProps) {
.join(","); .join(",");
return `conic-gradient(${colors})`; return `conic-gradient(${colors})`;
}, [colorWheel]); }, [colorWheel]);
const letters = useMemo(() => {
if (contact?.customName) {
return contact.customName.slice(0, 2);
}
if (contact.trueName) {
return contact.trueName.slice(0, 2);
}
}, [contact]);
const logoClassnName = useMemo(() => {
if (showOnlineStatus) {
if (contact.online) {
return "online";
}
return "offline";
}
return "";
}, [contact]);
return ( return (
<Wrapper radius={radius} conicGradient={conicGradient}> <Wrapper radius={radius} conicGradient={conicGradient}>
<Logo icon={icon} radius={radius}> <Logo icon={icon} radius={radius} className={logoClassnName}>
{!icon && text && <TextWrapper>{text}</TextWrapper>} {!icon && <TextWrapper radius={radius}>{letters}</TextWrapper>}
</Logo> </Logo>
</Wrapper> </Wrapper>
); );
} }
const TextWrapper = styled.div` const TextWrapper = styled.div<{ radius: number }>`
font-family: Inter; font-family: Inter;
font-style: normal; font-style: normal;
font-weight: bold; font-weight: bold;
font-size: 32px; font-size: calc(${({ radius }) => radius}px / 2.5);
line-height: 38px; line-height: calc(${({ radius }) => radius}px / 2.1);
display: flex; display: flex;
align-items: center; align-items: center;
text-align: center; text-align: center;
@ -57,6 +86,34 @@ const Logo = styled.div<{ radius: number; icon?: string }>`
color: ${({ theme }) => theme.iconTextColor}; color: ${({ theme }) => theme.iconTextColor};
margin: auto; margin: auto;
display: flex; display: flex;
&.offline {
&::after {
content: "";
position: absolute;
right: -1px;
bottom: -2px;
width: 7px;
height: 7px;
border-radius: 50%;
background-color: ${({ theme }) => theme.secondary};
border: 2px solid ${({ theme }) => theme.bodyBackgroundColor};
}
}
&.online {
&::after {
content: "";
position: absolute;
right: -1px;
bottom: -2px;
width: 7px;
height: 7px;
border-radius: 50%;
background-color: #4ebc60;
border: 2px solid ${({ theme }) => theme.bodyBackgroundColor};
}
}
`; `;
const Wrapper = styled.div<{ radius: number; conicGradient: string }>` const Wrapper = styled.div<{ radius: number; conicGradient: string }>`

View File

@ -15,7 +15,7 @@ import { Icon } from "../Icons/Icon";
import { ReactionSvg } from "../Icons/ReactionIcon"; import { ReactionSvg } from "../Icons/ReactionIcon";
import { ReplySvg } from "../Icons/ReplyIcon"; import { ReplySvg } from "../Icons/ReplyIcon";
import { UntrustworthIcon } from "../Icons/UntrustworthIcon"; import { UntrustworthIcon } from "../Icons/UntrustworthIcon";
import { UserIcon } from "../Icons/UserIcon"; import { UserLogo } from "../Members/UserLogo";
import { MessageQuote } from "./MessageQuote"; import { MessageQuote } from "./MessageQuote";
import { import {
@ -116,7 +116,15 @@ export function UiMessage({
{showMenu && ( {showMenu && (
<ContactMenu id={message.sender} setShowMenu={setShowMenu} /> <ContactMenu id={message.sender} setShowMenu={setShowMenu} />
)} )}
<UserIcon /> <UserLogo
contact={contact}
radius={40}
colorWheel={[
["red", 150],
["blue", 250],
["green", 360],
]}
/>
</Icon> </Icon>
<ContentWrapper> <ContentWrapper>
<MessageHeaderWrapper> <MessageHeaderWrapper>

View File

@ -7,6 +7,7 @@ import {
useSetNikcname, useSetNikcname,
} from "../../contexts/identityProvider"; } from "../../contexts/identityProvider";
import { useModal } from "../../contexts/modalProvider"; import { useModal } from "../../contexts/modalProvider";
import { Contact } from "../../models/Contact";
import { NameInput } from "../../styles/Inputs"; import { NameInput } from "../../styles/Inputs";
import { LeftIconSvg } from "../Icons/LeftIcon"; import { LeftIconSvg } from "../Icons/LeftIcon";
import { UserLogo } from "../Members/UserLogo"; import { UserLogo } from "../Members/UserLogo";
@ -44,7 +45,7 @@ export function UserCreationModal() {
</StyledHint> </StyledHint>
<LogoWrapper> <LogoWrapper>
<UserLogo <UserLogo
text={customNameInput.slice(0, 2)} contact={{ trueName: customNameInput } as Contact}
radius={80} radius={80}
colorWheel={[ colorWheel={[
["red", 150], ["red", 150],
@ -60,7 +61,7 @@ export function UserCreationModal() {
/> />
</Content> </Content>
</MiddleSection> </MiddleSection>
<ButtonSection style={{ marginBottom: "40px" }}> <ButtonSection>
<BackBtn onClick={() => setModal(false)}> <BackBtn onClick={() => setModal(false)}>
<LeftIconSvg width={28} height={28} /> <LeftIconSvg width={28} height={28} />
</BackBtn> </BackBtn>