@newtone-dev/ui-react-web

中文文档
0.42.0发布于 2026/11/02MITTypeScriptES Module零依赖

React components for the web, built on the Newtone token layer.

原始使用文档
文档目录6 节
  1. What is here
  2. Control sizes
  3. The idea in one example
  4. Scoped identity
  5. The build
  6. Consuming

newtone_ui_react-web

Newtone's component library for React on the web.

The authoritative description of this repo is ~/gallina/newtone/ui_react-web/_blueprint/index.md, and the components here discharge ~/gallina/newtone/_blueprint/contracts/. If this README and those disagree, they win.

What is here

Twenty-six Thirty-four components and a colour port (recounted with ls src/*/index.ts on 2026-09-25, when the six chart parts arrived in 0.6.0; the twenty-six had gone stale before them). ls src/*/index.ts is the complete public API that JavaScript can reach; package.json's exports map is the complete one including stylesheets. This table is the spine and not the list — the blueprint above carries every component.

SurfaceOwns the context its contents read: theme, elevation, mode
ButtonDischarges contracts/button.md. Three variants, five states, three size rungs
TextDischarges contracts/typography.md. font, weight, case, figures, ligatures
NavbarDischarges contracts/navbar.md. Parts and knobs; arrangements belong to the site
DesktopDischarges contracts/desktop.md. An OS frame: windows, launcher, panel, sheet (no menu bar or dock: the host has them); the consumer keeps the layout
IdentityA scoped seed set: re-derives colour for one subtree
color.tsA port of contracts/color-derivation.md — the runtime half of identity

Control sizes

Every control here is one of five heights — 36, 40, 44, 48, 56 — on one of two type pairs, 14/20 or 16/24. A size prop picks a rung and the rung carries its height, its type pair, its glyph and its padding together; there is no second axis. contracts/button.md, Sizes.

smmdlgxl
Control36404448
Button, Navbar404448—
Action, QuickAction48—56—

A Control sits a rung below a Button at the first three positions, and xl is the exception. It exists for controls standing on a photograph — Gallery's arrows, VideoLightbox's close — where there is no page whose primary action they could compete with.

The idea in one example

import { Surface, Button } from '@newtone-dev/ui-react-web'
import '@newtone-dev/ui-tokens/newtone.css'
import '@newtone-dev/ui-react-web/button.css'

<Surface theme="emphasis">
  <Button>Primary</Button>
</Surface>

That Button becomes a light fill with a brand label, and nothing was passed to it.

Components carry no facets. No theme, mode or elevation prop on Button, ever. Its tokens point at roles, and a role resolves against the Surface it is sitting on. A theme prop would put the 24-way context product back onto every component, which is precisely what the role layer exists to prevent.

Scoped identity

<Identity seeds={{ system: { accent: { h: 35, c: 0.78 } } }}>
  {/* this subtree wears another brand over the site's own neutrals */}
</Identity>

seeds is shaped like the tokens repo's seed.json — group, then palette, then a hue and a saturation. A seed is not a colour and has no lightness, because lightness is a property of the job a colour is doing, and the job is not known until a role asks for it. c is a ratio from 0 to 1 of the most colourful thing reachable at that lightness and hue, so c: 1 is the gamut boundary rather than an error, and the same number means the same request of a yellow as of a blue.

Only the core colour layer is identity-dependent, so this writes 51 custom properties per palette named and nothing else. Everything below is references and follows on its own. Palettes not named inherit from the enclosing scope, and nesting is free because that inheritance is CSS's own.

The derivation is computed, not tabulated: fifty-one steps spaced evenly in CIE L*, with chroma taken from the Display P3 ceiling. src/color.ts and the tokens repo's compute/ are two implementations of one contract and must produce the same bytes.

The build

npm run build — tsc to dist/, then copy-styles.mjs, which walks src and copies all 29 stylesheets across verbatim because tsc emits no CSS. dist/ is gitignored and built on publish by prepublishOnly; there is no bundler.

This section said There is no build until 2026-09-21, and had been wrong since the build landed. tsconfig.json sets "module": "NodeNext", which is why every relative import here carries an explicit extension — a bundler resolved from './button' and Node ESM does not.

Consuming

Published to npm as @newtone-dev/ui-react-web. It declares react as a peer (^18 || ^19) and does not depend on @newtone-dev/ui-tokens: every component reads --newtone-* custom properties by name, and supplying them is the consuming site's job.

npm install @newtone-dev/ui-react-web @newtone-dev/ui-tokens
import { Surface, Button } from '@newtone-dev/ui-react-web'
import '@newtone-dev/ui-react-web/button.css'

Stylesheets are imported one at a time, per component, and every path a consumer may import is a key in the exports map. sideEffects names **/*.css so a bundler keeps them.

This section said Nothing is published to npm until 2026-09-21, three weeks after publishConfig.access and prepublishOnly were added.

版本与发布记录

@newtone-dev/ui-react-web 共发布 47 个版本,首次发布于 2026/09/20;过去 12 个月发布了 47 个版本。

版本发布日期距今
0.42.0latest2026/11/021 天前
0.41.02026/10/312 天前
0.40.12026/10/1519 天前
0.40.02026/10/1420 天前
0.39.02026/10/1420 天前
0.38.12026/10/1222 天前

其他发布通道:next → 0.2.0。

关于 @newtone-dev/ui-react-web 的常见问题

@newtone-dev/ui-react-web 是什么?

用于web的React组件,构建在Newtone令牌层上。

如何安装 @newtone-dev/ui-react-web?

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

@newtone-dev/ui-react-web 支持 TypeScript 吗?

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

@newtone-dev/ui-react-web 支持 ESM 还是 CommonJS?

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

@newtone-dev/ui-react-web 可以商用吗?

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

@newtone-dev/ui-react-web 还在维护吗?

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