feat: 对于过长消息自动折叠并通过展开按钮展开

pull/81/head
moonrailgun 3 years ago
parent b086739199
commit 8ea2e9e873

@ -2,15 +2,11 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
interface AutoFolderProps { interface AutoFolderProps {
maxHeight: number; maxHeight: number;
showFullText?: string; showFullText?: React.ReactNode;
backgroundColor?: string; backgroundColor?: string;
} }
export const AutoFolder: React.FC<AutoFolderProps> = React.memo((props) => { export const AutoFolder: React.FC<AutoFolderProps> = React.memo((props) => {
const { const { maxHeight, showFullText = 'More', backgroundColor = 'white' } = props;
maxHeight,
showFullText = 'More',
backgroundColor = 'rgba(0,0,0,0)',
} = props;
const [isShowFull, setIsShowFull] = useState(false); const [isShowFull, setIsShowFull] = useState(false);
const contentRef = useRef<HTMLDivElement>(null); const contentRef = useRef<HTMLDivElement>(null);
@ -61,7 +57,7 @@ export const AutoFolder: React.FC<AutoFolderProps> = React.memo((props) => {
bottom: 0, bottom: 0,
textAlign: 'center', textAlign: 'center',
cursor: 'pointer', cursor: 'pointer',
backgroundImage: `linear-gradient(${backgroundColor}, white)`, backgroundImage: `linear-gradient(rgba(0,0,0,0), ${backgroundColor})`,
padding: '4px 0', padding: '4px 0',
}} }}
onClick={() => setIsShowFull(true)} onClick={() => setIsShowFull(true)}

@ -22,6 +22,7 @@ import { TcPopover } from '@/components/TcPopover';
import { useMessageReactions } from './useMessageReactions'; import { useMessageReactions } from './useMessageReactions';
import { stopPropagation } from '@/utils/dom-helper'; import { stopPropagation } from '@/utils/dom-helper';
import { useUserInfoList } from 'tailchat-shared/hooks/model/useUserInfoList'; import { useUserInfoList } from 'tailchat-shared/hooks/model/useUserInfoList';
import { AutoFolder } from 'tailchat-design';
import './Item.less'; import './Item.less';
/** /**
@ -104,6 +105,15 @@ const NormalMessage: React.FC<ChatMessageItemProps> = React.memo((props) => {
)} )}
{/* 消息内容 */} {/* 消息内容 */}
<AutoFolder
maxHeight={320}
backgroundColor="var(--tc-content-background-color)"
showFullText={
<div className="inline-block rounded-full bg-white dark:bg-black opacity-80 py-2 px-3 hover:opacity-100">
{t('点击展开更多')}
</div>
}
>
<div className="chat-message-item_body leading-6 break-words"> <div className="chat-message-item_body leading-6 break-words">
<MessageQuote payload={payload} /> <MessageQuote payload={payload} />
@ -112,6 +122,7 @@ const NormalMessage: React.FC<ChatMessageItemProps> = React.memo((props) => {
{/* 解释器按钮 */} {/* 解释器按钮 */}
{useRenderPluginMessageInterpreter(payload.content)} {useRenderPluginMessageInterpreter(payload.content)}
</div> </div>
</AutoFolder>
{/* 额外渲染 */} {/* 额外渲染 */}
<div> <div>

@ -4,6 +4,7 @@
--tc-background-image: url(../../assets/images/bg.jpg); --tc-background-image: url(../../assets/images/bg.jpg);
--tc-content-background-image: ''; --tc-content-background-image: '';
--tc-content-background-image-opacity: 0.2; --tc-content-background-image-opacity: 0.2;
--tc-content-background-color: rgba(243, 244, 246, 1); // copy from bg-content-light
.tc-background { .tc-background {
@apply bg-center bg-cover bg-no-repeat; @apply bg-center bg-cover bg-no-repeat;
@ -51,6 +52,7 @@
// 深色模式覆盖 // 深色模式覆盖
&.dark { &.dark {
@apply text-typography-dark bg-content-dark; @apply text-typography-dark bg-content-dark;
--tc-content-background-color: rgba(55, 65, 81, 1);; // copy from bg-content-light
h1,h2,h3,h4,h5,h6 { h1,h2,h3,h4,h5,h6 {
@apply text-typography-dark; @apply text-typography-dark;

Loading…
Cancel
Save