@cruglobal/cornerstone-components

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

The custom-element library of the Cornerstone design system.

原始使用文档
文档目录11 节
  1. Installation
  2. Developers ✨
  3. What are you using to build Cornerstone Components?
  4. Where do npm dependencies go?
  5. Getting the Repo
  6. Developing
  7. Building
  8. Testing
  9. Creating New Components
  10. Contributing
  11. License

Cornerstone Components

Cru's web component library: 70 components built with Lit.

  • Framework-agnostic. They are custom elements, so they work in React, Vue, Rails, WordPress or plain HTML.
  • Customizable with CSS. Every component exposes CSS custom properties and parts, and the library themes from one set of design tokens.
  • Light and dark. Three themes ship: cru (the default), fl for FamilyLife, and the unbranded default. Each carries both colour schemes.
  • Accessible. 59 of the 70 components assert against axe in the test suite, on three engines and both render modes. The 11 that do not render nothing interactive.

Documentation: cruglobal.github.io/cornerstone-design-system

Source: github.com/CruGlobal/cornerstone-design-system


Installation

npm install @cruglobal/cornerstone-components

Import the stylesheet once, then each component you use:

import '@cruglobal/cornerstone-components/styles/cornerstone.css';
import '@cruglobal/cornerstone-components/components/button/button.js';
<cs-button variant="brand">Click me</cs-button>

If you serve the library yourself rather than bundling it, copy dist/bundled out of the package and load cornerstone.loader.js from your own origin — the autoloader registers each cs-* element as it finds one. The installation guide covers both paths.


Developers ✨

Developers can use this documentation to learn how to build Cornerstone Components from source.

You don't need to do any of this to use Cornerstone Components! This page is for people who want to contribute to the project, tinker with the source, or create a custom build.

If that's not what you're trying to do, the documentation website is where you want to be.

What are you using to build Cornerstone Components?

Components are built with Lit, a custom elements base class that provides an intuitive API and reactive data binding. The build is a custom script with bundling powered by esbuild.

Where do npm dependencies go?

Anything a component needs at runtime — lit, for instance — belongs in dependencies, because it has to be installed for anyone consuming this package. Tooling used only to build, test or lint the library belongs in devDependencies.

npm install -D prettier

Getting the Repo

Clone the repo locally and install dependencies.

git clone https://github.com/CruGlobal/cornerstone-design-system
cd cornerstone-components
npm install

Developing

Once you've cloned the repo, run:

npm start

This watches src/ and rebuilds the library on change, serving dist/ so a page can load the built files. There is currently no hot module reloading (HMR), as browsers don't provide a way to reregister custom elements, but most changes to the source will reload the browser automatically.

To work on the documentation, run the docs site alongside it in a second terminal:

npm run start:docs

That starts Astro's dev server on http://localhost:4321. It copies the current dist/bundled/ in on startup, so rebuild the library and restart it to pick up component changes.

Building

To generate a production build, run the following command.

npm run build

You can also run npm run build:serve to start an http-server instance on http://localhost:4000 after the build completes, so you can preview the production build.

Testing

npm test runs every test file in Chromium, Firefox and WebKit. Build first: the tests load components from dist/.

CI splits the suite across six runners with WTR_SHARD, and you can run one of those slices yourself:

WTR_SHARD=2/6 npm test

Files are dealt to shards by how long each one takes, so the shards finish together. Those timings live in test-durations.json. A test file that is not in it still runs; it just counts as one second when the shards are dealt. Refresh the file when CI's shards drift more than a minute or two apart, or after adding several heavy test files:

npm run build
npm run test:durations

That runs the whole suite and rewrites test-durations.json with the seconds each file took, averaged over the three engines. Commit the result. Run it on a quiet machine, since a busy one inflates whichever files were running at the time. Tests are not retried during this run, so a test that times out fails. If the run warns that some files did not pass, refresh just those with the command below before committing: it replaces the inflated number.

To refresh one component's files and leave the rest as they are, call the runner itself. npm run test:durations -- --group button does not work: npm keeps --group for itself and the whole suite runs.

WTR_RECORD_DURATIONS=true npx web-test-runner --group button

Those numbers are rougher than a full run's. In any run, the first files each browser opens also wait for that browser to launch. In a one-group run every file is one of the first, and nothing else is loading the machine. Use it to get a new file onto the list or to replace a number a failure inflated, and do a full run when the shards drift.

Creating New Components

To scaffold a new component, run the following command. It prompts for the tag name, which must start with cs-.

npm run create

This generates four files: the component, its stylesheet, its test file, and a docs page. When you start the dev server, you'll find the new component in the "Components" section of the sidebar.

Contributing

Cornerstone Components is maintained by Cru. Issues and bug reports are welcome from anyone; pull requests come from the Cru design system team. See the contribution guidelines.

License

Cornerstone Components is available under the terms of the MIT License.

版本与发布记录

@cruglobal/cornerstone-components 共发布 13 个版本,首次发布于 2026/08/29;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.11.0latest2026/11/11今天
0.10.02026/10/2418 天前
0.9.02026/10/2220 天前
0.8.12026/10/1526 天前
0.8.02026/10/1527 天前
0.7.12026/10/101 个月前

关于 @cruglobal/cornerstone-components 的常见问题

@cruglobal/cornerstone-components 是什么?

The custom-element library of the Cornerstone design system.

如何安装 @cruglobal/cornerstone-components?

在项目目录运行 npm install @cruglobal/cornerstone-components,或使用 pnpm add / yarn add / bun add。

@cruglobal/cornerstone-components 支持 TypeScript 吗?

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

@cruglobal/cornerstone-components 支持 ESM 还是 CommonJS?

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

@cruglobal/cornerstone-components 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cruglobal/cornerstone-components 可以商用吗?

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

@cruglobal/cornerstone-components 的下载量有多少?

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

@cruglobal/cornerstone-components 还在维护吗?

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