@cdx-ui/theme-editor

中文文档
0.3.12发布于 2026/11/04MITTypeScriptES Module近 30 天下载 2563

coverage

原始使用文档
文档目录11 节
  1. Installation
  2. Usage
  3. 1. Add the editor to your Tailwind sources
  4. 2. Mount the editor
  5. 3. Edit an existing override
  6. Props
  7. Behavior notes
  8. Package structure
  9. Building
  10. Further reading
  11. License

@cdx-ui/theme-editor

coverage

A guided, web-only editor for authoring Forge Design System ThemeOverride JSON. Financial institutions choose generative inputs and package-owned semantic selections through Forge UI controls while a live panel previews real Forge UI components. The editor emits FI intent only; consuming apps persist it and apply it at runtime through @cdx-ui/styles.

Web-only. The editor uses browser APIs and React Native Web. It is not available on native platforms.

Installation

pnpm add @cdx-ui/theme-editor @cdx-ui/components @cdx-ui/styles

react, react-dom, react-native-web, and uniwind are peer dependencies — apps already consuming @cdx-ui/components will have these in place. Declare @cdx-ui/components and @cdx-ui/styles directly when importing their provider and types as shown below; the editor resolves its internal Forge UI dependencies automatically.

Usage

1. Add the editor to your Tailwind sources

The preview renders Forge UI components with Uniwind utility classes. Like the other @cdx-ui/* packages, this package ships no precompiled CSS or tokens — its ./styles.css is a Tailwind v4 @source directive that adds the editor's source to your content scan so the preview's utilities are generated. Import it in your Tailwind entry stylesheet, alongside the rest of the design system:

@import 'tailwindcss';
@import 'uniwind';

@import '@cdx-ui/styles/theme.css';
@import '@cdx-ui/styles/utilities.css';
@import '@cdx-ui/components/styles.css';
@import '@cdx-ui/theme-editor/styles.css';

2. Mount the editor

onChange fires (debounced, ~200ms) after the user edits a control with a valid target ThemeOverride. It is not called on mount. Persist the payload from onChange; production consumers apply it once during app startup:

import { SafeAreaProvider } from 'react-native-safe-area-context';
import { ThemeEditor } from '@cdx-ui/theme-editor';
import { ForgeDesignProvider } from '@cdx-ui/components';
import type { ThemeOverride } from '@cdx-ui/styles';

function ThemeConfigPage() {
  const handleChange = (override: ThemeOverride) => {
    void persistOverride(override); // your save (e.g. POST /api/themes)
  };

  return (
    <SafeAreaProvider>
      <ForgeDesignProvider>
        <ThemeEditor onChange={handleChange} showGetCode showThemeModeToggle />
      </ForgeDesignProvider>
    </SafeAreaProvider>
  );
}

showGetCode opens a Forge UI Dialog. Mount exactly one portal host near the app root: ForgeDesignProvider includes it automatically and must remain inside the app-owned SafeAreaProvider. If the app does not use the Forge provider, keep SafeAreaProvider and mount one PortalHost from @cdx-ui/primitives instead. Do not mount both; without either one, the dialog opens in state but renders no popup.

The editor parses and expands through @cdx-ui/styles, evaluates shared rules, and drives preview through a stateful covering session. Clears restore managed baseline values without dumping unrelated variables. Reload remains the recovery boundary after a physical writer failure.

3. Edit an existing override

Pass a previously saved override as initialValue to enter edit mode; the controls seed from its inputs:

<ThemeEditor initialValue={savedOverride} onChange={handleChange} />

Props

PropTypeDefaultDescription
onChange(override: ThemeOverride) => void—Required. Called (debounced, ~200ms) after the user edits a control with the current ThemeOverride. Not called on mount or while a color input is invalid.
initialValueunknown—Parses a persisted value for edit mode and surfaces invalid or unsupported payload diagnostics.
showGetCodebooleanfalseShows a "Get code" button that opens a Dialog with the override output and a copy-to-clipboard button.
showThemeModeTogglebooleanfalseShows a light/dark toggle that switches the preview surface.

The ThemeOverride shape and runtime are documented in @cdx-ui/styles.

Behavior notes

  • Intent-only output. Untouched preview defaults, derived Base, recipe members, and generated palettes are omitted. Incoming additive unknown fields are preserved.
  • Base. Base derives from Brand until explicitly pinned; unpinning removes basePrimary intent.
  • Fonts. Every catalog family is available. Choosing Default clears authored font intent and restores the generated baseline family.
  • Rules. Approved structural/source-set errors block output. Provisional visual calibration remains warning-only.
  • Live preview. The covering session writes the current sparse intent plus concrete fallback values needed to clear prior managed writes.
  • Preview isolation. The preview is wrapped in ScopedTheme so the light/dark toggle only affects the preview surface, not the editor chrome.

Package structure

theme-editor/
├── src/
│   ├── index.ts            # Public exports (ThemeEditor, ThemeEditorProps)
│   ├── styles.css          # `@source` directive — published as the ./styles.css export
│   ├── ThemeEditor.tsx     # Top-level component: state, debounced apply/emit, Dialog, toggle
│   ├── PreviewPanel.tsx    # Live preview surface (ScopedTheme + banking artboard)
│   ├── override/           # Draft provenance, serialization, controls, rules/runtime handoff
│   ├── validation.ts       # Hex validation
│   ├── fonts.ts            # Exact Google Fonts loading for display/platform families
│   ├── controls/           # FontControl, ColorControl, catalog-driven renderer
│   ├── components/         # ColorPickerInput
│   └── previews/           # Forge UI sample cards rendered in the preview
├── global.css              # Tailwind/Uniwind entry for the build (not published)
├── vite.config.ts
└── package.json

Building

pnpm --filter @cdx-ui/theme-editor build

Vite bundles src/index.ts to dist/index.js (externalizing React, React Native Web, Uniwind, and the @cdx-ui/* packages); tsc emits declarations. No CSS is emitted — src/styles.css (the @source directive) is published as-is and composes with the consumer's Tailwind build.

Further reading

  • Design tokens — how tokens and themes work
  • @cdx-ui/styles — baseline tokens, overrides, and runtime application
  • The repository's token-architecture documentation records the override payload contract and the build/runtime boundary.

License

License: MIT

MIT © 2026 Digital First Holdings LLC. The full license text ships in the package as LICENSE.

版本与发布记录

@cdx-ui/theme-editor 共发布 159 个版本,首次发布于 2026/06/19;过去 12 个月发布了 159 个版本。

版本发布日期距今
0.3.12latest2026/11/044 天前
0.3.112026/10/309 天前
0.3.102026/10/3010 天前
0.3.92026/10/3010 天前
0.3.82026/10/2811 天前
0.3.72026/10/2713 天前

其他发布通道:staging → 0.1.0。

关于 @cdx-ui/theme-editor 的常见问题

如何安装 @cdx-ui/theme-editor?

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

@cdx-ui/theme-editor 支持 TypeScript 吗?

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

@cdx-ui/theme-editor 支持 ESM 还是 CommonJS?

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

@cdx-ui/theme-editor 可以商用吗?

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

@cdx-ui/theme-editor 的下载量有多少?

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

@cdx-ui/theme-editor 还在维护吗?

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