From d93922f1d0dba52b4c23ce6d250c378f2b114de2 Mon Sep 17 00:00:00 2001 From: t1enne Date: Wed, 29 Jun 2022 08:22:22 +0200 Subject: [PATCH] Added background to own messages in chat and the rounded border. Closes #1985 --- .../ChatUserMessage.module.scss | 35 +++++++++++++++---- .../chat/ChatUserMessage/ChatUserMessage.tsx | 17 +++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss b/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss index 8923c0fae..80615872d 100644 --- a/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss +++ b/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss @@ -1,10 +1,9 @@ .root { + position: relative; font-size: 0.9rem; padding: 5px; padding-left: 1rem; margin: 8px 5px; - border-left: 2px solid; - border-radius: 0.3rem; .user { font: var(--theme-header-font-family); color: var(--color-owncast-grey-100); @@ -28,10 +27,32 @@ box-decoration-break: clone; } } -} + .customBorder { + position: absolute; + top: 0px; + left: 0px; + width: 5px; + height: 100%; + overflow: hidden; + &:after { + content: ''; + width: 10px; + height: 100%; + position: absolute; + top: 0%; + right: 0px; + background-color: currentColor; + border-radius: 0.5rem; + } + } - -.ownMessage { - border-left: 0px; - border-right: 2px solid; + &.ownMessage { + .customBorder { + left: auto; + right: 0px; + &:after { + left: 0px; + } + } + } } diff --git a/web/components/chat/ChatUserMessage/ChatUserMessage.tsx b/web/components/chat/ChatUserMessage/ChatUserMessage.tsx index 6b8cbe170..333772e1d 100644 --- a/web/components/chat/ChatUserMessage/ChatUserMessage.tsx +++ b/web/components/chat/ChatUserMessage/ChatUserMessage.tsx @@ -20,14 +20,18 @@ export default function ChatUserMessage({ showModeratorMenu, renderAsPersonallySent, // Move the border to the right and render a background }: Props) { + const [bgColor, setBgColor] = useState(); const { body, user, timestamp } = message; const { displayName, displayColor } = user; + const color = `var(--theme-user-colors-${displayColor})`; - // TODO: Need to convert the above color to a background color. - const bgColor = `hsl(100, 20%, 25%)`; const formattedTimestamp = `Sent at ${formatTimestamp(timestamp)}`; const [formattedMessage, setFormattedMessage] = useState(body); + useEffect(() => { + if (renderAsPersonallySent) setBgColor(getBgColor(displayColor)); + }, []); + useEffect(() => { setFormattedMessage(he.decode(body)); }, [message]); @@ -37,6 +41,7 @@ export default function ChatUserMessage({ className={cn(s.root, { [s.ownMessage]: renderAsPersonallySent, })} + data-display-color={displayColor} style={{ borderColor: color, backgroundColor: bgColor }} title={formattedTimestamp} > @@ -47,6 +52,14 @@ export default function ChatUserMessage({
{formattedMessage}
{showModeratorMenu &&
Moderator menu
} +
); } + +function getBgColor(displayColor: number, alpha = 13) { + const root = document.querySelector(':root'); + const css = getComputedStyle(root); + const hexColor = css.getPropertyValue(`--theme-user-colors-${displayColor}`); + return hexColor.concat(alpha.toString()); +}