From 511627ccb8aab828495374c93fd117ac284d422b Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Tue, 30 Jan 2024 15:01:12 +0100 Subject: [PATCH] Fix count avatar color + align thread preview items (#3695) Fix count avatar and align items Co-authored-by: Thomas Trompette --- .../activities/comment/CommentHeader.tsx | 2 +- .../emails/components/EmailThreadPreview.tsx | 56 +++++++++---------- .../command-menu/components/CommandMenu.tsx | 4 +- .../favorites/components/Favorites.tsx | 2 +- .../MultipleObjectRecordSelectItem.tsx | 2 +- .../components/SelectableMenuItemSelect.tsx | 2 +- .../MultipleRecordSelectDropdown.tsx | 2 +- .../ui/display/chip/components/EntityChip.tsx | 2 +- .../components/ShowPageSummaryCard.tsx | 2 +- .../src/modules/users/components/Avatar.tsx | 28 +++++++--- .../components/WorkspaceMemberCard.tsx | 2 +- 11 files changed, 56 insertions(+), 48 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx b/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx index a8cbb6b19..390851d52 100644 --- a/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx +++ b/packages/twenty-front/src/modules/activities/comment/CommentHeader.tsx @@ -77,7 +77,7 @@ export const CommentHeader = ({ comment, actionBar }: CommentHeaderProps) => { {authorName} diff --git a/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx b/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx index 431c6ef0a..cd3e8b08b 100644 --- a/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx +++ b/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx @@ -1,6 +1,7 @@ import styled from '@emotion/styled'; import { CardContent } from '@/ui/layout/card/components/CardContent'; +import { grayScale } from '@/ui/theme/constants/colors'; import { Avatar } from '@/users/components/Avatar'; import { TimelineThread } from '~/generated/graphql'; import { formatToHumanReadableDate } from '~/utils'; @@ -15,29 +16,17 @@ const StyledCardContent = styled(CardContent)` `; const StyledHeading = styled.div<{ unread: boolean }>` - align-items: center; + display: flex; color: ${({ theme, unread }) => unread ? theme.font.color.primary : theme.font.color.secondary}; - display: flex; font-weight: ${({ theme, unread }) => unread ? theme.font.weight.medium : theme.font.weight.regular}; - gap: ${({ theme }) => theme.spacing(1)}; overflow: hidden; - width: 160px; - - :before { - background-color: ${({ theme, unread }) => - unread ? theme.color.blue : 'transparent'}; - border-radius: ${({ theme }) => theme.border.radius.rounded}; - content: ''; - display: block; - height: 6px; - width: 6px; - } + width: 20%; `; const StyledParticipantsContainer = styled.div` - align-items: center; + align-items: flex-start; display: flex; `; @@ -46,6 +35,7 @@ const StyledAvatar = styled(Avatar)` `; const StyledSenderNames = styled.span` + display: flex; margin: ${({ theme }) => theme.spacing(0, 1)}; overflow: hidden; text-overflow: ellipsis; @@ -56,26 +46,27 @@ const StyledThreadCount = styled.span` color: ${({ theme }) => theme.font.color.tertiary}; `; -const StyledSubject = styled.span<{ unread: boolean }>` - color: ${({ theme, unread }) => - unread ? theme.font.color.primary : theme.font.color.secondary}; - white-space: nowrap; -`; - -const StyledBody = styled.span` - color: ${({ theme }) => theme.font.color.tertiary}; - min-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -`; - const StyledSubjectAndBody = styled.div` display: flex; flex: 1; gap: ${({ theme }) => theme.spacing(2)}; overflow: hidden; +`; + +const StyledSubject = styled.span<{ unread: boolean }>` + color: ${({ theme, unread }) => + unread ? theme.font.color.primary : theme.font.color.secondary}; + white-space: nowrap; + overflow: hidden; text-overflow: ellipsis; + flex-shrink: 0; +`; + +const StyledBody = styled.span` + color: ${({ theme }) => theme.font.color.tertiary}; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; `; const StyledReceivedAt = styled.div` @@ -104,12 +95,13 @@ export const EmailThreadPreview = ({ ? `, ${thread.lastTwoParticipants?.[1]?.displayName}` : ''); - const [finalDisplayedName, finalAvatarUrl] = + const [finalDisplayedName, finalAvatarUrl, isCountIcon] = thread.participantCount > 3 - ? [`${thread.participantCount}`, ''] + ? [`${thread.participantCount}`, '', true] : [ thread?.lastTwoParticipants?.[1]?.displayName, thread?.lastTwoParticipants?.[1]?.avatarUrl, + false, ]; return ( @@ -133,6 +125,8 @@ export const EmailThreadPreview = ({ avatarUrl={finalAvatarUrl} placeholder={finalDisplayedName} type="rounded" + color={isCountIcon ? grayScale.gray50 : undefined} + backgroundColor={isCountIcon ? grayScale.gray10 : undefined} /> )} diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx index 1e3a47224..68fdaac24 100644 --- a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx @@ -328,7 +328,7 @@ export const CommandMenu = () => { { to={`object/company/${company.id}`} Icon={() => ( { label={labelIdentifier} Icon={() => ( diff --git a/packages/twenty-front/src/modules/users/components/Avatar.tsx b/packages/twenty-front/src/modules/users/components/Avatar.tsx index 12dc109fd..9097c3ddc 100644 --- a/packages/twenty-front/src/modules/users/components/Avatar.tsx +++ b/packages/twenty-front/src/modules/users/components/Avatar.tsx @@ -16,21 +16,24 @@ export type AvatarProps = { className?: string; size?: AvatarSize; placeholder: string | undefined; - colorId?: string; + entityId?: string; type?: Nullable; + color?: string; + backgroundColor?: string; onClick?: () => void; }; -const StyledAvatar = styled.div` +export const StyledAvatar = styled.div< + AvatarProps & { color: string; backgroundColor: string } +>` align-items: center; - background-color: ${({ avatarUrl, colorId }) => - !isNonEmptyString(avatarUrl) ? stringToHslColor(colorId, 75, 85) : 'none'}; + background-color: ${({ backgroundColor }) => backgroundColor}; ${({ avatarUrl }) => isNonEmptyString(avatarUrl) ? `background-image: url(${avatarUrl});` : ''} background-position: center; background-size: cover; border-radius: ${(props) => (props.type === 'rounded' ? '50%' : '2px')}; - color: ${({ colorId }) => stringToHslColor(colorId, 75, 25)}; + color: ${({ color }) => color}; cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')}; display: flex; @@ -95,9 +98,11 @@ export const Avatar = ({ className, size = 'md', placeholder, - colorId = placeholder, + entityId = placeholder, onClick, type = 'squared', + color, + backgroundColor, }: AvatarProps) => { const noAvatarUrl = !isNonEmptyString(avatarUrl); const [isInvalidAvatarUrl, setIsInvalidAvatarUrl] = useState(false); @@ -114,6 +119,13 @@ export const Avatar = ({ } }, [avatarUrl]); + const fixedColor = color ?? stringToHslColor(entityId ?? '', 75, 25); + const fixedBackgroundColor = + backgroundColor ?? + (!isNonEmptyString(avatarUrl) + ? stringToHslColor(entityId ?? '', 75, 85) + : 'none'); + return ( {(noAvatarUrl || isInvalidAvatarUrl) && placeholder?.[0]?.toLocaleUpperCase()} diff --git a/packages/twenty-front/src/modules/workspace/components/WorkspaceMemberCard.tsx b/packages/twenty-front/src/modules/workspace/components/WorkspaceMemberCard.tsx index 3c5e3acab..c6529442a 100644 --- a/packages/twenty-front/src/modules/workspace/components/WorkspaceMemberCard.tsx +++ b/packages/twenty-front/src/modules/workspace/components/WorkspaceMemberCard.tsx @@ -40,7 +40,7 @@ export const WorkspaceMemberCard = ({