From 593bc563f0bc9c0c82932146b099c1394ba6c82a Mon Sep 17 00:00:00 2001 From: Maria Rushkova <66270386+mrushkova@users.noreply.github.com> Date: Mon, 29 Nov 2021 12:54:57 +0100 Subject: [PATCH] Add message style (#138) --- packages/react-chat-example/src/index.tsx | 2 +- .../components/Chat/ChatMessageContent.tsx | 20 ++++++++++++--- .../src/components/Chat/ChatMessages.tsx | 25 ++++++++++++++++--- packages/react-chat/src/styles/themes.ts | 11 +++++--- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/packages/react-chat-example/src/index.tsx b/packages/react-chat-example/src/index.tsx index 9c49bd55..0b279e19 100644 --- a/packages/react-chat-example/src/index.tsx +++ b/packages/react-chat-example/src/index.tsx @@ -123,7 +123,7 @@ const Bubble = styled.div` const Drag = styled.div` position: absolute; - overflow: hide; + overflow: hidden; `; ReactDOM.render( diff --git a/packages/react-chat/src/components/Chat/ChatMessageContent.tsx b/packages/react-chat/src/components/Chat/ChatMessageContent.tsx index e37f552b..2937002c 100644 --- a/packages/react-chat/src/components/Chat/ChatMessageContent.tsx +++ b/packages/react-chat/src/components/Chat/ChatMessageContent.tsx @@ -1,8 +1,10 @@ import { decode } from "html-entities"; import React, { useEffect, useMemo, useState } from "react"; +import { utils } from "status-communities/dist/cjs"; import styled from "styled-components"; import { useFetchMetadata } from "../../contexts/fetchMetadataProvider"; +import { useIdentity } from "../../contexts/identityProvider"; import { useMessengerContext } from "../../contexts/messengerProvider"; import { ChatMessage } from "../../models/ChatMessage"; import { Metadata } from "../../models/Metadata"; @@ -12,13 +14,18 @@ import { textMediumStyles, textSmallStyles } from "../Text"; interface MentionProps { id: string; + setMentioned: (val: boolean) => void; } -function Mention({ id }: MentionProps) { +function Mention({ id, setMentioned }: MentionProps) { const { contacts } = useMessengerContext(); const contact = useMemo(() => contacts[id.slice(1)], [id, contacts]); const [showMenu, setShowMenu] = useState(false); + const identity = useIdentity(); + if (!contact) return <>{id}; + if (contact.id === utils.bufToHex(identity.publicKey)) setMentioned(true); + return ( setShowMenu(!showMenu)}> {`@${contact.customName ?? contact.id}`} @@ -31,12 +38,14 @@ type ChatMessageContentProps = { message: ChatMessage; setImage: (image: string) => void; setLinkOpen: (link: string) => void; + setMentioned: (val: boolean) => void; }; export function ChatMessageContent({ message, setImage, setLinkOpen, + setMentioned, }: ChatMessageContentProps) { const fetchMetadata = useFetchMetadata(); const { content, image } = useMemo(() => message, [message]); @@ -60,7 +69,10 @@ export function ChatMessageContent({ ]; } if (element.startsWith("@")) { - return [, " "]; + return [ + , + " ", + ]; } return [element, " "]; }); @@ -181,7 +193,7 @@ const ContentWrapper = styled.div` const MentionBLock = styled.div` display: inline-block; color: ${({ theme }) => theme.mentionColor}; - background: ${({ theme }) => theme.mentionBg}; + background: ${({ theme }) => theme.mentionBgHover}; border-radius: 4px; font-weight: 500; position: relative; @@ -189,7 +201,7 @@ const MentionBLock = styled.div` cursor: pointer; &:hover { - background: ${({ theme }) => theme.mentionBgHover}; + background: ${({ theme }) => theme.mentionHover}; } ${textMediumStyles} diff --git a/packages/react-chat/src/components/Chat/ChatMessages.tsx b/packages/react-chat/src/components/Chat/ChatMessages.tsx index 9bc40658..39d41053 100644 --- a/packages/react-chat/src/components/Chat/ChatMessages.tsx +++ b/packages/react-chat/src/components/Chat/ChatMessages.tsx @@ -40,6 +40,7 @@ function ChatUiMessage({ [message.sender, contacts] ); const [showMenu, setShowMenu] = useState(false); + const [mentioned, setMentioned] = useState(false); return ( @@ -50,7 +51,7 @@ function ChatUiMessage({ : message.date.toLocaleDateString()} )} - + { setShowMenu((e) => !e); @@ -83,6 +84,7 @@ function ChatUiMessage({ message={message} setImage={setImage} setLinkOpen={setLink} + setMentioned={setMentioned} /> @@ -150,7 +152,7 @@ const MessagesWrapper = styled.div` flex-direction: column; height: calc(100% - 44px); overflow: auto; - padding: 8px 16px 0; + padding: 8px 0; &::-webkit-scrollbar { width: 0; @@ -160,8 +162,23 @@ const MessagesWrapper = styled.div` const MessageWrapper = styled.div` width: 100%; display: flex; - padding: 8px 0; - margin-bottom: 8px; + padding: 8px 16px; + border-left: 2px solid ${({ theme }) => theme.bodyBackgroundColor}; + + &:hover { + background: ${({ theme }) => theme.inputColor}; + border-color: ${({ theme }) => theme.inputColor}; + } + + &.mention { + background: ${({ theme }) => theme.mentionBg}; + border-color: ${({ theme }) => theme.mentionColor}; + } + + &.mention:hover { + background: ${({ theme }) => theme.mentionBgHover}; + border-color: ${({ theme }) => theme.mentionColor}; + } `; const MessageOuterWrapper = styled.div` diff --git a/packages/react-chat/src/styles/themes.ts b/packages/react-chat/src/styles/themes.ts index 9d6b7ecc..704c906c 100644 --- a/packages/react-chat/src/styles/themes.ts +++ b/packages/react-chat/src/styles/themes.ts @@ -20,6 +20,7 @@ export type Theme = { skeletonDark: string; redColor: string; mentionColor: string; + mentionHover: string; mentionBg: string; mentionBgHover: string; }; @@ -46,8 +47,9 @@ export const lightTheme: Theme = { skeletonDark: "#E9EDF1", redColor: "#FF2D55", mentionColor: "#0DA4C9", + mentionHover: "#BDE7F2", mentionBg: "#E5F8FD", - mentionBgHover: "#BDE7F2", + mentionBgHover: "#D4F3FA", }; export const darkTheme: Theme = { @@ -71,9 +73,10 @@ export const darkTheme: Theme = { skeletonLight: "#2E2F31", skeletonDark: "#141414", redColor: "#FF5C7B", - mentionColor: "#0DA4C9", - mentionBg: "#E5F8FD", - mentionBgHover: "#BDE7F2", + mentionColor: "#51D0F0", + mentionHover: "#004E60", + mentionBg: "#004050", + mentionBgHover: "#002D39", }; export default { lightTheme, darkTheme };