@bridge-ds/react

中文文档
1.8.5发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 1796

Bridge design system React components: Base UI behavior, token-only styling through CSS Modules.

原始使用文档

@bridge-ds/react

React components of the Bridge design system. Behavior comes from Base UI (focus, keyboard, ARIA); styling is token-only CSS, so every component follows the brand, theme and density set by @bridge-ds/tokens.

npm i @bridge-ds/react @bridge-ds/tokens
import '@bridge-ds/tokens/fonts.css';
import '@bridge-ds/tokens/tokens.css';
import '@bridge-ds/react/styles.css';
import { Button, ThemeProvider } from '@bridge-ds/react';

export function App() {
  return (
    <ThemeProvider asRoot theme="light" brand="bridge" density="comfortable">
      <Button>Save changes</Button>
    </ThemeProvider>
  );
}

@bridge-ds/react/styles.css holds the global base and every component's styles. Import it once, after the token CSS. Peer dependencies: react and react-dom 18 or later.

Pages without React

Static sites, server templates and pages that build rows in plain scripts use @bridge-ds/react/dom. Each renderer returns the exact markup of its React component, with the same CSS Module classes (from the same stylesheet), so it looks and behaves the same. Parity tests compare every renderer with its component.

import { badgeHtml, bindCodeBlocks, bindTooltips, codeBlockHtml, tooltipAttributes } from '@bridge-ds/react/dom';

row.innerHTML = badgeHtml('Approved', { tone: 'success', attributes: tooltipAttributes('Approved by the design owner', { focusable: true }) });
panel.innerHTML = codeBlockHtml('npm i @bridge-ds/react', { label: 'Install' });
bindTooltips(); // once per page: every [data-tooltip] element, now or later
bindCodeBlocks(); // once per page: copy buttons of CodeBlocks rendered without hydration

page.insertAdjacentHTML('beforeend', dialogHtml({ id: 'new-token', title: 'New token', body: trusted(fields), footer: trusted(actions) }));
bindDialogs(); // [data-dialog-open="new-token"] opens it, [data-dialog-close] and Escape close it
openDialog('new-token'); // or from a script; closeDialog(id, value) and the root's `close` event mirror <dialog>

Renderers: badgeHtml, badgeClassName, codeBlockHtml, tokenValueHtml, checklistHtml, checklistRowHtml, dialogHtml. The Dialog behaves like the React one: focus moves in and is trapped, the page behind is inert and does not scroll, Escape and the scrim close it, focus returns to the trigger; a <form method="dialog"> inside closes it on submit with the button's value (dialogReturnValue). Text is escaped; pass trusted(html) for markup you built and escaped yourself. bridge audit counts these calls as design system components, and counts homemade look-alikes in script-built markup (class="pill", data-tip tooltips) against adoption. Your bundler must handle CSS Modules imported from the package (Vite, Astro and Next do), or import @bridge-ds/react/styles.css and use the published build.

Try a design system branch on staging

Install a branch snapshot (see the PR comment "Try this DS branch in your product"), or preview a branch's tokens without reinstalling: pass tokenOverride to ThemeProvider with an allowlist, then open staging with ?bridge-tokens=<url-to-tokens.css>. Off by default and refused in production builds unless you opt in. Read the security notes in docs/PREVIEWS.md of the repository before enabling it.

MIT license.

版本与发布记录

@bridge-ds/react 共发布 16 个版本,首次发布于 2026/10/18;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.8.5latest2026/11/08今天
1.8.42026/11/036 天前
1.8.32026/11/027 天前
1.8.22026/10/319 天前
1.8.12026/10/2811 天前
1.8.02026/10/2514 天前

关于 @bridge-ds/react 的常见问题

@bridge-ds/react 是什么?

Bridge design system React components: Base UI behavior, token-only styling through CSS Modules.

如何安装 @bridge-ds/react?

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

@bridge-ds/react 支持 TypeScript 吗?

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

@bridge-ds/react 支持 ESM 还是 CommonJS?

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

@bridge-ds/react 可以商用吗?

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

@bridge-ds/react 的下载量有多少?

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

@bridge-ds/react 还在维护吗?

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