import React, { useState } from 'react'; import { Avatar } from '../../../Components/Avatar'; import { stringToColor } from '../../../util/colorMapping'; import { ChatCardProps } from './props'; import { styles } from './styles'; export const ChatCard: React.FC = (props: ChatCardProps) => { const { title = '', description = '', timeStamp = '' } = props; const [hovered, setHovered] = useState(false); const loadingBarStyle: React.CSSProperties = props.isLoading ? { ...styles.loadingBarStyle, ...props.loadingBarStyle } : {}; const hasNotificationStyle: React.CSSProperties = props.hasNotification ? {} : { display: 'none' }; if (props.renderChatCard) { return <>{props.renderChatCard(props)}; } return (
setHovered(true)} onMouseLeave={() => setHovered(false)} style={{ // Default ...styles.style, // State ...(hovered ? styles.hoveredStyle : {}), ...(props.isActive ? styles.activeStyle : {}), // Props ...props.style, // Props + State ...(hovered ? props.hoveredStyle : {}), ...(props.isActive ? props.activeStyle : {}), }} className={` ce-chat-card ${props.isActive && 'ce-active-chat-card'} ${hovered && 'ce-hovered-chat-card'} `} > {props.renderAvatar ? ( props.renderAvatar(props) ) : ( )}
{props.isLoading ? '.' : title}
{props.isLoading ? '.' : timeStamp}
); };