@gouvfr-lasuite/cunningham-tokens

中文文档
3.1.0发布于 2025/12/15MITTypeScriptESM + CJS近 30 天下载 6714

What are design tokens ?

原始使用文档
文档目录8 节
  1. Introduction
  2. Getting started
  3. Configuration file
  4. Build
  5. Use the design tokens
  6. Stylesheet
  7. Typescript
  8. Javascript

@gouvfr-lasuite/cunningham-tokens

Introduction

What are design tokens ?

Design tokens are the fundamental variables defining the precise behavior and rendering of ui components.

For example:

  • The primary color of a text element
  • The standard spacing between two elements
  • The border radius of a button
  • ...

Getting started

In this section we will install the library and generate the file that contains the design tokens of your app in order to make Cunningham's Design System yours!

Install the lib

yarn add @gouvfr-lasuite/cunningham-tokens

Configuration file

Typescript

If you prefer using Typescript, create a file named cunningham.ts at the root of your project

export default {
  theme: {
    colors: {
      primary: "purple",
    },
  },
};

Javascript

Or if you prefer Javascript, create a file named cunningham.cjs at the root of your project

module.exports = {
  theme: {
    colors: {
      primary: "purple",
    },
  },
};

In this configuration file you can overwrite all the default values of the design system. You can find the default values here.

Build

Now add this script to your package.json

{
    "scripts": {
        ...
        "build-theme": "cunningham -g css"
    }
}

The cunningham CLI's main purpose is to build a ad-hoc CSS,JS,TS files that contain all your customized design tokens, by taking into account your local configuration ( defined in the file that you previously created : cunningham.cjs, it is worth mentioning that this file is optional, hence it will generate a file containing the default values of the design system )

You can run yarn run cunningham -h to see the available options.

And in order to generate the tokens css file, run

yarn build-theme

It will generate a file named cunningham-tokens.css. Don't forget to run this command everytime you change the content of the cunningham.cjs file !

Then, add these lines at the top of your main stylesheet file:

@import "cunningham-tokens"; // Imports the file you just generated.
@import "@gouvfr-lasuite/cunningham-react/style";

It's all done!

You can also generate Typescript or Javascript files using the -g option. Example: cunningham -g css,ts,js

Use the design tokens

Stylesheet

Design tokens variable are all present in the cunningham-tokens.css file. They are all prefixed with --c in order to avoid collision.

Here is an example to make the text's color renders with the value of the primary color in .my-element matching elements

.my-element {
  color: var(--c--colors--primary);
}

Typescript

If you previously specified -g ts option you will have a cunningham-tokens.ts file generated. You can import it in your Typescript files and use the design tokens like this:

import { tokens } from "./cunningham-tokens";

const myColor = tokens.theme.colors.primary;

Javascript

If you previously specified -g js option you will have a cunningham-tokens.js file generated. You can import it in your Javascript files and use the design tokens like this:

import { tokens } from "./cunningham-tokens.js";

const myColor = tokens.theme.colors.primary;

版本与发布记录

@gouvfr-lasuite/cunningham-tokens 共发布 1 个版本,首次发布于 2025/12/15;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.0latest2025/12/1511 个月前

关于 @gouvfr-lasuite/cunningham-tokens 的常见问题

@gouvfr-lasuite/cunningham-tokens 是什么?

What are design tokens ?

如何安装 @gouvfr-lasuite/cunningham-tokens?

在项目目录运行 npm install @gouvfr-lasuite/cunningham-tokens,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cunningham,可以用 npx cunningham 直接运行。

@gouvfr-lasuite/cunningham-tokens 支持 TypeScript 吗?

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

@gouvfr-lasuite/cunningham-tokens 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gouvfr-lasuite/cunningham-tokens 需要什么版本的 Node.js?

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

@gouvfr-lasuite/cunningham-tokens 可以商用吗?

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

@gouvfr-lasuite/cunningham-tokens 的下载量有多少?

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

@gouvfr-lasuite/cunningham-tokens 还在维护吗?

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