Skip to content

Commit 3009385

Browse files
committed
feat: добавить компонент ElectricBorder с анимацией и стилями
1 parent af1f75a commit 3009385

File tree

6 files changed

+73
-9
lines changed

6 files changed

+73
-9
lines changed

src/components/OBS_Components/ChatVertical/Message.module.scss

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
}
88

99
.container {
10-
display: inline;
10+
display: inline-flex;
1111
flex-direction: row; // меняем на row для горизонтального расположения
12-
align-items: center; // выравниваем по центру
12+
align-items: center;
1313
gap: 8px;
1414
min-height: 60px;
1515
border-radius: 12px;
@@ -18,6 +18,10 @@
1818
box-sizing: border-box;
1919
}
2020

21+
.containerLargeMessage {
22+
align-items: flex-start;
23+
}
24+
2125
.userInfo {
2226
display: inline-flex;
2327
flex-direction: row;
@@ -27,6 +31,17 @@
2731
padding: 0 8px;
2832
border-radius: 12px;
2933
width: fit-content;
34+
flex-shrink: 0;
35+
36+
.badges {
37+
display: inline-flex;
38+
flex-direction: row;
39+
align-items: center;
40+
flex-wrap: nowrap;
41+
white-space: nowrap;
42+
gap: 4px;
43+
flex-shrink: 0;
44+
}
3045

3146
// Бейджи теперь напрямую в userInfo
3247
img {
@@ -36,16 +51,21 @@
3651
}
3752
}
3853

54+
.userInfoLargeMessage {
55+
margin-top: 12px;
56+
}
57+
3958
.nickname {
4059
font-weight: bold;
4160
color: white;
4261
font-size: 2em;
62+
line-height: 1;
4363
white-space: nowrap;
4464
flex-shrink: 0;
4565
}
4666

4767
.message {
48-
display: inline;
68+
display: inline-flex;
4969
flex-wrap: wrap;
5070
align-items: center;
5171
gap: 4px;
@@ -56,13 +76,19 @@
5676
width: fit-content; // сообщение по ширине контента
5777
max-width: 100%; // ограничиваем ширину
5878
min-width: 0;
79+
line-height: 1;
80+
flex: 1 1 auto;
5981

6082
& * {
6183
display: inline !important;
6284
backdrop-filter: none !important;
6385
}
6486
}
6587

88+
.messageLargeMessage {
89+
align-items: flex-start;
90+
}
91+
6692
.linkStub {
6793
color: #39ff14;
6894
text-decoration: underline;

src/components/OBS_Components/ChatVertical/Message.tsx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useEffect, useRef, useState } from "react";
2-
import ElectricBorder from "react-bits/src/content/Animations/ElectricBorder/ElectricBorder";
32
import GradientText from "react-bits/src/ts-default/TextAnimations/GradientText/GradientText";
43

54
import catisaVideo from "@/assets/catisa.mp4";
65
import { ChatMessage } from "@/shared/api";
6+
import ElectricBorder from "@/shared/components/ElectricBorderLegacy";
77
import useTwitchStore from "@/shared/twitchStore/twitchStore";
88
import { parseContent, replaceBadges, replaceEmotes } from "@/shared/Utils";
99

@@ -33,8 +33,10 @@ export function Message({ message, onRemove }: Props) {
3333
const parser = useTwitchStore(state => state.parser);
3434
const parserToLink = useTwitchStore(state => state.parseToLink);
3535
const [parts] = useState(() => parseContent(message.message));
36+
const [isMultilineMessage, setIsMultilineMessage] = useState(false);
3637
const roleColor = getRoleColor(message);
3738
const msgRef = useRef<HTMLDivElement>(null);
39+
const messageContentRef = useRef<HTMLDivElement>(null);
3840

3941
// Появление/исчезновение управляется фреймером (в родителе)
4042

@@ -49,6 +51,35 @@ export function Message({ message, onRemove }: Props) {
4951
return () => clearTimeout(timer);
5052
}, [onRemove, message]);
5153

54+
useEffect(() => {
55+
const messageElement = messageContentRef.current;
56+
if (!messageElement) {
57+
return;
58+
}
59+
60+
const updateMultilineState = () => {
61+
const computedStyles = window.getComputedStyle(messageElement);
62+
const parsedLineHeight = Number.parseFloat(computedStyles.lineHeight);
63+
const parsedFontSize = Number.parseFloat(computedStyles.fontSize);
64+
const lineHeight = Number.isFinite(parsedLineHeight)
65+
? parsedLineHeight
66+
: (Number.isFinite(parsedFontSize) ? parsedFontSize : 16) * 1.2;
67+
const messageHeight = messageElement.getBoundingClientRect().height;
68+
const hasMultipleTextLines =
69+
!isCatisa && messageHeight > lineHeight * 1.6;
70+
setIsMultilineMessage(hasMultipleTextLines);
71+
};
72+
73+
updateMultilineState();
74+
75+
const resizeObserver = new ResizeObserver(updateMultilineState);
76+
resizeObserver.observe(messageElement);
77+
78+
return () => {
79+
resizeObserver.disconnect();
80+
};
81+
}, [isCatisa, message.message]);
82+
5283
return (
5384
<>
5485
<div className={styles.wrapper}>
@@ -59,9 +90,12 @@ export function Message({ message, onRemove }: Props) {
5990
speed={1.2}
6091
>
6192
<div style={{ display: "block", padding: "3px 15px" }}>
62-
<div ref={msgRef} className={styles.container}>
93+
<div
94+
ref={msgRef}
95+
className={`${styles.container} ${isMultilineMessage ? styles.containerLargeMessage : ""}`}
96+
>
6397
<div
64-
className={styles.userInfo}
98+
className={`${styles.userInfo} ${isMultilineMessage ? styles.userInfoLargeMessage : ""}`}
6599
style={{ backgroundColor: roleColor ?? "transparent" }}
66100
>
67101
<div className={styles.badges}>
@@ -76,7 +110,10 @@ export function Message({ message, onRemove }: Props) {
76110
{message.displayName}
77111
</div>
78112
</div>
79-
<div className={styles.message}>
113+
<div
114+
ref={messageContentRef}
115+
className={`${styles.message} ${isMultilineMessage ? styles.messageLargeMessage : ""}`}
116+
>
80117
{isCatisa ? (
81118
<video
82119
src={catisaVideo}

src/components/OBS_Components/Credits/Credits.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import styles from "./Credits.module.scss";
2323

2424
// ОПТИМИЗАЦИЯ: Lazy loading для тяжелых анимаций - загружаем только когда нужно
2525
const ElectricBorder = lazy(
26-
() => import("./ElectricBorderLegacy/ElectricBorder")
26+
() => import("@/shared/components/ElectricBorderLegacy")
2727
);
2828
const Aurora = lazy(
2929
() => import("react-bits/src/ts-default/Backgrounds/Aurora/Aurora")

src/components/OBS_Components/Credits/ElectricBorderLegacy/ElectricBorder.css renamed to src/shared/components/ElectricBorderLegacy/ElectricBorder.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@
7272
transparent,
7373
var(--electric-border-color)
7474
);
75-
}
75+
}

src/components/OBS_Components/Credits/ElectricBorderLegacy/ElectricBorder.tsx renamed to src/shared/components/ElectricBorderLegacy/ElectricBorder.tsx

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./ElectricBorder";

0 commit comments

Comments
 (0)