@caspeco/casper-ui-library

中文文档
12.2.0发布于 2026/11/06TypeScriptES Module近 30 天下载 7149

NPM Version

原始使用文档
文档目录6 节
  1. Local development
  2. Commands
  3. Preview locally in another project
  4. Visual Regression Tests
  5. Contributing
  6. How to add new icons

@caspeco/casper-ui-library

NPM Version

Caspeco's UI component library, built on top of Chakra UI.

👉 The usage documentation can be found at https://caspeco.github.io/casper-ui-library**

Local development

To build this project you need to have Node.js installed.

Commands

All commands are run from the root of the project, from a terminal.

CommandDescription
npm installInstall dependencies.
npm run devBuild a local development version of the entire library, compiled into a single .js file for improved HMR. Automatically rebuilds when the file contents change.
npm run buildBuild the library as it will be shipped on npm. Does not automatically rebuild when files change, but you can still use this build output to verify your changes in the documentation website or in another project.
cd ../docs && npm run devStarts the documentation website. Usually you want to run this alongside the library in dev mode, so open a new terminal for this. See /docs for more info.
npm run testRun unit tests.
npm run test:visualRun visual regression tests using Playwright in Docker. Automatically starts/stops Docker container.
npm run test:visual:uiOpens the HTML report viewer for visual test results.
npm run test:visual:updateUpdate visual regression baseline screenshots. Run this after intentional UI changes.
npm run lintRun linting with @caspeco/eslint-config. If you use the recommended ESLint VSCode extension you can see your eslint errors directly in your editor without having to run this.
npm run prettier:fixReformat all files with @caspeco/prettier-config. If you use the recommended Prettier VSCode extension you can have your files automatically formatted on file save.
npm run chakra:typesGenerate Chakra UI type definitions for the theme. You run this if you modify component variants and want to get rid of TS errors, for example. Happens automatically on npm install.
npm run test:allRun every check the CI lint job runs, in sequence: prettier, lint, tsc, knip and test. Stops at the first failure. Requires Playwright browsers (npm exec -- playwright install chromium) for the unit tests.

Preview locally in another project

  1. Build local development version (see above).
  2. In the consuming app, run npm install --no-save ./relative/path/to/this/directory (no trailing slash).
    • For example: npm install --no-save ../../casper-ui-library/packages/casper-ui-library

Now when you make a change in the component library, it should rebuild automatically and the consuming app's HMR should kick in and reload the page (preserving state is not possible as the entire library is rebuilt).

To unlink again you just need to run npm install in the consuming app. If it fails, you may need to delete node_modules first.

If you get an error about duplicate react versions, make sure this is in the vite.config.ts in the consuming app:

import path from "node:path";

export default defineConfig({
    // ...
    resolve: {
        alias: {
            react: path.resolve("./node_modules/react"),
        },
    },
});

Visual Regression Tests

Visual regression tests catch unintended UI changes by comparing screenshots of component variants to committed baselines in __screenshots__/. They run with Playwright in Docker to ensure consistent rendering across different development environments and CI.

Requirements: Docker must be installed and running.

Running tests:

  • npm run test:visual - Runs all visual tests
  • npm run test:visual:ui - Opens the HTML report viewer
  • npm run test:visual:update - Updates baseline screenshots after intentional UI changes

[!TIP] CI fails but local passes?

  1. Go to the visual-tests job in GitHub Actions
  2. Download and extract the HTML artifact under the Upload visual test report step
  3. Run npx vite preview --outDir . in the extracted directory to see diff report from CI

You may need to tweak the pixelmatch comparator options if you see false positives due to anti-aliasing or sub-pixel rendering differences. See existing tests for examples.

Contributing

  1. Make sure your repository is up to date.
    git pull
    
  2. Create a new branch and make your changes there. Preferrably use a branch name that includes any related Jira issue and some short descriptive name.
    git checkout -b UTF-837-add-checkbox-component
    
  3. Make your changes. Don't touch the version field in package.json, CI handles it.
  4. Open a pull request using the template and assign a reviewer.
  5. If the change should be released, add one of the labels bump-patch, bump-minor or bump-major (following Semantic versioning). The version reflects API changes only (e.g. removing a prop → MAJOR, adding a prop → MINOR, no public API changes → PATCH). UI changes are NOT API changes.
  6. If the PR makes significant changes to the UI (e.g. changes the sizes for all buttons), clearly announce this in the Mattermost channel.
  7. After approval, merge the PR. If it has a bump label, CI bumps the version, commits it to main and publishes to npm. @caspeco/casper-ui-css is released the same way with its own bump-css-* labels. The documentation website is always rebuilt.

How to add new icons

  1. Export from Figma In the Figma Icons document, choose File → Export and export all icons as SVG.

  2. Clean icon assets From the repository root, run npm run clean:icons to delete the existing assets in lib/components/icon/assets and the generated React icon components in lib/components/icon/icons.

  3. Update assets Drop in the exported SVGs. Verify changes with git diff.

  4. Generate components From the repository root, run npm run generate:icons to generate React components for each icon.

  5. Format generated React icon components The generated icon components may not be formatted correctly initially. If that happens, run npm run prettier:fix.

版本与发布记录

@caspeco/casper-ui-library 共发布 118 个版本,首次发布于 2025/08/05;过去 12 个月发布了 86 个版本。

版本发布日期距今
12.2.0latest2026/11/062 天前
12.1.12026/10/1525 天前
12.1.02026/10/1326 天前
12.0.02026/10/061 个月前
11.4.02026/10/061 个月前
11.3.02026/09/301 个月前

其他发布通道:next → 9.0.0-alpha.6。

关于 @caspeco/casper-ui-library 的常见问题

如何安装 @caspeco/casper-ui-library?

在项目目录运行 npm install @caspeco/casper-ui-library,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.7)、react-dom(^19.2.7)、@emotion/cache(^11.14.0)、@emotion/react(^11.14.0)、@chakra-ui/react(^3.32.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@caspeco/casper-ui-library 支持 TypeScript 吗?

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

@caspeco/casper-ui-library 支持 ESM 还是 CommonJS?

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

@caspeco/casper-ui-library 可以商用吗?

@caspeco/casper-ui-library 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@caspeco/casper-ui-library 的下载量有多少?

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

@caspeco/casper-ui-library 还在维护吗?

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