Skip to content

Commit

Permalink
Fixed message alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaPrahoveanu-SL committed Nov 21, 2024
1 parent 770fcf3 commit 1f6d196
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
display: flex;
flex-direction: column;
box-sizing: border-box;
background-color: #ffffff;
background-color: var(--white);
justify-content: center;
border-radius: 24px;
margin-top: 12px;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/message.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@
line-height: 22px;
font-size: 16px;
}

.messageStyle.single-line {
margin-top: 0;
margin-bottom: 0;
}
30 changes: 28 additions & 2 deletions frontend/src/components/message.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import React, { useMemo } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import styles from './message.module.css';
import UserIcon from '../icons/account-circle.svg';
import BotIcon from '../icons/logomark.svg';
Expand Down Expand Up @@ -40,10 +40,36 @@ export const MessageComponent = ({ message }: MessageProps) => {

const { class: roleClass, icon } = useMemo(() => roleStyleMap[role], [role]);

const messageRef = useRef<HTMLParagraphElement>(null);
const [isSingleLine, setIsSingleLine] = useState(false);

const checkSingleLine = () => {
if (messageRef.current) {
const singleLineHeight = 22;
const actualHeight = messageRef.current.offsetHeight;
setIsSingleLine(actualHeight <= singleLineHeight);
}
};

useEffect(() => {
checkSingleLine();
window.addEventListener('resize', checkSingleLine);
return () => {
window.removeEventListener('resize', checkSingleLine);
};
}, [content]);

return (
<div className={classNames(styles.container, roleClass)}>
<img src={icon} className={styles.iconStyle} />
<p className={styles.messageStyle}>{content}</p>
<p
ref={messageRef}
className={classNames(styles.messageStyle, {
[styles['single-line']]: isSingleLine,
})}
>
{content}
</p>
</div>
);
};
6 changes: 0 additions & 6 deletions frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ body,
--black: #000000;
--white: #ffffff;

--background-color-primary: #282828;
--blue: #007bff;
--border-primary: #424242;
--text-color-primary: #ffffff;
--text-color-secondary: #899090;

background-color: var(--grey-200);
color: var(--grey-900);
}

0 comments on commit 1f6d196

Please sign in to comment.