@caqophony/ui

中文文档
0.6.3发布于 2026/11/10MITTypeScriptES Module近 30 天下载 2014

Generic, optional React UI reuse library (Gossamer tokens). Centrally maintained by Caqophony.

原始使用文档
文档目录6 节
  1. Install
  2. Styles (Tailwind v4)
  3. Styles (Tailwind v3)
  4. Animation and prose
  5. Use
  6. Licence

@caqophony/ui

Generic React UI components built on Gossamer semantic design tokens (Tailwind). Maintained centrally by Caqophony and MIT licensed.

This library is optional. Apps generated by Caqophony may use it so that common UI (buttons, cards, dialogs, tables, page layout) is not regenerated from scratch for every app, which saves tokens. It is a courtesy, not an SDK: nothing in a generated app requires it. If reuse is turned off for a project, the app is built without this dependency and its components are written from scratch. It contains only generic UI: no platform, product, auth or data-access code.

Install

pnpm add @caqophony/ui        # or npm i / yarn add

Peer dependencies: react and react-dom (^18 || ^19). @caqophony/ui/charts requires the optional peers chart.js and react-chartjs-2: install them yourself if you import that subpath. No next dependency.

The package is ESM-only. Subpath types (@caqophony/ui/charts) resolve through the exports map, so TypeScript needs moduleResolution of bundler (or node16/nodenext).

DiceBearAvatar renders an image from api.dicebear.com at runtime, so it makes a network request from the user's browser; do not use it where that is unacceptable.

Styles (Tailwind v4)

Components use Gossamer token classes (bg-primary, text-muted-foreground, border-intent-error-border, ...). Tailwind v4 does not scan node_modules and has no mapping for these names, so import the stylesheet this package ships, after Tailwind, in your global CSS:

@import 'tailwindcss';
@import '@caqophony/ui/styles.css';

styles.css defines the token variables (light, and dark under @media (prefers-color-scheme: dark), the same OS setting Tailwind v4's dark: variant follows), maps them to Tailwind v4 colour/radius/z-index/opacity/duration utilities and registers the package's built files as a Tailwind @source. Override any --token after the import to re-theme.

Styles (Tailwind v3)

Inside the Caqophony monorepo, an app takes the Gossamer preset and adds the library to content. Do not map the tokens by hand in theme.extend.colors: that left bg-primary-solid with no rule, or with a rule reading a variable nothing declares, and neither one raises an error.

import { gossamerPreset } from '@caqophony/tokens/tailwind-preset';

export default {
  presets: [gossamerPreset],
  darkMode: ['class'],
  content: ['./app/**/*.{ts,tsx}', '../../packages/ui/src/**/*.{ts,tsx}'],
};

The preset maps the library's tokens and declares its variables (light, and dark under .dark), and adds the utilities and the not-first: variant a v3 theme cannot express. It only adds names: stock Tailwind keeps its values, your theme wins over the preset, and a variable your CSS declares wins over the preset's.

pnpm exec tsx scripts/check-ui-classes-compile.ts covers the two surfaces that draw the library: the monorepo's product app on Tailwind v3, and a generated app's globals.css plus styles.css on Tailwind v4, each against the classes that surface can reach. It fails on a class Tailwind generates no rule for, or a rule reading a variable that does not reach the element by default. It runs in pre-push.

The preset is not published. Outside the monorepo, a Tailwind v3 app needs ./node_modules/@caqophony/ui/dist/**/*.js in content and the same mapping, variables, utilities and variant in its own config, or Tailwind v4 and styles.css above.

Animation and prose

On Tailwind v4, styles.css defines the animate-in / animate-out utilities the modal and tooltip use, and loads @tailwindcss/typography for MarkdownRenderer, which @caqophony/ui depends on. There is nothing to add. On Tailwind v3, install tailwindcss-animate and @tailwindcss/typography as plugins.

Use

import { Button, Card, PageContent } from '@caqophony/ui';
import { BarChart } from '@caqophony/ui/charts';
import { MarkdownRenderer } from '@caqophony/ui/markdown';
import { MarketingCta, MarketingFooter } from '@caqophony/ui/marketing';
import { Band, Display, Stack, Text } from '@caqophony/ui/material';

@caqophony/ui/material holds what a designed page is composed from: bands, display type, layout, and flat illustration pieces. Each colour is a token, so a theme change reaches all of it. Set a Band's surface to night and every library component inside reads on the dark ground, with no prop of its own.

@caqophony/ui/material-tones holds FILL and STROKE, the classes art draws in. It and @caqophony/ui/material-art are the entries with no 'use client' directive, so a server component can use them. Every other entry point carries the directive.

An app's own art is data, not code: a closed tree of SVG elements in tones, in a *.art.json file in art/ beside app/, outside the library. Art from @caqophony/ui/material-art draws it, as a Figure's one child, and nothing else makes elements in the slot. Shade paper with a held step at low opacity: paper keeps its colour in dark mode and mist-* does not.

Licence

MIT, see LICENSE.

版本与发布记录

@caqophony/ui 共发布 12 个版本,首次发布于 2026/10/13;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.6.3latest2026/11/10今天
0.6.22026/11/072 天前
0.6.12026/11/045 天前
0.6.02026/11/045 天前
0.5.12026/11/045 天前
0.5.02026/11/046 天前

关于 @caqophony/ui 的常见问题

@caqophony/ui 是什么?

Generic, optional React UI reuse library (Gossamer tokens). Centrally maintained by Caqophony.

如何安装 @caqophony/ui?

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

@caqophony/ui 支持 TypeScript 吗?

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

@caqophony/ui 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@caqophony/ui 可以商用吗?

@caqophony/ui 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@caqophony/ui 的下载量有多少?

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

@caqophony/ui 还在维护吗?

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