@gridui/theme

中文文档
2.3.0发布于 2026/11/01UNLICENSEDTypeScriptES Module

GridUI React theme

原始使用文档

@gridui/theme

GridUI theme. Part of the GridUI React monorepo.

Theme owns semantic token values for color, spacing, typography, focus, motion, and appearance. Grid applies those values to page geometry and structural boundaries; the other Core families apply them to functional surfaces. Theme does not own the structure or state of those components.

Import compiled styles.css for token definitions, opt into reset.css when the application wants document defaults, and use tailwind.css as the explicit raw Tailwind adapter. Shared responsive value resolution and spacing-variable construction live in the React-free @gridui/style-utils/responsive entry.

Palette scopes

Import paletteClass and its Palette type from @gridui/theme, and load @gridui/theme/styles.css. The helper returns a class for a native element; it adds no React dependency, wrapper, landmark, gutter, or structural boundary.

import { paletteClass } from "@gridui/theme";

<section className={paletteClass("brand")}>
    <div className={paletteClass("neutral")}>
        A neutral surface inside the brand region.
        <aside className={paletteClass("brand")}>Brand again.</aside>
    </div>
</section>

paletteClass() and paletteClass("inherit") return no scope class and preserve inherited colors. paletteClass("neutral") explicitly resets to the registered neutral palette. The other choices are brand, warning, and danger. Use one palette class on each surface. All four choices set their own semantic colors and native foreground/background; application utilities can still choose layout or override the painted foreground/background.

Applications register their neutral colors through --gridui-neutral-* source tokens. These are separate from the currently active --gridui-background, --gridui-foreground, and other semantic output tokens. Register at the document root so every nested reset restores the same application palette, for example:

:root {
    --gridui-neutral-background: light-dark(#f7f2e8, #18221e);
    --gridui-neutral-foreground: light-dark(#203c30, #e4eadf);
    --gridui-neutral-muted: light-dark(#5e7066, #aebeb2);
    --gridui-neutral-border: light-dark(#bccbbf, #435c4c);
    --gridui-neutral-link: var(--gridui-neutral-foreground);
    --gridui-neutral-accent-background: var(--gridui-neutral-foreground);
    --gridui-neutral-accent-foreground: var(--gridui-neutral-background);
    --gridui-neutral-surface: light-dark(#e8ede4, #25372d);
}

The built-in neutral source defaults retain the existing document colors. Existing root semantic overrides continue to style the document, but applications must register their --gridui-neutral-* source colors before using explicit neutral resets; those resets cannot infer an application's earlier overrides. For neutral registration, link defaults to the scope's active accent background when --gridui-neutral-link is omitted; locally registering only a neutral accent therefore also updates its derived link and focus colors.

Brand, warning, and danger retain their existing --gridui-<palette>-* source roles and default aliases for compatibility with direct token consumers. Their base source roles are independent: locally overriding a foreground does not rewrite an inherited link or accent source that already has a configured value. Supply the matching source roles when customizing those existing palettes. The scope still resolves all interaction-derived outputs against the resulting local base palette; it does not infer application color choices.

Every scope remaps background, foreground, muted, border, link, and accent colors, then resolves control borders, focus, surfaces, selection tint, and decoration at that same element. These outputs do not reuse an ancestor's already-computed interaction colors. Hover outlines derive from that local focus color; disabled and selected controls keep consuming the same local semantic tokens. Optional source overrides are control-border, focus-color, surface-hover, selection-tint, and decoration, alongside surface, under the chosen --gridui-<palette>- prefix. The selection source maps to the existing --gridui-brand-tint semantic output. Neutral also provides source defaults for surface and decoration; non-neutral choices retain their existing derived Grid tone formulas when these overrides are omitted.

Grid frame tones reuse this Theme owner. Their existing tone="neutral" means inheritance, preserving existing nested-frame behavior; an explicit reset is a separate paletteClass("neutral") on the caller's native content surface. Grid continues to own seams and region geometry.

Palette inheritance follows the DOM. A portal mounted outside the scoped surface uses its actual DOM host's palette. Supply an appropriate public portal container or apply the scope class to a caller-owned host when local overlay colors are required; Theme does not add application state or portal wrappers.

Sticky application chrome uses --gridui-z-sticky (4), above content, structural boundaries and interaction outlines, and below overlay and modal layers. All component stacking levels come from Theme tokens.

See the repository README for CSS setup, supported environments, development, and release requirements.

See quarterly release history for prepared release notes and consumption records.

版本与发布记录

@gridui/theme 共发布 10 个版本,首次发布于 2026/10/22;过去 12 个月发布了 10 个版本。

版本发布日期距今
2.3.0latest2026/11/012 天前
2.2.12026/11/012 天前
2.1.22026/10/313 天前
2.1.12026/10/277 天前
2.0.02026/10/268 天前
1.0.02026/10/259 天前

关于 @gridui/theme 的常见问题

@gridui/theme 是什么?

GridUI React主题

如何安装 @gridui/theme?

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

@gridui/theme 支持 TypeScript 吗?

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

@gridui/theme 支持 ESM 还是 CommonJS?

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

@gridui/theme 可以商用吗?

@gridui/theme 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@gridui/theme 还在维护吗?

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