@cometchat/cards

中文文档
1.0.0发布于 2026/05/27https://www.cometchat.com/legal-terms-of-serviceTypeScriptESM + CJS零依赖近 30 天下载 1.2万

CometChat Card Schema JSON renderer — vanilla TypeScript core

原始使用文档
文档目录7 节
  1. What it does
  2. Installation
  3. Usage
  4. React Wrapper
  5. Getting Started
  6. Prerequisites
  7. Help and Support

CometChat Card Renderer

A vanilla TypeScript renderer for the CometChat Card Schema. Pass in card JSON, get back a native DOM element tree. Taps on interactive elements are emitted to your app through a single callback — the package never executes actions itself.

What it does

  • Parses Card Schema JSON into typed models
  • Renders 20 element types (text, image, icon, avatar, badge, divider, spacer, chip, progressBar, codeBlock, markdown, row, column, grid, accordion, tabs, button, iconButton, link, table)
  • Resolves theme-aware colors and image URLs for auto, light, and dark modes, with optional theme overrides
  • Emits clicks on buttons, icon buttons, and links to your callback as typed CometChatCardActionEvents

The package is a pure renderer. It doesn't talk to the CometChat SDK, doesn't manage message lifecycle, and doesn't know about your app's routing. You decide what each action does.

Installation

npm install @cometchat/cards

Usage

import { renderCard } from "@cometchat/cards";

const { element, containerStyle, destroy } = renderCard({
  cardJson,
  themeMode: "auto",
  onAction: (event) => {
    console.log("action:", event.action.type, "from", event.elementId);
  },
});

document.getElementById("card-root")!.appendChild(element);

// Later, when unmounting:
destroy();

The destroy function cleans up the system-theme media query listener used in auto mode.

React Wrapper

For React projects, use @cometchat/cards-react which provides a CometChatCardView component that wraps this package.

Getting Started

Refer to the Integration Steps to integrate the cards into your app.

Prerequisites

  • Node.js >= 14.17.0
  • npm >= 7

Help and Support

For integration issues, create a support ticket or seek real-time support via the CometChat Dashboard.

版本与发布记录

@cometchat/cards 共发布 1 个版本,首次发布于 2026/05/27;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.0.0latest2026/05/275 个月前

关于 @cometchat/cards 的常见问题

@cometchat/cards 是什么?

CometChat Card Schema JSON renderer — vanilla TypeScript core

如何安装 @cometchat/cards?

在项目目录运行 npm install @cometchat/cards,或使用 pnpm add / yarn add / bun add。

@cometchat/cards 支持 TypeScript 吗?

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

@cometchat/cards 支持 ESM 还是 CommonJS?

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

@cometchat/cards 可以商用吗?

@cometchat/cards 使用 https://www.cometchat.com/legal-terms-of-service 许可。声明的许可为 https://www.cometchat.com/legal-terms-of-service,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@cometchat/cards 的下载量有多少?

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

@cometchat/cards 还在维护吗?

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