@ably/chat-react-ui-kit

中文文档
0.4.0发布于 2026/11/04Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2274

A library of configurable components for use with @ably/chat

原始使用文档
文档目录12 节
  1. Getting started
  2. Installation
  3. Supported Platforms
  4. Core Components
  5. App Component
  6. ChatWindow
  7. Sidebar
  8. Usage
  9. Using Individual Components
  10. Releases
  11. Contribute
  12. Support and known issues

Ably Chat Header

Ably Chat React UI Kit

A library of configurable UI components for building chat applications with the Ably Chat SDK. This package provides ready-to-use React components that integrate seamlessly with @ably/chat to handle real-time messaging, presence, typing indicators, and more.

Getting started

Everything you need to get started with Ably Chat React UI Kit:

Installation

npm install @ably/chat-react-ui-kit @ably/chat @ably/pubsub-device react react-dom

Supported Platforms

This SDK supports the following platforms:

PlatformSupport
BrowsersAll major desktop browsers, including Chrome, Firefox, Edge and Opera. Internet Explorer is not supported.
Node.jsVersion 22 or newer.
TypeScriptFully supported, the library is written in TypeScript.
ReactVersion 18 or newer. Includes providers and hooks for deep integration with the React ecosystem.

[!NOTE] The Chat UI Components SDK can be installed from NPM and requires the core Ably Chat SDK as a peer dependency.

Core Components

App Component

Full application component that provides a complete chat interface out of the box:

  • Integrated sidebar for room navigation
  • Chat area with message display and input
  • Theme support (light/dark mode)
  • Avatar management

ChatWindow

A comprehensive chat interface for individual rooms featuring:

  • Message history with pagination
  • Real-time message display
  • Message editing and deletion
  • Reactions support
  • Typing indicators

Sidebar

A collapsible navigation component for managing multiple chat rooms:

  • Room list with activity indicators
  • Room creation and management
  • Presence and occupancy display
  • Theme toggle integration

Usage

The following example demonstrates how to set up a complete chat application using the core components. This includes initializing the Ably client, wrapping your app with the required providers, and rendering the App component with a sidebar and chat window:

import { createClient } from '@ably/pubsub-device';
import { createChatClient } from '@ably/chat';
import { ChatClientProvider } from '@ably/chat/react';
import {
  App,
  ThemeProvider,
  AvatarProvider,
  ChatSettingsProvider,
} from '@ably/chat-react-ui-kit';

// Don't forget to import the styles
import '@ably/chat-react-ui-kit/dist/style.css';

// Initialize the Ably Pub/Sub client with your API key and a unique client ID
const pubsubClient = createClient({
  key: '<your-ably-api-key>',
  clientId: 'user-' + Math.random().toString(36).slice(2, 9),
});

// Create a Chat client using the Ably Pub/Sub client
const chatClient = createChatClient(pubsubClient);

function MyApp() {
  return (
    // ThemeProvider: Enables light/dark mode theming with optional persistence
    <ThemeProvider options={{ persist: true, defaultTheme: 'light' }}>
      {/* AvatarProvider: Manages user avatar state across the application */}
      <AvatarProvider>
        {/* ChatSettingsProvider: Provides chat configuration context */}
        <ChatSettingsProvider>
          {/* ChatClientProvider: Makes the chat client available to all child components */}
          <ChatClientProvider client={chatClient}>
            {/*
              App: The main chat application component
              - Renders a Sidebar for room navigation (create, select, leave rooms)
              - Renders a ChatWindow for the active room with messages, typing indicators, and reactions
              - initialRoomNames: Pre-populate the sidebar with these room names
            */}
            <App initialRoomNames={['general', 'random']} />
          </ChatClientProvider>
        </ChatSettingsProvider>
      </AvatarProvider>
    </ThemeProvider>
  );
}

Using Individual Components

For more control, you can use ChatWindow and Sidebar independently:

import { useState } from 'react';
import { ChatRoomProvider } from '@ably/chat/react';
import {
  ChatWindow,
  Sidebar,
  ThemeProvider,
} from '@ably/chat-react-ui-kit';

// Assumes ChatClientProvider is already set up in a parent component

function CustomChatApp() {
  const [rooms, setRooms] = useState<string[]>(['general']);
  const [activeRoom, setActiveRoom] = useState<string | undefined>('general');

  const addRoom = (name: string) => {
    setRooms((prev) => (prev.includes(name) ? prev : [...prev, name]));
    setActiveRoom(name);
  };

  const leaveRoom = (name: string) => {
    setRooms((prev) => {
      const next = prev.filter((r) => r !== name);
      // Update active room based on the new list to avoid stale state
      if (next.length === 0) {
        setActiveRoom(undefined);
      } else if (name === activeRoom) {
        setActiveRoom(next[0]);
      }
      return next;
    });
  };

  return (
    <ThemeProvider>
      <div className="flex h-screen">
        {/* Sidebar: Manages room list, creation, and selection */}
        <Sidebar
          roomNames={rooms}
          activeRoomName={activeRoom}
          addRoom={addRoom}
          setActiveRoom={setActiveRoom}
          leaveRoom={leaveRoom}
        />

        {/* ChatWindow: Displays messages, input, typing indicators for the active room */}
        {activeRoom && (
          <ChatRoomProvider key={activeRoom} name={activeRoom}>
            <ChatWindow
              roomName={activeRoom}
              enableTypingIndicators={true}
            />
          </ChatRoomProvider>
        )}
      </div>
    </ThemeProvider>
  );
}

Releases

The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.

Contribute

Read the MAINTAINERS.md guidelines to contribute to Ably or Share feedback or request a new feature.

Support and known issues

For help or technical support, visit Ably's support page. You can also view the community reported Github issues or raise one yourself.

版本与发布记录

@ably/chat-react-ui-kit 共发布 5 个版本,首次发布于 2025/10/11;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/11/043 天前
0.3.02025/10/301 年前
0.2.02025/10/231 年前
0.1.32025/10/221 年前
0.1.22025/10/111.1 年前

关于 @ably/chat-react-ui-kit 的常见问题

@ably/chat-react-ui-kit 是什么?

A library of configurable components for use with @ably/chat

如何安装 @ably/chat-react-ui-kit?

在项目目录运行 npm install @ably/chat-react-ui-kit,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)、@ably/chat(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ably/chat-react-ui-kit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ably/chat-react-ui-kit 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ably/chat-react-ui-kit 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ably/chat-react-ui-kit 可以商用吗?

@ably/chat-react-ui-kit 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ably/chat-react-ui-kit 的下载量有多少?

根据 npm 官方下载统计,@ably/chat-react-ui-kit 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,274 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ably/chat-react-ui-kit 还在维护吗?

最新版本 0.4.0 发布于 2026/11/04(3 天前);至今共发布 5 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/10/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。