Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: New avatar style #181

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/components/MultiChatWindow/ChatList/ChatCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useState } from 'react';

import { Avatar } from '../../../Components/Avatar';

import { stringToColor } from '../../../util/colorMapping';

import { Props } from './props';
import { styles } from './styles';

@@ -43,6 +47,20 @@ export const ChatCard: React.FC<Props> = (props: Props) => {
${hovered && 'ce-hovered-chat-card'}
`}
>
<Avatar
username={props.avatarUsername}
avatarUrl={props.avatarUrl}
style={{
...styles.avatarStyle,
...{
backgroundColor: props.isLoading
? '#e2e2e2'
: stringToColor(props.avatarUsername),
},
...props.avatarStyle,
}}
/>

<div
className="ce-chat-card-title"
style={{
3 changes: 2 additions & 1 deletion src/components/MultiChatWindow/ChatList/ChatCard/props.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { HTMLAttributes } from 'react';

import { ChatCardStyle } from './styles';

export interface Props extends HTMLAttributes<HTMLDivElement>, ChatCardStyle {
// Data
title?: string;
description?: string;
timeStamp?: string;
avatarUsername?: string;
avatarUrl?: string | null | undefined;
// State
hasNotification?: boolean;
isActive?: boolean;
7 changes: 7 additions & 0 deletions src/components/MultiChatWindow/ChatList/ChatCard/stories.mdx
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import { Props } from './props';
style: { table: { category: 'styles' } },
hoveredStyle: { table: { category: 'styles' } },
activeStyle: { table: { category: 'styles' } },
avatarStyle: { table: { category: 'styles' } },
titleStyle: { table: { category: 'styles' } },
notificationStyle: { table: { category: 'styles' } },
subtitleStyle: { table: { category: 'styles' } },
@@ -38,6 +39,7 @@ The Chat Card component represents a Chat room to click on.
title: 'Chat Card',
description: 'This is where the magic happens',
timeStamp: '4:24 PM',
avatarUsername: 'Adam',
style: {
maxWidth: '400px',
boxShadow: '0px 0px 3px 6px rgba(0, 0, 0, 0.1)',
@@ -57,6 +59,7 @@ You can see a notification dot if `hasNotification` is `true`.
<Story
name="Has Notification"
args={{
avatarUsername: 'Adam',
title: 'Notification Card',
description: 'Alert alert!!!',
timeStamp: 'Tues',
@@ -79,6 +82,7 @@ By default, the Chat Card component appears darker when `isActive` is `true`.
<Story
name="Is Active"
args={{
avatarUsername: 'Adam',
title: 'Active Chat Card',
description: 'You are in this chat now...',
timeStamp: '12:59 PM',
@@ -100,6 +104,7 @@ You can see data has not appeared yet if `isLoading` is `true`.
<Story
name="Is Loading"
args={{
avatarUsername: 'Adam',
title: 'Notification Card',
description: 'Alert alert!!!',
timeStamp: 'Tues',
@@ -122,6 +127,7 @@ You can render you own code instead of this component with the `render*` functio
<Story
name="Render Functions"
args={{
avatarUsername: 'Adam',
title: 'Notification Card',
description: 'Alert alert!!!',
timeStamp: 'Tues',
@@ -150,6 +156,7 @@ There are a list of `*Style` props which customize various parts of the componen
},
hoveredStyle: { border: '2px solid lime' },
activeStyle: { border: '2px solid pink' },
avatarStyle: { border: '2px solid grey' },
titleStyle: { border: '2px solid blue' },
notificationStyle: { border: '2px solid deeppink' },
subtitleStyle: { border: '2px solid green' },
10 changes: 6 additions & 4 deletions src/components/MultiChatWindow/ChatList/ChatCard/styles.tsx
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ export interface ChatCardStyle {
style?: React.CSSProperties;
hoveredStyle?: React.CSSProperties;
activeStyle?: React.CSSProperties;
avatarStyle?: React.CSSProperties;
titleStyle?: React.CSSProperties;
notificationStyle?: React.CSSProperties;
subtitleStyle?: React.CSSProperties;
@@ -27,13 +28,14 @@ export const styles: ChatCardStyle = {
backgroundColor: '#d9d9d9',
border: '0px solid white',
},
avatarStyle: { position: 'absolute', top: '16px', left: '12px' },
titleStyle: {
// Position
position: 'absolute',
top: '12px',
left: '12px',
left: '68px',
// Size
width: 'calc(100% - 12px - 32px)',
width: 'calc(100% - 68px - 32px)',
// Font
fontWeight: 500,
whiteSpace: 'nowrap',
@@ -56,9 +58,9 @@ export const styles: ChatCardStyle = {
// Position
position: 'absolute',
bottom: '12px',
left: '12px',
left: '68px',
// Size
width: '70%',
width: 'calc(70% - 68px)',
// Style
color: 'rgba(153, 153, 153, 1)',
fontSize: '14px',
7 changes: 7 additions & 0 deletions src/components/MultiChatWindow/ChatList/index.tsx
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ export const ChatList: React.FC<Props> = (props: Props) => {
const hasNotification = props.username
? !readLastMessage(props.username, chat)
: false;

return (
<ChatCard
key={`chat_${index}`}
@@ -66,6 +67,12 @@ export const ChatList: React.FC<Props> = (props: Props) => {
onClick={() =>
props.onChatCardClick && props.onChatCardClick(chat.id)
}
avatarUsername={chat.last_message.sender?.username}
avatarUrl={
chat.last_message.sender
? chat.last_message.sender.avatar
: 'https://chat-engine-assets.s3.amazonaws.com/empty-chat-thumb.png'
}
renderChatCard={props.renderChatCard}
/>
);