tencent cloud

即时通信 IM

ChatSetting

Download
聚焦模式
字号
最后更新时间: 2026-07-02 16:23:39

组件概述

ChatSetting 是一个智能的聊天设置组件,它能够根据当前激活的会话类型自动渲染相应的设置界面。该组件内部集成了 C2C(1 对 1)聊天设置和群聊设置两种模式,为用户提供了统一的聊天设置入口。
组件的核心特点:
自动适配 - 根据会话类型自动切换设置界面
状态驱动 - 基于当前激活会话状态自动更新内容

Props 参数

参数
类型
默认值
描述
className
string | undefined
undefined
自定义 CSS 类名
style
React.CSSProperties | undefined
undefined
自定义内联样式

快速使用

ChatSetting 是一个可自由使用的独立组件,默认的开关控制在 ChatHeader 组件上,也可以使用 useUIOpenControlState Hook 自定义 ChatSetting 的开关。

import { useState } from 'react';
import {
ChatSetting,
Search,
useChatContext,
VariantType,
} from '@tencentcloud/chat-uikit-react';
import './styles.css';

function ChatSidePanelsBasicDemo() {
const [isChatSettingShow, setIsChatSettingShow] = useState(false);
const [isSearchShow, setIsSearchShow] = useState(false);
const [targetID, setTargetID] = useState('');
const [conversationType, setConversationType] = useState<'C2C' | 'GROUP'>('C2C');
const { activeConversationID, setActiveConversation } = useChatContext();

const handleActivateConversation = () => {
const normalizedID = targetID.trim();
if (!normalizedID) {
return;
}
setActiveConversation(`${conversationType}${normalizedID}`);
};

return (
<div className="chat-side-panels-basic-demo">
<div className="chat-side-panels-basic-demo__header">
<h2>Chat Side Panels</h2>
<p>Activate a conversation, then open or close ChatSetting and Search.</p>
</div>

<div className="chat-side-panels-basic-demo__frame">
<div className="chat-side-panels-basic-demo__actions">
<input
onChange={event => setTargetID(event.target.value)}
placeholder="User ID or group ID"
value={targetID}
/>
<select
onChange={event => setConversationType(event.target.value as 'C2C' | 'GROUP')}
value={conversationType}
>
<option value="C2C">C2C</option>
<option value="GROUP">GROUP</option>
</select>
<button onClick={handleActivateConversation} type="button">
Activate Conversation
</button>
<span className="chat-side-panels-basic-demo__active">
Active: {activeConversationID || 'None'}
</span>
<button
onClick={() => setIsChatSettingShow(show => !show)}
type="button"
>
{isChatSettingShow ? 'Hide Setting' : 'Show Setting'}
</button>
<button
onClick={() => setIsSearchShow(show => !show)}
type="button"
>
{isSearchShow ? 'Hide Search' : 'Show Search'}
</button>
</div>

{isChatSettingShow && (
<div className="chat-side-panels-basic-demo__panel">
<ChatSetting />
</div>
)}

{isSearchShow && (
<div className="chat-side-panels-basic-demo__panel">
<Search variant={VariantType.EMBEDDED} />
</div>
)}
</div>
</div>
);
}

帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈